1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/psPromotionLAB.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,162 @@ 1.4 +/* 1.5 + * Copyright 2002-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "incls/_precompiled.incl" 1.29 +#include "incls/_psPromotionLAB.cpp.incl" 1.30 + 1.31 +const size_t PSPromotionLAB::filler_header_size = align_object_size(typeArrayOopDesc::header_size(T_INT)); 1.32 + 1.33 +// This is the shared initialization code. It sets up the basic pointers, 1.34 +// and allows enough extra space for a filler object. We call a virtual 1.35 +// method, "lab_is_valid()" to handle the different asserts the old/young 1.36 +// labs require. 1.37 +void PSPromotionLAB::initialize(MemRegion lab) { 1.38 + assert(lab_is_valid(lab), "Sanity"); 1.39 + 1.40 + HeapWord* bottom = lab.start(); 1.41 + HeapWord* end = lab.end(); 1.42 + 1.43 + set_bottom(bottom); 1.44 + set_end(end); 1.45 + set_top(bottom); 1.46 + 1.47 + // We can be initialized to a zero size! 1.48 + if (free() > 0) { 1.49 + if (ZapUnusedHeapArea) { 1.50 + debug_only(Copy::fill_to_words(top(), free()/HeapWordSize, badHeapWord)); 1.51 + } 1.52 + 1.53 + // NOTE! We need to allow space for a filler object. 1.54 + assert(lab.word_size() >= filler_header_size, "lab is too small"); 1.55 + end = end - filler_header_size; 1.56 + set_end(end); 1.57 + 1.58 + _state = needs_flush; 1.59 + } else { 1.60 + _state = zero_size; 1.61 + } 1.62 + 1.63 + assert(this->top() <= this->end(), "pointers out of order"); 1.64 +} 1.65 + 1.66 +// Fill all remaining lab space with an unreachable object. 1.67 +// The goal is to leave a contiguous parseable span of objects. 1.68 +void PSPromotionLAB::flush() { 1.69 + assert(_state != flushed, "Attempt to flush PLAB twice"); 1.70 + assert(top() <= end(), "pointers out of order"); 1.71 + 1.72 + // If we were initialized to a zero sized lab, there is 1.73 + // nothing to flush 1.74 + if (_state == zero_size) 1.75 + return; 1.76 + 1.77 + // PLAB's never allocate the last aligned_header_size 1.78 + // so they can always fill with an array. 1.79 + HeapWord* tlab_end = end() + filler_header_size; 1.80 + typeArrayOop filler_oop = (typeArrayOop) top(); 1.81 + filler_oop->set_mark(markOopDesc::prototype()); 1.82 + filler_oop->set_klass(Universe::intArrayKlassObj()); 1.83 + const size_t array_length = 1.84 + pointer_delta(tlab_end, top()) - typeArrayOopDesc::header_size(T_INT); 1.85 + assert( (array_length * (HeapWordSize/sizeof(jint))) < (size_t)max_jint, "array too big in PSPromotionLAB"); 1.86 + filler_oop->set_length((int)(array_length * (HeapWordSize/sizeof(jint)))); 1.87 + 1.88 +#ifdef ASSERT 1.89 + // Note that we actually DO NOT want to use the aligned header size! 1.90 + HeapWord* elt_words = ((HeapWord*)filler_oop) + typeArrayOopDesc::header_size(T_INT); 1.91 + Copy::fill_to_words(elt_words, array_length, 0xDEAABABE); 1.92 +#endif 1.93 + 1.94 + set_bottom(NULL); 1.95 + set_end(NULL); 1.96 + set_top(NULL); 1.97 + 1.98 + _state = flushed; 1.99 +} 1.100 + 1.101 +bool PSPromotionLAB::unallocate_object(oop obj) { 1.102 + assert(Universe::heap()->is_in(obj), "Object outside heap"); 1.103 + 1.104 + if (contains(obj)) { 1.105 + HeapWord* object_end = (HeapWord*)obj + obj->size(); 1.106 + assert(object_end <= top(), "Object crosses promotion LAB boundary"); 1.107 + 1.108 + if (object_end == top()) { 1.109 + set_top((HeapWord*)obj); 1.110 + return true; 1.111 + } 1.112 + } 1.113 + 1.114 + return false; 1.115 +} 1.116 + 1.117 +// Fill all remaining lab space with an unreachable object. 1.118 +// The goal is to leave a contiguous parseable span of objects. 1.119 +void PSOldPromotionLAB::flush() { 1.120 + assert(_state != flushed, "Attempt to flush PLAB twice"); 1.121 + assert(top() <= end(), "pointers out of order"); 1.122 + 1.123 + if (_state == zero_size) 1.124 + return; 1.125 + 1.126 + HeapWord* obj = top(); 1.127 + 1.128 + PSPromotionLAB::flush(); 1.129 + 1.130 + assert(_start_array != NULL, "Sanity"); 1.131 + 1.132 + _start_array->allocate_block(obj); 1.133 +} 1.134 + 1.135 +#ifdef ASSERT 1.136 + 1.137 +bool PSYoungPromotionLAB::lab_is_valid(MemRegion lab) { 1.138 + ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 1.139 + assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); 1.140 + 1.141 + MutableSpace* to_space = heap->young_gen()->to_space(); 1.142 + MemRegion used = to_space->used_region(); 1.143 + if (used.contains(lab)) { 1.144 + return true; 1.145 + } 1.146 + 1.147 + return false; 1.148 +} 1.149 + 1.150 +bool PSOldPromotionLAB::lab_is_valid(MemRegion lab) { 1.151 + ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 1.152 + assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); 1.153 + assert(_start_array->covered_region().contains(lab), "Sanity"); 1.154 + 1.155 + PSOldGen* old_gen = heap->old_gen(); 1.156 + MemRegion used = old_gen->object_space()->used_region(); 1.157 + 1.158 + if (used.contains(lab)) { 1.159 + return true; 1.160 + } 1.161 + 1.162 + return false; 1.163 +} 1.164 + 1.165 +#endif /* ASSERT */