< prev index next >

src/hotspot/share/classfile/systemDictionary.cpp

Print this page




1920   InstanceKlass** klassp = &_well_known_klasses[id];
1921 
1922   if ((*klassp) == NULL) {
1923     Klass* k = resolve_or_fail(symbol, true, CHECK_0);
1924     (*klassp) = InstanceKlass::cast(k);
1925   }
1926   return ((*klassp) != NULL);
1927 }
1928 
1929 void SystemDictionary::resolve_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) {
1930   assert((int)start_id <= (int)limit_id, "IDs are out of order!");
1931   for (int id = (int)start_id; id < (int)limit_id; id++) {
1932     assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
1933     resolve_wk_klass((WKID)id, CHECK);
1934   }
1935 
1936   // move the starting value forward to the limit:
1937   start_id = limit_id;
1938 }
1939 















































































1940 void SystemDictionary::resolve_well_known_classes(TRAPS) {
1941   assert(WK_KLASS(Object_klass) == NULL, "well-known classes should only be initialized once");
1942 
1943   // Create the ModuleEntry for java.base.  This call needs to be done here,
1944   // after vmSymbols::initialize() is called but before any classes are pre-loaded.
1945   ClassLoader::classLoader_init2(CHECK);
1946 
1947   // Preload commonly used klasses
1948   WKID scan = FIRST_WKID;
1949   // first do Object, then String, Class
1950 #if INCLUDE_CDS
1951   if (UseSharedSpaces) {
1952     resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Object_klass), scan, CHECK);
1953 
1954     // It's unsafe to access the archived heap regions before they
1955     // are fixed up, so we must do the fixup as early as possible
1956     // before the archived java objects are accessed by functions
1957     // such as java_lang_Class::restore_archived_mirror and
1958     // ConstantPool::restore_unshareable_info (restores the archived
1959     // resolved_references array object).
1960     //
1961     // HeapShared::fixup_mapped_heap_regions() fills the empty
1962     // spaces in the archived heap regions and may use
1963     // SystemDictionary::Object_klass(), so we can do this only after
1964     // Object_klass is resolved. See the above resolve_wk_klasses_through()
1965     // call. No mirror objects are accessed/restored in the above call.
1966     // Mirrors are restored after java.lang.Class is loaded.
1967     HeapShared::fixup_mapped_heap_regions();
1968 
1969     // Initialize the constant pool for the Object_class
1970     assert(Object_klass()->is_shared(), "must be");
1971     Object_klass()->constants()->restore_unshareable_info(CHECK);
1972     resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK);
1973   } else
1974 #endif
1975   {
1976     resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK);
1977   }









1978 
1979   // Calculate offsets for String and Class classes since they are loaded and
1980   // can be used after this point.
1981   java_lang_String::compute_offsets();
1982   java_lang_Class::compute_offsets();
1983 
1984   // Fixup mirrors for classes loaded before java.lang.Class.
1985   // These calls iterate over the objects currently in the perm gen
1986   // so calling them at this point is matters (not before when there
1987   // are fewer objects and not later after there are more objects
1988   // in the perm gen.
1989   Universe::initialize_basic_type_mirrors(CHECK);
1990   Universe::fixup_mirrors(CHECK);
1991 
1992   // do a bunch more:
1993   resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Reference_klass), scan, CHECK);
1994 
1995   // Preload ref klasses and set reference types
1996   InstanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
1997   InstanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));




1920   InstanceKlass** klassp = &_well_known_klasses[id];
1921 
1922   if ((*klassp) == NULL) {
1923     Klass* k = resolve_or_fail(symbol, true, CHECK_0);
1924     (*klassp) = InstanceKlass::cast(k);
1925   }
1926   return ((*klassp) != NULL);
1927 }
1928 
1929 void SystemDictionary::resolve_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) {
1930   assert((int)start_id <= (int)limit_id, "IDs are out of order!");
1931   for (int id = (int)start_id; id < (int)limit_id; id++) {
1932     assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
1933     resolve_wk_klass((WKID)id, CHECK);
1934   }
1935 
1936   // move the starting value forward to the limit:
1937   start_id = limit_id;
1938 }
1939 
1940 bool SystemDictionary::register_native(Klass* k, Symbol* name, Symbol* signature, address entry, TRAPS) {
1941   Method* method = k->lookup_method(name, signature);
1942   if (method == NULL) {
1943     ResourceMark rm;
1944     stringStream st;
1945     st.print("Method '");
1946     Method::print_external_name(&st, k, name, signature);
1947     st.print("' name or signature does not match");
1948     THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false);
1949   }
1950   if (!method->is_native()) {
1951     // trying to register to a non-native method, see if a JVM TI agent has added prefix(es)
1952     method = find_prefixed_native(k, name, signature, THREAD);
1953     if (method == NULL) {
1954       ResourceMark rm;
1955       stringStream st;
1956       st.print("Method '");
1957       Method::print_external_name(&st, k, name, signature);
1958       st.print("' is not declared as native");
1959       THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false);
1960     }
1961   }
1962 
1963   if (entry != NULL) {
1964     method->set_native_function(entry,
1965       Method::native_bind_event_is_interesting);
1966   } else {
1967     method->clear_native_function();
1968   }
1969   if (PrintJNIResolving) {
1970     ResourceMark rm(THREAD);
1971     tty->print_cr("[Registering JNI native method %s.%s]",
1972       method->method_holder()->external_name(),
1973       method->name()->as_C_string());
1974   }
1975   return true;
1976 }
1977 
1978 // The RegisterNatives call being attempted tried to register with a method that
1979 // is not native.  Ask JVM TI what prefixes have been specified.  Then check
1980 // to see if the native method is now wrapped with the prefixes.  See the
1981 // SetNativeMethodPrefix(es) functions in the JVM TI Spec for details.
1982 Method* SystemDictionary::find_prefixed_native(Klass* k, Symbol* name, Symbol* signature, TRAPS) {
1983 #if INCLUDE_JVMTI
1984   ResourceMark rm(THREAD);
1985   Method* method;
1986   int name_len = name->utf8_length();
1987   char* name_str = name->as_utf8();
1988   int prefix_count;
1989   char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
1990   for (int i = 0; i < prefix_count; i++) {
1991     char* prefix = prefixes[i];
1992     int prefix_len = (int)strlen(prefix);
1993 
1994     // try adding this prefix to the method name and see if it matches another method name
1995     int trial_len = name_len + prefix_len;
1996     char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
1997     strcpy(trial_name_str, prefix);
1998     strcat(trial_name_str, name_str);
1999     TempNewSymbol trial_name = SymbolTable::probe(trial_name_str, trial_len);
2000     if (trial_name == NULL) {
2001       continue; // no such symbol, so this prefix wasn't used, try the next prefix
2002     }
2003     method = k->lookup_method(trial_name, signature);
2004     if (method == NULL) {
2005       continue; // signature doesn't match, try the next prefix
2006     }
2007     if (method->is_native()) {
2008       method->set_is_prefixed_native();
2009       return method; // wahoo, we found a prefixed version of the method, return it
2010     }
2011     // found as non-native, so prefix is good, add it, probably just need more prefixes
2012     name_len = trial_len;
2013     name_str = trial_name_str;
2014   }
2015 #endif // INCLUDE_JVMTI
2016   return NULL; // not found
2017 }
2018 
2019 void SystemDictionary::resolve_well_known_classes(TRAPS) {
2020   assert(WK_KLASS(Object_klass) == NULL, "well-known classes should only be initialized once");
2021 
2022   // Create the ModuleEntry for java.base.  This call needs to be done here,
2023   // after vmSymbols::initialize() is called but before any classes are pre-loaded.
2024   ClassLoader::classLoader_init2(CHECK);
2025 
2026   // Preload commonly used klasses
2027   WKID scan = FIRST_WKID;
2028   // first do Object, then String, Class
2029 #if INCLUDE_CDS
2030   if (UseSharedSpaces) {
2031     resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Object_klass), scan, CHECK);
2032 
2033     // It's unsafe to access the archived heap regions before they
2034     // are fixed up, so we must do the fixup as early as possible
2035     // before the archived java objects are accessed by functions
2036     // such as java_lang_Class::restore_archived_mirror and
2037     // ConstantPool::restore_unshareable_info (restores the archived
2038     // resolved_references array object).
2039     //
2040     // HeapShared::fixup_mapped_heap_regions() fills the empty
2041     // spaces in the archived heap regions and may use
2042     // SystemDictionary::Object_klass(), so we can do this only after
2043     // Object_klass is resolved. See the above resolve_wk_klasses_through()
2044     // call. No mirror objects are accessed/restored in the above call.
2045     // Mirrors are restored after java.lang.Class is loaded.
2046     HeapShared::fixup_mapped_heap_regions();
2047 
2048     // Initialize the constant pool for the Object_class
2049     assert(Object_klass()->is_shared(), "must be");
2050     Object_klass()->constants()->restore_unshareable_info(CHECK);
2051     resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK);
2052   } else
2053 #endif
2054   {
2055     resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK);
2056   }
2057 
2058   assert(WK_KLASS(Object_klass) != NULL, "well-known classes should now be initialized");
2059 
2060   // Register native methods of Object
2061   register_native(Object_klass(), vmSymbols::hashCode_name(), vmSymbols::void_int_signature(), (address)&JVM_IHashCode, THREAD);
2062   register_native(Object_klass(), vmSymbols::wait_name(), vmSymbols::long_void_signature(), (address)&JVM_MonitorWait, THREAD);
2063   register_native(Object_klass(), vmSymbols::notify_name(), vmSymbols::void_method_signature(), (address)&JVM_MonitorNotify, THREAD);
2064   register_native(Object_klass(), vmSymbols::notifyAll_name(), vmSymbols::void_method_signature(), (address)&JVM_MonitorNotifyAll, THREAD);
2065   register_native(Object_klass(), vmSymbols::clone_name(), vmSymbols::void_object_signature(), (address)&JVM_Clone, THREAD);
2066 
2067   // Calculate offsets for String and Class classes since they are loaded and
2068   // can be used after this point.
2069   java_lang_String::compute_offsets();
2070   java_lang_Class::compute_offsets();
2071 
2072   // Fixup mirrors for classes loaded before java.lang.Class.
2073   // These calls iterate over the objects currently in the perm gen
2074   // so calling them at this point is matters (not before when there
2075   // are fewer objects and not later after there are more objects
2076   // in the perm gen.
2077   Universe::initialize_basic_type_mirrors(CHECK);
2078   Universe::fixup_mirrors(CHECK);
2079 
2080   // do a bunch more:
2081   resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Reference_klass), scan, CHECK);
2082 
2083   // Preload ref klasses and set reference types
2084   InstanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
2085   InstanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));


< prev index next >