23 */ |
23 */ |
24 |
24 |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
26 #include "classfile/classFileParser.hpp" |
26 #include "classfile/classFileParser.hpp" |
27 #include "classfile/classLoader.hpp" |
27 #include "classfile/classLoader.hpp" |
|
28 #include "classfile/classLoaderData.hpp" |
|
29 #include "classfile/classLoaderData.inline.hpp" |
28 #include "classfile/javaClasses.hpp" |
30 #include "classfile/javaClasses.hpp" |
29 #include "classfile/symbolTable.hpp" |
31 #include "classfile/symbolTable.hpp" |
30 #include "classfile/systemDictionary.hpp" |
32 #include "classfile/systemDictionary.hpp" |
31 #include "classfile/verificationType.hpp" |
33 #include "classfile/verificationType.hpp" |
32 #include "classfile/verifier.hpp" |
34 #include "classfile/verifier.hpp" |
33 #include "classfile/vmSymbols.hpp" |
35 #include "classfile/vmSymbols.hpp" |
34 #include "memory/allocation.hpp" |
36 #include "memory/allocation.hpp" |
35 #include "memory/gcLocker.hpp" |
37 #include "memory/gcLocker.hpp" |
|
38 #include "memory/metadataFactory.hpp" |
36 #include "memory/oopFactory.hpp" |
39 #include "memory/oopFactory.hpp" |
37 #include "memory/universe.inline.hpp" |
40 #include "memory/universe.inline.hpp" |
38 #include "oops/constantPoolOop.hpp" |
41 #include "oops/constantPool.hpp" |
39 #include "oops/fieldStreams.hpp" |
42 #include "oops/fieldStreams.hpp" |
40 #include "oops/instanceKlass.hpp" |
43 #include "oops/instanceKlass.hpp" |
41 #include "oops/instanceMirrorKlass.hpp" |
44 #include "oops/instanceMirrorKlass.hpp" |
42 #include "oops/klass.inline.hpp" |
45 #include "oops/klass.inline.hpp" |
43 #include "oops/klassOop.hpp" |
|
44 #include "oops/klassVtable.hpp" |
46 #include "oops/klassVtable.hpp" |
45 #include "oops/methodOop.hpp" |
47 #include "oops/method.hpp" |
46 #include "oops/symbol.hpp" |
48 #include "oops/symbol.hpp" |
|
49 #include "prims/jvm.h" |
47 #include "prims/jvmtiExport.hpp" |
50 #include "prims/jvmtiExport.hpp" |
48 #include "prims/jvmtiThreadState.hpp" |
51 #include "prims/jvmtiThreadState.hpp" |
49 #include "runtime/javaCalls.hpp" |
52 #include "runtime/javaCalls.hpp" |
50 #include "runtime/perfData.hpp" |
53 #include "runtime/perfData.hpp" |
51 #include "runtime/reflection.hpp" |
54 #include "runtime/reflection.hpp" |
52 #include "runtime/signature.hpp" |
55 #include "runtime/signature.hpp" |
53 #include "runtime/timer.hpp" |
56 #include "runtime/timer.hpp" |
54 #include "services/classLoadingService.hpp" |
57 #include "services/classLoadingService.hpp" |
55 #include "services/threadService.hpp" |
58 #include "services/threadService.hpp" |
|
59 #include "utilities/array.hpp" |
56 |
60 |
57 // We generally try to create the oops directly when parsing, rather than |
61 // We generally try to create the oops directly when parsing, rather than |
58 // allocating temporary data structures and copying the bytes twice. A |
62 // allocating temporary data structures and copying the bytes twice. A |
59 // temporary area is only needed when parsing utf8 entries in the constant |
63 // temporary area is only needed when parsing utf8 entries in the constant |
60 // pool and when parsing line number tables. |
64 // pool and when parsing line number tables. |
323 return cp->symbol_at(index); |
328 return cp->symbol_at(index); |
324 else |
329 else |
325 return NULL; |
330 return NULL; |
326 } |
331 } |
327 |
332 |
328 constantPoolHandle ClassFileParser::parse_constant_pool(Handle class_loader, TRAPS) { |
333 constantPoolHandle ClassFileParser::parse_constant_pool(ClassLoaderData* loader_data, TRAPS) { |
329 ClassFileStream* cfs = stream(); |
334 ClassFileStream* cfs = stream(); |
330 constantPoolHandle nullHandle; |
335 constantPoolHandle nullHandle; |
331 |
336 |
332 cfs->guarantee_more(3, CHECK_(nullHandle)); // length, first cp tag |
337 cfs->guarantee_more(3, CHECK_(nullHandle)); // length, first cp tag |
333 u2 length = cfs->get_u2_fast(); |
338 u2 length = cfs->get_u2_fast(); |
334 guarantee_property( |
339 guarantee_property( |
335 length >= 1, "Illegal constant pool size %u in class file %s", |
340 length >= 1, "Illegal constant pool size %u in class file %s", |
336 length, CHECK_(nullHandle)); |
341 length, CHECK_(nullHandle)); |
337 constantPoolOop constant_pool = |
342 ConstantPool* constant_pool = |
338 oopFactory::new_constantPool(length, |
343 ConstantPool::allocate(loader_data, |
339 oopDesc::IsSafeConc, |
344 length, |
340 CHECK_(nullHandle)); |
345 CHECK_(nullHandle)); |
341 constantPoolHandle cp (THREAD, constant_pool); |
346 constantPoolHandle cp (THREAD, constant_pool); |
342 |
347 |
343 cp->set_partially_loaded(); // Enables heap verify to work on partial constantPoolOops |
|
344 ConstantPoolCleaner cp_in_error(cp); // set constant pool to be cleaned up. |
348 ConstantPoolCleaner cp_in_error(cp); // set constant pool to be cleaned up. |
345 |
349 |
346 // parsing constant pool entries |
350 // parsing constant pool entries |
347 parse_constant_pool_entries(class_loader, cp, length, CHECK_(nullHandle)); |
351 parse_constant_pool_entries(loader_data, cp, length, CHECK_(nullHandle)); |
348 |
352 |
349 int index = 1; // declared outside of loops for portability |
353 int index = 1; // declared outside of loops for portability |
350 |
354 |
351 // first verification pass - validate cross references and fixup class and string constants |
355 // first verification pass - validate cross references and fixup class and string constants |
352 for (index = 1; index < length; index++) { // Index 0 is unused |
356 for (index = 1; index < length; index++) { // Index 0 is unused |
669 |
664 |
670 |
665 |
671 void ClassFileParser::patch_constant_pool(constantPoolHandle cp, int index, Handle patch, TRAPS) { |
666 void ClassFileParser::patch_constant_pool(constantPoolHandle cp, int index, Handle patch, TRAPS) { |
672 assert(EnableInvokeDynamic, ""); |
667 assert(EnableInvokeDynamic, ""); |
673 BasicType patch_type = T_VOID; |
668 BasicType patch_type = T_VOID; |
|
669 |
674 switch (cp->tag_at(index).value()) { |
670 switch (cp->tag_at(index).value()) { |
675 |
671 |
676 case JVM_CONSTANT_UnresolvedClass : |
672 case JVM_CONSTANT_UnresolvedClass : |
677 // Patching a class means pre-resolving it. |
673 // Patching a class means pre-resolving it. |
678 // The name in the constant pool is ignored. |
674 // The name in the constant pool is ignored. |
679 if (java_lang_Class::is_instance(patch())) { |
675 if (java_lang_Class::is_instance(patch())) { |
680 guarantee_property(!java_lang_Class::is_primitive(patch()), |
676 guarantee_property(!java_lang_Class::is_primitive(patch()), |
681 "Illegal class patch at %d in class file %s", |
677 "Illegal class patch at %d in class file %s", |
682 index, CHECK); |
678 index, CHECK); |
683 cp->klass_at_put(index, java_lang_Class::as_klassOop(patch())); |
679 cp->klass_at_put(index, java_lang_Class::as_Klass(patch())); |
684 } else { |
680 } else { |
685 guarantee_property(java_lang_String::is_instance(patch()), |
681 guarantee_property(java_lang_String::is_instance(patch()), |
686 "Illegal class patch at %d in class file %s", |
682 "Illegal class patch at %d in class file %s", |
687 index, CHECK); |
683 index, CHECK); |
688 Symbol* name = java_lang_String::as_symbol(patch(), CHECK); |
684 Symbol* name = java_lang_String::as_symbol(patch(), CHECK); |
689 cp->unresolved_klass_at_put(index, name); |
685 cp->unresolved_klass_at_put(index, name); |
690 } |
686 } |
691 break; |
687 break; |
692 |
688 |
693 case JVM_CONSTANT_UnresolvedString : |
689 case JVM_CONSTANT_String : |
694 // Patching a string means pre-resolving it. |
690 // skip this patch and don't clear it. Needs the oop array for resolved |
695 // The spelling in the constant pool is ignored. |
691 // references to be created first. |
696 // The constant reference may be any object whatever. |
692 return; |
697 // If it is not a real interned string, the constant is referred |
|
698 // to as a "pseudo-string", and must be presented to the CP |
|
699 // explicitly, because it may require scavenging. |
|
700 cp->pseudo_string_at_put(index, patch()); |
|
701 break; |
|
702 |
693 |
703 case JVM_CONSTANT_Integer : patch_type = T_INT; goto patch_prim; |
694 case JVM_CONSTANT_Integer : patch_type = T_INT; goto patch_prim; |
704 case JVM_CONSTANT_Float : patch_type = T_FLOAT; goto patch_prim; |
695 case JVM_CONSTANT_Float : patch_type = T_FLOAT; goto patch_prim; |
705 case JVM_CONSTANT_Long : patch_type = T_LONG; goto patch_prim; |
696 case JVM_CONSTANT_Long : patch_type = T_LONG; goto patch_prim; |
706 case JVM_CONSTANT_Double : patch_type = T_DOUBLE; goto patch_prim; |
697 case JVM_CONSTANT_Double : patch_type = T_DOUBLE; goto patch_prim; |
787 |
778 |
788 return true; |
779 return true; |
789 } |
780 } |
790 |
781 |
791 |
782 |
792 objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp, |
783 Array<Klass*>* ClassFileParser::parse_interfaces(constantPoolHandle cp, |
793 int length, |
784 int length, |
794 Handle class_loader, |
785 ClassLoaderData* loader_data, |
795 Handle protection_domain, |
786 Handle protection_domain, |
796 Symbol* class_name, |
787 Symbol* class_name, |
797 TRAPS) { |
788 TRAPS) { |
798 ClassFileStream* cfs = stream(); |
789 ClassFileStream* cfs = stream(); |
799 assert(length > 0, "only called for length>0"); |
790 assert(length > 0, "only called for length>0"); |
800 objArrayHandle nullHandle; |
791 // FIXME: Leak at later OOM. |
801 objArrayOop interface_oop = oopFactory::new_system_objArray(length, CHECK_(nullHandle)); |
792 Array<Klass*>* interfaces = MetadataFactory::new_array<Klass*>(loader_data, length, NULL, CHECK_NULL); |
802 objArrayHandle interfaces (THREAD, interface_oop); |
|
803 |
793 |
804 int index; |
794 int index; |
805 for (index = 0; index < length; index++) { |
795 for (index = 0; index < length; index++) { |
806 u2 interface_index = cfs->get_u2(CHECK_(nullHandle)); |
796 u2 interface_index = cfs->get_u2(CHECK_NULL); |
807 KlassHandle interf; |
797 KlassHandle interf; |
808 check_property( |
798 check_property( |
809 valid_cp_range(interface_index, cp->length()) && |
799 valid_cp_range(interface_index, cp->length()) && |
810 is_klass_reference(cp, interface_index), |
800 is_klass_reference(cp, interface_index), |
811 "Interface name has bad constant pool index %u in class file %s", |
801 "Interface name has bad constant pool index %u in class file %s", |
812 interface_index, CHECK_(nullHandle)); |
802 interface_index, CHECK_NULL); |
813 if (cp->tag_at(interface_index).is_klass()) { |
803 if (cp->tag_at(interface_index).is_klass()) { |
814 interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index)); |
804 interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index)); |
815 } else { |
805 } else { |
816 Symbol* unresolved_klass = cp->klass_name_at(interface_index); |
806 Symbol* unresolved_klass = cp->klass_name_at(interface_index); |
817 |
807 |
818 // Don't need to check legal name because it's checked when parsing constant pool. |
808 // Don't need to check legal name because it's checked when parsing constant pool. |
819 // But need to make sure it's not an array type. |
809 // But need to make sure it's not an array type. |
820 guarantee_property(unresolved_klass->byte_at(0) != JVM_SIGNATURE_ARRAY, |
810 guarantee_property(unresolved_klass->byte_at(0) != JVM_SIGNATURE_ARRAY, |
821 "Bad interface name in class file %s", CHECK_(nullHandle)); |
811 "Bad interface name in class file %s", CHECK_NULL); |
|
812 Handle class_loader(THREAD, loader_data->class_loader()); |
822 |
813 |
823 // Call resolve_super so classcircularity is checked |
814 // Call resolve_super so classcircularity is checked |
824 klassOop k = SystemDictionary::resolve_super_or_fail(class_name, |
815 Klass* k = SystemDictionary::resolve_super_or_fail(class_name, |
825 unresolved_klass, class_loader, protection_domain, |
816 unresolved_klass, class_loader, protection_domain, |
826 false, CHECK_(nullHandle)); |
817 false, CHECK_NULL); |
827 interf = KlassHandle(THREAD, k); |
818 interf = KlassHandle(THREAD, k); |
828 |
819 |
829 if (LinkWellKnownClasses) // my super type is well known to me |
820 if (LinkWellKnownClasses) // my super type is well known to me |
830 cp->klass_at_put(interface_index, interf()); // eagerly resolve |
821 cp->klass_at_put(interface_index, interf()); // eagerly resolve |
831 } |
822 } |
832 |
823 |
833 if (!Klass::cast(interf())->is_interface()) { |
824 if (!Klass::cast(interf())->is_interface()) { |
834 THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(), "Implementing class", nullHandle); |
825 THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(), "Implementing class", NULL); |
835 } |
826 } |
836 interfaces->obj_at_put(index, interf()); |
827 interfaces->at_put(index, interf()); |
837 } |
828 } |
838 |
829 |
839 if (!_need_verify || length <= 1) { |
830 if (!_need_verify || length <= 1) { |
840 return interfaces; |
831 return interfaces; |
841 } |
832 } |
1114 // array and any unused slots will be discarded. |
1107 // array and any unused slots will be discarded. |
1115 ResourceMark rm(THREAD); |
1108 ResourceMark rm(THREAD); |
1116 u2* fa = NEW_RESOURCE_ARRAY_IN_THREAD( |
1109 u2* fa = NEW_RESOURCE_ARRAY_IN_THREAD( |
1117 THREAD, u2, total_fields * (FieldInfo::field_slots + 1)); |
1110 THREAD, u2, total_fields * (FieldInfo::field_slots + 1)); |
1118 |
1111 |
1119 typeArrayHandle field_annotations; |
1112 AnnotationArray* field_annotations = NULL; |
1120 // The generic signature slots start after all other fields' data. |
1113 // The generic signature slots start after all other fields' data. |
1121 int generic_signature_slot = total_fields * FieldInfo::field_slots; |
1114 int generic_signature_slot = total_fields * FieldInfo::field_slots; |
1122 int num_generic_signature = 0; |
1115 int num_generic_signature = 0; |
1123 for (int n = 0; n < length; n++) { |
1116 for (int n = 0; n < length; n++) { |
1124 cfs->guarantee_more(8, CHECK_(nullHandle)); // access_flags, name_index, descriptor_index, attributes_count |
1117 cfs->guarantee_more(8, CHECK_NULL); // access_flags, name_index, descriptor_index, attributes_count |
1125 |
1118 |
1126 AccessFlags access_flags; |
1119 AccessFlags access_flags; |
1127 jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_FIELD_MODIFIERS; |
1120 jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_FIELD_MODIFIERS; |
1128 verify_legal_field_modifiers(flags, is_interface, CHECK_(nullHandle)); |
1121 verify_legal_field_modifiers(flags, is_interface, CHECK_NULL); |
1129 access_flags.set_flags(flags); |
1122 access_flags.set_flags(flags); |
1130 |
1123 |
1131 u2 name_index = cfs->get_u2_fast(); |
1124 u2 name_index = cfs->get_u2_fast(); |
1132 int cp_size = cp->length(); |
1125 int cp_size = cp->length(); |
1133 check_property( |
1126 check_property( |
1134 valid_cp_range(name_index, cp_size) && cp->tag_at(name_index).is_utf8(), |
1127 valid_cp_range(name_index, cp_size) && cp->tag_at(name_index).is_utf8(), |
1135 "Invalid constant pool index %u for field name in class file %s", |
1128 "Invalid constant pool index %u for field name in class file %s", |
1136 name_index, CHECK_(nullHandle)); |
1129 name_index, CHECK_NULL); |
1137 Symbol* name = cp->symbol_at(name_index); |
1130 Symbol* name = cp->symbol_at(name_index); |
1138 verify_legal_field_name(name, CHECK_(nullHandle)); |
1131 verify_legal_field_name(name, CHECK_NULL); |
1139 |
1132 |
1140 u2 signature_index = cfs->get_u2_fast(); |
1133 u2 signature_index = cfs->get_u2_fast(); |
1141 check_property( |
1134 check_property( |
1142 valid_cp_range(signature_index, cp_size) && |
1135 valid_cp_range(signature_index, cp_size) && |
1143 cp->tag_at(signature_index).is_utf8(), |
1136 cp->tag_at(signature_index).is_utf8(), |
1144 "Invalid constant pool index %u for field signature in class file %s", |
1137 "Invalid constant pool index %u for field signature in class file %s", |
1145 signature_index, CHECK_(nullHandle)); |
1138 signature_index, CHECK_NULL); |
1146 Symbol* sig = cp->symbol_at(signature_index); |
1139 Symbol* sig = cp->symbol_at(signature_index); |
1147 verify_legal_field_signature(name, sig, CHECK_(nullHandle)); |
1140 verify_legal_field_signature(name, sig, CHECK_NULL); |
1148 |
1141 |
1149 u2 constantvalue_index = 0; |
1142 u2 constantvalue_index = 0; |
1150 bool is_synthetic = false; |
1143 bool is_synthetic = false; |
1151 u2 generic_signature_index = 0; |
1144 u2 generic_signature_index = 0; |
1152 bool is_static = access_flags.is_static(); |
1145 bool is_static = access_flags.is_static(); |
1153 FieldAnnotationCollector parsed_annotations; |
1146 FieldAnnotationCollector parsed_annotations; |
1154 |
1147 |
1155 u2 attributes_count = cfs->get_u2_fast(); |
1148 u2 attributes_count = cfs->get_u2_fast(); |
1156 if (attributes_count > 0) { |
1149 if (attributes_count > 0) { |
1157 parse_field_attributes(cp, attributes_count, is_static, signature_index, |
1150 parse_field_attributes(loader_data, |
|
1151 cp, attributes_count, is_static, signature_index, |
1158 &constantvalue_index, &is_synthetic, |
1152 &constantvalue_index, &is_synthetic, |
1159 &generic_signature_index, &field_annotations, |
1153 &generic_signature_index, &field_annotations, |
1160 &parsed_annotations, |
1154 &parsed_annotations, |
1161 CHECK_(nullHandle)); |
1155 CHECK_NULL); |
1162 if (field_annotations.not_null()) { |
1156 if (field_annotations != NULL) { |
1163 if (fields_annotations->is_null()) { |
1157 if (*fields_annotations == NULL) { |
1164 objArrayOop md = oopFactory::new_system_objArray(length, CHECK_(nullHandle)); |
1158 *fields_annotations = MetadataFactory::new_array<AnnotationArray*>( |
1165 *fields_annotations = objArrayHandle(THREAD, md); |
1159 loader_data, length, NULL, |
1166 } |
1160 CHECK_NULL); |
1167 (*fields_annotations)->obj_at_put(n, field_annotations()); |
1161 } |
|
1162 (*fields_annotations)->at_put(n, field_annotations); |
1168 } |
1163 } |
1169 if (is_synthetic) { |
1164 if (is_synthetic) { |
1170 access_flags.set_is_synthetic(); |
1165 access_flags.set_is_synthetic(); |
1171 } |
1166 } |
1172 if (generic_signature_index != 0) { |
1167 if (generic_signature_index != 0) { |
1811 #define MAX_CODE_SIZE 65535 |
1806 #define MAX_CODE_SIZE 65535 |
1812 #define INITIAL_MAX_LVT_NUMBER 256 |
1807 #define INITIAL_MAX_LVT_NUMBER 256 |
1813 |
1808 |
1814 // Note: the parse_method below is big and clunky because all parsing of the code and exceptions |
1809 // Note: the parse_method below is big and clunky because all parsing of the code and exceptions |
1815 // attribute is inlined. This is cumbersome to avoid since we inline most of the parts in the |
1810 // attribute is inlined. This is cumbersome to avoid since we inline most of the parts in the |
1816 // methodOop to save footprint, so we only know the size of the resulting methodOop when the |
1811 // Method* to save footprint, so we only know the size of the resulting Method* when the |
1817 // entire method attribute is parsed. |
1812 // entire method attribute is parsed. |
1818 // |
1813 // |
1819 // The promoted_flags parameter is used to pass relevant access_flags |
1814 // The promoted_flags parameter is used to pass relevant access_flags |
1820 // from the method back up to the containing klass. These flag values |
1815 // from the method back up to the containing klass. These flag values |
1821 // are added to klass's access_flags. |
1816 // are added to klass's access_flags. |
1822 |
1817 |
1823 methodHandle ClassFileParser::parse_method(constantPoolHandle cp, bool is_interface, |
1818 methodHandle ClassFileParser::parse_method(ClassLoaderData* loader_data, |
|
1819 constantPoolHandle cp, |
|
1820 bool is_interface, |
1824 AccessFlags *promoted_flags, |
1821 AccessFlags *promoted_flags, |
1825 typeArrayHandle* method_annotations, |
1822 AnnotationArray** method_annotations, |
1826 typeArrayHandle* method_parameter_annotations, |
1823 AnnotationArray** method_parameter_annotations, |
1827 typeArrayHandle* method_default_annotations, |
1824 AnnotationArray** method_default_annotations, |
1828 TRAPS) { |
1825 TRAPS) { |
1829 ClassFileStream* cfs = stream(); |
1826 ClassFileStream* cfs = stream(); |
1830 methodHandle nullHandle; |
1827 methodHandle nullHandle; |
1831 ResourceMark rm(THREAD); |
1828 ResourceMark rm(THREAD); |
1832 // Parse fixed parts |
1829 // Parse fixed parts |
2319 clear_hashtable(lvt_Hash); |
2307 clear_hashtable(lvt_Hash); |
2320 } |
2308 } |
2321 |
2309 |
2322 if (parsed_annotations.has_any_annotations()) |
2310 if (parsed_annotations.has_any_annotations()) |
2323 parsed_annotations.apply_to(m); |
2311 parsed_annotations.apply_to(m); |
2324 *method_annotations = assemble_annotations(runtime_visible_annotations, |
2312 *method_annotations = assemble_annotations(loader_data, |
|
2313 runtime_visible_annotations, |
2325 runtime_visible_annotations_length, |
2314 runtime_visible_annotations_length, |
2326 runtime_invisible_annotations, |
2315 runtime_invisible_annotations, |
2327 runtime_invisible_annotations_length, |
2316 runtime_invisible_annotations_length, |
2328 CHECK_(nullHandle)); |
2317 CHECK_(nullHandle)); |
2329 *method_parameter_annotations = assemble_annotations(runtime_visible_parameter_annotations, |
2318 *method_parameter_annotations = assemble_annotations(loader_data, |
|
2319 runtime_visible_parameter_annotations, |
2330 runtime_visible_parameter_annotations_length, |
2320 runtime_visible_parameter_annotations_length, |
2331 runtime_invisible_parameter_annotations, |
2321 runtime_invisible_parameter_annotations, |
2332 runtime_invisible_parameter_annotations_length, |
2322 runtime_invisible_parameter_annotations_length, |
2333 CHECK_(nullHandle)); |
2323 CHECK_(nullHandle)); |
2334 *method_default_annotations = assemble_annotations(annotation_default, |
2324 *method_default_annotations = assemble_annotations(loader_data, |
|
2325 annotation_default, |
2335 annotation_default_length, |
2326 annotation_default_length, |
2336 NULL, |
2327 NULL, |
2337 0, |
2328 0, |
2338 CHECK_(nullHandle)); |
2329 CHECK_(nullHandle)); |
2339 |
2330 |
2357 |
2348 |
2358 // The promoted_flags parameter is used to pass relevant access_flags |
2349 // The promoted_flags parameter is used to pass relevant access_flags |
2359 // from the methods back up to the containing klass. These flag values |
2350 // from the methods back up to the containing klass. These flag values |
2360 // are added to klass's access_flags. |
2351 // are added to klass's access_flags. |
2361 |
2352 |
2362 objArrayHandle ClassFileParser::parse_methods(constantPoolHandle cp, bool is_interface, |
2353 Array<Method*>* ClassFileParser::parse_methods(ClassLoaderData* loader_data, |
|
2354 constantPoolHandle cp, |
|
2355 bool is_interface, |
2363 AccessFlags* promoted_flags, |
2356 AccessFlags* promoted_flags, |
2364 bool* has_final_method, |
2357 bool* has_final_method, |
2365 objArrayOop* methods_annotations_oop, |
2358 Array<AnnotationArray*>** methods_annotations, |
2366 objArrayOop* methods_parameter_annotations_oop, |
2359 Array<AnnotationArray*>** methods_parameter_annotations, |
2367 objArrayOop* methods_default_annotations_oop, |
2360 Array<AnnotationArray*>** methods_default_annotations, |
2368 TRAPS) { |
2361 TRAPS) { |
2369 ClassFileStream* cfs = stream(); |
2362 ClassFileStream* cfs = stream(); |
2370 objArrayHandle nullHandle; |
2363 AnnotationArray* method_annotations = NULL; |
2371 typeArrayHandle method_annotations; |
2364 AnnotationArray* method_parameter_annotations = NULL; |
2372 typeArrayHandle method_parameter_annotations; |
2365 AnnotationArray* method_default_annotations = NULL; |
2373 typeArrayHandle method_default_annotations; |
2366 cfs->guarantee_more(2, CHECK_NULL); // length |
2374 cfs->guarantee_more(2, CHECK_(nullHandle)); // length |
|
2375 u2 length = cfs->get_u2_fast(); |
2367 u2 length = cfs->get_u2_fast(); |
2376 if (length == 0) { |
2368 if (length == 0) { |
2377 return objArrayHandle(THREAD, Universe::the_empty_system_obj_array()); |
2369 return Universe::the_empty_method_array(); |
2378 } else { |
2370 } else { |
2379 objArrayOop m = oopFactory::new_system_objArray(length, CHECK_(nullHandle)); |
2371 // FIXME: Handle leaks at later failures. |
2380 objArrayHandle methods(THREAD, m); |
2372 Array<Method*>* methods = MetadataFactory::new_array<Method*>(loader_data, length, NULL, CHECK_NULL); |
|
2373 |
2381 HandleMark hm(THREAD); |
2374 HandleMark hm(THREAD); |
2382 objArrayHandle methods_annotations; |
|
2383 objArrayHandle methods_parameter_annotations; |
|
2384 objArrayHandle methods_default_annotations; |
|
2385 for (int index = 0; index < length; index++) { |
2375 for (int index = 0; index < length; index++) { |
2386 methodHandle method = parse_method(cp, is_interface, |
2376 methodHandle method = parse_method(loader_data, |
|
2377 cp, is_interface, |
2387 promoted_flags, |
2378 promoted_flags, |
2388 &method_annotations, |
2379 &method_annotations, |
2389 &method_parameter_annotations, |
2380 &method_parameter_annotations, |
2390 &method_default_annotations, |
2381 &method_default_annotations, |
2391 CHECK_(nullHandle)); |
2382 CHECK_NULL); |
|
2383 |
2392 if (method->is_final()) { |
2384 if (method->is_final()) { |
2393 *has_final_method = true; |
2385 *has_final_method = true; |
2394 } |
2386 } |
2395 methods->obj_at_put(index, method()); |
2387 methods->at_put(index, method()); |
2396 if (method_annotations.not_null()) { |
2388 if (*methods_annotations == NULL) { |
2397 if (methods_annotations.is_null()) { |
2389 *methods_annotations = |
2398 objArrayOop md = oopFactory::new_system_objArray(length, CHECK_(nullHandle)); |
2390 MetadataFactory::new_array<AnnotationArray*>(loader_data, length, NULL, CHECK_NULL); |
2399 methods_annotations = objArrayHandle(THREAD, md); |
2391 } |
2400 } |
2392 (*methods_annotations)->at_put(index, method_annotations); |
2401 methods_annotations->obj_at_put(index, method_annotations()); |
2393 if (*methods_parameter_annotations == NULL) { |
2402 } |
2394 *methods_parameter_annotations = |
2403 if (method_parameter_annotations.not_null()) { |
2395 MetadataFactory::new_array<AnnotationArray*>(loader_data, length, NULL, CHECK_NULL); |
2404 if (methods_parameter_annotations.is_null()) { |
2396 } |
2405 objArrayOop md = oopFactory::new_system_objArray(length, CHECK_(nullHandle)); |
2397 (*methods_parameter_annotations)->at_put(index, method_parameter_annotations); |
2406 methods_parameter_annotations = objArrayHandle(THREAD, md); |
2398 if (*methods_default_annotations == NULL) { |
2407 } |
2399 *methods_default_annotations = |
2408 methods_parameter_annotations->obj_at_put(index, method_parameter_annotations()); |
2400 MetadataFactory::new_array<AnnotationArray*>(loader_data, length, NULL, CHECK_NULL); |
2409 } |
2401 } |
2410 if (method_default_annotations.not_null()) { |
2402 (*methods_default_annotations)->at_put(index, method_default_annotations); |
2411 if (methods_default_annotations.is_null()) { |
|
2412 objArrayOop md = oopFactory::new_system_objArray(length, CHECK_(nullHandle)); |
|
2413 methods_default_annotations = objArrayHandle(THREAD, md); |
|
2414 } |
|
2415 methods_default_annotations->obj_at_put(index, method_default_annotations()); |
|
2416 } |
|
2417 } |
2403 } |
2418 if (_need_verify && length > 1) { |
2404 if (_need_verify && length > 1) { |
2419 // Check duplicated methods |
2405 // Check duplicated methods |
2420 ResourceMark rm(THREAD); |
2406 ResourceMark rm(THREAD); |
2421 NameSigHash** names_and_sigs = NEW_RESOURCE_ARRAY_IN_THREAD( |
2407 NameSigHash** names_and_sigs = NEW_RESOURCE_ARRAY_IN_THREAD( |
2423 initialize_hashtable(names_and_sigs); |
2409 initialize_hashtable(names_and_sigs); |
2424 bool dup = false; |
2410 bool dup = false; |
2425 { |
2411 { |
2426 debug_only(No_Safepoint_Verifier nsv;) |
2412 debug_only(No_Safepoint_Verifier nsv;) |
2427 for (int i = 0; i < length; i++) { |
2413 for (int i = 0; i < length; i++) { |
2428 methodOop m = (methodOop)methods->obj_at(i); |
2414 Method* m = methods->at(i); |
2429 // If no duplicates, add name/signature in hashtable names_and_sigs. |
2415 // If no duplicates, add name/signature in hashtable names_and_sigs. |
2430 if (!put_after_lookup(m->name(), m->signature(), names_and_sigs)) { |
2416 if (!put_after_lookup(m->name(), m->signature(), names_and_sigs)) { |
2431 dup = true; |
2417 dup = true; |
2432 break; |
2418 break; |
2433 } |
2419 } |
2434 } |
2420 } |
2435 } |
2421 } |
2436 if (dup) { |
2422 if (dup) { |
2437 classfile_parse_error("Duplicate method name&signature in class file %s", |
2423 classfile_parse_error("Duplicate method name&signature in class file %s", |
2438 CHECK_(nullHandle)); |
2424 CHECK_NULL); |
2439 } |
2425 } |
2440 } |
2426 } |
2441 |
|
2442 *methods_annotations_oop = methods_annotations(); |
|
2443 *methods_parameter_annotations_oop = methods_parameter_annotations(); |
|
2444 *methods_default_annotations_oop = methods_default_annotations(); |
|
2445 |
|
2446 return methods; |
2427 return methods; |
2447 } |
2428 } |
2448 } |
2429 } |
2449 |
2430 |
2450 |
2431 |
2451 typeArrayHandle ClassFileParser::sort_methods(objArrayHandle methods, |
2432 Array<int>* ClassFileParser::sort_methods(ClassLoaderData* loader_data, |
2452 objArrayHandle methods_annotations, |
2433 Array<Method*>* methods, |
2453 objArrayHandle methods_parameter_annotations, |
2434 Array<AnnotationArray*>* methods_annotations, |
2454 objArrayHandle methods_default_annotations, |
2435 Array<AnnotationArray*>* methods_parameter_annotations, |
|
2436 Array<AnnotationArray*>* methods_default_annotations, |
2455 TRAPS) { |
2437 TRAPS) { |
2456 typeArrayHandle nullHandle; |
2438 int length = methods->length(); |
2457 int length = methods()->length(); |
|
2458 // If JVMTI original method ordering or sharing is enabled we have to |
2439 // If JVMTI original method ordering or sharing is enabled we have to |
2459 // remember the original class file ordering. |
2440 // remember the original class file ordering. |
2460 // We temporarily use the vtable_index field in the methodOop to store the |
2441 // We temporarily use the vtable_index field in the Method* to store the |
2461 // class file index, so we can read in after calling qsort. |
2442 // class file index, so we can read in after calling qsort. |
2462 // Put the method ordering in the shared archive. |
2443 // Put the method ordering in the shared archive. |
2463 if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) { |
2444 if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) { |
2464 for (int index = 0; index < length; index++) { |
2445 for (int index = 0; index < length; index++) { |
2465 methodOop m = methodOop(methods->obj_at(index)); |
2446 Method* m = methods->at(index); |
2466 assert(!m->valid_vtable_index(), "vtable index should not be set"); |
2447 assert(!m->valid_vtable_index(), "vtable index should not be set"); |
2467 m->set_vtable_index(index); |
2448 m->set_vtable_index(index); |
2468 } |
2449 } |
2469 } |
2450 } |
2470 // Sort method array by ascending method name (for faster lookups & vtable construction) |
2451 // Sort method array by ascending method name (for faster lookups & vtable construction) |
2471 // Note that the ordering is not alphabetical, see Symbol::fast_compare |
2452 // Note that the ordering is not alphabetical, see Symbol::fast_compare |
2472 methodOopDesc::sort_methods(methods(), |
2453 Method::sort_methods(methods, |
2473 methods_annotations(), |
2454 methods_annotations, |
2474 methods_parameter_annotations(), |
2455 methods_parameter_annotations, |
2475 methods_default_annotations()); |
2456 methods_default_annotations); |
2476 |
2457 |
2477 // If JVMTI original method ordering or sharing is enabled construct int |
2458 // If JVMTI original method ordering or sharing is enabled construct int |
2478 // array remembering the original ordering |
2459 // array remembering the original ordering |
2479 if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) { |
2460 if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) { |
2480 typeArrayOop new_ordering = oopFactory::new_permanent_intArray(length, CHECK_(nullHandle)); |
2461 Array<int>* method_ordering = MetadataFactory::new_array<int>(loader_data, length, CHECK_NULL); |
2481 typeArrayHandle method_ordering(THREAD, new_ordering); |
|
2482 for (int index = 0; index < length; index++) { |
2462 for (int index = 0; index < length; index++) { |
2483 methodOop m = methodOop(methods->obj_at(index)); |
2463 Method* m = methods->at(index); |
2484 int old_index = m->vtable_index(); |
2464 int old_index = m->vtable_index(); |
2485 assert(old_index >= 0 && old_index < length, "invalid method index"); |
2465 assert(old_index >= 0 && old_index < length, "invalid method index"); |
2486 method_ordering->int_at_put(index, old_index); |
2466 method_ordering->at_put(index, old_index); |
2487 m->set_vtable_index(methodOopDesc::invalid_vtable_index); |
2467 m->set_vtable_index(Method::invalid_vtable_index); |
2488 } |
2468 } |
2489 return method_ordering; |
2469 return method_ordering; |
2490 } else { |
2470 } else { |
2491 return typeArrayHandle(THREAD, Universe::the_empty_int_array()); |
2471 return Universe::the_empty_int_array(); |
2492 } |
2472 } |
2493 } |
2473 } |
2494 |
2474 |
2495 |
2475 |
2496 void ClassFileParser::parse_classfile_sourcefile_attribute(constantPoolHandle cp, TRAPS) { |
2476 void ClassFileParser::parse_classfile_sourcefile_attribute(constantPoolHandle cp, TRAPS) { |
2598 flags |= JVM_ACC_ABSTRACT; |
2579 flags |= JVM_ACC_ABSTRACT; |
2599 } |
2580 } |
2600 verify_legal_class_modifiers(flags, CHECK_0); |
2581 verify_legal_class_modifiers(flags, CHECK_0); |
2601 inner_access_flags.set_flags(flags); |
2582 inner_access_flags.set_flags(flags); |
2602 |
2583 |
2603 inner_classes->short_at_put(index++, inner_class_info_index); |
2584 inner_classes->at_put(index++, inner_class_info_index); |
2604 inner_classes->short_at_put(index++, outer_class_info_index); |
2585 inner_classes->at_put(index++, outer_class_info_index); |
2605 inner_classes->short_at_put(index++, inner_name_index); |
2586 inner_classes->at_put(index++, inner_name_index); |
2606 inner_classes->short_at_put(index++, inner_access_flags.as_short()); |
2587 inner_classes->at_put(index++, inner_access_flags.as_short()); |
2607 } |
2588 } |
2608 |
2589 |
2609 // 4347400: make sure there's no duplicate entry in the classes array |
2590 // 4347400: make sure there's no duplicate entry in the classes array |
2610 if (_need_verify && _major_version >= JAVA_1_5_VERSION) { |
2591 if (_need_verify && _major_version >= JAVA_1_5_VERSION) { |
2611 for(int i = 0; i < length * 4; i += 4) { |
2592 for(int i = 0; i < length * 4; i += 4) { |
2612 for(int j = i + 4; j < length * 4; j += 4) { |
2593 for(int j = i + 4; j < length * 4; j += 4) { |
2613 guarantee_property((inner_classes->ushort_at(i) != inner_classes->ushort_at(j) || |
2594 guarantee_property((inner_classes->at(i) != inner_classes->at(j) || |
2614 inner_classes->ushort_at(i+1) != inner_classes->ushort_at(j+1) || |
2595 inner_classes->at(i+1) != inner_classes->at(j+1) || |
2615 inner_classes->ushort_at(i+2) != inner_classes->ushort_at(j+2) || |
2596 inner_classes->at(i+2) != inner_classes->at(j+2) || |
2616 inner_classes->ushort_at(i+3) != inner_classes->ushort_at(j+3)), |
2597 inner_classes->at(i+3) != inner_classes->at(j+3)), |
2617 "Duplicate entry in InnerClasses in class file %s", |
2598 "Duplicate entry in InnerClasses in class file %s", |
2618 CHECK_0); |
2599 CHECK_0); |
2619 } |
2600 } |
2620 } |
2601 } |
2621 } |
2602 } |
2622 |
2603 |
2623 // Set EnclosingMethod class and method indexes. |
2604 // Set EnclosingMethod class and method indexes. |
2624 if (parsed_enclosingmethod_attribute) { |
2605 if (parsed_enclosingmethod_attribute) { |
2625 inner_classes->short_at_put(index++, enclosing_method_class_index); |
2606 inner_classes->at_put(index++, enclosing_method_class_index); |
2626 inner_classes->short_at_put(index++, enclosing_method_method_index); |
2607 inner_classes->at_put(index++, enclosing_method_method_index); |
2627 } |
2608 } |
2628 assert(index == size, "wrong size"); |
2609 assert(index == size, "wrong size"); |
2629 |
2610 |
2630 // Update instanceKlass with inner class info. |
2611 // Update InstanceKlass with inner class info. |
2631 set_class_inner_classes(inner_classes); |
2612 set_class_inner_classes(inner_classes); |
2632 |
2613 |
2633 // Restore buffer's current position. |
2614 // Restore buffer's current position. |
2634 cfs->set_current(current_mark); |
2615 cfs->set_current(current_mark); |
2635 |
2616 |
2693 valid_cp_range(bootstrap_method_index, cp_size) && |
2672 valid_cp_range(bootstrap_method_index, cp_size) && |
2694 cp->tag_at(bootstrap_method_index).is_method_handle(), |
2673 cp->tag_at(bootstrap_method_index).is_method_handle(), |
2695 "bootstrap_method_index %u has bad constant type in class file %s", |
2674 "bootstrap_method_index %u has bad constant type in class file %s", |
2696 bootstrap_method_index, |
2675 bootstrap_method_index, |
2697 CHECK); |
2676 CHECK); |
2698 operands->short_at_put(operand_fill_index++, bootstrap_method_index); |
2677 operands->at_put(operand_fill_index++, bootstrap_method_index); |
2699 operands->short_at_put(operand_fill_index++, argument_count); |
2678 operands->at_put(operand_fill_index++, argument_count); |
2700 |
2679 |
2701 cfs->guarantee_more(sizeof(u2) * argument_count, CHECK); // argv[argc] |
2680 cfs->guarantee_more(sizeof(u2) * argument_count, CHECK); // argv[argc] |
2702 for (int j = 0; j < argument_count; j++) { |
2681 for (int j = 0; j < argument_count; j++) { |
2703 u2 argument_index = cfs->get_u2_fast(); |
2682 u2 argument_index = cfs->get_u2_fast(); |
2704 check_property( |
2683 check_property( |
2705 valid_cp_range(argument_index, cp_size) && |
2684 valid_cp_range(argument_index, cp_size) && |
2706 cp->tag_at(argument_index).is_loadable_constant(), |
2685 cp->tag_at(argument_index).is_loadable_constant(), |
2707 "argument_index %u has bad constant type in class file %s", |
2686 "argument_index %u has bad constant type in class file %s", |
2708 argument_index, |
2687 argument_index, |
2709 CHECK); |
2688 CHECK); |
2710 operands->short_at_put(operand_fill_index++, argument_index); |
2689 operands->at_put(operand_fill_index++, argument_index); |
2711 } |
2690 } |
2712 } |
2691 } |
2713 |
2692 |
2714 assert(operand_fill_index == operands()->length(), "exact fill"); |
2693 assert(operand_fill_index == operands->length(), "exact fill"); |
2715 assert(constantPoolOopDesc::operand_array_length(operands()) == attribute_array_length, "correct decode"); |
2694 assert(ConstantPool::operand_array_length(operands) == attribute_array_length, "correct decode"); |
2716 |
2695 |
2717 u1* current_end = cfs->current(); |
2696 u1* current_end = cfs->current(); |
2718 guarantee_property(current_end == current_start + attribute_byte_length, |
2697 guarantee_property(current_end == current_start + attribute_byte_length, |
2719 "Bad length on BootstrapMethods in class file %s", |
2698 "Bad length on BootstrapMethods in class file %s", |
2720 CHECK); |
2699 CHECK); |
2721 |
2700 |
2722 cp->set_operands(operands()); |
2701 cp->set_operands(operands); |
2723 } |
2702 } |
2724 |
2703 |
2725 |
2704 void ClassFileParser::parse_classfile_attributes(ClassLoaderData* loader_data, |
2726 void ClassFileParser::parse_classfile_attributes(constantPoolHandle cp, |
2705 constantPoolHandle cp, |
2727 ClassFileParser::ClassAnnotationCollector* parsed_annotations, |
2706 ClassFileParser::ClassAnnotationCollector* parsed_annotations, |
2728 TRAPS) { |
2707 TRAPS) { |
2729 ClassFileStream* cfs = stream(); |
2708 ClassFileStream* cfs = stream(); |
2730 // Set inner classes attribute to default sentinel |
2709 // Set inner classes attribute to default sentinel |
2731 set_class_inner_classes(typeArrayHandle(THREAD, Universe::the_empty_short_array())); |
2710 set_class_inner_classes(Universe::the_empty_short_array()); |
2732 cfs->guarantee_more(2, CHECK); // attributes_count |
2711 cfs->guarantee_more(2, CHECK); // attributes_count |
2733 u2 attributes_count = cfs->get_u2_fast(); |
2712 u2 attributes_count = cfs->get_u2_fast(); |
2734 bool parsed_sourcefile_attribute = false; |
2713 bool parsed_sourcefile_attribute = false; |
2735 bool parsed_innerclasses_attribute = false; |
2714 bool parsed_innerclasses_attribute = false; |
2736 bool parsed_enclosingmethod_attribute = false; |
2715 bool parsed_enclosingmethod_attribute = false; |
2842 } else if (tag == vmSymbols::tag_bootstrap_methods() && |
2821 } else if (tag == vmSymbols::tag_bootstrap_methods() && |
2843 _major_version >= Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { |
2822 _major_version >= Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { |
2844 if (parsed_bootstrap_methods_attribute) |
2823 if (parsed_bootstrap_methods_attribute) |
2845 classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK); |
2824 classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK); |
2846 parsed_bootstrap_methods_attribute = true; |
2825 parsed_bootstrap_methods_attribute = true; |
2847 parse_classfile_bootstrap_methods_attribute(cp, attribute_length, CHECK); |
2826 parse_classfile_bootstrap_methods_attribute(loader_data, cp, attribute_length, CHECK); |
2848 } else { |
2827 } else { |
2849 // Unknown attribute |
2828 // Unknown attribute |
2850 cfs->skip_u1(attribute_length, CHECK); |
2829 cfs->skip_u1(attribute_length, CHECK); |
2851 } |
2830 } |
2852 } else { |
2831 } else { |
2853 // Unknown attribute |
2832 // Unknown attribute |
2854 cfs->skip_u1(attribute_length, CHECK); |
2833 cfs->skip_u1(attribute_length, CHECK); |
2855 } |
2834 } |
2856 } |
2835 } |
2857 typeArrayHandle annotations = assemble_annotations(runtime_visible_annotations, |
2836 AnnotationArray* annotations = assemble_annotations(loader_data, |
|
2837 runtime_visible_annotations, |
2858 runtime_visible_annotations_length, |
2838 runtime_visible_annotations_length, |
2859 runtime_invisible_annotations, |
2839 runtime_invisible_annotations, |
2860 runtime_invisible_annotations_length, |
2840 runtime_invisible_annotations_length, |
2861 CHECK); |
2841 CHECK); |
2862 set_class_annotations(annotations); |
2842 set_class_annotations(annotations); |
2863 |
2843 |
2864 if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) { |
2844 if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) { |
2865 u2 num_of_classes = parse_classfile_inner_classes_attribute( |
2845 u2 num_of_classes = parse_classfile_inner_classes_attribute( |
|
2846 loader_data, |
2866 inner_classes_attribute_start, |
2847 inner_classes_attribute_start, |
2867 parsed_innerclasses_attribute, |
2848 parsed_innerclasses_attribute, |
2868 enclosing_method_class_index, |
2849 enclosing_method_class_index, |
2869 enclosing_method_method_index, |
2850 enclosing_method_method_index, |
2870 cp, CHECK); |
2851 cp, CHECK); |
2893 k->set_generic_signature(_generic_signature); |
2874 k->set_generic_signature(_generic_signature); |
2894 } |
2875 } |
2895 if (_sde_buffer != NULL) { |
2876 if (_sde_buffer != NULL) { |
2896 k->set_source_debug_extension(_sde_buffer, _sde_length); |
2877 k->set_source_debug_extension(_sde_buffer, _sde_length); |
2897 } |
2878 } |
2898 k->set_inner_classes(_inner_classes()); |
2879 k->set_inner_classes(_inner_classes); |
2899 k->set_class_annotations(_annotations()); |
2880 if (_annotations != NULL) { |
2900 } |
2881 k->annotations()->set_class_annotations(_annotations); |
2901 |
2882 } |
2902 typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annotations, |
2883 } |
|
2884 |
|
2885 AnnotationArray* ClassFileParser::assemble_annotations(ClassLoaderData* loader_data, |
|
2886 u1* runtime_visible_annotations, |
2903 int runtime_visible_annotations_length, |
2887 int runtime_visible_annotations_length, |
2904 u1* runtime_invisible_annotations, |
2888 u1* runtime_invisible_annotations, |
2905 int runtime_invisible_annotations_length, TRAPS) { |
2889 int runtime_invisible_annotations_length, TRAPS) { |
2906 typeArrayHandle annotations; |
2890 AnnotationArray* annotations = NULL; |
2907 if (runtime_visible_annotations != NULL || |
2891 if (runtime_visible_annotations != NULL || |
2908 runtime_invisible_annotations != NULL) { |
2892 runtime_invisible_annotations != NULL) { |
2909 typeArrayOop anno = oopFactory::new_permanent_byteArray(runtime_visible_annotations_length + |
2893 annotations = MetadataFactory::new_array<u1>(loader_data, |
2910 runtime_invisible_annotations_length, CHECK_(annotations)); |
2894 runtime_visible_annotations_length + |
2911 annotations = typeArrayHandle(THREAD, anno); |
2895 runtime_invisible_annotations_length, |
|
2896 CHECK_(annotations)); |
2912 if (runtime_visible_annotations != NULL) { |
2897 if (runtime_visible_annotations != NULL) { |
2913 memcpy(annotations->byte_at_addr(0), runtime_visible_annotations, runtime_visible_annotations_length); |
2898 for (int i = 0; i < runtime_visible_annotations_length; i++) { |
|
2899 annotations->at_put(i, runtime_visible_annotations[i]); |
|
2900 } |
2914 } |
2901 } |
2915 if (runtime_invisible_annotations != NULL) { |
2902 if (runtime_invisible_annotations != NULL) { |
2916 memcpy(annotations->byte_at_addr(runtime_visible_annotations_length), runtime_invisible_annotations, runtime_invisible_annotations_length); |
2903 for (int i = 0; i < runtime_invisible_annotations_length; i++) { |
|
2904 int append = runtime_visible_annotations_length+i; |
|
2905 annotations->at_put(append, runtime_invisible_annotations[i]); |
|
2906 } |
2917 } |
2907 } |
2918 } |
2908 } |
2919 return annotations; |
2909 return annotations; |
2920 } |
2910 } |
2921 |
2911 |
3144 } |
3135 } |
3145 } |
3136 } |
3146 |
3137 |
3147 // Interfaces |
3138 // Interfaces |
3148 u2 itfs_len = cfs->get_u2_fast(); |
3139 u2 itfs_len = cfs->get_u2_fast(); |
3149 objArrayHandle local_interfaces; |
3140 Array<Klass*>* local_interfaces; |
3150 if (itfs_len == 0) { |
3141 if (itfs_len == 0) { |
3151 local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array()); |
3142 local_interfaces = Universe::the_empty_klass_array(); |
3152 } else { |
3143 } else { |
3153 local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle)); |
3144 local_interfaces = parse_interfaces(cp, itfs_len, loader_data, protection_domain, _class_name, CHECK_(nullHandle)); |
3154 } |
3145 } |
3155 |
3146 |
3156 u2 java_fields_count = 0; |
3147 u2 java_fields_count = 0; |
3157 // Fields (offsets are filled in later) |
3148 // Fields (offsets are filled in later) |
3158 FieldAllocationCount fac; |
3149 FieldAllocationCount fac; |
3159 objArrayHandle fields_annotations; |
3150 Array<AnnotationArray*>* fields_annotations = NULL; |
3160 typeArrayHandle fields = parse_fields(class_name, cp, access_flags.is_interface(), &fac, &fields_annotations, |
3151 Array<u2>* fields = parse_fields(loader_data, class_name, cp, access_flags.is_interface(), &fac, &fields_annotations, |
3161 &java_fields_count, |
3152 &java_fields_count, |
3162 CHECK_(nullHandle)); |
3153 CHECK_(nullHandle)); |
3163 // Methods |
3154 // Methods |
3164 bool has_final_method = false; |
3155 bool has_final_method = false; |
3165 AccessFlags promoted_flags; |
3156 AccessFlags promoted_flags; |
3166 promoted_flags.set_flags(0); |
3157 promoted_flags.set_flags(0); |
3167 // These need to be oop pointers because they are allocated lazily |
3158 // These need to be oop pointers because they are allocated lazily |
3168 // inside parse_methods inside a nested HandleMark |
3159 // inside parse_methods inside a nested HandleMark |
3169 objArrayOop methods_annotations_oop = NULL; |
3160 Array<AnnotationArray*>* methods_annotations = NULL; |
3170 objArrayOop methods_parameter_annotations_oop = NULL; |
3161 Array<AnnotationArray*>* methods_parameter_annotations = NULL; |
3171 objArrayOop methods_default_annotations_oop = NULL; |
3162 Array<AnnotationArray*>* methods_default_annotations = NULL; |
3172 objArrayHandle methods = parse_methods(cp, access_flags.is_interface(), |
3163 Array<Method*>* methods = parse_methods(loader_data, |
|
3164 cp, access_flags.is_interface(), |
3173 &promoted_flags, |
3165 &promoted_flags, |
3174 &has_final_method, |
3166 &has_final_method, |
3175 &methods_annotations_oop, |
3167 &methods_annotations, |
3176 &methods_parameter_annotations_oop, |
3168 &methods_parameter_annotations, |
3177 &methods_default_annotations_oop, |
3169 &methods_default_annotations, |
3178 CHECK_(nullHandle)); |
3170 CHECK_(nullHandle)); |
3179 |
|
3180 objArrayHandle methods_annotations(THREAD, methods_annotations_oop); |
|
3181 objArrayHandle methods_parameter_annotations(THREAD, methods_parameter_annotations_oop); |
|
3182 objArrayHandle methods_default_annotations(THREAD, methods_default_annotations_oop); |
|
3183 |
3171 |
3184 // Additional attributes |
3172 // Additional attributes |
3185 ClassAnnotationCollector parsed_annotations; |
3173 ClassAnnotationCollector parsed_annotations; |
3186 parse_classfile_attributes(cp, &parsed_annotations, CHECK_(nullHandle)); |
3174 parse_classfile_attributes(loader_data, cp, &parsed_annotations, CHECK_(nullHandle)); |
3187 |
3175 |
3188 // Make sure this is the end of class file stream |
3176 // Make sure this is the end of class file stream |
3189 guarantee_property(cfs->at_eos(), "Extra bytes at the end of class file %s", CHECK_(nullHandle)); |
3177 guarantee_property(cfs->at_eos(), "Extra bytes at the end of class file %s", CHECK_(nullHandle)); |
3190 |
3178 |
3191 // We check super class after class file is parsed and format is checked |
3179 // We check super class after class file is parsed and format is checked |
3616 this_klass->set_layout_helper(lh); |
3618 this_klass->set_layout_helper(lh); |
3617 assert(this_klass->oop_is_instance(), "layout is correct"); |
3619 assert(this_klass->oop_is_instance(), "layout is correct"); |
3618 assert(this_klass->size_helper() == instance_size, "correct size_helper"); |
3620 assert(this_klass->size_helper() == instance_size, "correct size_helper"); |
3619 // Not yet: supers are done below to support the new subtype-checking fields |
3621 // Not yet: supers are done below to support the new subtype-checking fields |
3620 //this_klass->set_super(super_klass()); |
3622 //this_klass->set_super(super_klass()); |
3621 this_klass->set_class_loader(class_loader()); |
3623 this_klass->set_class_loader_data(loader_data); |
3622 this_klass->set_nonstatic_field_size(nonstatic_field_size); |
3624 this_klass->set_nonstatic_field_size(nonstatic_field_size); |
3623 this_klass->set_has_nonstatic_fields(has_nonstatic_fields); |
3625 this_klass->set_has_nonstatic_fields(has_nonstatic_fields); |
3624 this_klass->set_static_oop_field_count(fac.count[STATIC_OOP]); |
3626 this_klass->set_static_oop_field_count(fac.count[STATIC_OOP]); |
3625 cp->set_pool_holder(this_klass()); |
3627 cp->set_pool_holder(this_klass()); |
3626 error_handler.set_in_error(false); // turn off error handler for cp |
3628 error_handler.set_in_error(false); // turn off error handler for cp |
3627 this_klass->set_constants(cp()); |
3629 this_klass->set_constants(cp()); |
3628 this_klass->set_local_interfaces(local_interfaces()); |
3630 this_klass->set_local_interfaces(local_interfaces); |
3629 this_klass->set_fields(fields(), java_fields_count); |
3631 this_klass->set_fields(fields, java_fields_count); |
3630 this_klass->set_methods(methods()); |
3632 this_klass->set_methods(methods); |
3631 if (has_final_method) { |
3633 if (has_final_method) { |
3632 this_klass->set_has_final_method(); |
3634 this_klass->set_has_final_method(); |
3633 } |
3635 } |
3634 this_klass->set_method_ordering(method_ordering()); |
3636 this_klass->set_method_ordering(method_ordering); |
3635 // The instanceKlass::_methods_jmethod_ids cache and the |
3637 // The InstanceKlass::_methods_jmethod_ids cache and the |
3636 // instanceKlass::_methods_cached_itable_indices cache are |
3638 // InstanceKlass::_methods_cached_itable_indices cache are |
3637 // both managed on the assumption that the initial cache |
3639 // both managed on the assumption that the initial cache |
3638 // size is equal to the number of methods in the class. If |
3640 // size is equal to the number of methods in the class. If |
3639 // that changes, then instanceKlass::idnum_can_increment() |
3641 // that changes, then InstanceKlass::idnum_can_increment() |
3640 // has to be changed accordingly. |
3642 // has to be changed accordingly. |
3641 this_klass->set_initial_method_idnum(methods->length()); |
3643 this_klass->set_initial_method_idnum(methods->length()); |
3642 this_klass->set_name(cp->klass_name_at(this_class_index)); |
3644 this_klass->set_name(cp->klass_name_at(this_class_index)); |
3643 if (LinkWellKnownClasses || is_anonymous()) // I am well known to myself |
3645 if (LinkWellKnownClasses || is_anonymous()) // I am well known to myself |
3644 cp->klass_at_put(this_class_index, this_klass()); // eagerly resolve |
3646 cp->klass_at_put(this_class_index, this_klass()); // eagerly resolve |
3645 this_klass->set_protection_domain(protection_domain()); |
3647 |
3646 this_klass->set_fields_annotations(fields_annotations()); |
3648 if (fields_annotations != NULL || |
3647 this_klass->set_methods_annotations(methods_annotations()); |
3649 methods_annotations != NULL || |
3648 this_klass->set_methods_parameter_annotations(methods_parameter_annotations()); |
3650 methods_parameter_annotations != NULL || |
3649 this_klass->set_methods_default_annotations(methods_default_annotations()); |
3651 methods_default_annotations != NULL) { |
|
3652 // Allocate an annotation type if needed. |
|
3653 Annotations* anno = Annotations::allocate(loader_data, |
|
3654 fields_annotations, methods_annotations, |
|
3655 methods_parameter_annotations, |
|
3656 methods_default_annotations, CHECK_(nullHandle)); |
|
3657 this_klass->set_annotations(anno); |
|
3658 } else { |
|
3659 this_klass->set_annotations(NULL); |
|
3660 } |
|
3661 |
3650 |
3662 |
3651 this_klass->set_minor_version(minor_version); |
3663 this_klass->set_minor_version(minor_version); |
3652 this_klass->set_major_version(major_version); |
3664 this_klass->set_major_version(major_version); |
3653 |
3665 |
3654 // Set up methodOop::intrinsic_id as soon as we know the names of methods. |
3666 // Set up Method*::intrinsic_id as soon as we know the names of methods. |
3655 // (We used to do this lazily, but now we query it in Rewriter, |
3667 // (We used to do this lazily, but now we query it in Rewriter, |
3656 // which is eagerly done for every method, so we might as well do it now, |
3668 // which is eagerly done for every method, so we might as well do it now, |
3657 // when everything is fresh in memory.) |
3669 // when everything is fresh in memory.) |
3658 if (methodOopDesc::klass_id_for_intrinsics(this_klass->as_klassOop()) != vmSymbols::NO_SID) { |
3670 if (Method::klass_id_for_intrinsics(this_klass()) != vmSymbols::NO_SID) { |
3659 for (int j = 0; j < methods->length(); j++) { |
3671 for (int j = 0; j < methods->length(); j++) { |
3660 ((methodOop)methods->obj_at(j))->init_intrinsic_id(); |
3672 methods->at(j)->init_intrinsic_id(); |
3661 } |
3673 } |
3662 } |
3674 } |
3663 |
3675 |
3664 if (cached_class_file_bytes != NULL) { |
3676 if (cached_class_file_bytes != NULL) { |
3665 // JVMTI: we have an instanceKlass now, tell it about the cached bytes |
3677 // JVMTI: we have an InstanceKlass now, tell it about the cached bytes |
3666 this_klass->set_cached_class_file(cached_class_file_bytes, |
3678 this_klass->set_cached_class_file(cached_class_file_bytes, |
3667 cached_class_file_length); |
3679 cached_class_file_length); |
3668 } |
3680 } |
3669 |
3681 |
3670 // Miranda methods |
3682 // Miranda methods |
3716 } |
3733 } |
3717 |
3734 |
3718 // Allocate mirror and initialize static fields |
3735 // Allocate mirror and initialize static fields |
3719 java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle)); |
3736 java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle)); |
3720 |
3737 |
3721 ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()), |
3738 // Allocate a simple java object for locking during class initialization. |
|
3739 // This needs to be a java object because it can be held across a java call. |
|
3740 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK_NULL); |
|
3741 this_klass->set_init_lock(r); |
|
3742 |
|
3743 // TODO: Move these oops to the mirror |
|
3744 this_klass->set_protection_domain(protection_domain()); |
|
3745 |
|
3746 // Update the loader_data graph. |
|
3747 record_defined_class_dependencies(this_klass, CHECK_NULL); |
|
3748 |
|
3749 ClassLoadingService::notify_class_loaded(InstanceKlass::cast(this_klass()), |
3722 false /* not shared class */); |
3750 false /* not shared class */); |
3723 |
3751 |
3724 if (TraceClassLoading) { |
3752 if (TraceClassLoading) { |
3725 // print in a single call to reduce interleaving of output |
3753 // print in a single call to reduce interleaving of output |
3726 if (cfs->source() != NULL) { |
3754 if (cfs->source() != NULL) { |
3727 tty->print("[Loaded %s from %s]\n", this_klass->external_name(), |
3755 tty->print("[Loaded %s from %s]\n", this_klass->external_name(), |
3728 cfs->source()); |
3756 cfs->source()); |
3729 } else if (class_loader.is_null()) { |
3757 } else if (class_loader.is_null()) { |
3730 if (THREAD->is_Java_thread()) { |
3758 if (THREAD->is_Java_thread()) { |
3731 klassOop caller = ((JavaThread*)THREAD)->security_get_caller_class(1); |
3759 Klass* caller = ((JavaThread*)THREAD)->security_get_caller_class(1); |
3732 tty->print("[Loaded %s by instance of %s]\n", |
3760 tty->print("[Loaded %s by instance of %s]\n", |
3733 this_klass->external_name(), |
3761 this_klass->external_name(), |
3734 instanceKlass::cast(caller)->external_name()); |
3762 InstanceKlass::cast(caller)->external_name()); |
3735 } else { |
3763 } else { |
3736 tty->print("[Loaded %s]\n", this_klass->external_name()); |
3764 tty->print("[Loaded %s]\n", this_klass->external_name()); |
3737 } |
3765 } |
3738 } else { |
3766 } else { |
3739 ResourceMark rm; |
3767 ResourceMark rm; |
3740 tty->print("[Loaded %s from %s]\n", this_klass->external_name(), |
3768 tty->print("[Loaded %s from %s]\n", this_klass->external_name(), |
3741 instanceKlass::cast(class_loader->klass())->external_name()); |
3769 InstanceKlass::cast(class_loader->klass())->external_name()); |
3742 } |
3770 } |
3743 } |
3771 } |
3744 |
3772 |
3745 if (TraceClassResolution) { |
3773 if (TraceClassResolution) { |
3746 // print out the superclass. |
3774 // print out the superclass. |
3747 const char * from = Klass::cast(this_klass())->external_name(); |
3775 const char * from = Klass::cast(this_klass())->external_name(); |
3748 if (this_klass->java_super() != NULL) { |
3776 if (this_klass->java_super() != NULL) { |
3749 tty->print("RESOLVE %s %s (super)\n", from, instanceKlass::cast(this_klass->java_super())->external_name()); |
3777 tty->print("RESOLVE %s %s (super)\n", from, InstanceKlass::cast(this_klass->java_super())->external_name()); |
3750 } |
3778 } |
3751 // print out each of the interface classes referred to by this class. |
3779 // print out each of the interface classes referred to by this class. |
3752 objArrayHandle local_interfaces(THREAD, this_klass->local_interfaces()); |
3780 Array<Klass*>* local_interfaces = this_klass->local_interfaces(); |
3753 if (!local_interfaces.is_null()) { |
3781 if (local_interfaces != NULL) { |
3754 int length = local_interfaces->length(); |
3782 int length = local_interfaces->length(); |
3755 for (int i = 0; i < length; i++) { |
3783 for (int i = 0; i < length; i++) { |
3756 klassOop k = klassOop(local_interfaces->obj_at(i)); |
3784 Klass* k = local_interfaces->at(i); |
3757 instanceKlass* to_class = instanceKlass::cast(k); |
3785 InstanceKlass* to_class = InstanceKlass::cast(k); |
3758 const char * to = to_class->external_name(); |
3786 const char * to = to_class->external_name(); |
3759 tty->print("RESOLVE %s %s (interface)\n", from, to); |
3787 tty->print("RESOLVE %s %s (interface)\n", from, to); |
3760 } |
3788 } |
3761 } |
3789 } |
3762 } |
3790 } |
3899 k->set_has_vanilla_constructor(); |
3928 k->set_has_vanilla_constructor(); |
3900 } |
3929 } |
3901 #ifdef ASSERT |
3930 #ifdef ASSERT |
3902 bool v = false; |
3931 bool v = false; |
3903 if (Klass::cast(super)->has_vanilla_constructor()) { |
3932 if (Klass::cast(super)->has_vanilla_constructor()) { |
3904 methodOop constructor = k->find_method(vmSymbols::object_initializer_name( |
3933 Method* constructor = k->find_method(vmSymbols::object_initializer_name( |
3905 ), vmSymbols::void_method_signature()); |
3934 ), vmSymbols::void_method_signature()); |
3906 if (constructor != NULL && constructor->is_vanilla_constructor()) { |
3935 if (constructor != NULL && constructor->is_vanilla_constructor()) { |
3907 v = true; |
3936 v = true; |
3908 } |
3937 } |
3909 } |
3938 } |
3910 assert(v == k->has_vanilla_constructor(), "inconsistent has_vanilla_constructor"); |
3939 assert(v == k->has_vanilla_constructor(), "inconsistent has_vanilla_constructor"); |
3911 #endif |
3940 #endif |
3912 } |
3941 } |
3913 |
3942 |
3914 // If it cannot be fast-path allocated, set a bit in the layout helper. |
3943 // If it cannot be fast-path allocated, set a bit in the layout helper. |
3915 // See documentation of instanceKlass::can_be_fastpath_allocated(). |
3944 // See documentation of InstanceKlass::can_be_fastpath_allocated(). |
3916 assert(k->size_helper() > 0, "layout_helper is initialized"); |
3945 assert(k->size_helper() > 0, "layout_helper is initialized"); |
3917 if ((!RegisterFinalizersAtInit && k->has_finalizer()) |
3946 if ((!RegisterFinalizersAtInit && k->has_finalizer()) |
3918 || k->is_abstract() || k->is_interface() |
3947 || k->is_abstract() || k->is_interface() |
3919 || (k->name() == vmSymbols::java_lang_Class() |
3948 || (k->name() == vmSymbols::java_lang_Class() |
3920 && k->class_loader() == NULL) |
3949 && k->class_loader_data()->is_the_null_class_loader_data()) |
3921 || k->size_helper() >= FastAllocateSizeLimit) { |
3950 || k->size_helper() >= FastAllocateSizeLimit) { |
3922 // Forbid fast-path allocation. |
3951 // Forbid fast-path allocation. |
3923 jint lh = Klass::instance_layout_helper(k->size_helper(), true); |
3952 jint lh = Klass::instance_layout_helper(k->size_helper(), true); |
3924 k->set_layout_helper(lh); |
3953 k->set_layout_helper(lh); |
3925 } |
3954 } |
3926 } |
3955 } |
3927 |
3956 |
|
3957 // Attach super classes and interface classes to class loader data |
|
3958 void ClassFileParser::record_defined_class_dependencies(instanceKlassHandle defined_klass, TRAPS) { |
|
3959 ClassLoaderData * defining_loader_data = defined_klass->class_loader_data(); |
|
3960 if (defining_loader_data->is_the_null_class_loader_data()) { |
|
3961 // Dependencies to null class loader data are implicit. |
|
3962 return; |
|
3963 } else { |
|
3964 // add super class dependency |
|
3965 Klass* super = defined_klass->super(); |
|
3966 if (super != NULL) { |
|
3967 defining_loader_data->record_dependency(super, CHECK); |
|
3968 } |
|
3969 |
|
3970 // add super interface dependencies |
|
3971 Array<Klass*>* local_interfaces = defined_klass->local_interfaces(); |
|
3972 if (local_interfaces != NULL) { |
|
3973 int length = local_interfaces->length(); |
|
3974 for (int i = 0; i < length; i++) { |
|
3975 defining_loader_data->record_dependency(local_interfaces->at(i), CHECK); |
|
3976 } |
|
3977 } |
|
3978 } |
|
3979 } |
3928 |
3980 |
3929 // utility method for appending and array with check for duplicates |
3981 // utility method for appending and array with check for duplicates |
3930 |
3982 |
3931 void append_interfaces(objArrayHandle result, int& index, objArrayOop ifs) { |
3983 void append_interfaces(GrowableArray<Klass*>* result, Array<Klass*>* ifs) { |
3932 // iterate over new interfaces |
3984 // iterate over new interfaces |
3933 for (int i = 0; i < ifs->length(); i++) { |
3985 for (int i = 0; i < ifs->length(); i++) { |
3934 oop e = ifs->obj_at(i); |
3986 Klass* e = ifs->at(i); |
3935 assert(e->is_klass() && instanceKlass::cast(klassOop(e))->is_interface(), "just checking"); |
3987 assert(e->is_klass() && InstanceKlass::cast(e)->is_interface(), "just checking"); |
3936 // check for duplicates |
|
3937 bool duplicate = false; |
|
3938 for (int j = 0; j < index; j++) { |
|
3939 if (result->obj_at(j) == e) { |
|
3940 duplicate = true; |
|
3941 break; |
|
3942 } |
|
3943 } |
|
3944 // add new interface |
3988 // add new interface |
3945 if (!duplicate) { |
3989 result->append_if_missing(e); |
3946 result->obj_at_put(index++, e); |
3990 } |
3947 } |
3991 } |
3948 } |
3992 |
3949 } |
3993 |
3950 |
3994 Array<Klass*>* ClassFileParser::compute_transitive_interfaces(ClassLoaderData* loader_data, instanceKlassHandle super, Array<Klass*>* local_ifs, TRAPS) { |
3951 objArrayHandle ClassFileParser::compute_transitive_interfaces(instanceKlassHandle super, objArrayHandle local_ifs, TRAPS) { |
|
3952 // Compute maximum size for transitive interfaces |
3995 // Compute maximum size for transitive interfaces |
3953 int max_transitive_size = 0; |
3996 int max_transitive_size = 0; |
3954 int super_size = 0; |
3997 int super_size = 0; |
3955 // Add superclass transitive interfaces size |
3998 // Add superclass transitive interfaces size |
3956 if (super.not_null()) { |
3999 if (super.not_null()) { |
3958 max_transitive_size += super_size; |
4001 max_transitive_size += super_size; |
3959 } |
4002 } |
3960 // Add local interfaces' super interfaces |
4003 // Add local interfaces' super interfaces |
3961 int local_size = local_ifs->length(); |
4004 int local_size = local_ifs->length(); |
3962 for (int i = 0; i < local_size; i++) { |
4005 for (int i = 0; i < local_size; i++) { |
3963 klassOop l = klassOop(local_ifs->obj_at(i)); |
4006 Klass* l = local_ifs->at(i); |
3964 max_transitive_size += instanceKlass::cast(l)->transitive_interfaces()->length(); |
4007 max_transitive_size += InstanceKlass::cast(l)->transitive_interfaces()->length(); |
3965 } |
4008 } |
3966 // Finally add local interfaces |
4009 // Finally add local interfaces |
3967 max_transitive_size += local_size; |
4010 max_transitive_size += local_size; |
3968 // Construct array |
4011 // Construct array |
3969 objArrayHandle result; |
|
3970 if (max_transitive_size == 0) { |
4012 if (max_transitive_size == 0) { |
3971 // no interfaces, use canonicalized array |
4013 // no interfaces, use canonicalized array |
3972 result = objArrayHandle(THREAD, Universe::the_empty_system_obj_array()); |
4014 return Universe::the_empty_klass_array(); |
3973 } else if (max_transitive_size == super_size) { |
4015 } else if (max_transitive_size == super_size) { |
3974 // no new local interfaces added, share superklass' transitive interface array |
4016 // no new local interfaces added, share superklass' transitive interface array |
3975 result = objArrayHandle(THREAD, super->transitive_interfaces()); |
4017 return super->transitive_interfaces(); |
3976 } else if (max_transitive_size == local_size) { |
4018 } else if (max_transitive_size == local_size) { |
3977 // only local interfaces added, share local interface array |
4019 // only local interfaces added, share local interface array |
3978 result = local_ifs; |
4020 return local_ifs; |
3979 } else { |
4021 } else { |
3980 objArrayHandle nullHandle; |
4022 ResourceMark rm; |
3981 objArrayOop new_objarray = oopFactory::new_system_objArray(max_transitive_size, CHECK_(nullHandle)); |
4023 GrowableArray<Klass*>* result = new GrowableArray<Klass*>(max_transitive_size); |
3982 result = objArrayHandle(THREAD, new_objarray); |
4024 |
3983 int index = 0; |
|
3984 // Copy down from superclass |
4025 // Copy down from superclass |
3985 if (super.not_null()) { |
4026 if (super.not_null()) { |
3986 append_interfaces(result, index, super->transitive_interfaces()); |
4027 append_interfaces(result, super->transitive_interfaces()); |
3987 } |
4028 } |
|
4029 |
3988 // Copy down from local interfaces' superinterfaces |
4030 // Copy down from local interfaces' superinterfaces |
3989 for (int i = 0; i < local_ifs->length(); i++) { |
4031 for (int i = 0; i < local_ifs->length(); i++) { |
3990 klassOop l = klassOop(local_ifs->obj_at(i)); |
4032 Klass* l = local_ifs->at(i); |
3991 append_interfaces(result, index, instanceKlass::cast(l)->transitive_interfaces()); |
4033 append_interfaces(result, InstanceKlass::cast(l)->transitive_interfaces()); |
3992 } |
4034 } |
3993 // Finally add local interfaces |
4035 // Finally add local interfaces |
3994 append_interfaces(result, index, local_ifs()); |
4036 append_interfaces(result, local_ifs); |
3995 |
4037 |
3996 // Check if duplicates were removed |
4038 // length will be less than the max_transitive_size if duplicates were removed |
3997 if (index != max_transitive_size) { |
4039 int length = result->length(); |
3998 assert(index < max_transitive_size, "just checking"); |
4040 assert(length <= max_transitive_size, "just checking"); |
3999 objArrayOop new_result = oopFactory::new_system_objArray(index, CHECK_(nullHandle)); |
4041 Array<Klass*>* new_result = MetadataFactory::new_array<Klass*>(loader_data, length, CHECK_NULL); |
4000 for (int i = 0; i < index; i++) { |
4042 for (int i = 0; i < length; i++) { |
4001 oop e = result->obj_at(i); |
4043 Klass* e = result->at(i); |
4002 assert(e != NULL, "just checking"); |
4044 assert(e != NULL, "just checking"); |
4003 new_result->obj_at_put(i, e); |
4045 new_result->at_put(i, e); |
4004 } |
4046 } |
4005 result = objArrayHandle(THREAD, new_result); |
4047 return new_result; |
4006 } |
4048 } |
4007 } |
|
4008 return result; |
|
4009 } |
4049 } |
4010 |
4050 |
4011 |
4051 |
4012 void ClassFileParser::check_super_class_access(instanceKlassHandle this_klass, TRAPS) { |
4052 void ClassFileParser::check_super_class_access(instanceKlassHandle this_klass, TRAPS) { |
4013 klassOop super = this_klass->super(); |
4053 Klass* super = this_klass->super(); |
4014 if ((super != NULL) && |
4054 if ((super != NULL) && |
4015 (!Reflection::verify_class_access(this_klass->as_klassOop(), super, false))) { |
4055 (!Reflection::verify_class_access(this_klass(), super, false))) { |
4016 ResourceMark rm(THREAD); |
4056 ResourceMark rm(THREAD); |
4017 Exceptions::fthrow( |
4057 Exceptions::fthrow( |
4018 THREAD_AND_LOCATION, |
4058 THREAD_AND_LOCATION, |
4019 vmSymbols::java_lang_IllegalAccessError(), |
4059 vmSymbols::java_lang_IllegalAccessError(), |
4020 "class %s cannot access its superclass %s", |
4060 "class %s cannot access its superclass %s", |
4021 this_klass->external_name(), |
4061 this_klass->external_name(), |
4022 instanceKlass::cast(super)->external_name() |
4062 InstanceKlass::cast(super)->external_name() |
4023 ); |
4063 ); |
4024 return; |
4064 return; |
4025 } |
4065 } |
4026 } |
4066 } |
4027 |
4067 |
4028 |
4068 |
4029 void ClassFileParser::check_super_interface_access(instanceKlassHandle this_klass, TRAPS) { |
4069 void ClassFileParser::check_super_interface_access(instanceKlassHandle this_klass, TRAPS) { |
4030 objArrayHandle local_interfaces (THREAD, this_klass->local_interfaces()); |
4070 Array<Klass*>* local_interfaces = this_klass->local_interfaces(); |
4031 int lng = local_interfaces->length(); |
4071 int lng = local_interfaces->length(); |
4032 for (int i = lng - 1; i >= 0; i--) { |
4072 for (int i = lng - 1; i >= 0; i--) { |
4033 klassOop k = klassOop(local_interfaces->obj_at(i)); |
4073 Klass* k = local_interfaces->at(i); |
4034 assert (k != NULL && Klass::cast(k)->is_interface(), "invalid interface"); |
4074 assert (k != NULL && Klass::cast(k)->is_interface(), "invalid interface"); |
4035 if (!Reflection::verify_class_access(this_klass->as_klassOop(), k, false)) { |
4075 if (!Reflection::verify_class_access(this_klass(), k, false)) { |
4036 ResourceMark rm(THREAD); |
4076 ResourceMark rm(THREAD); |
4037 Exceptions::fthrow( |
4077 Exceptions::fthrow( |
4038 THREAD_AND_LOCATION, |
4078 THREAD_AND_LOCATION, |
4039 vmSymbols::java_lang_IllegalAccessError(), |
4079 vmSymbols::java_lang_IllegalAccessError(), |
4040 "class %s cannot access its superinterface %s", |
4080 "class %s cannot access its superinterface %s", |
4041 this_klass->external_name(), |
4081 this_klass->external_name(), |
4042 instanceKlass::cast(k)->external_name() |
4082 InstanceKlass::cast(k)->external_name() |
4043 ); |
4083 ); |
4044 return; |
4084 return; |
4045 } |
4085 } |
4046 } |
4086 } |
4047 } |
4087 } |
4048 |
4088 |
4049 |
4089 |
4050 void ClassFileParser::check_final_method_override(instanceKlassHandle this_klass, TRAPS) { |
4090 void ClassFileParser::check_final_method_override(instanceKlassHandle this_klass, TRAPS) { |
4051 objArrayHandle methods (THREAD, this_klass->methods()); |
4091 Array<Method*>* methods = this_klass->methods(); |
4052 int num_methods = methods->length(); |
4092 int num_methods = methods->length(); |
4053 |
4093 |
4054 // go thru each method and check if it overrides a final method |
4094 // go thru each method and check if it overrides a final method |
4055 for (int index = 0; index < num_methods; index++) { |
4095 for (int index = 0; index < num_methods; index++) { |
4056 methodOop m = (methodOop)methods->obj_at(index); |
4096 Method* m = methods->at(index); |
4057 |
4097 |
4058 // skip private, static and <init> methods |
4098 // skip private, static and <init> methods |
4059 if ((!m->is_private()) && |
4099 if ((!m->is_private()) && |
4060 (!m->is_static()) && |
4100 (!m->is_static()) && |
4061 (m->name() != vmSymbols::object_initializer_name())) { |
4101 (m->name() != vmSymbols::object_initializer_name())) { |
4062 |
4102 |
4063 Symbol* name = m->name(); |
4103 Symbol* name = m->name(); |
4064 Symbol* signature = m->signature(); |
4104 Symbol* signature = m->signature(); |
4065 klassOop k = this_klass->super(); |
4105 Klass* k = this_klass->super(); |
4066 methodOop super_m = NULL; |
4106 Method* super_m = NULL; |
4067 while (k != NULL) { |
4107 while (k != NULL) { |
4068 // skip supers that don't have final methods. |
4108 // skip supers that don't have final methods. |
4069 if (k->klass_part()->has_final_method()) { |
4109 if (k->has_final_method()) { |
4070 // lookup a matching method in the super class hierarchy |
4110 // lookup a matching method in the super class hierarchy |
4071 super_m = instanceKlass::cast(k)->lookup_method(name, signature); |
4111 super_m = InstanceKlass::cast(k)->lookup_method(name, signature); |
4072 if (super_m == NULL) { |
4112 if (super_m == NULL) { |
4073 break; // didn't find any match; get out |
4113 break; // didn't find any match; get out |
4074 } |
4114 } |
4075 |
4115 |
4076 if (super_m->is_final() && |
4116 if (super_m->is_final() && |
4077 // matching method in super is final |
4117 // matching method in super is final |
4078 (Reflection::verify_field_access(this_klass->as_klassOop(), |
4118 (Reflection::verify_field_access(this_klass(), |
4079 super_m->method_holder(), |
4119 super_m->method_holder(), |
4080 super_m->method_holder(), |
4120 super_m->method_holder(), |
4081 super_m->access_flags(), false)) |
4121 super_m->access_flags(), false)) |
4082 // this class can access super final method and therefore override |
4122 // this class can access super final method and therefore override |
4083 ) { |
4123 ) { |