hotspot/src/share/vm/memory/metachunk.cpp
author stuefe
Fri, 17 Mar 2017 19:05:45 +0100
changeset 46360 c753322134b0
parent 42017 ed85071e7d9d
child 46619 a3919f5e8d2b
permissions -rw-r--r--
8170520: Make Metaspace ChunkManager counters non-atomic Reviewed-by: mgerdin, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
     1
/*
42017
ed85071e7d9d 8166804: Convert TestMetachunk_test to GTest
kzhaldyb
parents: 36829
diff changeset
     2
 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
     4
 *
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
     8
 *
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    13
 * accompanied this code).
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    14
 *
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    18
 *
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    21
 * questions.
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    22
 *
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    23
 */
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    24
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    25
#include "precompiled.hpp"
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    26
#include "memory/allocation.hpp"
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    27
#include "memory/metachunk.hpp"
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    28
#include "utilities/copy.hpp"
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    29
#include "utilities/debug.hpp"
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    30
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    31
class VirtualSpaceNode;
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    32
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    33
size_t Metachunk::object_alignment() {
20730
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    34
  // Must align pointers and sizes to 8,
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    35
  // so that 64 bit types get correctly aligned.
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    36
  const size_t alignment = 8;
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    37
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    38
  // Make sure that the Klass alignment also agree.
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    39
  STATIC_ASSERT(alignment == (size_t)KlassAlignmentInBytes);
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    40
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    41
  return alignment;
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    42
}
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    43
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    44
size_t Metachunk::overhead() {
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    45
  return align_size_up(sizeof(Metachunk), object_alignment()) / BytesPerWord;
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    46
}
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    47
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    48
// Metachunk methods
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    49
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    50
Metachunk::Metachunk(size_t word_size,
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    51
                     VirtualSpaceNode* container)
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    52
    : Metabase<Metachunk>(word_size),
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    53
    _top(NULL),
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    54
    _container(container)
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    55
{
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    56
  _top = initial_top();
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    57
#ifdef ASSERT
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    58
  set_is_tagged_free(false);
36829
dd6004c32d75 8151623: Zap freed Metaspace chunks in non-product binaries
vlivanov
parents: 29800
diff changeset
    59
  mangle(uninitMetaWordVal);
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    60
#endif
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    61
}
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    62
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    63
MetaWord* Metachunk::allocate(size_t word_size) {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    64
  MetaWord* result = NULL;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    65
  // If available, bump the pointer to allocate.
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    66
  if (free_word_size() >= word_size) {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    67
    result = _top;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    68
    _top = _top + word_size;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    69
  }
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    70
  return result;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    71
}
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    72
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    73
// _bottom points to the start of the chunk including the overhead.
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14635
diff changeset
    74
size_t Metachunk::used_word_size() const {
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    75
  return pointer_delta(_top, bottom(), sizeof(MetaWord));
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    76
}
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    77
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14635
diff changeset
    78
size_t Metachunk::free_word_size() const {
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    79
  return pointer_delta(end(), _top, sizeof(MetaWord));
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    80
}
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    81
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    82
void Metachunk::print_on(outputStream* st) const {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    83
  st->print_cr("Metachunk:"
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    84
               " bottom " PTR_FORMAT " top " PTR_FORMAT
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    85
               " end " PTR_FORMAT " size " SIZE_FORMAT,
29800
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24424
diff changeset
    86
               p2i(bottom()), p2i(_top), p2i(end()), word_size());
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14635
diff changeset
    87
  if (Verbose) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14635
diff changeset
    88
    st->print_cr("    used " SIZE_FORMAT " free " SIZE_FORMAT,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14635
diff changeset
    89
                 used_word_size(), free_word_size());
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14635
diff changeset
    90
  }
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    91
}
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    92
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    93
#ifndef PRODUCT
36829
dd6004c32d75 8151623: Zap freed Metaspace chunks in non-product binaries
vlivanov
parents: 29800
diff changeset
    94
void Metachunk::mangle(juint word_value) {
dd6004c32d75 8151623: Zap freed Metaspace chunks in non-product binaries
vlivanov
parents: 29800
diff changeset
    95
  // Overwrite the payload of the chunk and not the links that
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    96
  // maintain list of chunks.
36829
dd6004c32d75 8151623: Zap freed Metaspace chunks in non-product binaries
vlivanov
parents: 29800
diff changeset
    97
  HeapWord* start = (HeapWord*)initial_top();
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    98
  size_t size = word_size() - overhead();
36829
dd6004c32d75 8151623: Zap freed Metaspace chunks in non-product binaries
vlivanov
parents: 29800
diff changeset
    99
  Copy::fill_to_words(start, size, word_value);
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   100
}
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   101
#endif // PRODUCT
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   102
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   103
void Metachunk::verify() {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   104
#ifdef ASSERT
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   105
  // Cannot walk through the blocks unless the blocks have
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   106
  // headers with sizes.
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   107
  assert(bottom() <= _top &&
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   108
         _top <= (MetaWord*)end(),
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   109
         "Chunk has been smashed");
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   110
#endif
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   111
  return;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   112
}
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   113