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