< prev index next >

src/share/vm/classfile/systemDictionary.cpp

Print this page
rev 11945 : 8023697: failed class resolution reports different class name in detail message for the first and subsequent times
Summary: Cache detail message when we cache exception for constant pool resolution.
Reviewed-by: acorn, twisti, jrose
rev 11952 : Merge jdk8u272-b02


 168 /**
 169  * Returns true if the passed class loader is the extension class loader.
 170  */
 171 bool SystemDictionary::is_ext_class_loader(Handle class_loader) {
 172   if (class_loader.is_null()) {
 173     return false;
 174   }
 175   return (class_loader->klass()->name() == vmSymbols::sun_misc_Launcher_ExtClassLoader());
 176 }
 177 
 178 // ----------------------------------------------------------------------------
 179 // Resolving of classes
 180 
 181 // Forwards to resolve_or_null
 182 
 183 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) {
 184   Klass* klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD);
 185   if (HAS_PENDING_EXCEPTION || klass == NULL) {
 186     KlassHandle k_h(THREAD, klass);
 187     // can return a null klass
 188     klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
 189   }
 190   return klass;
 191 }
 192 
 193 Klass* SystemDictionary::handle_resolution_exception(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS) {


 194   if (HAS_PENDING_EXCEPTION) {
 195     // If we have a pending exception we forward it to the caller, unless throw_error is true,
 196     // in which case we have to check whether the pending exception is a ClassNotFoundException,
 197     // and if so convert it to a NoClassDefFoundError
 198     // And chain the original ClassNotFoundException
 199     if (throw_error && PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass())) {
 200       ResourceMark rm(THREAD);
 201       assert(klass_h() == NULL, "Should not have result with exception pending");
 202       Handle e(THREAD, PENDING_EXCEPTION);
 203       CLEAR_PENDING_EXCEPTION;
 204       THROW_MSG_CAUSE_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string(), e);
 205     } else {
 206       return NULL;
 207     }
 208   }
 209   // Class not found, throw appropriate error or exception depending on value of throw_error
 210   if (klass_h() == NULL) {
 211     ResourceMark rm(THREAD);
 212     if (throw_error) {
 213       THROW_MSG_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string());


 381   Klass* superk = SystemDictionary::resolve_or_null(class_name,
 382                                                  class_loader,
 383                                                  protection_domain,
 384                                                  THREAD);
 385 
 386   KlassHandle superk_h(THREAD, superk);
 387 
 388   // Clean up of placeholders moved so that each classloadAction registrar self-cleans up
 389   // It is no longer necessary to keep the placeholder table alive until update_dictionary
 390   // or error. GC used to walk the placeholder table as strong roots.
 391   // The instanceKlass is kept alive because the class loader is on the stack,
 392   // which keeps the loader_data alive, as well as all instanceKlasses in
 393   // the loader_data. parseClassFile adds the instanceKlass to loader_data.
 394   {
 395     MutexLocker mu(SystemDictionary_lock, THREAD);
 396     placeholders()->find_and_remove(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD);
 397     SystemDictionary_lock->notify_all();
 398   }
 399   if (HAS_PENDING_EXCEPTION || superk_h() == NULL) {
 400     // can null superk
 401     superk_h = KlassHandle(THREAD, handle_resolution_exception(class_name, class_loader, protection_domain, true, superk_h, THREAD));
 402   }
 403 
 404   return superk_h();
 405 }
 406 
 407 void SystemDictionary::validate_protection_domain(instanceKlassHandle klass,
 408                                                   Handle class_loader,
 409                                                   Handle protection_domain,
 410                                                   TRAPS) {
 411   if(!has_checkPackageAccess()) return;
 412 
 413   // Now we have to call back to java to check if the initating class has access
 414   JavaValue result(T_VOID);
 415   if (TraceProtectionDomainVerification) {
 416     // Print out trace information
 417     tty->print_cr("Checking package access");
 418     tty->print(" - class loader:      "); class_loader()->print_value_on(tty);      tty->cr();
 419     tty->print(" - protection domain: "); protection_domain()->print_value_on(tty); tty->cr();
 420     tty->print(" - loading:           "); klass()->print_value_on(tty);             tty->cr();
 421   }


2229   unsigned int d_hash1 = dictionary()->compute_hash(constraint_name, loader_data1);
2230   int d_index1 = dictionary()->hash_to_index(d_hash1);
2231 
2232   unsigned int d_hash2 = dictionary()->compute_hash(constraint_name, loader_data2);
2233   int d_index2 = dictionary()->hash_to_index(d_hash2);
2234   {
2235   MutexLocker mu_s(SystemDictionary_lock, THREAD);
2236 
2237   // Better never do a GC while we're holding these oops
2238   No_Safepoint_Verifier nosafepoint;
2239 
2240   Klass* klass1 = find_class(d_index1, d_hash1, constraint_name, loader_data1);
2241   Klass* klass2 = find_class(d_index2, d_hash2, constraint_name, loader_data2);
2242   return constraints()->add_entry(constraint_name, klass1, class_loader1,
2243                                   klass2, class_loader2);
2244   }
2245 }
2246 
2247 // Add entry to resolution error table to record the error when the first
2248 // attempt to resolve a reference to a class has failed.
2249 void SystemDictionary::add_resolution_error(constantPoolHandle pool, int which, Symbol* error) {

2250   unsigned int hash = resolution_errors()->compute_hash(pool, which);
2251   int index = resolution_errors()->hash_to_index(hash);
2252   {
2253     MutexLocker ml(SystemDictionary_lock, Thread::current());
2254     resolution_errors()->add_entry(index, hash, pool, which, error);
2255   }
2256 }
2257 
2258 // Delete a resolution error for RedefineClasses for a constant pool is going away
2259 void SystemDictionary::delete_resolution_error(ConstantPool* pool) {
2260   resolution_errors()->delete_entry(pool);
2261 }
2262 
2263 // Lookup resolution error table. Returns error if found, otherwise NULL.
2264 Symbol* SystemDictionary::find_resolution_error(constantPoolHandle pool, int which) {

2265   unsigned int hash = resolution_errors()->compute_hash(pool, which);
2266   int index = resolution_errors()->hash_to_index(hash);
2267   {
2268     MutexLocker ml(SystemDictionary_lock, Thread::current());
2269     ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
2270     return (entry != NULL) ? entry->error() : (Symbol*)NULL;





2271   }
2272 }
2273 
2274 
2275 // Signature constraints ensure that callers and callees agree about
2276 // the meaning of type names in their signatures.  This routine is the
2277 // intake for constraints.  It collects them from several places:
2278 //
2279 //  * LinkResolver::resolve_method (if check_access is true) requires
2280 //    that the resolving class (the caller) and the defining class of
2281 //    the resolved method (the callee) agree on each type in the
2282 //    method's signature.
2283 //
2284 //  * LinkResolver::resolve_interface_method performs exactly the same
2285 //    checks.
2286 //
2287 //  * LinkResolver::resolve_field requires that the constant pool
2288 //    attempting to link to a field agree with the field's defining
2289 //    class about the type of the field signature.
2290 //




 168 /**
 169  * Returns true if the passed class loader is the extension class loader.
 170  */
 171 bool SystemDictionary::is_ext_class_loader(Handle class_loader) {
 172   if (class_loader.is_null()) {
 173     return false;
 174   }
 175   return (class_loader->klass()->name() == vmSymbols::sun_misc_Launcher_ExtClassLoader());
 176 }
 177 
 178 // ----------------------------------------------------------------------------
 179 // Resolving of classes
 180 
 181 // Forwards to resolve_or_null
 182 
 183 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) {
 184   Klass* klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD);
 185   if (HAS_PENDING_EXCEPTION || klass == NULL) {
 186     KlassHandle k_h(THREAD, klass);
 187     // can return a null klass
 188     klass = handle_resolution_exception(class_name, throw_error, k_h, THREAD);
 189   }
 190   return klass;
 191 }
 192 
 193 Klass* SystemDictionary::handle_resolution_exception(Symbol* class_name,
 194                                                      bool throw_error,
 195                                                      KlassHandle klass_h, TRAPS) {
 196   if (HAS_PENDING_EXCEPTION) {
 197     // If we have a pending exception we forward it to the caller, unless throw_error is true,
 198     // in which case we have to check whether the pending exception is a ClassNotFoundException,
 199     // and if so convert it to a NoClassDefFoundError
 200     // And chain the original ClassNotFoundException
 201     if (throw_error && PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass())) {
 202       ResourceMark rm(THREAD);
 203       assert(klass_h() == NULL, "Should not have result with exception pending");
 204       Handle e(THREAD, PENDING_EXCEPTION);
 205       CLEAR_PENDING_EXCEPTION;
 206       THROW_MSG_CAUSE_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string(), e);
 207     } else {
 208       return NULL;
 209     }
 210   }
 211   // Class not found, throw appropriate error or exception depending on value of throw_error
 212   if (klass_h() == NULL) {
 213     ResourceMark rm(THREAD);
 214     if (throw_error) {
 215       THROW_MSG_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string());


 383   Klass* superk = SystemDictionary::resolve_or_null(class_name,
 384                                                  class_loader,
 385                                                  protection_domain,
 386                                                  THREAD);
 387 
 388   KlassHandle superk_h(THREAD, superk);
 389 
 390   // Clean up of placeholders moved so that each classloadAction registrar self-cleans up
 391   // It is no longer necessary to keep the placeholder table alive until update_dictionary
 392   // or error. GC used to walk the placeholder table as strong roots.
 393   // The instanceKlass is kept alive because the class loader is on the stack,
 394   // which keeps the loader_data alive, as well as all instanceKlasses in
 395   // the loader_data. parseClassFile adds the instanceKlass to loader_data.
 396   {
 397     MutexLocker mu(SystemDictionary_lock, THREAD);
 398     placeholders()->find_and_remove(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD);
 399     SystemDictionary_lock->notify_all();
 400   }
 401   if (HAS_PENDING_EXCEPTION || superk_h() == NULL) {
 402     // can null superk
 403     superk_h = KlassHandle(THREAD, handle_resolution_exception(class_name, true, superk_h, THREAD));
 404   }
 405 
 406   return superk_h();
 407 }
 408 
 409 void SystemDictionary::validate_protection_domain(instanceKlassHandle klass,
 410                                                   Handle class_loader,
 411                                                   Handle protection_domain,
 412                                                   TRAPS) {
 413   if(!has_checkPackageAccess()) return;
 414 
 415   // Now we have to call back to java to check if the initating class has access
 416   JavaValue result(T_VOID);
 417   if (TraceProtectionDomainVerification) {
 418     // Print out trace information
 419     tty->print_cr("Checking package access");
 420     tty->print(" - class loader:      "); class_loader()->print_value_on(tty);      tty->cr();
 421     tty->print(" - protection domain: "); protection_domain()->print_value_on(tty); tty->cr();
 422     tty->print(" - loading:           "); klass()->print_value_on(tty);             tty->cr();
 423   }


2231   unsigned int d_hash1 = dictionary()->compute_hash(constraint_name, loader_data1);
2232   int d_index1 = dictionary()->hash_to_index(d_hash1);
2233 
2234   unsigned int d_hash2 = dictionary()->compute_hash(constraint_name, loader_data2);
2235   int d_index2 = dictionary()->hash_to_index(d_hash2);
2236   {
2237   MutexLocker mu_s(SystemDictionary_lock, THREAD);
2238 
2239   // Better never do a GC while we're holding these oops
2240   No_Safepoint_Verifier nosafepoint;
2241 
2242   Klass* klass1 = find_class(d_index1, d_hash1, constraint_name, loader_data1);
2243   Klass* klass2 = find_class(d_index2, d_hash2, constraint_name, loader_data2);
2244   return constraints()->add_entry(constraint_name, klass1, class_loader1,
2245                                   klass2, class_loader2);
2246   }
2247 }
2248 
2249 // Add entry to resolution error table to record the error when the first
2250 // attempt to resolve a reference to a class has failed.
2251 void SystemDictionary::add_resolution_error(constantPoolHandle pool, int which,
2252                                             Symbol* error, Symbol* message) {
2253   unsigned int hash = resolution_errors()->compute_hash(pool, which);
2254   int index = resolution_errors()->hash_to_index(hash);
2255   {
2256     MutexLocker ml(SystemDictionary_lock, Thread::current());
2257     resolution_errors()->add_entry(index, hash, pool, which, error, message);
2258   }
2259 }
2260 
2261 // Delete a resolution error for RedefineClasses for a constant pool is going away
2262 void SystemDictionary::delete_resolution_error(ConstantPool* pool) {
2263   resolution_errors()->delete_entry(pool);
2264 }
2265 
2266 // Lookup resolution error table. Returns error if found, otherwise NULL.
2267 Symbol* SystemDictionary::find_resolution_error(constantPoolHandle pool, int which,
2268                                                 Symbol** message) {
2269   unsigned int hash = resolution_errors()->compute_hash(pool, which);
2270   int index = resolution_errors()->hash_to_index(hash);
2271   {
2272     MutexLocker ml(SystemDictionary_lock, Thread::current());
2273     ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
2274     if (entry != NULL) {
2275       *message = entry->message();
2276       return entry->error();
2277     } else {
2278       return NULL;
2279     }
2280   }
2281 }
2282 
2283 
2284 // Signature constraints ensure that callers and callees agree about
2285 // the meaning of type names in their signatures.  This routine is the
2286 // intake for constraints.  It collects them from several places:
2287 //
2288 //  * LinkResolver::resolve_method (if check_access is true) requires
2289 //    that the resolving class (the caller) and the defining class of
2290 //    the resolved method (the callee) agree on each type in the
2291 //    method's signature.
2292 //
2293 //  * LinkResolver::resolve_interface_method performs exactly the same
2294 //    checks.
2295 //
2296 //  * LinkResolver::resolve_field requires that the constant pool
2297 //    attempting to link to a field agree with the field's defining
2298 //    class about the type of the field signature.
2299 //


< prev index next >