Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Difference in compilation between ECJ and Javac - BCEL fails to return class fileset
Difference in compilation between ECJ and Javac - BCEL fails to return class fileset [message #487617] Wed, 23 September 2009 18:41 Go to next message
Mohanraj Loganathan is currently offline Mohanraj LoganathanFriend
Messages: 3
Registered: September 2009
Junior Member
Consider the testcase E.java [1]. The constructor tries to print the class A (System.out.println(A.class) ; ). Class A intern has the references to class B, C and D. ANT tries to get the dependant classes for clas E using BCEL library.

When the class E compiled using ECJ, BCEL returns only E as dependent class. Where as javac returns A, B, C, D, E as the dependent classes for class E.

When analyzed further, i found that generated class file itself differing from ecj and javac.

javap output for ecj generated class file :


Max stack=3, Max locals=1
0: aload_0
1: invokespecial java.lang.Object.<init> ()V (11)
4: getstatic java.lang.System.out Ljava/io/PrintStream; (13)
7: getstatic E.class$0 Ljava/lang/Class; (19)
10: dup
11: ifnonnull #39
14: pop
15: ldc "A" (21)
17: invokestatic java.lang.Class.forName (Ljava/lang/String;)Ljava/lang/Class; (23)
20: dup
21: putstatic E.class$0 Ljava/lang/Class; (19)
24: goto #39
27: new <java.lang.NoClassDefFoundError> (29)
30: dup_x1
31: swap
32: invokevirtual java.lang.Throwable.getMessage ()Ljava/lang/String; (31)
35: invokespecial java.lang.NoClassDefFoundError.<init> (Ljava/lang/String;)V (37)
38: athrow
39: invokevirtual java.io.PrintStream.println (Ljava/lang/Object;)V (40)
42: return 


javap output for javac generated class file :
Code:
Max stack=2, Max locals=1
0: aload_0
1: invokespecial java.lang.Object.<init> ()V (1)
4: getstatic java.lang.System.out Ljava/io/PrintStream; (2)
7: ldc_w A (3)
10: invokevirtual java.io.PrintStream.println (Ljava/lang/Object;)V (4)
13: return 


Reason for BCEL failure to fetch the dependency?
1) ECJ generates the extra codes for the line System.out.prinln(A.class) line. Which is not necessary due to which BCEL is not able to get the Class reference of A from the class file. A is represented as a String and hence during the run time A gets loaded. Especially, look at the lines 15, 17 and 20.
2) Since A gets loaded via Class.forName, ANT/BCEL is not able to detect A as a dependency for class E.

where as ,

RI loads the reference of A in the byte-code itself, hence BCEL is able detect A as a dependency of class E

Why this difference in the bytecode in ECJ? is it a bug ? Any specific reason why ECJ expands the A.class fetching as reflection way.

Can i file a bug for the same?

References:

[1] E.java
Class E {
E() { System.out.println(A.class);}
}

[2] A.java
public class A extends B {
private D d = new D();
}
[3] B.java
public class B extends C { }

[4] D. java
public class D { }

[5] C.java
public class C { }

[6] BCEL Testcase :
Test program for BCEL which gets the dependency of a class --> http://illegalargumentexception.blogspot.com/2008/04/java-fi nding-binary-class-dependencies.html

[Updated on: Wed, 23 September 2009 18:57]

Report message to a moderator

Re: Difference in compilation between ECJ and Javac - BCEL fails to return class fileset [message #488311 is a reply to message #487617] Sun, 27 September 2009 23:28 Go to previous messageGo to next message
Walter Harley is currently offline Walter HarleyFriend
Messages: 847
Registered: July 2009
Senior Member
"Mohanraj Loganathan" <mohanraj.l@gmail.com> wrote in message
news:h9dq3u$ile$1@build.eclipse.org...
> Consider the testcase E.java [1]. The constructor tries to print the class
> A (System.out.println(A.class) ; ). Class A intern has the references to
> class B, C and D. ANT tries to get the dependant classes for clas E using
> BCEL library.
> When the class E compiled using ECJ, BCEL returns only E as dependent
> class. Where as javac returns A, B, C, D, E as the dependent classes for
> class E.
>
> When analyzed further, i found that generated class file itself differing
> from ecj and javac.

What command line options did you use when compiling? I wonder whether you
are implicitly targeting different JRE versions.
Re: Difference in compilation between ECJ and Javac - BCEL fails to return class fileset [message #488323 is a reply to message #488311] Mon, 28 September 2009 06:19 Go to previous messageGo to next message
Mohanraj Loganathan is currently offline Mohanraj LoganathanFriend
Messages: 3
Registered: September 2009
Junior Member

>What command line options did you use when compiling? I >wonder whether you
>are implicitly targeting different JRE versions.

I am using Harmony Java which intern uses eclipse batch compiler to generate javac. Harmony Java calls the eclipse compiler. Please find the wrapper class of harmony which intern calls ecj here

I am also trying with the following ecj command line :
java <classpathto ecj.jar> org.eclipse.jdt.internal.compiler.batch.Main *.java

Both generates the identical class files.

Thanks and Regards,
Mohan

Re: Difference in compilation between ECJ and Javac - BCEL fails to return class fileset [message #488375 is a reply to message #488323] Mon, 28 September 2009 13:13 Go to previous messageGo to next message
Olivier Thomann is currently offline Olivier ThomannFriend
Messages: 518
Registered: July 2009
Senior Member
Mohanraj Loganathan a écrit :
> Both generates the identical class files.
This is because you don't set the compiler compliance.
You must be using a javac 1.5 or above. This means that a reference to a
Class literal is compiled using the ldc bytecode.
You must set the compiler compliance to use a compliance 1.5 or above
and you must target a 1.5 VM or above.
Add:
-1.5 or -1.6 depending what VM you want to target.
This will set the compliance of the compiler to match the javac version
you are using and it should set the appropriate default target and
source version for the corresponding compliance.

Note that you would get the same result using a javac 1.4.
Hope this help,
--
Olivier
Re: Difference in compilation between ECJ and Javac - BCEL fails to return class fileset [message #488395 is a reply to message #488375] Mon, 28 September 2009 14:17 Go to previous message
Mohanraj Loganathan is currently offline Mohanraj LoganathanFriend
Messages: 3
Registered: September 2009
Junior Member
Hi Olivier,

Thank you so much . -1.5 /-1.6 resolves the issue.

Thanks and Regards,
Mohan
Previous Topic:Toolbar icon order
Next Topic:Galileo Update Not Working - Eclipse IDE for Java EE Developers 1.2.1.20090918-0703
Goto Forum:
  


Current Time: Fri Mar 29 00:19:05 GMT 2024

Powered by FUDForum. Page generated in 0.02866 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top