Java class file verification
john.bergin at gmail.com
Wed Jan 14 23:01:47 UTC 2015
Hi Christine. Many thanks for your reply.
I had a read of the sentence you linked to for the Java 5/6 Virtual
Machine Specification and I parse that sentence in two parts:
"The given local variable must have a value at indices into the code
array in the interval [start_pc, start_pc + length), that is, between
start_pc inclusive and start_pc + length exclusive."
To me this means a variable must hold a value in the defined interval.
"The value of start_pc must be a valid index into the code array of
this Code attribute and must be the index of the opcode of an
To me this means the start_pc value must be the index of an opcode --
the opcode's starting code-array offset only, and not an interval for
the size of the opcode.
But maybe I am interpreting the specification incorrectly.
Anyway, the offending byte-code that prompted me to intially send this
50: invokevirtual #314
53: goto 69
57: new #316
61: ldc_w #318
65: invokespecial #321
Start Length Slot Name Signature
55 11 3 e Ljava/lang/Exception;
On 14/01/15 21:03, Christine Flood wrote:
> If you look at the documentation:
> "start_pc, length The given local variable must have a value at
> indices into the code array in the interval [start_pc,
> start_pc+length], that is, between start_pc and start_pc+length
> inclusive. The value of start_pc must be a valid index into the
> code array of this Code attribute and must be the index of the
> opcode of an instruction. Either the value of start_pc+length must
> be a valid index into the code array of this Code attribute and be
> the index of the opcode of an instruction, or it must be the first
> index beyond the end of that code array."
> The first index beyond the end of the code array is acceptable.
> ----- Original Message -----
>> From: "John Bergin" <john.bergin at gmail.com> To:
>> discuss at openjdk.java.net Sent: Wednesday, January 14, 2015
>> 3:35:48 PM Subject: Java class file verification
>> Hi all.
>> I have a query regarding Java class file verification in
>> particular verification of the LocalVariableTable attribute
>> defined by the Java Virtual Machine 7 specification here,
The specification states that "The value of start_pc must be a valid
>> index into the code array of this Code attribute and must be the
>> index of the opcode of an instruction." And in the example below
>> the start_pc for args is 0 and for s it is 3 and both these
>> indexes are valid code array offsets.
>> public static void main(java.lang.String); flags: ACC_PUBLIC,
>> ACC_STATIC Code: stack=1, locals=2, args_size=1 0: ldc
>> #2 // String A string 2: astore_1 3: return
>> LineNumberTable: line 3: 0 line 4: 3 LocalVariableTable: Start
>> Length Slot Name Signature 0 4 0 args
>> [Ljava/lang/String; 3 1 1 s Ljava/lang/String;
>> My question is: a program I'm helping to develop is dynamically
>> generating Java class files where the start_pc indexes are NOT
>> valid indexes into the code array (in fact they're off by one)
>> and OpenJDK is not rejecting the class via a
>> ClassFormatException. Has anyone got any idea why this is the
>> Kind regards, John.
More information about the discuss