annotate src/share/vm/gc_implementation/shared/mutableSpace.cpp @ 269:850fdf70db2b

Merge
author jmasa
date Mon, 28 Jul 2008 15:30:23 -0700
parents d1605aabd0a1 12eea04c8b06
children 4e400c36026f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
196
d1605aabd0a1 6719955: Update copyright year
xdono
parents: 190
diff changeset
2 * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_mutableSpace.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
263
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
28 MutableSpace::MutableSpace(): ImmutableSpace(), _top(NULL) {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
29 _mangler = new MutableSpaceMangler(this);
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
30 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
31
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
32 MutableSpace::~MutableSpace() {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
33 delete _mangler;
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
34 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
35
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
36 void MutableSpace::initialize(MemRegion mr,
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
37 bool clear_space,
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
38 bool mangle_space) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
39 HeapWord* bottom = mr.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
40 HeapWord* end = mr.end();
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 assert(Universe::on_page_boundary(bottom) && Universe::on_page_boundary(end),
a61af66fc99e Initial load
duke
parents:
diff changeset
43 "invalid space boundaries");
a61af66fc99e Initial load
duke
parents:
diff changeset
44 set_bottom(bottom);
a61af66fc99e Initial load
duke
parents:
diff changeset
45 set_end(end);
a61af66fc99e Initial load
duke
parents:
diff changeset
46
263
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
47 if (clear_space) {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
48 clear(mangle_space);
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 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
51
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
52 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
53 set_top(bottom());
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
54 if (ZapUnusedHeapArea && mangle_space) {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
55 mangle_unused_area();
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
56 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
57 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
58
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
59 #ifndef PRODUCT
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
60 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
61 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
62 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
63
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
64 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
65 mangler()->check_mangled_unused_area_complete();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
263
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
68 // 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
69 // 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
70 // mangled.
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
71 void MutableSpace::mangle_unused_area() {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
72 mangler()->mangle_unused_area();
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
73 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
74
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
75 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
76 mangler()->mangle_unused_area_complete();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
263
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
79 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
80 SpaceMangler::mangle_region(mr);
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
81 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
82
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
83 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
84 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
85 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
86
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
87 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
88 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
89 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
90 #endif
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 190
diff changeset
91
0
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // This version requires locking. */
a61af66fc99e Initial load
duke
parents:
diff changeset
93 HeapWord* MutableSpace::allocate(size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 assert(Heap_lock->owned_by_self() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
95 (SafepointSynchronize::is_at_safepoint() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
96 Thread::current()->is_VM_thread()),
a61af66fc99e Initial load
duke
parents:
diff changeset
97 "not locked");
a61af66fc99e Initial load
duke
parents:
diff changeset
98 HeapWord* obj = top();
a61af66fc99e Initial load
duke
parents:
diff changeset
99 if (pointer_delta(end(), obj) >= size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 HeapWord* new_top = obj + size;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 set_top(new_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
102 assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
a61af66fc99e Initial load
duke
parents:
diff changeset
103 "checking alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
104 return obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // This version is lock-free.
a61af66fc99e Initial load
duke
parents:
diff changeset
111 HeapWord* MutableSpace::cas_allocate(size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 HeapWord* obj = top();
a61af66fc99e Initial load
duke
parents:
diff changeset
114 if (pointer_delta(end(), obj) >= size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 HeapWord* new_top = obj + size;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // result can be one of two:
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // the old top value: the exchange succeeded
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // otherwise: the new value of the top is returned.
a61af66fc99e Initial load
duke
parents:
diff changeset
120 if (result != obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 continue; // another thread beat us to the allocation, try again
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
a61af66fc99e Initial load
duke
parents:
diff changeset
124 "checking alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
125 return obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 } while (true);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // Try to deallocate previous allocation. Returns true upon success.
a61af66fc99e Initial load
duke
parents:
diff changeset
133 bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 HeapWord* expected_top = obj + size;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return (HeapWord*)Atomic::cmpxchg_ptr(obj, top_addr(), expected_top) == expected_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 void MutableSpace::oop_iterate(OopClosure* cl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 HeapWord* obj_addr = bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 HeapWord* t = top();
a61af66fc99e Initial load
duke
parents:
diff changeset
141 // Could call objects iterate, but this is easier.
a61af66fc99e Initial load
duke
parents:
diff changeset
142 while (obj_addr < t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 obj_addr += oop(obj_addr)->oop_iterate(cl);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 void MutableSpace::object_iterate(ObjectClosure* cl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 HeapWord* p = bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
149 while (p < top()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 cl->do_object(oop(p));
a61af66fc99e Initial load
duke
parents:
diff changeset
151 p += oop(p)->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 void MutableSpace::print_short() const { print_short_on(tty); }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 void MutableSpace::print_short_on( outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 st->print(" space " SIZE_FORMAT "K, %d%% used", capacity_in_bytes() / K,
a61af66fc99e Initial load
duke
parents:
diff changeset
158 (int) ((double) used_in_bytes() * 100 / capacity_in_bytes()));
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 void MutableSpace::print() const { print_on(tty); }
a61af66fc99e Initial load
duke
parents:
diff changeset
162 void MutableSpace::print_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 MutableSpace::print_short_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
164 st->print_cr(" [" INTPTR_FORMAT "," INTPTR_FORMAT "," INTPTR_FORMAT ")",
a61af66fc99e Initial load
duke
parents:
diff changeset
165 bottom(), top(), end());
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167
190
d1635bf93939 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 0
diff changeset
168 void MutableSpace::verify(bool allow_dirty) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
169 HeapWord* p = bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
170 HeapWord* t = top();
a61af66fc99e Initial load
duke
parents:
diff changeset
171 HeapWord* prev_p = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 while (p < t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 oop(p)->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
174 prev_p = p;
a61af66fc99e Initial load
duke
parents:
diff changeset
175 p += oop(p)->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177 guarantee(p == top(), "end of last object must match end of space");
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }