1 #ifdef USE_PRAGMA_IDENT_SRC 2 #pragma ident "@(#)psPromotionLAB.cpp 1.17 07/05/05 17:05:30 JVM" 3 #endif 4 /* 5 * Copyright 2002-2006 Sun Microsystems, Inc. All Rights Reserved. 6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 * 8 * This code is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License version 2 only, as 10 * published by the Free Software Foundation. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 23 * CA 95054 USA or visit www.sun.com if you need additional information or 24 * have any questions. 25 * 26 */ 27 28 #include "incls/_precompiled.incl" 29 #include "incls/_psPromotionLAB.cpp.incl" 30 31 const size_t PSPromotionLAB::filler_header_size = align_object_size(typeArrayOopDesc::header_size(T_INT)); 32 33 // This is the shared initialization code. It sets up the basic pointers, 34 // and allows enough extra space for a filler object. We call a virtual 35 // method, "lab_is_valid()" to handle the different asserts the old/young 36 // labs require. 37 void PSPromotionLAB::initialize(MemRegion lab) { 38 assert(lab_is_valid(lab), "Sanity"); 39 40 HeapWord* bottom = lab.start(); 41 HeapWord* end = lab.end(); 42 43 set_bottom(bottom); 44 set_end(end); 45 set_top(bottom); 46 47 // We can be initialized to a zero size! 48 if (free() > 0) { 49 if (ZapUnusedHeapArea) { 50 debug_only(Copy::fill_to_words(top(), free()/HeapWordSize, badHeapWord)); 51 } 52 53 // NOTE! We need to allow space for a filler object. 54 assert(lab.word_size() >= filler_header_size, "lab is too small"); 55 end = end - filler_header_size; 56 set_end(end); 57 58 _state = needs_flush; 59 } else { 60 _state = zero_size; 61 } 62 63 assert(this->top() <= this->end(), "pointers out of order"); 64 } 65 66 // Fill all remaining lab space with an unreachable object. 67 // The goal is to leave a contiguous parseable span of objects. 68 void PSPromotionLAB::flush() { 69 assert(_state != flushed, "Attempt to flush PLAB twice"); 70 assert(top() <= end(), "pointers out of order"); 71 72 // If we were initialized to a zero sized lab, there is 73 // nothing to flush 74 if (_state == zero_size) 75 return; 76 77 // PLAB's never allocate the last aligned_header_size 78 // so they can always fill with an array. 79 HeapWord* tlab_end = end() + filler_header_size; 80 typeArrayOop filler_oop = (typeArrayOop) top(); 81 filler_oop->set_mark(markOopDesc::prototype()); 82 filler_oop->set_klass(Universe::intArrayKlassObj()); 83 const size_t array_length = 84 pointer_delta(tlab_end, top()) - typeArrayOopDesc::header_size(T_INT); 85 assert( (array_length * (HeapWordSize/sizeof(jint))) < (size_t)max_jint, "array too big in PSPromotionLAB"); 86 filler_oop->set_length((int)(array_length * (HeapWordSize/sizeof(jint)))); 87 88 #ifdef ASSERT 89 // Note that we actually DO NOT want to use the aligned header size! 90 HeapWord* elt_words = ((HeapWord*)filler_oop) + typeArrayOopDesc::header_size(T_INT); 91 Copy::fill_to_words(elt_words, array_length, 0xDEAABABE); 92 #endif 93 94 set_bottom(NULL); 95 set_end(NULL); 96 set_top(NULL); 97 98 _state = flushed; 99 } 100 101 bool PSPromotionLAB::unallocate_object(oop obj) { 102 assert(Universe::heap()->is_in(obj), "Object outside heap"); 103 104 if (contains(obj)) { 105 HeapWord* object_end = (HeapWord*)obj + obj->size(); 106 assert(object_end <= top(), "Object crosses promotion LAB boundary"); 107 108 if (object_end == top()) { 109 set_top((HeapWord*)obj); 110 return true; 111 } 112 } 113 114 return false; 115 } 116 117 // Fill all remaining lab space with an unreachable object. 118 // The goal is to leave a contiguous parseable span of objects. 119 void PSOldPromotionLAB::flush() { 120 assert(_state != flushed, "Attempt to flush PLAB twice"); 121 assert(top() <= end(), "pointers out of order"); 122 123 if (_state == zero_size) 124 return; 125 126 HeapWord* obj = top(); 127 128 PSPromotionLAB::flush(); 129 130 assert(_start_array != NULL, "Sanity"); 131 132 _start_array->allocate_block(obj); 133 } 134 135 #ifdef ASSERT 136 137 bool PSYoungPromotionLAB::lab_is_valid(MemRegion lab) { 138 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 139 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); 140 141 MutableSpace* to_space = heap->young_gen()->to_space(); 142 MemRegion used = to_space->used_region(); 143 if (used.contains(lab)) { 144 return true; 145 } 146 147 return false; 148 } 149 150 bool PSOldPromotionLAB::lab_is_valid(MemRegion lab) { 151 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 152 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); 153 assert(_start_array->covered_region().contains(lab), "Sanity"); 154 155 PSOldGen* old_gen = heap->old_gen(); 156 MemRegion used = old_gen->object_space()->used_region(); 157 158 if (used.contains(lab)) { 159 return true; 160 } 161 162 return false; 163 } 164 165 #endif /* ASSERT */