ysr@777: /* ysr@777: * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved. ysr@777: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ysr@777: * ysr@777: * This code is free software; you can redistribute it and/or modify it ysr@777: * under the terms of the GNU General Public License version 2 only, as ysr@777: * published by the Free Software Foundation. ysr@777: * ysr@777: * This code is distributed in the hope that it will be useful, but WITHOUT ysr@777: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ysr@777: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ysr@777: * version 2 for more details (a copy is included in the LICENSE file that ysr@777: * accompanied this code). ysr@777: * ysr@777: * You should have received a copy of the GNU General Public License version ysr@777: * 2 along with this work; if not, write to the Free Software Foundation, ysr@777: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ysr@777: * ysr@777: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, ysr@777: * CA 95054 USA or visit www.sun.com if you need additional information or ysr@777: * have any questions. ysr@777: * ysr@777: */ ysr@777: ysr@777: inline HeapWord* G1OffsetTableContigSpace::allocate(size_t size) { ysr@777: HeapWord* res = ContiguousSpace::allocate(size); ysr@777: if (res != NULL) { ysr@777: _offsets.alloc_block(res, size); ysr@777: } ysr@777: return res; ysr@777: } ysr@777: ysr@777: // Because of the requirement of keeping "_offsets" up to date with the ysr@777: // allocations, we sequentialize these with a lock. Therefore, best if ysr@777: // this is used for larger LAB allocations only. ysr@777: inline HeapWord* G1OffsetTableContigSpace::par_allocate(size_t size) { ysr@777: MutexLocker x(&_par_alloc_lock); ysr@777: // This ought to be just "allocate", because of the lock above, but that ysr@777: // ContiguousSpace::allocate asserts that either the allocating thread ysr@777: // holds the heap lock or it is the VM thread and we're at a safepoint. ysr@777: // The best I (dld) could figure was to put a field in ContiguousSpace ysr@777: // meaning "locking at safepoint taken care of", and set/reset that ysr@777: // here. But this will do for now, especially in light of the comment ysr@777: // above. Perhaps in the future some lock-free manner of keeping the ysr@777: // coordination. ysr@777: HeapWord* res = ContiguousSpace::par_allocate(size); ysr@777: if (res != NULL) { ysr@777: _offsets.alloc_block(res, size); ysr@777: } ysr@777: return res; ysr@777: } ysr@777: ysr@777: inline HeapWord* G1OffsetTableContigSpace::block_start(const void* p) { ysr@777: return _offsets.block_start(p); ysr@777: } ysr@777: ysr@777: inline HeapWord* ysr@777: G1OffsetTableContigSpace::block_start_const(const void* p) const { ysr@777: return _offsets.block_start_const(p); ysr@777: }