comparison src/share/vm/classfile/classFileParser.cpp @ 7457:35431a769282

8004823: Add VM support for type annotation reflection Reviewed-by: dholmes, coleenp Contributed-by: joel.franck@oracle.com
author stefank
date Thu, 20 Dec 2012 10:22:19 +0100
parents 5fafdef522c6
children ade95d680b42
comparison
equal deleted inserted replaced
7456:7d42f3b08300 7457:35431a769282
904 bool is_static, u2 signature_index, 904 bool is_static, u2 signature_index,
905 u2* constantvalue_index_addr, 905 u2* constantvalue_index_addr,
906 bool* is_synthetic_addr, 906 bool* is_synthetic_addr,
907 u2* generic_signature_index_addr, 907 u2* generic_signature_index_addr,
908 AnnotationArray** field_annotations, 908 AnnotationArray** field_annotations,
909 AnnotationArray** field_type_annotations,
909 ClassFileParser::FieldAnnotationCollector* parsed_annotations, 910 ClassFileParser::FieldAnnotationCollector* parsed_annotations,
910 TRAPS) { 911 TRAPS) {
911 ClassFileStream* cfs = stream(); 912 ClassFileStream* cfs = stream();
912 assert(attributes_count > 0, "length should be greater than 0"); 913 assert(attributes_count > 0, "length should be greater than 0");
913 u2 constantvalue_index = 0; 914 u2 constantvalue_index = 0;
915 bool is_synthetic = false; 916 bool is_synthetic = false;
916 u1* runtime_visible_annotations = NULL; 917 u1* runtime_visible_annotations = NULL;
917 int runtime_visible_annotations_length = 0; 918 int runtime_visible_annotations_length = 0;
918 u1* runtime_invisible_annotations = NULL; 919 u1* runtime_invisible_annotations = NULL;
919 int runtime_invisible_annotations_length = 0; 920 int runtime_invisible_annotations_length = 0;
921 u1* runtime_visible_type_annotations = NULL;
922 int runtime_visible_type_annotations_length = 0;
923 u1* runtime_invisible_type_annotations = NULL;
924 int runtime_invisible_type_annotations_length = 0;
920 while (attributes_count--) { 925 while (attributes_count--) {
921 cfs->guarantee_more(6, CHECK); // attribute_name_index, attribute_length 926 cfs->guarantee_more(6, CHECK); // attribute_name_index, attribute_length
922 u2 attribute_name_index = cfs->get_u2_fast(); 927 u2 attribute_name_index = cfs->get_u2_fast();
923 u4 attribute_length = cfs->get_u4_fast(); 928 u4 attribute_length = cfs->get_u4_fast();
924 check_property(valid_cp_range(attribute_name_index, cp->length()) && 929 check_property(valid_cp_range(attribute_name_index, cp->length()) &&
969 } else if (PreserveAllAnnotations && attribute_name == vmSymbols::tag_runtime_invisible_annotations()) { 974 } else if (PreserveAllAnnotations && attribute_name == vmSymbols::tag_runtime_invisible_annotations()) {
970 runtime_invisible_annotations_length = attribute_length; 975 runtime_invisible_annotations_length = attribute_length;
971 runtime_invisible_annotations = cfs->get_u1_buffer(); 976 runtime_invisible_annotations = cfs->get_u1_buffer();
972 assert(runtime_invisible_annotations != NULL, "null invisible annotations"); 977 assert(runtime_invisible_annotations != NULL, "null invisible annotations");
973 cfs->skip_u1(runtime_invisible_annotations_length, CHECK); 978 cfs->skip_u1(runtime_invisible_annotations_length, CHECK);
979 } else if (attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) {
980 runtime_visible_type_annotations_length = attribute_length;
981 runtime_visible_type_annotations = cfs->get_u1_buffer();
982 assert(runtime_visible_type_annotations != NULL, "null visible type annotations");
983 cfs->skip_u1(runtime_visible_type_annotations_length, CHECK);
984 } else if (PreserveAllAnnotations && attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) {
985 runtime_invisible_type_annotations_length = attribute_length;
986 runtime_invisible_type_annotations = cfs->get_u1_buffer();
987 assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations");
988 cfs->skip_u1(runtime_invisible_type_annotations_length, CHECK);
974 } else { 989 } else {
975 cfs->skip_u1(attribute_length, CHECK); // Skip unknown attributes 990 cfs->skip_u1(attribute_length, CHECK); // Skip unknown attributes
976 } 991 }
977 } else { 992 } else {
978 cfs->skip_u1(attribute_length, CHECK); // Skip unknown attributes 993 cfs->skip_u1(attribute_length, CHECK); // Skip unknown attributes
985 *field_annotations = assemble_annotations(loader_data, 1000 *field_annotations = assemble_annotations(loader_data,
986 runtime_visible_annotations, 1001 runtime_visible_annotations,
987 runtime_visible_annotations_length, 1002 runtime_visible_annotations_length,
988 runtime_invisible_annotations, 1003 runtime_invisible_annotations,
989 runtime_invisible_annotations_length, 1004 runtime_invisible_annotations_length,
1005 CHECK);
1006 *field_type_annotations = assemble_annotations(loader_data,
1007 runtime_visible_type_annotations,
1008 runtime_visible_type_annotations_length,
1009 runtime_invisible_type_annotations,
1010 runtime_invisible_type_annotations_length,
990 CHECK); 1011 CHECK);
991 return; 1012 return;
992 } 1013 }
993 1014
994 1015
1082 Symbol* class_name, 1103 Symbol* class_name,
1083 constantPoolHandle cp, 1104 constantPoolHandle cp,
1084 bool is_interface, 1105 bool is_interface,
1085 FieldAllocationCount *fac, 1106 FieldAllocationCount *fac,
1086 Array<AnnotationArray*>** fields_annotations, 1107 Array<AnnotationArray*>** fields_annotations,
1108 Array<AnnotationArray*>** fields_type_annotations,
1087 u2* java_fields_count_ptr, TRAPS) { 1109 u2* java_fields_count_ptr, TRAPS) {
1088 ClassFileStream* cfs = stream(); 1110 ClassFileStream* cfs = stream();
1089 cfs->guarantee_more(2, CHECK_NULL); // length 1111 cfs->guarantee_more(2, CHECK_NULL); // length
1090 u2 length = cfs->get_u2_fast(); 1112 u2 length = cfs->get_u2_fast();
1091 *java_fields_count_ptr = length; 1113 *java_fields_count_ptr = length;
1117 ResourceMark rm(THREAD); 1139 ResourceMark rm(THREAD);
1118 u2* fa = NEW_RESOURCE_ARRAY_IN_THREAD( 1140 u2* fa = NEW_RESOURCE_ARRAY_IN_THREAD(
1119 THREAD, u2, total_fields * (FieldInfo::field_slots + 1)); 1141 THREAD, u2, total_fields * (FieldInfo::field_slots + 1));
1120 1142
1121 AnnotationArray* field_annotations = NULL; 1143 AnnotationArray* field_annotations = NULL;
1144 AnnotationArray* field_type_annotations = NULL;
1122 // The generic signature slots start after all other fields' data. 1145 // The generic signature slots start after all other fields' data.
1123 int generic_signature_slot = total_fields * FieldInfo::field_slots; 1146 int generic_signature_slot = total_fields * FieldInfo::field_slots;
1124 int num_generic_signature = 0; 1147 int num_generic_signature = 0;
1125 for (int n = 0; n < length; n++) { 1148 for (int n = 0; n < length; n++) {
1126 cfs->guarantee_more(8, CHECK_NULL); // access_flags, name_index, descriptor_index, attributes_count 1149 cfs->guarantee_more(8, CHECK_NULL); // access_flags, name_index, descriptor_index, attributes_count
1158 if (attributes_count > 0) { 1181 if (attributes_count > 0) {
1159 parse_field_attributes(loader_data, 1182 parse_field_attributes(loader_data,
1160 cp, attributes_count, is_static, signature_index, 1183 cp, attributes_count, is_static, signature_index,
1161 &constantvalue_index, &is_synthetic, 1184 &constantvalue_index, &is_synthetic,
1162 &generic_signature_index, &field_annotations, 1185 &generic_signature_index, &field_annotations,
1163 &parsed_annotations, 1186 &field_type_annotations, &parsed_annotations,
1164 CHECK_NULL); 1187 CHECK_NULL);
1165 if (field_annotations != NULL) { 1188 if (field_annotations != NULL) {
1166 if (*fields_annotations == NULL) { 1189 if (*fields_annotations == NULL) {
1167 *fields_annotations = MetadataFactory::new_array<AnnotationArray*>( 1190 *fields_annotations = MetadataFactory::new_array<AnnotationArray*>(
1168 loader_data, length, NULL, 1191 loader_data, length, NULL,
1169 CHECK_NULL); 1192 CHECK_NULL);
1170 } 1193 }
1171 (*fields_annotations)->at_put(n, field_annotations); 1194 (*fields_annotations)->at_put(n, field_annotations);
1195 }
1196 if (field_type_annotations != NULL) {
1197 if (*fields_type_annotations == NULL) {
1198 *fields_type_annotations = MetadataFactory::new_array<AnnotationArray*>(
1199 loader_data, length, NULL,
1200 CHECK_NULL);
1201 }
1202 (*fields_type_annotations)->at_put(n, field_type_annotations);
1172 } 1203 }
1173 if (is_synthetic) { 1204 if (is_synthetic) {
1174 access_flags.set_is_synthetic(); 1205 access_flags.set_is_synthetic();
1175 } 1206 }
1176 if (generic_signature_index != 0) { 1207 if (generic_signature_index != 0) {
1829 bool is_interface, 1860 bool is_interface,
1830 AccessFlags *promoted_flags, 1861 AccessFlags *promoted_flags,
1831 AnnotationArray** method_annotations, 1862 AnnotationArray** method_annotations,
1832 AnnotationArray** method_parameter_annotations, 1863 AnnotationArray** method_parameter_annotations,
1833 AnnotationArray** method_default_annotations, 1864 AnnotationArray** method_default_annotations,
1865 AnnotationArray** method_type_annotations,
1834 TRAPS) { 1866 TRAPS) {
1835 ClassFileStream* cfs = stream(); 1867 ClassFileStream* cfs = stream();
1836 methodHandle nullHandle; 1868 methodHandle nullHandle;
1837 ResourceMark rm(THREAD); 1869 ResourceMark rm(THREAD);
1838 // Parse fixed parts 1870 // Parse fixed parts
1916 int runtime_invisible_annotations_length = 0; 1948 int runtime_invisible_annotations_length = 0;
1917 u1* runtime_visible_parameter_annotations = NULL; 1949 u1* runtime_visible_parameter_annotations = NULL;
1918 int runtime_visible_parameter_annotations_length = 0; 1950 int runtime_visible_parameter_annotations_length = 0;
1919 u1* runtime_invisible_parameter_annotations = NULL; 1951 u1* runtime_invisible_parameter_annotations = NULL;
1920 int runtime_invisible_parameter_annotations_length = 0; 1952 int runtime_invisible_parameter_annotations_length = 0;
1953 u1* runtime_visible_type_annotations = NULL;
1954 int runtime_visible_type_annotations_length = 0;
1955 u1* runtime_invisible_type_annotations = NULL;
1956 int runtime_invisible_type_annotations_length = 0;
1921 u1* annotation_default = NULL; 1957 u1* annotation_default = NULL;
1922 int annotation_default_length = 0; 1958 int annotation_default_length = 0;
1923 1959
1924 // Parse code and exceptions attribute 1960 // Parse code and exceptions attribute
1925 u2 method_attributes_count = cfs->get_u2_fast(); 1961 u2 method_attributes_count = cfs->get_u2_fast();
2157 } else if (method_attribute_name == vmSymbols::tag_annotation_default()) { 2193 } else if (method_attribute_name == vmSymbols::tag_annotation_default()) {
2158 annotation_default_length = method_attribute_length; 2194 annotation_default_length = method_attribute_length;
2159 annotation_default = cfs->get_u1_buffer(); 2195 annotation_default = cfs->get_u1_buffer();
2160 assert(annotation_default != NULL, "null annotation default"); 2196 assert(annotation_default != NULL, "null annotation default");
2161 cfs->skip_u1(annotation_default_length, CHECK_(nullHandle)); 2197 cfs->skip_u1(annotation_default_length, CHECK_(nullHandle));
2198 } else if (method_attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) {
2199 runtime_visible_type_annotations_length = method_attribute_length;
2200 runtime_visible_type_annotations = cfs->get_u1_buffer();
2201 assert(runtime_visible_type_annotations != NULL, "null visible type annotations");
2202 // No need for the VM to parse Type annotations
2203 cfs->skip_u1(runtime_visible_type_annotations_length, CHECK_(nullHandle));
2204 } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) {
2205 runtime_invisible_type_annotations_length = method_attribute_length;
2206 runtime_invisible_type_annotations = cfs->get_u1_buffer();
2207 assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations");
2208 cfs->skip_u1(runtime_invisible_type_annotations_length, CHECK_(nullHandle));
2162 } else { 2209 } else {
2163 // Skip unknown attributes 2210 // Skip unknown attributes
2164 cfs->skip_u1(method_attribute_length, CHECK_(nullHandle)); 2211 cfs->skip_u1(method_attribute_length, CHECK_(nullHandle));
2165 } 2212 }
2166 } else { 2213 } else {
2331 annotation_default, 2378 annotation_default,
2332 annotation_default_length, 2379 annotation_default_length,
2333 NULL, 2380 NULL,
2334 0, 2381 0,
2335 CHECK_(nullHandle)); 2382 CHECK_(nullHandle));
2383 *method_type_annotations = assemble_annotations(loader_data,
2384 runtime_visible_type_annotations,
2385 runtime_visible_type_annotations_length,
2386 runtime_invisible_type_annotations,
2387 runtime_invisible_type_annotations_length,
2388 CHECK_(nullHandle));
2336 2389
2337 if (name == vmSymbols::finalize_method_name() && 2390 if (name == vmSymbols::finalize_method_name() &&
2338 signature == vmSymbols::void_method_signature()) { 2391 signature == vmSymbols::void_method_signature()) {
2339 if (m->is_empty_method()) { 2392 if (m->is_empty_method()) {
2340 _has_empty_finalizer = true; 2393 _has_empty_finalizer = true;
2362 AccessFlags* promoted_flags, 2415 AccessFlags* promoted_flags,
2363 bool* has_final_method, 2416 bool* has_final_method,
2364 Array<AnnotationArray*>** methods_annotations, 2417 Array<AnnotationArray*>** methods_annotations,
2365 Array<AnnotationArray*>** methods_parameter_annotations, 2418 Array<AnnotationArray*>** methods_parameter_annotations,
2366 Array<AnnotationArray*>** methods_default_annotations, 2419 Array<AnnotationArray*>** methods_default_annotations,
2420 Array<AnnotationArray*>** methods_type_annotations,
2367 bool* has_default_methods, 2421 bool* has_default_methods,
2368 TRAPS) { 2422 TRAPS) {
2369 ClassFileStream* cfs = stream(); 2423 ClassFileStream* cfs = stream();
2370 AnnotationArray* method_annotations = NULL; 2424 AnnotationArray* method_annotations = NULL;
2371 AnnotationArray* method_parameter_annotations = NULL; 2425 AnnotationArray* method_parameter_annotations = NULL;
2372 AnnotationArray* method_default_annotations = NULL; 2426 AnnotationArray* method_default_annotations = NULL;
2427 AnnotationArray* method_type_annotations = NULL;
2373 cfs->guarantee_more(2, CHECK_NULL); // length 2428 cfs->guarantee_more(2, CHECK_NULL); // length
2374 u2 length = cfs->get_u2_fast(); 2429 u2 length = cfs->get_u2_fast();
2375 if (length == 0) { 2430 if (length == 0) {
2376 return Universe::the_empty_method_array(); 2431 return Universe::the_empty_method_array();
2377 } else { 2432 } else {
2384 cp, is_interface, 2439 cp, is_interface,
2385 promoted_flags, 2440 promoted_flags,
2386 &method_annotations, 2441 &method_annotations,
2387 &method_parameter_annotations, 2442 &method_parameter_annotations,
2388 &method_default_annotations, 2443 &method_default_annotations,
2444 &method_type_annotations,
2389 CHECK_NULL); 2445 CHECK_NULL);
2390 2446
2391 if (method->is_final()) { 2447 if (method->is_final()) {
2392 *has_final_method = true; 2448 *has_final_method = true;
2393 } 2449 }
2409 if (*methods_default_annotations == NULL) { 2465 if (*methods_default_annotations == NULL) {
2410 *methods_default_annotations = 2466 *methods_default_annotations =
2411 MetadataFactory::new_array<AnnotationArray*>(loader_data, length, NULL, CHECK_NULL); 2467 MetadataFactory::new_array<AnnotationArray*>(loader_data, length, NULL, CHECK_NULL);
2412 } 2468 }
2413 (*methods_default_annotations)->at_put(index, method_default_annotations); 2469 (*methods_default_annotations)->at_put(index, method_default_annotations);
2414 } 2470 if (*methods_type_annotations == NULL) {
2471 *methods_type_annotations =
2472 MetadataFactory::new_array<AnnotationArray*>(loader_data, length, NULL, CHECK_NULL);
2473 }
2474 (*methods_type_annotations)->at_put(index, method_type_annotations);
2475 }
2476
2415 if (_need_verify && length > 1) { 2477 if (_need_verify && length > 1) {
2416 // Check duplicated methods 2478 // Check duplicated methods
2417 ResourceMark rm(THREAD); 2479 ResourceMark rm(THREAD);
2418 NameSigHash** names_and_sigs = NEW_RESOURCE_ARRAY_IN_THREAD( 2480 NameSigHash** names_and_sigs = NEW_RESOURCE_ARRAY_IN_THREAD(
2419 THREAD, NameSigHash*, HASH_ROW_SIZE); 2481 THREAD, NameSigHash*, HASH_ROW_SIZE);
2443 Array<int>* ClassFileParser::sort_methods(ClassLoaderData* loader_data, 2505 Array<int>* ClassFileParser::sort_methods(ClassLoaderData* loader_data,
2444 Array<Method*>* methods, 2506 Array<Method*>* methods,
2445 Array<AnnotationArray*>* methods_annotations, 2507 Array<AnnotationArray*>* methods_annotations,
2446 Array<AnnotationArray*>* methods_parameter_annotations, 2508 Array<AnnotationArray*>* methods_parameter_annotations,
2447 Array<AnnotationArray*>* methods_default_annotations, 2509 Array<AnnotationArray*>* methods_default_annotations,
2510 Array<AnnotationArray*>* methods_type_annotations,
2448 TRAPS) { 2511 TRAPS) {
2449 int length = methods->length(); 2512 int length = methods->length();
2450 // If JVMTI original method ordering or sharing is enabled we have to 2513 // If JVMTI original method ordering or sharing is enabled we have to
2451 // remember the original class file ordering. 2514 // remember the original class file ordering.
2452 // We temporarily use the vtable_index field in the Method* to store the 2515 // We temporarily use the vtable_index field in the Method* to store the
2461 } 2524 }
2462 // Sort method array by ascending method name (for faster lookups & vtable construction) 2525 // Sort method array by ascending method name (for faster lookups & vtable construction)
2463 // Note that the ordering is not alphabetical, see Symbol::fast_compare 2526 // Note that the ordering is not alphabetical, see Symbol::fast_compare
2464 Method::sort_methods(methods, methods_annotations, 2527 Method::sort_methods(methods, methods_annotations,
2465 methods_parameter_annotations, 2528 methods_parameter_annotations,
2466 methods_default_annotations); 2529 methods_default_annotations,
2530 methods_type_annotations);
2467 2531
2468 // If JVMTI original method ordering or sharing is enabled construct int 2532 // If JVMTI original method ordering or sharing is enabled construct int
2469 // array remembering the original ordering 2533 // array remembering the original ordering
2470 if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) { 2534 if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) {
2471 Array<int>* method_ordering = MetadataFactory::new_array<int>(loader_data, length, CHECK_NULL); 2535 Array<int>* method_ordering = MetadataFactory::new_array<int>(loader_data, length, CHECK_NULL);
2726 bool parsed_bootstrap_methods_attribute = false; 2790 bool parsed_bootstrap_methods_attribute = false;
2727 u1* runtime_visible_annotations = NULL; 2791 u1* runtime_visible_annotations = NULL;
2728 int runtime_visible_annotations_length = 0; 2792 int runtime_visible_annotations_length = 0;
2729 u1* runtime_invisible_annotations = NULL; 2793 u1* runtime_invisible_annotations = NULL;
2730 int runtime_invisible_annotations_length = 0; 2794 int runtime_invisible_annotations_length = 0;
2795 u1* runtime_visible_type_annotations = NULL;
2796 int runtime_visible_type_annotations_length = 0;
2797 u1* runtime_invisible_type_annotations = NULL;
2798 int runtime_invisible_type_annotations_length = 0;
2731 u1* inner_classes_attribute_start = NULL; 2799 u1* inner_classes_attribute_start = NULL;
2732 u4 inner_classes_attribute_length = 0; 2800 u4 inner_classes_attribute_length = 0;
2733 u2 enclosing_method_class_index = 0; 2801 u2 enclosing_method_class_index = 0;
2734 u2 enclosing_method_method_index = 0; 2802 u2 enclosing_method_method_index = 0;
2735 // Iterate over attributes 2803 // Iterate over attributes
2832 _major_version >= Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { 2900 _major_version >= Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
2833 if (parsed_bootstrap_methods_attribute) 2901 if (parsed_bootstrap_methods_attribute)
2834 classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK); 2902 classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK);
2835 parsed_bootstrap_methods_attribute = true; 2903 parsed_bootstrap_methods_attribute = true;
2836 parse_classfile_bootstrap_methods_attribute(loader_data, cp, attribute_length, CHECK); 2904 parse_classfile_bootstrap_methods_attribute(loader_data, cp, attribute_length, CHECK);
2905 } else if (tag == vmSymbols::tag_runtime_visible_type_annotations()) {
2906 runtime_visible_type_annotations_length = attribute_length;
2907 runtime_visible_type_annotations = cfs->get_u1_buffer();
2908 assert(runtime_visible_type_annotations != NULL, "null visible type annotations");
2909 // No need for the VM to parse Type annotations
2910 cfs->skip_u1(runtime_visible_type_annotations_length, CHECK);
2911 } else if (PreserveAllAnnotations && tag == vmSymbols::tag_runtime_invisible_type_annotations()) {
2912 runtime_invisible_type_annotations_length = attribute_length;
2913 runtime_invisible_type_annotations = cfs->get_u1_buffer();
2914 assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations");
2915 cfs->skip_u1(runtime_invisible_type_annotations_length, CHECK);
2837 } else { 2916 } else {
2838 // Unknown attribute 2917 // Unknown attribute
2839 cfs->skip_u1(attribute_length, CHECK); 2918 cfs->skip_u1(attribute_length, CHECK);
2840 } 2919 }
2841 } else { 2920 } else {
2848 runtime_visible_annotations_length, 2927 runtime_visible_annotations_length,
2849 runtime_invisible_annotations, 2928 runtime_invisible_annotations,
2850 runtime_invisible_annotations_length, 2929 runtime_invisible_annotations_length,
2851 CHECK); 2930 CHECK);
2852 set_class_annotations(annotations); 2931 set_class_annotations(annotations);
2932 AnnotationArray* type_annotations = assemble_annotations(loader_data,
2933 runtime_visible_type_annotations,
2934 runtime_visible_type_annotations_length,
2935 runtime_invisible_type_annotations,
2936 runtime_invisible_type_annotations_length,
2937 CHECK);
2938 set_class_type_annotations(type_annotations);
2853 2939
2854 if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) { 2940 if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) {
2855 u2 num_of_classes = parse_classfile_inner_classes_attribute( 2941 u2 num_of_classes = parse_classfile_inner_classes_attribute(
2856 loader_data, 2942 loader_data,
2857 inner_classes_attribute_start, 2943 inner_classes_attribute_start,
3188 3274
3189 u2 java_fields_count = 0; 3275 u2 java_fields_count = 0;
3190 // Fields (offsets are filled in later) 3276 // Fields (offsets are filled in later)
3191 FieldAllocationCount fac; 3277 FieldAllocationCount fac;
3192 Array<AnnotationArray*>* fields_annotations = NULL; 3278 Array<AnnotationArray*>* fields_annotations = NULL;
3279 Array<AnnotationArray*>* fields_type_annotations = NULL;
3193 Array<u2>* fields = parse_fields(loader_data, class_name, cp, access_flags.is_interface(), &fac, &fields_annotations, 3280 Array<u2>* fields = parse_fields(loader_data, class_name, cp, access_flags.is_interface(), &fac, &fields_annotations,
3281 &fields_type_annotations,
3194 &java_fields_count, 3282 &java_fields_count,
3195 CHECK_(nullHandle)); 3283 CHECK_(nullHandle));
3196 // Methods 3284 // Methods
3197 bool has_final_method = false; 3285 bool has_final_method = false;
3198 AccessFlags promoted_flags; 3286 AccessFlags promoted_flags;
3200 // These need to be oop pointers because they are allocated lazily 3288 // These need to be oop pointers because they are allocated lazily
3201 // inside parse_methods inside a nested HandleMark 3289 // inside parse_methods inside a nested HandleMark
3202 Array<AnnotationArray*>* methods_annotations = NULL; 3290 Array<AnnotationArray*>* methods_annotations = NULL;
3203 Array<AnnotationArray*>* methods_parameter_annotations = NULL; 3291 Array<AnnotationArray*>* methods_parameter_annotations = NULL;
3204 Array<AnnotationArray*>* methods_default_annotations = NULL; 3292 Array<AnnotationArray*>* methods_default_annotations = NULL;
3293 Array<AnnotationArray*>* methods_type_annotations = NULL;
3205 Array<Method*>* methods = parse_methods(loader_data, 3294 Array<Method*>* methods = parse_methods(loader_data,
3206 cp, access_flags.is_interface(), 3295 cp, access_flags.is_interface(),
3207 &promoted_flags, 3296 &promoted_flags,
3208 &has_final_method, 3297 &has_final_method,
3209 &methods_annotations, 3298 &methods_annotations,
3210 &methods_parameter_annotations, 3299 &methods_parameter_annotations,
3211 &methods_default_annotations, 3300 &methods_default_annotations,
3301 &methods_type_annotations,
3212 &has_default_methods, 3302 &has_default_methods,
3213 CHECK_(nullHandle)); 3303 CHECK_(nullHandle));
3214 3304
3215 // Additional attributes 3305 // Additional attributes
3216 ClassAnnotationCollector parsed_annotations; 3306 ClassAnnotationCollector parsed_annotations;
3268 Array<int>* method_ordering = sort_methods(loader_data, 3358 Array<int>* method_ordering = sort_methods(loader_data,
3269 methods, 3359 methods,
3270 methods_annotations, 3360 methods_annotations,
3271 methods_parameter_annotations, 3361 methods_parameter_annotations,
3272 methods_default_annotations, 3362 methods_default_annotations,
3363 methods_type_annotations,
3273 CHECK_(nullHandle)); 3364 CHECK_(nullHandle));
3274 3365
3275 // promote flags from parse_methods() to the klass' flags 3366 // promote flags from parse_methods() to the klass' flags
3276 access_flags.add_promoted_flags(promoted_flags.as_int()); 3367 access_flags.add_promoted_flags(promoted_flags.as_int());
3277 3368
3685 this_klass->set_initial_method_idnum(methods->length()); 3776 this_klass->set_initial_method_idnum(methods->length());
3686 this_klass->set_name(cp->klass_name_at(this_class_index)); 3777 this_klass->set_name(cp->klass_name_at(this_class_index));
3687 if (is_anonymous()) // I am well known to myself 3778 if (is_anonymous()) // I am well known to myself
3688 cp->klass_at_put(this_class_index, this_klass()); // eagerly resolve 3779 cp->klass_at_put(this_class_index, this_klass()); // eagerly resolve
3689 3780
3781 // Allocate an annotation type if needed.
3690 if (fields_annotations != NULL || 3782 if (fields_annotations != NULL ||
3691 methods_annotations != NULL || 3783 methods_annotations != NULL ||
3692 methods_parameter_annotations != NULL || 3784 methods_parameter_annotations != NULL ||
3693 methods_default_annotations != NULL) { 3785 methods_default_annotations != NULL ||
3694 // Allocate an annotation type if needed. 3786 fields_type_annotations != NULL ||
3787 methods_type_annotations != NULL) {
3695 Annotations* anno = Annotations::allocate(loader_data, 3788 Annotations* anno = Annotations::allocate(loader_data,
3696 fields_annotations, methods_annotations, 3789 fields_annotations, methods_annotations,
3697 methods_parameter_annotations, 3790 methods_parameter_annotations,
3698 methods_default_annotations, CHECK_(nullHandle)); 3791 methods_default_annotations, CHECK_(nullHandle));
3699 this_klass->set_annotations(anno); 3792 this_klass->set_annotations(anno);
3700 } else { 3793 } else {
3701 this_klass->set_annotations(NULL); 3794 this_klass->set_annotations(NULL);
3702 } 3795 }
3703 3796
3797 if (fields_type_annotations != NULL ||
3798 methods_type_annotations != NULL) {
3799 assert(this_klass->annotations() != NULL, "annotations should have been allocated");
3800 Annotations* anno = Annotations::allocate(loader_data,
3801 fields_type_annotations,
3802 methods_type_annotations,
3803 NULL,
3804 NULL, CHECK_(nullHandle));
3805 this_klass->annotations()->set_type_annotations(anno);
3806 }
3704 3807
3705 this_klass->set_minor_version(minor_version); 3808 this_klass->set_minor_version(minor_version);
3706 this_klass->set_major_version(major_version); 3809 this_klass->set_major_version(major_version);
3707 this_klass->set_has_default_methods(has_default_methods); 3810 this_klass->set_has_default_methods(has_default_methods);
3708 3811
3723 } 3826 }
3724 3827
3725 // Fill in field values obtained by parse_classfile_attributes 3828 // Fill in field values obtained by parse_classfile_attributes
3726 if (parsed_annotations.has_any_annotations()) 3829 if (parsed_annotations.has_any_annotations())
3727 parsed_annotations.apply_to(this_klass); 3830 parsed_annotations.apply_to(this_klass);
3831
3728 // Create annotations 3832 // Create annotations
3729 if (_annotations != NULL && this_klass->annotations() == NULL) { 3833 if (_annotations != NULL && this_klass->annotations() == NULL) {
3730 Annotations* anno = Annotations::allocate(loader_data, CHECK_NULL); 3834 Annotations* anno = Annotations::allocate(loader_data, CHECK_NULL);
3731 this_klass->set_annotations(anno); 3835 this_klass->set_annotations(anno);
3732 } 3836 }
3733 apply_parsed_class_attributes(this_klass); 3837 apply_parsed_class_attributes(this_klass);
3838
3839 // Create type annotations
3840 if (_type_annotations != NULL) {
3841 if (this_klass->annotations() == NULL) {
3842 Annotations* anno = Annotations::allocate(loader_data, CHECK_NULL);
3843 this_klass->set_annotations(anno);
3844 }
3845 if (this_klass->annotations()->type_annotations() == NULL) {
3846 Annotations* anno = Annotations::allocate(loader_data, CHECK_NULL);
3847 this_klass->annotations()->set_type_annotations(anno);
3848 }
3849 this_klass->annotations()->type_annotations()->set_class_annotations(_type_annotations);
3850 }
3734 3851
3735 // Miranda methods 3852 // Miranda methods
3736 if ((num_miranda_methods > 0) || 3853 if ((num_miranda_methods > 0) ||
3737 // if this class introduced new miranda methods or 3854 // if this class introduced new miranda methods or
3738 (super_klass.not_null() && (super_klass->has_miranda_methods())) 3855 (super_klass.not_null() && (super_klass->has_miranda_methods()))