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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/shared/space.inline.hpp"
27 #include "gc/shared/spaceDecorator.hpp"
28 #include "utilities/copy.hpp"
29
30 // Catch-all file for utility classes
31
32 #ifndef PRODUCT
33
34 // Returns true is the location q matches the mangling
35 // pattern.
36 bool SpaceMangler::is_mangled(HeapWord* q) {
37 // This test loses precision but is good enough
38 return badHeapWord == (max_juint & (uintptr_t) q->value());
39 }
40
41
42 void SpaceMangler::set_top_for_allocations(HeapWord* v) {
43 if (v < end()) {
44 assert(!CheckZapUnusedHeapArea || is_mangled(v),
45 "The high water mark is not mangled");
46 }
47 _top_for_allocations = v;
66 // DEBUG_MANGLING is defined.
67 check_mangled_unused_area_complete();
68 }
69
70 // A complete mangle is expected in the
71 // exceptional case where top_for_allocations is not
72 // properly tracking the high water mark for mangling.
73 // This can be the case when to-space is being used for
74 // scratch space during a mark-sweep-compact. See
75 // contribute_scratch() and PSMarkSweep::allocate_stacks().
76 void SpaceMangler::mangle_unused_area_complete() {
77 assert(ZapUnusedHeapArea, "Mangling should not be in use");
78 MemRegion mangle_mr(top(), end());
79 SpaceMangler::mangle_region(mangle_mr);
80 }
81
82 // Simply mangle the MemRegion mr.
83 void SpaceMangler::mangle_region(MemRegion mr) {
84 assert(ZapUnusedHeapArea, "Mangling should not be in use");
85 #ifdef ASSERT
86 if(TraceZapUnusedHeapArea) {
87 gclog_or_tty->print("Mangling [" PTR_FORMAT " to " PTR_FORMAT ")", p2i(mr.start()), p2i(mr.end()));
88 }
89 Copy::fill_to_words(mr.start(), mr.word_size(), badHeapWord);
90 if(TraceZapUnusedHeapArea) {
91 gclog_or_tty->print_cr(" done");
92 }
93 #endif
94 }
95
96 // Check that top, top_for_allocations and the last
97 // word of the space are mangled. In a tight memory
98 // situation even this light weight mangling could
99 // cause paging by touching the end of the space.
100 void SpaceMangler::check_mangled_unused_area(HeapWord* limit) {
101 if (CheckZapUnusedHeapArea) {
102 // This method can be called while the spaces are
103 // being reshaped so skip the test if the end of the
104 // space is beyond the specified limit;
105 if (end() > limit) return;
106
107 assert(top() == end() ||
108 (is_mangled(top())), "Top not mangled");
109 assert((top_for_allocations() < top()) ||
110 (top_for_allocations() >= end()) ||
111 (is_mangled(top_for_allocations())),
112 "Older unused not mangled");
|
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/shared/space.inline.hpp"
27 #include "gc/shared/spaceDecorator.hpp"
28 #include "logging/log.hpp"
29 #include "utilities/copy.hpp"
30
31 // Catch-all file for utility classes
32
33 #ifndef PRODUCT
34
35 // Returns true is the location q matches the mangling
36 // pattern.
37 bool SpaceMangler::is_mangled(HeapWord* q) {
38 // This test loses precision but is good enough
39 return badHeapWord == (max_juint & (uintptr_t) q->value());
40 }
41
42
43 void SpaceMangler::set_top_for_allocations(HeapWord* v) {
44 if (v < end()) {
45 assert(!CheckZapUnusedHeapArea || is_mangled(v),
46 "The high water mark is not mangled");
47 }
48 _top_for_allocations = v;
67 // DEBUG_MANGLING is defined.
68 check_mangled_unused_area_complete();
69 }
70
71 // A complete mangle is expected in the
72 // exceptional case where top_for_allocations is not
73 // properly tracking the high water mark for mangling.
74 // This can be the case when to-space is being used for
75 // scratch space during a mark-sweep-compact. See
76 // contribute_scratch() and PSMarkSweep::allocate_stacks().
77 void SpaceMangler::mangle_unused_area_complete() {
78 assert(ZapUnusedHeapArea, "Mangling should not be in use");
79 MemRegion mangle_mr(top(), end());
80 SpaceMangler::mangle_region(mangle_mr);
81 }
82
83 // Simply mangle the MemRegion mr.
84 void SpaceMangler::mangle_region(MemRegion mr) {
85 assert(ZapUnusedHeapArea, "Mangling should not be in use");
86 #ifdef ASSERT
87 log_develop(gc)("Mangling [" PTR_FORMAT " to " PTR_FORMAT ")", p2i(mr.start()), p2i(mr.end()));
88 Copy::fill_to_words(mr.start(), mr.word_size(), badHeapWord);
89 log_develop(gc)("Mangling done.");
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");
|