1 /* 2 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. 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 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 26 #include "precompiled.hpp" 27 28 #include "memory/metaspace/constants.hpp" 29 #include "memory/metaspace/commitMask.hpp" 30 #include "memory/metaspace/metaspaceCommon.hpp" 31 #include "runtime/stubRoutines.hpp" 32 33 #include "utilities/align.hpp" 34 #include "utilities/debug.hpp" 35 36 namespace metaspace { 37 38 #ifdef ASSERT 39 40 volatile u1 x; 41 42 void CommitMask::verify(bool slow) const { 43 44 // Walk the whole commit mask. 45 // For each 1 bit, check if the associated granule is accessible. 46 // For each 0 bit, check if the associated granule is not accessible. Slow mode only. 47 48 assert_is_aligned(_base, constants::commit_granule_bytes); 49 assert_is_aligned(_word_size, constants::commit_granule_words); 50 51 if (slow) { 52 assert(CanUseSafeFetch32, "We need SafeFetch for this test."); 53 } 54 55 for (idx_t i = 0; i < size(); i ++) { 56 const MetaWord* const p = _base + (i * constants::commit_granule_words); 57 if (at(i)) { 58 // Should be accessible. Just touch it. 59 x ^= (u1*)p; 60 } else { 61 // Should not be accessible. 62 if (slow) { 63 // Note: results may differ between platforms. On Linux, this should be true since 64 // we uncommit memory by setting protection to PROT_NONE. We may have to look if 65 // this works as expected on other platforms. 66 assert(os::is_readable_pointer(p) == false, "Should not be accessible."); 67 } 68 } 69 } 70 71 } 72 73 #endif // ASSERT 74 75 } // namespace metaspace 76