This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: --disable-assertions does not work when compiling from .class


Sergio Queiroz wrote:
> 
> I would like to use gcj to compile a .jar (of .class files) into an
> executable. I've noticed that the option --disable-assertions does not
> work in this case, the assertions are always enabled.
> 
> The simple class below show this behavior. When compiled from .java to
> object code (with --disable-assertions) the assertion message will not
> appear, as expected. However, when first compiled to .class (I use ecj)
> and then to object code (also using --disable-assertions), the assertion
> section will be executed.

While compiling a Java source file to object code, the code for
the assertions are generated (or not) by GCJ itself. While compiling
a Java class file however, the code for the assertions has already
been generated (or not) by whatever compiler produced the class file.

For example, Sun's JDK 1.5.0.3 produces the following bytecode for
a simple "main()" containing an assertion:
--------------------------- 8< ----------------------------------
public static void main(java.lang.String[]);
  Code:
   0:   getstatic       #2; //Field $assertionsDisabled:Z
   3:   ifne    20
   6:   invokestatic    #3; //Method amAsserting:()Z
   9:   ifne    20
   12:  new     #4; //class java/lang/AssertionError
   15:  dup
   16:  invokespecial   #5; //Method java/lang/AssertionError."<init>":()V
   19:  athrow
   20:  return
--------------------------- 8< ----------------------------------

To implement what you want, GCJ would have to recognise such
patterns in class files generated by itself, by javac, by ECJ,
by Jikes, etc. - needless to say, this is rather difficult
and does not provide much benefit.

Ranjit.

-- 
Ranjit Mathew      Email: rmathew AT gmail DOT com

Bangalore, INDIA.    Web: http://ranjitmathew.hostingzero.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]