Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/shared/mutableSpace.cpp @ 520:52a431267315
6791168: Fix invalid code in bytecodeInterpreter that can cause gcc ICE
Summary: Fix compilation errors from latest gcc in CC_INTERP including offending missing void* cast.
Reviewed-by: xlu
author | coleenp |
---|---|
date | Tue, 13 Jan 2009 14:41:44 -0500 |
parents | 850fdf70db2b |
children | 4e400c36026f |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 2001-2008 Sun Microsystems, Inc. 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 * | |
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 | |
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 | 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 | |
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 | 66 } |
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 | 77 } |
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 | 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 | |
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 | 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 } |