src/hotspot/share/memory/metaspace/commitMask.cpp
branchstuefe-new-metaspace-branch
changeset 58683 2d5dd194c65c
parent 58099 5aeb07390c74
equal deleted inserted replaced
58651:a2d3074db7a9 58683:2d5dd194c65c
    22  * questions.
    22  * questions.
    23  *
    23  *
    24  */
    24  */
    25 
    25 
    26 
    26 
    27 #include <memory/metaspace/settings.hpp>
       
    28 #include "precompiled.hpp"
    27 #include "precompiled.hpp"
    29 
    28 
    30 #include "memory/metaspace/commitMask.hpp"
    29 #include "memory/metaspace/commitMask.hpp"
    31 #include "memory/metaspace/metaspaceCommon.hpp"
    30 #include "memory/metaspace/metaspaceCommon.hpp"
    32 #include "memory/metaspace/settings.hpp"
    31 #include "memory/metaspace/settings.hpp"
    47          is_aligned(_word_size, _words_per_bit), "Sanity");
    46          is_aligned(_word_size, _words_per_bit), "Sanity");
    48 }
    47 }
    49 
    48 
    50 #ifdef ASSERT
    49 #ifdef ASSERT
    51 
    50 
       
    51 // This is very expensive
    52 static const bool TEST_UNCOMMITTED_REGION = false;
    52 static const bool TEST_UNCOMMITTED_REGION = false;
    53 
    53 
    54 volatile u1 x;
    54 volatile u1 x;
    55 
    55 
    56 void CommitMask::verify(bool slow, bool do_touch_test) const {
    56 static void check_range_is_accessible(const MetaWord* p, size_t word_size) {
       
    57   const MetaWord* const p_end = p + word_size;
       
    58   u1 x2 = 0;
       
    59   for (const MetaWord* q = p; q < p_end; q += os::vm_page_size() / BytesPerWord) {
       
    60     x2 += *(u1*)q;
       
    61   }
       
    62   x = x2;
       
    63 }
       
    64 
       
    65 void CommitMask::verify(bool slow) const {
    57 
    66 
    58   // Walk the whole commit mask.
    67   // Walk the whole commit mask.
    59   // For each 1 bit, check if the associated granule is accessible.
    68   // For each 1 bit, check if the associated granule is accessible.
    60   // For each 0 bit, check if the associated granule is not accessible. Slow mode only.
    69   // For each 0 bit, check if the associated granule is not accessible. Slow mode only.
    61 
    70 
       
    71   assert(_base != NULL && _word_size > 0 && _words_per_bit > 0, "Sanity");
    62   assert_is_aligned(_base, _words_per_bit * BytesPerWord);
    72   assert_is_aligned(_base, _words_per_bit * BytesPerWord);
    63   assert_is_aligned(_word_size, _words_per_bit);
    73   assert_is_aligned(_word_size, _words_per_bit);
    64 
    74 
    65   if (do_touch_test) {
    75   if (slow) {
    66     for (idx_t i = 0; i < size(); i ++) {
    76     for (idx_t i = 0; i < size(); i ++) {
    67       const MetaWord* const p = _base + (i * _words_per_bit);
    77       const MetaWord* const p = _base + (i * _words_per_bit);
    68       if (at(i)) {
    78       if (at(i)) {
    69         // Should be accessible. Just touch it.
    79         // Should be accessible. Just touch it.
    70         x ^= *(u1*)p;
    80         check_range_is_accessible(p, _words_per_bit);
    71       } else {
    81       } else {
    72         // Should not be accessible.
    82         // Note: results may differ between platforms. On Linux, this should be true since
    73         if (slow) {
    83         // we uncommit memory by setting protection to PROT_NONE. We may have to look if
    74           // Note: results may differ between platforms. On Linux, this should be true since
    84         // this works as expected on other platforms.
    75           // we uncommit memory by setting protection to PROT_NONE. We may have to look if
    85         if (TEST_UNCOMMITTED_REGION && CanUseSafeFetch32()) {
    76           // this works as expected on other platforms.
    86           assert(os::is_readable_pointer(p) == false,
    77           if (TEST_UNCOMMITTED_REGION && CanUseSafeFetch32()) {
    87                  "index %u, pointer " PTR_FORMAT ", should not be accessible.",
    78             assert(os::is_readable_pointer(p) == false,
    88                  (unsigned)i, p2i(p));
    79                    "index %u, pointer " PTR_FORMAT ", should not be accessible.",
       
    80                    (unsigned)i, p2i(p));
       
    81           }
       
    82         }
    89         }
    83       }
    90       }
    84     }
    91     }
    85   }
    92   }
    86 
    93