test/hotspot/gtest/metaspace/test_leftOverBins.cpp
author stuefe
Tue, 26 Nov 2019 11:29:20 +0100
branchstuefe-new-metaspace-branch
changeset 59271 1558266946de
parent 59238 6ce12ce00d3e
permissions -rw-r--r--
Improve BLA and LOM tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59155
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
     1
/*
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
     2
 * Copyright (c) 2019, SAP SE. All rights reserved.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
     3
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
     5
 *
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
     8
 * published by the Free Software Foundation.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
     9
 *
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    14
 * accompanied this code).
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    15
 *
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    19
 *
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    22
 * questions.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    23
 */
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    24
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    25
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    26
#include "precompiled.hpp"
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    27
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    28
//#define LOG_PLEASE
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    29
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    30
#include "metaspaceTestsCommon.hpp"
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    31
59271
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    32
#define CHECK_LOM_CONTENT(lom, num_blocks_expected, word_size_expected) \
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    33
{ \
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    34
  if (word_size_expected > 0) { \
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    35
    EXPECT_FALSE(lom.is_empty()); \
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    36
  } else { \
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    37
    EXPECT_TRUE(lom.is_empty()); \
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    38
  } \
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    39
  EXPECT_EQ(lom.total_word_size(), (size_t)word_size_expected); \
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    40
  metaspace::block_stats_t s; \
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    41
  memset(&s, 0xDD, sizeof(s)); \
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    42
  lom.statistics(&s); \
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    43
  EXPECT_EQ((size_t)word_size_expected, s.word_size); \
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    44
  if (num_blocks_expected >= 0) { \
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    45
	  EXPECT_EQ(num_blocks_expected, s.num_blocks); \
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    46
  } \
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    47
}
59155
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    48
59271
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
    49
class LeftOverBinsTest {
59155
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    50
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    51
  FeederBuffer _fb;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    52
  LeftOverManager _lom;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    53
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    54
  // random generator for block feeding
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    55
  RandSizeGenerator _rgen_feeding;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    56
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    57
  // random generator for allocations (and, hence, deallocations)
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    58
  RandSizeGenerator _rgen_allocations;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    59
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    60
  SizeCounter _allocated_words;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    61
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    62
  struct allocation_t {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    63
    allocation_t* next;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    64
    size_t word_size;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    65
    MetaWord* p;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    66
  };
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    67
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    68
  // Array of the same size as the pool max capacity; holds the allocated elements.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    69
  allocation_t* _allocations;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    70
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    71
  int _num_allocs;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    72
  int _num_deallocs;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    73
  int _num_feeds;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    74
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    75
  bool feed_some() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    76
    size_t word_size = _rgen_feeding.get();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    77
    MetaWord* p = _fb.get(word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    78
    if (p != NULL) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    79
      _lom.add_block(p, word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    80
      return true;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    81
    }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    82
    return false;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    83
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    84
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    85
  void deallocate_top() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    86
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    87
    allocation_t* a = _allocations;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    88
    if (a != NULL) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    89
      _allocations = a->next;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    90
      check_marked_range(a->p, a->word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    91
      _lom.add_block(a->p, a->word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    92
      delete a;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    93
      DEBUG_ONLY(_lom.verify();)
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    94
    }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    95
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    96
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    97
  bool allocate() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    98
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    99
    size_t word_size = MAX2(_rgen_allocations.get(), _lom.minimal_word_size());
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   100
    MetaWord* p = _lom.get_block(word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   101
    if (p != NULL) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   102
      _allocated_words.increment_by(word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   103
      allocation_t* a = new allocation_t;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   104
      a->p = p; a->word_size = word_size;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   105
      a->next = _allocations;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   106
      _allocations = a;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   107
      DEBUG_ONLY(_lom.verify();)
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   108
      mark_range(p, word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   109
      return true;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   110
    }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   111
    return false;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   112
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   113
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   114
  void test_all_marked_ranges() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   115
    for (allocation_t* a = _allocations; a != NULL; a = a->next) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   116
      check_marked_range(a->p, a->word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   117
    }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   118
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   119
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   120
  void test_loop() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   121
    // We loop and in each iteration execute one of three operations:
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   122
    // - allocation from lom
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   123
    // - deallocation to lom of a previously allocated block
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   124
    // - feeding a new larger block into the lom (mimicks chunk retiring)
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   125
    // When we have fed all large blocks into the lom (feedbuffer empty), we
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   126
    //  switch to draining the lom completely (only allocs)
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   127
    bool forcefeed = false;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   128
    bool draining = false;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   129
    bool stop = false;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   130
    int iter = 100000; // safety stop
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   131
    while (!stop && iter > 0) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   132
      iter --;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   133
      int surprise = (int)os::random() % 10;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   134
      if (!draining && (surprise >= 7 || forcefeed)) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   135
        forcefeed = false;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   136
        if (feed_some()) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   137
          _num_feeds ++;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   138
        } else {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   139
          // We fed all input memory into the LOM. Now lets proceed until the lom is drained.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   140
          draining = true;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   141
        }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   142
      } else if (!draining && surprise < 1) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   143
        deallocate_top();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   144
        _num_deallocs ++;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   145
      } else {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   146
        if (allocate()) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   147
          _num_allocs ++;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   148
        } else {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   149
          if (draining) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   150
            stop = _lom.total_word_size() < 512;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   151
          } else {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   152
            forcefeed = true;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   153
          }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   154
        }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   155
      }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   156
      if ((iter % 1000) == 0) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   157
        DEBUG_ONLY(_lom.verify();)
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   158
        test_all_marked_ranges();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   159
        LOG("a %d (" SIZE_FORMAT "), d %d, f %d", _num_allocs, _allocated_words.get(), _num_deallocs, _num_feeds);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   160
#ifdef LOG_PLEASE
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   161
        _lom.print(tty, true);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   162
        tty->cr();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   163
#endif
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   164
      }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   165
    }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   166
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   167
    // Drain
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   168
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   169
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   170
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   171
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   172
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   173
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   174
public:
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   175
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   176
  LeftOverBinsTest(size_t avg_alloc_size) :
59271
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
   177
    _fb(512 * K), _lom(),
59155
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   178
    _rgen_feeding(128, 4096),
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   179
    _rgen_allocations(avg_alloc_size / 4, avg_alloc_size * 2, 0.01f, avg_alloc_size / 3, avg_alloc_size * 30),
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   180
    _allocations(NULL),
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   181
    _num_allocs(0), _num_deallocs(0), _num_feeds(0)
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   182
  {
59271
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
   183
    CHECK_LOM_CONTENT(_lom, 0, 0);
59155
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   184
    // some initial feeding
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   185
    _lom.add_block(_fb.get(1024), 1024);
59271
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
   186
    CHECK_LOM_CONTENT(_lom, 1, 1024);
59155
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   187
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   188
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   189
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   190
  static void test_small_allocations() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   191
    LeftOverBinsTest test(10);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   192
    test.test_loop();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   193
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   194
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   195
  static void test_medium_allocations() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   196
    LeftOverBinsTest test(30);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   197
    test.test_loop();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   198
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   199
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   200
  static void test_large_allocations() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   201
    LeftOverBinsTest test(150);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   202
    test.test_loop();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   203
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   204
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   205
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   206
};
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   207
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   208
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   209
TEST_VM(metaspace, leftoverbins_basics) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   210
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   211
  LeftOverManager lom;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   212
  MetaWord tmp[1024];
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   213
  metaspace::block_stats_t stats;
59271
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
   214
  CHECK_LOM_CONTENT(lom, 0, 0);
59155
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   215
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   216
  lom.add_block(tmp, 1024);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   217
  DEBUG_ONLY(lom.verify();)
59271
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
   218
  ASSERT_FALSE(lom.is_empty());
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
   219
  CHECK_LOM_CONTENT(lom, 1, 1024);
59155
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   220
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   221
  MetaWord* p = lom.get_block(1024);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   222
  EXPECT_EQ(p, tmp);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   223
  DEBUG_ONLY(lom.verify();)
59271
1558266946de Improve BLA and LOM tests
stuefe
parents: 59238
diff changeset
   224
  CHECK_LOM_CONTENT(lom, 0, 0);
59155
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   225
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   226
}
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   227
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   228
TEST_VM(metaspace, leftoverbins_small) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   229
  LeftOverBinsTest::test_small_allocations();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   230
}
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   231
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   232
TEST_VM(metaspace, leftoverbins_medium) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   233
  LeftOverBinsTest::test_medium_allocations();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   234
}
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   235
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   236
TEST_VM(metaspace, leftoverbins_large) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   237
  LeftOverBinsTest::test_large_allocations();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   238
}
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   239