This discussion is archived
2 Replies Latest reply: Aug 21, 2010 12:24 PM by jschellSomeoneStoleMyAlias RSS

Compiler query

843810 Newbie
Currently Being Moderated
Hi All,

I have recently started working to understand the Java compiler . For this I started to understand the class file generated from a java file . I went through the VM spec available on Sun's website. The document said that the class file should have a format of


ClassFile {
     u4 magic;
     u2 minor_version;
     u2 major_version;
     u2 constant_pool_count;
     cp_info constant_pool[constant_pool_count-1];
     u2 access_flags;
     u2 this_class;
     u2 super_class;
     u2 interfaces_count;
     u2 interfaces[interfaces_count];
     u2 fields_count;
     field_info fields[fields_count];
     u2 methods_count;
     method_info methods[methods_count];
     u2 attributes_count;
     attribute_info attributes[attributes_count];
}


but when you look into a class file , i cannot see any such format followed . Other than that it contains a lot of ambiguous symbols like (Êþ) which i cant interpret . If suppose i need to write a decompiler I am not sure how to understand the class file .

Secondly when I went to java.c file in launcher directory of java source code , this file is said to be source for javac command line tool which is responsible for making a class file . I am unable to understand how to use this C file to understand the complete conversion of java file into a class file.

Any suggestions from your side would be very very helpful.

Thanks
Abhi
  • 1. Re: Compiler query
    608410 Newbie
    Currently Being Moderated
    Class files are binary. I suspect you are viewing it as text.

    javap command can be helpful to get an overview of the class file format.

    The launcher c source code files merely start up a VM and pass command line arguments to it (this is so that javac java jahah javap and friends are actually executables in the target operating system). The actual work of the compiler is done by code written in java. So find the javac source code and study that, rather than the launcher source code.

    Bruce

    Edited by: brucechapman on 18/08/2010 09:10
  • 2. Re: Compiler query
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    java_bee wrote:
    but when you look into a class file , i cannot see any such format followed . Other than that it contains a lot of ambiguous symbols like (Êþ) which i cant interpret . If suppose i need to write a decompiler I am not sure how to understand the class file .
    Learn hex (the hexadecimal numbering system) and get an editor/viewer that displays hex values.