2125 // If so, returns the basic type it holds. If not, returns T_OBJECT.
2126 BasicType SystemDictionary::box_klass_type(Klass* k) {
2127 assert(k != NULL, "");
2128 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
2129 if (_box_klasses[i] == k)
2130 return (BasicType)i;
2131 }
2132 return T_OBJECT;
2133 }
2134
2135 // Constraints on class loaders. The details of the algorithm can be
2136 // found in the OOPSLA'98 paper "Dynamic Class Loading in the Java
2137 // Virtual Machine" by Sheng Liang and Gilad Bracha. The basic idea is
2138 // that the dictionary needs to maintain a set of contraints that
2139 // must be satisfied by all classes in the dictionary.
2140 // if defining is true, then LinkageError if already in dictionary
2141 // if initiating loader, then ok if InstanceKlass matches existing entry
2142
2143 void SystemDictionary::check_constraints(unsigned int d_hash,
2144 InstanceKlass* k,
2145 Handle class_loader, bool defining,
2146 TRAPS) {
2147 const char *linkage_error1 = NULL;
2148 const char *linkage_error2 = NULL;
2149 {
2150 Symbol* name = k->name();
2151 ClassLoaderData *loader_data = class_loader_data(class_loader);
2152
2153 MutexLocker mu(SystemDictionary_lock, THREAD);
2154
2155 InstanceKlass* check = find_class(d_hash, name, loader_data->dictionary());
2156 if (check != NULL) {
2157 // if different InstanceKlass - duplicate class definition,
2158 // else - ok, class loaded by a different thread in parallel,
2159 // we should only have found it if it was done loading and ok to use
2160 // dictionary only holds instance classes, placeholders
2161 // also holds array classes
2162
2163 assert(check->is_instance_klass(), "noninstance in systemdictionary");
2164 if ((defining == true) || (k != check)) {
2165 linkage_error1 = "loader (instance of ";
2166 linkage_error2 = "): attempted duplicate class definition for name: \"";
2167 } else {
2168 return;
2169 }
2170 }
2171
2172 #ifdef ASSERT
2173 Symbol* ph_check = find_placeholder(name, loader_data);
2174 assert(ph_check == NULL || ph_check == name, "invalid symbol");
2175 #endif
2176
2177 if (linkage_error1 == NULL) {
2178 if (constraints()->check_or_update(k, class_loader, name) == false) {
2179 linkage_error1 = "loader constraint violation: loader (instance of ";
2180 linkage_error2 = ") previously initiated loading for a different type with name \"";
2181 }
2182 }
2183 }
2184
2185 // Throw error now if needed (cannot throw while holding
2186 // SystemDictionary_lock because of rank ordering)
2187
2188 if (linkage_error1) {
2189 ResourceMark rm(THREAD);
2190 const char* class_loader_name = loader_name(class_loader());
2191 char* type_name = k->name()->as_C_string();
2192 size_t buflen = strlen(linkage_error1) + strlen(class_loader_name) +
2193 strlen(linkage_error2) + strlen(type_name) + 2; // +2 for '"' and null byte.
2194 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
2195 jio_snprintf(buf, buflen, "%s%s%s%s\"", linkage_error1, class_loader_name, linkage_error2, type_name);
2196 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
2197 }
2198 }
2199
2200
2201 // Update class loader data dictionary - done after check_constraint and add_to_hierachy
2202 // have been called.
2203 void SystemDictionary::update_dictionary(unsigned int d_hash,
2204 int p_index, unsigned int p_hash,
2205 InstanceKlass* k,
2206 Handle class_loader,
2207 TRAPS) {
2208 // Compile_lock prevents systemDictionary updates during compilations
2209 assert_locked_or_safepoint(Compile_lock);
2210 Symbol* name = k->name();
2211 ClassLoaderData *loader_data = class_loader_data(class_loader);
2212
2213 {
2214 MutexLocker mu1(SystemDictionary_lock, THREAD);
2215
2216 // See whether biased locking is enabled and if so set it for this
2217 // klass.
2218 // Note that this must be done past the last potential blocking
2219 // point / safepoint. We enable biased locking lazily using a
2220 // VM_Operation to iterate the SystemDictionary and installing the
3076 // Combining platform and system loader dictionaries into boot loader dictionary.
3077 // During run time, we only have one shared dictionary.
3078 void SystemDictionary::combine_shared_dictionaries() {
3079 assert(DumpSharedSpaces, "dump time only");
3080 // If AppCDS isn't enabled, we only dump the classes in the boot loader dictionary
3081 // into the shared archive.
3082 if (UseAppCDS) {
3083 Dictionary* master_dictionary = ClassLoaderData::the_null_class_loader_data()->dictionary();
3084 CombineDictionariesClosure cdc(master_dictionary);
3085 ClassLoaderDataGraph::cld_do(&cdc);
3086 }
3087
3088 // These tables are no longer valid or necessary. Keeping them around will
3089 // cause SystemDictionary::verify() to fail. Let's empty them.
3090 _placeholders = new PlaceholderTable(_placeholder_table_size);
3091 _loader_constraints = new LoaderConstraintTable(_loader_constraint_size);
3092
3093 NOT_PRODUCT(SystemDictionary::verify());
3094 }
3095
3096 // caller needs ResourceMark
3097 const char* SystemDictionary::loader_name(const oop loader) {
3098 return ((loader) == NULL ? "<bootloader>" :
3099 InstanceKlass::cast((loader)->klass())->name()->as_C_string());
3100 }
3101
3102 // caller needs ResourceMark
3103 const char* SystemDictionary::loader_name(const ClassLoaderData* loader_data) {
3104 return (loader_data->class_loader() == NULL ? "<bootloader>" :
3105 SystemDictionary::loader_name(loader_data->class_loader()));
3106 }
|
2125 // If so, returns the basic type it holds. If not, returns T_OBJECT.
2126 BasicType SystemDictionary::box_klass_type(Klass* k) {
2127 assert(k != NULL, "");
2128 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
2129 if (_box_klasses[i] == k)
2130 return (BasicType)i;
2131 }
2132 return T_OBJECT;
2133 }
2134
2135 // Constraints on class loaders. The details of the algorithm can be
2136 // found in the OOPSLA'98 paper "Dynamic Class Loading in the Java
2137 // Virtual Machine" by Sheng Liang and Gilad Bracha. The basic idea is
2138 // that the dictionary needs to maintain a set of contraints that
2139 // must be satisfied by all classes in the dictionary.
2140 // if defining is true, then LinkageError if already in dictionary
2141 // if initiating loader, then ok if InstanceKlass matches existing entry
2142
2143 void SystemDictionary::check_constraints(unsigned int d_hash,
2144 InstanceKlass* k,
2145 Handle class_loader,
2146 bool defining,
2147 TRAPS) {
2148 const char *linkage_error1 = NULL;
2149 const char *linkage_error2 = NULL;
2150 const char *linkage_error3 = "";
2151 // Remember the loader of the similar class that is already loaded.
2152 const char *existing_klass_loader_name = "";
2153
2154 {
2155 Symbol* name = k->name();
2156 ClassLoaderData *loader_data = class_loader_data(class_loader);
2157
2158 MutexLocker mu(SystemDictionary_lock, THREAD);
2159
2160 InstanceKlass* check = find_class(d_hash, name, loader_data->dictionary());
2161 if (check != NULL) {
2162 // If different InstanceKlass - duplicate class definition,
2163 // else - ok, class loaded by a different thread in parallel.
2164 // We should only have found it if it was done loading and ok to use.
2165 // The dictionary only holds instance classes, placeholders
2166 // also hold array classes.
2167
2168 assert(check->is_instance_klass(), "noninstance in systemdictionary");
2169 if ((defining == true) || (k != check)) {
2170 linkage_error1 = "loader ";
2171 linkage_error2 = " attempted duplicate class definition for ";
2172 guarantee(check->class_loader() == class_loader(), "Per construction. Else report the other loader.");
2173 } else {
2174 return;
2175 }
2176 }
2177
2178 #ifdef ASSERT
2179 Symbol* ph_check = find_placeholder(name, loader_data);
2180 assert(ph_check == NULL || ph_check == name, "invalid symbol");
2181 #endif
2182
2183 if (linkage_error1 == NULL) {
2184 if (constraints()->check_or_update(k, class_loader, name) == false) {
2185 linkage_error1 = "loader constraint violation: loader ";
2186 linkage_error2 = " wants to load class ";
2187 linkage_error3 = ". A different class with the same name was previously loaded by ";
2188 Klass *existing_klass = constraints()->find_constrained_klass(name, class_loader);
2189 if (existing_klass->class_loader() != class_loader()) {
2190 existing_klass_loader_name =
2191 java_lang_ClassLoader::describe_external(existing_klass->class_loader());
2192 }
2193 }
2194 }
2195 }
2196
2197 // Throw error now if needed (cannot throw while holding
2198 // SystemDictionary_lock because of rank ordering)
2199
2200 if (linkage_error1) {
2201 ResourceMark rm(THREAD);
2202 stringStream ss;
2203 ss.print("%s", linkage_error1);
2204 ss.print("%s", java_lang_ClassLoader::describe_external(class_loader()));
2205 ss.print("%s", linkage_error2);
2206 ss.print("%s", k->external_name());
2207 ss.print("%s", linkage_error3);
2208 ss.print("%s", existing_klass_loader_name);
2209 ss.print(".");
2210 THROW_MSG(vmSymbols::java_lang_LinkageError(), ss.as_string());
2211 }
2212 }
2213
2214 // Update class loader data dictionary - done after check_constraint and add_to_hierachy
2215 // have been called.
2216 void SystemDictionary::update_dictionary(unsigned int d_hash,
2217 int p_index, unsigned int p_hash,
2218 InstanceKlass* k,
2219 Handle class_loader,
2220 TRAPS) {
2221 // Compile_lock prevents systemDictionary updates during compilations
2222 assert_locked_or_safepoint(Compile_lock);
2223 Symbol* name = k->name();
2224 ClassLoaderData *loader_data = class_loader_data(class_loader);
2225
2226 {
2227 MutexLocker mu1(SystemDictionary_lock, THREAD);
2228
2229 // See whether biased locking is enabled and if so set it for this
2230 // klass.
2231 // Note that this must be done past the last potential blocking
2232 // point / safepoint. We enable biased locking lazily using a
2233 // VM_Operation to iterate the SystemDictionary and installing the
3089 // Combining platform and system loader dictionaries into boot loader dictionary.
3090 // During run time, we only have one shared dictionary.
3091 void SystemDictionary::combine_shared_dictionaries() {
3092 assert(DumpSharedSpaces, "dump time only");
3093 // If AppCDS isn't enabled, we only dump the classes in the boot loader dictionary
3094 // into the shared archive.
3095 if (UseAppCDS) {
3096 Dictionary* master_dictionary = ClassLoaderData::the_null_class_loader_data()->dictionary();
3097 CombineDictionariesClosure cdc(master_dictionary);
3098 ClassLoaderDataGraph::cld_do(&cdc);
3099 }
3100
3101 // These tables are no longer valid or necessary. Keeping them around will
3102 // cause SystemDictionary::verify() to fail. Let's empty them.
3103 _placeholders = new PlaceholderTable(_placeholder_table_size);
3104 _loader_constraints = new LoaderConstraintTable(_loader_constraint_size);
3105
3106 NOT_PRODUCT(SystemDictionary::verify());
3107 }
3108
3109 // Return string to give helpful intformation about a classloader.
3110 // Caller needs ResourceMark.
3111 const char* SystemDictionary::loader_name(const oop loader) {
3112 #if INCLUDE_CDS
3113 if (DumpSharedSpaces) {
3114 // Describe_external() calls assert(is_instance...) in various places,
3115 // which may fail with DumpSharedSpaces.
3116 if ((loader) == NULL) return "<bootloader>";
3117 return InstanceKlass::cast((loader)->klass())->name()->as_C_string();
3118 }
3119 #endif
3120 return java_lang_ClassLoader::describe_external(loader);
3121 }
3122
3123 // caller needs ResourceMark
3124 const char* SystemDictionary::loader_name(const ClassLoaderData* loader_data) {
3125 return (loader_data->class_loader() == NULL ? "<bootloader>" :
3126 SystemDictionary::loader_name(loader_data->class_loader()));
3127 }
|