481 // so another thread got here in parallel
482 //
483 // lockObject must be held.
484 // Complicated dance due to lock ordering:
485 // Must first release the classloader object lock to
486 // allow initial definer to complete the class definition
487 // and to avoid deadlock
488 // Reclaim classloader lock object with same original recursion count
489 // Must release SystemDictionary_lock after notify, since
490 // class loader lock must be claimed before SystemDictionary_lock
491 // to prevent deadlocks
492 //
493 // The notify allows applications that did an untimed wait() on
494 // the classloader object lock to not hang.
495 void SystemDictionary::double_lock_wait(Handle lockObject, TRAPS) {
496 assert_lock_strong(SystemDictionary_lock);
497
498 bool calledholdinglock
499 = ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, lockObject);
500 assert(calledholdinglock,"must hold lock for notify");
501 assert((!(lockObject() == _system_loader_lock_obj) && !is_parallelCapable(lockObject)), "unexpected double_lock_wait");
502 ObjectSynchronizer::notifyall(lockObject, THREAD);
503 intptr_t recursions = ObjectSynchronizer::complete_exit(lockObject, THREAD);
504 SystemDictionary_lock->wait();
505 SystemDictionary_lock->unlock();
506 ObjectSynchronizer::reenter(lockObject, recursions, THREAD);
507 SystemDictionary_lock->lock();
508 }
509
510 // If the class in is in the placeholder table, class loading is in progress
511 // For cases where the application changes threads to load classes, it
512 // is critical to ClassCircularity detection that we try loading
513 // the superclass on the same thread internally, so we do parallel
514 // super class loading here.
515 // This also is critical in cases where the original thread gets stalled
516 // even in non-circularity situations.
517 // Note: must call resolve_super_or_fail even if null super -
518 // to force placeholder entry creation for this class for circularity detection
519 // Caller must check for pending exception
520 // Returns non-null Klass* if other thread has completed load
521 // and we are done,
1514 CLEAR_PENDING_EXCEPTION;
1515 } else {
1516 probe->set_instance_klass(k());
1517 }
1518 probe->set_definer(NULL);
1519 placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD);
1520 SystemDictionary_lock->notify_all();
1521 }
1522 }
1523
1524 // Can't throw exception while holding lock due to rank ordering
1525 if (linkage_exception() != NULL) {
1526 THROW_OOP_(linkage_exception(), nh); // throws exception and returns
1527 }
1528
1529 return k;
1530 }
1531 Handle SystemDictionary::compute_loader_lock_object(Handle class_loader, TRAPS) {
1532 // If class_loader is NULL we synchronize on _system_loader_lock_obj
1533 if (class_loader.is_null()) {
1534 return Handle(THREAD, _system_loader_lock_obj);
1535 } else {
1536 return class_loader;
1537 }
1538 }
1539
1540 // This method is added to check how often we have to wait to grab loader
1541 // lock. The results are being recorded in the performance counters defined in
1542 // ClassLoader::_sync_systemLoaderLockContentionRate and
1543 // ClassLoader::_sync_nonSystemLoaderLockConteionRate.
1544 void SystemDictionary::check_loader_lock_contention(Handle loader_lock, TRAPS) {
1545 if (!UsePerfData) {
1546 return;
1547 }
1548
1549 assert(!loader_lock.is_null(), "NULL lock object");
1550
1551 if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader_lock)
1552 == ObjectSynchronizer::owner_other) {
1553 // contention will likely happen, so increment the corresponding
1554 // contention counter.
1555 if (loader_lock() == _system_loader_lock_obj) {
1556 ClassLoader::sync_systemLoaderLockContentionRate()->inc();
1557 } else {
1558 ClassLoader::sync_nonSystemLoaderLockContentionRate()->inc();
1559 }
1560 }
1561 }
1562
1563 // ----------------------------------------------------------------------------
1564 // Lookup
1565
1566 Klass* SystemDictionary::find_class(int index, unsigned int hash,
1567 Symbol* class_name,
1568 ClassLoaderData* loader_data) {
1569 assert_locked_or_safepoint(SystemDictionary_lock);
1570 assert (index == dictionary()->index_for(class_name, loader_data),
1571 "incorrect index?");
1572
1573 Klass* k = dictionary()->find_class(index, hash, class_name, loader_data);
1574 return k;
1575 }
2662
2663 // utility function for class load event
2664 void SystemDictionary::post_class_load_event(const Ticks& start_time,
2665 instanceKlassHandle k,
2666 Handle initiating_loader) {
2667 #if INCLUDE_TRACE
2668 EventClassLoad event(UNTIMED);
2669 if (event.should_commit()) {
2670 event.set_starttime(start_time);
2671 event.set_loadedClass(k());
2672 oop defining_class_loader = k->class_loader();
2673 event.set_definingClassLoader(defining_class_loader != NULL ?
2674 defining_class_loader->klass() : (Klass*)NULL);
2675 oop class_loader = initiating_loader.is_null() ? (oop)NULL : initiating_loader();
2676 event.set_initiatingClassLoader(class_loader != NULL ?
2677 class_loader->klass() : (Klass*)NULL);
2678 event.commit();
2679 }
2680 #endif // INCLUDE_TRACE
2681 }
2682
|
481 // so another thread got here in parallel
482 //
483 // lockObject must be held.
484 // Complicated dance due to lock ordering:
485 // Must first release the classloader object lock to
486 // allow initial definer to complete the class definition
487 // and to avoid deadlock
488 // Reclaim classloader lock object with same original recursion count
489 // Must release SystemDictionary_lock after notify, since
490 // class loader lock must be claimed before SystemDictionary_lock
491 // to prevent deadlocks
492 //
493 // The notify allows applications that did an untimed wait() on
494 // the classloader object lock to not hang.
495 void SystemDictionary::double_lock_wait(Handle lockObject, TRAPS) {
496 assert_lock_strong(SystemDictionary_lock);
497
498 bool calledholdinglock
499 = ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, lockObject);
500 assert(calledholdinglock,"must hold lock for notify");
501 assert((!(oopDesc::bs()->write_barrier(lockObject()) == oopDesc::bs()->write_barrier(_system_loader_lock_obj)) && !is_parallelCapable(lockObject)), "unexpected double_lock_wait");
502 ObjectSynchronizer::notifyall(lockObject, THREAD);
503 intptr_t recursions = ObjectSynchronizer::complete_exit(lockObject, THREAD);
504 SystemDictionary_lock->wait();
505 SystemDictionary_lock->unlock();
506 ObjectSynchronizer::reenter(lockObject, recursions, THREAD);
507 SystemDictionary_lock->lock();
508 }
509
510 // If the class in is in the placeholder table, class loading is in progress
511 // For cases where the application changes threads to load classes, it
512 // is critical to ClassCircularity detection that we try loading
513 // the superclass on the same thread internally, so we do parallel
514 // super class loading here.
515 // This also is critical in cases where the original thread gets stalled
516 // even in non-circularity situations.
517 // Note: must call resolve_super_or_fail even if null super -
518 // to force placeholder entry creation for this class for circularity detection
519 // Caller must check for pending exception
520 // Returns non-null Klass* if other thread has completed load
521 // and we are done,
1514 CLEAR_PENDING_EXCEPTION;
1515 } else {
1516 probe->set_instance_klass(k());
1517 }
1518 probe->set_definer(NULL);
1519 placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD);
1520 SystemDictionary_lock->notify_all();
1521 }
1522 }
1523
1524 // Can't throw exception while holding lock due to rank ordering
1525 if (linkage_exception() != NULL) {
1526 THROW_OOP_(linkage_exception(), nh); // throws exception and returns
1527 }
1528
1529 return k;
1530 }
1531 Handle SystemDictionary::compute_loader_lock_object(Handle class_loader, TRAPS) {
1532 // If class_loader is NULL we synchronize on _system_loader_lock_obj
1533 if (class_loader.is_null()) {
1534 return Handle(THREAD, oopDesc::bs()->write_barrier(_system_loader_lock_obj));
1535 } else {
1536 return Handle(THREAD, oopDesc::bs()->write_barrier(class_loader()));
1537 }
1538 }
1539
1540 // This method is added to check how often we have to wait to grab loader
1541 // lock. The results are being recorded in the performance counters defined in
1542 // ClassLoader::_sync_systemLoaderLockContentionRate and
1543 // ClassLoader::_sync_nonSystemLoaderLockConteionRate.
1544 void SystemDictionary::check_loader_lock_contention(Handle loader_lock, TRAPS) {
1545 if (!UsePerfData) {
1546 return;
1547 }
1548
1549 assert(!loader_lock.is_null(), "NULL lock object");
1550
1551 if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader_lock)
1552 == ObjectSynchronizer::owner_other) {
1553 // contention will likely happen, so increment the corresponding
1554 // contention counter.
1555 if (oopDesc::bs()->write_barrier(loader_lock()) == oopDesc::bs()->write_barrier(_system_loader_lock_obj)) {
1556 ClassLoader::sync_systemLoaderLockContentionRate()->inc();
1557 } else {
1558 ClassLoader::sync_nonSystemLoaderLockContentionRate()->inc();
1559 }
1560 }
1561 }
1562
1563 // ----------------------------------------------------------------------------
1564 // Lookup
1565
1566 Klass* SystemDictionary::find_class(int index, unsigned int hash,
1567 Symbol* class_name,
1568 ClassLoaderData* loader_data) {
1569 assert_locked_or_safepoint(SystemDictionary_lock);
1570 assert (index == dictionary()->index_for(class_name, loader_data),
1571 "incorrect index?");
1572
1573 Klass* k = dictionary()->find_class(index, hash, class_name, loader_data);
1574 return k;
1575 }
2662
2663 // utility function for class load event
2664 void SystemDictionary::post_class_load_event(const Ticks& start_time,
2665 instanceKlassHandle k,
2666 Handle initiating_loader) {
2667 #if INCLUDE_TRACE
2668 EventClassLoad event(UNTIMED);
2669 if (event.should_commit()) {
2670 event.set_starttime(start_time);
2671 event.set_loadedClass(k());
2672 oop defining_class_loader = k->class_loader();
2673 event.set_definingClassLoader(defining_class_loader != NULL ?
2674 defining_class_loader->klass() : (Klass*)NULL);
2675 oop class_loader = initiating_loader.is_null() ? (oop)NULL : initiating_loader();
2676 event.set_initiatingClassLoader(class_loader != NULL ?
2677 class_loader->klass() : (Klass*)NULL);
2678 event.commit();
2679 }
2680 #endif // INCLUDE_TRACE
2681 }
|