Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/shared/mutableSpace.cpp @ 6294:b0fc02623974
exclude TestPrograms from JaCoCo processing
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 28 Aug 2012 13:55:11 +0200 |
parents | b632e80fc9dc |
children | da91efe96a93 |
rev | line source |
---|---|
0 | 1 /* |
6008 | 2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
579
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
579
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
579
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #ifndef SERIALGC | |
27 #include "gc_implementation/shared/mutableSpace.hpp" | |
28 #include "gc_implementation/shared/spaceDecorator.hpp" | |
29 #include "oops/oop.inline.hpp" | |
30 #include "runtime/safepoint.hpp" | |
31 #include "runtime/thread.hpp" | |
32 #endif | |
0 | 33 |
535
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
34 MutableSpace::MutableSpace(size_t alignment): ImmutableSpace(), _top(NULL), _alignment(alignment) { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
35 assert(MutableSpace::alignment() >= 0 && |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
36 MutableSpace::alignment() % os::vm_page_size() == 0, |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
37 "Space should be aligned"); |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
38 _mangler = new MutableSpaceMangler(this); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
39 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
40 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
41 MutableSpace::~MutableSpace() { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
42 delete _mangler; |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
43 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
44 |
535
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
45 void MutableSpace::numa_setup_pages(MemRegion mr, bool clear_space) { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
46 if (!mr.is_empty()) { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
47 size_t page_size = UseLargePages ? alignment() : os::vm_page_size(); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
48 HeapWord *start = (HeapWord*)round_to((intptr_t) mr.start(), page_size); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
49 HeapWord *end = (HeapWord*)round_down((intptr_t) mr.end(), page_size); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
50 if (end > start) { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
51 size_t size = pointer_delta(end, start, sizeof(char)); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
52 if (clear_space) { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
53 // Prefer page reallocation to migration. |
4734
20bfb6d15a94
7124829: NUMA: memory leak on Linux with large pages
iveresov
parents:
1972
diff
changeset
|
54 os::free_memory((char*)start, size, page_size); |
535
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
55 } |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
56 os::numa_make_global((char*)start, size); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
57 } |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
58 } |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
59 } |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
60 |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
61 void MutableSpace::pretouch_pages(MemRegion mr) { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
62 for (volatile char *p = (char*)mr.start(); p < (char*)mr.end(); p += os::vm_page_size()) { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
63 char t = *p; *p = t; |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
64 } |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
65 } |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
66 |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
67 void MutableSpace::initialize(MemRegion mr, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
68 bool clear_space, |
535
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
69 bool mangle_space, |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
70 bool setup_pages) { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
71 |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
72 assert(Universe::on_page_boundary(mr.start()) && Universe::on_page_boundary(mr.end()), |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
73 "invalid space boundaries"); |
0 | 74 |
535
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
75 if (setup_pages && (UseNUMA || AlwaysPreTouch)) { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
76 // The space may move left and right or expand/shrink. |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
77 // We'd like to enforce the desired page placement. |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
78 MemRegion head, tail; |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
79 if (last_setup_region().is_empty()) { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
80 // If it's the first initialization don't limit the amount of work. |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
81 head = mr; |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
82 tail = MemRegion(mr.end(), mr.end()); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
83 } else { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
84 // Is there an intersection with the address space? |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
85 MemRegion intersection = last_setup_region().intersection(mr); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
86 if (intersection.is_empty()) { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
87 intersection = MemRegion(mr.end(), mr.end()); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
88 } |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
89 // All the sizes below are in words. |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
90 size_t head_size = 0, tail_size = 0; |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
91 if (mr.start() <= intersection.start()) { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
92 head_size = pointer_delta(intersection.start(), mr.start()); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
93 } |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
94 if(intersection.end() <= mr.end()) { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
95 tail_size = pointer_delta(mr.end(), intersection.end()); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
96 } |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
97 // Limit the amount of page manipulation if necessary. |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
98 if (NUMASpaceResizeRate > 0 && !AlwaysPreTouch) { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
99 const size_t change_size = head_size + tail_size; |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
100 const float setup_rate_words = NUMASpaceResizeRate >> LogBytesPerWord; |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
101 head_size = MIN2((size_t)(setup_rate_words * head_size / change_size), |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
102 head_size); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
103 tail_size = MIN2((size_t)(setup_rate_words * tail_size / change_size), |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
104 tail_size); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
105 } |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
106 head = MemRegion(intersection.start() - head_size, intersection.start()); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
107 tail = MemRegion(intersection.end(), intersection.end() + tail_size); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
108 } |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
109 assert(mr.contains(head) && mr.contains(tail), "Sanity"); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
110 |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
111 if (UseNUMA) { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
112 numa_setup_pages(head, clear_space); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
113 numa_setup_pages(tail, clear_space); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
114 } |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
115 |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
116 if (AlwaysPreTouch) { |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
117 pretouch_pages(head); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
118 pretouch_pages(tail); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
119 } |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
120 |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
121 // Remember where we stopped so that we can continue later. |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
122 set_last_setup_region(MemRegion(head.start(), tail.end())); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
123 } |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
124 |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
125 set_bottom(mr.start()); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
126 set_end(mr.end()); |
0 | 127 |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
128 if (clear_space) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
129 clear(mangle_space); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
130 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
131 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
132 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
133 void MutableSpace::clear(bool mangle_space) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
134 set_top(bottom()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
135 if (ZapUnusedHeapArea && mangle_space) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
136 mangle_unused_area(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
137 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
138 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
139 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
140 #ifndef PRODUCT |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
141 void MutableSpace::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
|
142 mangler()->check_mangled_unused_area(limit); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
143 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
144 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
145 void MutableSpace::check_mangled_unused_area_complete() { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
146 mangler()->check_mangled_unused_area_complete(); |
0 | 147 } |
148 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
149 // Mangle only the unused space that has not previously |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
150 // been mangled and that has not been allocated since being |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
151 // mangled. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
152 void MutableSpace::mangle_unused_area() { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
153 mangler()->mangle_unused_area(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
154 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
155 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
156 void MutableSpace::mangle_unused_area_complete() { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
157 mangler()->mangle_unused_area_complete(); |
0 | 158 } |
159 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
160 void MutableSpace::mangle_region(MemRegion mr) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
161 SpaceMangler::mangle_region(mr); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
162 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
163 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
164 void MutableSpace::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
|
165 mangler()->set_top_for_allocations(v); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
166 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
167 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
168 void MutableSpace::set_top_for_allocations() { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
169 mangler()->set_top_for_allocations(top()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
170 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
171 #endif |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
190
diff
changeset
|
172 |
0 | 173 // This version requires locking. */ |
174 HeapWord* MutableSpace::allocate(size_t size) { | |
175 assert(Heap_lock->owned_by_self() || | |
176 (SafepointSynchronize::is_at_safepoint() && | |
177 Thread::current()->is_VM_thread()), | |
178 "not locked"); | |
179 HeapWord* obj = top(); | |
180 if (pointer_delta(end(), obj) >= size) { | |
181 HeapWord* new_top = obj + size; | |
182 set_top(new_top); | |
183 assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top), | |
184 "checking alignment"); | |
185 return obj; | |
186 } else { | |
187 return NULL; | |
188 } | |
189 } | |
190 | |
191 // This version is lock-free. | |
192 HeapWord* MutableSpace::cas_allocate(size_t size) { | |
193 do { | |
194 HeapWord* obj = top(); | |
195 if (pointer_delta(end(), obj) >= size) { | |
196 HeapWord* new_top = obj + size; | |
197 HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj); | |
198 // result can be one of two: | |
199 // the old top value: the exchange succeeded | |
200 // otherwise: the new value of the top is returned. | |
201 if (result != obj) { | |
202 continue; // another thread beat us to the allocation, try again | |
203 } | |
204 assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top), | |
205 "checking alignment"); | |
206 return obj; | |
207 } else { | |
208 return NULL; | |
209 } | |
210 } while (true); | |
211 } | |
212 | |
213 // Try to deallocate previous allocation. Returns true upon success. | |
214 bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) { | |
215 HeapWord* expected_top = obj + size; | |
216 return (HeapWord*)Atomic::cmpxchg_ptr(obj, top_addr(), expected_top) == expected_top; | |
217 } | |
218 | |
219 void MutableSpace::oop_iterate(OopClosure* cl) { | |
220 HeapWord* obj_addr = bottom(); | |
221 HeapWord* t = top(); | |
222 // Could call objects iterate, but this is easier. | |
223 while (obj_addr < t) { | |
224 obj_addr += oop(obj_addr)->oop_iterate(cl); | |
225 } | |
226 } | |
227 | |
228 void MutableSpace::object_iterate(ObjectClosure* cl) { | |
229 HeapWord* p = bottom(); | |
230 while (p < top()) { | |
231 cl->do_object(oop(p)); | |
232 p += oop(p)->size(); | |
233 } | |
234 } | |
235 | |
236 void MutableSpace::print_short() const { print_short_on(tty); } | |
237 void MutableSpace::print_short_on( outputStream* st) const { | |
238 st->print(" space " SIZE_FORMAT "K, %d%% used", capacity_in_bytes() / K, | |
239 (int) ((double) used_in_bytes() * 100 / capacity_in_bytes())); | |
240 } | |
241 | |
242 void MutableSpace::print() const { print_on(tty); } | |
243 void MutableSpace::print_on(outputStream* st) const { | |
244 MutableSpace::print_short_on(st); | |
245 st->print_cr(" [" INTPTR_FORMAT "," INTPTR_FORMAT "," INTPTR_FORMAT ")", | |
246 bottom(), top(), end()); | |
247 } | |
248 | |
6008 | 249 void MutableSpace::verify() { |
0 | 250 HeapWord* p = bottom(); |
251 HeapWord* t = top(); | |
252 HeapWord* prev_p = NULL; | |
253 while (p < t) { | |
254 oop(p)->verify(); | |
255 prev_p = p; | |
256 p += oop(p)->size(); | |
257 } | |
258 guarantee(p == top(), "end of last object must match end of space"); | |
259 } |