1472 }
1473 } else {
1474 // After the module system has been initialized, check if the class'
1475 // package is in a module defined to the boot loader.
1476 if (pkg_name == NULL || pkg_entry == NULL || pkg_entry->in_unnamed_module()) {
1477 // Class is either in the unnamed package, in a named package
1478 // within a module not defined to the boot loader or in a
1479 // a named package within the unnamed module. In all cases,
1480 // limit visibility to search for the class only in the boot
1481 // loader's append path.
1482 search_only_bootloader_append = true;
1483 }
1484 }
1485
1486 // Prior to bootstrapping's module initialization, never load a class outside
1487 // of the boot loader's module path
1488 assert(Universe::is_module_initialized() ||
1489 !search_only_bootloader_append,
1490 "Attempt to load a class outside of boot loader's module path");
1491
1492 // Search the shared system dictionary for classes preloaded into the
1493 // shared spaces.
1494 InstanceKlass* k = NULL;
1495 {
1496 #if INCLUDE_CDS
1497 PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
1498 k = load_shared_class(class_name, class_loader, THREAD);
1499 #endif
1500 }
1501
1502 if (k == NULL) {
1503 // Use VM class loader
1504 PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
1505 k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL);
1506 }
1507
1508 // find_or_define_instance_class may return a different InstanceKlass
1509 if (k != NULL) {
1510 InstanceKlass* defined_k =
1511 find_or_define_instance_class(class_name, class_loader, k, THREAD);
1512 if (!HAS_PENDING_EXCEPTION && defined_k != k) {
1513 // If a parallel capable class loader already defined this class, register 'k' for cleanup.
1941 RemoveClassesClosure rcc;
1942 MutexLocker ml(ClassLoaderDataGraph_lock);
1943 ClassLoaderDataGraph::cld_do(&rcc);
1944 }
1945
1946 // ----------------------------------------------------------------------------
1947 // Initialization
1948
1949 void SystemDictionary::initialize(TRAPS) {
1950 // Allocate arrays
1951 _placeholders = new PlaceholderTable(_placeholder_table_size);
1952 _number_of_modifications = 0;
1953 _loader_constraints = new LoaderConstraintTable(_loader_constraint_size);
1954 _resolution_errors = new ResolutionErrorTable(_resolution_error_size);
1955 _invoke_method_table = new SymbolPropertyTable(_invoke_method_size);
1956 _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize);
1957
1958 // Allocate private object used as system class loader lock
1959 _system_loader_lock_obj = oopFactory::new_intArray(0, CHECK);
1960 // Initialize basic classes
1961 resolve_preloaded_classes(CHECK);
1962 }
1963
1964 // Compact table of directions on the initialization of klasses:
1965 static const short wk_init_info[] = {
1966 #define WK_KLASS_INIT_INFO(name, symbol) \
1967 ((short)vmSymbols::VM_SYMBOL_ENUM_NAME(symbol)),
1968
1969 WK_KLASSES_DO(WK_KLASS_INIT_INFO)
1970 #undef WK_KLASS_INIT_INFO
1971 0
1972 };
1973
1974 bool SystemDictionary::resolve_wk_klass(WKID id, TRAPS) {
1975 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
1976 int sid = wk_init_info[id - FIRST_WKID];
1977 Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid);
1978 InstanceKlass** klassp = &_well_known_klasses[id];
1979
1980
1981 #if INCLUDE_JVMCI
1982 if (id >= FIRST_JVMCI_WKID) {
1983 assert(EnableJVMCI, "resolve JVMCI classes only when EnableJVMCI is true");
1984 }
1985 #endif
1986
1987 if ((*klassp) == NULL) {
1988 Klass* k = resolve_or_fail(symbol, true, CHECK_0);
1989 (*klassp) = InstanceKlass::cast(k);
1990 }
1991 return ((*klassp) != NULL);
1992 }
1993
1994 void SystemDictionary::resolve_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) {
1995 assert((int)start_id <= (int)limit_id, "IDs are out of order!");
1996 for (int id = (int)start_id; id < (int)limit_id; id++) {
1997 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
1998 resolve_wk_klass((WKID)id, CHECK);
1999 }
2000
2001 // move the starting value forward to the limit:
2002 start_id = limit_id;
2003 }
2004
2005 void SystemDictionary::resolve_preloaded_classes(TRAPS) {
2006 assert(WK_KLASS(Object_klass) == NULL, "preloaded classes should only be initialized once");
2007
2008 // Create the ModuleEntry for java.base. This call needs to be done here,
2009 // after vmSymbols::initialize() is called but before any classes are pre-loaded.
2010 ClassLoader::classLoader_init2(CHECK);
2011
2012 // Preload commonly used klasses
2013 WKID scan = FIRST_WKID;
2014 // first do Object, then String, Class
2015 #if INCLUDE_CDS
2016 if (UseSharedSpaces) {
2017 resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Object_klass), scan, CHECK);
2018
2019 // It's unsafe to access the archived heap regions before they
2020 // are fixed up, so we must do the fixup as early as possible
2021 // before the archived java objects are accessed by functions
2022 // such as java_lang_Class::restore_archived_mirror and
2023 // ConstantPool::restore_unshareable_info (restores the archived
2024 // resolved_references array object).
2025 //
2026 // HeapShared::fixup_mapped_heap_regions() fills the empty
2054 Universe::fixup_mirrors(CHECK);
2055
2056 // do a bunch more:
2057 resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Reference_klass), scan, CHECK);
2058
2059 // Preload ref klasses and set reference types
2060 InstanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
2061 InstanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
2062
2063 resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK);
2064 InstanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
2065 InstanceKlass::cast(WK_KLASS(WeakReference_klass))->set_reference_type(REF_WEAK);
2066 InstanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL);
2067 InstanceKlass::cast(WK_KLASS(PhantomReference_klass))->set_reference_type(REF_PHANTOM);
2068
2069 // JSR 292 classes
2070 WKID jsr292_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass);
2071 WKID jsr292_group_end = WK_KLASS_ENUM_NAME(VolatileCallSite_klass);
2072 resolve_wk_klasses_until(jsr292_group_start, scan, CHECK);
2073 resolve_wk_klasses_through(jsr292_group_end, scan, CHECK);
2074 resolve_wk_klasses_until(NOT_JVMCI(WKID_LIMIT) JVMCI_ONLY(FIRST_JVMCI_WKID), scan, CHECK);
2075
2076 _box_klasses[T_BOOLEAN] = WK_KLASS(Boolean_klass);
2077 _box_klasses[T_CHAR] = WK_KLASS(Character_klass);
2078 _box_klasses[T_FLOAT] = WK_KLASS(Float_klass);
2079 _box_klasses[T_DOUBLE] = WK_KLASS(Double_klass);
2080 _box_klasses[T_BYTE] = WK_KLASS(Byte_klass);
2081 _box_klasses[T_SHORT] = WK_KLASS(Short_klass);
2082 _box_klasses[T_INT] = WK_KLASS(Integer_klass);
2083 _box_klasses[T_LONG] = WK_KLASS(Long_klass);
2084 //_box_klasses[T_OBJECT] = WK_KLASS(object_klass);
2085 //_box_klasses[T_ARRAY] = WK_KLASS(object_klass);
2086
2087 { // Compute whether we should use checkPackageAccess or NOT
2088 Method* method = InstanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature());
2089 _has_checkPackageAccess = (method != NULL);
2090 }
2091 }
2092
2093 // Tells if a given klass is a box (wrapper class, such as java.lang.Integer).
2094 // If so, returns the basic type it holds. If not, returns T_OBJECT.
2095 BasicType SystemDictionary::box_klass_type(Klass* k) {
2096 assert(k != NULL, "");
2097 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
2098 if (_box_klasses[i] == k)
2099 return (BasicType)i;
2100 }
2101 return T_OBJECT;
2102 }
2103
2104 // Constraints on class loaders. The details of the algorithm can be
2105 // found in the OOPSLA'98 paper "Dynamic Class Loading in the Java
2106 // Virtual Machine" by Sheng Liang and Gilad Bracha. The basic idea is
2107 // that the dictionary needs to maintain a set of contraints that
2108 // must be satisfied by all classes in the dictionary.
2109 // if defining is true, then LinkageError if already in dictionary
|
1472 }
1473 } else {
1474 // After the module system has been initialized, check if the class'
1475 // package is in a module defined to the boot loader.
1476 if (pkg_name == NULL || pkg_entry == NULL || pkg_entry->in_unnamed_module()) {
1477 // Class is either in the unnamed package, in a named package
1478 // within a module not defined to the boot loader or in a
1479 // a named package within the unnamed module. In all cases,
1480 // limit visibility to search for the class only in the boot
1481 // loader's append path.
1482 search_only_bootloader_append = true;
1483 }
1484 }
1485
1486 // Prior to bootstrapping's module initialization, never load a class outside
1487 // of the boot loader's module path
1488 assert(Universe::is_module_initialized() ||
1489 !search_only_bootloader_append,
1490 "Attempt to load a class outside of boot loader's module path");
1491
1492 // Search for classes in the CDS archive.
1493 InstanceKlass* k = NULL;
1494 {
1495 #if INCLUDE_CDS
1496 PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
1497 k = load_shared_class(class_name, class_loader, THREAD);
1498 #endif
1499 }
1500
1501 if (k == NULL) {
1502 // Use VM class loader
1503 PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
1504 k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL);
1505 }
1506
1507 // find_or_define_instance_class may return a different InstanceKlass
1508 if (k != NULL) {
1509 InstanceKlass* defined_k =
1510 find_or_define_instance_class(class_name, class_loader, k, THREAD);
1511 if (!HAS_PENDING_EXCEPTION && defined_k != k) {
1512 // If a parallel capable class loader already defined this class, register 'k' for cleanup.
1940 RemoveClassesClosure rcc;
1941 MutexLocker ml(ClassLoaderDataGraph_lock);
1942 ClassLoaderDataGraph::cld_do(&rcc);
1943 }
1944
1945 // ----------------------------------------------------------------------------
1946 // Initialization
1947
1948 void SystemDictionary::initialize(TRAPS) {
1949 // Allocate arrays
1950 _placeholders = new PlaceholderTable(_placeholder_table_size);
1951 _number_of_modifications = 0;
1952 _loader_constraints = new LoaderConstraintTable(_loader_constraint_size);
1953 _resolution_errors = new ResolutionErrorTable(_resolution_error_size);
1954 _invoke_method_table = new SymbolPropertyTable(_invoke_method_size);
1955 _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize);
1956
1957 // Allocate private object used as system class loader lock
1958 _system_loader_lock_obj = oopFactory::new_intArray(0, CHECK);
1959 // Initialize basic classes
1960 resolve_well_known_classes(CHECK);
1961 }
1962
1963 // Compact table of directions on the initialization of klasses:
1964 static const short wk_init_info[] = {
1965 #define WK_KLASS_INIT_INFO(name, symbol) \
1966 ((short)vmSymbols::VM_SYMBOL_ENUM_NAME(symbol)),
1967
1968 WK_KLASSES_DO(WK_KLASS_INIT_INFO)
1969 #undef WK_KLASS_INIT_INFO
1970 0
1971 };
1972
1973 #ifdef ASSERT
1974 bool SystemDictionary::is_well_known_klass(Symbol* class_name) {
1975 for (int i = 0; ; i++) {
1976 int sid = wk_init_info[i];
1977 if (sid == 0) {
1978 break;
1979 }
1980 Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid);
1981 if (class_name == symbol) {
1982 return true;
1983 }
1984 }
1985 return false;
1986 }
1987 #endif
1988
1989 bool SystemDictionary::resolve_wk_klass(WKID id, TRAPS) {
1990 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
1991 int sid = wk_init_info[id - FIRST_WKID];
1992 Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid);
1993 InstanceKlass** klassp = &_well_known_klasses[id];
1994
1995
1996 #if INCLUDE_JVMCI
1997 if (id >= FIRST_JVMCI_WKID) {
1998 assert(EnableJVMCI, "resolve JVMCI classes only when EnableJVMCI is true");
1999 }
2000 #endif
2001
2002 if ((*klassp) == NULL) {
2003 Klass* k = resolve_or_fail(symbol, true, CHECK_0);
2004 (*klassp) = InstanceKlass::cast(k);
2005 }
2006 return ((*klassp) != NULL);
2007 }
2008
2009 void SystemDictionary::resolve_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) {
2010 assert((int)start_id <= (int)limit_id, "IDs are out of order!");
2011 for (int id = (int)start_id; id < (int)limit_id; id++) {
2012 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
2013 resolve_wk_klass((WKID)id, CHECK);
2014 }
2015
2016 // move the starting value forward to the limit:
2017 start_id = limit_id;
2018 }
2019
2020 void SystemDictionary::resolve_well_known_classes(TRAPS) {
2021 assert(WK_KLASS(Object_klass) == NULL, "well-known classes should only be initialized once");
2022
2023 // Create the ModuleEntry for java.base. This call needs to be done here,
2024 // after vmSymbols::initialize() is called but before any classes are pre-loaded.
2025 ClassLoader::classLoader_init2(CHECK);
2026
2027 // Preload commonly used klasses
2028 WKID scan = FIRST_WKID;
2029 // first do Object, then String, Class
2030 #if INCLUDE_CDS
2031 if (UseSharedSpaces) {
2032 resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Object_klass), scan, CHECK);
2033
2034 // It's unsafe to access the archived heap regions before they
2035 // are fixed up, so we must do the fixup as early as possible
2036 // before the archived java objects are accessed by functions
2037 // such as java_lang_Class::restore_archived_mirror and
2038 // ConstantPool::restore_unshareable_info (restores the archived
2039 // resolved_references array object).
2040 //
2041 // HeapShared::fixup_mapped_heap_regions() fills the empty
2069 Universe::fixup_mirrors(CHECK);
2070
2071 // do a bunch more:
2072 resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Reference_klass), scan, CHECK);
2073
2074 // Preload ref klasses and set reference types
2075 InstanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
2076 InstanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
2077
2078 resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK);
2079 InstanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
2080 InstanceKlass::cast(WK_KLASS(WeakReference_klass))->set_reference_type(REF_WEAK);
2081 InstanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL);
2082 InstanceKlass::cast(WK_KLASS(PhantomReference_klass))->set_reference_type(REF_PHANTOM);
2083
2084 // JSR 292 classes
2085 WKID jsr292_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass);
2086 WKID jsr292_group_end = WK_KLASS_ENUM_NAME(VolatileCallSite_klass);
2087 resolve_wk_klasses_until(jsr292_group_start, scan, CHECK);
2088 resolve_wk_klasses_through(jsr292_group_end, scan, CHECK);
2089 WKID last = NOT_JVMCI(WKID_LIMIT) JVMCI_ONLY(FIRST_JVMCI_WKID);
2090 resolve_wk_klasses_until(last, scan, CHECK);
2091
2092 _box_klasses[T_BOOLEAN] = WK_KLASS(Boolean_klass);
2093 _box_klasses[T_CHAR] = WK_KLASS(Character_klass);
2094 _box_klasses[T_FLOAT] = WK_KLASS(Float_klass);
2095 _box_klasses[T_DOUBLE] = WK_KLASS(Double_klass);
2096 _box_klasses[T_BYTE] = WK_KLASS(Byte_klass);
2097 _box_klasses[T_SHORT] = WK_KLASS(Short_klass);
2098 _box_klasses[T_INT] = WK_KLASS(Integer_klass);
2099 _box_klasses[T_LONG] = WK_KLASS(Long_klass);
2100 //_box_klasses[T_OBJECT] = WK_KLASS(object_klass);
2101 //_box_klasses[T_ARRAY] = WK_KLASS(object_klass);
2102
2103 { // Compute whether we should use checkPackageAccess or NOT
2104 Method* method = InstanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature());
2105 _has_checkPackageAccess = (method != NULL);
2106 }
2107
2108 if (UseSharedSpaces) {
2109 assert(JvmtiEnvBase::get_phase() <= JVMTI_PHASE_PRIMORDIAL,
2110 "All well known classes must be resolved in JVMTI_PHASE_PRIMORDIAL or before");
2111 for (int i=FIRST_WKID; i<last; i++) {
2112 InstanceKlass* k = _well_known_klasses[i];
2113 assert(k->is_shared(), "must not be replaced by JVMTI class file load hook");
2114 }
2115 }
2116 }
2117
2118 // Tells if a given klass is a box (wrapper class, such as java.lang.Integer).
2119 // If so, returns the basic type it holds. If not, returns T_OBJECT.
2120 BasicType SystemDictionary::box_klass_type(Klass* k) {
2121 assert(k != NULL, "");
2122 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
2123 if (_box_klasses[i] == k)
2124 return (BasicType)i;
2125 }
2126 return T_OBJECT;
2127 }
2128
2129 // Constraints on class loaders. The details of the algorithm can be
2130 // found in the OOPSLA'98 paper "Dynamic Class Loading in the Java
2131 // Virtual Machine" by Sheng Liang and Gilad Bracha. The basic idea is
2132 // that the dictionary needs to maintain a set of contraints that
2133 // must be satisfied by all classes in the dictionary.
2134 // if defining is true, then LinkageError if already in dictionary
|