On Wed, Feb 18, 2004 at 02:59:24PM -0700, Andrew Huntwork wrote:
> Depending on what
> kind of instrumentation you want to do, this is sufficient. For
> example, if you just want to know a complete call trace, you can insert
> the bytecode equivalent of the following at every method entry and exit:
>
> log("entering/leaving foo.bar()V");
Except that you can't do that right at entry of the constructor
(before the call to the superclass constructor). Try it. Or
look at the code in the Helloifier:
http://cvs.sourceforge.net/viewcvs.py/bcel/BCEL/helloify.java?view=markup
Look for "init". The code is there for a reason, and it's not
sufficient.
> >>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?
>
> As I say, not legal in Java (which your passage refers to), but totally
> legal in bytecode.
My passage refers to the VM spec, so it's about byte code, not
about the Java language.
> The attached class has this <init>:
>
> Method test()
> 0 iconst_0
> 1 ifeq 11
> 4 aload_0
> 5 invokespecial #10 <Method java.lang.Object()>
> 8 goto 15
> 11 aload_0
> 12 invokespecial #10 <Method java.lang.Object()>
> 15 return
>
> it verifies just fine
OK. I never would have guessed from the spec.
> >Does anyone do that?
>
> [No concrete examples mentioned]
>
> In general, you'd be surprised how many sources of bytecode there are
> besides javac, so you'll eventually suffer if you concentrate too much
> on handling just that kind of code.
That depends entirely on what you are trying to do.
--
Erik Corry I'd be a Libertarian, if they weren't all a
[EMAIL PROTECTED] bunch of tax-dodging professional whiners. - B. Breathed.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]