< 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:


  26 #include "gc_implementation/g1/g1PageBasedVirtualSpace.hpp"
  27 #include "oops/markOop.hpp"
  28 #include "oops/oop.inline.hpp"
  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), _executable(false) {

  49 }
  50 
  51 bool G1PageBasedVirtualSpace::initialize_with_granularity(ReservedSpace rs, size_t page_size) {
  52   if (!rs.is_reserved()) {
  53     return false;  // Allocation failed.
  54   }
  55   assert(_low_boundary == NULL, "VirtualSpace already initialized");
  56   assert(page_size > 0, "Granularity must be non-zero.");
  57 
  58   _low_boundary  = rs.base();
  59   _high_boundary = _low_boundary + rs.size();
  60 
  61   _special = rs.special();
  62   _executable = rs.executable();
  63 
  64   _page_size = page_size;
  65 
  66   assert(_committed.size() == 0, "virtual space initialized more than once");
  67   uintx size_in_bits = rs.size() / page_size;
  68   _committed.resize(size_in_bits, /* in_resource_area */ false);



  69 
  70   return true;
  71 }
  72 
  73 
  74 G1PageBasedVirtualSpace::~G1PageBasedVirtualSpace() {
  75   release();
  76 }
  77 
  78 void G1PageBasedVirtualSpace::release() {
  79   // This does not release memory it never reserved.
  80   // Caller must release via rs.release();
  81   _low_boundary           = NULL;
  82   _high_boundary          = NULL;
  83   _special                = false;
  84   _executable             = false;
  85   _page_size              = 0;
  86   _committed.resize(0, false);

  87 }
  88 
  89 size_t G1PageBasedVirtualSpace::committed_size() const {
  90   return _committed.count_one_bits() * _page_size;
  91 }
  92 
  93 size_t G1PageBasedVirtualSpace::reserved_size() const {
  94   return pointer_delta(_high_boundary, _low_boundary, sizeof(char));
  95 }
  96 
  97 size_t G1PageBasedVirtualSpace::uncommitted_size()  const {
  98   return reserved_size() - committed_size();
  99 }
 100 
 101 uintptr_t G1PageBasedVirtualSpace::addr_to_page_index(char* addr) const {
 102   return (addr - _low_boundary) / _page_size;
 103 }
 104 
 105 bool G1PageBasedVirtualSpace::is_area_committed(uintptr_t start, size_t size_in_pages) const {
 106   uintptr_t end = start + size_in_pages;
 107   return _committed.get_next_zero_offset(start, end) >= end;
 108 }
 109 
 110 bool G1PageBasedVirtualSpace::is_area_uncommitted(uintptr_t start, size_t size_in_pages) const {
 111   uintptr_t end = start + size_in_pages;
 112   return _committed.get_next_one_offset(start, end) >= end;
 113 }
 114 
 115 char* G1PageBasedVirtualSpace::page_start(uintptr_t index) {
 116   return _low_boundary + index * _page_size;
 117 }
 118 
 119 size_t G1PageBasedVirtualSpace::byte_size_for_pages(size_t num) {
 120   return num * _page_size;
 121 }
 122 
 123 MemRegion G1PageBasedVirtualSpace::commit(uintptr_t start, size_t size_in_pages) {
 124   // We need to make sure to commit all pages covered by the given area.
 125   guarantee(is_area_uncommitted(start, size_in_pages), "Specified area is not uncommitted");
 126 
 127   if (!_special) {










 128     os::commit_memory_or_exit(page_start(start), byte_size_for_pages(size_in_pages), _executable,
 129                               err_msg("Failed to commit pages from "SIZE_FORMAT" of length "SIZE_FORMAT, start, size_in_pages));
 130   }
 131   _committed.set_range(start, start + size_in_pages);
 132 
 133   MemRegion result((HeapWord*)page_start(start), byte_size_for_pages(size_in_pages) / HeapWordSize);
 134   if (AlwaysPreTouch) {
 135     os::pretouch_memory((char*)result.start(), (char*)result.end());
 136   }
 137   return result;
 138 }
 139 
 140 MemRegion G1PageBasedVirtualSpace::uncommit(uintptr_t start, size_t size_in_pages) {
 141   guarantee(is_area_committed(start, size_in_pages), "checking");
 142 
 143   if (!_special) {



 144     os::uncommit_memory(page_start(start), byte_size_for_pages(size_in_pages));
 145   }
 146 
 147   _committed.clear_range(start, start + size_in_pages);
 148 
 149   MemRegion result((HeapWord*)page_start(start), byte_size_for_pages(size_in_pages) / HeapWordSize);
 150   return result;
 151 }
 152 
 153 bool G1PageBasedVirtualSpace::contains(const void* p) const {
 154   return _low_boundary <= (const char*) p && (const char*) p < _high_boundary;
 155 }
 156 
 157 #ifndef PRODUCT
 158 void G1PageBasedVirtualSpace::print_on(outputStream* out) {
 159   out->print   ("Virtual space:");
 160   if (special()) out->print(" (pinned in memory)");
 161   out->cr();
 162   out->print_cr(" - committed: " SIZE_FORMAT, committed_size());
 163   out->print_cr(" - reserved:  " SIZE_FORMAT, reserved_size());


  26 #include "gc_implementation/g1/g1PageBasedVirtualSpace.hpp"
  27 #include "oops/markOop.hpp"
  28 #include "oops/oop.inline.hpp"
  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 #include "utilities/copy.hpp"
  47 
  48 G1PageBasedVirtualSpace::G1PageBasedVirtualSpace() : _low_boundary(NULL),
  49   _high_boundary(NULL), _committed(), _page_size(0), _special(false),
  50   _needs_clear_on_commit(), _executable(false) {
  51 }
  52 
  53 bool G1PageBasedVirtualSpace::initialize_with_granularity(ReservedSpace rs, size_t page_size) {
  54   if (!rs.is_reserved()) {
  55     return false;  // Allocation failed.
  56   }
  57   assert(_low_boundary == NULL, "VirtualSpace already initialized");
  58   assert(page_size > 0, "Granularity must be non-zero.");
  59 
  60   _low_boundary  = rs.base();
  61   _high_boundary = _low_boundary + rs.size();
  62 
  63   _special = rs.special();
  64   _executable = rs.executable();
  65 
  66   _page_size = page_size;
  67 
  68   assert(_committed.size() == 0, "virtual space initialized more than once");
  69   uintx size_in_bits = rs.size() / page_size;
  70   _committed.resize(size_in_bits, /* in_resource_area */ false);
  71   if (_special) {
  72     _needs_clear_on_commit.resize(size_in_bits, /* in_resource_area */ false);
  73   }
  74 
  75   return true;
  76 }
  77 
  78 
  79 G1PageBasedVirtualSpace::~G1PageBasedVirtualSpace() {
  80   release();
  81 }
  82 
  83 void G1PageBasedVirtualSpace::release() {
  84   // This does not release memory it never reserved.
  85   // Caller must release via rs.release();
  86   _low_boundary           = NULL;
  87   _high_boundary          = NULL;
  88   _special                = false;
  89   _executable             = false;
  90   _page_size              = 0;
  91   _committed.resize(0, false);
  92   _needs_clear_on_commit.resize(0, false);
  93 }
  94 
  95 size_t G1PageBasedVirtualSpace::committed_size() const {
  96   return _committed.count_one_bits() * _page_size;
  97 }
  98 
  99 size_t G1PageBasedVirtualSpace::reserved_size() const {
 100   return pointer_delta(_high_boundary, _low_boundary, sizeof(char));
 101 }
 102 
 103 size_t G1PageBasedVirtualSpace::uncommitted_size()  const {
 104   return reserved_size() - committed_size();
 105 }
 106 
 107 uintptr_t G1PageBasedVirtualSpace::addr_to_page_index(char* addr) const {
 108   return (addr - _low_boundary) / _page_size;
 109 }
 110 
 111 bool G1PageBasedVirtualSpace::is_area_committed(uintptr_t start, size_t size_in_pages) const {
 112   uintptr_t end = start + size_in_pages;
 113   return _committed.get_next_zero_offset(start, end) >= end;
 114 }
 115 
 116 bool G1PageBasedVirtualSpace::is_area_uncommitted(uintptr_t start, size_t size_in_pages) const {
 117   uintptr_t end = start + size_in_pages;
 118   return _committed.get_next_one_offset(start, end) >= end;
 119 }
 120 
 121 char* G1PageBasedVirtualSpace::page_start(uintptr_t index) {
 122   return _low_boundary + index * _page_size;
 123 }
 124 
 125 size_t G1PageBasedVirtualSpace::byte_size_for_pages(size_t num) {
 126   return num * _page_size;
 127 }
 128 
 129 MemRegion G1PageBasedVirtualSpace::commit(uintptr_t start, size_t size_in_pages) {
 130   // We need to make sure to commit all pages covered by the given area.
 131   guarantee(is_area_uncommitted(start, size_in_pages), "Specified area is not uncommitted");
 132 
 133   if (_special) {
 134     // When the memory is _special it is not really uncommitted. _needs_clear_on_commit
 135     // is used to communicate that the memory needs to be cleared because it is seen by
 136     // others as uncommitted.
 137     for (uintptr_t page_index = start; page_index < start + size_in_pages; page_index++) {
 138       if (_needs_clear_on_commit.at(page_index)) {
 139         Copy::zero_to_bytes((HeapWord*)page_start(page_index), _page_size);
 140         _needs_clear_on_commit.clear_bit(page_index);
 141       }
 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, start + size_in_pages);
 148 
 149   MemRegion result((HeapWord*)page_start(start), byte_size_for_pages(size_in_pages) / HeapWordSize);
 150   if (AlwaysPreTouch) {
 151     os::pretouch_memory((char*)result.start(), (char*)result.end());
 152   }
 153   return result;
 154 }
 155 
 156 MemRegion G1PageBasedVirtualSpace::uncommit(uintptr_t start, size_t size_in_pages) {
 157   guarantee(is_area_committed(start, size_in_pages), "checking");
 158 
 159   if (_special) {
 160     // Mark that memory needs to be cleared if committed again.
 161     _needs_clear_on_commit.set_range(start, start + size_in_pages);
 162   } else {
 163     os::uncommit_memory(page_start(start), byte_size_for_pages(size_in_pages));
 164   }
 165 
 166   _committed.clear_range(start, start + size_in_pages);
 167 
 168   MemRegion result((HeapWord*)page_start(start), byte_size_for_pages(size_in_pages) / HeapWordSize);
 169   return result;
 170 }
 171 
 172 bool G1PageBasedVirtualSpace::contains(const void* p) const {
 173   return _low_boundary <= (const char*) p && (const char*) p < _high_boundary;
 174 }
 175 
 176 #ifndef PRODUCT
 177 void G1PageBasedVirtualSpace::print_on(outputStream* out) {
 178   out->print   ("Virtual space:");
 179   if (special()) out->print(" (pinned in memory)");
 180   out->cr();
 181   out->print_cr(" - committed: " SIZE_FORMAT, committed_size());
 182   out->print_cr(" - reserved:  " SIZE_FORMAT, reserved_size());
< prev index next >