Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Machine > javac generates...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 774 of 803
Post > Topic >>

javac generates bytecode using an inner class but does not generate the code for that class?

by Eric Bodden <eric.bodden@[EMAIL PROTECTED] > Jun 2, 2007 at 06:51 PM

This here came up on the Soot mailing list... (see
http://www.sable.mcgill.ca/pipermail/soot-list/2007-June/001238.html).
It would be great if you could comment on the problem if you know of
anything that could be helpful.

I have a problem with inner classes, in particular the way javac
generates them. Assume you have the following small Java source
example:

========
public class SootProblem {
    public SootProblem()
    {
        if (false) {
            Runnable myRunnable =
                    new Runnable() {
                        public void run() {}
                    };
        }
        new SootProblemInner();
    }

    private class SootProblemInner {
        int foo;
    }
}
========

The bytecode javac generates for the inner class looks as follows:

========
{
int foo;
final SootProblem this$0;

private SootProblem$SootProblemInner(SootProblem);
  Code:
   Stack=2, Locals=2, Args_size=2
   0:   aload_0
   1:   aload_1
   2:   putfield        #2; //Field this$0:LSootProblem;
   5:   aload_0
   6:   invokespecial   #3; //Method java/lang/Object."<init>":()V
   9:   return
  LineNumberTable:
   line 18: 0

SootProblem$SootProblemInner(SootProblem, SootProblem$1);
  Code:
   Stack=2, Locals=3, Args_size=3
   0:   aload_0
   1:   aload_1
   2:   invokespecial   #1; //Method "<init>":(LSootProblem;)V
   5:   return
  LineNumberTable:
   line 18: 0
}
========

So far so good. Apparently it declares a new anonymous inner class
SootProblem$1 that is added to the constructor's signature. I have no
clue why but it exists. Fair enough. Next strange thing: At the actual
constructor call in SootProblem, this second parameter is set to null.
So why generate the class in the first place, when it's not used?
Odd...

HOWEVER, the actual real problem: No class file is ever being
generated for SootProblem$1. Hence, I don't see how the class can have
any definition at all. Yet, when you add a main-method to the class,
instantiating SootProblem, the code loads and runs just fine. How can
this possibly work? I am confused.

(The problem for us is that we have a static program analysis tool,
Soot, which expects to be able to find a definition for SootProblem$1,
sinc eit is referenced.)

Eric




 3 Posts in Topic:
javac generates bytecode using an inner class but does not gener
Eric Bodden <eric.bodd  2007-06-02 18:51:56 
Re: javac generates bytecode using an inner class but does not g
Tom Hawtin <usenet@[EM  2007-06-02 20:48:37 
Re: javac generates bytecode using an inner class but does not g
Eric Bodden <eric.bodd  2007-06-02 21:47:54 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue May 13 23:25:37 CDT 2008.