< prev index next >

src/share/vm/classfile/systemDictionary.cpp

Print this page




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


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


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




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


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


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


< prev index next >