Re: [PATCH] Documentation/java.txt: add Java 7 support
From: Jonathan Callen
Date: Thu Apr 10 2014 - 04:25:27 EST
On 04/09/2014 12:21 PM, Randy Dunlap wrote:
> On 03/30/2014 08:47 PM, Jonathan Callen wrote:
>> The sample wrapper currently fails on some Java 7 .class files. This
>> updates the wrapper to properly handle those files.
>>
>> Signed-off-by: Jonathan Callen <jcallen@xxxxxxxxxx>
>
> Applied. Thanks.
>
> How would I test this?
>
I have attached a hand-crafted HelloWorld.class file that fails unless this patch is applied. This
.class file intentionally has extra entries in its constant pool that are not used by Java, but the
file does pass validation.
A complete disassembly of that file, showing the purpose of each byte, is attached as HelloWorld.jj.
>
>> ---
>> Documentation/java.txt | 8 ++++++++
>> 1 file changed, 8 insertions(+)
>>
>> diff --git a/Documentation/java.txt b/Documentation/java.txt
>> index e6a7232..4180205 100644
>> --- a/Documentation/java.txt
>> +++ b/Documentation/java.txt
>> @@ -188,6 +188,9 @@ shift
>> #define CP_METHODREF 10
>> #define CP_INTERFACEMETHODREF 11
>> #define CP_NAMEANDTYPE 12
>> +#define CP_METHODHANDLE 15
>> +#define CP_METHODTYPE 16
>> +#define CP_INVOKEDYNAMIC 18
>>
>> /* Define some commonly used error messages */
>>
>> @@ -242,14 +245,19 @@ void skip_constant(FILE *classfile, u_int16_t *cur)
>> break;
>> case CP_CLASS:
>> case CP_STRING:
>> + case CP_METHODTYPE:
>> seekerr = fseek(classfile, 2, SEEK_CUR);
>> break;
>> + case CP_METHODHANDLE:
>> + seekerr = fseek(classfile, 3, SEEK_CUR);
>> + break;
>> case CP_INTEGER:
>> case CP_FLOAT:
>> case CP_FIELDREF:
>> case CP_METHODREF:
>> case CP_INTERFACEMETHODREF:
>> case CP_NAMEANDTYPE:
>> + case CP_INVOKEDYNAMIC:
>> seekerr = fseek(classfile, 4, SEEK_CUR);
>> break;
>> case CP_LONG:
>>
>
>
Attachment:
HelloWorld.class
Description: application/java-vm
{
u4 magic = cafebabe;
u2 minor_version = 0000;
u2 major_version = 0033;
u2 constant_pool_count = 001c;
cp_info constant_pool[constant_pool_count-1] = {
{ // 0001 = Methodref java/lang/Object.<init>:()V
u1 tag = 0a; // CONSTANT_Methodref
u2 class_index = 0006; // Class java/lang/Object
u2 name_and_type_index = 000c; // NameAndType <init>:()V
},
{ // 0002 = Fieldref java/lang/System.out:Ljava/io/PrintStream;
u1 tag = 09; // CONSTANT_Fieldref
u2 class_index = 000d; // Class java/lang/System
u2 name_and_type_index = 000e; // NameAndType out:Ljava/io/PrintStream;
},
{ // 0003 = String "Hello, world!"
u1 tag = 08; // CONSTANT_String_info
u2 string_index = 000f; // Utf8 Hello, world!
},
{ // 0004 = Methodref java/io/PrintStream.println:(Ljava/lang/String;)V
u1 tag = 0a; // CONSTANT_Methodref
u2 class_index = 0010; // Class java/io/PrintStream
u2 name_and_type_index = 0011; // NameAndType println:(Ljava/lang/String;)V
},
{ // 0005 = Class HelloWorld
u1 tag = 07; // CONSTANT_Class_info
u2 name_index = 0012; // Utf8 HelloWorld
},
{ // 0006 = Class java/lang/Object
u1 tag = 07; // CONSTANT_Class_info
u2 name_index = 0013; // Utf8 java/lang/Object
},
{ // 0007 = Utf8 <init>
u1 tag = 01; // CONSTANT_Utf8
u2 length = 0006;
u1 bytes[] = {3c,69,6e,69,74,3e}; // <init>
},
{ // 0008 = Utf8 ()V
u1 tag = 01; // CONSTANT_Utf8
u2 length = 0003;
u1 bytes[] = {28,29,56}; // ()V
},
{ // 0009 = Utf8 Code
u1 tag = 01; // CONSTANT_Utf8
u2 length = 0004;
u1 bytes[] = {43,6f,64,65}; // Code
},
{ // 000a = Utf8 main
u1 tag = 01; // CONSTANT_Utf8
u2 length = 0004;
u1 bytes[] = {6d,61,69,6e}; // main
},
{ // 000b = Utf8 ([Ljava/lang/String;)V
u1 tag = 01; // CONSTANT_Utf8
u2 length = 0016;
u1 bytes[] = {28,5b,4c,6a,61,76,61,2f,6c,61,6e,67,2f,53,74,72,69,6e,67,3b,29,56}; // ([Ljava/lang/String;)V
},
{ // 000c = NameAndType <init>:()V
u1 tag = 0c; // CONSTANT_NameAndType
u2 name_index = 0007; // Utf8 <init>
u2 descriptor_index = 0008; // Utf8 ()V
},
{ // 000d = Class java/lang/System
u1 tag = 07; // CONSTANT_Class_info
u2 name_index = 0014; // Utf8 java/lang/System
},
{ // 000e = NameAndType out:Ljava/io/PrintStream;
u1 tag = 0c; // CONSTANT_NameAndType
u2 name_index = 0015; // Utf8 out
u2 descriptor_index = 0016; // Utf8 Ljava/io/PrintStream;
},
{ // 000f = Utf8 Hello, world!
u1 tag = 01; // CONSTANT_Utf8
u2 length = 000d;
u1 bytes[] = {48,65,6c,6c,6f,2c,20,77,6f,72,6c,64,21}; // Hello, world!
},
{ // 0010 = Class java/io/PrintStream
u1 tag = 07;
u2 name_index = 0017; // Utf8 java/io/PrintStream
},
{ // 0011 = NameAndType println:(Ljava/lang/String;)V
u1 tag = 0c; // CONSTANT_NameAndType
u2 name_index = 0018; // Utf8 println
u2 descriptor_index = 0019; // Utf8 (Ljava/lang/String;)V
},
{ // 0012 = Utf8 HelloWorld
u1 tag = 01; // CONSTANT_Utf8
u2 length = 000a;
u1 bytes[] = {48,65,6c,6c,6f,57,6f,72,6c,64}; // HelloWorld
},
{ // 0013 = Utf8 java/lang/Object
u1 tag = 01; // CONSTANT_Utf8
u2 length = 0010;
u1 bytes[] = {6a,61,76,61,2f,6c,61,6e,67,2f,4f,62,6a,65,63,74}; // java/lang/Object
},
{ // 0014 = Utf8 java/lang/System
u1 tag = 01; // CONSTANT_Utf8
u2 length = 0010;
u1 bytes[] = {6a,61,76,61,2f,6c,61,6e,67,2f,53,79,73,74,65,6d}; // java/lang/System
},
{ // 0015 = Utf8 out
u1 tag = 01; // CONSTANT_Utf8
u2 length = 0003;
u1 bytes[] = {6f,75,74}; // out
},
{ // 0016 = Utf8 Ljava/io/PrintStream;
u1 tag = 01; // CONSTANT_Utf8
u2 length = 0015;
u1 bytes[] = {4c,6a,61,76,61,2f,69,6f,2f,50,72,69,6e,74,53,74,72,65,61,6d,3b}; // Ljava/io/PrintStream;
},
{ // 0017 = Utf8 java/io/PrintStream
u1 tag = 01; // CONSTANT_Utf8
u2 length = 0013;
u1 bytes[] = {6a,61,76,61,2f,69,6f,2f,50,72,69,6e,74,53,74,72,65,61,6d}; // java/io/PrintStream
},
{ // 0018 = Utf8 println
u1 tag = 01; // CONSTANT_Utf8
u2 length = 0007;
u1 bytes[] = {70,72,69,6e,74,6c,6e}; // println
},
{ // 0019 = Utf8 (Ljava/lang/String;)V
u1 tag = 01; // CONSTANT_Utf8
u2 length = 0015;
u1 bytes[] = {28,4c,6a,61,76,61,2f,6c,61,6e,67,2f,53,74,72,69,6e,67,3b,29,56}; // (Ljava/lang/String;)V
},
{ // 001a = MethodHandle getStatic java/lang/System.out:Ljava/io/PrintStream;
u1 tag = 0f; // CONSTANT_MethodHandle
u1 reference_kind = 02; // REF_getStatic
u2 reference_index = 0002; // Field java/lang/System.out:Ljava/io/PrintStream;
},
{ // 001b = MethodType (Ljava/lang/String;)V
u1 tag = 10; // CONSTANT_MethodType
u2 descriptor_index = 0019;
},
};
u2 access_flags = 0021; // ACC_PUBLIC | ACC_SUPER
u2 this_class = 0005; // Class: HelloWorld
u2 super_class = 0006; // Class: java/lang/Object
u2 interfaces_count = 0000;
u2 interfaces[interfaces_count] = {};
u2 fields_count = 0000;
field_info fields[fields_count] = {};
u2 methods_count = 0002;
method_info methods[methods_count] = {
{
u2 access_flags = 0001; // ACC_PUBLIC
u2 name_index = 0007; // Utf8 <init>
u2 descriptor_index = 0008; // Utf8 ()V
u2 attributes_count = 0001;
attribute_info attributes[attributes_count] = {
{
u2 attribute_name_index = 0009; // Utf8 Code
u4 attribute_length = 00000011;
u2 max_stack = 0001;
u2 max_locals = 0001;
u4 code_length = 00000005;
u1 code[code_length] = {
2a, // aload_0
b7, 00,01, // invokespecial 0001 // Method java/lang/Object.<init>:()V
b1, // return
};
u2 exception_table_length = 0000;
exception_table_item exception_table[exception_table_length] = {};
u2 attributes_count = 0000;
attribute_info attributes[attributes_count] = {};
},
};
},
{
u2 access_flags = 0009; // ACC_PUBLIC | ACC_STATIC
u2 name_index = 000a; // Utf8 main
u2 descriptor_index = 000b; // Utf8 ([Ljava/lang/String;)V
u2 attributes_count = 0001;
attribute_info attributes[attributes_count] = {
{
u2 attribute_name_index = 0009; // Utf8 Code
u4 attribute_length = 00000015;
u2 max_stack = 0002;
u2 max_locals = 0001;
u4 code_length = 00000009;
u1 code[code_length] = {
b2, 00,02, // getstatic 0002 // Field java/lang/System.out:Ljava/io/PrintStream;
12, 03, // ldc 03 // String "Hello, world!"
b6, 00,04, // invokevirtual 0004 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
b1, // return
};
u2 exception_table_length = 0000;
exception_table_item exception_table[exception_table_length] = {};
u2 attributes_count = 0000;
attribute_info attributes[attributes_count] = {};
},
};
},
};
u2 attributes_count = 0000;
attribute_info attributes[attributes_count] = {};
}Attachment:
signature.asc
Description: OpenPGP digital signature