jakarta-bcel-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Corry <e...@arbat.com>
Subject Re: Constructor Instrumentation : super()
Date Wed, 18 Feb 2004 21:26:44 GMT
On Wed, Feb 18, 2004 at 10:28:52AM -0700, Andrew Huntwork wrote:
> There are a couple things you could do, one of which may be easy.
> First, you could make the instrumentation method you're calling static. 
>  I assume the verifier error you're getting is that you're trying to do 
> a virtual method call on an uninitialized object.  Calling a static 
> method  won't call a method on an object, so you'll be fine.

No, that doesn't work either.  It's a different problem to the one
you think.  See VM spec section 4.9.4:

   "a special type is created and pushed on the verifier's
    model of the operand stack as the result of the Java virtual
    machine instruction new. The special type indicates the
    instruction by which the class instance was created and
    the type of the uninitialized class instance created"

The only thing you can do with that object is call the <init>
(contstructor) method.  You can't pass it as a parameter to a
profiling routine.

It's quite an irritating restriction.

> Second, you could do some pretty complicated stack and control flow 
> analysis.  Here's something that's legal in bytecode but not in java:
> if(...)
>   super(foo);
> else
>   super(bar);

Are you sure that's legal?  The VM spec says:

    "If a constructor body does not begin with an explicit
    constructor invocation and the constructor being declared
    is not part of the primordial class Object, then the
    constructor body is implicitly assumed by the compiler to
    begin with a superclass constructor invocation "super();",
    an invocation of the constructor of the direct superclass
    that takes no arguments."

Does you example begin with an explicit constructor invocation?
I don't think it does.  Is it allowed to call two different
constructors for the same class on an object?

> and here's something else that's legal in bytecode
> void <init>(Object foo) {
> aload_0
> aload_1
> astore_0
> dup
> invokespecial <init>()V
> astore_1
> return
> }

Does anyone do that?

Erik Corry         I'd be a Libertarian, if they weren't all a
erik@arbat.com     bunch of tax-dodging professional whiners.   - B. Breathed.

To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org

View raw message