[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Static field constant initializers
Ondrej Lhotak wrote:
> javac translates constant values of static fields to static initializer
> methods with the name <clinit>, which are implicitly called when the
> class is first used. So, in the bytecode that Soot reads, the constant
> values are not directly available. For example, here is the Java source,
> Java bytecode, and Jimple for a simple class:
>
> JAVA SOURCE:
>
> public class Foo {
> static int i = 5;
> }
>
> JAVA BYTECODE:
>
> Compiled from Foo.java
> public class Foo extends java.lang.Object {
> static int i;
> public Foo();
> static {};
> }
>
> Method Foo()
> 0 aload_0
> 1 invokespecial #1 <Method java.lang.Object()>
> 4 return
>
> Method static {}
> 0 iconst_5
> 1 putstatic #2 <Field int i>
> 4 return
But aren't you making an assumption about the particular java
compiler being used?
I'm just reading from the JVM spec. It says a field can have a
"ConstantValue" attribute, which must be applied at class initialization
time before any static initializers are executed. So it seems a
different compiler could choose to use "ConstantValue" instead of
creating a "hidden" static initializer; if so, Soot would break if
such a compiler were used to generate the class files.
Also.. any word on when "LineNumber" attributes will be supported?
Thanks for a super-cool piece of software by the way :-)
-Archie
__________________________________________________________________________
Archie Cobbs * Packet Design * http://www.packetdesign.com