< prev index next >

src/share/vm/classfile/classFileParser.cpp

Print this page
@  rev 12742 : imported patch alpinefixes-copyswapaligned
|


1657     {
1658       debug_only(NoSafepointVerifier nsv;)
1659       for (AllFieldStream fs(_fields, cp); !fs.done(); fs.next()) {
1660         const Symbol* const name = fs.name();
1661         const Symbol* const sig = fs.signature();
1662         // If no duplicates, add name/signature in hashtable names_and_sigs.
1663         if (!put_after_lookup(name, sig, names_and_sigs)) {
1664           dup = true;
1665           break;
1666         }
1667       }
1668     }
1669     if (dup) {
1670       classfile_parse_error("Duplicate field name&signature in class file %s",
1671                             CHECK);
1672     }
1673   }
1674 }
1675 
1676 
1677 static void copy_u2_with_conversion(u2* dest, const u2* src, int length) {
1678   while (length-- > 0) {
1679     *dest++ = Bytes::get_Java_u2((u1*) (src++));
1680   }
1681 }
1682 
1683 const u2* ClassFileParser::parse_exception_table(const ClassFileStream* const cfs,
1684                                                  u4 code_length,
1685                                                  u4 exception_table_length,
1686                                                  TRAPS) {
1687   assert(cfs != NULL, "invariant");
1688 
1689   const u2* const exception_table_start = cfs->get_u2_buffer();
1690   assert(exception_table_start != NULL, "null exception table");
1691 
1692   cfs->guarantee_more(8 * exception_table_length, CHECK_NULL); // start_pc,
1693                                                                // end_pc,
1694                                                                // handler_pc,
1695                                                                // catch_type_index
1696 
1697   // Will check legal target after parsing code array in verifier.
1698   if (_need_verify) {
1699     for (unsigned int i = 0; i < exception_table_length; i++) {
1700       const u2 start_pc = cfs->get_u2_fast();
1701       const u2 end_pc = cfs->get_u2_fast();
1702       const u2 handler_pc = cfs->get_u2_fast();
1703       const u2 catch_type_index = cfs->get_u2_fast();
1704       guarantee_property((start_pc < end_pc) && (end_pc <= code_length),
1705                          "Illegal exception table range in class file %s",
1706                          CHECK_NULL);
1707       guarantee_property(handler_pc < code_length,
1708                          "Illegal exception table handler in class file %s",
1709                          CHECK_NULL);


1787  public:
1788   u2 start_bci;
1789   u2 length;
1790   u2 name_cp_index;
1791   u2 descriptor_cp_index;
1792   u2 slot;
1793 };
1794 
1795 static void copy_lvt_element(const Classfile_LVT_Element* const src,
1796                              LocalVariableTableElement* const lvt) {
1797   lvt->start_bci           = Bytes::get_Java_u2((u1*) &src->start_bci);
1798   lvt->length              = Bytes::get_Java_u2((u1*) &src->length);
1799   lvt->name_cp_index       = Bytes::get_Java_u2((u1*) &src->name_cp_index);
1800   lvt->descriptor_cp_index = Bytes::get_Java_u2((u1*) &src->descriptor_cp_index);
1801   lvt->signature_cp_index  = 0;
1802   lvt->slot                = Bytes::get_Java_u2((u1*) &src->slot);
1803 }
1804 
1805 // Function is used to parse both attributes:
1806 // LocalVariableTable (LVT) and LocalVariableTypeTable (LVTT)
1807 const u2* ClassFileParser::parse_localvariable_table(const ClassFileStream* cfs,
1808                                                      u4 code_length,
1809                                                      u2 max_locals,
1810                                                      u4 code_attribute_length,
1811                                                      u2* const localvariable_table_length,
1812                                                      bool isLVTT,
1813                                                      TRAPS) {
1814   const char* const tbl_name = (isLVTT) ? "LocalVariableTypeTable" : "LocalVariableTable";
1815   *localvariable_table_length = cfs->get_u2(CHECK_NULL);
1816   const unsigned int size =
1817     (*localvariable_table_length) * sizeof(Classfile_LVT_Element) / sizeof(u2);
1818 
1819   const ConstantPool* const cp = _cp;
1820 
1821   // Verify local variable table attribute has right length
1822   if (_need_verify) {
1823     guarantee_property(code_attribute_length == (sizeof(*localvariable_table_length) + size * sizeof(u2)),
1824                        "%s has wrong length in class file %s", tbl_name, CHECK_NULL);
1825   }
1826 
1827   const u2* const localvariable_table_start = cfs->get_u2_buffer();
1828   assert(localvariable_table_start != NULL, "null local variable table");
1829   if (!_need_verify) {
1830     cfs->skip_u2_fast(size);
1831   } else {
1832     cfs->guarantee_more(size * 2, CHECK_NULL);
1833     for(int i = 0; i < (*localvariable_table_length); i++) {
1834       const u2 start_pc = cfs->get_u2_fast();
1835       const u2 length = cfs->get_u2_fast();
1836       const u2 name_index = cfs->get_u2_fast();
1837       const u2 descriptor_index = cfs->get_u2_fast();
1838       const u2 index = cfs->get_u2_fast();
1839       // Assign to a u4 to avoid overflow
1840       const u4 end_pc = (u4)start_pc + (u4)length;
1841 
1842       if (start_pc >= code_length) {
1843         classfile_parse_error(
1844           "Invalid start_pc %u in %s in class file %s",
1845           start_pc, tbl_name, CHECK_NULL);
1846       }
1847       if (end_pc > code_length) {


1923                                       bool need_verify,
1924                                       TRAPS) {
1925   assert(cfs != NULL, "invariant");
1926 
1927   if (0 == code_attribute_length) {
1928     return NULL;
1929   }
1930 
1931   const u1* const stackmap_table_start = cfs->get_u1_buffer();
1932   assert(stackmap_table_start != NULL, "null stackmap table");
1933 
1934   // check code_attribute_length first
1935   cfs->skip_u1(code_attribute_length, CHECK_NULL);
1936 
1937   if (!need_verify && !DumpSharedSpaces) {
1938     return NULL;
1939   }
1940   return stackmap_table_start;
1941 }
1942 
1943 const u2* ClassFileParser::parse_checked_exceptions(const ClassFileStream* const cfs,
1944                                                     u2* const checked_exceptions_length,
1945                                                     u4 method_attribute_length,
1946                                                     TRAPS) {
1947   assert(cfs != NULL, "invariant");
1948   assert(checked_exceptions_length != NULL, "invariant");
1949 
1950   cfs->guarantee_more(2, CHECK_NULL);  // checked_exceptions_length
1951   *checked_exceptions_length = cfs->get_u2_fast();
1952   const unsigned int size =
1953     (*checked_exceptions_length) * sizeof(CheckedExceptionElement) / sizeof(u2);
1954   const u2* const checked_exceptions_start = cfs->get_u2_buffer();
1955   assert(checked_exceptions_start != NULL, "null checked exceptions");
1956   if (!_need_verify) {
1957     cfs->skip_u2_fast(size);
1958   } else {
1959     // Verify each value in the checked exception table
1960     u2 checked_exception;
1961     const u2 len = *checked_exceptions_length;
1962     cfs->guarantee_more(2 * len, CHECK_NULL);
1963     for (int i = 0; i < len; i++) {
1964       checked_exception = cfs->get_u2_fast();
1965       check_property(
1966         valid_klass_reference_at(checked_exception),
1967         "Exception name has bad type at constant pool %u in class file %s",
1968         checked_exception, CHECK_NULL);
1969     }
1970   }
1971   // check exceptions attribute length
1972   if (_need_verify) {
1973     guarantee_property(method_attribute_length == (sizeof(*checked_exceptions_length) +
1974                                                    sizeof(u2) * size),


2101 #define MAX_ARGS_SIZE 255
2102 #define MAX_CODE_SIZE 65535
2103 #define INITIAL_MAX_LVT_NUMBER 256
2104 
2105 /* Copy class file LVT's/LVTT's into the HotSpot internal LVT.
2106  *
2107  * Rules for LVT's and LVTT's are:
2108  *   - There can be any number of LVT's and LVTT's.
2109  *   - If there are n LVT's, it is the same as if there was just
2110  *     one LVT containing all the entries from the n LVT's.
2111  *   - There may be no more than one LVT entry per local variable.
2112  *     Two LVT entries are 'equal' if these fields are the same:
2113  *        start_pc, length, name, slot
2114  *   - There may be no more than one LVTT entry per each LVT entry.
2115  *     Each LVTT entry has to match some LVT entry.
2116  *   - HotSpot internal LVT keeps natural ordering of class file LVT entries.
2117  */
2118 void ClassFileParser::copy_localvariable_table(const ConstMethod* cm,
2119                                                int lvt_cnt,
2120                                                u2* const localvariable_table_length,
2121                                                const u2**const localvariable_table_start,
2122                                                int lvtt_cnt,
2123                                                u2* const localvariable_type_table_length,
2124                                                const u2**const localvariable_type_table_start,
2125                                                TRAPS) {
2126 
2127   ResourceMark rm(THREAD);
2128 
2129   typedef ResourceHashtable<LocalVariableTableElement, LocalVariableTableElement*,
2130                             &LVT_Hash::hash, &LVT_Hash::equals> LVT_HashTable;
2131 
2132   LVT_HashTable* const table = new LVT_HashTable();
2133 
2134   // To fill LocalVariableTable in
2135   const Classfile_LVT_Element* cf_lvt;
2136   LocalVariableTableElement* lvt = cm->localvariable_table_start();
2137 
2138   for (int tbl_no = 0; tbl_no < lvt_cnt; tbl_no++) {
2139     cf_lvt = (Classfile_LVT_Element *) localvariable_table_start[tbl_no];
2140     for (int idx = 0; idx < localvariable_table_length[tbl_no]; idx++, lvt++) {
2141       copy_lvt_element(&cf_lvt[idx], lvt);
2142       // If no duplicates, add LVT elem in hashtable.
2143       if (table->put(*lvt, lvt) == false
2144           && _need_verify


2299     classfile_parse_error("Interface cannot have a method named <init>, class file %s", CHECK_NULL);
2300   }
2301 
2302   int args_size = -1;  // only used when _need_verify is true
2303   if (_need_verify) {
2304     args_size = ((flags & JVM_ACC_STATIC) ? 0 : 1) +
2305                  verify_legal_method_signature(name, signature, CHECK_NULL);
2306     if (args_size > MAX_ARGS_SIZE) {
2307       classfile_parse_error("Too many arguments in method signature in class file %s", CHECK_NULL);
2308     }
2309   }
2310 
2311   AccessFlags access_flags(flags & JVM_RECOGNIZED_METHOD_MODIFIERS);
2312 
2313   // Default values for code and exceptions attribute elements
2314   u2 max_stack = 0;
2315   u2 max_locals = 0;
2316   u4 code_length = 0;
2317   const u1* code_start = 0;
2318   u2 exception_table_length = 0;
2319   const u2* exception_table_start = NULL;
2320   Array<int>* exception_handlers = Universe::the_empty_int_array();
2321   u2 checked_exceptions_length = 0;
2322   const u2* checked_exceptions_start = NULL;
2323   CompressedLineNumberWriteStream* linenumber_table = NULL;
2324   int linenumber_table_length = 0;
2325   int total_lvt_length = 0;
2326   u2 lvt_cnt = 0;
2327   u2 lvtt_cnt = 0;
2328   bool lvt_allocated = false;
2329   u2 max_lvt_cnt = INITIAL_MAX_LVT_NUMBER;
2330   u2 max_lvtt_cnt = INITIAL_MAX_LVT_NUMBER;
2331   u2* localvariable_table_length = NULL;
2332   const u2** localvariable_table_start = NULL;
2333   u2* localvariable_type_table_length = NULL;
2334   const u2** localvariable_type_table_start = NULL;
2335   int method_parameters_length = -1;
2336   const u1* method_parameters_data = NULL;
2337   bool method_parameters_seen = false;
2338   bool parsed_code_attribute = false;
2339   bool parsed_checked_exceptions_attribute = false;
2340   bool parsed_stackmap_attribute = false;
2341   // stackmap attribute - JDK1.5
2342   const u1* stackmap_data = NULL;
2343   int stackmap_data_length = 0;
2344   u2 generic_signature_index = 0;
2345   MethodAnnotationCollector parsed_annotations;
2346   const u1* runtime_visible_annotations = NULL;
2347   int runtime_visible_annotations_length = 0;
2348   const u1* runtime_invisible_annotations = NULL;
2349   int runtime_invisible_annotations_length = 0;
2350   const u1* runtime_visible_parameter_annotations = NULL;
2351   int runtime_visible_parameter_annotations_length = 0;
2352   const u1* runtime_invisible_parameter_annotations = NULL;
2353   int runtime_invisible_parameter_annotations_length = 0;
2354   const u1* runtime_visible_type_annotations = NULL;


2455                                        sizeof(code_attribute_length);
2456         check_property(valid_symbol_at(code_attribute_name_index),
2457                        "Invalid code attribute name index %u in class file %s",
2458                        code_attribute_name_index,
2459                        CHECK_NULL);
2460         if (LoadLineNumberTables &&
2461             cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_line_number_table()) {
2462           // Parse and compress line number table
2463           parse_linenumber_table(code_attribute_length,
2464                                  code_length,
2465                                  &linenumber_table,
2466                                  CHECK_NULL);
2467 
2468         } else if (LoadLocalVariableTables &&
2469                    cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_table()) {
2470           // Parse local variable table
2471           if (!lvt_allocated) {
2472             localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
2473               THREAD, u2,  INITIAL_MAX_LVT_NUMBER);
2474             localvariable_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
2475               THREAD, const u2*, INITIAL_MAX_LVT_NUMBER);
2476             localvariable_type_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
2477               THREAD, u2,  INITIAL_MAX_LVT_NUMBER);
2478             localvariable_type_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
2479               THREAD, const u2*, INITIAL_MAX_LVT_NUMBER);
2480             lvt_allocated = true;
2481           }
2482           if (lvt_cnt == max_lvt_cnt) {
2483             max_lvt_cnt <<= 1;
2484             localvariable_table_length = REALLOC_RESOURCE_ARRAY(u2, localvariable_table_length, lvt_cnt, max_lvt_cnt);
2485             localvariable_table_start  = REALLOC_RESOURCE_ARRAY(const u2*, localvariable_table_start, lvt_cnt, max_lvt_cnt);
2486           }
2487           localvariable_table_start[lvt_cnt] =
2488             parse_localvariable_table(cfs,
2489                                       code_length,
2490                                       max_locals,
2491                                       code_attribute_length,
2492                                       &localvariable_table_length[lvt_cnt],
2493                                       false,    // is not LVTT
2494                                       CHECK_NULL);
2495           total_lvt_length += localvariable_table_length[lvt_cnt];
2496           lvt_cnt++;
2497         } else if (LoadLocalVariableTypeTables &&
2498                    _major_version >= JAVA_1_5_VERSION &&
2499                    cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_type_table()) {
2500           if (!lvt_allocated) {
2501             localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
2502               THREAD, u2,  INITIAL_MAX_LVT_NUMBER);
2503             localvariable_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
2504               THREAD, const u2*, INITIAL_MAX_LVT_NUMBER);
2505             localvariable_type_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
2506               THREAD, u2,  INITIAL_MAX_LVT_NUMBER);
2507             localvariable_type_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
2508               THREAD, const u2*, INITIAL_MAX_LVT_NUMBER);
2509             lvt_allocated = true;
2510           }
2511           // Parse local variable type table
2512           if (lvtt_cnt == max_lvtt_cnt) {
2513             max_lvtt_cnt <<= 1;
2514             localvariable_type_table_length = REALLOC_RESOURCE_ARRAY(u2, localvariable_type_table_length, lvtt_cnt, max_lvtt_cnt);
2515             localvariable_type_table_start  = REALLOC_RESOURCE_ARRAY(const u2*, localvariable_type_table_start, lvtt_cnt, max_lvtt_cnt);
2516           }
2517           localvariable_type_table_start[lvtt_cnt] =
2518             parse_localvariable_table(cfs,
2519                                       code_length,
2520                                       max_locals,
2521                                       code_attribute_length,
2522                                       &localvariable_type_table_length[lvtt_cnt],
2523                                       true,     // is LVTT
2524                                       CHECK_NULL);
2525           lvtt_cnt++;
2526         } else if (_major_version >= Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION &&
2527                    cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_stack_map_table()) {
2528           // Stack map is only needed by the new verifier in JDK1.5.
2529           if (parsed_stackmap_attribute) {
2530             classfile_parse_error("Multiple StackMapTable attributes in class file %s", CHECK_NULL);
2531           }
2532           stackmap_data = parse_stackmap_table(cfs, code_attribute_length, _need_verify, CHECK_NULL);
2533           stackmap_data_length = code_attribute_length;
2534           parsed_stackmap_attribute = true;
2535         } else {


2766   m->set_max_locals(max_locals);
2767   if (stackmap_data != NULL) {
2768     m->constMethod()->copy_stackmap_data(_loader_data,
2769                                          (u1*)stackmap_data,
2770                                          stackmap_data_length,
2771                                          CHECK_NULL);
2772   }
2773 
2774   // Copy byte codes
2775   m->set_code((u1*)code_start);
2776 
2777   // Copy line number table
2778   if (linenumber_table != NULL) {
2779     memcpy(m->compressed_linenumber_table(),
2780            linenumber_table->buffer(),
2781            linenumber_table_length);
2782   }
2783 
2784   // Copy exception table
2785   if (exception_table_length > 0) {
2786     int size =
2787       exception_table_length * sizeof(ExceptionTableElement) / sizeof(u2);
2788     copy_u2_with_conversion((u2*) m->exception_table_start(),
2789                             exception_table_start, size);
2790   }
2791 
2792   // Copy method parameters
2793   if (method_parameters_length > 0) {
2794     MethodParametersElement* elem = m->constMethod()->method_parameters_start();
2795     for (int i = 0; i < method_parameters_length; i++) {
2796       elem[i].name_cp_index = Bytes::get_Java_u2((address)method_parameters_data);
2797       method_parameters_data += 2;
2798       elem[i].flags = Bytes::get_Java_u2((address)method_parameters_data);
2799       method_parameters_data += 2;
2800     }
2801   }
2802 
2803   // Copy checked exceptions
2804   if (checked_exceptions_length > 0) {
2805     const int size =
2806       checked_exceptions_length * sizeof(CheckedExceptionElement) / sizeof(u2);
2807     copy_u2_with_conversion((u2*) m->checked_exceptions_start(),
2808                             checked_exceptions_start,
2809                             size);
2810   }
2811 
2812   // Copy class file LVT's/LVTT's into the HotSpot internal LVT.
2813   if (total_lvt_length > 0) {
2814     promoted_flags->set_has_localvariable_table();
2815     copy_localvariable_table(m->constMethod(),
2816                              lvt_cnt,
2817                              localvariable_table_length,
2818                              localvariable_table_start,
2819                              lvtt_cnt,
2820                              localvariable_type_table_length,
2821                              localvariable_type_table_start,
2822                              CHECK_NULL);
2823   }
2824 
2825   if (parsed_annotations.has_any_annotations())
2826     parsed_annotations.apply_to(m);
2827 
2828   // Copy annotations
2829   copy_method_annotations(m->constMethod(),




1657     {
1658       debug_only(NoSafepointVerifier nsv;)
1659       for (AllFieldStream fs(_fields, cp); !fs.done(); fs.next()) {
1660         const Symbol* const name = fs.name();
1661         const Symbol* const sig = fs.signature();
1662         // If no duplicates, add name/signature in hashtable names_and_sigs.
1663         if (!put_after_lookup(name, sig, names_and_sigs)) {
1664           dup = true;
1665           break;
1666         }
1667       }
1668     }
1669     if (dup) {
1670       classfile_parse_error("Duplicate field name&signature in class file %s",
1671                             CHECK);
1672     }
1673   }
1674 }
1675 
1676 
1677 const void* ClassFileParser::parse_exception_table(const ClassFileStream* const cfs,






1678                                                  u4 code_length,
1679                                                  u4 exception_table_length,
1680                                                  TRAPS) {
1681   assert(cfs != NULL, "invariant");
1682 
1683   const void* const exception_table_start = cfs->get_u1_buffer();
1684   assert(exception_table_start != NULL, "null exception table");
1685 
1686   cfs->guarantee_more(8 * exception_table_length, CHECK_NULL); // start_pc,
1687                                                                // end_pc,
1688                                                                // handler_pc,
1689                                                                // catch_type_index
1690 
1691   // Will check legal target after parsing code array in verifier.
1692   if (_need_verify) {
1693     for (unsigned int i = 0; i < exception_table_length; i++) {
1694       const u2 start_pc = cfs->get_u2_fast();
1695       const u2 end_pc = cfs->get_u2_fast();
1696       const u2 handler_pc = cfs->get_u2_fast();
1697       const u2 catch_type_index = cfs->get_u2_fast();
1698       guarantee_property((start_pc < end_pc) && (end_pc <= code_length),
1699                          "Illegal exception table range in class file %s",
1700                          CHECK_NULL);
1701       guarantee_property(handler_pc < code_length,
1702                          "Illegal exception table handler in class file %s",
1703                          CHECK_NULL);


1781  public:
1782   u2 start_bci;
1783   u2 length;
1784   u2 name_cp_index;
1785   u2 descriptor_cp_index;
1786   u2 slot;
1787 };
1788 
1789 static void copy_lvt_element(const Classfile_LVT_Element* const src,
1790                              LocalVariableTableElement* const lvt) {
1791   lvt->start_bci           = Bytes::get_Java_u2((u1*) &src->start_bci);
1792   lvt->length              = Bytes::get_Java_u2((u1*) &src->length);
1793   lvt->name_cp_index       = Bytes::get_Java_u2((u1*) &src->name_cp_index);
1794   lvt->descriptor_cp_index = Bytes::get_Java_u2((u1*) &src->descriptor_cp_index);
1795   lvt->signature_cp_index  = 0;
1796   lvt->slot                = Bytes::get_Java_u2((u1*) &src->slot);
1797 }
1798 
1799 // Function is used to parse both attributes:
1800 // LocalVariableTable (LVT) and LocalVariableTypeTable (LVTT)
1801 const void* ClassFileParser::parse_localvariable_table(const ClassFileStream* cfs,
1802                                                        u4 code_length,
1803                                                        u2 max_locals,
1804                                                        u4 code_attribute_length,
1805                                                        u2* const localvariable_table_length,
1806                                                        bool isLVTT,
1807                                                        TRAPS) {
1808   const char* const tbl_name = (isLVTT) ? "LocalVariableTypeTable" : "LocalVariableTable";
1809   *localvariable_table_length = cfs->get_u2(CHECK_NULL);
1810   const unsigned int size =
1811     (*localvariable_table_length) * sizeof(Classfile_LVT_Element) / sizeof(u2);
1812 
1813   const ConstantPool* const cp = _cp;
1814 
1815   // Verify local variable table attribute has right length
1816   if (_need_verify) {
1817     guarantee_property(code_attribute_length == (sizeof(*localvariable_table_length) + size * sizeof(u2)),
1818                        "%s has wrong length in class file %s", tbl_name, CHECK_NULL);
1819   }
1820 
1821   const u1* const localvariable_table_start = cfs->get_u1_buffer();
1822   assert(localvariable_table_start != NULL, "null local variable table");
1823   if (!_need_verify) {
1824     cfs->skip_u2_fast(size);
1825   } else {
1826     cfs->guarantee_more(size * 2, CHECK_NULL);
1827     for(int i = 0; i < (*localvariable_table_length); i++) {
1828       const u2 start_pc = cfs->get_u2_fast();
1829       const u2 length = cfs->get_u2_fast();
1830       const u2 name_index = cfs->get_u2_fast();
1831       const u2 descriptor_index = cfs->get_u2_fast();
1832       const u2 index = cfs->get_u2_fast();
1833       // Assign to a u4 to avoid overflow
1834       const u4 end_pc = (u4)start_pc + (u4)length;
1835 
1836       if (start_pc >= code_length) {
1837         classfile_parse_error(
1838           "Invalid start_pc %u in %s in class file %s",
1839           start_pc, tbl_name, CHECK_NULL);
1840       }
1841       if (end_pc > code_length) {


1917                                       bool need_verify,
1918                                       TRAPS) {
1919   assert(cfs != NULL, "invariant");
1920 
1921   if (0 == code_attribute_length) {
1922     return NULL;
1923   }
1924 
1925   const u1* const stackmap_table_start = cfs->get_u1_buffer();
1926   assert(stackmap_table_start != NULL, "null stackmap table");
1927 
1928   // check code_attribute_length first
1929   cfs->skip_u1(code_attribute_length, CHECK_NULL);
1930 
1931   if (!need_verify && !DumpSharedSpaces) {
1932     return NULL;
1933   }
1934   return stackmap_table_start;
1935 }
1936 
1937 const void* ClassFileParser::parse_checked_exceptions(const ClassFileStream* const cfs,
1938                                                       u2* const checked_exceptions_length,
1939                                                       u4 method_attribute_length,
1940                                                       TRAPS) {
1941   assert(cfs != NULL, "invariant");
1942   assert(checked_exceptions_length != NULL, "invariant");
1943 
1944   cfs->guarantee_more(2, CHECK_NULL);  // checked_exceptions_length
1945   *checked_exceptions_length = cfs->get_u2_fast();
1946   const unsigned int size =
1947     (*checked_exceptions_length) * sizeof(CheckedExceptionElement) / sizeof(u2);
1948   const void* const checked_exceptions_start = cfs->get_u1_buffer();
1949   assert(checked_exceptions_start != NULL, "null checked exceptions");
1950   if (!_need_verify) {
1951     cfs->skip_u2_fast(size);
1952   } else {
1953     // Verify each value in the checked exception table
1954     u2 checked_exception;
1955     const u2 len = *checked_exceptions_length;
1956     cfs->guarantee_more(2 * len, CHECK_NULL);
1957     for (int i = 0; i < len; i++) {
1958       checked_exception = cfs->get_u2_fast();
1959       check_property(
1960         valid_klass_reference_at(checked_exception),
1961         "Exception name has bad type at constant pool %u in class file %s",
1962         checked_exception, CHECK_NULL);
1963     }
1964   }
1965   // check exceptions attribute length
1966   if (_need_verify) {
1967     guarantee_property(method_attribute_length == (sizeof(*checked_exceptions_length) +
1968                                                    sizeof(u2) * size),


2095 #define MAX_ARGS_SIZE 255
2096 #define MAX_CODE_SIZE 65535
2097 #define INITIAL_MAX_LVT_NUMBER 256
2098 
2099 /* Copy class file LVT's/LVTT's into the HotSpot internal LVT.
2100  *
2101  * Rules for LVT's and LVTT's are:
2102  *   - There can be any number of LVT's and LVTT's.
2103  *   - If there are n LVT's, it is the same as if there was just
2104  *     one LVT containing all the entries from the n LVT's.
2105  *   - There may be no more than one LVT entry per local variable.
2106  *     Two LVT entries are 'equal' if these fields are the same:
2107  *        start_pc, length, name, slot
2108  *   - There may be no more than one LVTT entry per each LVT entry.
2109  *     Each LVTT entry has to match some LVT entry.
2110  *   - HotSpot internal LVT keeps natural ordering of class file LVT entries.
2111  */
2112 void ClassFileParser::copy_localvariable_table(const ConstMethod* cm,
2113                                                int lvt_cnt,
2114                                                u2* const localvariable_table_length,
2115                                                const void** const localvariable_table_start,
2116                                                int lvtt_cnt,
2117                                                u2* const localvariable_type_table_length,
2118                                                const void** const localvariable_type_table_start,
2119                                                TRAPS) {
2120 
2121   ResourceMark rm(THREAD);
2122 
2123   typedef ResourceHashtable<LocalVariableTableElement, LocalVariableTableElement*,
2124                             &LVT_Hash::hash, &LVT_Hash::equals> LVT_HashTable;
2125 
2126   LVT_HashTable* const table = new LVT_HashTable();
2127 
2128   // To fill LocalVariableTable in
2129   const Classfile_LVT_Element* cf_lvt;
2130   LocalVariableTableElement* lvt = cm->localvariable_table_start();
2131 
2132   for (int tbl_no = 0; tbl_no < lvt_cnt; tbl_no++) {
2133     cf_lvt = (Classfile_LVT_Element *) localvariable_table_start[tbl_no];
2134     for (int idx = 0; idx < localvariable_table_length[tbl_no]; idx++, lvt++) {
2135       copy_lvt_element(&cf_lvt[idx], lvt);
2136       // If no duplicates, add LVT elem in hashtable.
2137       if (table->put(*lvt, lvt) == false
2138           && _need_verify


2293     classfile_parse_error("Interface cannot have a method named <init>, class file %s", CHECK_NULL);
2294   }
2295 
2296   int args_size = -1;  // only used when _need_verify is true
2297   if (_need_verify) {
2298     args_size = ((flags & JVM_ACC_STATIC) ? 0 : 1) +
2299                  verify_legal_method_signature(name, signature, CHECK_NULL);
2300     if (args_size > MAX_ARGS_SIZE) {
2301       classfile_parse_error("Too many arguments in method signature in class file %s", CHECK_NULL);
2302     }
2303   }
2304 
2305   AccessFlags access_flags(flags & JVM_RECOGNIZED_METHOD_MODIFIERS);
2306 
2307   // Default values for code and exceptions attribute elements
2308   u2 max_stack = 0;
2309   u2 max_locals = 0;
2310   u4 code_length = 0;
2311   const u1* code_start = 0;
2312   u2 exception_table_length = 0;
2313   const void* exception_table_start = NULL; // (potentially unaligned) pointer to array of u2 elements
2314   Array<int>* exception_handlers = Universe::the_empty_int_array();
2315   u2 checked_exceptions_length = 0;
2316   const void* checked_exceptions_start = NULL; // (potentially unaligned) pointer to array of u2 elements
2317   CompressedLineNumberWriteStream* linenumber_table = NULL;
2318   int linenumber_table_length = 0;
2319   int total_lvt_length = 0;
2320   u2 lvt_cnt = 0;
2321   u2 lvtt_cnt = 0;
2322   bool lvt_allocated = false;
2323   u2 max_lvt_cnt = INITIAL_MAX_LVT_NUMBER;
2324   u2 max_lvtt_cnt = INITIAL_MAX_LVT_NUMBER;
2325   u2* localvariable_table_length = NULL;
2326   const void** localvariable_table_start = NULL; // (potentially unaligned) pointer to array of LVT attributes
2327   u2* localvariable_type_table_length = NULL;
2328   const void** localvariable_type_table_start = NULL; // (potentially unaligned) pointer to LVTT attributes
2329   int method_parameters_length = -1;
2330   const u1* method_parameters_data = NULL;
2331   bool method_parameters_seen = false;
2332   bool parsed_code_attribute = false;
2333   bool parsed_checked_exceptions_attribute = false;
2334   bool parsed_stackmap_attribute = false;
2335   // stackmap attribute - JDK1.5
2336   const u1* stackmap_data = NULL;
2337   int stackmap_data_length = 0;
2338   u2 generic_signature_index = 0;
2339   MethodAnnotationCollector parsed_annotations;
2340   const u1* runtime_visible_annotations = NULL;
2341   int runtime_visible_annotations_length = 0;
2342   const u1* runtime_invisible_annotations = NULL;
2343   int runtime_invisible_annotations_length = 0;
2344   const u1* runtime_visible_parameter_annotations = NULL;
2345   int runtime_visible_parameter_annotations_length = 0;
2346   const u1* runtime_invisible_parameter_annotations = NULL;
2347   int runtime_invisible_parameter_annotations_length = 0;
2348   const u1* runtime_visible_type_annotations = NULL;


2449                                        sizeof(code_attribute_length);
2450         check_property(valid_symbol_at(code_attribute_name_index),
2451                        "Invalid code attribute name index %u in class file %s",
2452                        code_attribute_name_index,
2453                        CHECK_NULL);
2454         if (LoadLineNumberTables &&
2455             cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_line_number_table()) {
2456           // Parse and compress line number table
2457           parse_linenumber_table(code_attribute_length,
2458                                  code_length,
2459                                  &linenumber_table,
2460                                  CHECK_NULL);
2461 
2462         } else if (LoadLocalVariableTables &&
2463                    cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_table()) {
2464           // Parse local variable table
2465           if (!lvt_allocated) {
2466             localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
2467               THREAD, u2,  INITIAL_MAX_LVT_NUMBER);
2468             localvariable_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
2469               THREAD, const void*, INITIAL_MAX_LVT_NUMBER);
2470             localvariable_type_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
2471               THREAD, u2,  INITIAL_MAX_LVT_NUMBER);
2472             localvariable_type_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
2473               THREAD, const void*, INITIAL_MAX_LVT_NUMBER);
2474             lvt_allocated = true;
2475           }
2476           if (lvt_cnt == max_lvt_cnt) {
2477             max_lvt_cnt <<= 1;
2478             localvariable_table_length = REALLOC_RESOURCE_ARRAY(u2, localvariable_table_length, lvt_cnt, max_lvt_cnt);
2479             localvariable_table_start  = REALLOC_RESOURCE_ARRAY(const void*, localvariable_table_start, lvt_cnt, max_lvt_cnt);
2480           }
2481           localvariable_table_start[lvt_cnt] =
2482             parse_localvariable_table(cfs,
2483                                       code_length,
2484                                       max_locals,
2485                                       code_attribute_length,
2486                                       &localvariable_table_length[lvt_cnt],
2487                                       false,    // is not LVTT
2488                                       CHECK_NULL);
2489           total_lvt_length += localvariable_table_length[lvt_cnt];
2490           lvt_cnt++;
2491         } else if (LoadLocalVariableTypeTables &&
2492                    _major_version >= JAVA_1_5_VERSION &&
2493                    cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_type_table()) {
2494           if (!lvt_allocated) {
2495             localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
2496               THREAD, u2,  INITIAL_MAX_LVT_NUMBER);
2497             localvariable_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
2498               THREAD, const void*, INITIAL_MAX_LVT_NUMBER);
2499             localvariable_type_table_length = NEW_RESOURCE_ARRAY_IN_THREAD(
2500               THREAD, u2,  INITIAL_MAX_LVT_NUMBER);
2501             localvariable_type_table_start = NEW_RESOURCE_ARRAY_IN_THREAD(
2502               THREAD, const void*, INITIAL_MAX_LVT_NUMBER);
2503             lvt_allocated = true;
2504           }
2505           // Parse local variable type table
2506           if (lvtt_cnt == max_lvtt_cnt) {
2507             max_lvtt_cnt <<= 1;
2508             localvariable_type_table_length = REALLOC_RESOURCE_ARRAY(u2, localvariable_type_table_length, lvtt_cnt, max_lvtt_cnt);
2509             localvariable_type_table_start  = REALLOC_RESOURCE_ARRAY(const void*, localvariable_type_table_start, lvtt_cnt, max_lvtt_cnt);
2510           }
2511           localvariable_type_table_start[lvtt_cnt] =
2512             parse_localvariable_table(cfs,
2513                                       code_length,
2514                                       max_locals,
2515                                       code_attribute_length,
2516                                       &localvariable_type_table_length[lvtt_cnt],
2517                                       true,     // is LVTT
2518                                       CHECK_NULL);
2519           lvtt_cnt++;
2520         } else if (_major_version >= Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION &&
2521                    cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_stack_map_table()) {
2522           // Stack map is only needed by the new verifier in JDK1.5.
2523           if (parsed_stackmap_attribute) {
2524             classfile_parse_error("Multiple StackMapTable attributes in class file %s", CHECK_NULL);
2525           }
2526           stackmap_data = parse_stackmap_table(cfs, code_attribute_length, _need_verify, CHECK_NULL);
2527           stackmap_data_length = code_attribute_length;
2528           parsed_stackmap_attribute = true;
2529         } else {


2760   m->set_max_locals(max_locals);
2761   if (stackmap_data != NULL) {
2762     m->constMethod()->copy_stackmap_data(_loader_data,
2763                                          (u1*)stackmap_data,
2764                                          stackmap_data_length,
2765                                          CHECK_NULL);
2766   }
2767 
2768   // Copy byte codes
2769   m->set_code((u1*)code_start);
2770 
2771   // Copy line number table
2772   if (linenumber_table != NULL) {
2773     memcpy(m->compressed_linenumber_table(),
2774            linenumber_table->buffer(),
2775            linenumber_table_length);
2776   }
2777 
2778   // Copy exception table
2779   if (exception_table_length > 0) {
2780     Copy::conjoint_swap_maybe<Endian::JAVA>(exception_table_start,
2781                                             m->exception_table_start(),
2782                                             exception_table_length * sizeof(ExceptionTableElement),
2783                                             sizeof(u2));
2784   }
2785 
2786   // Copy method parameters
2787   if (method_parameters_length > 0) {
2788     MethodParametersElement* elem = m->constMethod()->method_parameters_start();
2789     for (int i = 0; i < method_parameters_length; i++) {
2790       elem[i].name_cp_index = Bytes::get_Java_u2((address)method_parameters_data);
2791       method_parameters_data += 2;
2792       elem[i].flags = Bytes::get_Java_u2((address)method_parameters_data);
2793       method_parameters_data += 2;
2794     }
2795   }
2796 
2797   // Copy checked exceptions
2798   if (checked_exceptions_length > 0) {
2799     Copy::conjoint_swap_maybe<Endian::JAVA>(checked_exceptions_start,
2800                                             m->checked_exceptions_start(),
2801                                             checked_exceptions_length * sizeof(CheckedExceptionElement),
2802                                             sizeof(u2));

2803   }
2804 
2805   // Copy class file LVT's/LVTT's into the HotSpot internal LVT.
2806   if (total_lvt_length > 0) {
2807     promoted_flags->set_has_localvariable_table();
2808     copy_localvariable_table(m->constMethod(),
2809                              lvt_cnt,
2810                              localvariable_table_length,
2811                              localvariable_table_start,
2812                              lvtt_cnt,
2813                              localvariable_type_table_length,
2814                              localvariable_type_table_start,
2815                              CHECK_NULL);
2816   }
2817 
2818   if (parsed_annotations.has_any_annotations())
2819     parsed_annotations.apply_to(m);
2820 
2821   // Copy annotations
2822   copy_method_annotations(m->constMethod(),


< prev index next >