author | jmasa |
Mon, 28 Jul 2008 15:30:23 -0700 | |
changeset 977 | b90650e2a9f7 |
parent 670 | ddf3e9583f2f |
parent 971 | f0b20be4165d |
child 1911 | b7cfe7eb809c |
permissions | -rw-r--r-- |
1 | 1 |
/* |
670 | 2 |
* Copyright 2001-2008 Sun Microsystems, Inc. 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 |
* |
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 |
* have any questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
# include "incls/_precompiled.incl" |
|
26 |
# include "incls/_mutableSpace.cpp.incl" |
|
27 |
||
971
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
28 |
MutableSpace::MutableSpace(): ImmutableSpace(), _top(NULL) { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
29 |
_mangler = new MutableSpaceMangler(this); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
30 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
31 |
|
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
32 |
MutableSpace::~MutableSpace() { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
33 |
delete _mangler; |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
34 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
35 |
|
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
36 |
void MutableSpace::initialize(MemRegion mr, |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
37 |
bool clear_space, |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
38 |
bool mangle_space) { |
1 | 39 |
HeapWord* bottom = mr.start(); |
40 |
HeapWord* end = mr.end(); |
|
41 |
||
42 |
assert(Universe::on_page_boundary(bottom) && Universe::on_page_boundary(end), |
|
43 |
"invalid space boundaries"); |
|
44 |
set_bottom(bottom); |
|
45 |
set_end(end); |
|
46 |
||
971
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
47 |
if (clear_space) { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
48 |
clear(mangle_space); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
49 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
50 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
51 |
|
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
52 |
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
|
53 |
set_top(bottom()); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
54 |
if (ZapUnusedHeapArea && mangle_space) { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
55 |
mangle_unused_area(); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
56 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
57 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
58 |
|
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
59 |
#ifndef PRODUCT |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
60 |
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
|
61 |
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
|
62 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
63 |
|
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
64 |
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
|
65 |
mangler()->check_mangled_unused_area_complete(); |
1 | 66 |
} |
67 |
||
971
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
68 |
// 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
|
69 |
// 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
|
70 |
// mangled. |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
71 |
void MutableSpace::mangle_unused_area() { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
72 |
mangler()->mangle_unused_area(); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
73 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
74 |
|
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
75 |
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
|
76 |
mangler()->mangle_unused_area_complete(); |
1 | 77 |
} |
78 |
||
971
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
79 |
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
|
80 |
SpaceMangler::mangle_region(mr); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
81 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
82 |
|
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
83 |
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
|
84 |
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
|
85 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
86 |
|
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
87 |
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
|
88 |
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
|
89 |
} |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
90 |
#endif |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
616
diff
changeset
|
91 |
|
1 | 92 |
// This version requires locking. */ |
93 |
HeapWord* MutableSpace::allocate(size_t size) { |
|
94 |
assert(Heap_lock->owned_by_self() || |
|
95 |
(SafepointSynchronize::is_at_safepoint() && |
|
96 |
Thread::current()->is_VM_thread()), |
|
97 |
"not locked"); |
|
98 |
HeapWord* obj = top(); |
|
99 |
if (pointer_delta(end(), obj) >= size) { |
|
100 |
HeapWord* new_top = obj + size; |
|
101 |
set_top(new_top); |
|
102 |
assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top), |
|
103 |
"checking alignment"); |
|
104 |
return obj; |
|
105 |
} else { |
|
106 |
return NULL; |
|
107 |
} |
|
108 |
} |
|
109 |
||
110 |
// This version is lock-free. |
|
111 |
HeapWord* MutableSpace::cas_allocate(size_t size) { |
|
112 |
do { |
|
113 |
HeapWord* obj = top(); |
|
114 |
if (pointer_delta(end(), obj) >= size) { |
|
115 |
HeapWord* new_top = obj + size; |
|
116 |
HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj); |
|
117 |
// result can be one of two: |
|
118 |
// the old top value: the exchange succeeded |
|
119 |
// otherwise: the new value of the top is returned. |
|
120 |
if (result != obj) { |
|
121 |
continue; // another thread beat us to the allocation, try again |
|
122 |
} |
|
123 |
assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top), |
|
124 |
"checking alignment"); |
|
125 |
return obj; |
|
126 |
} else { |
|
127 |
return NULL; |
|
128 |
} |
|
129 |
} while (true); |
|
130 |
} |
|
131 |
||
132 |
// Try to deallocate previous allocation. Returns true upon success. |
|
133 |
bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) { |
|
134 |
HeapWord* expected_top = obj + size; |
|
135 |
return (HeapWord*)Atomic::cmpxchg_ptr(obj, top_addr(), expected_top) == expected_top; |
|
136 |
} |
|
137 |
||
138 |
void MutableSpace::oop_iterate(OopClosure* cl) { |
|
139 |
HeapWord* obj_addr = bottom(); |
|
140 |
HeapWord* t = top(); |
|
141 |
// Could call objects iterate, but this is easier. |
|
142 |
while (obj_addr < t) { |
|
143 |
obj_addr += oop(obj_addr)->oop_iterate(cl); |
|
144 |
} |
|
145 |
} |
|
146 |
||
147 |
void MutableSpace::object_iterate(ObjectClosure* cl) { |
|
148 |
HeapWord* p = bottom(); |
|
149 |
while (p < top()) { |
|
150 |
cl->do_object(oop(p)); |
|
151 |
p += oop(p)->size(); |
|
152 |
} |
|
153 |
} |
|
154 |
||
155 |
void MutableSpace::print_short() const { print_short_on(tty); } |
|
156 |
void MutableSpace::print_short_on( outputStream* st) const { |
|
157 |
st->print(" space " SIZE_FORMAT "K, %d%% used", capacity_in_bytes() / K, |
|
158 |
(int) ((double) used_in_bytes() * 100 / capacity_in_bytes())); |
|
159 |
} |
|
160 |
||
161 |
void MutableSpace::print() const { print_on(tty); } |
|
162 |
void MutableSpace::print_on(outputStream* st) const { |
|
163 |
MutableSpace::print_short_on(st); |
|
164 |
st->print_cr(" [" INTPTR_FORMAT "," INTPTR_FORMAT "," INTPTR_FORMAT ")", |
|
165 |
bottom(), top(), end()); |
|
166 |
} |
|
167 |
||
616
4f2dfc0168e2
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents:
1
diff
changeset
|
168 |
void MutableSpace::verify(bool allow_dirty) { |
1 | 169 |
HeapWord* p = bottom(); |
170 |
HeapWord* t = top(); |
|
171 |
HeapWord* prev_p = NULL; |
|
172 |
while (p < t) { |
|
173 |
oop(p)->verify(); |
|
174 |
prev_p = p; |
|
175 |
p += oop(p)->size(); |
|
176 |
} |
|
177 |
guarantee(p == top(), "end of last object must match end of space"); |
|
178 |
} |