comparison src/share/vm/classfile/systemDictionary.cpp @ 2356:72dee110246f

6839872: remove implementation inheritance from JSR 292 APIs Summary: consolidate runtime support in java.dyn.MethodHandleNatives; include transitional compatibility logic Reviewed-by: twisti
author jrose
date Fri, 11 Mar 2011 22:33:47 -0800
parents 4f26f535a225
children 8033953d67ff
comparison
equal deleted inserted replaced
2355:799d8ccf63cf 2356:72dee110246f
1 /* 1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
1885 WK_KLASSES_DO(WK_KLASS_INIT_INFO) 1885 WK_KLASSES_DO(WK_KLASS_INIT_INFO)
1886 #undef WK_KLASS_INIT_INFO 1886 #undef WK_KLASS_INIT_INFO
1887 0 1887 0
1888 }; 1888 };
1889 1889
1890 Symbol* SystemDictionary::find_backup_symbol(Symbol* symbol,
1891 const char* from_prefix,
1892 const char* to_prefix) {
1893 assert(AllowTransitionalJSR292, ""); // delete this subroutine
1894 Symbol* backup_symbol = NULL;
1895 size_t from_len = strlen(from_prefix);
1896 if (strncmp((const char*) symbol->base(), from_prefix, from_len) != 0)
1897 return NULL;
1898 char buf[100];
1899 size_t to_len = strlen(to_prefix);
1900 size_t tail_len = symbol->utf8_length() - from_len;
1901 size_t new_len = to_len + tail_len;
1902 guarantee(new_len < sizeof(buf), "buf too small");
1903 memcpy(buf, to_prefix, to_len);
1904 memcpy(buf + to_len, symbol->base() + from_len, tail_len);
1905 buf[new_len] = '\0';
1906 vmSymbols::SID backup_sid = vmSymbols::find_sid(buf);
1907 if (backup_sid != vmSymbols::NO_SID) {
1908 backup_symbol = vmSymbols::symbol_at(backup_sid);
1909 }
1910 return backup_symbol;
1911 }
1912
1913 Symbol* SystemDictionary::find_backup_class_name(Symbol* symbol) {
1914 assert(AllowTransitionalJSR292, ""); // delete this subroutine
1915 if (symbol == NULL) return NULL;
1916 Symbol* backup_symbol = find_backup_symbol(symbol, "java/lang/invoke/", "java/dyn/"); // AllowTransitionalJSR292 ONLY
1917 if (backup_symbol == NULL)
1918 backup_symbol = find_backup_symbol(symbol, "java/dyn/", "sun/dyn/"); // AllowTransitionalJSR292 ONLY
1919 return backup_symbol;
1920 }
1921
1922 Symbol* SystemDictionary::find_backup_signature(Symbol* symbol) {
1923 assert(AllowTransitionalJSR292, ""); // delete this subroutine
1924 if (symbol == NULL) return NULL;
1925 return find_backup_symbol(symbol, "Ljava/lang/invoke/", "Ljava/dyn/");
1926 }
1927
1890 bool SystemDictionary::initialize_wk_klass(WKID id, int init_opt, TRAPS) { 1928 bool SystemDictionary::initialize_wk_klass(WKID id, int init_opt, TRAPS) {
1891 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); 1929 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
1892 int info = wk_init_info[id - FIRST_WKID]; 1930 int info = wk_init_info[id - FIRST_WKID];
1893 int sid = (info >> CEIL_LG_OPTION_LIMIT); 1931 int sid = (info >> CEIL_LG_OPTION_LIMIT);
1894 Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid); 1932 Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid);
1895 klassOop* klassp = &_well_known_klasses[id]; 1933 klassOop* klassp = &_well_known_klasses[id];
1896 bool must_load = (init_opt < SystemDictionary::Opt); 1934 bool pre_load = (init_opt < SystemDictionary::Opt);
1897 bool try_load = true; 1935 bool try_load = true;
1898 if (init_opt == SystemDictionary::Opt_Kernel) { 1936 if (init_opt == SystemDictionary::Opt_Kernel) {
1899 #ifndef KERNEL 1937 #ifndef KERNEL
1900 try_load = false; 1938 try_load = false;
1901 #endif //KERNEL 1939 #endif //KERNEL
1902 } 1940 }
1903 if ((*klassp) == NULL && try_load) { 1941 Symbol* backup_symbol = NULL; // symbol to try if the current symbol fails
1942 if (init_opt == SystemDictionary::Pre_JSR292) {
1943 if (!EnableMethodHandles) try_load = false; // do not bother to load such classes
1944 if (AllowTransitionalJSR292) {
1945 backup_symbol = find_backup_class_name(symbol);
1946 if (try_load && PreferTransitionalJSR292) {
1947 while (backup_symbol != NULL) {
1948 (*klassp) = resolve_or_null(backup_symbol, CHECK_0); // try backup early
1949 if (TraceMethodHandles) {
1950 ResourceMark rm;
1951 tty->print_cr("MethodHandles: try backup first for %s => %s (%s)",
1952 symbol->as_C_string(), backup_symbol->as_C_string(),
1953 ((*klassp) == NULL) ? "no such class" : "backup load succeeded");
1954 }
1955 if ((*klassp) != NULL) return true;
1956 backup_symbol = find_backup_class_name(backup_symbol); // find next backup
1957 }
1958 }
1959 }
1960 }
1961 if ((*klassp) != NULL) return true;
1962 if (!try_load) return false;
1963 while (symbol != NULL) {
1964 bool must_load = (pre_load && (backup_symbol == NULL));
1904 if (must_load) { 1965 if (must_load) {
1905 (*klassp) = resolve_or_fail(symbol, true, CHECK_0); // load required class 1966 (*klassp) = resolve_or_fail(symbol, true, CHECK_0); // load required class
1906 } else { 1967 } else {
1907 (*klassp) = resolve_or_null(symbol, CHECK_0); // load optional klass 1968 (*klassp) = resolve_or_null(symbol, CHECK_0); // load optional klass
1908 } 1969 }
1909 } 1970 if ((*klassp) != NULL) return true;
1910 return ((*klassp) != NULL); 1971 // Go around again. Example of long backup sequence:
1972 // java.lang.invoke.MemberName, java.dyn.MemberName, sun.dyn.MemberName, ONLY if AllowTransitionalJSR292
1973 if (TraceMethodHandles && (backup_symbol != NULL)) {
1974 ResourceMark rm;
1975 tty->print_cr("MethodHandles: backup for %s => %s",
1976 symbol->as_C_string(), backup_symbol->as_C_string());
1977 }
1978 symbol = backup_symbol;
1979 if (AllowTransitionalJSR292)
1980 backup_symbol = find_backup_class_name(symbol);
1981 }
1982 return false;
1911 } 1983 }
1912 1984
1913 void SystemDictionary::initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) { 1985 void SystemDictionary::initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) {
1914 assert((int)start_id <= (int)limit_id, "IDs are out of order!"); 1986 assert((int)start_id <= (int)limit_id, "IDs are out of order!");
1915 for (int id = (int)start_id; id < (int)limit_id; id++) { 1987 for (int id = (int)start_id; id < (int)limit_id; id++) {
2346 spe = NULL; 2418 spe = NULL;
2347 // Must create lots of stuff here, but outside of the SystemDictionary lock. 2419 // Must create lots of stuff here, but outside of the SystemDictionary lock.
2348 if (THREAD->is_Compiler_thread()) 2420 if (THREAD->is_Compiler_thread())
2349 return NULL; // do not attempt from within compiler 2421 return NULL; // do not attempt from within compiler
2350 bool for_invokeGeneric = (name_id == vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name)); 2422 bool for_invokeGeneric = (name_id == vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name));
2423 if (AllowInvokeForInvokeGeneric && name_id == vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name))
2424 for_invokeGeneric = true;
2351 bool found_on_bcp = false; 2425 bool found_on_bcp = false;
2352 Handle mt = find_method_handle_type(signature, accessing_klass, 2426 Handle mt = find_method_handle_type(signature, accessing_klass,
2353 for_invokeGeneric, 2427 for_invokeGeneric,
2354 found_on_bcp, CHECK_NULL); 2428 found_on_bcp, CHECK_NULL);
2355 KlassHandle mh_klass = SystemDictionaryHandles::MethodHandle_klass(); 2429 KlassHandle mh_klass = SystemDictionaryHandles::MethodHandle_klass();
2529 args.push_oop(signature_invoker->method_handle_type()); 2603 args.push_oop(signature_invoker->method_handle_type());
2530 args.push_oop(info()); 2604 args.push_oop(info());
2531 args.push_oop(caller_mname()); 2605 args.push_oop(caller_mname());
2532 args.push_int(caller_bci); 2606 args.push_int(caller_bci);
2533 JavaValue result(T_OBJECT); 2607 JavaValue result(T_OBJECT);
2608 Symbol* makeDynamicCallSite_signature = vmSymbols::makeDynamicCallSite_signature();
2609 if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodHandleNatives_klass()->name() == vmSymbols::sun_dyn_MethodHandleNatives()) {
2610 makeDynamicCallSite_signature = vmSymbols::makeDynamicCallSite_TRANS_signature();
2611 }
2534 JavaCalls::call_static(&result, 2612 JavaCalls::call_static(&result,
2535 SystemDictionary::MethodHandleNatives_klass(), 2613 SystemDictionary::MethodHandleNatives_klass(),
2536 vmSymbols::makeDynamicCallSite_name(), 2614 vmSymbols::makeDynamicCallSite_name(),
2537 vmSymbols::makeDynamicCallSite_signature(), 2615 makeDynamicCallSite_signature,
2538 &args, CHECK_(empty)); 2616 &args, CHECK_(empty));
2539 oop call_site_oop = (oop) result.get_jobject(); 2617 oop call_site_oop = (oop) result.get_jobject();
2540 assert(call_site_oop->is_oop() 2618 assert(call_site_oop->is_oop()
2541 /*&& java_dyn_CallSite::is_instance(call_site_oop)*/, "must be sane"); 2619 /*&& java_dyn_CallSite::is_instance(call_site_oop)*/, "must be sane");
2542 if (TraceMethodHandles) { 2620 if (TraceMethodHandles) {