Tue, 08 Aug 2017 15:57:29 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #include "precompiled.hpp" |
aoqi@0 | 26 | #include "gc_implementation/shared/spaceDecorator.hpp" |
aoqi@0 | 27 | #include "memory/space.inline.hpp" |
aoqi@0 | 28 | #include "utilities/copy.hpp" |
aoqi@0 | 29 | |
aoqi@0 | 30 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
aoqi@0 | 31 | |
aoqi@0 | 32 | // Catch-all file for utility classes |
aoqi@0 | 33 | |
aoqi@0 | 34 | #ifndef PRODUCT |
aoqi@0 | 35 | |
aoqi@0 | 36 | // Returns true is the location q matches the mangling |
aoqi@0 | 37 | // pattern. |
aoqi@0 | 38 | bool SpaceMangler::is_mangled(HeapWord* q) { |
aoqi@0 | 39 | // This test loses precision but is good enough |
aoqi@0 | 40 | return badHeapWord == (max_juint & (uintptr_t) q->value()); |
aoqi@0 | 41 | } |
aoqi@0 | 42 | |
aoqi@0 | 43 | |
aoqi@0 | 44 | void SpaceMangler::set_top_for_allocations(HeapWord* v) { |
aoqi@0 | 45 | if (v < end()) { |
aoqi@0 | 46 | assert(!CheckZapUnusedHeapArea || is_mangled(v), |
aoqi@0 | 47 | "The high water mark is not mangled"); |
aoqi@0 | 48 | } |
aoqi@0 | 49 | _top_for_allocations = v; |
aoqi@0 | 50 | } |
aoqi@0 | 51 | |
aoqi@0 | 52 | // Mangle only the unused space that has not previously |
aoqi@0 | 53 | // been mangled and that has not been allocated since being |
aoqi@0 | 54 | // mangled. |
aoqi@0 | 55 | void SpaceMangler::mangle_unused_area() { |
aoqi@0 | 56 | assert(ZapUnusedHeapArea, "Mangling should not be in use"); |
aoqi@0 | 57 | // Mangle between top and the high water mark. Safeguard |
aoqi@0 | 58 | // against the space changing since top_for_allocations was |
aoqi@0 | 59 | // set. |
aoqi@0 | 60 | HeapWord* mangled_end = MIN2(top_for_allocations(), end()); |
aoqi@0 | 61 | if (top() < mangled_end) { |
aoqi@0 | 62 | MemRegion mangle_mr(top(), mangled_end); |
aoqi@0 | 63 | SpaceMangler::mangle_region(mangle_mr); |
aoqi@0 | 64 | // Light weight check of mangling. |
aoqi@0 | 65 | check_mangled_unused_area(end()); |
aoqi@0 | 66 | } |
aoqi@0 | 67 | // Complete check of unused area which is functional when |
aoqi@0 | 68 | // DEBUG_MANGLING is defined. |
aoqi@0 | 69 | check_mangled_unused_area_complete(); |
aoqi@0 | 70 | } |
aoqi@0 | 71 | |
aoqi@0 | 72 | // A complete mangle is expected in the |
aoqi@0 | 73 | // exceptional case where top_for_allocations is not |
aoqi@0 | 74 | // properly tracking the high water mark for mangling. |
aoqi@0 | 75 | // This can be the case when to-space is being used for |
aoqi@0 | 76 | // scratch space during a mark-sweep-compact. See |
aoqi@0 | 77 | // contribute_scratch() and PSMarkSweep::allocate_stacks(). |
aoqi@0 | 78 | void SpaceMangler::mangle_unused_area_complete() { |
aoqi@0 | 79 | assert(ZapUnusedHeapArea, "Mangling should not be in use"); |
aoqi@0 | 80 | MemRegion mangle_mr(top(), end()); |
aoqi@0 | 81 | SpaceMangler::mangle_region(mangle_mr); |
aoqi@0 | 82 | } |
aoqi@0 | 83 | |
aoqi@0 | 84 | // Simply mangle the MemRegion mr. |
aoqi@0 | 85 | void SpaceMangler::mangle_region(MemRegion mr) { |
aoqi@0 | 86 | assert(ZapUnusedHeapArea, "Mangling should not be in use"); |
aoqi@0 | 87 | #ifdef ASSERT |
aoqi@0 | 88 | if(TraceZapUnusedHeapArea) { |
aoqi@0 | 89 | gclog_or_tty->print("Mangling [0x%x to 0x%x)", mr.start(), mr.end()); |
aoqi@0 | 90 | } |
aoqi@0 | 91 | Copy::fill_to_words(mr.start(), mr.word_size(), badHeapWord); |
aoqi@0 | 92 | if(TraceZapUnusedHeapArea) { |
aoqi@0 | 93 | gclog_or_tty->print_cr(" done"); |
aoqi@0 | 94 | } |
aoqi@0 | 95 | #endif |
aoqi@0 | 96 | } |
aoqi@0 | 97 | |
aoqi@0 | 98 | // Check that top, top_for_allocations and the last |
aoqi@0 | 99 | // word of the space are mangled. In a tight memory |
aoqi@0 | 100 | // situation even this light weight mangling could |
aoqi@0 | 101 | // cause paging by touching the end of the space. |
aoqi@0 | 102 | void SpaceMangler::check_mangled_unused_area(HeapWord* limit) { |
aoqi@0 | 103 | if (CheckZapUnusedHeapArea) { |
aoqi@0 | 104 | // This method can be called while the spaces are |
aoqi@0 | 105 | // being reshaped so skip the test if the end of the |
aoqi@0 | 106 | // space is beyond the specified limit; |
aoqi@0 | 107 | if (end() > limit) return; |
aoqi@0 | 108 | |
aoqi@0 | 109 | assert(top() == end() || |
aoqi@0 | 110 | (is_mangled(top())), "Top not mangled"); |
aoqi@0 | 111 | assert((top_for_allocations() < top()) || |
aoqi@0 | 112 | (top_for_allocations() >= end()) || |
aoqi@0 | 113 | (is_mangled(top_for_allocations())), |
aoqi@0 | 114 | "Older unused not mangled"); |
aoqi@0 | 115 | assert(top() == end() || |
aoqi@0 | 116 | (is_mangled(end() - 1)), "End not properly mangled"); |
aoqi@0 | 117 | // Only does checking when DEBUG_MANGLING is defined. |
aoqi@0 | 118 | check_mangled_unused_area_complete(); |
aoqi@0 | 119 | } |
aoqi@0 | 120 | } |
aoqi@0 | 121 | |
aoqi@0 | 122 | #undef DEBUG_MANGLING |
aoqi@0 | 123 | // This should only be used while debugging the mangling |
aoqi@0 | 124 | // because of the high cost of checking the completeness. |
aoqi@0 | 125 | void SpaceMangler::check_mangled_unused_area_complete() { |
aoqi@0 | 126 | if (CheckZapUnusedHeapArea) { |
aoqi@0 | 127 | assert(ZapUnusedHeapArea, "Not mangling unused area"); |
aoqi@0 | 128 | #ifdef DEBUG_MANGLING |
aoqi@0 | 129 | HeapWord* q = top(); |
aoqi@0 | 130 | HeapWord* limit = end(); |
aoqi@0 | 131 | |
aoqi@0 | 132 | bool passed = true; |
aoqi@0 | 133 | while (q < limit) { |
aoqi@0 | 134 | if (!is_mangled(q)) { |
aoqi@0 | 135 | passed = false; |
aoqi@0 | 136 | break; |
aoqi@0 | 137 | } |
aoqi@0 | 138 | q++; |
aoqi@0 | 139 | } |
aoqi@0 | 140 | assert(passed, "Mangling is not complete"); |
aoqi@0 | 141 | #endif |
aoqi@0 | 142 | } |
aoqi@0 | 143 | } |
aoqi@0 | 144 | #undef DEBUG_MANGLING |
aoqi@0 | 145 | #endif // not PRODUCT |