Java class file verification
Christine Flood
chf at redhat.com
Wed Jan 14 21:03:18 UTC 2015
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