flat assembler
Message board for the users of flat assembler.

Index > Main > Java to assembler

Author
Thread Post new topic Reply to topic
radoslavkirilov



Joined: 27 Dec 2006
Posts: 7
radoslavkirilov
Hello all! I want to ask you if there exists an assembler that converts java source code to assembler source code. Thanks in regards to all who will post me.
Post 08 Mar 2007, 08:48
View user's profile Send private message Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 824
Location: Jakarta, Indonesia
TmX
I don't think there is such assembler, since Java prog runs on JVM. But who knows ??
Post 08 Mar 2007, 09:55
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
There's a GCC frontend for compiling JAVA to native code... but... ugh Smile
Post 08 Mar 2007, 11:13
View user's profile Send private message Visit poster's website Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 824
Location: Jakarta, Indonesia
TmX
ah you mean GCJ ?

ah I almost forget that ...

Let's see ...
This is a simple code

Code:
public class Foo
{
        public static void main(String args[])
        {
                for (int x = 0; x < 10; x++)
                        System.out.println("Blah blah blah");
        }
}    


Compiled using : gcj -S Foo.java, the result is :

Code:
        .file   "Foo.java"
        .stabs  "/cygdrive/d/",100,0,0,Ltext0
        .stabs  "Foo.java",100,0,0,Ltext0
        .text
Ltext0:
        .stabs  "gcc2_compiled.",60,0,0,0
        .stabs  "java.lang.Class:T(0,1)=s120!1,020,(0,2)=xsjava.lang.Object:;next:/0(0,3)=*(0,1),32,32;name:/0(0,4)=*(0,5)=s4hash:(0,6)=@s16;r(0,6);0;65535;,0,16;length:(0,6),16,16;;,64,32;accflags:/0(0,6),96,16;superclass:/0(0,3),128,32;constants:/0(0,7)=s12size:(0,Cool=r(0,Cool;0000000000000;0037777777777;,0,32;tags:(0,9)=*(0,10)=(0,10),32,32;data:(0,9),64,32;;,160,96;methods:/0(0,11)=*(0,12)=s20name:(0,4),0,32;signature:(0,4),32,32;accflags:(0,6),64,16;index:(0,6),80,16;ncode:(0,9),96,32;throws:(0,9),128,32;;,256,32;method_count:/0(0,13)=@s16;r(0,13);-32768;32767;,288,16;vtable_method_count:/0(0,13),304,16;fields:/0(0,14)=*(0,15)=s16name:(0,4),0,32;type:(0,3),32,32;accflags:(0,6),64,16;bsize:(0,6),80,16;info:(0,16)=u4boffset:(0,17)=r(0,17);-2147483648;2147483647;,0,32;addr:(0,9),0,32;;,96,32;;,320,32;size_in_bytes:/0(0,17),352,32;field_count:/0(0,13),384,16;static_field_count:/0(0,13),400,16;vtable:/0(0,1Cool=*(0,19)=s12class:(0,3),0,32;methods:(0,20)=ar(0,21)=r(0,21);0000000000000;0037777777777;;0;1;(0,9),32,64;;,416,32;otable:/0(0,22)=*(0,23)=ar(0,21);0;1;(0,17),448,32;otable_syms:/0(0,24)=*(0,25)=ar(0,21);0;1;(0,26)=s12clname:(0,4),0,32;name:(0,4),32,32;signature:(0,4),64,32;;,480,32;atable:/0(0,27)=*(0,20),512,32;atable_syms:/0(0,24),544,32;catch_classes:/0(0,9),576,32;interfaces:/0(0,2Cool=*(0,3),608,32;loader:/0(0,9),640,32;interface_count:/0(0,13),672,16;state:/0(0,29)=@s8;r(0,29);-128;127;,688,8;thread:/0(0,9),704,32;depth:/0(0,13),736,16;ancestors:/0(0,9),768,32;idt:/0(0,9),800,32;arrayclass:/0(0,9),832,32;protectionDomain:/0(0,9),864,32;hack_signers:/0(0,9),896,32;chain:/0(0,9),928,32;;",128,0,0,0
        .stabs  "java.lang.Class:Tt(0,1)",128,0,0,0
        .stabs  "java.lang.Object:Tt(0,2)=s4vtable:/0(0,1Cool,0,32;;",128,0,0,0
        .stabs  "double:t(0,30)=r(0,17);8;0;",128,0,0,0
        .stabs  "float:t(0,31)=r(0,17);4;0;",128,0,0,0
        .stabs  "promoted_boolean:t(0,32)=@s32;-16;",128,0,0,0
        .stabs  "promoted_char:t(0,33)=@s32;-20;",128,0,0,0
        .stabs  "promoted_short:t(0,34)=r(0,34);-2147483648;2147483647;",128,0,0,0
        .stabs  "promoted_byte:t(0,35)=r(0,35);-2147483648;2147483647;",128,0,0,0
        .stabs  "boolean:t(0,36)=@s8;-16;",128,0,0,0
        .stabs  "char:t(0,37)=@s16;-20;",128,0,0,0
        .stabs  "void:t(0,10)",128,0,0,0
        .stabs  "unsigned long:t(0,3Cool=@s64;r(0,3Cool;0000000000000;01777777777777777777777;",128,0,0,0
        .stabs  "unsigned int:t(0,Cool",128,0,0,0
        .stabs  "unsigned short:t(0,6)",128,0,0,0
        .stabs  "unsigned byte:t(0,39)=@s8;r(0,39);0;255;",128,0,0,0
        .stabs  "long:t(0,40)=@s64;r(0,40);01000000000000000000000;0777777777777777777777;",128,0,0,0
        .stabs  "int:t(0,17)",128,0,0,0
        .stabs  "short:t(0,13)",128,0,0,0
        .stabs  "byte:t(0,29)",128,0,0,0
        .align 2
        .stabs  "_ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE:F(0,10)",36,0,4,__ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE
        .stabs  "args:p(0,41)=*(0,42)=xsjava.lang.String[]:",160,0,4,8
.globl __ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE
        .def    __ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE;   .scl    2;      .type   32;     .endef
__ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE:
.stabn 68,0,4,LM1-__ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE
LM1:
LFB2:
        pushl   %ebp
LCFI0:
        movl    %esp, %ebp
LCFI1:
        subl    $24, %esp
LCFI2:
.stabn 68,0,4,LM2-__ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE
LM2:
        cmpb    $14, __ZN4java4lang6System6class$E+86
        setge   %al
        movb    %al, -1(%ebp)
        movl    $__ZN3Foo6class$E, (%esp)
        call    __Jv_InitClass
.stabn 68,0,5,LM3-__ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE
LM3:
        movl    $0, -8(%ebp)
L2:
        cmpl    $9, -8(%ebp)
        jg      L7
.stabn 68,0,6,LM4-__ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE
LM4:
        cmpb    $0, -1(%ebp)
        jne     L5
        movl    $__ZN4java4lang6System6class$E, (%esp)
        call    __Jv_InitClass
L5:
        movb    $1, -1(%ebp)
        movl    __ZN4java4lang6System3outE, %edx
        movl    (%edx), %ecx
        addl    $120, %ecx
        movl    __CD_Foo+4, %eax
        movl    %eax, 4(%esp)
        movl    %edx, (%esp)
        movl    (%ecx), %eax
        call    *%eax
.stabn 68,0,5,LM5-__ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE
LM5:
        leal    -8(%ebp), %eax
        incl    (%eax)
        jmp     L2
L7:
.stabn 68,0,7,LM6-__ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE
LM6:
        leave
        ret
LFE2:
Lscope0:
        .stabs  "",36,0,0,Lscope0-__ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE
        .align 2
        .stabs  "_ZN3FooC1Ev:F(0,10)",36,0,1,__ZN3FooC1Ev
        .stabs  "this:p(0,43)=*(0,44)=xsFoo:",160,0,0,8
.globl __ZN3FooC1Ev
        .def    __ZN3FooC1Ev;   .scl    2;      .type   32;     .endef
__ZN3FooC1Ev:
.stabn 68,0,1,LM7-__ZN3FooC1Ev
LM7:
LFB3:
        pushl   %ebp
LCFI3:
        movl    %esp, %ebp
LCFI4:
        subl    $8, %esp
LCFI5:
.stabn 68,0,1,LM8-__ZN3FooC1Ev
LM8:
        movl    8(%ebp), %eax
        movl    %eax, (%esp)
        call    __ZN4java4lang6ObjectC1Ev
        leave
        ret
LFE3:
Lscope1:
        .stabs  "",36,0,0,Lscope1-__ZN3FooC1Ev
        .section .rdata,"dr"
        .align 2
__Utf1:
        .word   1465
        .word   4
        .ascii "main"
        .space 1
        .align 2
__Utf2:
        .word   59434
        .word   22
        .ascii "([Ljava.lang.String;)V"
        .space 1
        .align 2
__Utf3:
        .word   626
        .word   6
        .ascii "<init>"
        .space 1
        .align 2
__Utf4:
        .word   39797
        .word   3
        .ascii "()V"
        .space 1
        .data
        .align 32
__MT_Foo:
        .long   __Utf1
        .long   __Utf2
        .word   16393
        .word   -1
        .long   __ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE
        .long   0
        .long   __Utf3
        .long   __Utf4
        .word   16385
        .word   -1
        .long   __ZN3FooC1Ev
        .long   0
.globl __ZTVN3FooE
        .align 32
__ZTVN3FooE:
        .long   0
        .long   0
        .long   __ZN3Foo6class$E
        .long   4
        .long   __ZN4java4lang6Object8finalizeEv
        .long   __ZN4java4lang6Object8hashCodeEv
        .long   __ZN4java4lang6Object6equalsEPS1_
        .long   __ZN4java4lang6Object8toStringEv
        .long   __ZN4java4lang6Object5cloneEv
        .section .rdata,"dr"
        .align 2
__Utf5:
        .word   9073
        .word   14
        .ascii "Blah blah blah"
        .space 1
        .data
        .align 4
__CD_Foo:
        .long   0
        .long   __Utf5
__CT_Foo:
        .byte   0
        .byte   8
        .align 4
__catch_classes_Foo:
        .long   0
        .long   0
        .long   0
        .long   0
        .space 8
        .section .rdata,"dr"
        .align 2
__Utf6:
        .word   5286
        .word   3
        .ascii "Foo"
        .space 1
.globl __ZN3Foo6class$E
        .data
        .align 32
__ZN3Foo6class$E:
        .long   __ZTVN4java4lang5ClassE+8
        .long   0
        .long   __Utf6
        .word   1
        .space 2
        .long   __ZN4java4lang6Object6class$E
        .long   2
        .long   __CT_Foo
        .long   __CD_Foo
        .long   __MT_Foo
        .word   2
        .word   5
        .long   0
        .long   4
        .word   0
        .word   0
        .long   __ZTVN3FooE+8
        .long   0
        .long   0
        .long   0
        .long   0
        .long   __catch_classes_Foo
        .long   0
        .long   0
        .word   0
        .byte   0
        .space 1
        .long   0
        .word   0
        .space 2
        .long   0
        .long   0
        .long   0
        .long   0
        .long   0
        .long   0
        .stabs  "Foo:Tt(0,44)=s4!1,020,(0,2);main:Sad0,45)=f(0,10):_ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE;2A?;<init>:Sad0,46)=#(0,44),(0,10),(0,43),(0,10);:_ZN3FooC1Ev;2A.;;",128,0,1,0
        .def    __Jv_RegisterClass;     .scl    2;      .type   32;     .endef
        .text
        .align 2
        .stabs  "_GLOBAL__I__ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE:f(0,10)",36,0,0,__GLOBAL__I__ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE
        .def    __GLOBAL__I__ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE;        .scl    3;      .type   32;     .endef
__GLOBAL__I__ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE:
.stabn 68,0,0,LM9-__GLOBAL__I__ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE
LM9:
LFB4:
        pushl   %ebp
LCFI6:
        movl    %esp, %ebp
LCFI7:
        subl    $24, %esp
LCFI8:
        movl    $__ZN3Foo6class$E, (%esp)
        call    __Jv_RegisterClass
        leave
        ret
LFE4:
Lscope2:
        .stabs  "",36,0,0,Lscope2-__GLOBAL__I__ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE
        .section        .ctors,"w"
        .align 4
        .long   __GLOBAL__I__ZN3Foo4mainEP6JArrayIPN4java4lang6StringEE
        .text
        .stabs "",100,0,0,Letext
Letext:
        .def    __ZN4java4lang6Object5cloneEv;  .scl    3;      .type   32;     .endef
        .def    __ZN4java4lang6Object8toStringEv;       .scl    3;      .type   32;     .endef
        .def    __ZN4java4lang6Object6equalsEPS1_;      .scl    3;      .type   32;     .endef
        .def    __ZN4java4lang6Object8hashCodeEv;       .scl    3;      .type   32;     .endef
        .def    __ZN4java4lang6Object8finalizeEv;       .scl    3;      .type   32;     .endef
        .def    __ZN4java4lang6ObjectC1Ev;      .scl    3;      .type   32;     .endef
        .def    __Jv_InitClass; .scl    3;      .type   32;     .endef
    


uuuhhh ..... Very Happy
Post 08 Mar 2007, 11:19
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Yeah, there's a reason I said "ugh" Smile
Post 08 Mar 2007, 11:37
View user's profile Send private message Visit poster's website Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22
I'd think compiling java into native code wouldn't be too optimal *OF course it would be faster than JVM run code but* all of the packages and cann'd libraries java uses for linkedlists and what not probably aren't the most efficient when the are converted from java straight to native code.

When I was working on radixsort my initial implementation was in java then I ported it to assembly. (so I ended up with the fastest unsigned integer sorts in java and x86 asm).
Post 08 Mar 2007, 14:38
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Why "of course"?

While current implementations might not be "quite there yet", hotspot JITting can at least theoretically be done pretty well...
Post 08 Mar 2007, 15:47
View user's profile Send private message Visit poster's website Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22
When theory turns into practice I'll make an effort to retract my statement Razz

I was simply speaking from my own experience on the subject. I've coded things in java then directly ported them to assembler, what may be the fastest possible java implementation doesn't equal the fastest native code. BUT even if the assembler code had A LOT of room for improvement it would still run at least 3x faster than the java code.
In an automated system, this problem is pretty much dependent on the optimization logic of the JIT compiler.

To make sense of that rambling, I library coded natively will ALMOST ALWAYS IMHO run faster than a java library compiled into native code.

Say your taking java source files or even java bytecode and running it through a java 2 native code compiler. The src/bytecode won't have any compiler hints so it'd be very difficult for the compiler to optimize the code to it's best ability.

This is true even now with c/c++ with parallel execution, SIMD, or even loop unrolling.
Post 08 Mar 2007, 21:38
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
radoslavkirilov



Joined: 27 Dec 2006
Posts: 7
radoslavkirilov
Maybe a .java to .exe compiler will use a java to assembler procedures as a part of creating a real executable.
Post 10 Mar 2007, 11:24
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.