src/hotspot/share/memory/metaspace/commitMask.cpp
branchstuefe-new-metaspace-branch
changeset 58063 bdf136b8ae0e
child 58099 5aeb07390c74
equal deleted inserted replaced
58062:65cad575ace3 58063:bdf136b8ae0e
       
     1 /*
       
     2  * Copyright (c) 2019, SAP SE. All rights reserved.
       
     3  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
       
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     5  *
       
     6  * This code is free software; you can redistribute it and/or modify it
       
     7  * under the terms of the GNU General Public License version 2 only, as
       
     8  * published by the Free Software Foundation.
       
     9  *
       
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    13  * version 2 for more details (a copy is included in the LICENSE file that
       
    14  * accompanied this code).
       
    15  *
       
    16  * You should have received a copy of the GNU General Public License version
       
    17  * 2 along with this work; if not, write to the Free Software Foundation,
       
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    19  *
       
    20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    21  * or visit www.oracle.com if you need additional information or have any
       
    22  * questions.
       
    23  *
       
    24  */
       
    25 
       
    26 
       
    27 #include <memory/metaspace/settings.hpp>
       
    28 #include "precompiled.hpp"
       
    29 
       
    30 #include "memory/metaspace/commitMask.hpp"
       
    31 #include "memory/metaspace/metaspaceCommon.hpp"
       
    32 #include "runtime/stubRoutines.hpp"
       
    33 
       
    34 #include "utilities/align.hpp"
       
    35 #include "utilities/debug.hpp"
       
    36 
       
    37 namespace metaspace {
       
    38 
       
    39 CommitMask::CommitMask(const MetaWord* start, size_t word_size)
       
    40   : CHeapBitMap(mask_size(word_size, Settings::commit_granule_words()))
       
    41   , _base(start)
       
    42   , _word_size(word_size)
       
    43   , _words_per_bit(Settings::commit_granule_words())
       
    44 {
       
    45   assert(_word_size > 0 && _words_per_bit > 0 &&
       
    46          is_aligned(_word_size, _words_per_bit), "Sanity");
       
    47 }
       
    48 
       
    49 #ifdef ASSERT
       
    50 
       
    51 static const bool TEST_UNCOMMITTED_REGION = false;
       
    52 
       
    53 volatile u1 x;
       
    54 
       
    55 void CommitMask::verify(bool slow, bool do_touch_test) const {
       
    56 
       
    57   // Walk the whole commit mask.
       
    58   // For each 1 bit, check if the associated granule is accessible.
       
    59   // For each 0 bit, check if the associated granule is not accessible. Slow mode only.
       
    60 
       
    61   assert_is_aligned(_base, _words_per_bit * BytesPerWord);
       
    62   assert_is_aligned(_word_size, _words_per_bit);
       
    63 
       
    64   if (slow) {
       
    65     assert(CanUseSafeFetch32, "We need SafeFetch for this test.");
       
    66   }
       
    67 
       
    68   if (do_touch_test) {
       
    69     for (idx_t i = 0; i < size(); i ++) {
       
    70       const MetaWord* const p = _base + (i * _words_per_bit);
       
    71       if (at(i)) {
       
    72         // Should be accessible. Just touch it.
       
    73         x ^= *(u1*)p;
       
    74       } else {
       
    75         // Should not be accessible.
       
    76         if (slow) {
       
    77           // Note: results may differ between platforms. On Linux, this should be true since
       
    78           // we uncommit memory by setting protection to PROT_NONE. We may have to look if
       
    79           // this works as expected on other platforms.
       
    80           if (CanUseSafeFetch32() && TEST_UNCOMMITTED_REGION) {
       
    81             assert(os::is_readable_pointer(p) == false,
       
    82                    "index %u, pointer " PTR_FORMAT ", should not be accessible.",
       
    83                    (unsigned)i, p2i(p));
       
    84           }
       
    85         }
       
    86       }
       
    87     }
       
    88   }
       
    89 
       
    90 }
       
    91 
       
    92 #endif // ASSERT
       
    93 
       
    94 void CommitMask::print_on(outputStream* st) const {
       
    95 
       
    96   st->print("commit mask, base " PTR_FORMAT ":", p2i(base()));
       
    97 
       
    98   for (idx_t i = 0; i < size(); i ++) {
       
    99     st->print("%c", at(i) ? 'X' : '-');
       
   100   }
       
   101 
       
   102   st->cr();
       
   103 
       
   104 }
       
   105 
       
   106 } // namespace metaspace
       
   107