hotspot/src/share/vm/memory/metachunk.cpp
author kbarrett
Fri, 21 Jul 2017 21:01:59 -0400
changeset 46704 211b3f6b75ef
parent 46625 edefffab74e2
permissions -rw-r--r--
8182169: ArrayAllocator should take MEMFLAGS as regular parameter Summary: Change ArrayAllocator memflags from template parameter to ordinary function parameters Reviewed-by: kbarrett, tschatzl Contributed-by: milan.mimica@gmail.com
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"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    28
#include "utilities/align.hpp"
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    29
#include "utilities/copy.hpp"
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    30
#include "utilities/debug.hpp"
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    31
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    32
class VirtualSpaceNode;
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    33
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    34
size_t Metachunk::object_alignment() {
20730
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    35
  // Must align pointers and sizes to 8,
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    36
  // so that 64 bit types get correctly aligned.
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    37
  const size_t alignment = 8;
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    38
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    39
  // Make sure that the Klass alignment also agree.
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    40
  STATIC_ASSERT(alignment == (size_t)KlassAlignmentInBytes);
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    41
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    42
  return alignment;
20729
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
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    45
size_t Metachunk::overhead() {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 42017
diff changeset
    46
  return align_up(sizeof(Metachunk), object_alignment()) / BytesPerWord;
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    47
}
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    48
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    49
// Metachunk methods
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    50
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    51
Metachunk::Metachunk(size_t word_size,
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    52
                     VirtualSpaceNode* container)
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    53
    : Metabase<Metachunk>(word_size),
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    54
    _top(NULL),
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    55
    _container(container)
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    56
{
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    57
  _top = initial_top();
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    58
#ifdef ASSERT
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    59
  set_is_tagged_free(false);
36829
dd6004c32d75 8151623: Zap freed Metaspace chunks in non-product binaries
vlivanov
parents: 29800
diff changeset
    60
  mangle(uninitMetaWordVal);
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    61
#endif
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
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    64
MetaWord* Metachunk::allocate(size_t word_size) {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    65
  MetaWord* result = NULL;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    66
  // If available, bump the pointer to allocate.
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    67
  if (free_word_size() >= word_size) {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    68
    result = _top;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    69
    _top = _top + word_size;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    70
  }
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    71
  return result;
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
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    74
// _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
    75
size_t Metachunk::used_word_size() const {
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    76
  return pointer_delta(_top, bottom(), sizeof(MetaWord));
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    77
}
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    78
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14635
diff changeset
    79
size_t Metachunk::free_word_size() const {
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    80
  return pointer_delta(end(), _top, sizeof(MetaWord));
14635
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
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    83
void Metachunk::print_on(outputStream* st) const {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    84
  st->print_cr("Metachunk:"
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    85
               " bottom " PTR_FORMAT " top " PTR_FORMAT
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    86
               " 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
    87
               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
    88
  if (Verbose) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14635
diff changeset
    89
    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
    90
                 used_word_size(), free_word_size());
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14635
diff changeset
    91
  }
14635
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
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    94
#ifndef PRODUCT
36829
dd6004c32d75 8151623: Zap freed Metaspace chunks in non-product binaries
vlivanov
parents: 29800
diff changeset
    95
void Metachunk::mangle(juint word_value) {
dd6004c32d75 8151623: Zap freed Metaspace chunks in non-product binaries
vlivanov
parents: 29800
diff changeset
    96
  // 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
    97
  // maintain list of chunks.
36829
dd6004c32d75 8151623: Zap freed Metaspace chunks in non-product binaries
vlivanov
parents: 29800
diff changeset
    98
  HeapWord* start = (HeapWord*)initial_top();
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    99
  size_t size = word_size() - overhead();
36829
dd6004c32d75 8151623: Zap freed Metaspace chunks in non-product binaries
vlivanov
parents: 29800
diff changeset
   100
  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
   101
}
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   102
#endif // PRODUCT
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   103
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   104
void Metachunk::verify() {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   105
#ifdef ASSERT
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   106
  // 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
   107
  // headers with sizes.
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   108
  assert(bottom() <= _top &&
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   109
         _top <= (MetaWord*)end(),
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   110
         "Chunk has been smashed");
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   111
#endif
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   112
  return;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   113
}
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   114