< prev index next >

src/share/vm/classfile/systemDictionary.cpp

Print this page




 341   int d_index = dictionary()->hash_to_index(d_hash);
 342   unsigned int p_hash = placeholders()->compute_hash(child_name, loader_data);
 343   int p_index = placeholders()->hash_to_index(p_hash);
 344   // can't throw error holding a lock
 345   bool child_already_loaded = false;
 346   bool throw_circularity_error = false;
 347   {
 348     MutexLocker mu(SystemDictionary_lock, THREAD);
 349     Klass* childk = find_class(d_index, d_hash, child_name, loader_data);
 350     Klass* quicksuperk;
 351     // to support // loading: if child done loading, just return superclass
 352     // if class_name, & class_loader don't match:
 353     // if initial define, SD update will give LinkageError
 354     // if redefine: compare_class_versions will give HIERARCHY_CHANGED
 355     // so we don't throw an exception here.
 356     // see: nsk redefclass014 & java.lang.instrument Instrument032
 357     if ((childk != NULL ) && (is_superclass) &&
 358        ((quicksuperk = InstanceKlass::cast(childk)->super()) != NULL) &&
 359 
 360          ((quicksuperk->name() == class_name) &&
 361             (quicksuperk->class_loader()  == class_loader()))) {
 362            return quicksuperk;
 363     } else {
 364       PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, loader_data);
 365       if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) {
 366           throw_circularity_error = true;
 367       }
 368     }
 369     if (!throw_circularity_error) {
 370       PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, class_name, THREAD);
 371     }
 372   }
 373   if (throw_circularity_error) {
 374       ResourceMark rm(THREAD);
 375       THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string());
 376   }
 377 
 378 // java.lang.Object should have been found above
 379   assert(class_name != NULL, "null super class for resolving");
 380   // Resolve the super class or interface, check results on return
 381   Klass* superk = SystemDictionary::resolve_or_null(class_name,


 482 //     so another thread got here in parallel
 483 //
 484 // lockObject must be held.
 485 // Complicated dance due to lock ordering:
 486 // Must first release the classloader object lock to
 487 // allow initial definer to complete the class definition
 488 // and to avoid deadlock
 489 // Reclaim classloader lock object with same original recursion count
 490 // Must release SystemDictionary_lock after notify, since
 491 // class loader lock must be claimed before SystemDictionary_lock
 492 // to prevent deadlocks
 493 //
 494 // The notify allows applications that did an untimed wait() on
 495 // the classloader object lock to not hang.
 496 void SystemDictionary::double_lock_wait(Handle lockObject, TRAPS) {
 497   assert_lock_strong(SystemDictionary_lock);
 498 
 499   bool calledholdinglock
 500       = ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, lockObject);
 501   assert(calledholdinglock,"must hold lock for notify");
 502   assert((!(lockObject() == _system_loader_lock_obj) && !is_parallelCapable(lockObject)), "unexpected double_lock_wait");
 503   ObjectSynchronizer::notifyall(lockObject, THREAD);
 504   intptr_t recursions =  ObjectSynchronizer::complete_exit(lockObject, THREAD);
 505   SystemDictionary_lock->wait();
 506   SystemDictionary_lock->unlock();
 507   ObjectSynchronizer::reenter(lockObject, recursions, THREAD);
 508   SystemDictionary_lock->lock();
 509 }
 510 
 511 // If the class in is in the placeholder table, class loading is in progress
 512 // For cases where the application changes threads to load classes, it
 513 // is critical to ClassCircularity detection that we try loading
 514 // the superclass on the same thread internally, so we do parallel
 515 // super class loading here.
 516 // This also is critical in cases where the original thread gets stalled
 517 // even in non-circularity situations.
 518 // Note: must call resolve_super_or_fail even if null super -
 519 // to force placeholder entry creation for this class for circularity detection
 520 // Caller must check for pending exception
 521 // Returns non-null Klass* if other thread has completed load
 522 // and we are done,


 815       // Should not get here for classloaders that support parallelism
 816       // with the new cleaner mechanism, even with AllowParallelDefineClass
 817       // Bootstrap goes through here to allow for an extra guarantee check
 818       if (UnsyncloadClass || (class_loader.is_null())) {
 819         if (k.is_null() && HAS_PENDING_EXCEPTION
 820           && PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
 821           MutexLocker mu(SystemDictionary_lock, THREAD);
 822           Klass* check = find_class(d_index, d_hash, name, loader_data);
 823           if (check != NULL) {
 824             // Klass is already loaded, so just use it
 825             k = instanceKlassHandle(THREAD, check);
 826             CLEAR_PENDING_EXCEPTION;
 827             guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?");
 828           }
 829         }
 830       }
 831 
 832       // If everything was OK (no exceptions, no null return value), and
 833       // class_loader is NOT the defining loader, do a little more bookkeeping.
 834       if (!HAS_PENDING_EXCEPTION && !k.is_null() &&
 835         k->class_loader() != class_loader()) {
 836 
 837         check_constraints(d_index, d_hash, k, class_loader, false, THREAD);
 838 
 839         // Need to check for a PENDING_EXCEPTION again; check_constraints
 840         // can throw but we may have to remove entry from the placeholder table below.
 841         if (!HAS_PENDING_EXCEPTION) {
 842           // Record dependency for non-parent delegation.
 843           // This recording keeps the defining class loader of the klass (k) found
 844           // from being unloaded while the initiating class loader is loaded
 845           // even if the reference to the defining class loader is dropped
 846           // before references to the initiating class loader.
 847           loader_data->record_dependency(k(), THREAD);
 848         }
 849 
 850         if (!HAS_PENDING_EXCEPTION) {
 851           { // Grabbing the Compile_lock prevents systemDictionary updates
 852             // during compilations.
 853             MutexLocker mu(Compile_lock, THREAD);
 854             update_dictionary(d_index, d_hash, p_index, p_hash,
 855                               k, class_loader, THREAD);




 341   int d_index = dictionary()->hash_to_index(d_hash);
 342   unsigned int p_hash = placeholders()->compute_hash(child_name, loader_data);
 343   int p_index = placeholders()->hash_to_index(p_hash);
 344   // can't throw error holding a lock
 345   bool child_already_loaded = false;
 346   bool throw_circularity_error = false;
 347   {
 348     MutexLocker mu(SystemDictionary_lock, THREAD);
 349     Klass* childk = find_class(d_index, d_hash, child_name, loader_data);
 350     Klass* quicksuperk;
 351     // to support // loading: if child done loading, just return superclass
 352     // if class_name, & class_loader don't match:
 353     // if initial define, SD update will give LinkageError
 354     // if redefine: compare_class_versions will give HIERARCHY_CHANGED
 355     // so we don't throw an exception here.
 356     // see: nsk redefclass014 & java.lang.instrument Instrument032
 357     if ((childk != NULL ) && (is_superclass) &&
 358        ((quicksuperk = InstanceKlass::cast(childk)->super()) != NULL) &&
 359 
 360          ((quicksuperk->name() == class_name) &&
 361           (quicksuperk->class_loader() == class_loader()))) {
 362            return quicksuperk;
 363     } else {
 364       PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, loader_data);
 365       if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) {
 366           throw_circularity_error = true;
 367       }
 368     }
 369     if (!throw_circularity_error) {
 370       PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, class_name, THREAD);
 371     }
 372   }
 373   if (throw_circularity_error) {
 374       ResourceMark rm(THREAD);
 375       THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string());
 376   }
 377 
 378 // java.lang.Object should have been found above
 379   assert(class_name != NULL, "null super class for resolving");
 380   // Resolve the super class or interface, check results on return
 381   Klass* superk = SystemDictionary::resolve_or_null(class_name,


 482 //     so another thread got here in parallel
 483 //
 484 // lockObject must be held.
 485 // Complicated dance due to lock ordering:
 486 // Must first release the classloader object lock to
 487 // allow initial definer to complete the class definition
 488 // and to avoid deadlock
 489 // Reclaim classloader lock object with same original recursion count
 490 // Must release SystemDictionary_lock after notify, since
 491 // class loader lock must be claimed before SystemDictionary_lock
 492 // to prevent deadlocks
 493 //
 494 // The notify allows applications that did an untimed wait() on
 495 // the classloader object lock to not hang.
 496 void SystemDictionary::double_lock_wait(Handle lockObject, TRAPS) {
 497   assert_lock_strong(SystemDictionary_lock);
 498 
 499   bool calledholdinglock
 500       = ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, lockObject);
 501   assert(calledholdinglock,"must hold lock for notify");
 502   assert((lockObject() != _system_loader_lock_obj && !is_parallelCapable(lockObject)), "unexpected double_lock_wait");
 503   ObjectSynchronizer::notifyall(lockObject, THREAD);
 504   intptr_t recursions =  ObjectSynchronizer::complete_exit(lockObject, THREAD);
 505   SystemDictionary_lock->wait();
 506   SystemDictionary_lock->unlock();
 507   ObjectSynchronizer::reenter(lockObject, recursions, THREAD);
 508   SystemDictionary_lock->lock();
 509 }
 510 
 511 // If the class in is in the placeholder table, class loading is in progress
 512 // For cases where the application changes threads to load classes, it
 513 // is critical to ClassCircularity detection that we try loading
 514 // the superclass on the same thread internally, so we do parallel
 515 // super class loading here.
 516 // This also is critical in cases where the original thread gets stalled
 517 // even in non-circularity situations.
 518 // Note: must call resolve_super_or_fail even if null super -
 519 // to force placeholder entry creation for this class for circularity detection
 520 // Caller must check for pending exception
 521 // Returns non-null Klass* if other thread has completed load
 522 // and we are done,


 815       // Should not get here for classloaders that support parallelism
 816       // with the new cleaner mechanism, even with AllowParallelDefineClass
 817       // Bootstrap goes through here to allow for an extra guarantee check
 818       if (UnsyncloadClass || (class_loader.is_null())) {
 819         if (k.is_null() && HAS_PENDING_EXCEPTION
 820           && PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
 821           MutexLocker mu(SystemDictionary_lock, THREAD);
 822           Klass* check = find_class(d_index, d_hash, name, loader_data);
 823           if (check != NULL) {
 824             // Klass is already loaded, so just use it
 825             k = instanceKlassHandle(THREAD, check);
 826             CLEAR_PENDING_EXCEPTION;
 827             guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?");
 828           }
 829         }
 830       }
 831 
 832       // If everything was OK (no exceptions, no null return value), and
 833       // class_loader is NOT the defining loader, do a little more bookkeeping.
 834       if (!HAS_PENDING_EXCEPTION && !k.is_null() &&
 835           k->class_loader() != class_loader()) {
 836 
 837         check_constraints(d_index, d_hash, k, class_loader, false, THREAD);
 838 
 839         // Need to check for a PENDING_EXCEPTION again; check_constraints
 840         // can throw but we may have to remove entry from the placeholder table below.
 841         if (!HAS_PENDING_EXCEPTION) {
 842           // Record dependency for non-parent delegation.
 843           // This recording keeps the defining class loader of the klass (k) found
 844           // from being unloaded while the initiating class loader is loaded
 845           // even if the reference to the defining class loader is dropped
 846           // before references to the initiating class loader.
 847           loader_data->record_dependency(k(), THREAD);
 848         }
 849 
 850         if (!HAS_PENDING_EXCEPTION) {
 851           { // Grabbing the Compile_lock prevents systemDictionary updates
 852             // during compilations.
 853             MutexLocker mu(Compile_lock, THREAD);
 854             update_dictionary(d_index, d_hash, p_index, p_hash,
 855                               k, class_loader, THREAD);


< prev index next >