Bytecode and objects

I am working on a bytecode toolkit project. Currently, when processing objects, the verifier most often causes an error. Therefore, I would like to get an idea of ​​the rules with objects (I read the JVMS, but could not find the answer I was looking for):

I use the NEW statement:

original bytecode

NEW <MyClass> DUP INVOKESPECIAL <MyClass.<init>> 

after instrumentation

 NEW <MyClass> DUP INVOKESTATIC <Profiler.handleNEW> DUP INVOKESPECIAL <MyClass.<init>> 

Note that I added a call to Profiler.handleNEW (), which takes as an argument a reference to an object (a newly created object).

The code part above throws a VerificationError. Although, if I do not add INVOKESTATIC (leaving only DUP), it is not. So what is the rule that I break? I can duplicate an uninitialized link, but I can not pass it as a parameter? I would be grateful for any help. Thanks you

+7
java bytecode verification instrumentation
source share
2 answers

The JVM verifier processes an object whose constructor must still be called, as if it had a special type of compilation time called "uninitialized".

So what happens from the point of view of the verifier is that you pass the wrong type of object as the first parameter to Profiler.handleNEW() , because "uninitialized" is not considered a subclass of Object (so to speak).

The relevant part of the JVM specification regarding how "uninitialization" is defined is here .

+4
source share

Until the constructor java.lang.Object is called (technically, it probably usually exits), the link type is "uninitialized". Thus, you cannot do much with a link before invoking the constructor on it. This is also true in the constructors of the object in question.

+1
source share

All Articles