duke@435: /* duke@435: * Copyright 2001-2006 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: CompactibleSpace* DefNewGeneration::first_compaction_space() const { duke@435: return eden(); duke@435: } duke@435: duke@435: HeapWord* DefNewGeneration::allocate(size_t word_size, duke@435: bool is_tlab) { duke@435: // This is the slow-path allocation for the DefNewGeneration. duke@435: // Most allocations are fast-path in compiled code. duke@435: // We try to allocate from the eden. If that works, we are happy. duke@435: // Note that since DefNewGeneration supports lock-free allocation, we duke@435: // have to use it here, as well. duke@435: HeapWord* result = eden()->par_allocate(word_size); duke@435: if (result != NULL) { duke@435: return result; duke@435: } duke@435: do { duke@435: HeapWord* old_limit = eden()->soft_end(); duke@435: if (old_limit < eden()->end()) { duke@435: // Tell the next generation we reached a limit. duke@435: HeapWord* new_limit = duke@435: next_gen()->allocation_limit_reached(eden(), eden()->top(), word_size); duke@435: if (new_limit != NULL) { duke@435: Atomic::cmpxchg_ptr(new_limit, eden()->soft_end_addr(), old_limit); duke@435: } else { duke@435: assert(eden()->soft_end() == eden()->end(), duke@435: "invalid state after allocation_limit_reached returned null"); duke@435: } duke@435: } else { duke@435: // The allocation failed and the soft limit is equal to the hard limit, duke@435: // there are no reasons to do an attempt to allocate duke@435: assert(old_limit == eden()->end(), "sanity check"); duke@435: break; duke@435: } duke@435: // Try to allocate until succeeded or the soft limit can't be adjusted duke@435: result = eden()->par_allocate(word_size); duke@435: } while (result == NULL); duke@435: duke@435: // If the eden is full and the last collection bailed out, we are running duke@435: // out of heap space, and we try to allocate the from-space, too. duke@435: // allocate_from_space can't be inlined because that would introduce a duke@435: // circular dependency at compile time. duke@435: if (result == NULL) { duke@435: result = allocate_from_space(word_size); duke@435: } duke@435: return result; duke@435: } duke@435: duke@435: HeapWord* DefNewGeneration::par_allocate(size_t word_size, duke@435: bool is_tlab) { duke@435: return eden()->par_allocate(word_size); duke@435: } duke@435: duke@435: void DefNewGeneration::gc_prologue(bool full) { duke@435: // Ensure that _end and _soft_end are the same in eden space. duke@435: eden()->set_soft_end(eden()->end()); duke@435: } duke@435: duke@435: size_t DefNewGeneration::tlab_capacity() const { duke@435: return eden()->capacity(); duke@435: } duke@435: duke@435: size_t DefNewGeneration::unsafe_max_tlab_alloc() const { duke@435: return unsafe_max_alloc_nogc(); duke@435: }