Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bytecode and Objects

I am working on a bytecode instrumentation project. Currently when handling objects, the verifier throws an error most of the time. So I would like to get things clear concerning rules with objects (I read the JVMS but couldn't find the answer I was looking for):

I am instrumenting the NEW instruction:

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 argument an object reference (the newly created object).

The piece of code above throws a VerificationError. While if I don't add the INVOKESTATIC (leaving only the DUP), it doesn't. So what is the rule that I'm violating? I can duplicate an uninitialized reference but I can't pass it as parameter? I would appreciate any help. Thank you

like image 373
H-H Avatar asked May 07 '10 18:05

H-H


People also ask

Is byte code same as object code?

Bytecode is computer object code that an interpreter converts into binary machine code so it can be read by a computer's hardware processor. The interpreter is typically implemented as a virtual machine (VM) that translates the bytecode for the target platform.

Is bytecode and object code same in Java?

Machine code, object code and byte code are the same thing. They are all the lowest level of “normal program” code to be executed by a machine.

What do you mean by bytecode?

Byte code is the intermediate code compiled and executed by a virtual machine (VM). Byte code can be used unchanged on any platform on which the VM operates.

What is object code and machine code?

Whereas machine code is binary code that can be executed directly by the CPU, object code has the jumps partially parametrized so that a linker can fill them in. An assembler is used to convert assembly code into machine code (object code). A linker links several object (and library) files to generate an executable.


1 Answers

The JVM verifier treats an object whose constructor has yet to be called as if it had a special compile-time type called "uninitialized".

So what's happening from the verifier's point of view is that you are passing 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 spec regarding how "uninitialized" is defined is here.

like image 104
Archie Avatar answered Sep 29 '22 12:09

Archie