< prev index next >

src/share/vm/gc_implementation/g1/g1PageBasedVirtualSpace.cpp

Print this page
rev 7618 : 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
Summary: Making sure committed memory is cleared when re-committed, even if using large pages.
Reviewed-by:
rev 7619 : [mq]: clear-in-listener
rev 7620 : [mq]: needs-zeroing-to-dirty


  29 #include "services/memTracker.hpp"
  30 #ifdef TARGET_OS_FAMILY_linux
  31 # include "os_linux.inline.hpp"
  32 #endif
  33 #ifdef TARGET_OS_FAMILY_solaris
  34 # include "os_solaris.inline.hpp"
  35 #endif
  36 #ifdef TARGET_OS_FAMILY_windows
  37 # include "os_windows.inline.hpp"
  38 #endif
  39 #ifdef TARGET_OS_FAMILY_aix
  40 # include "os_aix.inline.hpp"
  41 #endif
  42 #ifdef TARGET_OS_FAMILY_bsd
  43 # include "os_bsd.inline.hpp"
  44 #endif
  45 #include "utilities/bitMap.inline.hpp"
  46 
  47 G1PageBasedVirtualSpace::G1PageBasedVirtualSpace() : _low_boundary(NULL),
  48   _high_boundary(NULL), _committed(), _page_size(0), _special(false),
  49   _needs_zeroing(), _executable(false) {
  50 }
  51 
  52 bool G1PageBasedVirtualSpace::initialize_with_granularity(ReservedSpace rs, size_t page_size) {
  53   if (!rs.is_reserved()) {
  54     return false;  // Allocation failed.
  55   }
  56   assert(_low_boundary == NULL, "VirtualSpace already initialized");
  57   assert(page_size > 0, "Granularity must be non-zero.");
  58 
  59   _low_boundary  = rs.base();
  60   _high_boundary = _low_boundary + rs.size();
  61 
  62   _special = rs.special();
  63   _executable = rs.executable();
  64 
  65   _page_size = page_size;
  66 
  67   assert(_committed.size() == 0, "virtual space initialized more than once");
  68   uintx size_in_bits = rs.size() / page_size;
  69   _committed.resize(size_in_bits, /* in_resource_area */ false);
  70   if (_special) {
  71     _needs_zeroing.resize(size_in_bits, /* in_resource_area */ false);
  72   }
  73 
  74   return true;
  75 }
  76 
  77 
  78 G1PageBasedVirtualSpace::~G1PageBasedVirtualSpace() {
  79   release();
  80 }
  81 
  82 void G1PageBasedVirtualSpace::release() {
  83   // This does not release memory it never reserved.
  84   // Caller must release via rs.release();
  85   _low_boundary           = NULL;
  86   _high_boundary          = NULL;
  87   _special                = false;
  88   _executable             = false;
  89   _page_size              = 0;
  90   _committed.resize(0, false);
  91   _needs_zeroing.resize(0, false);
  92 }
  93 
  94 size_t G1PageBasedVirtualSpace::committed_size() const {
  95   return _committed.count_one_bits() * _page_size;
  96 }
  97 
  98 size_t G1PageBasedVirtualSpace::reserved_size() const {
  99   return pointer_delta(_high_boundary, _low_boundary, sizeof(char));
 100 }
 101 
 102 size_t G1PageBasedVirtualSpace::uncommitted_size()  const {
 103   return reserved_size() - committed_size();
 104 }
 105 
 106 uintptr_t G1PageBasedVirtualSpace::addr_to_page_index(char* addr) const {
 107   return (addr - _low_boundary) / _page_size;
 108 }
 109 
 110 bool G1PageBasedVirtualSpace::is_area_committed(uintptr_t start, size_t size_in_pages) const {
 111   uintptr_t end = start + size_in_pages;


 116   uintptr_t end = start + size_in_pages;
 117   return _committed.get_next_one_offset(start, end) >= end;
 118 }
 119 
 120 char* G1PageBasedVirtualSpace::page_start(uintptr_t index) {
 121   return _low_boundary + index * _page_size;
 122 }
 123 
 124 size_t G1PageBasedVirtualSpace::byte_size_for_pages(size_t num) {
 125   return num * _page_size;
 126 }
 127 
 128 bool G1PageBasedVirtualSpace::commit(uintptr_t start, size_t size_in_pages) {
 129   // We need to make sure to commit all pages covered by the given area.
 130   guarantee(is_area_uncommitted(start, size_in_pages), "Specified area is not uncommitted");
 131 
 132   bool zero_filled = true;
 133   uintptr_t end = start + size_in_pages;
 134 
 135   if (_special) {
 136     // When the memory is _special it is not really uncommitted. _needs_zeroing is
 137     // used to keep track if the current committed range contains pages that are all
 138     // zeroed or not.
 139     if (_needs_zeroing.get_next_one_offset(start,end) < end) {
 140       zero_filled = false;
 141       _needs_zeroing.clear_range(start, end);
 142     }
 143   } else {
 144     os::commit_memory_or_exit(page_start(start), byte_size_for_pages(size_in_pages), _executable,
 145                               err_msg("Failed to commit pages from "SIZE_FORMAT" of length "SIZE_FORMAT, start, size_in_pages));
 146   }
 147   _committed.set_range(start, end);
 148 
 149   if (AlwaysPreTouch) {
 150     os::pretouch_memory(page_start(start), page_start(end));
 151   }
 152   return zero_filled;
 153 }
 154 
 155 void G1PageBasedVirtualSpace::uncommit(uintptr_t start, size_t size_in_pages) {
 156   guarantee(is_area_committed(start, size_in_pages), "checking");
 157 
 158   if (_special) {
 159     // Mark that memory needs to be cleared if committed again.
 160     _needs_zeroing.set_range(start, start + size_in_pages);

 161   } else {
 162     os::uncommit_memory(page_start(start), byte_size_for_pages(size_in_pages));
 163   }
 164 
 165   _committed.clear_range(start, start + size_in_pages);
 166 }
 167 
 168 bool G1PageBasedVirtualSpace::contains(const void* p) const {
 169   return _low_boundary <= (const char*) p && (const char*) p < _high_boundary;
 170 }
 171 
 172 #ifndef PRODUCT
 173 void G1PageBasedVirtualSpace::print_on(outputStream* out) {
 174   out->print   ("Virtual space:");
 175   if (_special) out->print(" (pinned in memory)");
 176   out->cr();
 177   out->print_cr(" - committed: " SIZE_FORMAT, committed_size());
 178   out->print_cr(" - reserved:  " SIZE_FORMAT, reserved_size());
 179   out->print_cr(" - [low_b, high_b]: [" INTPTR_FORMAT ", " INTPTR_FORMAT "]",  p2i(_low_boundary), p2i(_high_boundary));
 180 }


  29 #include "services/memTracker.hpp"
  30 #ifdef TARGET_OS_FAMILY_linux
  31 # include "os_linux.inline.hpp"
  32 #endif
  33 #ifdef TARGET_OS_FAMILY_solaris
  34 # include "os_solaris.inline.hpp"
  35 #endif
  36 #ifdef TARGET_OS_FAMILY_windows
  37 # include "os_windows.inline.hpp"
  38 #endif
  39 #ifdef TARGET_OS_FAMILY_aix
  40 # include "os_aix.inline.hpp"
  41 #endif
  42 #ifdef TARGET_OS_FAMILY_bsd
  43 # include "os_bsd.inline.hpp"
  44 #endif
  45 #include "utilities/bitMap.inline.hpp"
  46 
  47 G1PageBasedVirtualSpace::G1PageBasedVirtualSpace() : _low_boundary(NULL),
  48   _high_boundary(NULL), _committed(), _page_size(0), _special(false),
  49   _dirty(), _executable(false) {
  50 }
  51 
  52 bool G1PageBasedVirtualSpace::initialize_with_granularity(ReservedSpace rs, size_t page_size) {
  53   if (!rs.is_reserved()) {
  54     return false;  // Allocation failed.
  55   }
  56   assert(_low_boundary == NULL, "VirtualSpace already initialized");
  57   assert(page_size > 0, "Granularity must be non-zero.");
  58 
  59   _low_boundary  = rs.base();
  60   _high_boundary = _low_boundary + rs.size();
  61 
  62   _special = rs.special();
  63   _executable = rs.executable();
  64 
  65   _page_size = page_size;
  66 
  67   assert(_committed.size() == 0, "virtual space initialized more than once");
  68   uintx size_in_bits = rs.size() / page_size;
  69   _committed.resize(size_in_bits, /* in_resource_area */ false);
  70   if (_special) {
  71     _dirty.resize(size_in_bits, /* in_resource_area */ false);
  72   }
  73 
  74   return true;
  75 }
  76 
  77 
  78 G1PageBasedVirtualSpace::~G1PageBasedVirtualSpace() {
  79   release();
  80 }
  81 
  82 void G1PageBasedVirtualSpace::release() {
  83   // This does not release memory it never reserved.
  84   // Caller must release via rs.release();
  85   _low_boundary           = NULL;
  86   _high_boundary          = NULL;
  87   _special                = false;
  88   _executable             = false;
  89   _page_size              = 0;
  90   _committed.resize(0, false);
  91   _dirty.resize(0, false);
  92 }
  93 
  94 size_t G1PageBasedVirtualSpace::committed_size() const {
  95   return _committed.count_one_bits() * _page_size;
  96 }
  97 
  98 size_t G1PageBasedVirtualSpace::reserved_size() const {
  99   return pointer_delta(_high_boundary, _low_boundary, sizeof(char));
 100 }
 101 
 102 size_t G1PageBasedVirtualSpace::uncommitted_size()  const {
 103   return reserved_size() - committed_size();
 104 }
 105 
 106 uintptr_t G1PageBasedVirtualSpace::addr_to_page_index(char* addr) const {
 107   return (addr - _low_boundary) / _page_size;
 108 }
 109 
 110 bool G1PageBasedVirtualSpace::is_area_committed(uintptr_t start, size_t size_in_pages) const {
 111   uintptr_t end = start + size_in_pages;


 116   uintptr_t end = start + size_in_pages;
 117   return _committed.get_next_one_offset(start, end) >= end;
 118 }
 119 
 120 char* G1PageBasedVirtualSpace::page_start(uintptr_t index) {
 121   return _low_boundary + index * _page_size;
 122 }
 123 
 124 size_t G1PageBasedVirtualSpace::byte_size_for_pages(size_t num) {
 125   return num * _page_size;
 126 }
 127 
 128 bool G1PageBasedVirtualSpace::commit(uintptr_t start, size_t size_in_pages) {
 129   // We need to make sure to commit all pages covered by the given area.
 130   guarantee(is_area_uncommitted(start, size_in_pages), "Specified area is not uncommitted");
 131 
 132   bool zero_filled = true;
 133   uintptr_t end = start + size_in_pages;
 134 
 135   if (_special) {
 136     // Check for dirty pages and update zero_filled if any found.
 137     if (_dirty.get_next_one_offset(start,end) < end) {


 138       zero_filled = false;
 139       _dirty.clear_range(start, end);
 140     }
 141   } else {
 142     os::commit_memory_or_exit(page_start(start), byte_size_for_pages(size_in_pages), _executable,
 143                               err_msg("Failed to commit pages from "SIZE_FORMAT" of length "SIZE_FORMAT, start, size_in_pages));
 144   }
 145   _committed.set_range(start, end);
 146 
 147   if (AlwaysPreTouch) {
 148     os::pretouch_memory(page_start(start), page_start(end));
 149   }
 150   return zero_filled;
 151 }
 152 
 153 void G1PageBasedVirtualSpace::uncommit(uintptr_t start, size_t size_in_pages) {
 154   guarantee(is_area_committed(start, size_in_pages), "checking");
 155 
 156   if (_special) {
 157     // Mark that memory is dirty. If committed again the memory might
 158     // need to be cleared explicitly.
 159     _dirty.set_range(start, start + size_in_pages);
 160   } else {
 161     os::uncommit_memory(page_start(start), byte_size_for_pages(size_in_pages));
 162   }
 163 
 164   _committed.clear_range(start, start + size_in_pages);
 165 }
 166 
 167 bool G1PageBasedVirtualSpace::contains(const void* p) const {
 168   return _low_boundary <= (const char*) p && (const char*) p < _high_boundary;
 169 }
 170 
 171 #ifndef PRODUCT
 172 void G1PageBasedVirtualSpace::print_on(outputStream* out) {
 173   out->print   ("Virtual space:");
 174   if (_special) out->print(" (pinned in memory)");
 175   out->cr();
 176   out->print_cr(" - committed: " SIZE_FORMAT, committed_size());
 177   out->print_cr(" - reserved:  " SIZE_FORMAT, reserved_size());
 178   out->print_cr(" - [low_b, high_b]: [" INTPTR_FORMAT ", " INTPTR_FORMAT "]",  p2i(_low_boundary), p2i(_high_boundary));
 179 }
< prev index next >