23 */ |
23 */ |
24 |
24 |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
26 #include "classfile/symbolTable.hpp" |
26 #include "classfile/symbolTable.hpp" |
27 #include "interpreter/bytecodeStream.hpp" |
27 #include "interpreter/bytecodeStream.hpp" |
|
28 #include "oops/fieldStreams.hpp" |
28 #include "prims/jvmtiClassFileReconstituter.hpp" |
29 #include "prims/jvmtiClassFileReconstituter.hpp" |
29 #include "runtime/signature.hpp" |
30 #include "runtime/signature.hpp" |
30 #ifdef TARGET_ARCH_x86 |
31 #ifdef TARGET_ARCH_x86 |
31 # include "bytes_x86.hpp" |
32 # include "bytes_x86.hpp" |
32 #endif |
33 #endif |
50 // Write the field information portion of ClassFile structure |
51 // Write the field information portion of ClassFile structure |
51 // JVMSpec| u2 fields_count; |
52 // JVMSpec| u2 fields_count; |
52 // JVMSpec| field_info fields[fields_count]; |
53 // JVMSpec| field_info fields[fields_count]; |
53 void JvmtiClassFileReconstituter::write_field_infos() { |
54 void JvmtiClassFileReconstituter::write_field_infos() { |
54 HandleMark hm(thread()); |
55 HandleMark hm(thread()); |
55 typeArrayHandle fields(thread(), ikh()->fields()); |
|
56 int fields_length = fields->length(); |
|
57 int num_fields = fields_length / instanceKlass::next_offset; |
|
58 objArrayHandle fields_anno(thread(), ikh()->fields_annotations()); |
56 objArrayHandle fields_anno(thread(), ikh()->fields_annotations()); |
59 |
57 |
60 write_u2(num_fields); |
58 // Compute the real number of Java fields |
61 for (int index = 0; index < fields_length; index += instanceKlass::next_offset) { |
59 int java_fields = ikh()->java_fields_count(); |
62 AccessFlags access_flags; |
60 |
63 int flags = fields->ushort_at(index + instanceKlass::access_flags_offset); |
61 write_u2(java_fields * FieldInfo::field_slots); |
64 access_flags.set_flags(flags); |
62 for (JavaFieldStream fs(ikh()); !fs.done(); fs.next()) { |
65 int name_index = fields->ushort_at(index + instanceKlass::name_index_offset); |
63 AccessFlags access_flags = fs.access_flags(); |
66 int signature_index = fields->ushort_at(index + instanceKlass::signature_index_offset); |
64 int name_index = fs.name_index(); |
67 int initial_value_index = fields->ushort_at(index + instanceKlass::initval_index_offset); |
65 int signature_index = fs.signature_index(); |
|
66 int initial_value_index = fs.initval_index(); |
68 guarantee(name_index != 0 && signature_index != 0, "bad constant pool index for field"); |
67 guarantee(name_index != 0 && signature_index != 0, "bad constant pool index for field"); |
69 int offset = ikh()->offset_from_fields( index ); |
68 // int offset = ikh()->field_offset( index ); |
70 int generic_signature_index = |
69 int generic_signature_index = fs.generic_signature_index(); |
71 fields->ushort_at(index + instanceKlass::generic_signature_offset); |
|
72 typeArrayHandle anno(thread(), fields_anno.not_null() ? |
70 typeArrayHandle anno(thread(), fields_anno.not_null() ? |
73 (typeArrayOop)(fields_anno->obj_at(index / instanceKlass::next_offset)) : |
71 (typeArrayOop)(fields_anno->obj_at(fs.index())) : |
74 (typeArrayOop)NULL); |
72 (typeArrayOop)NULL); |
75 |
73 |
76 // JVMSpec| field_info { |
74 // JVMSpec| field_info { |
77 // JVMSpec| u2 access_flags; |
75 // JVMSpec| u2 access_flags; |
78 // JVMSpec| u2 name_index; |
76 // JVMSpec| u2 name_index; |
79 // JVMSpec| u2 descriptor_index; |
77 // JVMSpec| u2 descriptor_index; |
80 // JVMSpec| u2 attributes_count; |
78 // JVMSpec| u2 attributes_count; |
81 // JVMSpec| attribute_info attributes[attributes_count]; |
79 // JVMSpec| attribute_info attributes[attributes_count]; |
82 // JVMSpec| } |
80 // JVMSpec| } |
83 |
81 |
84 write_u2(flags & JVM_RECOGNIZED_FIELD_MODIFIERS); |
82 write_u2(access_flags.as_int() & JVM_RECOGNIZED_FIELD_MODIFIERS); |
85 write_u2(name_index); |
83 write_u2(name_index); |
86 write_u2(signature_index); |
84 write_u2(signature_index); |
87 int attr_count = 0; |
85 int attr_count = 0; |
88 if (initial_value_index != 0) { |
86 if (initial_value_index != 0) { |
89 ++attr_count; |
87 ++attr_count; |