Mercurial > hg > truffle
comparison src/share/vm/classfile/classFileParser.cpp @ 8031:927a311d00f9
8007320: NPG: move method annotations
Summary: allocate method annotations and attach to ConstMethod if present
Reviewed-by: dcubed, jiangli, sspitsyn, iklam
author | coleenp |
---|---|
date | Mon, 11 Feb 2013 14:06:22 -0500 |
parents | 24a91505f9d5 |
children | 96480359523a |
comparison
equal
deleted
inserted
replaced
8030:f989aff6946f | 8031:927a311d00f9 |
---|---|
1854 | 1854 |
1855 #define MAX_ARGS_SIZE 255 | 1855 #define MAX_ARGS_SIZE 255 |
1856 #define MAX_CODE_SIZE 65535 | 1856 #define MAX_CODE_SIZE 65535 |
1857 #define INITIAL_MAX_LVT_NUMBER 256 | 1857 #define INITIAL_MAX_LVT_NUMBER 256 |
1858 | 1858 |
1859 /* Copy class file LVT's/LVTT's into the HotSpot internal LVT. | |
1860 * | |
1861 * Rules for LVT's and LVTT's are: | |
1862 * - There can be any number of LVT's and LVTT's. | |
1863 * - If there are n LVT's, it is the same as if there was just | |
1864 * one LVT containing all the entries from the n LVT's. | |
1865 * - There may be no more than one LVT entry per local variable. | |
1866 * Two LVT entries are 'equal' if these fields are the same: | |
1867 * start_pc, length, name, slot | |
1868 * - There may be no more than one LVTT entry per each LVT entry. | |
1869 * Each LVTT entry has to match some LVT entry. | |
1870 * - HotSpot internal LVT keeps natural ordering of class file LVT entries. | |
1871 */ | |
1872 void ClassFileParser::copy_localvariable_table(ConstMethod* cm, | |
1873 int lvt_cnt, | |
1874 u2* localvariable_table_length, | |
1875 u2** localvariable_table_start, | |
1876 int lvtt_cnt, | |
1877 u2* localvariable_type_table_length, | |
1878 u2** localvariable_type_table_start, | |
1879 TRAPS) { | |
1880 | |
1881 LVT_Hash** lvt_Hash = NEW_RESOURCE_ARRAY(LVT_Hash*, HASH_ROW_SIZE); | |
1882 initialize_hashtable(lvt_Hash); | |
1883 | |
1884 // To fill LocalVariableTable in | |
1885 Classfile_LVT_Element* cf_lvt; | |
1886 LocalVariableTableElement* lvt = cm->localvariable_table_start(); | |
1887 | |
1888 for (int tbl_no = 0; tbl_no < lvt_cnt; tbl_no++) { | |
1889 cf_lvt = (Classfile_LVT_Element *) localvariable_table_start[tbl_no]; | |
1890 for (int idx = 0; idx < localvariable_table_length[tbl_no]; idx++, lvt++) { | |
1891 copy_lvt_element(&cf_lvt[idx], lvt); | |
1892 // If no duplicates, add LVT elem in hashtable lvt_Hash. | |
1893 if (LVT_put_after_lookup(lvt, lvt_Hash) == false | |
1894 && _need_verify | |
1895 && _major_version >= JAVA_1_5_VERSION) { | |
1896 clear_hashtable(lvt_Hash); | |
1897 ConstantPool* cp = cm->constants(); | |
1898 classfile_parse_error("Duplicated LocalVariableTable attribute " | |
1899 "entry for '%s' in class file %s", | |
1900 cp->symbol_at(lvt->name_cp_index)->as_utf8(), | |
1901 CHECK); | |
1902 } | |
1903 } | |
1904 } | |
1905 | |
1906 // To merge LocalVariableTable and LocalVariableTypeTable | |
1907 Classfile_LVT_Element* cf_lvtt; | |
1908 LocalVariableTableElement lvtt_elem; | |
1909 | |
1910 for (int tbl_no = 0; tbl_no < lvtt_cnt; tbl_no++) { | |
1911 cf_lvtt = (Classfile_LVT_Element *) localvariable_type_table_start[tbl_no]; | |
1912 for (int idx = 0; idx < localvariable_type_table_length[tbl_no]; idx++) { | |
1913 copy_lvt_element(&cf_lvtt[idx], &lvtt_elem); | |
1914 int index = hash(&lvtt_elem); | |
1915 LVT_Hash* entry = LVT_lookup(&lvtt_elem, index, lvt_Hash); | |
1916 if (entry == NULL) { | |
1917 if (_need_verify) { | |
1918 clear_hashtable(lvt_Hash); | |
1919 ConstantPool* cp = cm->constants(); | |
1920 classfile_parse_error("LVTT entry for '%s' in class file %s " | |
1921 "does not match any LVT entry", | |
1922 cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(), | |
1923 CHECK); | |
1924 } | |
1925 } else if (entry->_elem->signature_cp_index != 0 && _need_verify) { | |
1926 clear_hashtable(lvt_Hash); | |
1927 ConstantPool* cp = cm->constants(); | |
1928 classfile_parse_error("Duplicated LocalVariableTypeTable attribute " | |
1929 "entry for '%s' in class file %s", | |
1930 cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(), | |
1931 CHECK); | |
1932 } else { | |
1933 // to add generic signatures into LocalVariableTable | |
1934 entry->_elem->signature_cp_index = lvtt_elem.descriptor_cp_index; | |
1935 } | |
1936 } | |
1937 } | |
1938 clear_hashtable(lvt_Hash); | |
1939 } | |
1940 | |
1941 | |
1942 void ClassFileParser::copy_method_annotations(ClassLoaderData* loader_data, | |
1943 ConstMethod* cm, | |
1944 u1* runtime_visible_annotations, | |
1945 int runtime_visible_annotations_length, | |
1946 u1* runtime_invisible_annotations, | |
1947 int runtime_invisible_annotations_length, | |
1948 u1* runtime_visible_parameter_annotations, | |
1949 int runtime_visible_parameter_annotations_length, | |
1950 u1* runtime_invisible_parameter_annotations, | |
1951 int runtime_invisible_parameter_annotations_length, | |
1952 u1* runtime_visible_type_annotations, | |
1953 int runtime_visible_type_annotations_length, | |
1954 u1* runtime_invisible_type_annotations, | |
1955 int runtime_invisible_type_annotations_length, | |
1956 u1* annotation_default, | |
1957 int annotation_default_length, | |
1958 TRAPS) { | |
1959 | |
1960 AnnotationArray* a; | |
1961 | |
1962 if (runtime_visible_annotations_length + | |
1963 runtime_invisible_annotations_length > 0) { | |
1964 a = assemble_annotations(loader_data, | |
1965 runtime_visible_annotations, | |
1966 runtime_visible_annotations_length, | |
1967 runtime_invisible_annotations, | |
1968 runtime_invisible_annotations_length, | |
1969 CHECK); | |
1970 cm->set_method_annotations(a); | |
1971 } | |
1972 | |
1973 if (runtime_visible_parameter_annotations_length + | |
1974 runtime_invisible_parameter_annotations_length > 0) { | |
1975 a = assemble_annotations(loader_data, | |
1976 runtime_visible_parameter_annotations, | |
1977 runtime_visible_parameter_annotations_length, | |
1978 runtime_invisible_parameter_annotations, | |
1979 runtime_invisible_parameter_annotations_length, | |
1980 CHECK); | |
1981 cm->set_parameter_annotations(a); | |
1982 } | |
1983 | |
1984 if (annotation_default_length > 0) { | |
1985 a = assemble_annotations(loader_data, | |
1986 annotation_default, | |
1987 annotation_default_length, | |
1988 NULL, | |
1989 0, | |
1990 CHECK); | |
1991 cm->set_default_annotations(a); | |
1992 } | |
1993 | |
1994 if (runtime_visible_type_annotations_length + | |
1995 runtime_invisible_type_annotations_length > 0) { | |
1996 a = assemble_annotations(loader_data, | |
1997 runtime_visible_type_annotations, | |
1998 runtime_visible_type_annotations_length, | |
1999 runtime_invisible_type_annotations, | |
2000 runtime_invisible_type_annotations_length, | |
2001 CHECK); | |
2002 cm->set_type_annotations(a); | |
2003 } | |
2004 } | |
2005 | |
2006 | |
1859 // Note: the parse_method below is big and clunky because all parsing of the code and exceptions | 2007 // Note: the parse_method below is big and clunky because all parsing of the code and exceptions |
1860 // attribute is inlined. This is cumbersome to avoid since we inline most of the parts in the | 2008 // attribute is inlined. This is cumbersome to avoid since we inline most of the parts in the |
1861 // Method* to save footprint, so we only know the size of the resulting Method* when the | 2009 // Method* to save footprint, so we only know the size of the resulting Method* when the |
1862 // entire method attribute is parsed. | 2010 // entire method attribute is parsed. |
1863 // | 2011 // |
1867 | 2015 |
1868 methodHandle ClassFileParser::parse_method(ClassLoaderData* loader_data, | 2016 methodHandle ClassFileParser::parse_method(ClassLoaderData* loader_data, |
1869 constantPoolHandle cp, | 2017 constantPoolHandle cp, |
1870 bool is_interface, | 2018 bool is_interface, |
1871 AccessFlags *promoted_flags, | 2019 AccessFlags *promoted_flags, |
1872 AnnotationArray** method_annotations, | |
1873 AnnotationArray** method_parameter_annotations, | |
1874 AnnotationArray** method_default_annotations, | |
1875 AnnotationArray** method_type_annotations, | |
1876 TRAPS) { | 2020 TRAPS) { |
1877 ClassFileStream* cfs = stream(); | 2021 ClassFileStream* cfs = stream(); |
1878 methodHandle nullHandle; | 2022 methodHandle nullHandle; |
1879 ResourceMark rm(THREAD); | 2023 ResourceMark rm(THREAD); |
1880 // Parse fixed parts | 2024 // Parse fixed parts |
2271 guarantee_property(access_flags.is_native() || access_flags.is_abstract() || parsed_code_attribute, | 2415 guarantee_property(access_flags.is_native() || access_flags.is_abstract() || parsed_code_attribute, |
2272 "Absent Code attribute in method that is not native or abstract in class file %s", CHECK_(nullHandle)); | 2416 "Absent Code attribute in method that is not native or abstract in class file %s", CHECK_(nullHandle)); |
2273 } | 2417 } |
2274 | 2418 |
2275 // All sizing information for a Method* is finally available, now create it | 2419 // All sizing information for a Method* is finally available, now create it |
2420 InlineTableSizes sizes( | |
2421 total_lvt_length, | |
2422 linenumber_table_length, | |
2423 exception_table_length, | |
2424 checked_exceptions_length, | |
2425 method_parameters_length, | |
2426 generic_signature_index, | |
2427 runtime_visible_annotations_length + | |
2428 runtime_invisible_annotations_length, | |
2429 runtime_visible_parameter_annotations_length + | |
2430 runtime_invisible_parameter_annotations_length, | |
2431 runtime_visible_type_annotations_length + | |
2432 runtime_invisible_type_annotations_length, | |
2433 annotation_default_length, | |
2434 0); | |
2435 | |
2276 Method* m = Method::allocate( | 2436 Method* m = Method::allocate( |
2277 loader_data, code_length, access_flags, linenumber_table_length, | 2437 loader_data, code_length, access_flags, &sizes, |
2278 total_lvt_length, exception_table_length, checked_exceptions_length, | |
2279 method_parameters_length, generic_signature_index, | |
2280 ConstMethod::NORMAL, CHECK_(nullHandle)); | 2438 ConstMethod::NORMAL, CHECK_(nullHandle)); |
2281 | 2439 |
2282 ClassLoadingService::add_class_method_size(m->size()*HeapWordSize); | 2440 ClassLoadingService::add_class_method_size(m->size()*HeapWordSize); |
2283 | 2441 |
2284 // Fill in information from fixed part (access_flags already set) | 2442 // Fill in information from fixed part (access_flags already set) |
2345 if (checked_exceptions_length > 0) { | 2503 if (checked_exceptions_length > 0) { |
2346 int size = checked_exceptions_length * sizeof(CheckedExceptionElement) / sizeof(u2); | 2504 int size = checked_exceptions_length * sizeof(CheckedExceptionElement) / sizeof(u2); |
2347 copy_u2_with_conversion((u2*) m->checked_exceptions_start(), checked_exceptions_start, size); | 2505 copy_u2_with_conversion((u2*) m->checked_exceptions_start(), checked_exceptions_start, size); |
2348 } | 2506 } |
2349 | 2507 |
2350 /* Copy class file LVT's/LVTT's into the HotSpot internal LVT. | 2508 // Copy class file LVT's/LVTT's into the HotSpot internal LVT. |
2351 * | |
2352 * Rules for LVT's and LVTT's are: | |
2353 * - There can be any number of LVT's and LVTT's. | |
2354 * - If there are n LVT's, it is the same as if there was just | |
2355 * one LVT containing all the entries from the n LVT's. | |
2356 * - There may be no more than one LVT entry per local variable. | |
2357 * Two LVT entries are 'equal' if these fields are the same: | |
2358 * start_pc, length, name, slot | |
2359 * - There may be no more than one LVTT entry per each LVT entry. | |
2360 * Each LVTT entry has to match some LVT entry. | |
2361 * - HotSpot internal LVT keeps natural ordering of class file LVT entries. | |
2362 */ | |
2363 if (total_lvt_length > 0) { | 2509 if (total_lvt_length > 0) { |
2364 int tbl_no, idx; | |
2365 | |
2366 promoted_flags->set_has_localvariable_table(); | 2510 promoted_flags->set_has_localvariable_table(); |
2367 | 2511 copy_localvariable_table(m->constMethod(), lvt_cnt, |
2368 LVT_Hash** lvt_Hash = NEW_RESOURCE_ARRAY(LVT_Hash*, HASH_ROW_SIZE); | 2512 localvariable_table_length, |
2369 initialize_hashtable(lvt_Hash); | 2513 localvariable_table_start, |
2370 | 2514 lvtt_cnt, |
2371 // To fill LocalVariableTable in | 2515 localvariable_type_table_length, |
2372 Classfile_LVT_Element* cf_lvt; | 2516 localvariable_type_table_start, CHECK_NULL); |
2373 LocalVariableTableElement* lvt = m->localvariable_table_start(); | |
2374 | |
2375 for (tbl_no = 0; tbl_no < lvt_cnt; tbl_no++) { | |
2376 cf_lvt = (Classfile_LVT_Element *) localvariable_table_start[tbl_no]; | |
2377 for (idx = 0; idx < localvariable_table_length[tbl_no]; idx++, lvt++) { | |
2378 copy_lvt_element(&cf_lvt[idx], lvt); | |
2379 // If no duplicates, add LVT elem in hashtable lvt_Hash. | |
2380 if (LVT_put_after_lookup(lvt, lvt_Hash) == false | |
2381 && _need_verify | |
2382 && _major_version >= JAVA_1_5_VERSION ) { | |
2383 clear_hashtable(lvt_Hash); | |
2384 classfile_parse_error("Duplicated LocalVariableTable attribute " | |
2385 "entry for '%s' in class file %s", | |
2386 cp->symbol_at(lvt->name_cp_index)->as_utf8(), | |
2387 CHECK_(nullHandle)); | |
2388 } | |
2389 } | |
2390 } | |
2391 | |
2392 // To merge LocalVariableTable and LocalVariableTypeTable | |
2393 Classfile_LVT_Element* cf_lvtt; | |
2394 LocalVariableTableElement lvtt_elem; | |
2395 | |
2396 for (tbl_no = 0; tbl_no < lvtt_cnt; tbl_no++) { | |
2397 cf_lvtt = (Classfile_LVT_Element *) localvariable_type_table_start[tbl_no]; | |
2398 for (idx = 0; idx < localvariable_type_table_length[tbl_no]; idx++) { | |
2399 copy_lvt_element(&cf_lvtt[idx], &lvtt_elem); | |
2400 int index = hash(&lvtt_elem); | |
2401 LVT_Hash* entry = LVT_lookup(&lvtt_elem, index, lvt_Hash); | |
2402 if (entry == NULL) { | |
2403 if (_need_verify) { | |
2404 clear_hashtable(lvt_Hash); | |
2405 classfile_parse_error("LVTT entry for '%s' in class file %s " | |
2406 "does not match any LVT entry", | |
2407 cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(), | |
2408 CHECK_(nullHandle)); | |
2409 } | |
2410 } else if (entry->_elem->signature_cp_index != 0 && _need_verify) { | |
2411 clear_hashtable(lvt_Hash); | |
2412 classfile_parse_error("Duplicated LocalVariableTypeTable attribute " | |
2413 "entry for '%s' in class file %s", | |
2414 cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(), | |
2415 CHECK_(nullHandle)); | |
2416 } else { | |
2417 // to add generic signatures into LocalVariableTable | |
2418 entry->_elem->signature_cp_index = lvtt_elem.descriptor_cp_index; | |
2419 } | |
2420 } | |
2421 } | |
2422 clear_hashtable(lvt_Hash); | |
2423 } | 2517 } |
2424 | 2518 |
2425 if (parsed_annotations.has_any_annotations()) | 2519 if (parsed_annotations.has_any_annotations()) |
2426 parsed_annotations.apply_to(m); | 2520 parsed_annotations.apply_to(m); |
2427 *method_annotations = assemble_annotations(loader_data, | 2521 |
2428 runtime_visible_annotations, | 2522 // Copy annotations |
2429 runtime_visible_annotations_length, | 2523 copy_method_annotations(loader_data, m->constMethod(), |
2430 runtime_invisible_annotations, | 2524 runtime_visible_annotations, |
2431 runtime_invisible_annotations_length, | 2525 runtime_visible_annotations_length, |
2432 CHECK_(nullHandle)); | 2526 runtime_invisible_annotations, |
2433 *method_parameter_annotations = assemble_annotations(loader_data, | 2527 runtime_invisible_annotations_length, |
2434 runtime_visible_parameter_annotations, | 2528 runtime_visible_parameter_annotations, |
2435 runtime_visible_parameter_annotations_length, | 2529 runtime_visible_parameter_annotations_length, |
2436 runtime_invisible_parameter_annotations, | 2530 runtime_invisible_parameter_annotations, |
2437 runtime_invisible_parameter_annotations_length, | 2531 runtime_invisible_parameter_annotations_length, |
2438 CHECK_(nullHandle)); | 2532 runtime_visible_type_annotations, |
2439 *method_default_annotations = assemble_annotations(loader_data, | 2533 runtime_visible_type_annotations_length, |
2440 annotation_default, | 2534 runtime_invisible_type_annotations, |
2441 annotation_default_length, | 2535 runtime_invisible_type_annotations_length, |
2442 NULL, | 2536 annotation_default, |
2443 0, | 2537 annotation_default_length, |
2444 CHECK_(nullHandle)); | 2538 CHECK_NULL); |
2445 *method_type_annotations = assemble_annotations(loader_data, | |
2446 runtime_visible_type_annotations, | |
2447 runtime_visible_type_annotations_length, | |
2448 runtime_invisible_type_annotations, | |
2449 runtime_invisible_type_annotations_length, | |
2450 CHECK_(nullHandle)); | |
2451 | 2539 |
2452 if (name == vmSymbols::finalize_method_name() && | 2540 if (name == vmSymbols::finalize_method_name() && |
2453 signature == vmSymbols::void_method_signature()) { | 2541 signature == vmSymbols::void_method_signature()) { |
2454 if (m->is_empty_method()) { | 2542 if (m->is_empty_method()) { |
2455 _has_empty_finalizer = true; | 2543 _has_empty_finalizer = true; |
2461 signature == vmSymbols::void_method_signature() && | 2549 signature == vmSymbols::void_method_signature() && |
2462 m->is_vanilla_constructor()) { | 2550 m->is_vanilla_constructor()) { |
2463 _has_vanilla_constructor = true; | 2551 _has_vanilla_constructor = true; |
2464 } | 2552 } |
2465 | 2553 |
2554 NOT_PRODUCT(m->verify()); | |
2466 return m; | 2555 return m; |
2467 } | 2556 } |
2468 | 2557 |
2469 | 2558 |
2470 // The promoted_flags parameter is used to pass relevant access_flags | 2559 // The promoted_flags parameter is used to pass relevant access_flags |
2474 Array<Method*>* ClassFileParser::parse_methods(ClassLoaderData* loader_data, | 2563 Array<Method*>* ClassFileParser::parse_methods(ClassLoaderData* loader_data, |
2475 constantPoolHandle cp, | 2564 constantPoolHandle cp, |
2476 bool is_interface, | 2565 bool is_interface, |
2477 AccessFlags* promoted_flags, | 2566 AccessFlags* promoted_flags, |
2478 bool* has_final_method, | 2567 bool* has_final_method, |
2479 Array<AnnotationArray*>** methods_annotations, | |
2480 Array<AnnotationArray*>** methods_parameter_annotations, | |
2481 Array<AnnotationArray*>** methods_default_annotations, | |
2482 Array<AnnotationArray*>** methods_type_annotations, | |
2483 bool* has_default_methods, | 2568 bool* has_default_methods, |
2484 TRAPS) { | 2569 TRAPS) { |
2485 ClassFileStream* cfs = stream(); | 2570 ClassFileStream* cfs = stream(); |
2486 AnnotationArray* method_annotations = NULL; | |
2487 AnnotationArray* method_parameter_annotations = NULL; | |
2488 AnnotationArray* method_default_annotations = NULL; | |
2489 AnnotationArray* method_type_annotations = NULL; | |
2490 cfs->guarantee_more(2, CHECK_NULL); // length | 2571 cfs->guarantee_more(2, CHECK_NULL); // length |
2491 u2 length = cfs->get_u2_fast(); | 2572 u2 length = cfs->get_u2_fast(); |
2492 if (length == 0) { | 2573 if (length == 0) { |
2493 return Universe::the_empty_method_array(); | 2574 return Universe::the_empty_method_array(); |
2494 } else { | 2575 } else { |
2498 HandleMark hm(THREAD); | 2579 HandleMark hm(THREAD); |
2499 for (int index = 0; index < length; index++) { | 2580 for (int index = 0; index < length; index++) { |
2500 methodHandle method = parse_method(loader_data, | 2581 methodHandle method = parse_method(loader_data, |
2501 cp, is_interface, | 2582 cp, is_interface, |
2502 promoted_flags, | 2583 promoted_flags, |
2503 &method_annotations, | |
2504 &method_parameter_annotations, | |
2505 &method_default_annotations, | |
2506 &method_type_annotations, | |
2507 CHECK_NULL); | 2584 CHECK_NULL); |
2508 | 2585 |
2509 if (method->is_final()) { | 2586 if (method->is_final()) { |
2510 *has_final_method = true; | 2587 *has_final_method = true; |
2511 } | 2588 } |
2512 if (is_interface && !method->is_abstract() && !method->is_static()) { | 2589 if (is_interface && !method->is_abstract() && !method->is_static()) { |
2513 // default method | 2590 // default method |
2514 *has_default_methods = true; | 2591 *has_default_methods = true; |
2515 } | 2592 } |
2516 methods->at_put(index, method()); | 2593 methods->at_put(index, method()); |
2517 | |
2518 if (method_annotations != NULL) { | |
2519 if (*methods_annotations == NULL) { | |
2520 *methods_annotations = | |
2521 MetadataFactory::new_array<AnnotationArray*>(loader_data, length, NULL, CHECK_NULL); | |
2522 } | |
2523 (*methods_annotations)->at_put(index, method_annotations); | |
2524 } | |
2525 | |
2526 if (method_parameter_annotations != NULL) { | |
2527 if (*methods_parameter_annotations == NULL) { | |
2528 *methods_parameter_annotations = | |
2529 MetadataFactory::new_array<AnnotationArray*>(loader_data, length, NULL, CHECK_NULL); | |
2530 } | |
2531 (*methods_parameter_annotations)->at_put(index, method_parameter_annotations); | |
2532 } | |
2533 | |
2534 if (method_default_annotations != NULL) { | |
2535 if (*methods_default_annotations == NULL) { | |
2536 *methods_default_annotations = | |
2537 MetadataFactory::new_array<AnnotationArray*>(loader_data, length, NULL, CHECK_NULL); | |
2538 } | |
2539 (*methods_default_annotations)->at_put(index, method_default_annotations); | |
2540 } | |
2541 | |
2542 if (method_type_annotations != NULL) { | |
2543 if (*methods_type_annotations == NULL) { | |
2544 *methods_type_annotations = | |
2545 MetadataFactory::new_array<AnnotationArray*>(loader_data, length, NULL, CHECK_NULL); | |
2546 } | |
2547 (*methods_type_annotations)->at_put(index, method_type_annotations); | |
2548 } | |
2549 } | 2594 } |
2550 | 2595 |
2551 if (_need_verify && length > 1) { | 2596 if (_need_verify && length > 1) { |
2552 // Check duplicated methods | 2597 // Check duplicated methods |
2553 ResourceMark rm(THREAD); | 2598 ResourceMark rm(THREAD); |
2576 } | 2621 } |
2577 | 2622 |
2578 | 2623 |
2579 Array<int>* ClassFileParser::sort_methods(ClassLoaderData* loader_data, | 2624 Array<int>* ClassFileParser::sort_methods(ClassLoaderData* loader_data, |
2580 Array<Method*>* methods, | 2625 Array<Method*>* methods, |
2581 Array<AnnotationArray*>* methods_annotations, | 2626 TRAPS) { |
2582 Array<AnnotationArray*>* methods_parameter_annotations, | |
2583 Array<AnnotationArray*>* methods_default_annotations, | |
2584 Array<AnnotationArray*>* methods_type_annotations, | |
2585 TRAPS) { | |
2586 int length = methods->length(); | 2627 int length = methods->length(); |
2587 // If JVMTI original method ordering or sharing is enabled we have to | 2628 // If JVMTI original method ordering or sharing is enabled we have to |
2588 // remember the original class file ordering. | 2629 // remember the original class file ordering. |
2589 // We temporarily use the vtable_index field in the Method* to store the | 2630 // We temporarily use the vtable_index field in the Method* to store the |
2590 // class file index, so we can read in after calling qsort. | 2631 // class file index, so we can read in after calling qsort. |
2596 m->set_vtable_index(index); | 2637 m->set_vtable_index(index); |
2597 } | 2638 } |
2598 } | 2639 } |
2599 // Sort method array by ascending method name (for faster lookups & vtable construction) | 2640 // Sort method array by ascending method name (for faster lookups & vtable construction) |
2600 // Note that the ordering is not alphabetical, see Symbol::fast_compare | 2641 // Note that the ordering is not alphabetical, see Symbol::fast_compare |
2601 Method::sort_methods(methods, methods_annotations, | 2642 Method::sort_methods(methods); |
2602 methods_parameter_annotations, | |
2603 methods_default_annotations, | |
2604 methods_type_annotations); | |
2605 | 2643 |
2606 // If JVMTI original method ordering or sharing is enabled construct int | 2644 // If JVMTI original method ordering or sharing is enabled construct int |
2607 // array remembering the original ordering | 2645 // array remembering the original ordering |
2608 if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) { | 2646 if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) { |
2609 Array<int>* method_ordering = MetadataFactory::new_array<int>(loader_data, length, CHECK_NULL); | 2647 Array<int>* method_ordering = MetadataFactory::new_array<int>(loader_data, length, CHECK_NULL); |
3046 } | 3084 } |
3047 if (_sde_buffer != NULL) { | 3085 if (_sde_buffer != NULL) { |
3048 k->set_source_debug_extension(_sde_buffer, _sde_length); | 3086 k->set_source_debug_extension(_sde_buffer, _sde_length); |
3049 } | 3087 } |
3050 k->set_inner_classes(_inner_classes); | 3088 k->set_inner_classes(_inner_classes); |
3051 if (_annotations != NULL) { | |
3052 k->annotations()->set_class_annotations(_annotations); | |
3053 } | |
3054 } | 3089 } |
3055 | 3090 |
3056 AnnotationArray* ClassFileParser::assemble_annotations(ClassLoaderData* loader_data, | 3091 AnnotationArray* ClassFileParser::assemble_annotations(ClassLoaderData* loader_data, |
3057 u1* runtime_visible_annotations, | 3092 u1* runtime_visible_annotations, |
3058 int runtime_visible_annotations_length, | 3093 int runtime_visible_annotations_length, |
3359 CHECK_(nullHandle)); | 3394 CHECK_(nullHandle)); |
3360 // Methods | 3395 // Methods |
3361 bool has_final_method = false; | 3396 bool has_final_method = false; |
3362 AccessFlags promoted_flags; | 3397 AccessFlags promoted_flags; |
3363 promoted_flags.set_flags(0); | 3398 promoted_flags.set_flags(0); |
3364 | |
3365 Array<AnnotationArray*>* methods_annotations = NULL; | |
3366 Array<AnnotationArray*>* methods_parameter_annotations = NULL; | |
3367 Array<AnnotationArray*>* methods_default_annotations = NULL; | |
3368 Array<AnnotationArray*>* methods_type_annotations = NULL; | |
3369 Array<Method*>* methods = parse_methods(loader_data, | 3399 Array<Method*>* methods = parse_methods(loader_data, |
3370 cp, access_flags.is_interface(), | 3400 cp, access_flags.is_interface(), |
3371 &promoted_flags, | 3401 &promoted_flags, |
3372 &has_final_method, | 3402 &has_final_method, |
3373 &methods_annotations, | |
3374 &methods_parameter_annotations, | |
3375 &methods_default_annotations, | |
3376 &methods_type_annotations, | |
3377 &has_default_methods, | 3403 &has_default_methods, |
3378 CHECK_(nullHandle)); | 3404 CHECK_(nullHandle)); |
3379 | 3405 |
3380 // Additional attributes | 3406 // Additional attributes |
3381 ClassAnnotationCollector parsed_annotations; | 3407 ClassAnnotationCollector parsed_annotations; |
3430 Array<Klass*>* transitive_interfaces = compute_transitive_interfaces(loader_data, super_klass, local_interfaces, CHECK_(nullHandle)); | 3456 Array<Klass*>* transitive_interfaces = compute_transitive_interfaces(loader_data, super_klass, local_interfaces, CHECK_(nullHandle)); |
3431 | 3457 |
3432 // sort methods | 3458 // sort methods |
3433 Array<int>* method_ordering = sort_methods(loader_data, | 3459 Array<int>* method_ordering = sort_methods(loader_data, |
3434 methods, | 3460 methods, |
3435 methods_annotations, | |
3436 methods_parameter_annotations, | |
3437 methods_default_annotations, | |
3438 methods_type_annotations, | |
3439 CHECK_(nullHandle)); | 3461 CHECK_(nullHandle)); |
3440 | 3462 |
3441 // promote flags from parse_methods() to the klass' flags | 3463 // promote flags from parse_methods() to the klass' flags |
3442 access_flags.add_promoted_flags(promoted_flags.as_int()); | 3464 access_flags.add_promoted_flags(promoted_flags.as_int()); |
3443 | 3465 |
4033 | 4055 |
4034 // Number of non-static oop map blocks allocated at end of klass. | 4056 // Number of non-static oop map blocks allocated at end of klass. |
4035 const unsigned int total_oop_map_count = | 4057 const unsigned int total_oop_map_count = |
4036 compute_oop_map_count(super_klass, nonstatic_oop_map_count, | 4058 compute_oop_map_count(super_klass, nonstatic_oop_map_count, |
4037 first_nonstatic_oop_offset); | 4059 first_nonstatic_oop_offset); |
4038 | |
4039 // Compute reference type | 4060 // Compute reference type |
4040 ReferenceType rt; | 4061 ReferenceType rt; |
4041 if (super_klass() == NULL) { | 4062 if (super_klass() == NULL) { |
4042 rt = REF_NONE; | 4063 rt = REF_NONE; |
4043 } else { | 4064 } else { |
4055 total_oop_map_size2, | 4076 total_oop_map_size2, |
4056 rt, | 4077 rt, |
4057 access_flags, | 4078 access_flags, |
4058 name, | 4079 name, |
4059 super_klass(), | 4080 super_klass(), |
4060 host_klass, | 4081 !host_klass.is_null(), |
4061 CHECK_(nullHandle)); | 4082 CHECK_(nullHandle)); |
4062 | 4083 |
4063 // Add all classes to our internal class loader list here, | 4084 // Add all classes to our internal class loader list here, |
4064 // including classes in the bootstrap (NULL) class loader. | 4085 // including classes in the bootstrap (NULL) class loader. |
4065 loader_data->add_class(ik); | 4086 loader_data->add_class(ik); |
4101 this_klass->set_initial_method_idnum(methods->length()); | 4122 this_klass->set_initial_method_idnum(methods->length()); |
4102 this_klass->set_name(cp->klass_name_at(this_class_index)); | 4123 this_klass->set_name(cp->klass_name_at(this_class_index)); |
4103 if (is_anonymous()) // I am well known to myself | 4124 if (is_anonymous()) // I am well known to myself |
4104 cp->klass_at_put(this_class_index, this_klass()); // eagerly resolve | 4125 cp->klass_at_put(this_class_index, this_klass()); // eagerly resolve |
4105 | 4126 |
4106 // Allocate an annotation type if needed. | 4127 // Assign allocations if needed |
4107 if (fields_annotations != NULL || | 4128 if (_annotations != NULL || _type_annotations != NULL || |
4108 methods_annotations != NULL || | 4129 fields_annotations != NULL || fields_type_annotations != NULL) { |
4109 methods_parameter_annotations != NULL || | 4130 Annotations* annotations = Annotations::allocate(loader_data, CHECK_NULL); |
4110 methods_default_annotations != NULL || | 4131 annotations->set_class_annotations(_annotations); |
4111 fields_type_annotations != NULL || | 4132 annotations->set_class_type_annotations(_type_annotations); |
4112 methods_type_annotations != NULL) { | 4133 annotations->set_fields_annotations(fields_annotations); |
4113 Annotations* anno = Annotations::allocate(loader_data, | 4134 annotations->set_fields_type_annotations(fields_type_annotations); |
4114 fields_annotations, methods_annotations, | 4135 this_klass->set_annotations(annotations); |
4115 methods_parameter_annotations, | |
4116 methods_default_annotations, CHECK_(nullHandle)); | |
4117 this_klass->set_annotations(anno); | |
4118 } else { | |
4119 this_klass->set_annotations(NULL); | |
4120 } | |
4121 | |
4122 if (fields_type_annotations != NULL || | |
4123 methods_type_annotations != NULL) { | |
4124 assert(this_klass->annotations() != NULL, "annotations should have been allocated"); | |
4125 Annotations* anno = Annotations::allocate(loader_data, | |
4126 fields_type_annotations, | |
4127 methods_type_annotations, | |
4128 NULL, | |
4129 NULL, CHECK_(nullHandle)); | |
4130 this_klass->annotations()->set_type_annotations(anno); | |
4131 } | 4136 } |
4132 | 4137 |
4133 this_klass->set_minor_version(minor_version); | 4138 this_klass->set_minor_version(minor_version); |
4134 this_klass->set_major_version(major_version); | 4139 this_klass->set_major_version(major_version); |
4135 this_klass->set_has_default_methods(has_default_methods); | 4140 this_klass->set_has_default_methods(has_default_methods); |
4151 } | 4156 } |
4152 | 4157 |
4153 // Fill in field values obtained by parse_classfile_attributes | 4158 // Fill in field values obtained by parse_classfile_attributes |
4154 if (parsed_annotations.has_any_annotations()) | 4159 if (parsed_annotations.has_any_annotations()) |
4155 parsed_annotations.apply_to(this_klass); | 4160 parsed_annotations.apply_to(this_klass); |
4156 | |
4157 // Create annotations | |
4158 if (_annotations != NULL && this_klass->annotations() == NULL) { | |
4159 Annotations* anno = Annotations::allocate(loader_data, CHECK_NULL); | |
4160 this_klass->set_annotations(anno); | |
4161 } | |
4162 apply_parsed_class_attributes(this_klass); | 4161 apply_parsed_class_attributes(this_klass); |
4163 | |
4164 // Create type annotations | |
4165 if (_type_annotations != NULL) { | |
4166 if (this_klass->annotations() == NULL) { | |
4167 Annotations* anno = Annotations::allocate(loader_data, CHECK_NULL); | |
4168 this_klass->set_annotations(anno); | |
4169 } | |
4170 if (this_klass->annotations()->type_annotations() == NULL) { | |
4171 Annotations* anno = Annotations::allocate(loader_data, CHECK_NULL); | |
4172 this_klass->annotations()->set_type_annotations(anno); | |
4173 } | |
4174 this_klass->annotations()->type_annotations()->set_class_annotations(_type_annotations); | |
4175 } | |
4176 | 4162 |
4177 // Miranda methods | 4163 // Miranda methods |
4178 if ((num_miranda_methods > 0) || | 4164 if ((num_miranda_methods > 0) || |
4179 // if this class introduced new miranda methods or | 4165 // if this class introduced new miranda methods or |
4180 (super_klass.not_null() && (super_klass->has_miranda_methods())) | 4166 (super_klass.not_null() && (super_klass->has_miranda_methods())) |