src/hotspot/share/memory/metaspace/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
#include "memory/metaspace/leftOverBins.inline.hpp"
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    28
#include "utilities/globalDefinitions.hpp"
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    29
#include "utilities/ostream.hpp"
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    30
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
namespace metaspace {
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
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
#ifdef ASSERT
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    37
void LeftOverManager::verify() const {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    38
  _very_small_bins.verify();
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
  if (_large_block_reserve != NULL) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    41
    assert(_current != NULL, "Sanity");
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    42
  }
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
  assert( (_current == NULL && _current_size == 0) ||
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    45
          (_current != NULL && _current_size > 0), "Sanity");
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
  for (block_t* b = _large_block_reserve; b != NULL; b = b->next) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    48
    assert(b->size > 0 && b->size <= 4 * M, "Weird block size");
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    49
  }
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
#endif
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
void LeftOverManager::large_block_statistics(block_stats_t* stats) const {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    55
  for (block_t* b = _large_block_reserve; b != NULL; b = b->next) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    56
    stats->num_blocks ++;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    57
    stats->word_size += b->size;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    58
  }
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
void LeftOverManager::statistics(block_stats_t* stats) const {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    62
  stats->num_blocks = 0;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    63
  stats->word_size = 0;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    64
  _very_small_bins.statistics(stats);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    65
  if (_current != NULL) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    66
    stats->num_blocks ++;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    67
    stats->word_size += _current_size;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    68
    large_block_statistics(stats);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    69
  } else {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    70
    assert(_large_block_reserve == NULL, "Sanity");
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
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    74
void LeftOverManager::print(outputStream* st, bool detailed) const {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    75
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    76
  block_stats_t s;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    77
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
    st->print("current: " SIZE_FORMAT " words; ", _current_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    80
  }
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
  s.num_blocks = 0; s.word_size = 0;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    83
  large_block_statistics(&s);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    84
  st->print("large blocks: %d blocks, " SIZE_FORMAT " words", s.num_blocks, s.word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    85
  if (detailed) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    86
    st->print(" (");
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    87
    for (block_t* b = _large_block_reserve; b != NULL; b = b->next) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    88
      st->print(SIZE_FORMAT "%s", b->size, b->next != NULL ? ", " : "");
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
    st->print(")");
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
  st->print("; ");
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    93
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    94
  s.num_blocks = 0; s.word_size = 0;
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    95
  _very_small_bins.statistics(&s);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    96
  st->print("small blocks: %d blocks, " SIZE_FORMAT " words", s.num_blocks, s.word_size);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    97
  if (detailed) {
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    98
    st->print(" (");
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
    99
    _very_small_bins.print(st);
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   100
    st->print(")");
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   101
  }
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   102
  st->print("; ");
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   103
}
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   104
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   105
} // namespace metaspace
b537e6386306 LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff changeset
   106