< prev index next >

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

Print this page




  27 #include "gc/shared/workgroup.hpp"
  28 #include "oops/markOop.hpp"
  29 #include "oops/oop.inline.hpp"
  30 #include "runtime/atomic.hpp"
  31 #include "runtime/os.inline.hpp"
  32 #include "services/memTracker.hpp"
  33 #include "utilities/bitMap.inline.hpp"
  34 
  35 G1PageBasedVirtualSpace::G1PageBasedVirtualSpace(ReservedSpace rs, size_t used_size, size_t page_size) :
  36   _low_boundary(NULL), _high_boundary(NULL), _committed(), _page_size(0), _special(false),
  37   _dirty(), _executable(false) {
  38   initialize_with_page_size(rs, used_size, page_size);
  39 }
  40 
  41 void G1PageBasedVirtualSpace::initialize_with_page_size(ReservedSpace rs, size_t used_size, size_t page_size) {
  42   guarantee(rs.is_reserved(), "Given reserved space must have been reserved already.");
  43 
  44   vmassert(_low_boundary == NULL, "VirtualSpace already initialized");
  45   vmassert(page_size > 0, "Page size must be non-zero.");
  46 
  47   guarantee(is_ptr_aligned(rs.base(), page_size),
  48             "Reserved space base " PTR_FORMAT " is not aligned to requested page size " SIZE_FORMAT, p2i(rs.base()), page_size);
  49   guarantee(is_size_aligned(used_size, os::vm_page_size()),
  50             "Given used reserved space size needs to be OS page size aligned (%d bytes) but is " SIZE_FORMAT, os::vm_page_size(), used_size);
  51   guarantee(used_size <= rs.size(),
  52             "Used size of reserved space " SIZE_FORMAT " bytes is smaller than reservation at " SIZE_FORMAT " bytes", used_size, rs.size());
  53   guarantee(is_size_aligned(rs.size(), page_size),
  54             "Expected that the virtual space is size aligned, but " SIZE_FORMAT " is not aligned to page size " SIZE_FORMAT, rs.size(), page_size);
  55 
  56   _low_boundary  = rs.base();
  57   _high_boundary = _low_boundary + used_size;
  58 
  59   _special = rs.special();
  60   _executable = rs.executable();
  61 
  62   _page_size = page_size;
  63 
  64   vmassert(_committed.size() == 0, "virtual space initialized more than once");
  65   BitMap::idx_t size_in_pages = rs.size() / page_size;
  66   _committed.initialize(size_in_pages);
  67   if (_special) {
  68     _dirty.initialize(size_in_pages);
  69   }
  70 
  71   _tail_size = used_size % _page_size;
  72 }
  73 


 124 }
 125 
 126 void G1PageBasedVirtualSpace::commit_preferred_pages(size_t start, size_t num_pages) {
 127   vmassert(num_pages > 0, "No full pages to commit");
 128   vmassert(start + num_pages <= _committed.size(),
 129            "Tried to commit area from page " SIZE_FORMAT " to page " SIZE_FORMAT " "
 130            "that is outside of managed space of " SIZE_FORMAT " pages",
 131            start, start + num_pages, _committed.size());
 132 
 133   char* start_addr = page_start(start);
 134   size_t size = num_pages * _page_size;
 135 
 136   os::commit_memory_or_exit(start_addr, size, _page_size, _executable,
 137                             err_msg("Failed to commit area from " PTR_FORMAT " to " PTR_FORMAT " of length " SIZE_FORMAT ".",
 138                             p2i(start_addr), p2i(start_addr + size), size));
 139 }
 140 
 141 void G1PageBasedVirtualSpace::commit_tail() {
 142   vmassert(_tail_size > 0, "The size of the tail area must be > 0 when reaching here");
 143 
 144   char* const aligned_end_address = align_ptr_down(_high_boundary, _page_size);
 145   os::commit_memory_or_exit(aligned_end_address, _tail_size, os::vm_page_size(), _executable,
 146                             err_msg("Failed to commit tail area from " PTR_FORMAT " to " PTR_FORMAT " of length " SIZE_FORMAT ".",
 147                             p2i(aligned_end_address), p2i(_high_boundary), _tail_size));
 148 }
 149 
 150 void G1PageBasedVirtualSpace::commit_internal(size_t start_page, size_t end_page) {
 151   guarantee(start_page < end_page,
 152             "Given start page " SIZE_FORMAT " is larger or equal to end page " SIZE_FORMAT, start_page, end_page);
 153   guarantee(end_page <= _committed.size(),
 154             "Given end page " SIZE_FORMAT " is beyond end of managed page amount of " SIZE_FORMAT, end_page, _committed.size());
 155 
 156   size_t pages = end_page - start_page;
 157   bool need_to_commit_tail = is_after_last_page(end_page) && is_last_page_partial();
 158 
 159   // If we have to commit some (partial) tail area, decrease the amount of pages to avoid
 160   // committing that in the full-page commit code.
 161   if (need_to_commit_tail) {
 162     pages--;
 163   }
 164 




  27 #include "gc/shared/workgroup.hpp"
  28 #include "oops/markOop.hpp"
  29 #include "oops/oop.inline.hpp"
  30 #include "runtime/atomic.hpp"
  31 #include "runtime/os.inline.hpp"
  32 #include "services/memTracker.hpp"
  33 #include "utilities/bitMap.inline.hpp"
  34 
  35 G1PageBasedVirtualSpace::G1PageBasedVirtualSpace(ReservedSpace rs, size_t used_size, size_t page_size) :
  36   _low_boundary(NULL), _high_boundary(NULL), _committed(), _page_size(0), _special(false),
  37   _dirty(), _executable(false) {
  38   initialize_with_page_size(rs, used_size, page_size);
  39 }
  40 
  41 void G1PageBasedVirtualSpace::initialize_with_page_size(ReservedSpace rs, size_t used_size, size_t page_size) {
  42   guarantee(rs.is_reserved(), "Given reserved space must have been reserved already.");
  43 
  44   vmassert(_low_boundary == NULL, "VirtualSpace already initialized");
  45   vmassert(page_size > 0, "Page size must be non-zero.");
  46 
  47   guarantee(is_aligned(rs.base(), page_size),
  48             "Reserved space base " PTR_FORMAT " is not aligned to requested page size " SIZE_FORMAT, p2i(rs.base()), page_size);
  49   guarantee(is_aligned(used_size, os::vm_page_size()),
  50             "Given used reserved space size needs to be OS page size aligned (%d bytes) but is " SIZE_FORMAT, os::vm_page_size(), used_size);
  51   guarantee(used_size <= rs.size(),
  52             "Used size of reserved space " SIZE_FORMAT " bytes is smaller than reservation at " SIZE_FORMAT " bytes", used_size, rs.size());
  53   guarantee(is_aligned(rs.size(), page_size),
  54             "Expected that the virtual space is size aligned, but " SIZE_FORMAT " is not aligned to page size " SIZE_FORMAT, rs.size(), page_size);
  55 
  56   _low_boundary  = rs.base();
  57   _high_boundary = _low_boundary + used_size;
  58 
  59   _special = rs.special();
  60   _executable = rs.executable();
  61 
  62   _page_size = page_size;
  63 
  64   vmassert(_committed.size() == 0, "virtual space initialized more than once");
  65   BitMap::idx_t size_in_pages = rs.size() / page_size;
  66   _committed.initialize(size_in_pages);
  67   if (_special) {
  68     _dirty.initialize(size_in_pages);
  69   }
  70 
  71   _tail_size = used_size % _page_size;
  72 }
  73 


 124 }
 125 
 126 void G1PageBasedVirtualSpace::commit_preferred_pages(size_t start, size_t num_pages) {
 127   vmassert(num_pages > 0, "No full pages to commit");
 128   vmassert(start + num_pages <= _committed.size(),
 129            "Tried to commit area from page " SIZE_FORMAT " to page " SIZE_FORMAT " "
 130            "that is outside of managed space of " SIZE_FORMAT " pages",
 131            start, start + num_pages, _committed.size());
 132 
 133   char* start_addr = page_start(start);
 134   size_t size = num_pages * _page_size;
 135 
 136   os::commit_memory_or_exit(start_addr, size, _page_size, _executable,
 137                             err_msg("Failed to commit area from " PTR_FORMAT " to " PTR_FORMAT " of length " SIZE_FORMAT ".",
 138                             p2i(start_addr), p2i(start_addr + size), size));
 139 }
 140 
 141 void G1PageBasedVirtualSpace::commit_tail() {
 142   vmassert(_tail_size > 0, "The size of the tail area must be > 0 when reaching here");
 143 
 144   char* const aligned_end_address = align_down(_high_boundary, _page_size);
 145   os::commit_memory_or_exit(aligned_end_address, _tail_size, os::vm_page_size(), _executable,
 146                             err_msg("Failed to commit tail area from " PTR_FORMAT " to " PTR_FORMAT " of length " SIZE_FORMAT ".",
 147                             p2i(aligned_end_address), p2i(_high_boundary), _tail_size));
 148 }
 149 
 150 void G1PageBasedVirtualSpace::commit_internal(size_t start_page, size_t end_page) {
 151   guarantee(start_page < end_page,
 152             "Given start page " SIZE_FORMAT " is larger or equal to end page " SIZE_FORMAT, start_page, end_page);
 153   guarantee(end_page <= _committed.size(),
 154             "Given end page " SIZE_FORMAT " is beyond end of managed page amount of " SIZE_FORMAT, end_page, _committed.size());
 155 
 156   size_t pages = end_page - start_page;
 157   bool need_to_commit_tail = is_after_last_page(end_page) && is_last_page_partial();
 158 
 159   // If we have to commit some (partial) tail area, decrease the amount of pages to avoid
 160   // committing that in the full-page commit code.
 161   if (need_to_commit_tail) {
 162     pages--;
 163   }
 164 


< prev index next >