1682 {
1683 debug_only(NoSafepointVerifier nsv;)
1684 for (AllFieldStream fs(_fields, cp); !fs.done(); fs.next()) {
1685 name = fs.name();
1686 sig = fs.signature();
1687 // If no duplicates, add name/signature in hashtable names_and_sigs.
1688 if (!put_after_lookup(name, sig, names_and_sigs)) {
1689 dup = true;
1690 break;
1691 }
1692 }
1693 }
1694 if (dup) {
1695 classfile_parse_error("Duplicate field name \"%s\" with signature \"%s\" in class file %s",
1696 name->as_C_string(), sig->as_klass_external_name(), CHECK);
1697 }
1698 }
1699 }
1700
1701
1702 const void* ClassFileParser::parse_exception_table(const ClassFileStream* const cfs,
1703 u4 code_length,
1704 u4 exception_table_length,
1705 TRAPS) {
1706 assert(cfs != NULL, "invariant");
1707
1708 const void* const exception_table_start = cfs->current();
1709 assert(exception_table_start != NULL, "null exception table");
1710
1711 cfs->guarantee_more(8 * exception_table_length, CHECK_NULL); // start_pc,
1712 // end_pc,
1713 // handler_pc,
1714 // catch_type_index
1715
1716 // Will check legal target after parsing code array in verifier.
1717 if (_need_verify) {
1718 for (unsigned int i = 0; i < exception_table_length; i++) {
1719 const u2 start_pc = cfs->get_u2_fast();
1720 const u2 end_pc = cfs->get_u2_fast();
1721 const u2 handler_pc = cfs->get_u2_fast();
1722 const u2 catch_type_index = cfs->get_u2_fast();
1723 guarantee_property((start_pc < end_pc) && (end_pc <= code_length),
1724 "Illegal exception table range in class file %s",
1725 CHECK_NULL);
1726 guarantee_property(handler_pc < code_length,
1727 "Illegal exception table handler in class file %s",
1728 CHECK_NULL);
1806 public:
1807 u2 start_bci;
1808 u2 length;
1809 u2 name_cp_index;
1810 u2 descriptor_cp_index;
1811 u2 slot;
1812 };
1813
1814 static void copy_lvt_element(const Classfile_LVT_Element* const src,
1815 LocalVariableTableElement* const lvt) {
1816 lvt->start_bci = Bytes::get_Java_u2((u1*) &src->start_bci);
1817 lvt->length = Bytes::get_Java_u2((u1*) &src->length);
1818 lvt->name_cp_index = Bytes::get_Java_u2((u1*) &src->name_cp_index);
1819 lvt->descriptor_cp_index = Bytes::get_Java_u2((u1*) &src->descriptor_cp_index);
1820 lvt->signature_cp_index = 0;
1821 lvt->slot = Bytes::get_Java_u2((u1*) &src->slot);
1822 }
1823
1824 // Function is used to parse both attributes:
1825 // LocalVariableTable (LVT) and LocalVariableTypeTable (LVTT)
1826 const void* ClassFileParser::parse_localvariable_table(const ClassFileStream* cfs,
1827 u4 code_length,
1828 u2 max_locals,
1829 u4 code_attribute_length,
1830 u2* const localvariable_table_length,
1831 bool isLVTT,
1832 TRAPS) {
1833 const char* const tbl_name = (isLVTT) ? "LocalVariableTypeTable" : "LocalVariableTable";
1834 *localvariable_table_length = cfs->get_u2(CHECK_NULL);
1835 const unsigned int size =
1836 (*localvariable_table_length) * sizeof(Classfile_LVT_Element) / sizeof(u2);
1837
1838 const ConstantPool* const cp = _cp;
1839
1840 // Verify local variable table attribute has right length
1841 if (_need_verify) {
1842 guarantee_property(code_attribute_length == (sizeof(*localvariable_table_length) + size * sizeof(u2)),
1843 "%s has wrong length in class file %s", tbl_name, CHECK_NULL);
1844 }
1845
1846 const void* const localvariable_table_start = cfs->current();
1847 assert(localvariable_table_start != NULL, "null local variable table");
1848 if (!_need_verify) {
1849 cfs->skip_u2_fast(size);
1850 } else {
1851 cfs->guarantee_more(size * 2, CHECK_NULL);
1852 for(int i = 0; i < (*localvariable_table_length); i++) {
1853 const u2 start_pc = cfs->get_u2_fast();
1854 const u2 length = cfs->get_u2_fast();
1855 const u2 name_index = cfs->get_u2_fast();
1856 const u2 descriptor_index = cfs->get_u2_fast();
1857 const u2 index = cfs->get_u2_fast();
1858 // Assign to a u4 to avoid overflow
1859 const u4 end_pc = (u4)start_pc + (u4)length;
1860
1861 if (start_pc >= code_length) {
1862 classfile_parse_error(
1863 "Invalid start_pc %u in %s in class file %s",
1864 start_pc, tbl_name, CHECK_NULL);
1865 }
1866 if (end_pc > code_length) {
1942 bool need_verify,
1943 TRAPS) {
1944 assert(cfs != NULL, "invariant");
1945
1946 if (0 == code_attribute_length) {
1947 return NULL;
1948 }
1949
1950 const u1* const stackmap_table_start = cfs->current();
1951 assert(stackmap_table_start != NULL, "null stackmap table");
1952
1953 // check code_attribute_length first
1954 cfs->skip_u1(code_attribute_length, CHECK_NULL);
1955
1956 if (!need_verify && !DumpSharedSpaces) {
1957 return NULL;
1958 }
1959 return stackmap_table_start;
1960 }
1961
1962 const void* ClassFileParser::parse_checked_exceptions(const ClassFileStream* const cfs,
1963 u2* const checked_exceptions_length,
1964 u4 method_attribute_length,
1965 TRAPS) {
1966 assert(cfs != NULL, "invariant");
1967 assert(checked_exceptions_length != NULL, "invariant");
1968
1969 cfs->guarantee_more(2, CHECK_NULL); // checked_exceptions_length
1970 *checked_exceptions_length = cfs->get_u2_fast();
1971 const unsigned int size =
1972 (*checked_exceptions_length) * sizeof(CheckedExceptionElement) / sizeof(u2);
1973 const void* const checked_exceptions_start = cfs->current();
1974 assert(checked_exceptions_start != NULL, "null checked exceptions");
1975 if (!_need_verify) {
1976 cfs->skip_u2_fast(size);
1977 } else {
1978 // Verify each value in the checked exception table
1979 u2 checked_exception;
1980 const u2 len = *checked_exceptions_length;
1981 cfs->guarantee_more(2 * len, CHECK_NULL);
1982 for (int i = 0; i < len; i++) {
1983 checked_exception = cfs->get_u2_fast();
1984 check_property(
1985 valid_klass_reference_at(checked_exception),
1986 "Exception name has bad type at constant pool %u in class file %s",
1987 checked_exception, CHECK_NULL);
1988 }
1989 }
1990 // check exceptions attribute length
1991 if (_need_verify) {
1992 guarantee_property(method_attribute_length == (sizeof(*checked_exceptions_length) +
1993 sizeof(u2) * size),
2120 #define MAX_ARGS_SIZE 255
2121 #define MAX_CODE_SIZE 65535
2122 #define INITIAL_MAX_LVT_NUMBER 256
2123
2124 /* Copy class file LVT's/LVTT's into the HotSpot internal LVT.
2125 *
2126 * Rules for LVT's and LVTT's are:
2127 * - There can be any number of LVT's and LVTT's.
2128 * - If there are n LVT's, it is the same as if there was just
2129 * one LVT containing all the entries from the n LVT's.
2130 * - There may be no more than one LVT entry per local variable.
2131 * Two LVT entries are 'equal' if these fields are the same:
2132 * start_pc, length, name, slot
2133 * - There may be no more than one LVTT entry per each LVT entry.
2134 * Each LVTT entry has to match some LVT entry.
2135 * - HotSpot internal LVT keeps natural ordering of class file LVT entries.
2136 */
2137 void ClassFileParser::copy_localvariable_table(const ConstMethod* cm,
2138 int lvt_cnt,
2139 u2* const localvariable_table_length,
2140 const void** const localvariable_table_start,
2141 int lvtt_cnt,
2142 u2* const localvariable_type_table_length,
2143 const void** const localvariable_type_table_start,
2144 TRAPS) {
2145
2146 ResourceMark rm(THREAD);
2147
2148 typedef ResourceHashtable<LocalVariableTableElement, LocalVariableTableElement*,
2149 &LVT_Hash::hash, &LVT_Hash::equals> LVT_HashTable;
2150
2151 LVT_HashTable* const table = new LVT_HashTable();
2152
2153 // To fill LocalVariableTable in
2154 const Classfile_LVT_Element* cf_lvt;
2155 LocalVariableTableElement* lvt = cm->localvariable_table_start();
2156
2157 for (int tbl_no = 0; tbl_no < lvt_cnt; tbl_no++) {
2158 cf_lvt = (Classfile_LVT_Element *) localvariable_table_start[tbl_no];
2159 for (int idx = 0; idx < localvariable_table_length[tbl_no]; idx++, lvt++) {
2160 copy_lvt_element(&cf_lvt[idx], lvt);
2161 // If no duplicates, add LVT elem in hashtable.
2162 if (table->put(*lvt, lvt) == false
2163 && _need_verify
2318 classfile_parse_error("Interface cannot have a method named <init>, class file %s", CHECK_NULL);
2319 }
2320
2321 int args_size = -1; // only used when _need_verify is true
2322 if (_need_verify) {
2323 args_size = ((flags & JVM_ACC_STATIC) ? 0 : 1) +
2324 verify_legal_method_signature(name, signature, CHECK_NULL);
2325 if (args_size > MAX_ARGS_SIZE) {
2326 classfile_parse_error("Too many arguments in method signature in class file %s", CHECK_NULL);
2327 }
2328 }
2329
2330 AccessFlags access_flags(flags & JVM_RECOGNIZED_METHOD_MODIFIERS);
2331
2332 // Default values for code and exceptions attribute elements
2333 u2 max_stack = 0;
2334 u2 max_locals = 0;
2335 u4 code_length = 0;
2336 const u1* code_start = 0;
2337 u2 exception_table_length = 0;
2338 const void* exception_table_start = NULL; // (potentially unaligned) pointer to array of u2 elements
2339 Array<int>* exception_handlers = Universe::the_empty_int_array();
2340 u2 checked_exceptions_length = 0;
2341 const void* checked_exceptions_start = NULL; // (potentially unaligned) pointer to array of u2 elements
2342 CompressedLineNumberWriteStream* linenumber_table = NULL;
2343 int linenumber_table_length = 0;
2344 int total_lvt_length = 0;
2345 u2 lvt_cnt = 0;
2346 u2 lvtt_cnt = 0;
2347 bool lvt_allocated = false;
2348 u2 max_lvt_cnt = INITIAL_MAX_LVT_NUMBER;
2349 u2 max_lvtt_cnt = INITIAL_MAX_LVT_NUMBER;
2350 u2* localvariable_table_length = NULL;
2351 const void** localvariable_table_start = NULL; // (potentially unaligned) pointer to array of LVT attributes
2352 u2* localvariable_type_table_length = NULL;
2353 const void** localvariable_type_table_start = NULL; // (potentially unaligned) pointer to LVTT attributes
2354 int method_parameters_length = -1;
2355 const u1* method_parameters_data = NULL;
2356 bool method_parameters_seen = false;
2357 bool parsed_code_attribute = false;
2358 bool parsed_checked_exceptions_attribute = false;
2359 bool parsed_stackmap_attribute = false;
2360 // stackmap attribute - JDK1.5
2361 const u1* stackmap_data = NULL;
2362 int stackmap_data_length = 0;
2363 u2 generic_signature_index = 0;
2364 MethodAnnotationCollector parsed_annotations;
2365 const u1* runtime_visible_annotations = NULL;
2366 int runtime_visible_annotations_length = 0;
2367 const u1* runtime_invisible_annotations = NULL;
2368 int runtime_invisible_annotations_length = 0;
2369 const u1* runtime_visible_parameter_annotations = NULL;
2370 int runtime_visible_parameter_annotations_length = 0;
2371 const u1* runtime_invisible_parameter_annotations = NULL;
2372 int runtime_invisible_parameter_annotations_length = 0;
2373 const u1* runtime_visible_type_annotations = NULL;
2474 sizeof(code_attribute_length);
2475 check_property(valid_symbol_at(code_attribute_name_index),
2476 "Invalid code attribute name index %u in class file %s",
2477 code_attribute_name_index,
2478 CHECK_NULL);
2479 if (LoadLineNumberTables &&
2480 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_line_number_table()) {
2481 // Parse and compress line number table
2482 parse_linenumber_table(code_attribute_length,
2483 code_length,
2484 &linenumber_table,
2485 CHECK_NULL);
2486
2487 } else if (LoadLocalVariableTables &&
2488 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_table()) {
2489 // Parse local variable table
2490 if (!lvt_allocated) {
2491 localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
2492 THREAD, u2, INITIAL_MAX_LVT_NUMBER);
2493 localvariable_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
2494 THREAD, const void*, INITIAL_MAX_LVT_NUMBER);
2495 localvariable_type_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
2496 THREAD, u2, INITIAL_MAX_LVT_NUMBER);
2497 localvariable_type_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
2498 THREAD, const void*, INITIAL_MAX_LVT_NUMBER);
2499 lvt_allocated = true;
2500 }
2501 if (lvt_cnt == max_lvt_cnt) {
2502 max_lvt_cnt <<= 1;
2503 localvariable_table_length = REALLOC_RESOURCE_ARRAY(u2, localvariable_table_length, lvt_cnt, max_lvt_cnt);
2504 localvariable_table_start = REALLOC_RESOURCE_ARRAY(const void*, localvariable_table_start, lvt_cnt, max_lvt_cnt);
2505 }
2506 localvariable_table_start[lvt_cnt] =
2507 parse_localvariable_table(cfs,
2508 code_length,
2509 max_locals,
2510 code_attribute_length,
2511 &localvariable_table_length[lvt_cnt],
2512 false, // is not LVTT
2513 CHECK_NULL);
2514 total_lvt_length += localvariable_table_length[lvt_cnt];
2515 lvt_cnt++;
2516 } else if (LoadLocalVariableTypeTables &&
2517 _major_version >= JAVA_1_5_VERSION &&
2518 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_type_table()) {
2519 if (!lvt_allocated) {
2520 localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
2521 THREAD, u2, INITIAL_MAX_LVT_NUMBER);
2522 localvariable_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
2523 THREAD, const void*, INITIAL_MAX_LVT_NUMBER);
2524 localvariable_type_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
2525 THREAD, u2, INITIAL_MAX_LVT_NUMBER);
2526 localvariable_type_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
2527 THREAD, const void*, INITIAL_MAX_LVT_NUMBER);
2528 lvt_allocated = true;
2529 }
2530 // Parse local variable type table
2531 if (lvtt_cnt == max_lvtt_cnt) {
2532 max_lvtt_cnt <<= 1;
2533 localvariable_type_table_length = REALLOC_RESOURCE_ARRAY(u2, localvariable_type_table_length, lvtt_cnt, max_lvtt_cnt);
2534 localvariable_type_table_start = REALLOC_RESOURCE_ARRAY(const void*, localvariable_type_table_start, lvtt_cnt, max_lvtt_cnt);
2535 }
2536 localvariable_type_table_start[lvtt_cnt] =
2537 parse_localvariable_table(cfs,
2538 code_length,
2539 max_locals,
2540 code_attribute_length,
2541 &localvariable_type_table_length[lvtt_cnt],
2542 true, // is LVTT
2543 CHECK_NULL);
2544 lvtt_cnt++;
2545 } else if (_major_version >= Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION &&
2546 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_stack_map_table()) {
2547 // Stack map is only needed by the new verifier in JDK1.5.
2548 if (parsed_stackmap_attribute) {
2549 classfile_parse_error("Multiple StackMapTable attributes in class file %s", CHECK_NULL);
2550 }
2551 stackmap_data = parse_stackmap_table(cfs, code_attribute_length, _need_verify, CHECK_NULL);
2552 stackmap_data_length = code_attribute_length;
2553 parsed_stackmap_attribute = true;
2554 } else {
|
1682 {
1683 debug_only(NoSafepointVerifier nsv;)
1684 for (AllFieldStream fs(_fields, cp); !fs.done(); fs.next()) {
1685 name = fs.name();
1686 sig = fs.signature();
1687 // If no duplicates, add name/signature in hashtable names_and_sigs.
1688 if (!put_after_lookup(name, sig, names_and_sigs)) {
1689 dup = true;
1690 break;
1691 }
1692 }
1693 }
1694 if (dup) {
1695 classfile_parse_error("Duplicate field name \"%s\" with signature \"%s\" in class file %s",
1696 name->as_C_string(), sig->as_klass_external_name(), CHECK);
1697 }
1698 }
1699 }
1700
1701
1702 const ClassFileParser::unsafe_u2* ClassFileParser::parse_exception_table(const ClassFileStream* const cfs,
1703 u4 code_length,
1704 u4 exception_table_length,
1705 TRAPS) {
1706 assert(cfs != NULL, "invariant");
1707
1708 const unsafe_u2* const exception_table_start = cfs->current();
1709 assert(exception_table_start != NULL, "null exception table");
1710
1711 cfs->guarantee_more(8 * exception_table_length, CHECK_NULL); // start_pc,
1712 // end_pc,
1713 // handler_pc,
1714 // catch_type_index
1715
1716 // Will check legal target after parsing code array in verifier.
1717 if (_need_verify) {
1718 for (unsigned int i = 0; i < exception_table_length; i++) {
1719 const u2 start_pc = cfs->get_u2_fast();
1720 const u2 end_pc = cfs->get_u2_fast();
1721 const u2 handler_pc = cfs->get_u2_fast();
1722 const u2 catch_type_index = cfs->get_u2_fast();
1723 guarantee_property((start_pc < end_pc) && (end_pc <= code_length),
1724 "Illegal exception table range in class file %s",
1725 CHECK_NULL);
1726 guarantee_property(handler_pc < code_length,
1727 "Illegal exception table handler in class file %s",
1728 CHECK_NULL);
1806 public:
1807 u2 start_bci;
1808 u2 length;
1809 u2 name_cp_index;
1810 u2 descriptor_cp_index;
1811 u2 slot;
1812 };
1813
1814 static void copy_lvt_element(const Classfile_LVT_Element* const src,
1815 LocalVariableTableElement* const lvt) {
1816 lvt->start_bci = Bytes::get_Java_u2((u1*) &src->start_bci);
1817 lvt->length = Bytes::get_Java_u2((u1*) &src->length);
1818 lvt->name_cp_index = Bytes::get_Java_u2((u1*) &src->name_cp_index);
1819 lvt->descriptor_cp_index = Bytes::get_Java_u2((u1*) &src->descriptor_cp_index);
1820 lvt->signature_cp_index = 0;
1821 lvt->slot = Bytes::get_Java_u2((u1*) &src->slot);
1822 }
1823
1824 // Function is used to parse both attributes:
1825 // LocalVariableTable (LVT) and LocalVariableTypeTable (LVTT)
1826 const ClassFileParser::unsafe_u2* ClassFileParser::parse_localvariable_table(const ClassFileStream* cfs,
1827 u4 code_length,
1828 u2 max_locals,
1829 u4 code_attribute_length,
1830 u2* const localvariable_table_length,
1831 bool isLVTT,
1832 TRAPS) {
1833 const char* const tbl_name = (isLVTT) ? "LocalVariableTypeTable" : "LocalVariableTable";
1834 *localvariable_table_length = cfs->get_u2(CHECK_NULL);
1835 const unsigned int size =
1836 (*localvariable_table_length) * sizeof(Classfile_LVT_Element) / sizeof(u2);
1837
1838 const ConstantPool* const cp = _cp;
1839
1840 // Verify local variable table attribute has right length
1841 if (_need_verify) {
1842 guarantee_property(code_attribute_length == (sizeof(*localvariable_table_length) + size * sizeof(u2)),
1843 "%s has wrong length in class file %s", tbl_name, CHECK_NULL);
1844 }
1845
1846 const unsafe_u2* const localvariable_table_start = cfs->current();
1847 assert(localvariable_table_start != NULL, "null local variable table");
1848 if (!_need_verify) {
1849 cfs->skip_u2_fast(size);
1850 } else {
1851 cfs->guarantee_more(size * 2, CHECK_NULL);
1852 for(int i = 0; i < (*localvariable_table_length); i++) {
1853 const u2 start_pc = cfs->get_u2_fast();
1854 const u2 length = cfs->get_u2_fast();
1855 const u2 name_index = cfs->get_u2_fast();
1856 const u2 descriptor_index = cfs->get_u2_fast();
1857 const u2 index = cfs->get_u2_fast();
1858 // Assign to a u4 to avoid overflow
1859 const u4 end_pc = (u4)start_pc + (u4)length;
1860
1861 if (start_pc >= code_length) {
1862 classfile_parse_error(
1863 "Invalid start_pc %u in %s in class file %s",
1864 start_pc, tbl_name, CHECK_NULL);
1865 }
1866 if (end_pc > code_length) {
1942 bool need_verify,
1943 TRAPS) {
1944 assert(cfs != NULL, "invariant");
1945
1946 if (0 == code_attribute_length) {
1947 return NULL;
1948 }
1949
1950 const u1* const stackmap_table_start = cfs->current();
1951 assert(stackmap_table_start != NULL, "null stackmap table");
1952
1953 // check code_attribute_length first
1954 cfs->skip_u1(code_attribute_length, CHECK_NULL);
1955
1956 if (!need_verify && !DumpSharedSpaces) {
1957 return NULL;
1958 }
1959 return stackmap_table_start;
1960 }
1961
1962 const ClassFileParser::unsafe_u2* ClassFileParser::parse_checked_exceptions(const ClassFileStream* const cfs,
1963 u2* const checked_exceptions_length,
1964 u4 method_attribute_length,
1965 TRAPS) {
1966 assert(cfs != NULL, "invariant");
1967 assert(checked_exceptions_length != NULL, "invariant");
1968
1969 cfs->guarantee_more(2, CHECK_NULL); // checked_exceptions_length
1970 *checked_exceptions_length = cfs->get_u2_fast();
1971 const unsigned int size =
1972 (*checked_exceptions_length) * sizeof(CheckedExceptionElement) / sizeof(u2);
1973 const unsafe_u2* const checked_exceptions_start = cfs->current();
1974 assert(checked_exceptions_start != NULL, "null checked exceptions");
1975 if (!_need_verify) {
1976 cfs->skip_u2_fast(size);
1977 } else {
1978 // Verify each value in the checked exception table
1979 u2 checked_exception;
1980 const u2 len = *checked_exceptions_length;
1981 cfs->guarantee_more(2 * len, CHECK_NULL);
1982 for (int i = 0; i < len; i++) {
1983 checked_exception = cfs->get_u2_fast();
1984 check_property(
1985 valid_klass_reference_at(checked_exception),
1986 "Exception name has bad type at constant pool %u in class file %s",
1987 checked_exception, CHECK_NULL);
1988 }
1989 }
1990 // check exceptions attribute length
1991 if (_need_verify) {
1992 guarantee_property(method_attribute_length == (sizeof(*checked_exceptions_length) +
1993 sizeof(u2) * size),
2120 #define MAX_ARGS_SIZE 255
2121 #define MAX_CODE_SIZE 65535
2122 #define INITIAL_MAX_LVT_NUMBER 256
2123
2124 /* Copy class file LVT's/LVTT's into the HotSpot internal LVT.
2125 *
2126 * Rules for LVT's and LVTT's are:
2127 * - There can be any number of LVT's and LVTT's.
2128 * - If there are n LVT's, it is the same as if there was just
2129 * one LVT containing all the entries from the n LVT's.
2130 * - There may be no more than one LVT entry per local variable.
2131 * Two LVT entries are 'equal' if these fields are the same:
2132 * start_pc, length, name, slot
2133 * - There may be no more than one LVTT entry per each LVT entry.
2134 * Each LVTT entry has to match some LVT entry.
2135 * - HotSpot internal LVT keeps natural ordering of class file LVT entries.
2136 */
2137 void ClassFileParser::copy_localvariable_table(const ConstMethod* cm,
2138 int lvt_cnt,
2139 u2* const localvariable_table_length,
2140 const unsafe_u2** const localvariable_table_start,
2141 int lvtt_cnt,
2142 u2* const localvariable_type_table_length,
2143 const unsafe_u2** const localvariable_type_table_start,
2144 TRAPS) {
2145
2146 ResourceMark rm(THREAD);
2147
2148 typedef ResourceHashtable<LocalVariableTableElement, LocalVariableTableElement*,
2149 &LVT_Hash::hash, &LVT_Hash::equals> LVT_HashTable;
2150
2151 LVT_HashTable* const table = new LVT_HashTable();
2152
2153 // To fill LocalVariableTable in
2154 const Classfile_LVT_Element* cf_lvt;
2155 LocalVariableTableElement* lvt = cm->localvariable_table_start();
2156
2157 for (int tbl_no = 0; tbl_no < lvt_cnt; tbl_no++) {
2158 cf_lvt = (Classfile_LVT_Element *) localvariable_table_start[tbl_no];
2159 for (int idx = 0; idx < localvariable_table_length[tbl_no]; idx++, lvt++) {
2160 copy_lvt_element(&cf_lvt[idx], lvt);
2161 // If no duplicates, add LVT elem in hashtable.
2162 if (table->put(*lvt, lvt) == false
2163 && _need_verify
2318 classfile_parse_error("Interface cannot have a method named <init>, class file %s", CHECK_NULL);
2319 }
2320
2321 int args_size = -1; // only used when _need_verify is true
2322 if (_need_verify) {
2323 args_size = ((flags & JVM_ACC_STATIC) ? 0 : 1) +
2324 verify_legal_method_signature(name, signature, CHECK_NULL);
2325 if (args_size > MAX_ARGS_SIZE) {
2326 classfile_parse_error("Too many arguments in method signature in class file %s", CHECK_NULL);
2327 }
2328 }
2329
2330 AccessFlags access_flags(flags & JVM_RECOGNIZED_METHOD_MODIFIERS);
2331
2332 // Default values for code and exceptions attribute elements
2333 u2 max_stack = 0;
2334 u2 max_locals = 0;
2335 u4 code_length = 0;
2336 const u1* code_start = 0;
2337 u2 exception_table_length = 0;
2338 const unsafe_u2* exception_table_start = NULL; // (potentially unaligned) pointer to array of u2 elements
2339 Array<int>* exception_handlers = Universe::the_empty_int_array();
2340 u2 checked_exceptions_length = 0;
2341 const unsafe_u2* checked_exceptions_start = NULL; // (potentially unaligned) pointer to array of u2 elements
2342 CompressedLineNumberWriteStream* linenumber_table = NULL;
2343 int linenumber_table_length = 0;
2344 int total_lvt_length = 0;
2345 u2 lvt_cnt = 0;
2346 u2 lvtt_cnt = 0;
2347 bool lvt_allocated = false;
2348 u2 max_lvt_cnt = INITIAL_MAX_LVT_NUMBER;
2349 u2 max_lvtt_cnt = INITIAL_MAX_LVT_NUMBER;
2350 u2* localvariable_table_length = NULL;
2351 const unsafe_u2** localvariable_table_start = NULL; // (potentially unaligned) pointer to array of LVT attributes
2352 u2* localvariable_type_table_length = NULL;
2353 const unsafe_u2** localvariable_type_table_start = NULL; // (potentially unaligned) pointer to LVTT attributes
2354 int method_parameters_length = -1;
2355 const u1* method_parameters_data = NULL;
2356 bool method_parameters_seen = false;
2357 bool parsed_code_attribute = false;
2358 bool parsed_checked_exceptions_attribute = false;
2359 bool parsed_stackmap_attribute = false;
2360 // stackmap attribute - JDK1.5
2361 const u1* stackmap_data = NULL;
2362 int stackmap_data_length = 0;
2363 u2 generic_signature_index = 0;
2364 MethodAnnotationCollector parsed_annotations;
2365 const u1* runtime_visible_annotations = NULL;
2366 int runtime_visible_annotations_length = 0;
2367 const u1* runtime_invisible_annotations = NULL;
2368 int runtime_invisible_annotations_length = 0;
2369 const u1* runtime_visible_parameter_annotations = NULL;
2370 int runtime_visible_parameter_annotations_length = 0;
2371 const u1* runtime_invisible_parameter_annotations = NULL;
2372 int runtime_invisible_parameter_annotations_length = 0;
2373 const u1* runtime_visible_type_annotations = NULL;
2474 sizeof(code_attribute_length);
2475 check_property(valid_symbol_at(code_attribute_name_index),
2476 "Invalid code attribute name index %u in class file %s",
2477 code_attribute_name_index,
2478 CHECK_NULL);
2479 if (LoadLineNumberTables &&
2480 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_line_number_table()) {
2481 // Parse and compress line number table
2482 parse_linenumber_table(code_attribute_length,
2483 code_length,
2484 &linenumber_table,
2485 CHECK_NULL);
2486
2487 } else if (LoadLocalVariableTables &&
2488 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_table()) {
2489 // Parse local variable table
2490 if (!lvt_allocated) {
2491 localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
2492 THREAD, u2, INITIAL_MAX_LVT_NUMBER);
2493 localvariable_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
2494 THREAD, const unsafe_u2*, INITIAL_MAX_LVT_NUMBER);
2495 localvariable_type_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
2496 THREAD, u2, INITIAL_MAX_LVT_NUMBER);
2497 localvariable_type_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
2498 THREAD, const unsafe_u2*, INITIAL_MAX_LVT_NUMBER);
2499 lvt_allocated = true;
2500 }
2501 if (lvt_cnt == max_lvt_cnt) {
2502 max_lvt_cnt <<= 1;
2503 localvariable_table_length = REALLOC_RESOURCE_ARRAY(u2, localvariable_table_length, lvt_cnt, max_lvt_cnt);
2504 localvariable_table_start = REALLOC_RESOURCE_ARRAY(const unsafe_u2*, localvariable_table_start, lvt_cnt, max_lvt_cnt);
2505 }
2506 localvariable_table_start[lvt_cnt] =
2507 parse_localvariable_table(cfs,
2508 code_length,
2509 max_locals,
2510 code_attribute_length,
2511 &localvariable_table_length[lvt_cnt],
2512 false, // is not LVTT
2513 CHECK_NULL);
2514 total_lvt_length += localvariable_table_length[lvt_cnt];
2515 lvt_cnt++;
2516 } else if (LoadLocalVariableTypeTables &&
2517 _major_version >= JAVA_1_5_VERSION &&
2518 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_type_table()) {
2519 if (!lvt_allocated) {
2520 localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
2521 THREAD, u2, INITIAL_MAX_LVT_NUMBER);
2522 localvariable_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
2523 THREAD, const unsafe_u2*, INITIAL_MAX_LVT_NUMBER);
2524 localvariable_type_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
2525 THREAD, u2, INITIAL_MAX_LVT_NUMBER);
2526 localvariable_type_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
2527 THREAD, const unsafe_u2*, INITIAL_MAX_LVT_NUMBER);
2528 lvt_allocated = true;
2529 }
2530 // Parse local variable type table
2531 if (lvtt_cnt == max_lvtt_cnt) {
2532 max_lvtt_cnt <<= 1;
2533 localvariable_type_table_length = REALLOC_RESOURCE_ARRAY(u2, localvariable_type_table_length, lvtt_cnt, max_lvtt_cnt);
2534 localvariable_type_table_start = REALLOC_RESOURCE_ARRAY(const unsafe_u2*, localvariable_type_table_start, lvtt_cnt, max_lvtt_cnt);
2535 }
2536 localvariable_type_table_start[lvtt_cnt] =
2537 parse_localvariable_table(cfs,
2538 code_length,
2539 max_locals,
2540 code_attribute_length,
2541 &localvariable_type_table_length[lvtt_cnt],
2542 true, // is LVTT
2543 CHECK_NULL);
2544 lvtt_cnt++;
2545 } else if (_major_version >= Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION &&
2546 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_stack_map_table()) {
2547 // Stack map is only needed by the new verifier in JDK1.5.
2548 if (parsed_stackmap_attribute) {
2549 classfile_parse_error("Multiple StackMapTable attributes in class file %s", CHECK_NULL);
2550 }
2551 stackmap_data = parse_stackmap_table(cfs, code_attribute_length, _need_verify, CHECK_NULL);
2552 stackmap_data_length = code_attribute_length;
2553 parsed_stackmap_attribute = true;
2554 } else {
|