741 uint loop_count = 0; |
741 uint loop_count = 0; |
742 uint gc_count = 0; |
742 uint gc_count = 0; |
743 uint full_gc_count = 0; |
743 uint full_gc_count = 0; |
744 |
744 |
745 do { |
745 do { |
|
746 MetaWord* result = NULL; |
|
747 if (GC_locker::is_active_and_needs_gc()) { |
|
748 // If the GC_locker is active, just expand and allocate. |
|
749 // If that does not succeed, wait if this thread is not |
|
750 // in a critical section itself. |
|
751 result = |
|
752 loader_data->metaspace_non_null()->expand_and_allocate(word_size, |
|
753 mdtype); |
|
754 if (result != NULL) { |
|
755 return result; |
|
756 } |
|
757 JavaThread* jthr = JavaThread::current(); |
|
758 if (!jthr->in_critical()) { |
|
759 MutexUnlocker mul(Heap_lock); |
|
760 // Wait for JNI critical section to be exited |
|
761 GC_locker::stall_until_clear(); |
|
762 // The GC invoked by the last thread leaving the critical |
|
763 // section will be a young collection and a full collection |
|
764 // is (currently) needed for unloading classes so continue |
|
765 // to the next iteration to get a full GC. |
|
766 continue; |
|
767 } else { |
|
768 if (CheckJNICalls) { |
|
769 fatal("Possible deadlock due to allocating while" |
|
770 " in jni critical section"); |
|
771 } |
|
772 return NULL; |
|
773 } |
|
774 } |
|
775 |
746 { // Need lock to get self consistent gc_count's |
776 { // Need lock to get self consistent gc_count's |
747 MutexLocker ml(Heap_lock); |
777 MutexLocker ml(Heap_lock); |
748 gc_count = Universe::heap()->total_collections(); |
778 gc_count = Universe::heap()->total_collections(); |
749 full_gc_count = Universe::heap()->total_full_collections(); |
779 full_gc_count = Universe::heap()->total_full_collections(); |
750 } |
780 } |