src/hotspot/share/memory/metaspace/leftOverBins.inline.hpp
author stuefe
Sat, 23 Nov 2019 11:05:16 +0100
branchstuefe-new-metaspace-branch
changeset 59238 6ce12ce00d3e
parent 59155 b537e6386306
permissions -rw-r--r--
Factor out block list array from LOM since we may use it elsewhere
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
#ifndef SHARE_MEMORY_METASPACE_LEFTOVERBINS_INLINE_HPP
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    27
#define SHARE_MEMORY_METASPACE_LEFTOVERBINS_INLINE_HPP
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    28
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    29
#include "memory/allocation.hpp"
59238
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents: 59155
diff changeset
    30
#include "memory/metaspace/blockListArray.inline.hpp"
59155
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    31
#include "memory/metaspace/leftOverBins.hpp"
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    32
#include "utilities/debug.hpp"
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    33
#include "utilities/globalDefinitions.hpp"
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    34
#include "utilities/ostream.hpp"
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    35
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    36
namespace metaspace {
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
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    39
///////////////////////////////////////
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    40
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    41
// Take the topmost block from the large block reserve list
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    42
// and make it current.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    43
inline void LeftOverManager::prime_current() {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    44
  if (_large_block_reserve != NULL) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    45
    _current = (MetaWord*) _large_block_reserve;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    46
    _current_size = _large_block_reserve->size;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    47
    _large_block_reserve = _large_block_reserve->next;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    48
  } else {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    49
    _current = NULL;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    50
    _current_size = 0;
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
}
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
// Allocate from current block. Returns NULL if current block
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    55
// is too small.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    56
inline MetaWord* LeftOverManager::alloc_from_current(size_t word_size) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    57
  if (_current_size >= word_size) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    58
    assert(_current != NULL, "Must be");
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    59
    MetaWord* p = _current;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    60
    size_t remaining = _current_size - word_size;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    61
    if (remaining >= _very_small_bins.minimal_word_size()) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    62
      _current = p + word_size;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    63
      _current_size = remaining;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    64
    } else {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    65
      // completely used up old large block. Proceed to next.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    66
      prime_current();
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
    return p;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    69
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    70
  return NULL;
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
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    73
inline void LeftOverManager::add_block(MetaWord* p, size_t word_size) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    74
  if (word_size >= minimal_word_size()) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    75
    if (word_size < _very_small_bins.maximal_word_size()) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    76
      _very_small_bins.put(p, word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    77
    } else {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    78
      if (_current == NULL) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    79
        assert(_large_block_reserve == NULL, "Should be primed.");
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    80
        _current = p;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    81
        _current_size = word_size;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    82
      } else {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    83
        assert(sizeof(block_t) <= word_size * BytesPerWord, "must be");
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    84
        block_t* b = (block_t*)p;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    85
        b->size = word_size;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    86
        b->next = _large_block_reserve;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    87
        _large_block_reserve = b;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    88
      }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    89
    }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    90
    _total_word_size.increment_by(word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    91
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    92
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    93
  DEBUG_ONLY(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
inline MetaWord* LeftOverManager::get_block(size_t requested_word_size) {
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
  requested_word_size = MAX2(requested_word_size, minimal_word_size());
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   100
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   101
  // First attempt to take from current large block because that is cheap (pointer bump)
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   102
  // and efficient (no spread)
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   103
  MetaWord* p = alloc_from_current(requested_word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   104
  if (p == NULL && _current_size > 0) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   105
    // current large block is too small. If it is moth-eaten enough to be put
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   106
    // into the small remains bin, do so.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   107
    if (_current_size < _very_small_bins.maximal_word_size()) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   108
      _very_small_bins.put(_current, _current_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   109
      prime_current(); // proceed to next large block.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   110
      // --- and re-attempt - but only once more. If that fails too, we give up.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   111
      p = alloc_from_current(requested_word_size);
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
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   115
  if (p == NULL) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   116
    // Did not work. Check the small bins.
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   117
    if (requested_word_size < _very_small_bins.maximal_word_size()) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   118
      block_t* b = _very_small_bins.get(requested_word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   119
      if (b != NULL) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   120
        p = (MetaWord*)b;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   121
        size_t remaining = b->size - requested_word_size;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   122
        if (remaining >= _very_small_bins.minimal_word_size()) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   123
          MetaWord* q = p + requested_word_size;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   124
          _very_small_bins.put(q, remaining);
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
    }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   128
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   129
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   130
  if (p != NULL) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   131
    _total_word_size.decrement_by(requested_word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   132
    DEBUG_ONLY(verify();)
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   133
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   134
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   135
  return p;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   136
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   137
}
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   138
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   139
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   140
} // namespace metaspace
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
#endif // SHARE_MEMORY_METASPACE_CHUNKMANAGER_HPP