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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/parallel/mutableNUMASpace.hpp"
27 #include "gc/shared/collectedHeap.hpp"
28 #include "gc/shared/spaceDecorator.hpp"
29 #include "oops/oop.inline.hpp"
30 #include "runtime/atomic.hpp"
31 #include "runtime/thread.inline.hpp"
32 #include "utilities/align.hpp"
33
34 MutableNUMASpace::MutableNUMASpace(size_t alignment) : MutableSpace(alignment), _must_use_large_pages(false) {
35 _lgrp_spaces = new (ResourceObj::C_HEAP, mtGC) GrowableArray<LGRPSpace*>(0, true);
36 _page_size = os::vm_page_size();
37 _adaptation_cycles = 0;
38 _samples_count = 0;
39
40 #ifdef LINUX
41 // Changing the page size can lead to freeing of memory. When using large pages
42 // and the memory has been both reserved and committed, Linux does not support
43 // freeing parts of it.
44 if (UseLargePages && !os::can_commit_large_page_memory()) {
45 _must_use_large_pages = true;
46 }
47 #endif // LINUX
48
49 update_layout(true);
50 }
51
270 // Remove spaces for the removed nodes.
271 for (int i = 0; i < lgrp_spaces()->length();) {
272 bool found = false;
273 for (int j = 0; j < lgrp_num; j++) {
274 if (lgrp_spaces()->at(i)->lgrp_id() == lgrp_ids[j]) {
275 found = true;
276 break;
277 }
278 }
279 if (!found) {
280 delete lgrp_spaces()->at(i);
281 lgrp_spaces()->remove_at(i);
282 } else {
283 i++;
284 }
285 }
286
287 FREE_C_HEAP_ARRAY(int, lgrp_ids);
288
289 if (changed) {
290 for (JavaThread *thread = Threads::first(); thread; thread = thread->next()) {
291 thread->set_lgrp_id(-1);
292 }
293 }
294 return true;
295 }
296 return false;
297 }
298
299 // Bias region towards the first-touching lgrp. Set the right page sizes.
300 void MutableNUMASpace::bias_region(MemRegion mr, int lgrp_id) {
301 HeapWord *start = align_up(mr.start(), page_size());
302 HeapWord *end = align_down(mr.end(), page_size());
303 if (end > start) {
304 MemRegion aligned_region(start, end);
305 assert((intptr_t)aligned_region.start() % page_size() == 0 &&
306 (intptr_t)aligned_region.byte_size() % page_size() == 0, "Bad alignment");
307 assert(region().contains(aligned_region), "Sanity");
308 // First we tell the OS which page size we want in the given range. The underlying
309 // large page can be broken down if we require small pages.
310 os::realign_memory((char*)aligned_region.start(), aligned_region.byte_size(), page_size());
|
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/parallel/mutableNUMASpace.hpp"
27 #include "gc/shared/collectedHeap.hpp"
28 #include "gc/shared/spaceDecorator.hpp"
29 #include "oops/oop.inline.hpp"
30 #include "runtime/atomic.hpp"
31 #include "runtime/thread.inline.hpp"
32 #include "runtime/threadSMR.hpp"
33 #include "utilities/align.hpp"
34
35 MutableNUMASpace::MutableNUMASpace(size_t alignment) : MutableSpace(alignment), _must_use_large_pages(false) {
36 _lgrp_spaces = new (ResourceObj::C_HEAP, mtGC) GrowableArray<LGRPSpace*>(0, true);
37 _page_size = os::vm_page_size();
38 _adaptation_cycles = 0;
39 _samples_count = 0;
40
41 #ifdef LINUX
42 // Changing the page size can lead to freeing of memory. When using large pages
43 // and the memory has been both reserved and committed, Linux does not support
44 // freeing parts of it.
45 if (UseLargePages && !os::can_commit_large_page_memory()) {
46 _must_use_large_pages = true;
47 }
48 #endif // LINUX
49
50 update_layout(true);
51 }
52
271 // Remove spaces for the removed nodes.
272 for (int i = 0; i < lgrp_spaces()->length();) {
273 bool found = false;
274 for (int j = 0; j < lgrp_num; j++) {
275 if (lgrp_spaces()->at(i)->lgrp_id() == lgrp_ids[j]) {
276 found = true;
277 break;
278 }
279 }
280 if (!found) {
281 delete lgrp_spaces()->at(i);
282 lgrp_spaces()->remove_at(i);
283 } else {
284 i++;
285 }
286 }
287
288 FREE_C_HEAP_ARRAY(int, lgrp_ids);
289
290 if (changed) {
291 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) {
292 thread->set_lgrp_id(-1);
293 }
294 }
295 return true;
296 }
297 return false;
298 }
299
300 // Bias region towards the first-touching lgrp. Set the right page sizes.
301 void MutableNUMASpace::bias_region(MemRegion mr, int lgrp_id) {
302 HeapWord *start = align_up(mr.start(), page_size());
303 HeapWord *end = align_down(mr.end(), page_size());
304 if (end > start) {
305 MemRegion aligned_region(start, end);
306 assert((intptr_t)aligned_region.start() % page_size() == 0 &&
307 (intptr_t)aligned_region.byte_size() % page_size() == 0, "Bad alignment");
308 assert(region().contains(aligned_region), "Sanity");
309 // First we tell the OS which page size we want in the given range. The underlying
310 // large page can be broken down if we require small pages.
311 os::realign_memory((char*)aligned_region.start(), aligned_region.byte_size(), page_size());
|