Java class file verification
John Bergin
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:
Part-one:
"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.
Part-two:
"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."
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
e-mail is:
50: invokevirtual #314
53: goto 69
56: astore_3
57: new #316
60: dup
61: ldc_w #318
64: aload_3
65: invokespecial #321
68: athrow
LocalVariableTable:
Start Length Slot Name Signature
55 11 3 e Ljava/lang/Exception;
Kind regards,
John.
On 14/01/15 21:03, Christine Flood wrote:
> If you look at the documentation:
> https://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html
>
> "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.
>
> Christine
>
> ----- 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,
>>
>> http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.13
>>
>>
>>
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
>> case?
>>
>> Kind regards, John.
>>
More information about the discuss
mailing list