< prev index next >

src/share/vm/classfile/systemDictionary.cpp

Print this page




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


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


 794       // Should not get here for classloaders that support parallelism
 795       // with the new cleaner mechanism, even with AllowParallelDefineClass
 796       // Bootstrap goes through here to allow for an extra guarantee check
 797       if (UnsyncloadClass || (class_loader.is_null())) {
 798         if (k.is_null() && HAS_PENDING_EXCEPTION
 799           && PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
 800           MutexLocker mu(SystemDictionary_lock, THREAD);
 801           Klass* check = find_class(d_index, d_hash, name, loader_data);
 802           if (check != NULL) {
 803             // Klass is already loaded, so just use it
 804             k = instanceKlassHandle(THREAD, check);
 805             CLEAR_PENDING_EXCEPTION;
 806             guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?");
 807           }
 808         }
 809       }
 810 
 811       // If everything was OK (no exceptions, no null return value), and
 812       // class_loader is NOT the defining loader, do a little more bookkeeping.
 813       if (!HAS_PENDING_EXCEPTION && !k.is_null() &&
 814         k->class_loader() != class_loader()) {
 815 
 816         check_constraints(d_index, d_hash, k, class_loader, false, THREAD);
 817 
 818         // Need to check for a PENDING_EXCEPTION again; check_constraints
 819         // can throw but we may have to remove entry from the placeholder table below.
 820         if (!HAS_PENDING_EXCEPTION) {
 821           // Record dependency for non-parent delegation.
 822           // This recording keeps the defining class loader of the klass (k) found
 823           // from being unloaded while the initiating class loader is loaded
 824           // even if the reference to the defining class loader is dropped
 825           // before references to the initiating class loader.
 826           loader_data->record_dependency(k(), THREAD);
 827         }
 828 
 829         if (!HAS_PENDING_EXCEPTION) {
 830           { // Grabbing the Compile_lock prevents systemDictionary updates
 831             // during compilations.
 832             MutexLocker mu(Compile_lock, THREAD);
 833             update_dictionary(d_index, d_hash, p_index, p_hash,
 834                               k, class_loader, THREAD);




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


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


 794       // Should not get here for classloaders that support parallelism
 795       // with the new cleaner mechanism, even with AllowParallelDefineClass
 796       // Bootstrap goes through here to allow for an extra guarantee check
 797       if (UnsyncloadClass || (class_loader.is_null())) {
 798         if (k.is_null() && HAS_PENDING_EXCEPTION
 799           && PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
 800           MutexLocker mu(SystemDictionary_lock, THREAD);
 801           Klass* check = find_class(d_index, d_hash, name, loader_data);
 802           if (check != NULL) {
 803             // Klass is already loaded, so just use it
 804             k = instanceKlassHandle(THREAD, check);
 805             CLEAR_PENDING_EXCEPTION;
 806             guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?");
 807           }
 808         }
 809       }
 810 
 811       // If everything was OK (no exceptions, no null return value), and
 812       // class_loader is NOT the defining loader, do a little more bookkeeping.
 813       if (!HAS_PENDING_EXCEPTION && !k.is_null() &&
 814           k->class_loader() != class_loader()) {
 815 
 816         check_constraints(d_index, d_hash, k, class_loader, false, THREAD);
 817 
 818         // Need to check for a PENDING_EXCEPTION again; check_constraints
 819         // can throw but we may have to remove entry from the placeholder table below.
 820         if (!HAS_PENDING_EXCEPTION) {
 821           // Record dependency for non-parent delegation.
 822           // This recording keeps the defining class loader of the klass (k) found
 823           // from being unloaded while the initiating class loader is loaded
 824           // even if the reference to the defining class loader is dropped
 825           // before references to the initiating class loader.
 826           loader_data->record_dependency(k(), THREAD);
 827         }
 828 
 829         if (!HAS_PENDING_EXCEPTION) {
 830           { // Grabbing the Compile_lock prevents systemDictionary updates
 831             // during compilations.
 832             MutexLocker mu(Compile_lock, THREAD);
 833             update_dictionary(d_index, d_hash, p_index, p_hash,
 834                               k, class_loader, THREAD);


< prev index next >