Mercurial > hg > truffle
comparison src/share/vm/classfile/classFileParser.cpp @ 6725:da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author | coleenp |
---|---|
date | Sat, 01 Sep 2012 13:25:18 -0400 |
parents | 1d7922586cf6 |
children | aed758eda82a |
comparison
equal
deleted
inserted
replaced
6724:36d1d483d5d6 | 6725:da91efe96a93 |
---|---|
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. |
79 // Used for backward compatibility reasons: | 83 // Used for backward compatibility reasons: |
80 // - to check NameAndType_info signatures more aggressively | 84 // - to check NameAndType_info signatures more aggressively |
81 #define JAVA_7_VERSION 51 | 85 #define JAVA_7_VERSION 51 |
82 | 86 |
83 | 87 |
84 void ClassFileParser::parse_constant_pool_entries(Handle class_loader, constantPoolHandle cp, int length, TRAPS) { | 88 void ClassFileParser::parse_constant_pool_entries(ClassLoaderData* loader_data, constantPoolHandle cp, int length, TRAPS) { |
85 // Use a local copy of ClassFileStream. It helps the C++ compiler to optimize | 89 // Use a local copy of ClassFileStream. It helps the C++ compiler to optimize |
86 // this function (_current can be allocated in a register, with scalar | 90 // this function (_current can be allocated in a register, with scalar |
87 // replacement of aggregates). The _current pointer is copied back to | 91 // replacement of aggregates). The _current pointer is copied back to |
88 // stream() when this function returns. DON'T call another method within | 92 // stream() when this function returns. DON'T call another method within |
89 // this method that uses stream(). | 93 // this method that uses stream(). |
92 ClassFileStream* cfs = &cfs1; | 96 ClassFileStream* cfs = &cfs1; |
93 #ifdef ASSERT | 97 #ifdef ASSERT |
94 assert(cfs->allocated_on_stack(),"should be local"); | 98 assert(cfs->allocated_on_stack(),"should be local"); |
95 u1* old_current = cfs0->current(); | 99 u1* old_current = cfs0->current(); |
96 #endif | 100 #endif |
101 Handle class_loader(THREAD, loader_data->class_loader()); | |
97 | 102 |
98 // Used for batching symbol allocations. | 103 // Used for batching symbol allocations. |
99 const char* names[SymbolTable::symbol_alloc_batch_size]; | 104 const char* names[SymbolTable::symbol_alloc_batch_size]; |
100 int lengths[SymbolTable::symbol_alloc_batch_size]; | 105 int lengths[SymbolTable::symbol_alloc_batch_size]; |
101 int indices[SymbolTable::symbol_alloc_batch_size]; | 106 int indices[SymbolTable::symbol_alloc_batch_size]; |
270 names[names_count] = (char*)utf8_buffer; | 275 names[names_count] = (char*)utf8_buffer; |
271 lengths[names_count] = utf8_length; | 276 lengths[names_count] = utf8_length; |
272 indices[names_count] = index; | 277 indices[names_count] = index; |
273 hashValues[names_count++] = hash; | 278 hashValues[names_count++] = hash; |
274 if (names_count == SymbolTable::symbol_alloc_batch_size) { | 279 if (names_count == SymbolTable::symbol_alloc_batch_size) { |
275 SymbolTable::new_symbols(class_loader, cp, names_count, names, lengths, indices, hashValues, CHECK); | 280 SymbolTable::new_symbols(loader_data, cp, names_count, names, lengths, indices, hashValues, CHECK); |
276 names_count = 0; | 281 names_count = 0; |
277 } | 282 } |
278 } else { | 283 } else { |
279 cp->symbol_at_put(index, result); | 284 cp->symbol_at_put(index, result); |
280 } | 285 } |
287 } | 292 } |
288 } | 293 } |
289 | 294 |
290 // Allocate the remaining symbols | 295 // Allocate the remaining symbols |
291 if (names_count > 0) { | 296 if (names_count > 0) { |
292 SymbolTable::new_symbols(class_loader, cp, names_count, names, lengths, indices, hashValues, CHECK); | 297 SymbolTable::new_symbols(loader_data, cp, names_count, names, lengths, indices, hashValues, CHECK); |
293 } | 298 } |
294 | 299 |
295 // Copy _current pointer of local copy back to stream(). | 300 // Copy _current pointer of local copy back to stream(). |
296 #ifdef ASSERT | 301 #ifdef ASSERT |
297 assert(cfs0->current() == old_current, "non-exclusive use of stream()"); | 302 assert(cfs0->current() == old_current, "non-exclusive use of stream()"); |
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 |
420 cp->tag_at(class_index).is_utf8(), | 424 cp->tag_at(class_index).is_utf8(), |
421 "Invalid constant pool index %u in class file %s", | 425 "Invalid constant pool index %u in class file %s", |
422 class_index, CHECK_(nullHandle)); | 426 class_index, CHECK_(nullHandle)); |
423 cp->unresolved_klass_at_put(index, cp->symbol_at(class_index)); | 427 cp->unresolved_klass_at_put(index, cp->symbol_at(class_index)); |
424 } | 428 } |
425 break; | |
426 case JVM_CONSTANT_UnresolvedString : | |
427 ShouldNotReachHere(); // Only JVM_CONSTANT_StringIndex should be present | |
428 break; | 429 break; |
429 case JVM_CONSTANT_StringIndex : | 430 case JVM_CONSTANT_StringIndex : |
430 { | 431 { |
431 int string_index = cp->string_index_at(index); | 432 int string_index = cp->string_index_at(index); |
432 check_property( | 433 check_property( |
528 guarantee_property(index != this_class_index, | 529 guarantee_property(index != this_class_index, |
529 "Illegal constant pool patch to self at %d in class file %s", | 530 "Illegal constant pool patch to self at %d in class file %s", |
530 index, CHECK_(nullHandle)); | 531 index, CHECK_(nullHandle)); |
531 patch_constant_pool(cp, index, cp_patch_at(index), CHECK_(nullHandle)); | 532 patch_constant_pool(cp, index, cp_patch_at(index), CHECK_(nullHandle)); |
532 } | 533 } |
533 } | |
534 // Ensure that all the patches have been used. | |
535 for (index = 0; index < _cp_patches->length(); index++) { | |
536 guarantee_property(!has_cp_patch_at(index), | |
537 "Unused constant pool patch at %d in class file %s", | |
538 index, CHECK_(nullHandle)); | |
539 } | 534 } |
540 } | 535 } |
541 | 536 |
542 if (!_need_verify) { | 537 if (!_need_verify) { |
543 cp_in_error.set_in_error(false); | 538 cp_in_error.set_in_error(false); |
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 } |
847 initialize_hashtable(interface_names); | 838 initialize_hashtable(interface_names); |
848 bool dup = false; | 839 bool dup = false; |
849 { | 840 { |
850 debug_only(No_Safepoint_Verifier nsv;) | 841 debug_only(No_Safepoint_Verifier nsv;) |
851 for (index = 0; index < length; index++) { | 842 for (index = 0; index < length; index++) { |
852 klassOop k = (klassOop)interfaces->obj_at(index); | 843 Klass* k = interfaces->at(index); |
853 Symbol* name = instanceKlass::cast(k)->name(); | 844 Symbol* name = InstanceKlass::cast(k)->name(); |
854 // If no duplicates, add (name, NULL) in hashtable interface_names. | 845 // If no duplicates, add (name, NULL) in hashtable interface_names. |
855 if (!put_after_lookup(name, NULL, interface_names)) { | 846 if (!put_after_lookup(name, NULL, interface_names)) { |
856 dup = true; | 847 dup = true; |
857 break; | 848 break; |
858 } | 849 } |
859 } | 850 } |
860 } | 851 } |
861 if (dup) { | 852 if (dup) { |
862 classfile_parse_error("Duplicate interface name in class file %s", | 853 classfile_parse_error("Duplicate interface name in class file %s", CHECK_NULL); |
863 CHECK_(nullHandle)); | |
864 } | 854 } |
865 | 855 |
866 return interfaces; | 856 return interfaces; |
867 } | 857 } |
868 | 858 |
888 case T_BYTE: case T_CHAR: case T_SHORT: case T_BOOLEAN: case T_INT: | 878 case T_BYTE: case T_CHAR: case T_SHORT: case T_BOOLEAN: case T_INT: |
889 guarantee_property(value_type.is_int(), "Inconsistent constant value type in class file %s", CHECK); | 879 guarantee_property(value_type.is_int(), "Inconsistent constant value type in class file %s", CHECK); |
890 break; | 880 break; |
891 case T_OBJECT: | 881 case T_OBJECT: |
892 guarantee_property((cp->symbol_at(signature_index)->equals("Ljava/lang/String;") | 882 guarantee_property((cp->symbol_at(signature_index)->equals("Ljava/lang/String;") |
893 && (value_type.is_string() || value_type.is_unresolved_string())), | 883 && value_type.is_string()), |
894 "Bad string initial value in class file %s", CHECK); | 884 "Bad string initial value in class file %s", CHECK); |
895 break; | 885 break; |
896 default: | 886 default: |
897 classfile_parse_error( | 887 classfile_parse_error( |
898 "Unable to set initial value %u in class file %s", | 888 "Unable to set initial value %u in class file %s", |
900 } | 890 } |
901 } | 891 } |
902 | 892 |
903 | 893 |
904 // Parse attributes for a field. | 894 // Parse attributes for a field. |
905 void ClassFileParser::parse_field_attributes(constantPoolHandle cp, | 895 void ClassFileParser::parse_field_attributes(ClassLoaderData* loader_data, |
896 constantPoolHandle cp, | |
906 u2 attributes_count, | 897 u2 attributes_count, |
907 bool is_static, u2 signature_index, | 898 bool is_static, u2 signature_index, |
908 u2* constantvalue_index_addr, | 899 u2* constantvalue_index_addr, |
909 bool* is_synthetic_addr, | 900 bool* is_synthetic_addr, |
910 u2* generic_signature_index_addr, | 901 u2* generic_signature_index_addr, |
911 typeArrayHandle* field_annotations, | 902 AnnotationArray** field_annotations, |
912 ClassFileParser::FieldAnnotationCollector* parsed_annotations, | 903 ClassFileParser::FieldAnnotationCollector* parsed_annotations, |
913 TRAPS) { | 904 TRAPS) { |
914 ClassFileStream* cfs = stream(); | 905 ClassFileStream* cfs = stream(); |
915 assert(attributes_count > 0, "length should be greater than 0"); | 906 assert(attributes_count > 0, "length should be greater than 0"); |
916 u2 constantvalue_index = 0; | 907 u2 constantvalue_index = 0; |
983 } | 974 } |
984 | 975 |
985 *constantvalue_index_addr = constantvalue_index; | 976 *constantvalue_index_addr = constantvalue_index; |
986 *is_synthetic_addr = is_synthetic; | 977 *is_synthetic_addr = is_synthetic; |
987 *generic_signature_index_addr = generic_signature_index; | 978 *generic_signature_index_addr = generic_signature_index; |
988 *field_annotations = assemble_annotations(runtime_visible_annotations, | 979 *field_annotations = assemble_annotations(loader_data, |
980 runtime_visible_annotations, | |
989 runtime_visible_annotations_length, | 981 runtime_visible_annotations_length, |
990 runtime_invisible_annotations, | 982 runtime_invisible_annotations, |
991 runtime_invisible_annotations_length, | 983 runtime_invisible_annotations_length, |
992 CHECK); | 984 CHECK); |
993 return; | 985 return; |
1027 NONSTATIC_OOP, // T_OBJECT = 12, | 1019 NONSTATIC_OOP, // T_OBJECT = 12, |
1028 NONSTATIC_OOP, // T_ARRAY = 13, | 1020 NONSTATIC_OOP, // T_ARRAY = 13, |
1029 BAD_ALLOCATION_TYPE, // T_VOID = 14, | 1021 BAD_ALLOCATION_TYPE, // T_VOID = 14, |
1030 BAD_ALLOCATION_TYPE, // T_ADDRESS = 15, | 1022 BAD_ALLOCATION_TYPE, // T_ADDRESS = 15, |
1031 BAD_ALLOCATION_TYPE, // T_NARROWOOP= 16, | 1023 BAD_ALLOCATION_TYPE, // T_NARROWOOP= 16, |
1032 BAD_ALLOCATION_TYPE, // T_CONFLICT = 17, | 1024 BAD_ALLOCATION_TYPE, // T_METADATA = 17, |
1025 BAD_ALLOCATION_TYPE, // T_CONFLICT = 18, | |
1033 BAD_ALLOCATION_TYPE, // 0 | 1026 BAD_ALLOCATION_TYPE, // 0 |
1034 BAD_ALLOCATION_TYPE, // 1 | 1027 BAD_ALLOCATION_TYPE, // 1 |
1035 BAD_ALLOCATION_TYPE, // 2 | 1028 BAD_ALLOCATION_TYPE, // 2 |
1036 BAD_ALLOCATION_TYPE, // 3 | 1029 BAD_ALLOCATION_TYPE, // 3 |
1037 STATIC_BYTE , // T_BOOLEAN = 4, | 1030 STATIC_BYTE , // T_BOOLEAN = 4, |
1045 STATIC_OOP, // T_OBJECT = 12, | 1038 STATIC_OOP, // T_OBJECT = 12, |
1046 STATIC_OOP, // T_ARRAY = 13, | 1039 STATIC_OOP, // T_ARRAY = 13, |
1047 BAD_ALLOCATION_TYPE, // T_VOID = 14, | 1040 BAD_ALLOCATION_TYPE, // T_VOID = 14, |
1048 BAD_ALLOCATION_TYPE, // T_ADDRESS = 15, | 1041 BAD_ALLOCATION_TYPE, // T_ADDRESS = 15, |
1049 BAD_ALLOCATION_TYPE, // T_NARROWOOP= 16, | 1042 BAD_ALLOCATION_TYPE, // T_NARROWOOP= 16, |
1050 BAD_ALLOCATION_TYPE, // T_CONFLICT = 17, | 1043 BAD_ALLOCATION_TYPE, // T_METADATA = 17, |
1044 BAD_ALLOCATION_TYPE, // T_CONFLICT = 18, | |
1051 }; | 1045 }; |
1052 | 1046 |
1053 static FieldAllocationType basic_type_to_atype(bool is_static, BasicType type) { | 1047 static FieldAllocationType basic_type_to_atype(bool is_static, BasicType type) { |
1054 assert(type >= T_BOOLEAN && type < T_VOID, "only allowable values"); | 1048 assert(type >= T_BOOLEAN && type < T_VOID, "only allowable values"); |
1055 FieldAllocationType result = _basic_type_to_atype[type + (is_static ? (T_CONFLICT + 1) : 0)]; | 1049 FieldAllocationType result = _basic_type_to_atype[type + (is_static ? (T_CONFLICT + 1) : 0)]; |
1074 count[atype]++; | 1068 count[atype]++; |
1075 return atype; | 1069 return atype; |
1076 } | 1070 } |
1077 }; | 1071 }; |
1078 | 1072 |
1079 | 1073 Array<u2>* ClassFileParser::parse_fields(ClassLoaderData* loader_data, |
1080 typeArrayHandle ClassFileParser::parse_fields(Symbol* class_name, | 1074 Symbol* class_name, |
1081 constantPoolHandle cp, bool is_interface, | 1075 constantPoolHandle cp, bool is_interface, |
1082 FieldAllocationCount *fac, | 1076 FieldAllocationCount *fac, |
1083 objArrayHandle* fields_annotations, | 1077 Array<AnnotationArray*>** fields_annotations, |
1084 u2* java_fields_count_ptr, TRAPS) { | 1078 u2* java_fields_count_ptr, TRAPS) { |
1085 ClassFileStream* cfs = stream(); | 1079 ClassFileStream* cfs = stream(); |
1086 typeArrayHandle nullHandle; | 1080 cfs->guarantee_more(2, CHECK_NULL); // length |
1087 cfs->guarantee_more(2, CHECK_(nullHandle)); // length | |
1088 u2 length = cfs->get_u2_fast(); | 1081 u2 length = cfs->get_u2_fast(); |
1089 *java_fields_count_ptr = length; | 1082 *java_fields_count_ptr = length; |
1090 | 1083 |
1091 int num_injected = 0; | 1084 int num_injected = 0; |
1092 InjectedField* injected = JavaClasses::get_injected(class_name, &num_injected); | 1085 InjectedField* injected = JavaClasses::get_injected(class_name, &num_injected); |
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) { |
1242 // Now copy the fields' data from the temporary resource array. | 1237 // Now copy the fields' data from the temporary resource array. |
1243 // Sometimes injected fields already exist in the Java source so | 1238 // Sometimes injected fields already exist in the Java source so |
1244 // the fields array could be too long. In that case the | 1239 // the fields array could be too long. In that case the |
1245 // fields array is trimed. Also unused slots that were reserved | 1240 // fields array is trimed. Also unused slots that were reserved |
1246 // for generic signature indexes are discarded. | 1241 // for generic signature indexes are discarded. |
1247 typeArrayOop new_fields = oopFactory::new_permanent_shortArray( | 1242 Array<u2>* fields = MetadataFactory::new_array<u2>( |
1248 index * FieldInfo::field_slots + num_generic_signature, | 1243 loader_data, index * FieldInfo::field_slots + num_generic_signature, |
1249 CHECK_(nullHandle)); | 1244 CHECK_NULL); |
1250 typeArrayHandle fields(THREAD, new_fields); | |
1251 { | 1245 { |
1252 int i = 0; | 1246 int i = 0; |
1253 for (; i < index * FieldInfo::field_slots; i++) { | 1247 for (; i < index * FieldInfo::field_slots; i++) { |
1254 new_fields->short_at_put(i, fa[i]); | 1248 fields->at_put(i, fa[i]); |
1255 } | 1249 } |
1256 for (int j = total_fields * FieldInfo::field_slots; | 1250 for (int j = total_fields * FieldInfo::field_slots; |
1257 j < generic_signature_slot; j++) { | 1251 j < generic_signature_slot; j++) { |
1258 new_fields->short_at_put(i++, fa[j]); | 1252 fields->at_put(i++, fa[j]); |
1259 } | 1253 } |
1260 assert(i == new_fields->length(), ""); | 1254 assert(i == fields->length(), ""); |
1261 } | 1255 } |
1262 | 1256 |
1263 if (_need_verify && length > 1) { | 1257 if (_need_verify && length > 1) { |
1264 // Check duplicated fields | 1258 // Check duplicated fields |
1265 ResourceMark rm(THREAD); | 1259 ResourceMark rm(THREAD); |
1279 } | 1273 } |
1280 } | 1274 } |
1281 } | 1275 } |
1282 if (dup) { | 1276 if (dup) { |
1283 classfile_parse_error("Duplicate field name&signature in class file %s", | 1277 classfile_parse_error("Duplicate field name&signature in class file %s", |
1284 CHECK_(nullHandle)); | 1278 CHECK_NULL); |
1285 } | 1279 } |
1286 } | 1280 } |
1287 | 1281 |
1288 return fields; | 1282 return fields; |
1289 } | 1283 } |
1294 *dest++ = Bytes::get_Java_u2((u1*) (src++)); | 1288 *dest++ = Bytes::get_Java_u2((u1*) (src++)); |
1295 } | 1289 } |
1296 } | 1290 } |
1297 | 1291 |
1298 | 1292 |
1299 u2* ClassFileParser::parse_exception_table(u4 code_length, | 1293 u2* ClassFileParser::parse_exception_table(ClassLoaderData* loader_data, |
1294 u4 code_length, | |
1300 u4 exception_table_length, | 1295 u4 exception_table_length, |
1301 constantPoolHandle cp, | 1296 constantPoolHandle cp, |
1302 TRAPS) { | 1297 TRAPS) { |
1303 ClassFileStream* cfs = stream(); | 1298 ClassFileStream* cfs = stream(); |
1304 | 1299 |
1576 u2_array[*u2_index] = index; | 1571 u2_array[*u2_index] = index; |
1577 *u1_index = i1; | 1572 *u1_index = i1; |
1578 *u2_index = i2; | 1573 *u2_index = i2; |
1579 } | 1574 } |
1580 | 1575 |
1581 typeArrayOop ClassFileParser::parse_stackmap_table( | 1576 Array<u1>* ClassFileParser::parse_stackmap_table( |
1577 ClassLoaderData* loader_data, | |
1582 u4 code_attribute_length, TRAPS) { | 1578 u4 code_attribute_length, TRAPS) { |
1583 if (code_attribute_length == 0) | 1579 if (code_attribute_length == 0) |
1584 return NULL; | 1580 return NULL; |
1585 | 1581 |
1586 ClassFileStream* cfs = stream(); | 1582 ClassFileStream* cfs = stream(); |
1592 | 1588 |
1593 if (!_need_verify && !DumpSharedSpaces) { | 1589 if (!_need_verify && !DumpSharedSpaces) { |
1594 return NULL; | 1590 return NULL; |
1595 } | 1591 } |
1596 | 1592 |
1597 typeArrayOop stackmap_data = | 1593 Array<u1>* stackmap_data = |
1598 oopFactory::new_permanent_byteArray(code_attribute_length, CHECK_NULL); | 1594 MetadataFactory::new_array<u1>(loader_data, code_attribute_length, 0, CHECK_NULL); |
1599 | 1595 |
1600 stackmap_data->set_length(code_attribute_length); | 1596 memcpy((void*)stackmap_data->adr_at(0), |
1601 memcpy((void*)stackmap_data->byte_at_addr(0), | |
1602 (void*)stackmap_table_start, code_attribute_length); | 1597 (void*)stackmap_table_start, code_attribute_length); |
1603 return stackmap_data; | 1598 return stackmap_data; |
1604 } | 1599 } |
1605 | 1600 |
1606 u2* ClassFileParser::parse_checked_exceptions(u2* checked_exceptions_length, | 1601 u2* ClassFileParser::parse_checked_exceptions(u2* checked_exceptions_length, |
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 |
1880 u2 max_locals = 0; | 1877 u2 max_locals = 0; |
1881 u4 code_length = 0; | 1878 u4 code_length = 0; |
1882 u1* code_start = 0; | 1879 u1* code_start = 0; |
1883 u2 exception_table_length = 0; | 1880 u2 exception_table_length = 0; |
1884 u2* exception_table_start = NULL; | 1881 u2* exception_table_start = NULL; |
1885 typeArrayHandle exception_handlers(THREAD, Universe::the_empty_int_array()); | 1882 Array<int>* exception_handlers = Universe::the_empty_int_array(); |
1886 u2 checked_exceptions_length = 0; | 1883 u2 checked_exceptions_length = 0; |
1887 u2* checked_exceptions_start = NULL; | 1884 u2* checked_exceptions_start = NULL; |
1888 CompressedLineNumberWriteStream* linenumber_table = NULL; | 1885 CompressedLineNumberWriteStream* linenumber_table = NULL; |
1889 int linenumber_table_length = 0; | 1886 int linenumber_table_length = 0; |
1890 int total_lvt_length = 0; | 1887 int total_lvt_length = 0; |
1899 u2** localvariable_type_table_start; | 1896 u2** localvariable_type_table_start; |
1900 bool parsed_code_attribute = false; | 1897 bool parsed_code_attribute = false; |
1901 bool parsed_checked_exceptions_attribute = false; | 1898 bool parsed_checked_exceptions_attribute = false; |
1902 bool parsed_stackmap_attribute = false; | 1899 bool parsed_stackmap_attribute = false; |
1903 // stackmap attribute - JDK1.5 | 1900 // stackmap attribute - JDK1.5 |
1904 typeArrayHandle stackmap_data; | 1901 Array<u1>* stackmap_data = NULL; |
1905 u2 generic_signature_index = 0; | 1902 u2 generic_signature_index = 0; |
1906 MethodAnnotationCollector parsed_annotations; | 1903 MethodAnnotationCollector parsed_annotations; |
1907 u1* runtime_visible_annotations = NULL; | 1904 u1* runtime_visible_annotations = NULL; |
1908 int runtime_visible_annotations_length = 0; | 1905 int runtime_visible_annotations_length = 0; |
1909 u1* runtime_invisible_annotations = NULL; | 1906 u1* runtime_invisible_annotations = NULL; |
1968 // Exception handler table | 1965 // Exception handler table |
1969 cfs->guarantee_more(2, CHECK_(nullHandle)); // exception_table_length | 1966 cfs->guarantee_more(2, CHECK_(nullHandle)); // exception_table_length |
1970 exception_table_length = cfs->get_u2_fast(); | 1967 exception_table_length = cfs->get_u2_fast(); |
1971 if (exception_table_length > 0) { | 1968 if (exception_table_length > 0) { |
1972 exception_table_start = | 1969 exception_table_start = |
1973 parse_exception_table(code_length, exception_table_length, cp, CHECK_(nullHandle)); | 1970 parse_exception_table(loader_data, code_length, exception_table_length, cp, CHECK_(nullHandle)); |
1974 } | 1971 } |
1975 | 1972 |
1976 // Parse additional attributes in code attribute | 1973 // Parse additional attributes in code attribute |
1977 cfs->guarantee_more(2, CHECK_(nullHandle)); // code_attributes_count | 1974 cfs->guarantee_more(2, CHECK_(nullHandle)); // code_attributes_count |
1978 u2 code_attributes_count = cfs->get_u2_fast(); | 1975 u2 code_attributes_count = cfs->get_u2_fast(); |
2077 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_stack_map_table()) { | 2074 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_stack_map_table()) { |
2078 // Stack map is only needed by the new verifier in JDK1.5. | 2075 // Stack map is only needed by the new verifier in JDK1.5. |
2079 if (parsed_stackmap_attribute) { | 2076 if (parsed_stackmap_attribute) { |
2080 classfile_parse_error("Multiple StackMapTable attributes in class file %s", CHECK_(nullHandle)); | 2077 classfile_parse_error("Multiple StackMapTable attributes in class file %s", CHECK_(nullHandle)); |
2081 } | 2078 } |
2082 typeArrayOop sm = | 2079 stackmap_data = parse_stackmap_table(loader_data, code_attribute_length, CHECK_(nullHandle)); |
2083 parse_stackmap_table(code_attribute_length, CHECK_(nullHandle)); | |
2084 stackmap_data = typeArrayHandle(THREAD, sm); | |
2085 parsed_stackmap_attribute = true; | 2080 parsed_stackmap_attribute = true; |
2086 } else { | 2081 } else { |
2087 // Skip unknown attributes | 2082 // Skip unknown attributes |
2088 cfs->skip_u1(code_attribute_length, CHECK_(nullHandle)); | 2083 cfs->skip_u1(code_attribute_length, CHECK_(nullHandle)); |
2089 } | 2084 } |
2171 if (_need_verify) { | 2166 if (_need_verify) { |
2172 guarantee_property(access_flags.is_native() || access_flags.is_abstract() || parsed_code_attribute, | 2167 guarantee_property(access_flags.is_native() || access_flags.is_abstract() || parsed_code_attribute, |
2173 "Absent Code attribute in method that is not native or abstract in class file %s", CHECK_(nullHandle)); | 2168 "Absent Code attribute in method that is not native or abstract in class file %s", CHECK_(nullHandle)); |
2174 } | 2169 } |
2175 | 2170 |
2176 // All sizing information for a methodOop is finally available, now create it | 2171 // All sizing information for a Method* is finally available, now create it |
2177 methodOop m_oop = oopFactory::new_method(code_length, access_flags, | 2172 Method* m = Method::allocate(loader_data, |
2173 code_length, | |
2174 access_flags, | |
2178 linenumber_table_length, | 2175 linenumber_table_length, |
2179 total_lvt_length, | 2176 total_lvt_length, |
2180 exception_table_length, | 2177 exception_table_length, |
2181 checked_exceptions_length, | 2178 checked_exceptions_length, |
2182 oopDesc::IsSafeConc, | |
2183 CHECK_(nullHandle)); | 2179 CHECK_(nullHandle)); |
2184 methodHandle m (THREAD, m_oop); | 2180 |
2185 | 2181 ClassLoadingService::add_class_method_size(m->size()*HeapWordSize); |
2186 ClassLoadingService::add_class_method_size(m_oop->size()*HeapWordSize); | |
2187 | 2182 |
2188 // Fill in information from fixed part (access_flags already set) | 2183 // Fill in information from fixed part (access_flags already set) |
2189 m->set_constants(cp()); | 2184 m->set_constants(cp()); |
2190 m->set_name_index(name_index); | 2185 m->set_name_index(name_index); |
2191 m->set_signature_index(signature_index); | 2186 m->set_signature_index(signature_index); |
2210 | 2205 |
2211 // Fill in code attribute information | 2206 // Fill in code attribute information |
2212 m->set_max_stack(max_stack); | 2207 m->set_max_stack(max_stack); |
2213 m->set_max_locals(max_locals); | 2208 m->set_max_locals(max_locals); |
2214 | 2209 |
2215 /** | 2210 m->constMethod()->set_stackmap_data(stackmap_data); |
2216 * The stackmap_data field is the flag used to indicate | |
2217 * that the methodOop and it's associated constMethodOop are partially | |
2218 * initialized and thus are exempt from pre/post GC verification. Once | |
2219 * the field is set, the oops are considered fully initialized so make | |
2220 * sure that the oops can pass verification when this field is set. | |
2221 */ | |
2222 m->constMethod()->set_stackmap_data(stackmap_data()); | |
2223 | 2211 |
2224 // Copy byte codes | 2212 // Copy byte codes |
2225 m->set_code(code_start); | 2213 m->set_code(code_start); |
2226 | 2214 |
2227 // Copy line number table | 2215 // Copy line number table |
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) { |
2530 | 2510 |
2531 // Inner classes can be static, private or protected (classic VM does this) | 2511 // Inner classes can be static, private or protected (classic VM does this) |
2532 #define RECOGNIZED_INNER_CLASS_MODIFIERS (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_PRIVATE | JVM_ACC_PROTECTED | JVM_ACC_STATIC) | 2512 #define RECOGNIZED_INNER_CLASS_MODIFIERS (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_PRIVATE | JVM_ACC_PROTECTED | JVM_ACC_STATIC) |
2533 | 2513 |
2534 // Return number of classes in the inner classes attribute table | 2514 // Return number of classes in the inner classes attribute table |
2535 u2 ClassFileParser::parse_classfile_inner_classes_attribute(u1* inner_classes_attribute_start, | 2515 u2 ClassFileParser::parse_classfile_inner_classes_attribute(ClassLoaderData* loader_data, |
2516 u1* inner_classes_attribute_start, | |
2536 bool parsed_enclosingmethod_attribute, | 2517 bool parsed_enclosingmethod_attribute, |
2537 u2 enclosing_method_class_index, | 2518 u2 enclosing_method_class_index, |
2538 u2 enclosing_method_method_index, | 2519 u2 enclosing_method_method_index, |
2539 constantPoolHandle cp, | 2520 constantPoolHandle cp, |
2540 TRAPS) { | 2521 TRAPS) { |
2555 // inner_class_access_flags, | 2536 // inner_class_access_flags, |
2556 // ... | 2537 // ... |
2557 // enclosing_method_class_index, | 2538 // enclosing_method_class_index, |
2558 // enclosing_method_method_index] | 2539 // enclosing_method_method_index] |
2559 int size = length * 4 + (parsed_enclosingmethod_attribute ? 2 : 0); | 2540 int size = length * 4 + (parsed_enclosingmethod_attribute ? 2 : 0); |
2560 typeArrayOop ic = oopFactory::new_permanent_shortArray(size, CHECK_0); | 2541 // FIXME: Will leak on exceptions. |
2561 typeArrayHandle inner_classes(THREAD, ic); | 2542 Array<u2>* inner_classes = MetadataFactory::new_array<u2>(loader_data, size, CHECK_0); |
2562 int index = 0; | 2543 int index = 0; |
2563 int cp_size = cp->length(); | 2544 int cp_size = cp->length(); |
2564 cfs->guarantee_more(8 * length, CHECK_0); // 4-tuples of u2 | 2545 cfs->guarantee_more(8 * length, CHECK_0); // 4-tuples of u2 |
2565 for (int n = 0; n < length; n++) { | 2546 for (int n = 0; n < length; n++) { |
2566 // Inner class index | 2547 // Inner class index |
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 |
2649 "Invalid constant pool index %u in Signature attribute in class file %s", | 2630 "Invalid constant pool index %u in Signature attribute in class file %s", |
2650 signature_index, CHECK); | 2631 signature_index, CHECK); |
2651 set_class_generic_signature(cp->symbol_at(signature_index)); | 2632 set_class_generic_signature(cp->symbol_at(signature_index)); |
2652 } | 2633 } |
2653 | 2634 |
2654 void ClassFileParser::parse_classfile_bootstrap_methods_attribute(constantPoolHandle cp, | 2635 void ClassFileParser::parse_classfile_bootstrap_methods_attribute(ClassLoaderData* loader_data, |
2636 constantPoolHandle cp, | |
2655 u4 attribute_byte_length, TRAPS) { | 2637 u4 attribute_byte_length, TRAPS) { |
2656 ClassFileStream* cfs = stream(); | 2638 ClassFileStream* cfs = stream(); |
2657 u1* current_start = cfs->current(); | 2639 u1* current_start = cfs->current(); |
2658 | 2640 |
2659 cfs->guarantee_more(2, CHECK); // length | 2641 cfs->guarantee_more(2, CHECK); // length |
2671 | 2653 |
2672 // The attribute is copied into a short[] array. | 2654 // The attribute is copied into a short[] array. |
2673 // The array begins with a series of short[2] pairs, one for each tuple. | 2655 // The array begins with a series of short[2] pairs, one for each tuple. |
2674 int index_size = (attribute_array_length * 2); | 2656 int index_size = (attribute_array_length * 2); |
2675 | 2657 |
2676 typeArrayOop operands_oop = oopFactory::new_permanent_intArray(index_size + operand_count, CHECK); | 2658 Array<u2>* operands = MetadataFactory::new_array<u2>(loader_data, index_size + operand_count, CHECK); |
2677 typeArrayHandle operands(THREAD, operands_oop); | |
2678 operands_oop = NULL; // tidy | |
2679 | 2659 |
2680 int operand_fill_index = index_size; | 2660 int operand_fill_index = index_size; |
2681 int cp_size = cp->length(); | 2661 int cp_size = cp->length(); |
2682 | 2662 |
2683 for (int n = 0; n < attribute_array_length; n++) { | 2663 for (int n = 0; n < attribute_array_length; n++) { |
2684 // Store a 32-bit offset into the header of the operand array. | 2664 // Store a 32-bit offset into the header of the operand array. |
2685 assert(constantPoolOopDesc::operand_offset_at(operands(), n) == 0, ""); | 2665 ConstantPool::operand_offset_at_put(operands, n, operand_fill_index); |
2686 constantPoolOopDesc::operand_offset_at_put(operands(), n, operand_fill_index); | |
2687 | 2666 |
2688 // Read a bootstrap specifier. | 2667 // Read a bootstrap specifier. |
2689 cfs->guarantee_more(sizeof(u2) * 2, CHECK); // bsm, argc | 2668 cfs->guarantee_more(sizeof(u2) * 2, CHECK); // bsm, argc |
2690 u2 bootstrap_method_index = cfs->get_u2_fast(); | 2669 u2 bootstrap_method_index = cfs->get_u2_fast(); |
2691 u2 argument_count = cfs->get_u2_fast(); | 2670 u2 argument_count = cfs->get_u2_fast(); |
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 |
2933 // If RedefineClasses() was used before the retransformable | 2923 // If RedefineClasses() was used before the retransformable |
2934 // agent attached, then the cached class bytes may not be the | 2924 // agent attached, then the cached class bytes may not be the |
2935 // original class bytes. | 2925 // original class bytes. |
2936 unsigned char *cached_class_file_bytes = NULL; | 2926 unsigned char *cached_class_file_bytes = NULL; |
2937 jint cached_class_file_length; | 2927 jint cached_class_file_length; |
2928 ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader()); | |
2938 | 2929 |
2939 ClassFileStream* cfs = stream(); | 2930 ClassFileStream* cfs = stream(); |
2940 // Timing | 2931 // Timing |
2941 assert(THREAD->is_Java_thread(), "must be a JavaThread"); | 2932 assert(THREAD->is_Java_thread(), "must be a JavaThread"); |
2942 JavaThread* jt = (JavaThread*) THREAD; | 2933 JavaThread* jt = (JavaThread*) THREAD; |
3041 // Check if verification needs to be relaxed for this class file | 3032 // Check if verification needs to be relaxed for this class file |
3042 // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376) | 3033 // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376) |
3043 _relax_verify = Verifier::relax_verify_for(class_loader()); | 3034 _relax_verify = Verifier::relax_verify_for(class_loader()); |
3044 | 3035 |
3045 // Constant pool | 3036 // Constant pool |
3046 constantPoolHandle cp = parse_constant_pool(class_loader, CHECK_(nullHandle)); | 3037 constantPoolHandle cp = parse_constant_pool(loader_data, CHECK_(nullHandle)); |
3047 ConstantPoolCleaner error_handler(cp); // set constant pool to be cleaned up. | 3038 ConstantPoolCleaner error_handler(cp); // set constant pool to be cleaned up. |
3048 | 3039 |
3049 int cp_size = cp->length(); | 3040 int cp_size = cp->length(); |
3050 | 3041 |
3051 cfs->guarantee_more(8, CHECK_(nullHandle)); // flags, this_class, super_class, infs_len | 3042 cfs->guarantee_more(8, CHECK_(nullHandle)); // flags, this_class, super_class, infs_len |
3090 guarantee_property(class_name->byte_at(0) != JVM_SIGNATURE_ARRAY, | 3081 guarantee_property(class_name->byte_at(0) != JVM_SIGNATURE_ARRAY, |
3091 "Bad class name in class file %s", | 3082 "Bad class name in class file %s", |
3092 CHECK_(nullHandle)); | 3083 CHECK_(nullHandle)); |
3093 } | 3084 } |
3094 | 3085 |
3095 klassOop preserve_this_klass; // for storing result across HandleMark | 3086 Klass* preserve_this_klass; // for storing result across HandleMark |
3096 | 3087 |
3097 // release all handles when parsing is done | 3088 // release all handles when parsing is done |
3098 { HandleMark hm(THREAD); | 3089 { HandleMark hm(THREAD); |
3099 | 3090 |
3100 // Checks if name in class file matches requested name | 3091 // Checks if name in class file matches requested name |
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 |
3196 // errors not checked yet. | 3184 // errors not checked yet. |
3197 guarantee_property(sk == vmSymbols::java_lang_Object(), | 3185 guarantee_property(sk == vmSymbols::java_lang_Object(), |
3198 "Interfaces must have java.lang.Object as superclass in class file %s", | 3186 "Interfaces must have java.lang.Object as superclass in class file %s", |
3199 CHECK_(nullHandle)); | 3187 CHECK_(nullHandle)); |
3200 } | 3188 } |
3201 klassOop k = SystemDictionary::resolve_super_or_fail(class_name, | 3189 Klass* k = SystemDictionary::resolve_super_or_fail(class_name, |
3202 sk, | 3190 sk, |
3203 class_loader, | 3191 class_loader, |
3204 protection_domain, | 3192 protection_domain, |
3205 true, | 3193 true, |
3206 CHECK_(nullHandle)); | 3194 CHECK_(nullHandle)); |
3227 THROW_MSG_(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class", nullHandle); | 3215 THROW_MSG_(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class", nullHandle); |
3228 } | 3216 } |
3229 } | 3217 } |
3230 | 3218 |
3231 // Compute the transitive list of all unique interfaces implemented by this class | 3219 // Compute the transitive list of all unique interfaces implemented by this class |
3232 objArrayHandle transitive_interfaces = compute_transitive_interfaces(super_klass, local_interfaces, CHECK_(nullHandle)); | 3220 Array<Klass*>* transitive_interfaces = compute_transitive_interfaces(loader_data, super_klass, local_interfaces, CHECK_(nullHandle)); |
3233 | 3221 |
3234 // sort methods | 3222 // sort methods |
3235 typeArrayHandle method_ordering = sort_methods(methods, | 3223 Array<int>* method_ordering = sort_methods(loader_data, |
3224 methods, | |
3236 methods_annotations, | 3225 methods_annotations, |
3237 methods_parameter_annotations, | 3226 methods_parameter_annotations, |
3238 methods_default_annotations, | 3227 methods_default_annotations, |
3239 CHECK_(nullHandle)); | 3228 CHECK_(nullHandle)); |
3240 | 3229 |
3247 int num_miranda_methods = 0; | 3236 int num_miranda_methods = 0; |
3248 | 3237 |
3249 klassVtable::compute_vtable_size_and_num_mirandas(vtable_size, | 3238 klassVtable::compute_vtable_size_and_num_mirandas(vtable_size, |
3250 num_miranda_methods, | 3239 num_miranda_methods, |
3251 super_klass(), | 3240 super_klass(), |
3252 methods(), | 3241 methods, |
3253 access_flags, | 3242 access_flags, |
3254 class_loader, | 3243 class_loader, |
3255 class_name, | 3244 class_name, |
3256 local_interfaces(), | 3245 local_interfaces, |
3257 CHECK_(nullHandle)); | 3246 CHECK_(nullHandle)); |
3258 | 3247 |
3259 // Size of Java itable (in words) | 3248 // Size of Java itable (in words) |
3260 itable_size = access_flags.is_interface() ? 0 : klassItable::compute_itable_size(transitive_interfaces); | 3249 itable_size = access_flags.is_interface() ? 0 : klassItable::compute_itable_size(transitive_interfaces); |
3261 | 3250 |
3595 rt = REF_NONE; | 3584 rt = REF_NONE; |
3596 } else { | 3585 } else { |
3597 rt = super_klass->reference_type(); | 3586 rt = super_klass->reference_type(); |
3598 } | 3587 } |
3599 | 3588 |
3600 // We can now create the basic klassOop for this klass | 3589 // We can now create the basic Klass* for this klass |
3601 klassOop ik = oopFactory::new_instanceKlass(name, vtable_size, itable_size, | 3590 int total_oop_map_size2 = |
3591 InstanceKlass::nonstatic_oop_map_size(total_oop_map_count); | |
3592 | |
3593 Klass* ik = InstanceKlass::allocate_instance_klass(loader_data, | |
3594 vtable_size, | |
3595 itable_size, | |
3602 static_field_size, | 3596 static_field_size, |
3603 total_oop_map_count, | 3597 total_oop_map_size2, |
3598 rt, | |
3604 access_flags, | 3599 access_flags, |
3605 rt, host_klass, | 3600 name, |
3601 super_klass(), | |
3602 host_klass, | |
3606 CHECK_(nullHandle)); | 3603 CHECK_(nullHandle)); |
3604 | |
3605 // Add all classes to our internal class loader list here, | |
3606 // including classes in the bootstrap (NULL) class loader. | |
3607 loader_data->add_class(ik); | |
3608 | |
3607 instanceKlassHandle this_klass (THREAD, ik); | 3609 instanceKlassHandle this_klass (THREAD, ik); |
3608 | 3610 |
3609 assert(this_klass->static_field_size() == static_field_size, "sanity"); | 3611 assert(this_klass->static_field_size() == static_field_size, "sanity"); |
3610 assert(this_klass->nonstatic_oop_map_count() == total_oop_map_count, | 3612 assert(this_klass->nonstatic_oop_map_count() == total_oop_map_count, |
3611 "sanity"); | 3613 "sanity"); |
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 |
3675 ) { | 3687 ) { |
3676 this_klass->set_has_miranda_methods(); // then set a flag | 3688 this_klass->set_has_miranda_methods(); // then set a flag |
3677 } | 3689 } |
3678 | 3690 |
3679 // Fill in field values obtained by parse_classfile_attributes | 3691 // Fill in field values obtained by parse_classfile_attributes |
3680 if (parsed_annotations.has_any_annotations()) | 3692 if (parsed_annotations.has_any_annotations()) { |
3681 parsed_annotations.apply_to(this_klass); | 3693 parsed_annotations.apply_to(this_klass); |
3694 } | |
3695 // Create annotations | |
3696 if (_annotations != NULL && this_klass->annotations() == NULL) { | |
3697 Annotations* anno = Annotations::allocate(loader_data, CHECK_NULL); | |
3698 this_klass->set_annotations(anno); | |
3699 } | |
3682 apply_parsed_class_attributes(this_klass); | 3700 apply_parsed_class_attributes(this_klass); |
3683 | 3701 |
3684 // VerifyOops believes that once this has been set, the object is completely loaded. | |
3685 // Compute transitive closure of interfaces this class implements | 3702 // Compute transitive closure of interfaces this class implements |
3686 this_klass->set_transitive_interfaces(transitive_interfaces()); | 3703 this_klass->set_transitive_interfaces(transitive_interfaces); |
3687 | 3704 |
3688 // Fill in information needed to compute superclasses. | 3705 // Fill in information needed to compute superclasses. |
3689 this_klass->initialize_supers(super_klass(), CHECK_(nullHandle)); | 3706 this_klass->initialize_supers(super_klass(), CHECK_(nullHandle)); |
3690 | 3707 |
3691 // Initialize itable offset tables | 3708 // Initialize itable offset tables |
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 } |
3779 | 3807 |
3780 // preserve result across HandleMark | 3808 // preserve result across HandleMark |
3781 preserve_this_klass = this_klass(); | 3809 preserve_this_klass = this_klass(); |
3782 } | 3810 } |
3783 | 3811 |
3784 // Create new handle outside HandleMark | 3812 // Create new handle outside HandleMark (might be needed for |
3813 // Extended Class Redefinition) | |
3785 instanceKlassHandle this_klass (THREAD, preserve_this_klass); | 3814 instanceKlassHandle this_klass (THREAD, preserve_this_klass); |
3786 debug_only(this_klass->as_klassOop()->verify();) | 3815 debug_only(this_klass->verify();) |
3787 | 3816 |
3788 return this_klass; | 3817 return this_klass; |
3789 } | 3818 } |
3790 | 3819 |
3791 | 3820 |
3824 void ClassFileParser::fill_oop_maps(instanceKlassHandle k, | 3853 void ClassFileParser::fill_oop_maps(instanceKlassHandle k, |
3825 unsigned int nonstatic_oop_map_count, | 3854 unsigned int nonstatic_oop_map_count, |
3826 int* nonstatic_oop_offsets, | 3855 int* nonstatic_oop_offsets, |
3827 unsigned int* nonstatic_oop_counts) { | 3856 unsigned int* nonstatic_oop_counts) { |
3828 OopMapBlock* this_oop_map = k->start_of_nonstatic_oop_maps(); | 3857 OopMapBlock* this_oop_map = k->start_of_nonstatic_oop_maps(); |
3829 const instanceKlass* const super = k->superklass(); | 3858 const InstanceKlass* const super = k->superklass(); |
3830 const unsigned int super_count = super ? super->nonstatic_oop_map_count() : 0; | 3859 const unsigned int super_count = super ? super->nonstatic_oop_map_count() : 0; |
3831 if (super_count > 0) { | 3860 if (super_count > 0) { |
3832 // Copy maps from superklass | 3861 // Copy maps from superklass |
3833 OopMapBlock* super_oop_map = super->start_of_nonstatic_oop_maps(); | 3862 OopMapBlock* super_oop_map = super->start_of_nonstatic_oop_maps(); |
3834 for (unsigned int i = 0; i < super_count; ++i) { | 3863 for (unsigned int i = 0; i < super_count; ++i) { |
3859 } | 3888 } |
3860 } | 3889 } |
3861 | 3890 |
3862 | 3891 |
3863 void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) { | 3892 void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) { |
3864 klassOop super = k->super(); | 3893 Klass* super = k->super(); |
3865 | 3894 |
3866 // Check if this klass has an empty finalize method (i.e. one with return bytecode only), | 3895 // Check if this klass has an empty finalize method (i.e. one with return bytecode only), |
3867 // in which case we don't have to register objects as finalizable | 3896 // in which case we don't have to register objects as finalizable |
3868 if (!_has_empty_finalizer) { | 3897 if (!_has_empty_finalizer) { |
3869 if (_has_finalizer || | 3898 if (_has_finalizer || |
3870 (super != NULL && super->klass_part()->has_finalizer())) { | 3899 (super != NULL && super->has_finalizer())) { |
3871 k->set_has_finalizer(); | 3900 k->set_has_finalizer(); |
3872 } | 3901 } |
3873 } | 3902 } |
3874 | 3903 |
3875 #ifdef ASSERT | 3904 #ifdef ASSERT |
3876 bool f = false; | 3905 bool f = false; |
3877 methodOop m = k->lookup_method(vmSymbols::finalize_method_name(), | 3906 Method* m = k->lookup_method(vmSymbols::finalize_method_name(), |
3878 vmSymbols::void_method_signature()); | 3907 vmSymbols::void_method_signature()); |
3879 if (m != NULL && !m->is_empty_method()) { | 3908 if (m != NULL && !m->is_empty_method()) { |
3880 f = true; | 3909 f = true; |
3881 } | 3910 } |
3882 assert(f == k->has_finalizer(), "inconsistent has_finalizer"); | 3911 assert(f == k->has_finalizer(), "inconsistent has_finalizer"); |
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 ) { |
4092 ); | 4132 ); |
4093 return; | 4133 return; |
4094 } | 4134 } |
4095 | 4135 |
4096 // continue to look from super_m's holder's super. | 4136 // continue to look from super_m's holder's super. |
4097 k = instanceKlass::cast(super_m->method_holder())->super(); | 4137 k = InstanceKlass::cast(super_m->method_holder())->super(); |
4098 continue; | 4138 continue; |
4099 } | 4139 } |
4100 | 4140 |
4101 k = k->klass_part()->super(); | 4141 k = k->super(); |
4102 } | 4142 } |
4103 } | 4143 } |
4104 } | 4144 } |
4105 } | 4145 } |
4106 | 4146 |
4107 | 4147 |
4108 // assumes that this_klass is an interface | 4148 // assumes that this_klass is an interface |
4109 void ClassFileParser::check_illegal_static_method(instanceKlassHandle this_klass, TRAPS) { | 4149 void ClassFileParser::check_illegal_static_method(instanceKlassHandle this_klass, TRAPS) { |
4110 assert(this_klass->is_interface(), "not an interface"); | 4150 assert(this_klass->is_interface(), "not an interface"); |
4111 objArrayHandle methods (THREAD, this_klass->methods()); | 4151 Array<Method*>* methods = this_klass->methods(); |
4112 int num_methods = methods->length(); | 4152 int num_methods = methods->length(); |
4113 | 4153 |
4114 for (int index = 0; index < num_methods; index++) { | 4154 for (int index = 0; index < num_methods; index++) { |
4115 methodOop m = (methodOop)methods->obj_at(index); | 4155 Method* m = methods->at(index); |
4116 // if m is static and not the init method, throw a verify error | 4156 // if m is static and not the init method, throw a verify error |
4117 if ((m->is_static()) && (m->name() != vmSymbols::class_initializer_name())) { | 4157 if ((m->is_static()) && (m->name() != vmSymbols::class_initializer_name())) { |
4118 ResourceMark rm(THREAD); | 4158 ResourceMark rm(THREAD); |
4119 Exceptions::fthrow( | 4159 Exceptions::fthrow( |
4120 THREAD_AND_LOCATION, | 4160 THREAD_AND_LOCATION, |