< prev index next >

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

Print this page




  25 #include "precompiled.hpp"
  26 #include "gc/g1/g1BiasedArray.hpp"
  27 #include "memory/padded.inline.hpp"
  28 
  29 // Allocate a new array, generic version.
  30 address G1BiasedMappedArrayBase::create_new_base_array(size_t length, size_t elem_size) {
  31   assert(length > 0, "just checking");
  32   assert(elem_size > 0, "just checking");
  33   return PaddedPrimitiveArray<u_char, mtGC>::create_unfreeable(length * elem_size);
  34 }
  35 
  36 #ifndef PRODUCT
  37 void G1BiasedMappedArrayBase::verify_index(idx_t index) const {
  38   guarantee(_base != NULL, "Array not initialized");
  39   guarantee(index < length(), "Index out of bounds index: " SIZE_FORMAT " length: " SIZE_FORMAT, index, length());
  40 }
  41 
  42 void G1BiasedMappedArrayBase::verify_biased_index(idx_t biased_index) const {
  43   guarantee(_biased_base != NULL, "Array not initialized");
  44   guarantee(biased_index >= bias() && biased_index < (bias() + length()),
  45     "Biased index out of bounds, index: " SIZE_FORMAT " bias: " SIZE_FORMAT " length: " SIZE_FORMAT, biased_index, bias(), length());

  46 }
  47 
  48 void G1BiasedMappedArrayBase::verify_biased_index_inclusive_end(idx_t biased_index) const {
  49   guarantee(_biased_base != NULL, "Array not initialized");
  50   guarantee(biased_index >= bias() && biased_index <= (bias() + length()),
  51     "Biased index out of inclusive bounds, index: " SIZE_FORMAT " bias: " SIZE_FORMAT " length: " SIZE_FORMAT, biased_index, bias(), length());

  52 }
  53 
  54 class TestMappedArray : public G1BiasedMappedArray<int> {
  55 protected:
  56   virtual int default_value() const { return 0xBAADBABE; }
  57 public:
  58   static void test_biasedarray() {
  59     const size_t REGION_SIZE_IN_WORDS = 512;
  60     const size_t NUM_REGIONS = 20;
  61     HeapWord* fake_heap = (HeapWord*)LP64_ONLY(0xBAAA00000) NOT_LP64(0xBA000000); // Any value that is non-zero
  62 
  63     TestMappedArray array;
  64     array.initialize(fake_heap, fake_heap + REGION_SIZE_IN_WORDS * NUM_REGIONS,
  65             REGION_SIZE_IN_WORDS * HeapWordSize);
  66     // Check address calculation (bounds)
  67     assert(array.bottom_address_mapped() == fake_heap,
  68            "bottom mapped address should be " PTR_FORMAT ", but is " PTR_FORMAT, p2i(fake_heap), p2i(array.bottom_address_mapped()));
  69     assert(array.end_address_mapped() == (fake_heap + REGION_SIZE_IN_WORDS * NUM_REGIONS), "must be");
  70 
  71     int* bottom = array.address_mapped_to(fake_heap);




  25 #include "precompiled.hpp"
  26 #include "gc/g1/g1BiasedArray.hpp"
  27 #include "memory/padded.inline.hpp"
  28 
  29 // Allocate a new array, generic version.
  30 address G1BiasedMappedArrayBase::create_new_base_array(size_t length, size_t elem_size) {
  31   assert(length > 0, "just checking");
  32   assert(elem_size > 0, "just checking");
  33   return PaddedPrimitiveArray<u_char, mtGC>::create_unfreeable(length * elem_size);
  34 }
  35 
  36 #ifndef PRODUCT
  37 void G1BiasedMappedArrayBase::verify_index(idx_t index) const {
  38   guarantee(_base != NULL, "Array not initialized");
  39   guarantee(index < length(), "Index out of bounds index: " SIZE_FORMAT " length: " SIZE_FORMAT, index, length());
  40 }
  41 
  42 void G1BiasedMappedArrayBase::verify_biased_index(idx_t biased_index) const {
  43   guarantee(_biased_base != NULL, "Array not initialized");
  44   guarantee(biased_index >= bias() && biased_index < (bias() + length()),
  45             "Biased index out of bounds, index: " SIZE_FORMAT " bias: " SIZE_FORMAT " length: " SIZE_FORMAT,
  46             biased_index, bias(), length());
  47 }
  48 
  49 void G1BiasedMappedArrayBase::verify_biased_index_inclusive_end(idx_t biased_index) const {
  50   guarantee(_biased_base != NULL, "Array not initialized");
  51   guarantee(biased_index >= bias() && biased_index <= (bias() + length()),
  52             "Biased index out of inclusive bounds, index: " SIZE_FORMAT " bias: " SIZE_FORMAT " length: " SIZE_FORMAT,
  53             biased_index, bias(), length());
  54 }
  55 
  56 class TestMappedArray : public G1BiasedMappedArray<int> {
  57 protected:
  58   virtual int default_value() const { return 0xBAADBABE; }
  59 public:
  60   static void test_biasedarray() {
  61     const size_t REGION_SIZE_IN_WORDS = 512;
  62     const size_t NUM_REGIONS = 20;
  63     HeapWord* fake_heap = (HeapWord*)LP64_ONLY(0xBAAA00000) NOT_LP64(0xBA000000); // Any value that is non-zero
  64 
  65     TestMappedArray array;
  66     array.initialize(fake_heap, fake_heap + REGION_SIZE_IN_WORDS * NUM_REGIONS,
  67             REGION_SIZE_IN_WORDS * HeapWordSize);
  68     // Check address calculation (bounds)
  69     assert(array.bottom_address_mapped() == fake_heap,
  70            "bottom mapped address should be " PTR_FORMAT ", but is " PTR_FORMAT, p2i(fake_heap), p2i(array.bottom_address_mapped()));
  71     assert(array.end_address_mapped() == (fake_heap + REGION_SIZE_IN_WORDS * NUM_REGIONS), "must be");
  72 
  73     int* bottom = array.address_mapped_to(fake_heap);


< prev index next >