src/share/vm/classfile/classFileParser.cpp

Print this page




2298   assert(sde_buffer != NULL, "null sde buffer");
2299 
2300   // Don't bother storing it if there is no way to retrieve it
2301   if (JvmtiExport::can_get_source_debug_extension()) {
2302     // Optimistically assume that only 1 byte UTF format is used
2303     // (common case)
2304     TempNewSymbol sde_symbol = SymbolTable::new_symbol((const char*)sde_buffer, length, CHECK);
2305     k->set_source_debug_extension(sde_symbol);
2306     // Note that set_source_debug_extension() increments the reference count
2307     // for its copy of the Symbol*, so use a TempNewSymbol here.
2308   }
2309   // Got utf8 string, set stream position forward
2310   cfs->skip_u1(length, CHECK);
2311 }
2312 
2313 
2314 // Inner classes can be static, private or protected (classic VM does this)
2315 #define RECOGNIZED_INNER_CLASS_MODIFIERS (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_PRIVATE | JVM_ACC_PROTECTED | JVM_ACC_STATIC)
2316 
2317 // Return number of classes in the inner classes attribute table
2318 u2 ClassFileParser::parse_classfile_inner_classes_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {





2319   ClassFileStream* cfs = stream();




2320   cfs->guarantee_more(2, CHECK_0);  // length
2321   u2 length = cfs->get_u2_fast();

2322 
2323   // 4-tuples of shorts [inner_class_info_index, outer_class_info_index, inner_name_index, inner_class_access_flags]
2324   typeArrayOop ic = oopFactory::new_permanent_shortArray(length*4, CHECK_0);









2325   typeArrayHandle inner_classes(THREAD, ic);
2326   int index = 0;
2327   int cp_size = cp->length();
2328   cfs->guarantee_more(8 * length, CHECK_0);  // 4-tuples of u2
2329   for (int n = 0; n < length; n++) {
2330     // Inner class index
2331     u2 inner_class_info_index = cfs->get_u2_fast();
2332     check_property(
2333       inner_class_info_index == 0 ||
2334         (valid_cp_range(inner_class_info_index, cp_size) &&
2335         is_klass_reference(cp, inner_class_info_index)),
2336       "inner_class_info_index %u has bad constant type in class file %s",
2337       inner_class_info_index, CHECK_0);
2338     // Outer class index
2339     u2 outer_class_info_index = cfs->get_u2_fast();
2340     check_property(
2341       outer_class_info_index == 0 ||
2342         (valid_cp_range(outer_class_info_index, cp_size) &&
2343         is_klass_reference(cp, outer_class_info_index)),
2344       "outer_class_info_index %u has bad constant type in class file %s",


2367     inner_classes->short_at_put(index++, inner_class_info_index);
2368     inner_classes->short_at_put(index++, outer_class_info_index);
2369     inner_classes->short_at_put(index++, inner_name_index);
2370     inner_classes->short_at_put(index++, inner_access_flags.as_short());
2371   }
2372 
2373   // 4347400: make sure there's no duplicate entry in the classes array
2374   if (_need_verify && _major_version >= JAVA_1_5_VERSION) {
2375     for(int i = 0; i < inner_classes->length(); i += 4) {
2376       for(int j = i + 4; j < inner_classes->length(); j += 4) {
2377         guarantee_property((inner_classes->ushort_at(i)   != inner_classes->ushort_at(j) ||
2378                             inner_classes->ushort_at(i+1) != inner_classes->ushort_at(j+1) ||
2379                             inner_classes->ushort_at(i+2) != inner_classes->ushort_at(j+2) ||
2380                             inner_classes->ushort_at(i+3) != inner_classes->ushort_at(j+3)),
2381                             "Duplicate entry in InnerClasses in class file %s",
2382                             CHECK_0);
2383       }
2384     }
2385   }
2386 






2387   // Update instanceKlass with inner class info.
2388   k->set_inner_classes(inner_classes());




2389   return length;
2390 }
2391 
2392 void ClassFileParser::parse_classfile_synthetic_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {
2393   k->set_is_synthetic();
2394 }
2395 
2396 void ClassFileParser::parse_classfile_signature_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {
2397   ClassFileStream* cfs = stream();
2398   u2 signature_index = cfs->get_u2(CHECK);
2399   check_property(
2400     valid_cp_range(signature_index, cp->length()) &&
2401       cp->tag_at(signature_index).is_utf8(),
2402     "Invalid constant pool index %u in Signature attribute in class file %s",
2403     signature_index, CHECK);
2404   k->set_generic_signature(cp->symbol_at(signature_index));
2405 }
2406 
2407 void ClassFileParser::parse_classfile_bootstrap_methods_attribute(constantPoolHandle cp, instanceKlassHandle k,
2408                                                                   u4 attribute_byte_length, TRAPS) {


2473                      CHECK);
2474 
2475   cp->set_operands(operands());
2476 }
2477 
2478 
2479 void ClassFileParser::parse_classfile_attributes(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {
2480   ClassFileStream* cfs = stream();
2481   // Set inner classes attribute to default sentinel
2482   k->set_inner_classes(Universe::the_empty_short_array());
2483   cfs->guarantee_more(2, CHECK);  // attributes_count
2484   u2 attributes_count = cfs->get_u2_fast();
2485   bool parsed_sourcefile_attribute = false;
2486   bool parsed_innerclasses_attribute = false;
2487   bool parsed_enclosingmethod_attribute = false;
2488   bool parsed_bootstrap_methods_attribute = false;
2489   u1* runtime_visible_annotations = NULL;
2490   int runtime_visible_annotations_length = 0;
2491   u1* runtime_invisible_annotations = NULL;
2492   int runtime_invisible_annotations_length = 0;




2493   // Iterate over attributes
2494   while (attributes_count--) {
2495     cfs->guarantee_more(6, CHECK);  // attribute_name_index, attribute_length
2496     u2 attribute_name_index = cfs->get_u2_fast();
2497     u4 attribute_length = cfs->get_u4_fast();
2498     check_property(
2499       valid_cp_range(attribute_name_index, cp->length()) &&
2500         cp->tag_at(attribute_name_index).is_utf8(),
2501       "Attribute name has bad constant pool index %u in class file %s",
2502       attribute_name_index, CHECK);
2503     Symbol* tag = cp->symbol_at(attribute_name_index);
2504     if (tag == vmSymbols::tag_source_file()) {
2505       // Check for SourceFile tag
2506       if (_need_verify) {
2507         guarantee_property(attribute_length == 2, "Wrong SourceFile attribute length in class file %s", CHECK);
2508       }
2509       if (parsed_sourcefile_attribute) {
2510         classfile_parse_error("Multiple SourceFile attributes in class file %s", CHECK);
2511       } else {
2512         parsed_sourcefile_attribute = true;
2513       }
2514       parse_classfile_sourcefile_attribute(cp, k, CHECK);
2515     } else if (tag == vmSymbols::tag_source_debug_extension()) {
2516       // Check for SourceDebugExtension tag
2517       parse_classfile_source_debug_extension_attribute(cp, k, (int)attribute_length, CHECK);
2518     } else if (tag == vmSymbols::tag_inner_classes()) {
2519       // Check for InnerClasses tag
2520       if (parsed_innerclasses_attribute) {
2521         classfile_parse_error("Multiple InnerClasses attributes in class file %s", CHECK);
2522       } else {
2523         parsed_innerclasses_attribute = true;
2524       }
2525       u2 num_of_classes = parse_classfile_inner_classes_attribute(cp, k, CHECK);
2526       if (_need_verify && _major_version >= JAVA_1_5_VERSION) {
2527         guarantee_property(attribute_length == sizeof(num_of_classes) + 4 * sizeof(u2) * num_of_classes,
2528                           "Wrong InnerClasses attribute length in class file %s", CHECK);
2529       }
2530     } else if (tag == vmSymbols::tag_synthetic()) {
2531       // Check for Synthetic tag
2532       // Shouldn't we check that the synthetic flags wasn't already set? - not required in spec
2533       if (attribute_length != 0) {
2534         classfile_parse_error(
2535           "Invalid Synthetic classfile attribute length %u in class file %s",
2536           attribute_length, CHECK);
2537       }
2538       parse_classfile_synthetic_attribute(cp, k, CHECK);
2539     } else if (tag == vmSymbols::tag_deprecated()) {
2540       // Check for Deprecatd tag - 4276120
2541       if (attribute_length != 0) {
2542         classfile_parse_error(
2543           "Invalid Deprecated classfile attribute length %u in class file %s",
2544           attribute_length, CHECK);
2545       }
2546     } else if (_major_version >= JAVA_1_5_VERSION) {
2547       if (tag == vmSymbols::tag_signature()) {
2548         if (attribute_length != 2) {
2549           classfile_parse_error(


2551             attribute_length, CHECK);
2552         }
2553         parse_classfile_signature_attribute(cp, k, CHECK);
2554       } else if (tag == vmSymbols::tag_runtime_visible_annotations()) {
2555         runtime_visible_annotations_length = attribute_length;
2556         runtime_visible_annotations = cfs->get_u1_buffer();
2557         assert(runtime_visible_annotations != NULL, "null visible annotations");
2558         cfs->skip_u1(runtime_visible_annotations_length, CHECK);
2559       } else if (PreserveAllAnnotations && tag == vmSymbols::tag_runtime_invisible_annotations()) {
2560         runtime_invisible_annotations_length = attribute_length;
2561         runtime_invisible_annotations = cfs->get_u1_buffer();
2562         assert(runtime_invisible_annotations != NULL, "null invisible annotations");
2563         cfs->skip_u1(runtime_invisible_annotations_length, CHECK);
2564       } else if (tag == vmSymbols::tag_enclosing_method()) {
2565         if (parsed_enclosingmethod_attribute) {
2566           classfile_parse_error("Multiple EnclosingMethod attributes in class file %s", CHECK);
2567         }   else {
2568           parsed_enclosingmethod_attribute = true;
2569         }
2570         cfs->guarantee_more(4, CHECK);  // class_index, method_index
2571         u2 class_index  = cfs->get_u2_fast();
2572         u2 method_index = cfs->get_u2_fast();
2573         if (class_index == 0) {
2574           classfile_parse_error("Invalid class index in EnclosingMethod attribute in class file %s", CHECK);
2575         }
2576         // Validate the constant pool indices and types
2577         if (!cp->is_within_bounds(class_index) ||
2578             !is_klass_reference(cp, class_index)) {
2579           classfile_parse_error("Invalid or out-of-bounds class index in EnclosingMethod attribute in class file %s", CHECK);
2580         }
2581         if (method_index != 0 &&
2582             (!cp->is_within_bounds(method_index) ||
2583              !cp->tag_at(method_index).is_name_and_type())) {
2584           classfile_parse_error("Invalid or out-of-bounds method index in EnclosingMethod attribute in class file %s", CHECK);
2585         }
2586         k->set_enclosing_method_indices(class_index, method_index);
2587       } else if (tag == vmSymbols::tag_bootstrap_methods() &&
2588                  _major_version >= Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
2589         if (parsed_bootstrap_methods_attribute)
2590           classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK);
2591         parsed_bootstrap_methods_attribute = true;
2592         parse_classfile_bootstrap_methods_attribute(cp, k, attribute_length, CHECK);
2593       } else {
2594         // Unknown attribute
2595         cfs->skip_u1(attribute_length, CHECK);
2596       }
2597     } else {
2598       // Unknown attribute
2599       cfs->skip_u1(attribute_length, CHECK);
2600     }
2601   }
2602   typeArrayHandle annotations = assemble_annotations(runtime_visible_annotations,
2603                                                      runtime_visible_annotations_length,
2604                                                      runtime_invisible_annotations,
2605                                                      runtime_invisible_annotations_length,
2606                                                      CHECK);
2607   k->set_class_annotations(annotations());
2608 












2609   if (_max_bootstrap_specifier_index >= 0) {
2610     guarantee_property(parsed_bootstrap_methods_attribute,
2611                        "Missing BootstrapMethods attribute in class file %s", CHECK);
2612   }
2613 }
2614 
2615 
2616 typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annotations,
2617                                                       int runtime_visible_annotations_length,
2618                                                       u1* runtime_invisible_annotations,
2619                                                       int runtime_invisible_annotations_length, TRAPS) {
2620   typeArrayHandle annotations;
2621   if (runtime_visible_annotations != NULL ||
2622       runtime_invisible_annotations != NULL) {
2623     typeArrayOop anno = oopFactory::new_permanent_byteArray(runtime_visible_annotations_length +
2624                                                             runtime_invisible_annotations_length, CHECK_(annotations));
2625     annotations = typeArrayHandle(THREAD, anno);
2626     if (runtime_visible_annotations != NULL) {
2627       memcpy(annotations->byte_at_addr(0), runtime_visible_annotations, runtime_visible_annotations_length);
2628     }




2298   assert(sde_buffer != NULL, "null sde buffer");
2299 
2300   // Don't bother storing it if there is no way to retrieve it
2301   if (JvmtiExport::can_get_source_debug_extension()) {
2302     // Optimistically assume that only 1 byte UTF format is used
2303     // (common case)
2304     TempNewSymbol sde_symbol = SymbolTable::new_symbol((const char*)sde_buffer, length, CHECK);
2305     k->set_source_debug_extension(sde_symbol);
2306     // Note that set_source_debug_extension() increments the reference count
2307     // for its copy of the Symbol*, so use a TempNewSymbol here.
2308   }
2309   // Got utf8 string, set stream position forward
2310   cfs->skip_u1(length, CHECK);
2311 }
2312 
2313 
2314 // Inner classes can be static, private or protected (classic VM does this)
2315 #define RECOGNIZED_INNER_CLASS_MODIFIERS (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_PRIVATE | JVM_ACC_PROTECTED | JVM_ACC_STATIC)
2316 
2317 // Return number of classes in the inner classes attribute table
2318 u2 ClassFileParser::parse_classfile_inner_classes_attribute(u1* inner_classes_attribute_start,
2319                                                             bool parsed_enclosingmethod_attribute,
2320                                                             u2 enclosing_method_class_index,
2321                                                             u2 enclosing_method_method_index,
2322                                                             constantPoolHandle cp, 
2323                                                             instanceKlassHandle k, TRAPS) {
2324   ClassFileStream* cfs = stream();
2325   u1* current_mark = cfs->current();
2326   u2 length = 0;
2327   if (inner_classes_attribute_start != NULL) {
2328     cfs->set_current(inner_classes_attribute_start);
2329     cfs->guarantee_more(2, CHECK_0);  // length
2330     length = cfs->get_u2_fast();
2331   }
2332 
2333   // 4-tuples of shorts of inner classes data and 2 shorts of enclosing
2334   // method data:
2335   //   [inner_class_info_index, 
2336   //    outer_class_info_index, 
2337   //    inner_name_index, 
2338   //    inner_class_access_flags,
2339   //    ...
2340   //    enclosing_method_class_index,
2341   //    enclosing_method_method_index]
2342   u2 size = length * 4 + (parsed_enclosingmethod_attribute ? 2 : 0);
2343   typeArrayOop ic = oopFactory::new_permanent_shortArray(size, CHECK_0);
2344   typeArrayHandle inner_classes(THREAD, ic);
2345   int index = 0;
2346   int cp_size = cp->length();
2347   cfs->guarantee_more(8 * length, CHECK_0);  // 4-tuples of u2
2348   for (int n = 0; n < length; n++) {
2349     // Inner class index
2350     u2 inner_class_info_index = cfs->get_u2_fast();
2351     check_property(
2352       inner_class_info_index == 0 ||
2353         (valid_cp_range(inner_class_info_index, cp_size) &&
2354         is_klass_reference(cp, inner_class_info_index)),
2355       "inner_class_info_index %u has bad constant type in class file %s",
2356       inner_class_info_index, CHECK_0);
2357     // Outer class index
2358     u2 outer_class_info_index = cfs->get_u2_fast();
2359     check_property(
2360       outer_class_info_index == 0 ||
2361         (valid_cp_range(outer_class_info_index, cp_size) &&
2362         is_klass_reference(cp, outer_class_info_index)),
2363       "outer_class_info_index %u has bad constant type in class file %s",


2386     inner_classes->short_at_put(index++, inner_class_info_index);
2387     inner_classes->short_at_put(index++, outer_class_info_index);
2388     inner_classes->short_at_put(index++, inner_name_index);
2389     inner_classes->short_at_put(index++, inner_access_flags.as_short());
2390   }
2391 
2392   // 4347400: make sure there's no duplicate entry in the classes array
2393   if (_need_verify && _major_version >= JAVA_1_5_VERSION) {
2394     for(int i = 0; i < inner_classes->length(); i += 4) {
2395       for(int j = i + 4; j < inner_classes->length(); j += 4) {
2396         guarantee_property((inner_classes->ushort_at(i)   != inner_classes->ushort_at(j) ||
2397                             inner_classes->ushort_at(i+1) != inner_classes->ushort_at(j+1) ||
2398                             inner_classes->ushort_at(i+2) != inner_classes->ushort_at(j+2) ||
2399                             inner_classes->ushort_at(i+3) != inner_classes->ushort_at(j+3)),
2400                             "Duplicate entry in InnerClasses in class file %s",
2401                             CHECK_0);
2402       }
2403     }
2404   }
2405 
2406   // Set EnclosingMethod class and method indexes.
2407   if (parsed_enclosingmethod_attribute) {
2408     inner_classes->short_at_put(index++, enclosing_method_class_index);
2409     inner_classes->short_at_put(index++, enclosing_method_method_index);
2410   }
2411 
2412   // Update instanceKlass with inner class info.
2413   k->set_inner_classes(inner_classes());
2414 
2415   // Restore buffer's current position.
2416   cfs->set_current(current_mark);
2417 
2418   return length;
2419 }
2420 
2421 void ClassFileParser::parse_classfile_synthetic_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {
2422   k->set_is_synthetic();
2423 }
2424 
2425 void ClassFileParser::parse_classfile_signature_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {
2426   ClassFileStream* cfs = stream();
2427   u2 signature_index = cfs->get_u2(CHECK);
2428   check_property(
2429     valid_cp_range(signature_index, cp->length()) &&
2430       cp->tag_at(signature_index).is_utf8(),
2431     "Invalid constant pool index %u in Signature attribute in class file %s",
2432     signature_index, CHECK);
2433   k->set_generic_signature(cp->symbol_at(signature_index));
2434 }
2435 
2436 void ClassFileParser::parse_classfile_bootstrap_methods_attribute(constantPoolHandle cp, instanceKlassHandle k,
2437                                                                   u4 attribute_byte_length, TRAPS) {


2502                      CHECK);
2503 
2504   cp->set_operands(operands());
2505 }
2506 
2507 
2508 void ClassFileParser::parse_classfile_attributes(constantPoolHandle cp, instanceKlassHandle k, TRAPS) {
2509   ClassFileStream* cfs = stream();
2510   // Set inner classes attribute to default sentinel
2511   k->set_inner_classes(Universe::the_empty_short_array());
2512   cfs->guarantee_more(2, CHECK);  // attributes_count
2513   u2 attributes_count = cfs->get_u2_fast();
2514   bool parsed_sourcefile_attribute = false;
2515   bool parsed_innerclasses_attribute = false;
2516   bool parsed_enclosingmethod_attribute = false;
2517   bool parsed_bootstrap_methods_attribute = false;
2518   u1* runtime_visible_annotations = NULL;
2519   int runtime_visible_annotations_length = 0;
2520   u1* runtime_invisible_annotations = NULL;
2521   int runtime_invisible_annotations_length = 0;
2522   u1* inner_classes_attribute_start = NULL;
2523   u4  inner_classes_attribute_length = 0;
2524   u2  enclosing_method_class_index = 0;
2525   u2  enclosing_method_method_index = 0;
2526   // Iterate over attributes
2527   while (attributes_count--) {
2528     cfs->guarantee_more(6, CHECK);  // attribute_name_index, attribute_length
2529     u2 attribute_name_index = cfs->get_u2_fast();
2530     u4 attribute_length = cfs->get_u4_fast();
2531     check_property(
2532       valid_cp_range(attribute_name_index, cp->length()) &&
2533         cp->tag_at(attribute_name_index).is_utf8(),
2534       "Attribute name has bad constant pool index %u in class file %s",
2535       attribute_name_index, CHECK);
2536     Symbol* tag = cp->symbol_at(attribute_name_index);
2537     if (tag == vmSymbols::tag_source_file()) {
2538       // Check for SourceFile tag
2539       if (_need_verify) {
2540         guarantee_property(attribute_length == 2, "Wrong SourceFile attribute length in class file %s", CHECK);
2541       }
2542       if (parsed_sourcefile_attribute) {
2543         classfile_parse_error("Multiple SourceFile attributes in class file %s", CHECK);
2544       } else {
2545         parsed_sourcefile_attribute = true;
2546       }
2547       parse_classfile_sourcefile_attribute(cp, k, CHECK);
2548     } else if (tag == vmSymbols::tag_source_debug_extension()) {
2549       // Check for SourceDebugExtension tag
2550       parse_classfile_source_debug_extension_attribute(cp, k, (int)attribute_length, CHECK);
2551     } else if (tag == vmSymbols::tag_inner_classes()) {
2552       // Check for InnerClasses tag
2553       if (parsed_innerclasses_attribute) {
2554         classfile_parse_error("Multiple InnerClasses attributes in class file %s", CHECK);
2555       } else {
2556         parsed_innerclasses_attribute = true;
2557       }
2558       inner_classes_attribute_start = cfs->get_u1_buffer();
2559       inner_classes_attribute_length = attribute_length;
2560       cfs->skip_u1(inner_classes_attribute_length, CHECK);


2561     } else if (tag == vmSymbols::tag_synthetic()) {
2562       // Check for Synthetic tag
2563       // Shouldn't we check that the synthetic flags wasn't already set? - not required in spec
2564       if (attribute_length != 0) {
2565         classfile_parse_error(
2566           "Invalid Synthetic classfile attribute length %u in class file %s",
2567           attribute_length, CHECK);
2568       }
2569       parse_classfile_synthetic_attribute(cp, k, CHECK);
2570     } else if (tag == vmSymbols::tag_deprecated()) {
2571       // Check for Deprecatd tag - 4276120
2572       if (attribute_length != 0) {
2573         classfile_parse_error(
2574           "Invalid Deprecated classfile attribute length %u in class file %s",
2575           attribute_length, CHECK);
2576       }
2577     } else if (_major_version >= JAVA_1_5_VERSION) {
2578       if (tag == vmSymbols::tag_signature()) {
2579         if (attribute_length != 2) {
2580           classfile_parse_error(


2582             attribute_length, CHECK);
2583         }
2584         parse_classfile_signature_attribute(cp, k, CHECK);
2585       } else if (tag == vmSymbols::tag_runtime_visible_annotations()) {
2586         runtime_visible_annotations_length = attribute_length;
2587         runtime_visible_annotations = cfs->get_u1_buffer();
2588         assert(runtime_visible_annotations != NULL, "null visible annotations");
2589         cfs->skip_u1(runtime_visible_annotations_length, CHECK);
2590       } else if (PreserveAllAnnotations && tag == vmSymbols::tag_runtime_invisible_annotations()) {
2591         runtime_invisible_annotations_length = attribute_length;
2592         runtime_invisible_annotations = cfs->get_u1_buffer();
2593         assert(runtime_invisible_annotations != NULL, "null invisible annotations");
2594         cfs->skip_u1(runtime_invisible_annotations_length, CHECK);
2595       } else if (tag == vmSymbols::tag_enclosing_method()) {
2596         if (parsed_enclosingmethod_attribute) {
2597           classfile_parse_error("Multiple EnclosingMethod attributes in class file %s", CHECK);
2598         }   else {
2599           parsed_enclosingmethod_attribute = true;
2600         }
2601         cfs->guarantee_more(4, CHECK);  // class_index, method_index
2602         enclosing_method_class_index  = cfs->get_u2_fast();
2603         enclosing_method_method_index = cfs->get_u2_fast();
2604         if (enclosing_method_class_index == 0) {
2605           classfile_parse_error("Invalid class index in EnclosingMethod attribute in class file %s", CHECK);
2606         }
2607         // Validate the constant pool indices and types
2608         if (!cp->is_within_bounds(enclosing_method_class_index) ||
2609             !is_klass_reference(cp, enclosing_method_class_index)) {
2610           classfile_parse_error("Invalid or out-of-bounds class index in EnclosingMethod attribute in class file %s", CHECK);
2611         }
2612         if (enclosing_method_method_index != 0 &&
2613             (!cp->is_within_bounds(enclosing_method_method_index) ||
2614              !cp->tag_at(enclosing_method_method_index).is_name_and_type())) {
2615           classfile_parse_error("Invalid or out-of-bounds method index in EnclosingMethod attribute in class file %s", CHECK);
2616         }

2617       } else if (tag == vmSymbols::tag_bootstrap_methods() &&
2618                  _major_version >= Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
2619         if (parsed_bootstrap_methods_attribute)
2620           classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK);
2621         parsed_bootstrap_methods_attribute = true;
2622         parse_classfile_bootstrap_methods_attribute(cp, k, attribute_length, CHECK);
2623       } else {
2624         // Unknown attribute
2625         cfs->skip_u1(attribute_length, CHECK);
2626       }
2627     } else {
2628       // Unknown attribute
2629       cfs->skip_u1(attribute_length, CHECK);
2630     }
2631   }
2632   typeArrayHandle annotations = assemble_annotations(runtime_visible_annotations,
2633                                                      runtime_visible_annotations_length,
2634                                                      runtime_invisible_annotations,
2635                                                      runtime_invisible_annotations_length,
2636                                                      CHECK);
2637   k->set_class_annotations(annotations());
2638 
2639   if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) {
2640     u2 num_of_classes = parse_classfile_inner_classes_attribute(
2641       inner_classes_attribute_start, parsed_innerclasses_attribute, 
2642       enclosing_method_class_index, enclosing_method_method_index, 
2643       cp, k, CHECK);
2644     if (parsed_innerclasses_attribute &&_need_verify && _major_version >= JAVA_1_5_VERSION) {
2645       guarantee_property(
2646         inner_classes_attribute_length == sizeof(num_of_classes) + 4 * sizeof(u2) * num_of_classes,
2647         "Wrong InnerClasses attribute length in class file %s", CHECK);
2648     }
2649   }
2650 
2651   if (_max_bootstrap_specifier_index >= 0) {
2652     guarantee_property(parsed_bootstrap_methods_attribute,
2653                        "Missing BootstrapMethods attribute in class file %s", CHECK);
2654   }
2655 }
2656 
2657 
2658 typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annotations,
2659                                                       int runtime_visible_annotations_length,
2660                                                       u1* runtime_invisible_annotations,
2661                                                       int runtime_invisible_annotations_length, TRAPS) {
2662   typeArrayHandle annotations;
2663   if (runtime_visible_annotations != NULL ||
2664       runtime_invisible_annotations != NULL) {
2665     typeArrayOop anno = oopFactory::new_permanent_byteArray(runtime_visible_annotations_length +
2666                                                             runtime_invisible_annotations_length, CHECK_(annotations));
2667     annotations = typeArrayHandle(THREAD, anno);
2668     if (runtime_visible_annotations != NULL) {
2669       memcpy(annotations->byte_at_addr(0), runtime_visible_annotations, runtime_visible_annotations_length);
2670     }