hotspot/src/share/vm/gc/shared/collectorPolicy.cpp
changeset 35492 c8c0273e6b91
parent 35061 be6025ebffea
child 35521 3cb32806ed1d
equal deleted inserted replaced
35491:663c609dfeee 35492:c8c0273e6b91
   618       if (result != NULL) {
   618       if (result != NULL) {
   619         assert(gch->is_in_reserved(result), "result not in heap");
   619         assert(gch->is_in_reserved(result), "result not in heap");
   620         return result;
   620         return result;
   621       }
   621       }
   622 
   622 
   623       if (GC_locker::is_active_and_needs_gc()) {
   623       if (GCLocker::is_active_and_needs_gc()) {
   624         if (is_tlab) {
   624         if (is_tlab) {
   625           return NULL;  // Caller will retry allocating individual object.
   625           return NULL;  // Caller will retry allocating individual object.
   626         }
   626         }
   627         if (!gch->is_maximal_no_gc()) {
   627         if (!gch->is_maximal_no_gc()) {
   628           // Try and expand heap to satisfy request.
   628           // Try and expand heap to satisfy request.
   645         // rather than causing more, now probably unnecessary, GC attempts.
   645         // rather than causing more, now probably unnecessary, GC attempts.
   646         JavaThread* jthr = JavaThread::current();
   646         JavaThread* jthr = JavaThread::current();
   647         if (!jthr->in_critical()) {
   647         if (!jthr->in_critical()) {
   648           MutexUnlocker mul(Heap_lock);
   648           MutexUnlocker mul(Heap_lock);
   649           // Wait for JNI critical section to be exited
   649           // Wait for JNI critical section to be exited
   650           GC_locker::stall_until_clear();
   650           GCLocker::stall_until_clear();
   651           gclocker_stalled_count += 1;
   651           gclocker_stalled_count += 1;
   652           continue;
   652           continue;
   653         } else {
   653         } else {
   654           if (CheckJNICalls) {
   654           if (CheckJNICalls) {
   655             fatal("Possible deadlock due to allocating while"
   655             fatal("Possible deadlock due to allocating while"
   726   GenCollectedHeap *gch = GenCollectedHeap::heap();
   726   GenCollectedHeap *gch = GenCollectedHeap::heap();
   727   GCCauseSetter x(gch, GCCause::_allocation_failure);
   727   GCCauseSetter x(gch, GCCause::_allocation_failure);
   728   HeapWord* result = NULL;
   728   HeapWord* result = NULL;
   729 
   729 
   730   assert(size != 0, "Precondition violated");
   730   assert(size != 0, "Precondition violated");
   731   if (GC_locker::is_active_and_needs_gc()) {
   731   if (GCLocker::is_active_and_needs_gc()) {
   732     // GC locker is active; instead of a collection we will attempt
   732     // GC locker is active; instead of a collection we will attempt
   733     // to expand the heap, if there's room for expansion.
   733     // to expand the heap, if there's room for expansion.
   734     if (!gch->is_maximal_no_gc()) {
   734     if (!gch->is_maximal_no_gc()) {
   735       result = expand_heap_and_allocate(size, is_tlab);
   735       result = expand_heap_and_allocate(size, is_tlab);
   736     }
   736     }
   813     MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
   813     MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
   814     if (result != NULL) {
   814     if (result != NULL) {
   815       return result;
   815       return result;
   816     }
   816     }
   817 
   817 
   818     if (GC_locker::is_active_and_needs_gc()) {
   818     if (GCLocker::is_active_and_needs_gc()) {
   819       // If the GC_locker is active, just expand and allocate.
   819       // If the GCLocker is active, just expand and allocate.
   820       // If that does not succeed, wait if this thread is not
   820       // If that does not succeed, wait if this thread is not
   821       // in a critical section itself.
   821       // in a critical section itself.
   822       result =
   822       result =
   823         loader_data->metaspace_non_null()->expand_and_allocate(word_size,
   823         loader_data->metaspace_non_null()->expand_and_allocate(word_size,
   824                                                                mdtype);
   824                                                                mdtype);
   826         return result;
   826         return result;
   827       }
   827       }
   828       JavaThread* jthr = JavaThread::current();
   828       JavaThread* jthr = JavaThread::current();
   829       if (!jthr->in_critical()) {
   829       if (!jthr->in_critical()) {
   830         // Wait for JNI critical section to be exited
   830         // Wait for JNI critical section to be exited
   831         GC_locker::stall_until_clear();
   831         GCLocker::stall_until_clear();
   832         // The GC invoked by the last thread leaving the critical
   832         // The GC invoked by the last thread leaving the critical
   833         // section will be a young collection and a full collection
   833         // section will be a young collection and a full collection
   834         // is (currently) needed for unloading classes so continue
   834         // is (currently) needed for unloading classes so continue
   835         // to the next iteration to get a full GC.
   835         // to the next iteration to get a full GC.
   836         continue;
   836         continue;
   885 bool GenCollectorPolicy::should_try_older_generation_allocation(
   885 bool GenCollectorPolicy::should_try_older_generation_allocation(
   886         size_t word_size) const {
   886         size_t word_size) const {
   887   GenCollectedHeap* gch = GenCollectedHeap::heap();
   887   GenCollectedHeap* gch = GenCollectedHeap::heap();
   888   size_t young_capacity = gch->young_gen()->capacity_before_gc();
   888   size_t young_capacity = gch->young_gen()->capacity_before_gc();
   889   return    (word_size > heap_word_size(young_capacity))
   889   return    (word_size > heap_word_size(young_capacity))
   890          || GC_locker::is_active_and_needs_gc()
   890          || GCLocker::is_active_and_needs_gc()
   891          || gch->incremental_collection_failed();
   891          || gch->incremental_collection_failed();
   892 }
   892 }
   893 
   893 
   894 
   894 
   895 //
   895 //