< prev index next >

test/hotspot/gtest/memory/test_metaspace_allocation.cpp

Print this page
rev 49210 : imported patch 8185034-metaspace-cleanup-1-rename-metaspaceaux
rev 49211 : 8199431: Split up class Metaspace into a static and a non-static part
Reviewed-by:


  56                stat.num_medium_chunks, stat.num_humongous_chunks);
  57 }
  58 
  59 #endif
  60 
  61 struct chunk_geometry_t {
  62   size_t specialized_chunk_word_size;
  63   size_t small_chunk_word_size;
  64   size_t medium_chunk_word_size;
  65 };
  66 
  67 extern void test_metaspace_retrieve_chunk_geometry(Metaspace::MetadataType mdType, chunk_geometry_t* out);
  68 
  69 
  70 class MetaspaceAllocationTest : public ::testing::Test {
  71 protected:
  72 
  73   struct {
  74     size_t allocated;
  75     Mutex* lock;
  76     Metaspace* space;
  77     bool is_empty() const { return allocated == 0; }
  78     bool is_full() const { return allocated >= MAX_PER_METASPACE_ALLOCATION_WORDSIZE; }
  79   } _spaces[NUM_PARALLEL_METASPACES];
  80 
  81   chunk_geometry_t _chunk_geometry;
  82 
  83   virtual void SetUp() {
  84     ::memset(_spaces, 0, sizeof(_spaces));
  85     test_metaspace_retrieve_chunk_geometry(Metaspace::NonClassType, &_chunk_geometry);
  86   }
  87 
  88   virtual void TearDown() {
  89     for (int i = 0; i < NUM_PARALLEL_METASPACES; i ++) {
  90       if (_spaces[i].space != NULL) {
  91         delete _spaces[i].space;
  92         delete _spaces[i].lock;
  93       }
  94     }
  95   }
  96 
  97   void create_space(int i) {
  98     assert(i >= 0 && i < NUM_PARALLEL_METASPACES, "Sanity");
  99     assert(_spaces[i].space == NULL && _spaces[i].allocated == 0, "Sanity");
 100     if (_spaces[i].lock == NULL) {
 101       _spaces[i].lock = new Mutex(Monitor::native, "gtest-MetaspaceAllocationTest-lock", false, Monitor::_safepoint_check_never);
 102       ASSERT_TRUE(_spaces[i].lock != NULL);
 103     }
 104     // Let every ~10th space be an anonymous one to test different allocation patterns.
 105     const Metaspace::MetaspaceType msType = (os::random() % 100 < 10) ?
 106       Metaspace::AnonymousMetaspaceType : Metaspace::StandardMetaspaceType;
 107     _spaces[i].space = new Metaspace(_spaces[i].lock, msType);
 108     _spaces[i].allocated = 0;
 109     ASSERT_TRUE(_spaces[i].space != NULL);
 110   }
 111 
 112   // Returns the index of a random space where index is [0..metaspaces) and which is
 113   //   empty, non-empty or full.
 114   // Returns -1 if no matching space exists.
 115   enum fillgrade { fg_empty, fg_non_empty, fg_full };
 116   int get_random_matching_space(int metaspaces, fillgrade fg) {
 117     const int start_index = os::random() % metaspaces;
 118     int i = start_index;
 119     do {
 120       if (fg == fg_empty && _spaces[i].is_empty()) {
 121         return i;
 122       } else if ((fg == fg_full && _spaces[i].is_full()) ||
 123                  (fg == fg_non_empty && !_spaces[i].is_full() && !_spaces[i].is_empty())) {
 124         return i;
 125       }
 126       i ++;
 127       if (i == metaspaces) {




  56                stat.num_medium_chunks, stat.num_humongous_chunks);
  57 }
  58 
  59 #endif
  60 
  61 struct chunk_geometry_t {
  62   size_t specialized_chunk_word_size;
  63   size_t small_chunk_word_size;
  64   size_t medium_chunk_word_size;
  65 };
  66 
  67 extern void test_metaspace_retrieve_chunk_geometry(Metaspace::MetadataType mdType, chunk_geometry_t* out);
  68 
  69 
  70 class MetaspaceAllocationTest : public ::testing::Test {
  71 protected:
  72 
  73   struct {
  74     size_t allocated;
  75     Mutex* lock;
  76     ClassLoaderMetaspace* space;
  77     bool is_empty() const { return allocated == 0; }
  78     bool is_full() const { return allocated >= MAX_PER_METASPACE_ALLOCATION_WORDSIZE; }
  79   } _spaces[NUM_PARALLEL_METASPACES];
  80 
  81   chunk_geometry_t _chunk_geometry;
  82 
  83   virtual void SetUp() {
  84     ::memset(_spaces, 0, sizeof(_spaces));
  85     test_metaspace_retrieve_chunk_geometry(Metaspace::NonClassType, &_chunk_geometry);
  86   }
  87 
  88   virtual void TearDown() {
  89     for (int i = 0; i < NUM_PARALLEL_METASPACES; i ++) {
  90       if (_spaces[i].space != NULL) {
  91         delete _spaces[i].space;
  92         delete _spaces[i].lock;
  93       }
  94     }
  95   }
  96 
  97   void create_space(int i) {
  98     assert(i >= 0 && i < NUM_PARALLEL_METASPACES, "Sanity");
  99     assert(_spaces[i].space == NULL && _spaces[i].allocated == 0, "Sanity");
 100     if (_spaces[i].lock == NULL) {
 101       _spaces[i].lock = new Mutex(Monitor::native, "gtest-MetaspaceAllocationTest-lock", false, Monitor::_safepoint_check_never);
 102       ASSERT_TRUE(_spaces[i].lock != NULL);
 103     }
 104     // Let every ~10th space be an anonymous one to test different allocation patterns.
 105     const Metaspace::MetaspaceType msType = (os::random() % 100 < 10) ?
 106       Metaspace::AnonymousMetaspaceType : Metaspace::StandardMetaspaceType;
 107     _spaces[i].space = new ClassLoaderMetaspace(_spaces[i].lock, msType);
 108     _spaces[i].allocated = 0;
 109     ASSERT_TRUE(_spaces[i].space != NULL);
 110   }
 111 
 112   // Returns the index of a random space where index is [0..metaspaces) and which is
 113   //   empty, non-empty or full.
 114   // Returns -1 if no matching space exists.
 115   enum fillgrade { fg_empty, fg_non_empty, fg_full };
 116   int get_random_matching_space(int metaspaces, fillgrade fg) {
 117     const int start_index = os::random() % metaspaces;
 118     int i = start_index;
 119     do {
 120       if (fg == fg_empty && _spaces[i].is_empty()) {
 121         return i;
 122       } else if ((fg == fg_full && _spaces[i].is_full()) ||
 123                  (fg == fg_non_empty && !_spaces[i].is_full() && !_spaces[i].is_empty())) {
 124         return i;
 125       }
 126       i ++;
 127       if (i == metaspaces) {


< prev index next >