Mercurial > hg > graal-jvmci-8
annotate src/share/vm/gc_implementation/shared/mutableNUMASpace.cpp @ 263:12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
Summary: Maintain a high water mark for the allocations in a space and mangle only up to that high water mark.
Reviewed-by: ysr, apetrusenko
author | jmasa |
---|---|
date | Wed, 09 Jul 2008 15:08:55 -0700 |
parents | d1635bf93939 |
children | d6340ab4105b |
rev | line source |
---|---|
0 | 1 |
2 /* | |
3 * Copyright 2006-2007 Sun Microsystems, Inc. All Rights Reserved. | |
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
5 * | |
6 * This code is free software; you can redistribute it and/or modify it | |
7 * under the terms of the GNU General Public License version 2 only, as | |
8 * published by the Free Software Foundation. | |
9 * | |
10 * This code is distributed in the hope that it will be useful, but WITHOUT | |
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 * version 2 for more details (a copy is included in the LICENSE file that | |
14 * accompanied this code). | |
15 * | |
16 * You should have received a copy of the GNU General Public License version | |
17 * 2 along with this work; if not, write to the Free Software Foundation, | |
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
19 * | |
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
21 * CA 95054 USA or visit www.sun.com if you need additional information or | |
22 * have any questions. | |
23 * | |
24 */ | |
25 | |
26 # include "incls/_precompiled.incl" | |
27 # include "incls/_mutableNUMASpace.cpp.incl" | |
28 | |
29 | |
30 MutableNUMASpace::MutableNUMASpace() { | |
31 _lgrp_spaces = new (ResourceObj::C_HEAP) GrowableArray<LGRPSpace*>(0, true); | |
32 _page_size = os::vm_page_size(); | |
33 _adaptation_cycles = 0; | |
34 _samples_count = 0; | |
35 update_layout(true); | |
36 } | |
37 | |
38 MutableNUMASpace::~MutableNUMASpace() { | |
39 for (int i = 0; i < lgrp_spaces()->length(); i++) { | |
40 delete lgrp_spaces()->at(i); | |
41 } | |
42 delete lgrp_spaces(); | |
43 } | |
44 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
45 #ifndef PRODUCT |
0 | 46 void MutableNUMASpace::mangle_unused_area() { |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
47 // This method should do nothing. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
48 // It can be called on a numa space during a full compaction. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
49 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
50 void MutableNUMASpace::mangle_unused_area_complete() { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
51 // This method should do nothing. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
52 // It can be called on a numa space during a full compaction. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
53 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
54 void MutableNUMASpace::mangle_region(MemRegion mr) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
55 // This method should do nothing because numa spaces are not mangled. |
0 | 56 } |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
57 void MutableNUMASpace::set_top_for_allocations(HeapWord* v) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
58 assert(false, "Do not mangle MutableNUMASpace's"); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
59 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
60 void MutableNUMASpace::set_top_for_allocations() { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
61 // This method should do nothing. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
62 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
63 void MutableNUMASpace::check_mangled_unused_area(HeapWord* limit) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
64 // This method should do nothing. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
65 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
66 void MutableNUMASpace::check_mangled_unused_area_complete() { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
67 // This method should do nothing. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
68 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
69 #endif // NOT_PRODUCT |
0 | 70 |
71 // There may be unallocated holes in the middle chunks | |
72 // that should be filled with dead objects to ensure parseability. | |
73 void MutableNUMASpace::ensure_parsability() { | |
74 for (int i = 0; i < lgrp_spaces()->length(); i++) { | |
75 LGRPSpace *ls = lgrp_spaces()->at(i); | |
76 MutableSpace *s = ls->space(); | |
144
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
77 if (s->top() < top()) { // For all spaces preceeding the one containing top() |
0 | 78 if (s->free_in_words() > 0) { |
79 SharedHeap::fill_region_with_object(MemRegion(s->top(), s->end())); | |
144
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
80 size_t area_touched_words = pointer_delta(s->end(), s->top()); |
0 | 81 #ifndef ASSERT |
82 if (!ZapUnusedHeapArea) { | |
83 area_touched_words = MIN2((size_t)align_object_size(typeArrayOopDesc::header_size(T_INT)), | |
84 area_touched_words); | |
85 } | |
86 #endif | |
141 | 87 if (!os::numa_has_static_binding()) { |
88 MemRegion invalid; | |
89 HeapWord *crossing_start = (HeapWord*)round_to((intptr_t)s->top(), os::vm_page_size()); | |
90 HeapWord *crossing_end = (HeapWord*)round_to((intptr_t)(s->top() + area_touched_words), | |
91 os::vm_page_size()); | |
92 if (crossing_start != crossing_end) { | |
93 // If object header crossed a small page boundary we mark the area | |
94 // as invalid rounding it to a page_size(). | |
95 HeapWord *start = MAX2((HeapWord*)round_down((intptr_t)s->top(), page_size()), s->bottom()); | |
96 HeapWord *end = MIN2((HeapWord*)round_to((intptr_t)(s->top() + area_touched_words), page_size()), | |
97 s->end()); | |
98 invalid = MemRegion(start, end); | |
99 } | |
100 | |
101 ls->add_invalid_region(invalid); | |
0 | 102 } |
103 } | |
104 } else { | |
141 | 105 if (!os::numa_has_static_binding()) { |
0 | 106 #ifdef ASSERT |
107 MemRegion invalid(s->top(), s->end()); | |
108 ls->add_invalid_region(invalid); | |
141 | 109 #else |
110 if (ZapUnusedHeapArea) { | |
111 MemRegion invalid(s->top(), s->end()); | |
112 ls->add_invalid_region(invalid); | |
144
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
113 } else { |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
114 return; |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
115 } |
0 | 116 #endif |
144
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
117 } else { |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
118 return; |
141 | 119 } |
0 | 120 } |
121 } | |
122 } | |
123 | |
124 size_t MutableNUMASpace::used_in_words() const { | |
125 size_t s = 0; | |
126 for (int i = 0; i < lgrp_spaces()->length(); i++) { | |
127 s += lgrp_spaces()->at(i)->space()->used_in_words(); | |
128 } | |
129 return s; | |
130 } | |
131 | |
132 size_t MutableNUMASpace::free_in_words() const { | |
133 size_t s = 0; | |
134 for (int i = 0; i < lgrp_spaces()->length(); i++) { | |
135 s += lgrp_spaces()->at(i)->space()->free_in_words(); | |
136 } | |
137 return s; | |
138 } | |
139 | |
140 | |
141 size_t MutableNUMASpace::tlab_capacity(Thread *thr) const { | |
142 guarantee(thr != NULL, "No thread"); | |
143 int lgrp_id = thr->lgrp_id(); | |
144 assert(lgrp_id != -1, "No lgrp_id set"); | |
145 int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals); | |
146 if (i == -1) { | |
147 return 0; | |
148 } | |
149 return lgrp_spaces()->at(i)->space()->capacity_in_bytes(); | |
150 } | |
151 | |
152 size_t MutableNUMASpace::unsafe_max_tlab_alloc(Thread *thr) const { | |
153 guarantee(thr != NULL, "No thread"); | |
154 int lgrp_id = thr->lgrp_id(); | |
155 assert(lgrp_id != -1, "No lgrp_id set"); | |
156 int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals); | |
157 if (i == -1) { | |
158 return 0; | |
159 } | |
160 return lgrp_spaces()->at(i)->space()->free_in_bytes(); | |
161 } | |
162 | |
163 // Check if the NUMA topology has changed. Add and remove spaces if needed. | |
164 // The update can be forced by setting the force parameter equal to true. | |
165 bool MutableNUMASpace::update_layout(bool force) { | |
166 // Check if the topology had changed. | |
167 bool changed = os::numa_topology_changed(); | |
168 if (force || changed) { | |
169 // Compute lgrp intersection. Add/remove spaces. | |
170 int lgrp_limit = (int)os::numa_get_groups_num(); | |
171 int *lgrp_ids = NEW_C_HEAP_ARRAY(int, lgrp_limit); | |
172 int lgrp_num = (int)os::numa_get_leaf_groups(lgrp_ids, lgrp_limit); | |
173 assert(lgrp_num > 0, "There should be at least one locality group"); | |
174 // Add new spaces for the new nodes | |
175 for (int i = 0; i < lgrp_num; i++) { | |
176 bool found = false; | |
177 for (int j = 0; j < lgrp_spaces()->length(); j++) { | |
178 if (lgrp_spaces()->at(j)->lgrp_id() == lgrp_ids[i]) { | |
179 found = true; | |
180 break; | |
181 } | |
182 } | |
183 if (!found) { | |
184 lgrp_spaces()->append(new LGRPSpace(lgrp_ids[i])); | |
185 } | |
186 } | |
187 | |
188 // Remove spaces for the removed nodes. | |
189 for (int i = 0; i < lgrp_spaces()->length();) { | |
190 bool found = false; | |
191 for (int j = 0; j < lgrp_num; j++) { | |
192 if (lgrp_spaces()->at(i)->lgrp_id() == lgrp_ids[j]) { | |
193 found = true; | |
194 break; | |
195 } | |
196 } | |
197 if (!found) { | |
198 delete lgrp_spaces()->at(i); | |
199 lgrp_spaces()->remove_at(i); | |
200 } else { | |
201 i++; | |
202 } | |
203 } | |
204 | |
205 FREE_C_HEAP_ARRAY(int, lgrp_ids); | |
206 | |
207 if (changed) { | |
208 for (JavaThread *thread = Threads::first(); thread; thread = thread->next()) { | |
209 thread->set_lgrp_id(-1); | |
210 } | |
211 } | |
212 return true; | |
213 } | |
214 return false; | |
215 } | |
216 | |
217 // Bias region towards the first-touching lgrp. Set the right page sizes. | |
141 | 218 void MutableNUMASpace::bias_region(MemRegion mr, int lgrp_id) { |
0 | 219 HeapWord *start = (HeapWord*)round_to((intptr_t)mr.start(), page_size()); |
220 HeapWord *end = (HeapWord*)round_down((intptr_t)mr.end(), page_size()); | |
221 if (end > start) { | |
222 MemRegion aligned_region(start, end); | |
223 assert((intptr_t)aligned_region.start() % page_size() == 0 && | |
224 (intptr_t)aligned_region.byte_size() % page_size() == 0, "Bad alignment"); | |
225 assert(region().contains(aligned_region), "Sanity"); | |
141 | 226 // First we tell the OS which page size we want in the given range. The underlying |
227 // large page can be broken down if we require small pages. | |
0 | 228 os::realign_memory((char*)aligned_region.start(), aligned_region.byte_size(), page_size()); |
141 | 229 // Then we uncommit the pages in the range. |
230 os::free_memory((char*)aligned_region.start(), aligned_region.byte_size()); | |
231 // And make them local/first-touch biased. | |
232 os::numa_make_local((char*)aligned_region.start(), aligned_region.byte_size(), lgrp_id); | |
0 | 233 } |
234 } | |
235 | |
236 // Free all pages in the region. | |
237 void MutableNUMASpace::free_region(MemRegion mr) { | |
238 HeapWord *start = (HeapWord*)round_to((intptr_t)mr.start(), page_size()); | |
239 HeapWord *end = (HeapWord*)round_down((intptr_t)mr.end(), page_size()); | |
240 if (end > start) { | |
241 MemRegion aligned_region(start, end); | |
242 assert((intptr_t)aligned_region.start() % page_size() == 0 && | |
243 (intptr_t)aligned_region.byte_size() % page_size() == 0, "Bad alignment"); | |
244 assert(region().contains(aligned_region), "Sanity"); | |
245 os::free_memory((char*)aligned_region.start(), aligned_region.byte_size()); | |
246 } | |
247 } | |
248 | |
249 // Update space layout. Perform adaptation. | |
250 void MutableNUMASpace::update() { | |
251 if (update_layout(false)) { | |
252 // If the topology has changed, make all chunks zero-sized. | |
253 for (int i = 0; i < lgrp_spaces()->length(); i++) { | |
254 MutableSpace *s = lgrp_spaces()->at(i)->space(); | |
255 s->set_end(s->bottom()); | |
256 s->set_top(s->bottom()); | |
257 } | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
258 // A NUMA space is never mangled |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
259 initialize(region(), |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
260 SpaceDecorator::Clear, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
261 SpaceDecorator::DontMangle); |
0 | 262 } else { |
263 bool should_initialize = false; | |
141 | 264 if (!os::numa_has_static_binding()) { |
265 for (int i = 0; i < lgrp_spaces()->length(); i++) { | |
266 if (!lgrp_spaces()->at(i)->invalid_region().is_empty()) { | |
267 should_initialize = true; | |
268 break; | |
269 } | |
0 | 270 } |
271 } | |
272 | |
273 if (should_initialize || | |
274 (UseAdaptiveNUMAChunkSizing && adaptation_cycles() < samples_count())) { | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
275 // A NUMA space is never mangled |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
276 initialize(region(), |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
277 SpaceDecorator::Clear, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
278 SpaceDecorator::DontMangle); |
0 | 279 } |
280 } | |
281 | |
282 if (NUMAStats) { | |
283 for (int i = 0; i < lgrp_spaces()->length(); i++) { | |
284 lgrp_spaces()->at(i)->accumulate_statistics(page_size()); | |
285 } | |
286 } | |
287 | |
288 scan_pages(NUMAPageScanRate); | |
289 } | |
290 | |
291 // Scan pages. Free pages that have smaller size or wrong placement. | |
292 void MutableNUMASpace::scan_pages(size_t page_count) | |
293 { | |
294 size_t pages_per_chunk = page_count / lgrp_spaces()->length(); | |
295 if (pages_per_chunk > 0) { | |
296 for (int i = 0; i < lgrp_spaces()->length(); i++) { | |
297 LGRPSpace *ls = lgrp_spaces()->at(i); | |
298 ls->scan_pages(page_size(), pages_per_chunk); | |
299 } | |
300 } | |
301 } | |
302 | |
303 // Accumulate statistics about the allocation rate of each lgrp. | |
304 void MutableNUMASpace::accumulate_statistics() { | |
305 if (UseAdaptiveNUMAChunkSizing) { | |
306 for (int i = 0; i < lgrp_spaces()->length(); i++) { | |
307 lgrp_spaces()->at(i)->sample(); | |
308 } | |
309 increment_samples_count(); | |
310 } | |
311 | |
312 if (NUMAStats) { | |
313 for (int i = 0; i < lgrp_spaces()->length(); i++) { | |
314 lgrp_spaces()->at(i)->accumulate_statistics(page_size()); | |
315 } | |
316 } | |
317 } | |
318 | |
319 // Get the current size of a chunk. | |
320 // This function computes the size of the chunk based on the | |
321 // difference between chunk ends. This allows it to work correctly in | |
322 // case the whole space is resized and during the process of adaptive | |
323 // chunk resizing. | |
324 size_t MutableNUMASpace::current_chunk_size(int i) { | |
325 HeapWord *cur_end, *prev_end; | |
326 if (i == 0) { | |
327 prev_end = bottom(); | |
328 } else { | |
329 prev_end = lgrp_spaces()->at(i - 1)->space()->end(); | |
330 } | |
331 if (i == lgrp_spaces()->length() - 1) { | |
332 cur_end = end(); | |
333 } else { | |
334 cur_end = lgrp_spaces()->at(i)->space()->end(); | |
335 } | |
336 if (cur_end > prev_end) { | |
337 return pointer_delta(cur_end, prev_end, sizeof(char)); | |
338 } | |
339 return 0; | |
340 } | |
341 | |
342 // Return the default chunk size by equally diving the space. | |
343 // page_size() aligned. | |
344 size_t MutableNUMASpace::default_chunk_size() { | |
345 return base_space_size() / lgrp_spaces()->length() * page_size(); | |
346 } | |
347 | |
348 // Produce a new chunk size. page_size() aligned. | |
349 size_t MutableNUMASpace::adaptive_chunk_size(int i, size_t limit) { | |
350 size_t pages_available = base_space_size(); | |
351 for (int j = 0; j < i; j++) { | |
352 pages_available -= round_down(current_chunk_size(j), page_size()) / page_size(); | |
353 } | |
354 pages_available -= lgrp_spaces()->length() - i - 1; | |
355 assert(pages_available > 0, "No pages left"); | |
356 float alloc_rate = 0; | |
357 for (int j = i; j < lgrp_spaces()->length(); j++) { | |
358 alloc_rate += lgrp_spaces()->at(j)->alloc_rate()->average(); | |
359 } | |
360 size_t chunk_size = 0; | |
361 if (alloc_rate > 0) { | |
362 LGRPSpace *ls = lgrp_spaces()->at(i); | |
363 chunk_size = (size_t)(ls->alloc_rate()->average() * pages_available / alloc_rate) * page_size(); | |
364 } | |
365 chunk_size = MAX2(chunk_size, page_size()); | |
366 | |
367 if (limit > 0) { | |
368 limit = round_down(limit, page_size()); | |
369 if (chunk_size > current_chunk_size(i)) { | |
370 chunk_size = MIN2((off_t)chunk_size, (off_t)current_chunk_size(i) + (off_t)limit); | |
371 } else { | |
372 chunk_size = MAX2((off_t)chunk_size, (off_t)current_chunk_size(i) - (off_t)limit); | |
373 } | |
374 } | |
375 assert(chunk_size <= pages_available * page_size(), "Chunk size out of range"); | |
376 return chunk_size; | |
377 } | |
378 | |
379 | |
380 // Return the bottom_region and the top_region. Align them to page_size() boundary. | |
381 // |------------------new_region---------------------------------| | |
382 // |----bottom_region--|---intersection---|------top_region------| | |
383 void MutableNUMASpace::select_tails(MemRegion new_region, MemRegion intersection, | |
384 MemRegion* bottom_region, MemRegion *top_region) { | |
385 // Is there bottom? | |
386 if (new_region.start() < intersection.start()) { // Yes | |
387 // Try to coalesce small pages into a large one. | |
388 if (UseLargePages && page_size() >= os::large_page_size()) { | |
389 HeapWord* p = (HeapWord*)round_to((intptr_t) intersection.start(), os::large_page_size()); | |
390 if (new_region.contains(p) | |
391 && pointer_delta(p, new_region.start(), sizeof(char)) >= os::large_page_size()) { | |
392 if (intersection.contains(p)) { | |
393 intersection = MemRegion(p, intersection.end()); | |
394 } else { | |
395 intersection = MemRegion(p, p); | |
396 } | |
397 } | |
398 } | |
399 *bottom_region = MemRegion(new_region.start(), intersection.start()); | |
400 } else { | |
401 *bottom_region = MemRegion(); | |
402 } | |
403 | |
404 // Is there top? | |
405 if (intersection.end() < new_region.end()) { // Yes | |
406 // Try to coalesce small pages into a large one. | |
407 if (UseLargePages && page_size() >= os::large_page_size()) { | |
408 HeapWord* p = (HeapWord*)round_down((intptr_t) intersection.end(), os::large_page_size()); | |
409 if (new_region.contains(p) | |
410 && pointer_delta(new_region.end(), p, sizeof(char)) >= os::large_page_size()) { | |
411 if (intersection.contains(p)) { | |
412 intersection = MemRegion(intersection.start(), p); | |
413 } else { | |
414 intersection = MemRegion(p, p); | |
415 } | |
416 } | |
417 } | |
418 *top_region = MemRegion(intersection.end(), new_region.end()); | |
419 } else { | |
420 *top_region = MemRegion(); | |
421 } | |
422 } | |
423 | |
424 // Try to merge the invalid region with the bottom or top region by decreasing | |
425 // the intersection area. Return the invalid_region aligned to the page_size() | |
426 // boundary if it's inside the intersection. Return non-empty invalid_region | |
427 // if it lies inside the intersection (also page-aligned). | |
428 // |------------------new_region---------------------------------| | |
429 // |----------------|-------invalid---|--------------------------| | |
430 // |----bottom_region--|---intersection---|------top_region------| | |
431 void MutableNUMASpace::merge_regions(MemRegion new_region, MemRegion* intersection, | |
432 MemRegion *invalid_region) { | |
433 if (intersection->start() >= invalid_region->start() && intersection->contains(invalid_region->end())) { | |
434 *intersection = MemRegion(invalid_region->end(), intersection->end()); | |
435 *invalid_region = MemRegion(); | |
436 } else | |
437 if (intersection->end() <= invalid_region->end() && intersection->contains(invalid_region->start())) { | |
438 *intersection = MemRegion(intersection->start(), invalid_region->start()); | |
439 *invalid_region = MemRegion(); | |
440 } else | |
441 if (intersection->equals(*invalid_region) || invalid_region->contains(*intersection)) { | |
442 *intersection = MemRegion(new_region.start(), new_region.start()); | |
443 *invalid_region = MemRegion(); | |
444 } else | |
445 if (intersection->contains(invalid_region)) { | |
446 // That's the only case we have to make an additional bias_region() call. | |
447 HeapWord* start = invalid_region->start(); | |
448 HeapWord* end = invalid_region->end(); | |
449 if (UseLargePages && page_size() >= os::large_page_size()) { | |
450 HeapWord *p = (HeapWord*)round_down((intptr_t) start, os::large_page_size()); | |
451 if (new_region.contains(p)) { | |
452 start = p; | |
453 } | |
454 p = (HeapWord*)round_to((intptr_t) end, os::large_page_size()); | |
455 if (new_region.contains(end)) { | |
456 end = p; | |
457 } | |
458 } | |
459 if (intersection->start() > start) { | |
460 *intersection = MemRegion(start, intersection->end()); | |
461 } | |
462 if (intersection->end() < end) { | |
463 *intersection = MemRegion(intersection->start(), end); | |
464 } | |
465 *invalid_region = MemRegion(start, end); | |
466 } | |
467 } | |
468 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
469 void MutableNUMASpace::initialize(MemRegion mr, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
470 bool clear_space, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
471 bool mangle_space) { |
0 | 472 assert(clear_space, "Reallocation will destory data!"); |
473 assert(lgrp_spaces()->length() > 0, "There should be at least one space"); | |
474 | |
475 MemRegion old_region = region(), new_region; | |
476 set_bottom(mr.start()); | |
477 set_end(mr.end()); | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
478 // Must always clear the space |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
479 clear(SpaceDecorator::DontMangle); |
0 | 480 |
481 // Compute chunk sizes | |
482 size_t prev_page_size = page_size(); | |
483 set_page_size(UseLargePages ? os::large_page_size() : os::vm_page_size()); | |
484 HeapWord* rounded_bottom = (HeapWord*)round_to((intptr_t) bottom(), page_size()); | |
485 HeapWord* rounded_end = (HeapWord*)round_down((intptr_t) end(), page_size()); | |
486 size_t base_space_size_pages = pointer_delta(rounded_end, rounded_bottom, sizeof(char)) / page_size(); | |
487 | |
488 // Try small pages if the chunk size is too small | |
489 if (base_space_size_pages / lgrp_spaces()->length() == 0 | |
490 && page_size() > (size_t)os::vm_page_size()) { | |
491 set_page_size(os::vm_page_size()); | |
492 rounded_bottom = (HeapWord*)round_to((intptr_t) bottom(), page_size()); | |
493 rounded_end = (HeapWord*)round_down((intptr_t) end(), page_size()); | |
494 base_space_size_pages = pointer_delta(rounded_end, rounded_bottom, sizeof(char)) / page_size(); | |
495 } | |
496 guarantee(base_space_size_pages / lgrp_spaces()->length() > 0, "Space too small"); | |
497 set_base_space_size(base_space_size_pages); | |
498 | |
499 // Handle space resize | |
500 MemRegion top_region, bottom_region; | |
501 if (!old_region.equals(region())) { | |
502 new_region = MemRegion(rounded_bottom, rounded_end); | |
503 MemRegion intersection = new_region.intersection(old_region); | |
504 if (intersection.start() == NULL || | |
505 intersection.end() == NULL || | |
506 prev_page_size > page_size()) { // If the page size got smaller we have to change | |
507 // the page size preference for the whole space. | |
508 intersection = MemRegion(new_region.start(), new_region.start()); | |
509 } | |
510 select_tails(new_region, intersection, &bottom_region, &top_region); | |
141 | 511 bias_region(bottom_region, lgrp_spaces()->at(0)->lgrp_id()); |
512 bias_region(top_region, lgrp_spaces()->at(lgrp_spaces()->length() - 1)->lgrp_id()); | |
0 | 513 } |
514 | |
515 // Check if the space layout has changed significantly? | |
516 // This happens when the space has been resized so that either head or tail | |
517 // chunk became less than a page. | |
518 bool layout_valid = UseAdaptiveNUMAChunkSizing && | |
519 current_chunk_size(0) > page_size() && | |
520 current_chunk_size(lgrp_spaces()->length() - 1) > page_size(); | |
521 | |
522 | |
523 for (int i = 0; i < lgrp_spaces()->length(); i++) { | |
524 LGRPSpace *ls = lgrp_spaces()->at(i); | |
525 MutableSpace *s = ls->space(); | |
526 old_region = s->region(); | |
527 | |
528 size_t chunk_byte_size = 0, old_chunk_byte_size = 0; | |
529 if (i < lgrp_spaces()->length() - 1) { | |
530 if (!UseAdaptiveNUMAChunkSizing || | |
531 (UseAdaptiveNUMAChunkSizing && NUMAChunkResizeWeight == 0) || | |
532 samples_count() < AdaptiveSizePolicyReadyThreshold) { | |
533 // No adaptation. Divide the space equally. | |
534 chunk_byte_size = default_chunk_size(); | |
535 } else | |
536 if (!layout_valid || NUMASpaceResizeRate == 0) { | |
537 // Fast adaptation. If no space resize rate is set, resize | |
538 // the chunks instantly. | |
539 chunk_byte_size = adaptive_chunk_size(i, 0); | |
540 } else { | |
541 // Slow adaptation. Resize the chunks moving no more than | |
542 // NUMASpaceResizeRate bytes per collection. | |
543 size_t limit = NUMASpaceResizeRate / | |
544 (lgrp_spaces()->length() * (lgrp_spaces()->length() + 1) / 2); | |
545 chunk_byte_size = adaptive_chunk_size(i, MAX2(limit * (i + 1), page_size())); | |
546 } | |
547 | |
548 assert(chunk_byte_size >= page_size(), "Chunk size too small"); | |
549 assert(chunk_byte_size <= capacity_in_bytes(), "Sanity check"); | |
550 } | |
551 | |
552 if (i == 0) { // Bottom chunk | |
553 if (i != lgrp_spaces()->length() - 1) { | |
554 new_region = MemRegion(bottom(), rounded_bottom + (chunk_byte_size >> LogHeapWordSize)); | |
555 } else { | |
556 new_region = MemRegion(bottom(), end()); | |
557 } | |
558 } else | |
559 if (i < lgrp_spaces()->length() - 1) { // Middle chunks | |
560 MutableSpace *ps = lgrp_spaces()->at(i - 1)->space(); | |
561 new_region = MemRegion(ps->end(), | |
562 ps->end() + (chunk_byte_size >> LogHeapWordSize)); | |
563 } else { // Top chunk | |
564 MutableSpace *ps = lgrp_spaces()->at(i - 1)->space(); | |
565 new_region = MemRegion(ps->end(), end()); | |
566 } | |
567 guarantee(region().contains(new_region), "Region invariant"); | |
568 | |
569 | |
570 // The general case: | |
571 // |---------------------|--invalid---|--------------------------| | |
572 // |------------------new_region---------------------------------| | |
573 // |----bottom_region--|---intersection---|------top_region------| | |
574 // |----old_region----| | |
575 // The intersection part has all pages in place we don't need to migrate them. | |
576 // Pages for the top and bottom part should be freed and then reallocated. | |
577 | |
578 MemRegion intersection = old_region.intersection(new_region); | |
579 | |
580 if (intersection.start() == NULL || intersection.end() == NULL) { | |
581 intersection = MemRegion(new_region.start(), new_region.start()); | |
582 } | |
583 | |
141 | 584 if (!os::numa_has_static_binding()) { |
585 MemRegion invalid_region = ls->invalid_region().intersection(new_region); | |
586 // Invalid region is a range of memory that could've possibly | |
587 // been allocated on the other node. That's relevant only on Solaris where | |
588 // there is no static memory binding. | |
589 if (!invalid_region.is_empty()) { | |
590 merge_regions(new_region, &intersection, &invalid_region); | |
591 free_region(invalid_region); | |
592 ls->set_invalid_region(MemRegion()); | |
593 } | |
0 | 594 } |
141 | 595 |
0 | 596 select_tails(new_region, intersection, &bottom_region, &top_region); |
141 | 597 |
598 if (!os::numa_has_static_binding()) { | |
599 // If that's a system with the first-touch policy then it's enough | |
600 // to free the pages. | |
601 free_region(bottom_region); | |
602 free_region(top_region); | |
603 } else { | |
604 // In a system with static binding we have to change the bias whenever | |
605 // we reshape the heap. | |
606 bias_region(bottom_region, ls->lgrp_id()); | |
607 bias_region(top_region, ls->lgrp_id()); | |
608 } | |
0 | 609 |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
610 // Clear space (set top = bottom) but never mangle. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
611 s->initialize(new_region, SpaceDecorator::Clear, SpaceDecorator::DontMangle); |
0 | 612 |
613 set_adaptation_cycles(samples_count()); | |
614 } | |
615 } | |
616 | |
617 // Set the top of the whole space. | |
618 // Mark the the holes in chunks below the top() as invalid. | |
619 void MutableNUMASpace::set_top(HeapWord* value) { | |
620 bool found_top = false; | |
190
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
621 for (int i = 0; i < lgrp_spaces()->length();) { |
0 | 622 LGRPSpace *ls = lgrp_spaces()->at(i); |
623 MutableSpace *s = ls->space(); | |
624 HeapWord *top = MAX2((HeapWord*)round_down((intptr_t)s->top(), page_size()), s->bottom()); | |
625 | |
626 if (s->contains(value)) { | |
190
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
627 // Check if setting the chunk's top to a given value would create a hole less than |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
628 // a minimal object; assuming that's not the last chunk in which case we don't care. |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
629 if (i < lgrp_spaces()->length() - 1) { |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
630 size_t remainder = pointer_delta(s->end(), value); |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
631 const size_t minimal_object_size = oopDesc::header_size(); |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
632 if (remainder < minimal_object_size && remainder > 0) { |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
633 // Add a filler object of a minimal size, it will cross the chunk boundary. |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
634 SharedHeap::fill_region_with_object(MemRegion(value, minimal_object_size)); |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
635 value += minimal_object_size; |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
636 assert(!s->contains(value), "Should be in the next chunk"); |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
637 // Restart the loop from the same chunk, since the value has moved |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
638 // to the next one. |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
639 continue; |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
640 } |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
641 } |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
642 |
141 | 643 if (!os::numa_has_static_binding() && top < value && top < s->end()) { |
0 | 644 ls->add_invalid_region(MemRegion(top, value)); |
645 } | |
646 s->set_top(value); | |
647 found_top = true; | |
648 } else { | |
649 if (found_top) { | |
650 s->set_top(s->bottom()); | |
651 } else { | |
141 | 652 if (!os::numa_has_static_binding() && top < s->end()) { |
653 ls->add_invalid_region(MemRegion(top, s->end())); | |
654 } | |
655 s->set_top(s->end()); | |
0 | 656 } |
657 } | |
190
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
658 i++; |
0 | 659 } |
660 MutableSpace::set_top(value); | |
661 } | |
662 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
663 void MutableNUMASpace::clear(bool mangle_space) { |
0 | 664 MutableSpace::set_top(bottom()); |
665 for (int i = 0; i < lgrp_spaces()->length(); i++) { | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
666 // Never mangle NUMA spaces because the mangling will |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
667 // bind the memory to a possibly unwanted lgroup. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
668 lgrp_spaces()->at(i)->space()->clear(SpaceDecorator::DontMangle); |
0 | 669 } |
670 } | |
671 | |
141 | 672 /* |
673 Linux supports static memory binding, therefore the most part of the | |
674 logic dealing with the possible invalid page allocation is effectively | |
675 disabled. Besides there is no notion of the home node in Linux. A | |
676 thread is allowed to migrate freely. Although the scheduler is rather | |
677 reluctant to move threads between the nodes. We check for the current | |
678 node every allocation. And with a high probability a thread stays on | |
679 the same node for some time allowing local access to recently allocated | |
680 objects. | |
681 */ | |
682 | |
0 | 683 HeapWord* MutableNUMASpace::allocate(size_t size) { |
141 | 684 Thread* thr = Thread::current(); |
685 int lgrp_id = thr->lgrp_id(); | |
686 if (lgrp_id == -1 || !os::numa_has_group_homing()) { | |
0 | 687 lgrp_id = os::numa_get_group_id(); |
141 | 688 thr->set_lgrp_id(lgrp_id); |
0 | 689 } |
690 | |
691 int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals); | |
692 | |
693 // It is possible that a new CPU has been hotplugged and | |
694 // we haven't reshaped the space accordingly. | |
695 if (i == -1) { | |
696 i = os::random() % lgrp_spaces()->length(); | |
697 } | |
698 | |
699 MutableSpace *s = lgrp_spaces()->at(i)->space(); | |
700 HeapWord *p = s->allocate(size); | |
701 | |
144
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
702 if (p != NULL) { |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
703 size_t remainder = s->free_in_words(); |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
704 if (remainder < (size_t)oopDesc::header_size() && remainder > 0) { |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
705 s->set_top(s->top() - size); |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
706 p = NULL; |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
707 } |
0 | 708 } |
709 if (p != NULL) { | |
710 if (top() < s->top()) { // Keep _top updated. | |
711 MutableSpace::set_top(s->top()); | |
712 } | |
713 } | |
141 | 714 // Make the page allocation happen here if there is no static binding.. |
715 if (p != NULL && !os::numa_has_static_binding()) { | |
0 | 716 for (HeapWord *i = p; i < p + size; i += os::vm_page_size() >> LogHeapWordSize) { |
717 *(int*)i = 0; | |
718 } | |
719 } | |
720 return p; | |
721 } | |
722 | |
723 // This version is lock-free. | |
724 HeapWord* MutableNUMASpace::cas_allocate(size_t size) { | |
141 | 725 Thread* thr = Thread::current(); |
726 int lgrp_id = thr->lgrp_id(); | |
727 if (lgrp_id == -1 || !os::numa_has_group_homing()) { | |
0 | 728 lgrp_id = os::numa_get_group_id(); |
141 | 729 thr->set_lgrp_id(lgrp_id); |
0 | 730 } |
731 | |
732 int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals); | |
733 // It is possible that a new CPU has been hotplugged and | |
734 // we haven't reshaped the space accordingly. | |
735 if (i == -1) { | |
736 i = os::random() % lgrp_spaces()->length(); | |
737 } | |
738 MutableSpace *s = lgrp_spaces()->at(i)->space(); | |
739 HeapWord *p = s->cas_allocate(size); | |
144
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
740 if (p != NULL) { |
190
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
741 size_t remainder = pointer_delta(s->end(), p + size); |
144
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
742 if (remainder < (size_t)oopDesc::header_size() && remainder > 0) { |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
743 if (s->cas_deallocate(p, size)) { |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
744 // We were the last to allocate and created a fragment less than |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
745 // a minimal object. |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
746 p = NULL; |
190
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
747 } else { |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
748 guarantee(false, "Deallocation should always succeed"); |
144
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
749 } |
0 | 750 } |
751 } | |
752 if (p != NULL) { | |
753 HeapWord* cur_top, *cur_chunk_top = p + size; | |
754 while ((cur_top = top()) < cur_chunk_top) { // Keep _top updated. | |
755 if (Atomic::cmpxchg_ptr(cur_chunk_top, top_addr(), cur_top) == cur_top) { | |
756 break; | |
757 } | |
758 } | |
759 } | |
760 | |
141 | 761 // Make the page allocation happen here if there is no static binding. |
762 if (p != NULL && !os::numa_has_static_binding() ) { | |
0 | 763 for (HeapWord *i = p; i < p + size; i += os::vm_page_size() >> LogHeapWordSize) { |
764 *(int*)i = 0; | |
765 } | |
766 } | |
767 return p; | |
768 } | |
769 | |
770 void MutableNUMASpace::print_short_on(outputStream* st) const { | |
771 MutableSpace::print_short_on(st); | |
772 st->print(" ("); | |
773 for (int i = 0; i < lgrp_spaces()->length(); i++) { | |
774 st->print("lgrp %d: ", lgrp_spaces()->at(i)->lgrp_id()); | |
775 lgrp_spaces()->at(i)->space()->print_short_on(st); | |
776 if (i < lgrp_spaces()->length() - 1) { | |
777 st->print(", "); | |
778 } | |
779 } | |
780 st->print(")"); | |
781 } | |
782 | |
783 void MutableNUMASpace::print_on(outputStream* st) const { | |
784 MutableSpace::print_on(st); | |
785 for (int i = 0; i < lgrp_spaces()->length(); i++) { | |
786 LGRPSpace *ls = lgrp_spaces()->at(i); | |
787 st->print(" lgrp %d", ls->lgrp_id()); | |
788 ls->space()->print_on(st); | |
789 if (NUMAStats) { | |
144
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
790 for (int i = 0; i < lgrp_spaces()->length(); i++) { |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
791 lgrp_spaces()->at(i)->accumulate_statistics(page_size()); |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
792 } |
0 | 793 st->print(" local/remote/unbiased/uncommitted: %dK/%dK/%dK/%dK, large/small pages: %d/%d\n", |
794 ls->space_stats()->_local_space / K, | |
795 ls->space_stats()->_remote_space / K, | |
796 ls->space_stats()->_unbiased_space / K, | |
797 ls->space_stats()->_uncommited_space / K, | |
798 ls->space_stats()->_large_pages, | |
799 ls->space_stats()->_small_pages); | |
800 } | |
801 } | |
802 } | |
803 | |
190
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
804 void MutableNUMASpace::verify(bool allow_dirty) { |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
805 // This can be called after setting an arbitary value to the space's top, |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
806 // so an object can cross the chunk boundary. We ensure the parsablity |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
807 // of the space and just walk the objects in linear fashion. |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
808 ensure_parsability(); |
d1635bf93939
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
144
diff
changeset
|
809 MutableSpace::verify(allow_dirty); |
0 | 810 } |
811 | |
812 // Scan pages and gather stats about page placement and size. | |
813 void MutableNUMASpace::LGRPSpace::accumulate_statistics(size_t page_size) { | |
814 clear_space_stats(); | |
815 char *start = (char*)round_to((intptr_t) space()->bottom(), page_size); | |
816 char* end = (char*)round_down((intptr_t) space()->end(), page_size); | |
817 if (start < end) { | |
818 for (char *p = start; p < end;) { | |
819 os::page_info info; | |
820 if (os::get_page_info(p, &info)) { | |
821 if (info.size > 0) { | |
822 if (info.size > (size_t)os::vm_page_size()) { | |
823 space_stats()->_large_pages++; | |
824 } else { | |
825 space_stats()->_small_pages++; | |
826 } | |
827 if (info.lgrp_id == lgrp_id()) { | |
828 space_stats()->_local_space += info.size; | |
829 } else { | |
830 space_stats()->_remote_space += info.size; | |
831 } | |
832 p += info.size; | |
833 } else { | |
834 p += os::vm_page_size(); | |
835 space_stats()->_uncommited_space += os::vm_page_size(); | |
836 } | |
837 } else { | |
838 return; | |
839 } | |
840 } | |
841 } | |
842 space_stats()->_unbiased_space = pointer_delta(start, space()->bottom(), sizeof(char)) + | |
843 pointer_delta(space()->end(), end, sizeof(char)); | |
844 | |
845 } | |
846 | |
847 // Scan page_count pages and verify if they have the right size and right placement. | |
848 // If invalid pages are found they are freed in hope that subsequent reallocation | |
849 // will be more successful. | |
850 void MutableNUMASpace::LGRPSpace::scan_pages(size_t page_size, size_t page_count) | |
851 { | |
852 char* range_start = (char*)round_to((intptr_t) space()->bottom(), page_size); | |
853 char* range_end = (char*)round_down((intptr_t) space()->end(), page_size); | |
854 | |
855 if (range_start > last_page_scanned() || last_page_scanned() >= range_end) { | |
856 set_last_page_scanned(range_start); | |
857 } | |
858 | |
859 char *scan_start = last_page_scanned(); | |
860 char* scan_end = MIN2(scan_start + page_size * page_count, range_end); | |
861 | |
862 os::page_info page_expected, page_found; | |
863 page_expected.size = page_size; | |
864 page_expected.lgrp_id = lgrp_id(); | |
865 | |
866 char *s = scan_start; | |
867 while (s < scan_end) { | |
868 char *e = os::scan_pages(s, (char*)scan_end, &page_expected, &page_found); | |
869 if (e == NULL) { | |
870 break; | |
871 } | |
872 if (e != scan_end) { | |
873 if ((page_expected.size != page_size || page_expected.lgrp_id != lgrp_id()) | |
874 && page_expected.size != 0) { | |
875 os::free_memory(s, pointer_delta(e, s, sizeof(char))); | |
876 } | |
877 page_expected = page_found; | |
878 } | |
879 s = e; | |
880 } | |
881 | |
882 set_last_page_scanned(scan_end); | |
883 } |