[Soot-list] Soot typing issue: local gets the null_type

Etienne Gagnon egagnon at sablevm.org
Wed Apr 5 22:33:55 EDT 2006


Hi Todd,

The type inference result, for local variable n0, is correct.  null_type
is a subtype of all reference types.  A problem happens when you want to
use this inferred type in a program, as it is a theoretical type.  But,
just think about the following verifiable bytecode written is pseudo-java:

{
  null_type n0;

  n0 = null;

  staticinvoke <Foo: void test1(String)>(n0);
  staticinvoke <Foo: void test1(Number)>(n0);
}

This code will be accepted by the verifier.  Yet, if you try giving n0
any other static type, one of the two invokes will reject it.

So, if you really want to use it, simply replace null_type by Object,
and add casts on every use, as in:

{
  Object n0;

  n0 = null;

  staticinvoke <Foo: void test1(String)>((String) n0);
  staticinvoke <Foo: void test1(Number)>((Number) n0);
}

Of course, if you regenerate bytecode, you there is no problem as local
variables have no declared type.  I designed the type inferer primarily
for a bytecode optimization framework, so null_type wasn't a problem in
such environment.  :-)

Have fun!

Etienne

Todd Wallentine wrote:
>     public static void main(java.lang.String[])
>     {
>         java.lang.String[] r0;
>         Foo $r1, r2;
>         null_type n0;
> 
>         r0 := @parameter0: java.lang.String[];
>         $r1 = new Foo;
>         specialinvoke $r1.<Foo: void <init>()>();
>         r2 = $r1;
>         n0 = null;
>         virtualinvoke n0.<Foo: void inc()>();
>         return;
>     }
> 
> To reiterate the question, is this a bug or my lack of understanding of
> what the type system can/should provide?

-- 
Etienne M. Gagnon, Ph.D.            http://www.info2.uqam.ca/~egagnon/
SableVM:                                       http://www.sablevm.org/
SableCC:                                       http://www.sablecc.org/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20060405/c2fc52e4/signature.bin


More information about the Soot-list mailing list