[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Static field constant initializers



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

JIMPLE:

public class Foo extends java.lang.Object
{
    static int i;

    public void <init>()
    {
        Foo r0;

        r0 := @this: Foo;
        specialinvoke r0.<java.lang.Object: void <init>()>();
        return;
    }

    static void <clinit>()
    {
        <Foo: int i> = 5;
        return;
    }
}


Ondrej


On Thu, Jan 02, 2003 at 12:10:42PM -0800, Archie Cobbs wrote:
> I must be missing something, please excuse my ignorance..
> 
> Does Soot have support for static field constant value initializers?
> I.e., what shows up as "ConstantValue" attributes associated with static
> fields in a classfile?
> 
> The jimple output doesn't seem to show them, and SootField doesn't seem to
> contain a method for accessing them... ?
> 
> Thanks,
> -Archie
> 
> __________________________________________________________________________
> Archie Cobbs     *     Packet Design     *     http://www.packetdesign.com