author | hseigel |
Tue, 31 Jul 2018 14:24:10 -0400 | |
changeset 51268 | 4ac20e5f96ce |
parent 50800 | 6da12aa23b88 |
child 51332 | c25572739e7c |
permissions | -rw-r--r-- |
1 | 1 |
/* |
51268
4ac20e5f96ce
8202171: Some oopDesc functions compare this with NULL
hseigel
parents:
50800
diff
changeset
|
2 |
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2105
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2105
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2105
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
30764 | 26 |
#include "gc/parallel/mutableSpace.hpp" |
27 |
#include "gc/shared/spaceDecorator.hpp" |
|
50752 | 28 |
#include "memory/iterator.inline.hpp" |
30764 | 29 |
#include "oops/oop.inline.hpp" |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
37046
diff
changeset
|
30 |
#include "runtime/atomic.hpp" |
7397 | 31 |
#include "runtime/safepoint.hpp" |
32 |
#include "runtime/thread.hpp" |
|
46625 | 33 |
#include "utilities/align.hpp" |
30764 | 34 |
#include "utilities/macros.hpp" |
1 | 35 |
|
1911
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
36 |
MutableSpace::MutableSpace(size_t alignment): ImmutableSpace(), _top(NULL), _alignment(alignment) { |
29580
a67a581cfe11
8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents:
28208
diff
changeset
|
37 |
assert(MutableSpace::alignment() % os::vm_page_size() == 0, |
1911
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
38 |
"Space should be aligned"); |
971
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
39 |
_mangler = new MutableSpaceMangler(this); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
40 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
41 |
|
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
42 |
MutableSpace::~MutableSpace() { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
43 |
delete _mangler; |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
44 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
45 |
|
1911
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
46 |
void MutableSpace::numa_setup_pages(MemRegion mr, bool clear_space) { |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
47 |
if (!mr.is_empty()) { |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
48 |
size_t page_size = UseLargePages ? alignment() : os::vm_page_size(); |
46620
750c6edff33b
8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents:
46619
diff
changeset
|
49 |
HeapWord *start = align_up(mr.start(), page_size); |
750c6edff33b
8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents:
46619
diff
changeset
|
50 |
HeapWord *end = align_down(mr.end(), page_size); |
1911
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
51 |
if (end > start) { |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
52 |
size_t size = pointer_delta(end, start, sizeof(char)); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
53 |
if (clear_space) { |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
54 |
// Prefer page reallocation to migration. |
11402
739e52129c84
7124829: NUMA: memory leak on Linux with large pages
iveresov
parents:
7397
diff
changeset
|
55 |
os::free_memory((char*)start, size, page_size); |
1911
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
56 |
} |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
57 |
os::numa_make_global((char*)start, size); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
58 |
} |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
59 |
} |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
60 |
} |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
61 |
|
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
62 |
void MutableSpace::pretouch_pages(MemRegion mr) { |
37046
88fbf4e7b9c6
8151414: os::pretouch_memory should take void* instead of char*
tschatzl
parents:
32606
diff
changeset
|
63 |
os::pretouch_memory(mr.start(), mr.end()); |
1911
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
64 |
} |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
65 |
|
971
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
66 |
void MutableSpace::initialize(MemRegion mr, |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
67 |
bool clear_space, |
1911
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
68 |
bool mangle_space, |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
69 |
bool setup_pages) { |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
70 |
|
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
71 |
assert(Universe::on_page_boundary(mr.start()) && Universe::on_page_boundary(mr.end()), |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
72 |
"invalid space boundaries"); |
1 | 73 |
|
1911
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
74 |
if (setup_pages && (UseNUMA || AlwaysPreTouch)) { |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
75 |
// The space may move left and right or expand/shrink. |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
76 |
// We'd like to enforce the desired page placement. |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
77 |
MemRegion head, tail; |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
78 |
if (last_setup_region().is_empty()) { |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
79 |
// If it's the first initialization don't limit the amount of work. |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
80 |
head = mr; |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
81 |
tail = MemRegion(mr.end(), mr.end()); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
82 |
} else { |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
83 |
// Is there an intersection with the address space? |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
84 |
MemRegion intersection = last_setup_region().intersection(mr); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
85 |
if (intersection.is_empty()) { |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
86 |
intersection = MemRegion(mr.end(), mr.end()); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
87 |
} |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
88 |
// All the sizes below are in words. |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
89 |
size_t head_size = 0, tail_size = 0; |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
90 |
if (mr.start() <= intersection.start()) { |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
91 |
head_size = pointer_delta(intersection.start(), mr.start()); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
92 |
} |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
93 |
if(intersection.end() <= mr.end()) { |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
94 |
tail_size = pointer_delta(mr.end(), intersection.end()); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
95 |
} |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
96 |
// Limit the amount of page manipulation if necessary. |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
97 |
if (NUMASpaceResizeRate > 0 && !AlwaysPreTouch) { |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
98 |
const size_t change_size = head_size + tail_size; |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
99 |
const float setup_rate_words = NUMASpaceResizeRate >> LogBytesPerWord; |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
100 |
head_size = MIN2((size_t)(setup_rate_words * head_size / change_size), |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
101 |
head_size); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
102 |
tail_size = MIN2((size_t)(setup_rate_words * tail_size / change_size), |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
103 |
tail_size); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
104 |
} |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
105 |
head = MemRegion(intersection.start() - head_size, intersection.start()); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
106 |
tail = MemRegion(intersection.end(), intersection.end() + tail_size); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
107 |
} |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
108 |
assert(mr.contains(head) && mr.contains(tail), "Sanity"); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
109 |
|
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
110 |
if (UseNUMA) { |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
111 |
numa_setup_pages(head, clear_space); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
112 |
numa_setup_pages(tail, clear_space); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
113 |
} |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
114 |
|
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
115 |
if (AlwaysPreTouch) { |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
116 |
pretouch_pages(head); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
117 |
pretouch_pages(tail); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
118 |
} |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
119 |
|
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
120 |
// Remember where we stopped so that we can continue later. |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
121 |
set_last_setup_region(MemRegion(head.start(), tail.end())); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
122 |
} |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
123 |
|
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
124 |
set_bottom(mr.start()); |
b7cfe7eb809c
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
977
diff
changeset
|
125 |
set_end(mr.end()); |
1 | 126 |
|
971
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
127 |
if (clear_space) { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
128 |
clear(mangle_space); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
129 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
130 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
131 |
|
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
132 |
void MutableSpace::clear(bool mangle_space) { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
133 |
set_top(bottom()); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
134 |
if (ZapUnusedHeapArea && mangle_space) { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
135 |
mangle_unused_area(); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
136 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
137 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
138 |
|
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
139 |
#ifndef PRODUCT |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
140 |
void MutableSpace::check_mangled_unused_area(HeapWord* limit) { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
141 |
mangler()->check_mangled_unused_area(limit); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
142 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
143 |
|
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
144 |
void MutableSpace::check_mangled_unused_area_complete() { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
145 |
mangler()->check_mangled_unused_area_complete(); |
1 | 146 |
} |
147 |
||
971
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
148 |
// Mangle only the unused space that has not previously |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
149 |
// been mangled and that has not been allocated since being |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
150 |
// mangled. |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
151 |
void MutableSpace::mangle_unused_area() { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
152 |
mangler()->mangle_unused_area(); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
153 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
154 |
|
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
155 |
void MutableSpace::mangle_unused_area_complete() { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
156 |
mangler()->mangle_unused_area_complete(); |
1 | 157 |
} |
158 |
||
971
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
159 |
void MutableSpace::mangle_region(MemRegion mr) { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
160 |
SpaceMangler::mangle_region(mr); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
161 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
162 |
|
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
163 |
void MutableSpace::set_top_for_allocations(HeapWord* v) { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
164 |
mangler()->set_top_for_allocations(v); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
165 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
166 |
|
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
167 |
void MutableSpace::set_top_for_allocations() { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
168 |
mangler()->set_top_for_allocations(top()); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
169 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
170 |
#endif |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
171 |
|
1 | 172 |
// This version requires locking. */ |
173 |
HeapWord* MutableSpace::allocate(size_t size) { |
|
174 |
assert(Heap_lock->owned_by_self() || |
|
175 |
(SafepointSynchronize::is_at_safepoint() && |
|
176 |
Thread::current()->is_VM_thread()), |
|
177 |
"not locked"); |
|
178 |
HeapWord* obj = top(); |
|
179 |
if (pointer_delta(end(), obj) >= size) { |
|
180 |
HeapWord* new_top = obj + size; |
|
181 |
set_top(new_top); |
|
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46565
diff
changeset
|
182 |
assert(is_object_aligned(obj) && is_object_aligned(new_top), |
1 | 183 |
"checking alignment"); |
184 |
return obj; |
|
185 |
} else { |
|
186 |
return NULL; |
|
187 |
} |
|
188 |
} |
|
189 |
||
190 |
// This version is lock-free. |
|
191 |
HeapWord* MutableSpace::cas_allocate(size_t size) { |
|
192 |
do { |
|
193 |
HeapWord* obj = top(); |
|
194 |
if (pointer_delta(end(), obj) >= size) { |
|
195 |
HeapWord* new_top = obj + size; |
|
47634
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47216
diff
changeset
|
196 |
HeapWord* result = Atomic::cmpxchg(new_top, top_addr(), obj); |
1 | 197 |
// result can be one of two: |
198 |
// the old top value: the exchange succeeded |
|
199 |
// otherwise: the new value of the top is returned. |
|
200 |
if (result != obj) { |
|
201 |
continue; // another thread beat us to the allocation, try again |
|
202 |
} |
|
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46565
diff
changeset
|
203 |
assert(is_object_aligned(obj) && is_object_aligned(new_top), |
1 | 204 |
"checking alignment"); |
205 |
return obj; |
|
206 |
} else { |
|
207 |
return NULL; |
|
208 |
} |
|
209 |
} while (true); |
|
210 |
} |
|
211 |
||
212 |
// Try to deallocate previous allocation. Returns true upon success. |
|
213 |
bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) { |
|
214 |
HeapWord* expected_top = obj + size; |
|
47634
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47216
diff
changeset
|
215 |
return Atomic::cmpxchg(obj, top_addr(), expected_top) == expected_top; |
1 | 216 |
} |
217 |
||
50800
6da12aa23b88
8205607: Use oop_iterate instead of oop_iterate_no_header
stefank
parents:
50752
diff
changeset
|
218 |
void MutableSpace::oop_iterate(OopIterateClosure* cl) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12379
diff
changeset
|
219 |
HeapWord* obj_addr = bottom(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12379
diff
changeset
|
220 |
HeapWord* t = top(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12379
diff
changeset
|
221 |
// Could call objects iterate, but this is easier. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12379
diff
changeset
|
222 |
while (obj_addr < t) { |
50800
6da12aa23b88
8205607: Use oop_iterate instead of oop_iterate_no_header
stefank
parents:
50752
diff
changeset
|
223 |
obj_addr += oop(obj_addr)->oop_iterate_size(cl); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12379
diff
changeset
|
224 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12379
diff
changeset
|
225 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
12379
diff
changeset
|
226 |
|
1 | 227 |
void MutableSpace::object_iterate(ObjectClosure* cl) { |
228 |
HeapWord* p = bottom(); |
|
229 |
while (p < top()) { |
|
230 |
cl->do_object(oop(p)); |
|
231 |
p += oop(p)->size(); |
|
232 |
} |
|
233 |
} |
|
234 |
||
235 |
void MutableSpace::print_short() const { print_short_on(tty); } |
|
236 |
void MutableSpace::print_short_on( outputStream* st) const { |
|
237 |
st->print(" space " SIZE_FORMAT "K, %d%% used", capacity_in_bytes() / K, |
|
238 |
(int) ((double) used_in_bytes() * 100 / capacity_in_bytes())); |
|
239 |
} |
|
240 |
||
241 |
void MutableSpace::print() const { print_on(tty); } |
|
242 |
void MutableSpace::print_on(outputStream* st) const { |
|
243 |
MutableSpace::print_short_on(st); |
|
244 |
st->print_cr(" [" INTPTR_FORMAT "," INTPTR_FORMAT "," INTPTR_FORMAT ")", |
|
29800
fa5f7a2bf717
8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
29580
diff
changeset
|
245 |
p2i(bottom()), p2i(top()), p2i(end())); |
1 | 246 |
} |
247 |
||
12379 | 248 |
void MutableSpace::verify() { |
1 | 249 |
HeapWord* p = bottom(); |
250 |
HeapWord* t = top(); |
|
251 |
HeapWord* prev_p = NULL; |
|
252 |
while (p < t) { |
|
51268
4ac20e5f96ce
8202171: Some oopDesc functions compare this with NULL
hseigel
parents:
50800
diff
changeset
|
253 |
oopDesc::verify(oop(p)); |
1 | 254 |
prev_p = p; |
255 |
p += oop(p)->size(); |
|
256 |
} |
|
257 |
guarantee(p == top(), "end of last object must match end of space"); |
|
258 |
} |