comparison src/share/vm/classfile/classFileParser.cpp @ 6226:9c9fb30d2b3b

Merge
author kvn
date Mon, 16 Jul 2012 19:50:52 -0700
parents 04ade88d9712 6d8f36bcef55
children dd785aabe02b
comparison
equal deleted inserted replaced
6212:54e66510c9cd 6226:9c9fb30d2b3b
315 } 315 }
316 void set_in_error(bool clean) { _in_error = clean; } 316 void set_in_error(bool clean) { _in_error = clean; }
317 }; 317 };
318 318
319 bool inline valid_cp_range(int index, int length) { return (index > 0 && index < length); } 319 bool inline valid_cp_range(int index, int length) { return (index > 0 && index < length); }
320
321 inline Symbol* check_symbol_at(constantPoolHandle cp, int index) {
322 if (valid_cp_range(index, cp->length()) && cp->tag_at(index).is_utf8())
323 return cp->symbol_at(index);
324 else
325 return NULL;
326 }
320 327
321 constantPoolHandle ClassFileParser::parse_constant_pool(Handle class_loader, TRAPS) { 328 constantPoolHandle ClassFileParser::parse_constant_pool(Handle class_loader, TRAPS) {
322 ClassFileStream* cfs = stream(); 329 ClassFileStream* cfs = stream();
323 constantPoolHandle nullHandle; 330 constantPoolHandle nullHandle;
324 331
900 bool is_static, u2 signature_index, 907 bool is_static, u2 signature_index,
901 u2* constantvalue_index_addr, 908 u2* constantvalue_index_addr,
902 bool* is_synthetic_addr, 909 bool* is_synthetic_addr,
903 u2* generic_signature_index_addr, 910 u2* generic_signature_index_addr,
904 typeArrayHandle* field_annotations, 911 typeArrayHandle* field_annotations,
912 ClassFileParser::FieldAnnotationCollector* parsed_annotations,
905 TRAPS) { 913 TRAPS) {
906 ClassFileStream* cfs = stream(); 914 ClassFileStream* cfs = stream();
907 assert(attributes_count > 0, "length should be greater than 0"); 915 assert(attributes_count > 0, "length should be greater than 0");
908 u2 constantvalue_index = 0; 916 u2 constantvalue_index = 0;
909 u2 generic_signature_index = 0; 917 u2 generic_signature_index = 0;
1140 1148
1141 u2 constantvalue_index = 0; 1149 u2 constantvalue_index = 0;
1142 bool is_synthetic = false; 1150 bool is_synthetic = false;
1143 u2 generic_signature_index = 0; 1151 u2 generic_signature_index = 0;
1144 bool is_static = access_flags.is_static(); 1152 bool is_static = access_flags.is_static();
1153 FieldAnnotationCollector parsed_annotations;
1145 1154
1146 u2 attributes_count = cfs->get_u2_fast(); 1155 u2 attributes_count = cfs->get_u2_fast();
1147 if (attributes_count > 0) { 1156 if (attributes_count > 0) {
1148 parse_field_attributes(cp, attributes_count, is_static, signature_index, 1157 parse_field_attributes(cp, attributes_count, is_static, signature_index,
1149 &constantvalue_index, &is_synthetic, 1158 &constantvalue_index, &is_synthetic,
1150 &generic_signature_index, &field_annotations, 1159 &generic_signature_index, &field_annotations,
1160 &parsed_annotations,
1151 CHECK_(nullHandle)); 1161 CHECK_(nullHandle));
1152 if (field_annotations.not_null()) { 1162 if (field_annotations.not_null()) {
1153 if (fields_annotations->is_null()) { 1163 if (fields_annotations->is_null()) {
1154 objArrayOop md = oopFactory::new_system_objArray(length, CHECK_(nullHandle)); 1164 objArrayOop md = oopFactory::new_system_objArray(length, CHECK_(nullHandle));
1155 *fields_annotations = objArrayHandle(THREAD, md); 1165 *fields_annotations = objArrayHandle(THREAD, md);
1171 field->initialize(access_flags.as_short(), 1181 field->initialize(access_flags.as_short(),
1172 name_index, 1182 name_index,
1173 signature_index, 1183 signature_index,
1174 constantvalue_index, 1184 constantvalue_index,
1175 0); 1185 0);
1186 if (parsed_annotations.has_any_annotations())
1187 parsed_annotations.apply_to(field);
1176 1188
1177 BasicType type = cp->basic_type_for_signature_at(signature_index); 1189 BasicType type = cp->basic_type_for_signature_at(signature_index);
1178 1190
1179 // Remember how many oops we encountered and compute allocation type 1191 // Remember how many oops we encountered and compute allocation type
1180 FieldAllocationType atype = fac->update(is_static, type); 1192 FieldAllocationType atype = fac->update(is_static, type);
1636 vmSymbols::java_lang_ClassFormatError(), 1648 vmSymbols::java_lang_ClassFormatError(),
1637 "%s \"%s\" in class %s has illegal signature \"%s\"", type, 1649 "%s \"%s\" in class %s has illegal signature \"%s\"", type,
1638 name->as_C_string(), _class_name->as_C_string(), sig->as_C_string()); 1650 name->as_C_string(), _class_name->as_C_string(), sig->as_C_string());
1639 } 1651 }
1640 1652
1653 // Skip an annotation. Return >=limit if there is any problem.
1654 int ClassFileParser::skip_annotation(u1* buffer, int limit, int index) {
1655 // annotation := atype:u2 do(nmem:u2) {member:u2 value}
1656 // value := switch (tag:u1) { ... }
1657 index += 2; // skip atype
1658 if ((index += 2) >= limit) return limit; // read nmem
1659 int nmem = Bytes::get_Java_u2(buffer+index-2);
1660 while (--nmem >= 0 && index < limit) {
1661 index += 2; // skip member
1662 index = skip_annotation_value(buffer, limit, index);
1663 }
1664 return index;
1665 }
1666
1667 // Skip an annotation value. Return >=limit if there is any problem.
1668 int ClassFileParser::skip_annotation_value(u1* buffer, int limit, int index) {
1669 // value := switch (tag:u1) {
1670 // case B, C, I, S, Z, D, F, J, c: con:u2;
1671 // case e: e_class:u2 e_name:u2;
1672 // case s: s_con:u2;
1673 // case [: do(nval:u2) {value};
1674 // case @: annotation;
1675 // case s: s_con:u2;
1676 // }
1677 if ((index += 1) >= limit) return limit; // read tag
1678 u1 tag = buffer[index-1];
1679 switch (tag) {
1680 case 'B': case 'C': case 'I': case 'S': case 'Z':
1681 case 'D': case 'F': case 'J': case 'c': case 's':
1682 index += 2; // skip con or s_con
1683 break;
1684 case 'e':
1685 index += 4; // skip e_class, e_name
1686 break;
1687 case '[':
1688 {
1689 if ((index += 2) >= limit) return limit; // read nval
1690 int nval = Bytes::get_Java_u2(buffer+index-2);
1691 while (--nval >= 0 && index < limit) {
1692 index = skip_annotation_value(buffer, limit, index);
1693 }
1694 }
1695 break;
1696 case '@':
1697 index = skip_annotation(buffer, limit, index);
1698 break;
1699 default:
1700 assert(false, "annotation tag");
1701 return limit; // bad tag byte
1702 }
1703 return index;
1704 }
1705
1706 // Sift through annotations, looking for those significant to the VM:
1707 void ClassFileParser::parse_annotations(u1* buffer, int limit,
1708 constantPoolHandle cp,
1709 ClassFileParser::AnnotationCollector* coll,
1710 TRAPS) {
1711 // annotations := do(nann:u2) {annotation}
1712 int index = 0;
1713 if ((index += 2) >= limit) return; // read nann
1714 int nann = Bytes::get_Java_u2(buffer+index-2);
1715 enum { // initial annotation layout
1716 atype_off = 0, // utf8 such as 'Ljava/lang/annotation/Retention;'
1717 count_off = 2, // u2 such as 1 (one value)
1718 member_off = 4, // utf8 such as 'value'
1719 tag_off = 6, // u1 such as 'c' (type) or 'e' (enum)
1720 e_tag_val = 'e',
1721 e_type_off = 7, // utf8 such as 'Ljava/lang/annotation/RetentionPolicy;'
1722 e_con_off = 9, // utf8 payload, such as 'SOURCE', 'CLASS', 'RUNTIME'
1723 e_size = 11, // end of 'e' annotation
1724 c_tag_val = 'c',
1725 c_con_off = 7, // utf8 payload, such as 'I' or 'Ljava/lang/String;'
1726 c_size = 9, // end of 'c' annotation
1727 min_size = 6 // smallest possible size (zero members)
1728 };
1729 while ((--nann) >= 0 && (index-2 + min_size <= limit)) {
1730 int index0 = index;
1731 index = skip_annotation(buffer, limit, index);
1732 u1* abase = buffer + index0;
1733 int atype = Bytes::get_Java_u2(abase + atype_off);
1734 int count = Bytes::get_Java_u2(abase + count_off);
1735 Symbol* aname = check_symbol_at(cp, atype);
1736 if (aname == NULL) break; // invalid annotation name
1737 Symbol* member = NULL;
1738 if (count >= 1) {
1739 int member_index = Bytes::get_Java_u2(abase + member_off);
1740 member = check_symbol_at(cp, member_index);
1741 if (member == NULL) break; // invalid member name
1742 }
1743
1744 // Here is where parsing particular annotations will take place.
1745 AnnotationCollector::ID id = coll->annotation_index(aname);
1746 if (id == AnnotationCollector::_unknown) continue;
1747 coll->set_annotation(id);
1748 // If there are no values, just set the bit and move on:
1749 if (count == 0) continue;
1750
1751 // For the record, here is how annotation payloads can be collected.
1752 // Suppose we want to capture @Retention.value. Here is how:
1753 //if (id == AnnotationCollector::_class_Retention) {
1754 // Symbol* payload = NULL;
1755 // if (count == 1
1756 // && e_size == (index0 - index) // match size
1757 // && e_tag_val == *(abase + tag_off)
1758 // && (check_symbol_at(cp, Bytes::get_Java_u2(abase + e_type_off))
1759 // == vmSymbols::RetentionPolicy_signature())
1760 // && member == vmSymbols::value_name()) {
1761 // payload = check_symbol_at(cp, Bytes::get_Java_u2(abase + e_con_off));
1762 // }
1763 // check_property(payload != NULL,
1764 // "Invalid @Retention annotation at offset %u in class file %s",
1765 // index0, CHECK);
1766 // if (payload != NULL) {
1767 // payload->increment_refcount();
1768 // coll->_class_RetentionPolicy = payload;
1769 // }
1770 //}
1771 }
1772 }
1773
1774 ClassFileParser::AnnotationCollector::ID ClassFileParser::AnnotationCollector::annotation_index(Symbol* name) {
1775 vmSymbols::SID sid = vmSymbols::find_sid(name);
1776 switch (sid) {
1777 case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_ForceInline_signature):
1778 if (_location != _in_method) break; // only allow for methods
1779 return _method_ForceInline;
1780 default: break;
1781 }
1782 return AnnotationCollector::_unknown;
1783 }
1784
1785 void ClassFileParser::FieldAnnotationCollector::apply_to(FieldInfo* f) {
1786 fatal("no field annotations yet");
1787 }
1788
1789 void ClassFileParser::MethodAnnotationCollector::apply_to(methodHandle m) {
1790 if (has_annotation(_method_ForceInline))
1791 m->set_force_inline(true);
1792 }
1793
1794 void ClassFileParser::ClassAnnotationCollector::apply_to(instanceKlassHandle k) {
1795 fatal("no class annotations yet");
1796 }
1797
1798
1641 #define MAX_ARGS_SIZE 255 1799 #define MAX_ARGS_SIZE 255
1642 #define MAX_CODE_SIZE 65535 1800 #define MAX_CODE_SIZE 65535
1643 #define INITIAL_MAX_LVT_NUMBER 256 1801 #define INITIAL_MAX_LVT_NUMBER 256
1644 1802
1645 // Note: the parse_method below is big and clunky because all parsing of the code and exceptions 1803 // Note: the parse_method below is big and clunky because all parsing of the code and exceptions
1646 // attribute is inlined. This is curbersome to avoid since we inline most of the parts in the 1804 // attribute is inlined. This is cumbersome to avoid since we inline most of the parts in the
1647 // methodOop to save footprint, so we only know the size of the resulting methodOop when the 1805 // methodOop to save footprint, so we only know the size of the resulting methodOop when the
1648 // entire method attribute is parsed. 1806 // entire method attribute is parsed.
1649 // 1807 //
1650 // The promoted_flags parameter is used to pass relevant access_flags 1808 // The promoted_flags parameter is used to pass relevant access_flags
1651 // from the method back up to the containing klass. These flag values 1809 // from the method back up to the containing klass. These flag values
1731 bool parsed_checked_exceptions_attribute = false; 1889 bool parsed_checked_exceptions_attribute = false;
1732 bool parsed_stackmap_attribute = false; 1890 bool parsed_stackmap_attribute = false;
1733 // stackmap attribute - JDK1.5 1891 // stackmap attribute - JDK1.5
1734 typeArrayHandle stackmap_data; 1892 typeArrayHandle stackmap_data;
1735 u2 generic_signature_index = 0; 1893 u2 generic_signature_index = 0;
1894 MethodAnnotationCollector parsed_annotations;
1736 u1* runtime_visible_annotations = NULL; 1895 u1* runtime_visible_annotations = NULL;
1737 int runtime_visible_annotations_length = 0; 1896 int runtime_visible_annotations_length = 0;
1738 u1* runtime_invisible_annotations = NULL; 1897 u1* runtime_invisible_annotations = NULL;
1739 int runtime_invisible_annotations_length = 0; 1898 int runtime_invisible_annotations_length = 0;
1740 u1* runtime_visible_parameter_annotations = NULL; 1899 u1* runtime_visible_parameter_annotations = NULL;
1957 generic_signature_index = cfs->get_u2_fast(); 2116 generic_signature_index = cfs->get_u2_fast();
1958 } else if (method_attribute_name == vmSymbols::tag_runtime_visible_annotations()) { 2117 } else if (method_attribute_name == vmSymbols::tag_runtime_visible_annotations()) {
1959 runtime_visible_annotations_length = method_attribute_length; 2118 runtime_visible_annotations_length = method_attribute_length;
1960 runtime_visible_annotations = cfs->get_u1_buffer(); 2119 runtime_visible_annotations = cfs->get_u1_buffer();
1961 assert(runtime_visible_annotations != NULL, "null visible annotations"); 2120 assert(runtime_visible_annotations != NULL, "null visible annotations");
2121 parse_annotations(runtime_visible_annotations, runtime_visible_annotations_length, cp, &parsed_annotations, CHECK_(nullHandle));
1962 cfs->skip_u1(runtime_visible_annotations_length, CHECK_(nullHandle)); 2122 cfs->skip_u1(runtime_visible_annotations_length, CHECK_(nullHandle));
1963 } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_annotations()) { 2123 } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_annotations()) {
1964 runtime_invisible_annotations_length = method_attribute_length; 2124 runtime_invisible_annotations_length = method_attribute_length;
1965 runtime_invisible_annotations = cfs->get_u1_buffer(); 2125 runtime_invisible_annotations = cfs->get_u1_buffer();
1966 assert(runtime_invisible_annotations != NULL, "null invisible annotations"); 2126 assert(runtime_invisible_annotations != NULL, "null invisible annotations");
2134 } 2294 }
2135 } 2295 }
2136 clear_hashtable(lvt_Hash); 2296 clear_hashtable(lvt_Hash);
2137 } 2297 }
2138 2298
2299 if (parsed_annotations.has_any_annotations())
2300 parsed_annotations.apply_to(m);
2139 *method_annotations = assemble_annotations(runtime_visible_annotations, 2301 *method_annotations = assemble_annotations(runtime_visible_annotations,
2140 runtime_visible_annotations_length, 2302 runtime_visible_annotations_length,
2141 runtime_invisible_annotations, 2303 runtime_invisible_annotations,
2142 runtime_invisible_annotations_length, 2304 runtime_invisible_annotations_length,
2143 CHECK_(nullHandle)); 2305 CHECK_(nullHandle));
2312 return typeArrayHandle(THREAD, Universe::the_empty_int_array()); 2474 return typeArrayHandle(THREAD, Universe::the_empty_int_array());
2313 } 2475 }
2314 } 2476 }
2315 2477
2316 2478
2317 void ClassFileParser::parse_classfile_sourcefile_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS) { 2479 void ClassFileParser::parse_classfile_sourcefile_attribute(constantPoolHandle cp, TRAPS) {
2318 ClassFileStream* cfs = stream(); 2480 ClassFileStream* cfs = stream();
2319 cfs->guarantee_more(2, CHECK); // sourcefile_index 2481 cfs->guarantee_more(2, CHECK); // sourcefile_index
2320 u2 sourcefile_index = cfs->get_u2_fast(); 2482 u2 sourcefile_index = cfs->get_u2_fast();
2321 check_property( 2483 check_property(
2322 valid_cp_range(sourcefile_index, cp->length()) && 2484 valid_cp_range(sourcefile_index, cp->length()) &&
2323 cp->tag_at(sourcefile_index).is_utf8(), 2485 cp->tag_at(sourcefile_index).is_utf8(),
2324 "Invalid SourceFile attribute at constant pool index %u in class file %s", 2486 "Invalid SourceFile attribute at constant pool index %u in class file %s",
2325 sourcefile_index, CHECK); 2487 sourcefile_index, CHECK);
2326 k->set_source_file_name(cp->symbol_at(sourcefile_index)); 2488 set_class_sourcefile(cp->symbol_at(sourcefile_index));
2327 } 2489 }
2328 2490
2329 2491
2330 2492
2331 void ClassFileParser::parse_classfile_source_debug_extension_attribute(constantPoolHandle cp, 2493 void ClassFileParser::parse_classfile_source_debug_extension_attribute(constantPoolHandle cp,
2332 instanceKlassHandle k,
2333 int length, TRAPS) { 2494 int length, TRAPS) {
2334 ClassFileStream* cfs = stream(); 2495 ClassFileStream* cfs = stream();
2335 u1* sde_buffer = cfs->get_u1_buffer(); 2496 u1* sde_buffer = cfs->get_u1_buffer();
2336 assert(sde_buffer != NULL, "null sde buffer"); 2497 assert(sde_buffer != NULL, "null sde buffer");
2337 2498
2338 // Don't bother storing it if there is no way to retrieve it 2499 // Don't bother storing it if there is no way to retrieve it
2339 if (JvmtiExport::can_get_source_debug_extension()) { 2500 if (JvmtiExport::can_get_source_debug_extension()) {
2340 k->set_source_debug_extension((char*)sde_buffer, length); 2501 assert((length+1) > length, "Overflow checking");
2502 u1* sde = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, u1, length+1);
2503 for (int i = 0; i < length; i++) {
2504 sde[i] = sde_buffer[i];
2505 }
2506 sde[length] = '\0';
2507 set_class_sde_buffer((char*)sde, length);
2341 } 2508 }
2342 // Got utf8 string, set stream position forward 2509 // Got utf8 string, set stream position forward
2343 cfs->skip_u1(length, CHECK); 2510 cfs->skip_u1(length, CHECK);
2344 } 2511 }
2345 2512
2351 u2 ClassFileParser::parse_classfile_inner_classes_attribute(u1* inner_classes_attribute_start, 2518 u2 ClassFileParser::parse_classfile_inner_classes_attribute(u1* inner_classes_attribute_start,
2352 bool parsed_enclosingmethod_attribute, 2519 bool parsed_enclosingmethod_attribute,
2353 u2 enclosing_method_class_index, 2520 u2 enclosing_method_class_index,
2354 u2 enclosing_method_method_index, 2521 u2 enclosing_method_method_index,
2355 constantPoolHandle cp, 2522 constantPoolHandle cp,
2356 instanceKlassHandle k, TRAPS) { 2523 TRAPS) {
2357 ClassFileStream* cfs = stream(); 2524 ClassFileStream* cfs = stream();
2358 u1* current_mark = cfs->current(); 2525 u1* current_mark = cfs->current();
2359 u2 length = 0; 2526 u2 length = 0;
2360 if (inner_classes_attribute_start != NULL) { 2527 if (inner_classes_attribute_start != NULL) {
2361 cfs->set_current(inner_classes_attribute_start); 2528 cfs->set_current(inner_classes_attribute_start);
2442 inner_classes->short_at_put(index++, enclosing_method_method_index); 2609 inner_classes->short_at_put(index++, enclosing_method_method_index);
2443 } 2610 }
2444 assert(index == size, "wrong size"); 2611 assert(index == size, "wrong size");
2445 2612
2446 // Update instanceKlass with inner class info. 2613 // Update instanceKlass with inner class info.
2447 k->set_inner_classes(inner_classes()); 2614 set_class_inner_classes(inner_classes);
2448 2615
2449 // Restore buffer's current position. 2616 // Restore buffer's current position.
2450 cfs->set_current(current_mark); 2617 cfs->set_current(current_mark);
2451 2618
2452 return length; 2619 return length;
2453 } 2620 }
2454 2621
2455 void ClassFileParser::parse_classfile_synthetic_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS) { 2622 void ClassFileParser::parse_classfile_synthetic_attribute(constantPoolHandle cp, TRAPS) {
2456 k->set_is_synthetic(); 2623 set_class_synthetic_flag(true);
2457 } 2624 }
2458 2625
2459 void ClassFileParser::parse_classfile_signature_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS) { 2626 void ClassFileParser::parse_classfile_signature_attribute(constantPoolHandle cp, TRAPS) {
2460 ClassFileStream* cfs = stream(); 2627 ClassFileStream* cfs = stream();
2461 u2 signature_index = cfs->get_u2(CHECK); 2628 u2 signature_index = cfs->get_u2(CHECK);
2462 check_property( 2629 check_property(
2463 valid_cp_range(signature_index, cp->length()) && 2630 valid_cp_range(signature_index, cp->length()) &&
2464 cp->tag_at(signature_index).is_utf8(), 2631 cp->tag_at(signature_index).is_utf8(),
2465 "Invalid constant pool index %u in Signature attribute in class file %s", 2632 "Invalid constant pool index %u in Signature attribute in class file %s",
2466 signature_index, CHECK); 2633 signature_index, CHECK);
2467 k->set_generic_signature(cp->symbol_at(signature_index)); 2634 set_class_generic_signature(cp->symbol_at(signature_index));
2468 } 2635 }
2469 2636
2470 void ClassFileParser::parse_classfile_bootstrap_methods_attribute(constantPoolHandle cp, instanceKlassHandle k, 2637 void ClassFileParser::parse_classfile_bootstrap_methods_attribute(constantPoolHandle cp,
2471 u4 attribute_byte_length, TRAPS) { 2638 u4 attribute_byte_length, TRAPS) {
2472 ClassFileStream* cfs = stream(); 2639 ClassFileStream* cfs = stream();
2473 u1* current_start = cfs->current(); 2640 u1* current_start = cfs->current();
2474 2641
2475 cfs->guarantee_more(2, CHECK); // length 2642 cfs->guarantee_more(2, CHECK); // length
2537 2704
2538 cp->set_operands(operands()); 2705 cp->set_operands(operands());
2539 } 2706 }
2540 2707
2541 2708
2542 void ClassFileParser::parse_classfile_attributes(constantPoolHandle cp, instanceKlassHandle k, TRAPS) { 2709 void ClassFileParser::parse_classfile_attributes(constantPoolHandle cp,
2710 ClassFileParser::ClassAnnotationCollector* parsed_annotations,
2711 TRAPS) {
2543 ClassFileStream* cfs = stream(); 2712 ClassFileStream* cfs = stream();
2544 // Set inner classes attribute to default sentinel 2713 // Set inner classes attribute to default sentinel
2545 k->set_inner_classes(Universe::the_empty_short_array()); 2714 set_class_inner_classes(typeArrayHandle(THREAD, Universe::the_empty_short_array()));
2546 cfs->guarantee_more(2, CHECK); // attributes_count 2715 cfs->guarantee_more(2, CHECK); // attributes_count
2547 u2 attributes_count = cfs->get_u2_fast(); 2716 u2 attributes_count = cfs->get_u2_fast();
2548 bool parsed_sourcefile_attribute = false; 2717 bool parsed_sourcefile_attribute = false;
2549 bool parsed_innerclasses_attribute = false; 2718 bool parsed_innerclasses_attribute = false;
2550 bool parsed_enclosingmethod_attribute = false; 2719 bool parsed_enclosingmethod_attribute = false;
2576 if (parsed_sourcefile_attribute) { 2745 if (parsed_sourcefile_attribute) {
2577 classfile_parse_error("Multiple SourceFile attributes in class file %s", CHECK); 2746 classfile_parse_error("Multiple SourceFile attributes in class file %s", CHECK);
2578 } else { 2747 } else {
2579 parsed_sourcefile_attribute = true; 2748 parsed_sourcefile_attribute = true;
2580 } 2749 }
2581 parse_classfile_sourcefile_attribute(cp, k, CHECK); 2750 parse_classfile_sourcefile_attribute(cp, CHECK);
2582 } else if (tag == vmSymbols::tag_source_debug_extension()) { 2751 } else if (tag == vmSymbols::tag_source_debug_extension()) {
2583 // Check for SourceDebugExtension tag 2752 // Check for SourceDebugExtension tag
2584 parse_classfile_source_debug_extension_attribute(cp, k, (int)attribute_length, CHECK); 2753 parse_classfile_source_debug_extension_attribute(cp, (int)attribute_length, CHECK);
2585 } else if (tag == vmSymbols::tag_inner_classes()) { 2754 } else if (tag == vmSymbols::tag_inner_classes()) {
2586 // Check for InnerClasses tag 2755 // Check for InnerClasses tag
2587 if (parsed_innerclasses_attribute) { 2756 if (parsed_innerclasses_attribute) {
2588 classfile_parse_error("Multiple InnerClasses attributes in class file %s", CHECK); 2757 classfile_parse_error("Multiple InnerClasses attributes in class file %s", CHECK);
2589 } else { 2758 } else {
2598 if (attribute_length != 0) { 2767 if (attribute_length != 0) {
2599 classfile_parse_error( 2768 classfile_parse_error(
2600 "Invalid Synthetic classfile attribute length %u in class file %s", 2769 "Invalid Synthetic classfile attribute length %u in class file %s",
2601 attribute_length, CHECK); 2770 attribute_length, CHECK);
2602 } 2771 }
2603 parse_classfile_synthetic_attribute(cp, k, CHECK); 2772 parse_classfile_synthetic_attribute(cp, CHECK);
2604 } else if (tag == vmSymbols::tag_deprecated()) { 2773 } else if (tag == vmSymbols::tag_deprecated()) {
2605 // Check for Deprecatd tag - 4276120 2774 // Check for Deprecatd tag - 4276120
2606 if (attribute_length != 0) { 2775 if (attribute_length != 0) {
2607 classfile_parse_error( 2776 classfile_parse_error(
2608 "Invalid Deprecated classfile attribute length %u in class file %s", 2777 "Invalid Deprecated classfile attribute length %u in class file %s",
2613 if (attribute_length != 2) { 2782 if (attribute_length != 2) {
2614 classfile_parse_error( 2783 classfile_parse_error(
2615 "Wrong Signature attribute length %u in class file %s", 2784 "Wrong Signature attribute length %u in class file %s",
2616 attribute_length, CHECK); 2785 attribute_length, CHECK);
2617 } 2786 }
2618 parse_classfile_signature_attribute(cp, k, CHECK); 2787 parse_classfile_signature_attribute(cp, CHECK);
2619 } else if (tag == vmSymbols::tag_runtime_visible_annotations()) { 2788 } else if (tag == vmSymbols::tag_runtime_visible_annotations()) {
2620 runtime_visible_annotations_length = attribute_length; 2789 runtime_visible_annotations_length = attribute_length;
2621 runtime_visible_annotations = cfs->get_u1_buffer(); 2790 runtime_visible_annotations = cfs->get_u1_buffer();
2622 assert(runtime_visible_annotations != NULL, "null visible annotations"); 2791 assert(runtime_visible_annotations != NULL, "null visible annotations");
2792 parse_annotations(runtime_visible_annotations,
2793 runtime_visible_annotations_length,
2794 cp,
2795 parsed_annotations,
2796 CHECK);
2623 cfs->skip_u1(runtime_visible_annotations_length, CHECK); 2797 cfs->skip_u1(runtime_visible_annotations_length, CHECK);
2624 } else if (PreserveAllAnnotations && tag == vmSymbols::tag_runtime_invisible_annotations()) { 2798 } else if (PreserveAllAnnotations && tag == vmSymbols::tag_runtime_invisible_annotations()) {
2625 runtime_invisible_annotations_length = attribute_length; 2799 runtime_invisible_annotations_length = attribute_length;
2626 runtime_invisible_annotations = cfs->get_u1_buffer(); 2800 runtime_invisible_annotations = cfs->get_u1_buffer();
2627 assert(runtime_invisible_annotations != NULL, "null invisible annotations"); 2801 assert(runtime_invisible_annotations != NULL, "null invisible annotations");
2651 } else if (tag == vmSymbols::tag_bootstrap_methods() && 2825 } else if (tag == vmSymbols::tag_bootstrap_methods() &&
2652 _major_version >= Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { 2826 _major_version >= Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
2653 if (parsed_bootstrap_methods_attribute) 2827 if (parsed_bootstrap_methods_attribute)
2654 classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK); 2828 classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK);
2655 parsed_bootstrap_methods_attribute = true; 2829 parsed_bootstrap_methods_attribute = true;
2656 parse_classfile_bootstrap_methods_attribute(cp, k, attribute_length, CHECK); 2830 parse_classfile_bootstrap_methods_attribute(cp, attribute_length, CHECK);
2657 } else { 2831 } else {
2658 // Unknown attribute 2832 // Unknown attribute
2659 cfs->skip_u1(attribute_length, CHECK); 2833 cfs->skip_u1(attribute_length, CHECK);
2660 } 2834 }
2661 } else { 2835 } else {
2666 typeArrayHandle annotations = assemble_annotations(runtime_visible_annotations, 2840 typeArrayHandle annotations = assemble_annotations(runtime_visible_annotations,
2667 runtime_visible_annotations_length, 2841 runtime_visible_annotations_length,
2668 runtime_invisible_annotations, 2842 runtime_invisible_annotations,
2669 runtime_invisible_annotations_length, 2843 runtime_invisible_annotations_length,
2670 CHECK); 2844 CHECK);
2671 k->set_class_annotations(annotations()); 2845 set_class_annotations(annotations);
2672 2846
2673 if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) { 2847 if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) {
2674 u2 num_of_classes = parse_classfile_inner_classes_attribute( 2848 u2 num_of_classes = parse_classfile_inner_classes_attribute(
2675 inner_classes_attribute_start, 2849 inner_classes_attribute_start,
2676 parsed_innerclasses_attribute, 2850 parsed_innerclasses_attribute,
2677 enclosing_method_class_index, 2851 enclosing_method_class_index,
2678 enclosing_method_method_index, 2852 enclosing_method_method_index,
2679 cp, k, CHECK); 2853 cp, CHECK);
2680 if (parsed_innerclasses_attribute &&_need_verify && _major_version >= JAVA_1_5_VERSION) { 2854 if (parsed_innerclasses_attribute &&_need_verify && _major_version >= JAVA_1_5_VERSION) {
2681 guarantee_property( 2855 guarantee_property(
2682 inner_classes_attribute_length == sizeof(num_of_classes) + 4 * sizeof(u2) * num_of_classes, 2856 inner_classes_attribute_length == sizeof(num_of_classes) + 4 * sizeof(u2) * num_of_classes,
2683 "Wrong InnerClasses attribute length in class file %s", CHECK); 2857 "Wrong InnerClasses attribute length in class file %s", CHECK);
2684 } 2858 }
2688 guarantee_property(parsed_bootstrap_methods_attribute, 2862 guarantee_property(parsed_bootstrap_methods_attribute,
2689 "Missing BootstrapMethods attribute in class file %s", CHECK); 2863 "Missing BootstrapMethods attribute in class file %s", CHECK);
2690 } 2864 }
2691 } 2865 }
2692 2866
2867 void ClassFileParser::apply_parsed_class_attributes(instanceKlassHandle k) {
2868 if (_synthetic_flag)
2869 k->set_is_synthetic();
2870 if (_sourcefile != NULL) {
2871 _sourcefile->increment_refcount();
2872 k->set_source_file_name(_sourcefile);
2873 }
2874 if (_generic_signature != NULL) {
2875 _generic_signature->increment_refcount();
2876 k->set_generic_signature(_generic_signature);
2877 }
2878 if (_sde_buffer != NULL) {
2879 k->set_source_debug_extension(_sde_buffer, _sde_length);
2880 }
2881 k->set_inner_classes(_inner_classes());
2882 k->set_class_annotations(_annotations());
2883 }
2693 2884
2694 typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annotations, 2885 typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annotations,
2695 int runtime_visible_annotations_length, 2886 int runtime_visible_annotations_length,
2696 u1* runtime_invisible_annotations, 2887 u1* runtime_invisible_annotations,
2697 int runtime_invisible_annotations_length, TRAPS) { 2888 int runtime_invisible_annotations_length, TRAPS) {
2738 NULL, 2929 NULL,
2739 jt->get_thread_stat()->perf_recursion_counts_addr(), 2930 jt->get_thread_stat()->perf_recursion_counts_addr(),
2740 jt->get_thread_stat()->perf_timers_addr(), 2931 jt->get_thread_stat()->perf_timers_addr(),
2741 PerfClassTraceTime::PARSE_CLASS); 2932 PerfClassTraceTime::PARSE_CLASS);
2742 2933
2743 _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false; 2934 init_parsed_class_attributes();
2744 _max_bootstrap_specifier_index = -1;
2745 2935
2746 if (JvmtiExport::should_post_class_file_load_hook()) { 2936 if (JvmtiExport::should_post_class_file_load_hook()) {
2747 // Get the cached class file bytes (if any) from the class that 2937 // Get the cached class file bytes (if any) from the class that
2748 // is being redefined or retransformed. We use jvmti_thread_state() 2938 // is being redefined or retransformed. We use jvmti_thread_state()
2749 // instead of JvmtiThreadState::state_for(jt) so we don't allocate 2939 // instead of JvmtiThreadState::state_for(jt) so we don't allocate
2971 CHECK_(nullHandle)); 3161 CHECK_(nullHandle));
2972 3162
2973 objArrayHandle methods_annotations(THREAD, methods_annotations_oop); 3163 objArrayHandle methods_annotations(THREAD, methods_annotations_oop);
2974 objArrayHandle methods_parameter_annotations(THREAD, methods_parameter_annotations_oop); 3164 objArrayHandle methods_parameter_annotations(THREAD, methods_parameter_annotations_oop);
2975 objArrayHandle methods_default_annotations(THREAD, methods_default_annotations_oop); 3165 objArrayHandle methods_default_annotations(THREAD, methods_default_annotations_oop);
3166
3167 // Additional attributes
3168 ClassAnnotationCollector parsed_annotations;
3169 parse_classfile_attributes(cp, &parsed_annotations, CHECK_(nullHandle));
3170
3171 // Make sure this is the end of class file stream
3172 guarantee_property(cfs->at_eos(), "Extra bytes at the end of class file %s", CHECK_(nullHandle));
2976 3173
2977 // We check super class after class file is parsed and format is checked 3174 // We check super class after class file is parsed and format is checked
2978 if (super_class_index > 0 && super_klass.is_null()) { 3175 if (super_class_index > 0 && super_klass.is_null()) {
2979 Symbol* sk = cp->klass_name_at(super_class_index); 3176 Symbol* sk = cp->klass_name_at(super_class_index);
2980 if (access_flags.is_interface()) { 3177 if (access_flags.is_interface()) {
3460 // super class exists and this class inherited miranda methods 3657 // super class exists and this class inherited miranda methods
3461 ) { 3658 ) {
3462 this_klass->set_has_miranda_methods(); // then set a flag 3659 this_klass->set_has_miranda_methods(); // then set a flag
3463 } 3660 }
3464 3661
3465 // Additional attributes 3662 // Fill in field values obtained by parse_classfile_attributes
3466 parse_classfile_attributes(cp, this_klass, CHECK_(nullHandle)); 3663 if (parsed_annotations.has_any_annotations())
3467 3664 parsed_annotations.apply_to(this_klass);
3468 // Make sure this is the end of class file stream 3665 apply_parsed_class_attributes(this_klass);
3469 guarantee_property(cfs->at_eos(), "Extra bytes at the end of class file %s", CHECK_(nullHandle));
3470 3666
3471 // VerifyOops believes that once this has been set, the object is completely loaded. 3667 // VerifyOops believes that once this has been set, the object is completely loaded.
3472 // Compute transitive closure of interfaces this class implements 3668 // Compute transitive closure of interfaces this class implements
3473 this_klass->set_transitive_interfaces(transitive_interfaces()); 3669 this_klass->set_transitive_interfaces(transitive_interfaces());
3474 3670
3479 klassItable::setup_itable_offset_table(this_klass); 3675 klassItable::setup_itable_offset_table(this_klass);
3480 3676
3481 // Do final class setup 3677 // Do final class setup
3482 fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts); 3678 fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
3483 3679
3680 // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
3484 set_precomputed_flags(this_klass); 3681 set_precomputed_flags(this_klass);
3485 3682
3486 // reinitialize modifiers, using the InnerClasses attribute 3683 // reinitialize modifiers, using the InnerClasses attribute
3487 int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle)); 3684 int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
3488 this_klass->set_modifier_flags(computed_modifiers); 3685 this_klass->set_modifier_flags(computed_modifiers);