test/hotspot/gtest/metaspace/test_leftOverBins.cpp
author stuefe
Fri, 01 Nov 2019 10:28:15 +0100
branchstuefe-new-metaspace-branch
changeset 59155 b537e6386306
child 59238 6ce12ce00d3e
permissions -rw-r--r--
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
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
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    32
class LeftOverBinsTest {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    33
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    34
  // A simple preallocated buffer used to "feed" the allocator.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    35
  // Mimicks chunk retirement leftover blocks.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    36
  class FeederBuffer {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    37
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    38
    static const size_t buf_word_size = 512 * K;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    39
    MetaWord* _buf;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    40
    size_t _used;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    41
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    42
  public:
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    43
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    44
    FeederBuffer() : _used(0) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    45
      _buf = NEW_C_HEAP_ARRAY(MetaWord, buf_word_size, mtInternal);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    46
    }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    47
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    48
    ~FeederBuffer() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    49
      FREE_C_HEAP_ARRAY(MetaWord, _buf);
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
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    52
    MetaWord* get(size_t word_size) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    53
      if (_used > (buf_word_size - word_size)) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    54
        return NULL;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    55
      }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    56
      MetaWord* p = _buf + _used;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    57
      _used += word_size;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    58
      return p;
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
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
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    63
  FeederBuffer _fb;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    64
  LeftOverManager _lom;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    65
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    66
  // random generator for block feeding
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    67
  RandSizeGenerator _rgen_feeding;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    68
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    69
  // 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
    70
  RandSizeGenerator _rgen_allocations;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    71
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    72
  SizeCounter _allocated_words;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    73
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    74
  struct allocation_t {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    75
    allocation_t* next;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    76
    size_t word_size;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    77
    MetaWord* p;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    78
  };
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    79
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    80
  // 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
    81
  allocation_t* _allocations;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    82
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
  int _num_allocs;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    85
  int _num_deallocs;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    86
  int _num_feeds;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    87
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    88
  bool feed_some() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    89
    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
    90
    MetaWord* p = _fb.get(word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    91
    if (p != NULL) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    92
      _lom.add_block(p, word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    93
      return true;
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
    return false;
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
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    98
  void deallocate_top() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    99
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   100
    allocation_t* a = _allocations;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   101
    if (a != NULL) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   102
      _allocations = a->next;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   103
      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
   104
      _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
   105
      delete a;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   106
      DEBUG_ONLY(_lom.verify();)
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   107
    }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   108
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   109
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   110
  bool allocate() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   111
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   112
    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
   113
    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
   114
    if (p != NULL) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   115
      _allocated_words.increment_by(word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   116
      allocation_t* a = new allocation_t;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   117
      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
   118
      a->next = _allocations;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   119
      _allocations = a;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   120
      DEBUG_ONLY(_lom.verify();)
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   121
      mark_range(p, word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   122
      return true;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   123
    }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   124
    return false;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   125
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   126
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   127
  void test_all_marked_ranges() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   128
    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
   129
      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
   130
    }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   131
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   132
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   133
  void test_loop() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   134
    // 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
   135
    // - allocation from lom
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   136
    // - 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
   137
    // - 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
   138
    // 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
   139
    //  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
   140
    bool forcefeed = false;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   141
    bool draining = false;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   142
    bool stop = false;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   143
    int iter = 100000; // safety stop
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   144
    while (!stop && iter > 0) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   145
      iter --;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   146
      int surprise = (int)os::random() % 10;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   147
      if (!draining && (surprise >= 7 || forcefeed)) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   148
        forcefeed = false;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   149
        if (feed_some()) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   150
          _num_feeds ++;
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
          // 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
   153
          draining = true;
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
      } else if (!draining && surprise < 1) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   156
        deallocate_top();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   157
        _num_deallocs ++;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   158
      } else {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   159
        if (allocate()) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   160
          _num_allocs ++;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   161
        } else {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   162
          if (draining) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   163
            stop = _lom.total_word_size() < 512;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   164
          } else {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   165
            forcefeed = true;
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
        }
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
      if ((iter % 1000) == 0) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   170
        DEBUG_ONLY(_lom.verify();)
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   171
        test_all_marked_ranges();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   172
        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
   173
#ifdef LOG_PLEASE
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   174
        _lom.print(tty, true);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   175
        tty->cr();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   176
#endif
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   177
      }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   178
    }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   179
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   180
    // Drain
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   181
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   182
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   183
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   184
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   185
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   186
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   187
public:
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
  LeftOverBinsTest(size_t avg_alloc_size) :
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   190
    _fb(), _lom(),
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   191
    _rgen_feeding(128, 4096),
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   192
    _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
   193
    _allocations(NULL),
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   194
    _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
   195
  {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   196
    // some initial feeding
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   197
    _lom.add_block(_fb.get(1024), 1024);
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
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   201
  static void test_small_allocations() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   202
    LeftOverBinsTest test(10);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   203
    test.test_loop();
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
  static void test_medium_allocations() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   207
    LeftOverBinsTest test(30);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   208
    test.test_loop();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   209
  }
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
  static void test_large_allocations() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   212
    LeftOverBinsTest test(150);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   213
    test.test_loop();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   214
  }
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
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   217
};
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   218
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   219
TEST_VM(metaspace, leftoverbins_mask_basic) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   220
  // Basic tests
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   221
  metaspace::BinMap map;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   222
  EXPECT_TRUE(map.all_zero());
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   223
  for (int i = 0; i < map.size(); i ++) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   224
    map.set_bit(i);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   225
    EXPECT_TRUE(map.get_bit(i));
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   226
    map.clr_bit(i);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   227
    EXPECT_FALSE(map.get_bit(i));
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   228
    EXPECT_TRUE(map.all_zero());
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   229
  }
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_mask_find_next_set_bit) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   233
  metaspace::BinMap map;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   234
  EXPECT_TRUE(map.all_zero());
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   235
  for (int i = 0; i < map.size(); i ++) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   236
    map.set_bit(i);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   237
    for (int j = 0; j < i; j ++) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   238
      int n = map.find_next_set_bit(j);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   239
      if (j <= i) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   240
        EXPECT_EQ(n, i);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   241
      } else {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   242
        EXPECT_EQ(n, -1);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   243
      }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   244
    }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   245
    map.clr_bit(i);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   246
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   247
}
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   248
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   249
TEST_VM(metaspace, leftoverbins_basics) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   250
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   251
  LeftOverManager lom;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   252
  MetaWord tmp[1024];
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   253
  metaspace::block_stats_t stats;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   254
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   255
  lom.add_block(tmp, 1024);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   256
  DEBUG_ONLY(lom.verify();)
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   257
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   258
  lom.statistics(&stats);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   259
  EXPECT_EQ(stats.num_blocks, 1);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   260
  EXPECT_EQ(stats.word_size, (size_t)1024);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   261
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   262
  MetaWord* p = lom.get_block(1024);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   263
  EXPECT_EQ(p, tmp);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   264
  DEBUG_ONLY(lom.verify();)
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   265
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   266
  lom.statistics(&stats);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   267
  EXPECT_EQ(stats.num_blocks, 0);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   268
  EXPECT_EQ(stats.word_size, (size_t)0);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   269
}
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   270
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   271
TEST_VM(metaspace, leftoverbins_small) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   272
  LeftOverBinsTest::test_small_allocations();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   273
}
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   274
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   275
TEST_VM(metaspace, leftoverbins_medium) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   276
  LeftOverBinsTest::test_medium_allocations();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   277
}
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   278
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   279
TEST_VM(metaspace, leftoverbins_large) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   280
  LeftOverBinsTest::test_large_allocations();
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   281
}
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   282