comparison src/share/vm/classfile/classFileParser.cpp @ 12355:cefad50507d8

Merge with hs25-b53
author Gilles Duboscq <duboscq@ssw.jku.at>
date Fri, 11 Oct 2013 10:38:03 +0200
parents 6b0fd0964b87 268e7a2178d7
children 096c224171c4
comparison
equal deleted inserted replaced
12058:ccb4f2af2319 12355:cefad50507d8
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" 28 #include "classfile/classLoaderData.hpp"
29 #include "classfile/classLoaderData.inline.hpp" 29 #include "classfile/classLoaderData.inline.hpp"
30 #include "classfile/defaultMethods.hpp" 30 #include "classfile/defaultMethods.hpp"
31 #include "classfile/genericSignatures.hpp"
32 #include "classfile/javaClasses.hpp" 31 #include "classfile/javaClasses.hpp"
33 #include "classfile/symbolTable.hpp" 32 #include "classfile/symbolTable.hpp"
34 #include "classfile/systemDictionary.hpp" 33 #include "classfile/systemDictionary.hpp"
35 #include "classfile/verificationType.hpp" 34 #include "classfile/verificationType.hpp"
36 #include "classfile/verifier.hpp" 35 #include "classfile/verifier.hpp"
887 int runtime_invisible_annotations_length = 0; 886 int runtime_invisible_annotations_length = 0;
888 u1* runtime_visible_type_annotations = NULL; 887 u1* runtime_visible_type_annotations = NULL;
889 int runtime_visible_type_annotations_length = 0; 888 int runtime_visible_type_annotations_length = 0;
890 u1* runtime_invisible_type_annotations = NULL; 889 u1* runtime_invisible_type_annotations = NULL;
891 int runtime_invisible_type_annotations_length = 0; 890 int runtime_invisible_type_annotations_length = 0;
891 bool runtime_invisible_type_annotations_exists = false;
892 while (attributes_count--) { 892 while (attributes_count--) {
893 cfs->guarantee_more(6, CHECK); // attribute_name_index, attribute_length 893 cfs->guarantee_more(6, CHECK); // attribute_name_index, attribute_length
894 u2 attribute_name_index = cfs->get_u2_fast(); 894 u2 attribute_name_index = cfs->get_u2_fast();
895 u4 attribute_length = cfs->get_u4_fast(); 895 u4 attribute_length = cfs->get_u4_fast();
896 check_property(valid_symbol_at(attribute_name_index), 896 check_property(valid_symbol_at(attribute_name_index),
945 runtime_invisible_annotations_length = attribute_length; 945 runtime_invisible_annotations_length = attribute_length;
946 runtime_invisible_annotations = cfs->get_u1_buffer(); 946 runtime_invisible_annotations = cfs->get_u1_buffer();
947 assert(runtime_invisible_annotations != NULL, "null invisible annotations"); 947 assert(runtime_invisible_annotations != NULL, "null invisible annotations");
948 cfs->skip_u1(runtime_invisible_annotations_length, CHECK); 948 cfs->skip_u1(runtime_invisible_annotations_length, CHECK);
949 } else if (attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) { 949 } else if (attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) {
950 if (runtime_visible_type_annotations != NULL) {
951 classfile_parse_error(
952 "Multiple RuntimeVisibleTypeAnnotations attributes for field in class file %s", CHECK);
953 }
950 runtime_visible_type_annotations_length = attribute_length; 954 runtime_visible_type_annotations_length = attribute_length;
951 runtime_visible_type_annotations = cfs->get_u1_buffer(); 955 runtime_visible_type_annotations = cfs->get_u1_buffer();
952 assert(runtime_visible_type_annotations != NULL, "null visible type annotations"); 956 assert(runtime_visible_type_annotations != NULL, "null visible type annotations");
953 cfs->skip_u1(runtime_visible_type_annotations_length, CHECK); 957 cfs->skip_u1(runtime_visible_type_annotations_length, CHECK);
954 } else if (PreserveAllAnnotations && attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) { 958 } else if (attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) {
955 runtime_invisible_type_annotations_length = attribute_length; 959 if (runtime_invisible_type_annotations_exists) {
956 runtime_invisible_type_annotations = cfs->get_u1_buffer(); 960 classfile_parse_error(
957 assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations"); 961 "Multiple RuntimeInvisibleTypeAnnotations attributes for field in class file %s", CHECK);
958 cfs->skip_u1(runtime_invisible_type_annotations_length, CHECK); 962 } else {
963 runtime_invisible_type_annotations_exists = true;
964 }
965 if (PreserveAllAnnotations) {
966 runtime_invisible_type_annotations_length = attribute_length;
967 runtime_invisible_type_annotations = cfs->get_u1_buffer();
968 assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations");
969 }
970 cfs->skip_u1(attribute_length, CHECK);
959 } else { 971 } else {
960 cfs->skip_u1(attribute_length, CHECK); // Skip unknown attributes 972 cfs->skip_u1(attribute_length, CHECK); // Skip unknown attributes
961 } 973 }
962 } else { 974 } else {
963 cfs->skip_u1(attribute_length, CHECK); // Skip unknown attributes 975 cfs->skip_u1(attribute_length, CHECK); // Skip unknown attributes
1773 return _method_LambdaForm_Compiled; 1785 return _method_LambdaForm_Compiled;
1774 case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_LambdaForm_Hidden_signature): 1786 case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_LambdaForm_Hidden_signature):
1775 if (_location != _in_method) break; // only allow for methods 1787 if (_location != _in_method) break; // only allow for methods
1776 if (!privileged) break; // only allow in privileged code 1788 if (!privileged) break; // only allow in privileged code
1777 return _method_LambdaForm_Hidden; 1789 return _method_LambdaForm_Hidden;
1790 case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_Stable_signature):
1791 if (_location != _in_field) break; // only allow for fields
1792 if (!privileged) break; // only allow in privileged code
1793 return _field_Stable;
1778 case vmSymbols::VM_SYMBOL_ENUM_NAME(sun_misc_Contended_signature): 1794 case vmSymbols::VM_SYMBOL_ENUM_NAME(sun_misc_Contended_signature):
1779 if (_location != _in_field && _location != _in_class) break; // only allow for fields and classes 1795 if (_location != _in_field && _location != _in_class) break; // only allow for fields and classes
1780 if (!EnableContended || (RestrictContended && !privileged)) break; // honor privileges 1796 if (!EnableContended || (RestrictContended && !privileged)) break; // honor privileges
1781 return _sun_misc_Contended; 1797 return _sun_misc_Contended;
1782 default: break; 1798 default: break;
1785 } 1801 }
1786 1802
1787 void ClassFileParser::FieldAnnotationCollector::apply_to(FieldInfo* f) { 1803 void ClassFileParser::FieldAnnotationCollector::apply_to(FieldInfo* f) {
1788 if (is_contended()) 1804 if (is_contended())
1789 f->set_contended_group(contended_group()); 1805 f->set_contended_group(contended_group());
1806 if (is_stable())
1807 f->set_stable(true);
1790 } 1808 }
1791 1809
1792 ClassFileParser::FieldAnnotationCollector::~FieldAnnotationCollector() { 1810 ClassFileParser::FieldAnnotationCollector::~FieldAnnotationCollector() {
1793 // If there's an error deallocate metadata for field annotations 1811 // If there's an error deallocate metadata for field annotations
1794 MetadataFactory::free_array<u1>(_loader_data, _field_annotations); 1812 MetadataFactory::free_array<u1>(_loader_data, _field_annotations);
2059 int runtime_invisible_parameter_annotations_length = 0; 2077 int runtime_invisible_parameter_annotations_length = 0;
2060 u1* runtime_visible_type_annotations = NULL; 2078 u1* runtime_visible_type_annotations = NULL;
2061 int runtime_visible_type_annotations_length = 0; 2079 int runtime_visible_type_annotations_length = 0;
2062 u1* runtime_invisible_type_annotations = NULL; 2080 u1* runtime_invisible_type_annotations = NULL;
2063 int runtime_invisible_type_annotations_length = 0; 2081 int runtime_invisible_type_annotations_length = 0;
2082 bool runtime_invisible_type_annotations_exists = false;
2064 u1* annotation_default = NULL; 2083 u1* annotation_default = NULL;
2065 int annotation_default_length = 0; 2084 int annotation_default_length = 0;
2066 2085
2067 // Parse code and exceptions attribute 2086 // Parse code and exceptions attribute
2068 u2 method_attributes_count = cfs->get_u2_fast(); 2087 u2 method_attributes_count = cfs->get_u2_fast();
2315 annotation_default_length = method_attribute_length; 2334 annotation_default_length = method_attribute_length;
2316 annotation_default = cfs->get_u1_buffer(); 2335 annotation_default = cfs->get_u1_buffer();
2317 assert(annotation_default != NULL, "null annotation default"); 2336 assert(annotation_default != NULL, "null annotation default");
2318 cfs->skip_u1(annotation_default_length, CHECK_(nullHandle)); 2337 cfs->skip_u1(annotation_default_length, CHECK_(nullHandle));
2319 } else if (method_attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) { 2338 } else if (method_attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) {
2339 if (runtime_visible_type_annotations != NULL) {
2340 classfile_parse_error(
2341 "Multiple RuntimeVisibleTypeAnnotations attributes for method in class file %s",
2342 CHECK_(nullHandle));
2343 }
2320 runtime_visible_type_annotations_length = method_attribute_length; 2344 runtime_visible_type_annotations_length = method_attribute_length;
2321 runtime_visible_type_annotations = cfs->get_u1_buffer(); 2345 runtime_visible_type_annotations = cfs->get_u1_buffer();
2322 assert(runtime_visible_type_annotations != NULL, "null visible type annotations"); 2346 assert(runtime_visible_type_annotations != NULL, "null visible type annotations");
2323 // No need for the VM to parse Type annotations 2347 // No need for the VM to parse Type annotations
2324 cfs->skip_u1(runtime_visible_type_annotations_length, CHECK_(nullHandle)); 2348 cfs->skip_u1(runtime_visible_type_annotations_length, CHECK_(nullHandle));
2325 } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) { 2349 } else if (method_attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) {
2326 runtime_invisible_type_annotations_length = method_attribute_length; 2350 if (runtime_invisible_type_annotations_exists) {
2327 runtime_invisible_type_annotations = cfs->get_u1_buffer(); 2351 classfile_parse_error(
2328 assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations"); 2352 "Multiple RuntimeInvisibleTypeAnnotations attributes for method in class file %s",
2329 cfs->skip_u1(runtime_invisible_type_annotations_length, CHECK_(nullHandle)); 2353 CHECK_(nullHandle));
2354 } else {
2355 runtime_invisible_type_annotations_exists = true;
2356 }
2357 if (PreserveAllAnnotations) {
2358 runtime_invisible_type_annotations_length = method_attribute_length;
2359 runtime_invisible_type_annotations = cfs->get_u1_buffer();
2360 assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations");
2361 }
2362 cfs->skip_u1(method_attribute_length, CHECK_(nullHandle));
2330 } else { 2363 } else {
2331 // Skip unknown attributes 2364 // Skip unknown attributes
2332 cfs->skip_u1(method_attribute_length, CHECK_(nullHandle)); 2365 cfs->skip_u1(method_attribute_length, CHECK_(nullHandle));
2333 } 2366 }
2334 } else { 2367 } else {
2510 CHECK_NULL); 2543 CHECK_NULL);
2511 2544
2512 if (method->is_final()) { 2545 if (method->is_final()) {
2513 *has_final_method = true; 2546 *has_final_method = true;
2514 } 2547 }
2515 if (is_interface && !method->is_abstract() && !method->is_static()) { 2548 if (is_interface && !(*has_default_methods)
2549 && !method->is_abstract() && !method->is_static()
2550 && !method->is_private()) {
2516 // default method 2551 // default method
2517 *has_default_methods = true; 2552 *has_default_methods = true;
2518 } 2553 }
2519 _methods->at_put(index, method()); 2554 _methods->at_put(index, method());
2520 } 2555 }
2588 u2 sourcefile_index = cfs->get_u2_fast(); 2623 u2 sourcefile_index = cfs->get_u2_fast();
2589 check_property( 2624 check_property(
2590 valid_symbol_at(sourcefile_index), 2625 valid_symbol_at(sourcefile_index),
2591 "Invalid SourceFile attribute at constant pool index %u in class file %s", 2626 "Invalid SourceFile attribute at constant pool index %u in class file %s",
2592 sourcefile_index, CHECK); 2627 sourcefile_index, CHECK);
2593 set_class_sourcefile(_cp->symbol_at(sourcefile_index)); 2628 set_class_sourcefile_index(sourcefile_index);
2594 } 2629 }
2595 2630
2596 2631
2597 2632
2598 void ClassFileParser::parse_classfile_source_debug_extension_attribute(int length, TRAPS) { 2633 void ClassFileParser::parse_classfile_source_debug_extension_attribute(int length, TRAPS) {
2726 u2 signature_index = cfs->get_u2(CHECK); 2761 u2 signature_index = cfs->get_u2(CHECK);
2727 check_property( 2762 check_property(
2728 valid_symbol_at(signature_index), 2763 valid_symbol_at(signature_index),
2729 "Invalid constant pool index %u in Signature attribute in class file %s", 2764 "Invalid constant pool index %u in Signature attribute in class file %s",
2730 signature_index, CHECK); 2765 signature_index, CHECK);
2731 set_class_generic_signature(_cp->symbol_at(signature_index)); 2766 set_class_generic_signature_index(signature_index);
2732 } 2767 }
2733 2768
2734 void ClassFileParser::parse_classfile_bootstrap_methods_attribute(u4 attribute_byte_length, TRAPS) { 2769 void ClassFileParser::parse_classfile_bootstrap_methods_attribute(u4 attribute_byte_length, TRAPS) {
2735 ClassFileStream* cfs = stream(); 2770 ClassFileStream* cfs = stream();
2736 u1* current_start = cfs->current(); 2771 u1* current_start = cfs->current();
2817 int runtime_invisible_annotations_length = 0; 2852 int runtime_invisible_annotations_length = 0;
2818 u1* runtime_visible_type_annotations = NULL; 2853 u1* runtime_visible_type_annotations = NULL;
2819 int runtime_visible_type_annotations_length = 0; 2854 int runtime_visible_type_annotations_length = 0;
2820 u1* runtime_invisible_type_annotations = NULL; 2855 u1* runtime_invisible_type_annotations = NULL;
2821 int runtime_invisible_type_annotations_length = 0; 2856 int runtime_invisible_type_annotations_length = 0;
2857 bool runtime_invisible_type_annotations_exists = false;
2822 u1* inner_classes_attribute_start = NULL; 2858 u1* inner_classes_attribute_start = NULL;
2823 u4 inner_classes_attribute_length = 0; 2859 u4 inner_classes_attribute_length = 0;
2824 u2 enclosing_method_class_index = 0; 2860 u2 enclosing_method_class_index = 0;
2825 u2 enclosing_method_method_index = 0; 2861 u2 enclosing_method_method_index = 0;
2826 // Iterate over attributes 2862 // Iterate over attributes
2920 if (parsed_bootstrap_methods_attribute) 2956 if (parsed_bootstrap_methods_attribute)
2921 classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK); 2957 classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK);
2922 parsed_bootstrap_methods_attribute = true; 2958 parsed_bootstrap_methods_attribute = true;
2923 parse_classfile_bootstrap_methods_attribute(attribute_length, CHECK); 2959 parse_classfile_bootstrap_methods_attribute(attribute_length, CHECK);
2924 } else if (tag == vmSymbols::tag_runtime_visible_type_annotations()) { 2960 } else if (tag == vmSymbols::tag_runtime_visible_type_annotations()) {
2961 if (runtime_visible_type_annotations != NULL) {
2962 classfile_parse_error(
2963 "Multiple RuntimeVisibleTypeAnnotations attributes in class file %s", CHECK);
2964 }
2925 runtime_visible_type_annotations_length = attribute_length; 2965 runtime_visible_type_annotations_length = attribute_length;
2926 runtime_visible_type_annotations = cfs->get_u1_buffer(); 2966 runtime_visible_type_annotations = cfs->get_u1_buffer();
2927 assert(runtime_visible_type_annotations != NULL, "null visible type annotations"); 2967 assert(runtime_visible_type_annotations != NULL, "null visible type annotations");
2928 // No need for the VM to parse Type annotations 2968 // No need for the VM to parse Type annotations
2929 cfs->skip_u1(runtime_visible_type_annotations_length, CHECK); 2969 cfs->skip_u1(runtime_visible_type_annotations_length, CHECK);
2930 } else if (PreserveAllAnnotations && tag == vmSymbols::tag_runtime_invisible_type_annotations()) { 2970 } else if (tag == vmSymbols::tag_runtime_invisible_type_annotations()) {
2931 runtime_invisible_type_annotations_length = attribute_length; 2971 if (runtime_invisible_type_annotations_exists) {
2932 runtime_invisible_type_annotations = cfs->get_u1_buffer(); 2972 classfile_parse_error(
2933 assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations"); 2973 "Multiple RuntimeInvisibleTypeAnnotations attributes in class file %s", CHECK);
2934 cfs->skip_u1(runtime_invisible_type_annotations_length, CHECK); 2974 } else {
2975 runtime_invisible_type_annotations_exists = true;
2976 }
2977 if (PreserveAllAnnotations) {
2978 runtime_invisible_type_annotations_length = attribute_length;
2979 runtime_invisible_type_annotations = cfs->get_u1_buffer();
2980 assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations");
2981 }
2982 cfs->skip_u1(attribute_length, CHECK);
2935 } else { 2983 } else {
2936 // Unknown attribute 2984 // Unknown attribute
2937 cfs->skip_u1(attribute_length, CHECK); 2985 cfs->skip_u1(attribute_length, CHECK);
2938 } 2986 }
2939 } else { 2987 } else {
2973 } 3021 }
2974 3022
2975 void ClassFileParser::apply_parsed_class_attributes(instanceKlassHandle k) { 3023 void ClassFileParser::apply_parsed_class_attributes(instanceKlassHandle k) {
2976 if (_synthetic_flag) 3024 if (_synthetic_flag)
2977 k->set_is_synthetic(); 3025 k->set_is_synthetic();
2978 if (_sourcefile != NULL) { 3026 if (_sourcefile_index != 0) {
2979 _sourcefile->increment_refcount(); 3027 k->set_source_file_name_index(_sourcefile_index);
2980 k->set_source_file_name(_sourcefile); 3028 }
2981 } 3029 if (_generic_signature_index != 0) {
2982 if (_generic_signature != NULL) { 3030 k->set_generic_signature_index(_generic_signature_index);
2983 _generic_signature->increment_refcount();
2984 k->set_generic_signature(_generic_signature);
2985 } 3031 }
2986 if (_sde_buffer != NULL) { 3032 if (_sde_buffer != NULL) {
2987 k->set_source_debug_extension(_sde_buffer, _sde_length); 3033 k->set_source_debug_extension(_sde_buffer, _sde_length);
2988 } 3034 }
2989 } 3035 }
3038 } 3084 }
3039 } 3085 }
3040 } 3086 }
3041 return annotations; 3087 return annotations;
3042 } 3088 }
3043
3044
3045 #ifdef ASSERT
3046 static void parseAndPrintGenericSignatures(
3047 instanceKlassHandle this_klass, TRAPS) {
3048 assert(ParseAllGenericSignatures == true, "Shouldn't call otherwise");
3049 ResourceMark rm;
3050
3051 if (this_klass->generic_signature() != NULL) {
3052 using namespace generic;
3053 ClassDescriptor* spec = ClassDescriptor::parse_generic_signature(this_klass(), CHECK);
3054
3055 tty->print_cr("Parsing %s", this_klass->generic_signature()->as_C_string());
3056 spec->print_on(tty);
3057
3058 for (int i = 0; i < this_klass->methods()->length(); ++i) {
3059 Method* m = this_klass->methods()->at(i);
3060 MethodDescriptor* method_spec = MethodDescriptor::parse_generic_signature(m, spec);
3061 Symbol* sig = m->generic_signature();
3062 if (sig == NULL) {
3063 sig = m->signature();
3064 }
3065 tty->print_cr("Parsing %s", sig->as_C_string());
3066 method_spec->print_on(tty);
3067 }
3068 }
3069 }
3070 #endif // def ASSERT
3071
3072 3089
3073 instanceKlassHandle ClassFileParser::parse_super_class(int super_class_index, 3090 instanceKlassHandle ClassFileParser::parse_super_class(int super_class_index,
3074 TRAPS) { 3091 TRAPS) {
3075 instanceKlassHandle super_klass; 3092 instanceKlassHandle super_klass;
3076 if (super_class_index == 0) { 3093 if (super_class_index == 0) {
3978 3995
3979 if (has_final_method) { 3996 if (has_final_method) {
3980 this_klass->set_has_final_method(); 3997 this_klass->set_has_final_method();
3981 } 3998 }
3982 this_klass->copy_method_ordering(method_ordering, CHECK_NULL); 3999 this_klass->copy_method_ordering(method_ordering, CHECK_NULL);
3983 // The InstanceKlass::_methods_jmethod_ids cache and the 4000 // The InstanceKlass::_methods_jmethod_ids cache
3984 // InstanceKlass::_methods_cached_itable_indices cache are 4001 // is managed on the assumption that the initial cache
3985 // both managed on the assumption that the initial cache
3986 // size is equal to the number of methods in the class. If 4002 // size is equal to the number of methods in the class. If
3987 // that changes, then InstanceKlass::idnum_can_increment() 4003 // that changes, then InstanceKlass::idnum_can_increment()
3988 // has to be changed accordingly. 4004 // has to be changed accordingly.
3989 this_klass->set_initial_method_idnum(methods->length()); 4005 this_klass->set_initial_method_idnum(methods->length());
3990 this_klass->set_name(cp->klass_name_at(this_class_index)); 4006 this_klass->set_name(cp->klass_name_at(this_class_index));
4059 } 4075 }
4060 4076
4061 // Allocate mirror and initialize static fields 4077 // Allocate mirror and initialize static fields
4062 java_lang_Class::create_mirror(this_klass, protection_domain, CHECK_(nullHandle)); 4078 java_lang_Class::create_mirror(this_klass, protection_domain, CHECK_(nullHandle));
4063 4079
4064
4065 #ifdef ASSERT
4066 if (ParseAllGenericSignatures) {
4067 parseAndPrintGenericSignatures(this_klass, CHECK_(nullHandle));
4068 }
4069 #endif
4070 4080
4071 // Generate any default methods - default methods are interface methods 4081 // Generate any default methods - default methods are interface methods
4072 // that have a default implementation. This is new with Lambda project. 4082 // that have a default implementation. This is new with Lambda project.
4073 if (has_default_methods && !access_flags.is_interface() && 4083 if (has_default_methods && !access_flags.is_interface() &&
4074 local_interfaces->length() > 0) { 4084 local_interfaces->length() > 0) {