src/hotspot/share/gc/shared/collectedHeap.cpp
changeset 49045 9b556b613a07
parent 48961 120b61d50f85
child 49361 1956d0ec092a
equal deleted inserted replaced
49044:b01b69c220be 49045:9b556b613a07
    26 #include "classfile/systemDictionary.hpp"
    26 #include "classfile/systemDictionary.hpp"
    27 #include "gc/shared/allocTracer.hpp"
    27 #include "gc/shared/allocTracer.hpp"
    28 #include "gc/shared/barrierSet.inline.hpp"
    28 #include "gc/shared/barrierSet.inline.hpp"
    29 #include "gc/shared/collectedHeap.hpp"
    29 #include "gc/shared/collectedHeap.hpp"
    30 #include "gc/shared/collectedHeap.inline.hpp"
    30 #include "gc/shared/collectedHeap.inline.hpp"
       
    31 #include "gc/shared/gcLocker.inline.hpp"
    31 #include "gc/shared/gcHeapSummary.hpp"
    32 #include "gc/shared/gcHeapSummary.hpp"
    32 #include "gc/shared/gcTrace.hpp"
    33 #include "gc/shared/gcTrace.hpp"
    33 #include "gc/shared/gcTraceTime.inline.hpp"
    34 #include "gc/shared/gcTraceTime.inline.hpp"
    34 #include "gc/shared/gcWhen.hpp"
    35 #include "gc/shared/gcWhen.hpp"
    35 #include "gc/shared/vmGCOperations.hpp"
    36 #include "gc/shared/vmGCOperations.hpp"
    39 #include "oops/instanceMirrorKlass.hpp"
    40 #include "oops/instanceMirrorKlass.hpp"
    40 #include "oops/oop.inline.hpp"
    41 #include "oops/oop.inline.hpp"
    41 #include "runtime/init.hpp"
    42 #include "runtime/init.hpp"
    42 #include "runtime/thread.inline.hpp"
    43 #include "runtime/thread.inline.hpp"
    43 #include "runtime/threadSMR.hpp"
    44 #include "runtime/threadSMR.hpp"
       
    45 #include "runtime/vmThread.hpp"
    44 #include "services/heapDumper.hpp"
    46 #include "services/heapDumper.hpp"
    45 #include "utilities/align.hpp"
    47 #include "utilities/align.hpp"
    46 
    48 
       
    49 class ClassLoaderData;
    47 
    50 
    48 #ifdef ASSERT
    51 #ifdef ASSERT
    49 int CollectedHeap::_fire_out_of_memory_count = 0;
    52 int CollectedHeap::_fire_out_of_memory_count = 0;
    50 #endif
    53 #endif
    51 
    54 
   229       break;
   232       break;
   230     }
   233     }
   231     default:
   234     default:
   232       ShouldNotReachHere(); // Unexpected use of this function
   235       ShouldNotReachHere(); // Unexpected use of this function
   233   }
   236   }
       
   237 }
       
   238 
       
   239 MetaWord* CollectedHeap::satisfy_failed_metadata_allocation(ClassLoaderData* loader_data,
       
   240                                                             size_t word_size,
       
   241                                                             Metaspace::MetadataType mdtype) {
       
   242   uint loop_count = 0;
       
   243   uint gc_count = 0;
       
   244   uint full_gc_count = 0;
       
   245 
       
   246   assert(!Heap_lock->owned_by_self(), "Should not be holding the Heap_lock");
       
   247 
       
   248   do {
       
   249     MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
       
   250     if (result != NULL) {
       
   251       return result;
       
   252     }
       
   253 
       
   254     if (GCLocker::is_active_and_needs_gc()) {
       
   255       // If the GCLocker is active, just expand and allocate.
       
   256       // If that does not succeed, wait if this thread is not
       
   257       // in a critical section itself.
       
   258       result = loader_data->metaspace_non_null()->expand_and_allocate(word_size, mdtype);
       
   259       if (result != NULL) {
       
   260         return result;
       
   261       }
       
   262       JavaThread* jthr = JavaThread::current();
       
   263       if (!jthr->in_critical()) {
       
   264         // Wait for JNI critical section to be exited
       
   265         GCLocker::stall_until_clear();
       
   266         // The GC invoked by the last thread leaving the critical
       
   267         // section will be a young collection and a full collection
       
   268         // is (currently) needed for unloading classes so continue
       
   269         // to the next iteration to get a full GC.
       
   270         continue;
       
   271       } else {
       
   272         if (CheckJNICalls) {
       
   273           fatal("Possible deadlock due to allocating while"
       
   274                 " in jni critical section");
       
   275         }
       
   276         return NULL;
       
   277       }
       
   278     }
       
   279 
       
   280     {  // Need lock to get self consistent gc_count's
       
   281       MutexLocker ml(Heap_lock);
       
   282       gc_count      = Universe::heap()->total_collections();
       
   283       full_gc_count = Universe::heap()->total_full_collections();
       
   284     }
       
   285 
       
   286     // Generate a VM operation
       
   287     VM_CollectForMetadataAllocation op(loader_data,
       
   288                                        word_size,
       
   289                                        mdtype,
       
   290                                        gc_count,
       
   291                                        full_gc_count,
       
   292                                        GCCause::_metadata_GC_threshold);
       
   293     VMThread::execute(&op);
       
   294 
       
   295     // If GC was locked out, try again. Check before checking success because the
       
   296     // prologue could have succeeded and the GC still have been locked out.
       
   297     if (op.gc_locked()) {
       
   298       continue;
       
   299     }
       
   300 
       
   301     if (op.prologue_succeeded()) {
       
   302       return op.result();
       
   303     }
       
   304     loop_count++;
       
   305     if ((QueuedAllocationWarningCount > 0) &&
       
   306         (loop_count % QueuedAllocationWarningCount == 0)) {
       
   307       log_warning(gc, ergo)("satisfy_failed_metadata_allocation() retries %d times,"
       
   308                             " size=" SIZE_FORMAT, loop_count, word_size);
       
   309     }
       
   310   } while (true);  // Until a GC is done
   234 }
   311 }
   235 
   312 
   236 void CollectedHeap::set_barrier_set(BarrierSet* barrier_set) {
   313 void CollectedHeap::set_barrier_set(BarrierSet* barrier_set) {
   237   _barrier_set = barrier_set;
   314   _barrier_set = barrier_set;
   238   BarrierSet::set_bs(barrier_set);
   315   BarrierSet::set_bs(barrier_set);