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