// The last collection bailed out, we are running out of heap space, // so we try to allocate the from-space, too. HeapWord* DefNewGeneration::allocate_from_space(size_t size) { HeapWord* result = NULL; if (Verbose && PrintGCDetails) { gclog_or_tty->print("DefNewGeneration::allocate_from_space(%u):" " will_fail: %s" " heap_lock: %s" " free: " SIZE_FORMAT, size, GenCollectedHeap::heap()->incremental_collection_will_fail(false /* don't consult_young */) ? "true" : "false", Heap_lock->is_locked() ? "locked" : "unlocked", from()->free()); } if (should_allocate_from_space() || GC_locker::is_active_and_needs_gc()) { if (Heap_lock->owned_by_self() || (SafepointSynchronize::is_at_safepoint() && Thread::current()->is_VM_thread())) { // If the Heap_lock is not locked by this thread, this will be called // again later with the Heap_lock held. result = from()->allocate(size); } else if (PrintGC && Verbose) { gclog_or_tty->print_cr(" Heap_lock is not owned by self"); } } else if (PrintGC && Verbose) { gclog_or_tty->print_cr(" should_allocate_from_space: NOT"); } if (PrintGC && Verbose) { gclog_or_tty->print_cr(" returns %s", result == NULL ? "NULL" : "object"); } return result; }
// The last collection bailed out, we are running out of heap space, // so we try to allocate the from-space, too. HeapWord* DefNewGeneration::allocate_from_space(size_t size) { bool should_try_alloc = should_allocate_from_space() || GC_locker::is_active_and_needs_gc(); // If the Heap_lock is not locked by this thread, this will be called // again later with the Heap_lock held. bool do_alloc = should_try_alloc && (Heap_lock->owned_by_self() || (SafepointSynchronize::is_at_safepoint() && Thread::current()->is_VM_thread())); HeapWord* result = NULL; if (do_alloc) { result = from()->allocate(size); } log_trace(gc, alloc)("DefNewGeneration::allocate_from_space(" SIZE_FORMAT "): will_fail: %s heap_lock: %s free: " SIZE_FORMAT "%s%s returns %s", size, GenCollectedHeap::heap()->incremental_collection_will_fail(false /* don't consult_young */) ? "true" : "false", Heap_lock->is_locked() ? "locked" : "unlocked", from()->free(), should_try_alloc ? "" : " should_allocate_from_space: NOT", do_alloc ? " Heap_lock is not owned by self" : "", result == NULL ? "NULL" : "object"); return result; }