|
1 /* |
|
2 * Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved. |
|
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/_spaceDecorator.cpp.incl" |
|
27 |
|
28 // Catch-all file for utility classes |
|
29 |
|
30 #ifndef PRODUCT |
|
31 |
|
32 // Returns true is the location q matches the mangling |
|
33 // pattern. |
|
34 bool SpaceMangler::is_mangled(HeapWord* q) { |
|
35 // This test loses precision but is good enough |
|
36 return badHeapWord == (max_juint & (uintptr_t) q->value()); |
|
37 } |
|
38 |
|
39 |
|
40 void SpaceMangler::set_top_for_allocations(HeapWord* v) { |
|
41 if (v < end()) { |
|
42 assert(is_mangled(v), "The high water mark is not mangled"); |
|
43 } |
|
44 _top_for_allocations = v; |
|
45 } |
|
46 |
|
47 // Mangle only the unused space that has not previously |
|
48 // been mangled and that has not been allocated since being |
|
49 // mangled. |
|
50 void SpaceMangler::mangle_unused_area() { |
|
51 assert(ZapUnusedHeapArea, "Mangling should not be in use"); |
|
52 // Mangle between top and the high water mark. Safeguard |
|
53 // against the space changing since top_for_allocations was |
|
54 // set. |
|
55 HeapWord* mangled_end = MIN2(top_for_allocations(), end()); |
|
56 if (top() < mangled_end) { |
|
57 MemRegion mangle_mr(top(), mangled_end); |
|
58 SpaceMangler::mangle_region(mangle_mr); |
|
59 // Light weight check of mangling. |
|
60 check_mangled_unused_area(end()); |
|
61 } |
|
62 // Complete check of unused area which is functional when |
|
63 // DEBUG_MANGLING is defined. |
|
64 check_mangled_unused_area_complete(); |
|
65 } |
|
66 |
|
67 // A complete mangle is expected in the |
|
68 // exceptional case where top_for_allocations is not |
|
69 // properly tracking the high water mark for mangling. |
|
70 // This can be the case when to-space is being used for |
|
71 // scratch space during a mark-sweep-compact. See |
|
72 // contribute_scratch() and PSMarkSweep::allocate_stacks(). |
|
73 void SpaceMangler::mangle_unused_area_complete() { |
|
74 assert(ZapUnusedHeapArea, "Mangling should not be in use"); |
|
75 MemRegion mangle_mr(top(), end()); |
|
76 SpaceMangler::mangle_region(mangle_mr); |
|
77 } |
|
78 |
|
79 // Simply mangle the MemRegion mr. |
|
80 void SpaceMangler::mangle_region(MemRegion mr) { |
|
81 assert(ZapUnusedHeapArea, "Mangling should not be in use"); |
|
82 #ifdef ASSERT |
|
83 if(TraceZapUnusedHeapArea) { |
|
84 gclog_or_tty->print("Mangling [0x%x to 0x%x)", mr.start(), mr.end()); |
|
85 } |
|
86 Copy::fill_to_words(mr.start(), mr.word_size(), badHeapWord); |
|
87 if(TraceZapUnusedHeapArea) { |
|
88 gclog_or_tty->print_cr(" done"); |
|
89 } |
|
90 #endif |
|
91 } |
|
92 |
|
93 // Check that top, top_for_allocations and the last |
|
94 // word of the space are mangled. In a tight memory |
|
95 // situation even this light weight mangling could |
|
96 // cause paging by touching the end of the space. |
|
97 void SpaceMangler::check_mangled_unused_area(HeapWord* limit) { |
|
98 if (CheckZapUnusedHeapArea) { |
|
99 // This method can be called while the spaces are |
|
100 // being reshaped so skip the test if the end of the |
|
101 // space is beyond the specified limit; |
|
102 if (end() > limit) return; |
|
103 |
|
104 assert(top() == end() || |
|
105 (is_mangled(top())), "Top not mangled"); |
|
106 assert((top_for_allocations() < top()) || |
|
107 (top_for_allocations() >= end()) || |
|
108 (is_mangled(top_for_allocations())), |
|
109 "Older unused not mangled"); |
|
110 assert(top() == end() || |
|
111 (is_mangled(end() - 1)), "End not properly mangled"); |
|
112 // Only does checking when DEBUG_MANGLING is defined. |
|
113 check_mangled_unused_area_complete(); |
|
114 } |
|
115 } |
|
116 |
|
117 #undef DEBUG_MANGLING |
|
118 // This should only be used while debugging the mangling |
|
119 // because of the high cost of checking the completeness. |
|
120 void SpaceMangler::check_mangled_unused_area_complete() { |
|
121 if (CheckZapUnusedHeapArea) { |
|
122 assert(ZapUnusedHeapArea, "Not mangling unused area"); |
|
123 #ifdef DEBUG_MANGLING |
|
124 HeapWord* q = top(); |
|
125 HeapWord* limit = end(); |
|
126 |
|
127 bool passed = true; |
|
128 while (q < limit) { |
|
129 if (!is_mangled(q)) { |
|
130 passed = false; |
|
131 break; |
|
132 } |
|
133 q++; |
|
134 } |
|
135 assert(passed, "Mangling is not complete"); |
|
136 #endif |
|
137 } |
|
138 } |
|
139 #undef DEBUG_MANGLING |
|
140 #endif // not PRODUCT |