src/hotspot/share/memory/metaspace/virtualSpaceNode.cpp
author dcubed
Sat, 21 Sep 2019 10:13:25 -0400
changeset 58252 14c1ff687621
parent 53970 1ad7c590a6e7
child 57464 32e61f51ee09
child 58063 bdf136b8ae0e
child 59292 95b1385dd476
permissions -rw-r--r--
8231323: ProblemList jdk/jfr/jcmd/TestJcmdConfigure.java Reviewed-by: ysuenaga
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     1
/*
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     4
 *
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     7
 * published by the Free Software Foundation.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     8
 *
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    13
 * accompanied this code).
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    14
 *
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    18
 *
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    21
 * questions.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    22
 *
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    23
 */
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    24
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    25
#include "precompiled.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    26
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    27
#include "logging/log.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    28
#include "logging/logStream.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    29
#include "memory/metaspace/metachunk.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    30
#include "memory/metaspace.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    31
#include "memory/metaspace/chunkManager.hpp"
53970
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
    32
#include "memory/metaspace/metaDebug.hpp"
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    33
#include "memory/metaspace/metaspaceCommon.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    34
#include "memory/metaspace/occupancyMap.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    35
#include "memory/metaspace/virtualSpaceNode.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    36
#include "memory/virtualspace.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    37
#include "runtime/os.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    38
#include "services/memTracker.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    39
#include "utilities/copy.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    40
#include "utilities/debug.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    41
#include "utilities/globalDefinitions.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    42
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    43
namespace metaspace {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    44
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    45
// Decide if large pages should be committed when the memory is reserved.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    46
static bool should_commit_large_pages_when_reserving(size_t bytes) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    47
  if (UseLargePages && UseLargePagesInMetaspace && !os::can_commit_large_page_memory()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    48
    size_t words = bytes / BytesPerWord;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    49
    bool is_class = false; // We never reserve large pages for the class space.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    50
    if (MetaspaceGC::can_expand(words, is_class) &&
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    51
        MetaspaceGC::allowed_expansion() >= words) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    52
      return true;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    53
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    54
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    55
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    56
  return false;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    57
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    58
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    59
// byte_size is the size of the associated virtualspace.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    60
VirtualSpaceNode::VirtualSpaceNode(bool is_class, size_t bytes) :
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50811
diff changeset
    61
    _next(NULL), _is_class(is_class), _rs(), _top(NULL), _container_count(0), _occupancy_map(NULL) {
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    62
  assert_is_aligned(bytes, Metaspace::reserve_alignment());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    63
  bool large_pages = should_commit_large_pages_when_reserving(bytes);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    64
  _rs = ReservedSpace(bytes, Metaspace::reserve_alignment(), large_pages);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    65
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    66
  if (_rs.is_reserved()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    67
    assert(_rs.base() != NULL, "Catch if we get a NULL address");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    68
    assert(_rs.size() != 0, "Catch if we get a 0 size");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    69
    assert_is_aligned(_rs.base(), Metaspace::reserve_alignment());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    70
    assert_is_aligned(_rs.size(), Metaspace::reserve_alignment());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    71
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    72
    MemTracker::record_virtual_memory_type((address)_rs.base(), mtClass);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    73
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    74
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    75
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    76
void VirtualSpaceNode::purge(ChunkManager* chunk_manager) {
53970
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
    77
  // When a node is purged, lets give it a thorough examination.
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
    78
  DEBUG_ONLY(verify(true);)
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
    79
  Metachunk* chunk = first_chunk();
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    80
  Metachunk* invalid_chunk = (Metachunk*) top();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    81
  while (chunk < invalid_chunk ) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    82
    assert(chunk->is_tagged_free(), "Should be tagged free");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    83
    MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    84
    chunk_manager->remove_chunk(chunk);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    85
    chunk->remove_sentinel();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    86
    assert(chunk->next() == NULL &&
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    87
        chunk->prev() == NULL,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    88
        "Was not removed from its list");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    89
    chunk = (Metachunk*) next;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    90
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    91
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    92
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    93
void VirtualSpaceNode::print_map(outputStream* st, bool is_class) const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    94
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    95
  if (bottom() == top()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    96
    return;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    97
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    98
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    99
  const size_t spec_chunk_size = is_class ? ClassSpecializedChunk : SpecializedChunk;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   100
  const size_t small_chunk_size = is_class ? ClassSmallChunk : SmallChunk;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   101
  const size_t med_chunk_size = is_class ? ClassMediumChunk : MediumChunk;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   102
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   103
  int line_len = 100;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   104
  const size_t section_len = align_up(spec_chunk_size * line_len, med_chunk_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   105
  line_len = (int)(section_len / spec_chunk_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   106
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   107
  static const int NUM_LINES = 4;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   108
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   109
  char* lines[NUM_LINES];
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   110
  for (int i = 0; i < NUM_LINES; i ++) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   111
    lines[i] = (char*)os::malloc(line_len, mtInternal);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   112
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   113
  int pos = 0;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   114
  const MetaWord* p = bottom();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   115
  const Metachunk* chunk = (const Metachunk*)p;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   116
  const MetaWord* chunk_end = p + chunk->word_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   117
  while (p < top()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   118
    if (pos == line_len) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   119
      pos = 0;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   120
      for (int i = 0; i < NUM_LINES; i ++) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   121
        st->fill_to(22);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   122
        st->print_raw(lines[i], line_len);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   123
        st->cr();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   124
      }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   125
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   126
    if (pos == 0) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   127
      st->print(PTR_FORMAT ":", p2i(p));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   128
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   129
    if (p == chunk_end) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   130
      chunk = (Metachunk*)p;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   131
      chunk_end = p + chunk->word_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   132
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   133
    // line 1: chunk starting points (a dot if that area is a chunk start).
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   134
    lines[0][pos] = p == (const MetaWord*)chunk ? '.' : ' ';
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   135
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   136
    // Line 2: chunk type (x=spec, s=small, m=medium, h=humongous), uppercase if
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   137
    // chunk is in use.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   138
    const bool chunk_is_free = ((Metachunk*)chunk)->is_tagged_free();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   139
    if (chunk->word_size() == spec_chunk_size) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   140
      lines[1][pos] = chunk_is_free ? 'x' : 'X';
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   141
    } else if (chunk->word_size() == small_chunk_size) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   142
      lines[1][pos] = chunk_is_free ? 's' : 'S';
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   143
    } else if (chunk->word_size() == med_chunk_size) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   144
      lines[1][pos] = chunk_is_free ? 'm' : 'M';
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   145
    } else if (chunk->word_size() > med_chunk_size) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   146
      lines[1][pos] = chunk_is_free ? 'h' : 'H';
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   147
    } else {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   148
      ShouldNotReachHere();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   149
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   150
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   151
    // Line 3: chunk origin
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   152
    const ChunkOrigin origin = chunk->get_origin();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   153
    lines[2][pos] = origin == origin_normal ? ' ' : '0' + (int) origin;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   154
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   155
    // Line 4: Virgin chunk? Virgin chunks are chunks created as a byproduct of padding or splitting,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   156
    //         but were never used.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   157
    lines[3][pos] = chunk->get_use_count() > 0 ? ' ' : 'v';
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   158
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   159
    p += spec_chunk_size;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   160
    pos ++;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   161
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   162
  if (pos > 0) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   163
    for (int i = 0; i < NUM_LINES; i ++) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   164
      st->fill_to(22);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   165
      st->print_raw(lines[i], line_len);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   166
      st->cr();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   167
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   168
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   169
  for (int i = 0; i < NUM_LINES; i ++) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   170
    os::free(lines[i]);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   171
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   172
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   173
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   174
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   175
#ifdef ASSERT
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   176
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   177
// Verify counters, all chunks in this list node and the occupancy map.
53970
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   178
void VirtualSpaceNode::verify(bool slow) {
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   179
  log_trace(gc, metaspace, freelist)("verifying %s virtual space node (%s).",
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   180
    (is_class() ? "class space" : "metaspace"), (slow ? "slow" : "quick"));
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   181
  // Fast mode: just verify chunk counters and basic geometry
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   182
  // Slow mode: verify chunks and occupancy map
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   183
  uintx num_in_use_chunks = 0;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   184
  Metachunk* chunk = first_chunk();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   185
  Metachunk* invalid_chunk = (Metachunk*) top();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   186
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   187
  // Iterate the chunks in this node and verify each chunk.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   188
  while (chunk < invalid_chunk ) {
53970
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   189
    if (slow) {
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   190
      do_verify_chunk(chunk);
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   191
    }
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   192
    if (!chunk->is_tagged_free()) {
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   193
      num_in_use_chunks ++;
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   194
    }
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   195
    const size_t s = chunk->word_size();
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   196
    // Prevent endless loop on invalid chunk size.
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   197
    assert(is_valid_chunksize(is_class(), s), "Invalid chunk size: " SIZE_FORMAT ".", s);
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   198
    MetaWord* next = ((MetaWord*)chunk) + s;
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   199
    chunk = (Metachunk*) next;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   200
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   201
  assert(_container_count == num_in_use_chunks, "Container count mismatch (real: " UINTX_FORMAT
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   202
      ", counter: " UINTX_FORMAT ".", num_in_use_chunks, _container_count);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   203
  // Also verify the occupancy map.
53970
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   204
  if (slow) {
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   205
    occupancy_map()->verify(bottom(), top());
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   206
  }
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   207
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   208
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   209
// Verify that all free chunks in this node are ideally merged
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   210
// (there not should be multiple small chunks where a large chunk could exist.)
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   211
void VirtualSpaceNode::verify_free_chunks_are_ideally_merged() {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   212
  Metachunk* chunk = first_chunk();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   213
  Metachunk* invalid_chunk = (Metachunk*) top();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   214
  // Shorthands.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   215
  const size_t size_med = (is_class() ? ClassMediumChunk : MediumChunk) * BytesPerWord;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   216
  const size_t size_small = (is_class() ? ClassSmallChunk : SmallChunk) * BytesPerWord;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   217
  int num_free_chunks_since_last_med_boundary = -1;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   218
  int num_free_chunks_since_last_small_boundary = -1;
53970
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   219
  bool error = false;
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   220
  char err[256];
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   221
  while (!error && chunk < invalid_chunk ) {
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   222
    // Test for missed chunk merge opportunities: count number of free chunks since last chunk boundary.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   223
    // Reset the counter when encountering a non-free chunk.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   224
    if (chunk->get_chunk_type() != HumongousIndex) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   225
      if (chunk->is_tagged_free()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   226
        // Count successive free, non-humongous chunks.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   227
        if (is_aligned(chunk, size_small)) {
53970
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   228
          if (num_free_chunks_since_last_small_boundary > 0) {
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   229
            error = true;
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   230
            jio_snprintf(err, sizeof(err), "Missed chunk merge opportunity to merge a small chunk preceding " PTR_FORMAT ".", p2i(chunk));
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   231
          } else {
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   232
            num_free_chunks_since_last_small_boundary = 0;
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   233
          }
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   234
        } else if (num_free_chunks_since_last_small_boundary != -1) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   235
          num_free_chunks_since_last_small_boundary ++;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   236
        }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   237
        if (is_aligned(chunk, size_med)) {
53970
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   238
          if (num_free_chunks_since_last_med_boundary > 0) {
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   239
            error = true;
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   240
            jio_snprintf(err, sizeof(err), "Missed chunk merge opportunity to merge a medium chunk preceding " PTR_FORMAT ".", p2i(chunk));
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   241
          } else {
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   242
            num_free_chunks_since_last_med_boundary = 0;
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   243
          }
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   244
        } else if (num_free_chunks_since_last_med_boundary != -1) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   245
          num_free_chunks_since_last_med_boundary ++;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   246
        }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   247
      } else {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   248
        // Encountering a non-free chunk, reset counters.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   249
        num_free_chunks_since_last_med_boundary = -1;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   250
        num_free_chunks_since_last_small_boundary = -1;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   251
      }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   252
    } else {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   253
      // One cannot merge areas with a humongous chunk in the middle. Reset counters.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   254
      num_free_chunks_since_last_med_boundary = -1;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   255
      num_free_chunks_since_last_small_boundary = -1;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   256
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   257
53970
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   258
    if (error) {
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   259
      print_map(tty, is_class());
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   260
      fatal("%s", err);
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   261
    }
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   262
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   263
    MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   264
    chunk = (Metachunk*) next;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   265
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   266
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   267
#endif // ASSERT
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   268
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   269
void VirtualSpaceNode::inc_container_count() {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   270
  assert_lock_strong(MetaspaceExpand_lock);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   271
  _container_count++;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   272
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   273
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   274
void VirtualSpaceNode::dec_container_count() {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   275
  assert_lock_strong(MetaspaceExpand_lock);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   276
  _container_count--;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   277
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   278
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   279
VirtualSpaceNode::~VirtualSpaceNode() {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   280
  _rs.release();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   281
  if (_occupancy_map != NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   282
    delete _occupancy_map;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   283
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   284
#ifdef ASSERT
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   285
  size_t word_size = sizeof(*this) / BytesPerWord;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   286
  Copy::fill_to_words((HeapWord*) this, word_size, 0xf1f1f1f1);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   287
#endif
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   288
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   289
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   290
size_t VirtualSpaceNode::used_words_in_vs() const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   291
  return pointer_delta(top(), bottom(), sizeof(MetaWord));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   292
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   293
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   294
// Space committed in the VirtualSpace
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   295
size_t VirtualSpaceNode::capacity_words_in_vs() const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   296
  return pointer_delta(end(), bottom(), sizeof(MetaWord));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   297
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   298
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   299
size_t VirtualSpaceNode::free_words_in_vs() const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   300
  return pointer_delta(end(), top(), sizeof(MetaWord));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   301
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   302
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   303
// Given an address larger than top(), allocate padding chunks until top is at the given address.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   304
void VirtualSpaceNode::allocate_padding_chunks_until_top_is_at(MetaWord* target_top) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   305
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   306
  assert(target_top > top(), "Sanity");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   307
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   308
  // Padding chunks are added to the freelist.
53970
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   309
  ChunkManager* const chunk_manager = Metaspace::get_chunk_manager(is_class());
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   310
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   311
  // shorthands
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   312
  const size_t spec_word_size = chunk_manager->specialized_chunk_word_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   313
  const size_t small_word_size = chunk_manager->small_chunk_word_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   314
  const size_t med_word_size = chunk_manager->medium_chunk_word_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   315
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   316
  while (top() < target_top) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   317
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   318
    // We could make this coding more generic, but right now we only deal with two possible chunk sizes
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   319
    // for padding chunks, so it is not worth it.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   320
    size_t padding_chunk_word_size = small_word_size;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   321
    if (is_aligned(top(), small_word_size * sizeof(MetaWord)) == false) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   322
      assert_is_aligned(top(), spec_word_size * sizeof(MetaWord)); // Should always hold true.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   323
      padding_chunk_word_size = spec_word_size;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   324
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   325
    MetaWord* here = top();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   326
    assert_is_aligned(here, padding_chunk_word_size * sizeof(MetaWord));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   327
    inc_top(padding_chunk_word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   328
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   329
    // Create new padding chunk.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   330
    ChunkIndex padding_chunk_type = get_chunk_type_by_size(padding_chunk_word_size, is_class());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   331
    assert(padding_chunk_type == SpecializedIndex || padding_chunk_type == SmallIndex, "sanity");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   332
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   333
    Metachunk* const padding_chunk =
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   334
        ::new (here) Metachunk(padding_chunk_type, is_class(), padding_chunk_word_size, this);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   335
    assert(padding_chunk == (Metachunk*)here, "Sanity");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   336
    DEBUG_ONLY(padding_chunk->set_origin(origin_pad);)
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   337
    log_trace(gc, metaspace, freelist)("Created padding chunk in %s at "
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   338
        PTR_FORMAT ", size " SIZE_FORMAT_HEX ".",
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   339
        (is_class() ? "class space " : "metaspace"),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   340
        p2i(padding_chunk), padding_chunk->word_size() * sizeof(MetaWord));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   341
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   342
    // Mark chunk start in occupancy map.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   343
    occupancy_map()->set_chunk_starts_at_address((MetaWord*)padding_chunk, true);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   344
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   345
    // Chunks are born as in-use (see MetaChunk ctor). So, before returning
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   346
    // the padding chunk to its chunk manager, mark it as in use (ChunkManager
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   347
    // will assert that).
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   348
    do_update_in_use_info_for_chunk(padding_chunk, true);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   349
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   350
    // Return Chunk to freelist.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   351
    inc_container_count();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   352
    chunk_manager->return_single_chunk(padding_chunk);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   353
    // Please note: at this point, ChunkManager::return_single_chunk()
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   354
    // may already have merged the padding chunk with neighboring chunks, so
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   355
    // it may have vanished at this point. Do not reference the padding
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   356
    // chunk beyond this point.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   357
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   358
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   359
  assert(top() == target_top, "Sanity");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   360
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   361
} // allocate_padding_chunks_until_top_is_at()
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   362
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   363
// Allocates the chunk from the virtual space only.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   364
// This interface is also used internally for debugging.  Not all
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   365
// chunks removed here are necessarily used for allocation.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   366
Metachunk* VirtualSpaceNode::take_from_committed(size_t chunk_word_size) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   367
  // Non-humongous chunks are to be allocated aligned to their chunk
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   368
  // size. So, start addresses of medium chunks are aligned to medium
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   369
  // chunk size, those of small chunks to small chunk size and so
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   370
  // forth. This facilitates merging of free chunks and reduces
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   371
  // fragmentation. Chunk sizes are spec < small < medium, with each
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   372
  // larger chunk size being a multiple of the next smaller chunk
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   373
  // size.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   374
  // Because of this alignment, me may need to create a number of padding
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   375
  // chunks. These chunks are created and added to the freelist.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   376
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   377
  // The chunk manager to which we will give our padding chunks.
53970
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   378
  ChunkManager* const chunk_manager = Metaspace::get_chunk_manager(is_class());
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   379
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   380
  // shorthands
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   381
  const size_t spec_word_size = chunk_manager->specialized_chunk_word_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   382
  const size_t small_word_size = chunk_manager->small_chunk_word_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   383
  const size_t med_word_size = chunk_manager->medium_chunk_word_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   384
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   385
  assert(chunk_word_size == spec_word_size || chunk_word_size == small_word_size ||
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   386
      chunk_word_size >= med_word_size, "Invalid chunk size requested.");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   387
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   388
  // Chunk alignment (in bytes) == chunk size unless humongous.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   389
  // Humongous chunks are aligned to the smallest chunk size (spec).
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   390
  const size_t required_chunk_alignment = (chunk_word_size > med_word_size ?
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   391
      spec_word_size : chunk_word_size) * sizeof(MetaWord);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   392
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   393
  // Do we have enough space to create the requested chunk plus
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   394
  // any padding chunks needed?
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   395
  MetaWord* const next_aligned =
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   396
      static_cast<MetaWord*>(align_up(top(), required_chunk_alignment));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   397
  if (!is_available((next_aligned - top()) + chunk_word_size)) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   398
    return NULL;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   399
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   400
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   401
  // Before allocating the requested chunk, allocate padding chunks if necessary.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   402
  // We only need to do this for small or medium chunks: specialized chunks are the
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   403
  // smallest size, hence always aligned. Homungous chunks are allocated unaligned
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   404
  // (implicitly, also aligned to smallest chunk size).
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   405
  if ((chunk_word_size == med_word_size || chunk_word_size == small_word_size) && next_aligned > top())  {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   406
    log_trace(gc, metaspace, freelist)("Creating padding chunks in %s between %p and %p...",
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   407
        (is_class() ? "class space " : "metaspace"),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   408
        top(), next_aligned);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   409
    allocate_padding_chunks_until_top_is_at(next_aligned);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   410
    // Now, top should be aligned correctly.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   411
    assert_is_aligned(top(), required_chunk_alignment);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   412
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   413
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   414
  // Now, top should be aligned correctly.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   415
  assert_is_aligned(top(), required_chunk_alignment);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   416
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   417
  // Bottom of the new chunk
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   418
  MetaWord* chunk_limit = top();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   419
  assert(chunk_limit != NULL, "Not safe to call this method");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   420
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   421
  // The virtual spaces are always expanded by the
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   422
  // commit granularity to enforce the following condition.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   423
  // Without this the is_available check will not work correctly.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   424
  assert(_virtual_space.committed_size() == _virtual_space.actual_committed_size(),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   425
      "The committed memory doesn't match the expanded memory.");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   426
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   427
  if (!is_available(chunk_word_size)) {
50811
f533eb5e7430 8205664: Move detailed metaspace logging from debug to trace
pliden
parents: 50286
diff changeset
   428
    LogTarget(Trace, gc, metaspace, freelist) lt;
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   429
    if (lt.is_enabled()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   430
      LogStream ls(lt);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   431
      ls.print("VirtualSpaceNode::take_from_committed() not available " SIZE_FORMAT " words ", chunk_word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   432
      // Dump some information about the virtual space that is nearly full
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   433
      print_on(&ls);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   434
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   435
    return NULL;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   436
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   437
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   438
  // Take the space  (bump top on the current virtual space).
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   439
  inc_top(chunk_word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   440
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   441
  // Initialize the chunk
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   442
  ChunkIndex chunk_type = get_chunk_type_by_size(chunk_word_size, is_class());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   443
  Metachunk* result = ::new (chunk_limit) Metachunk(chunk_type, is_class(), chunk_word_size, this);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   444
  assert(result == (Metachunk*)chunk_limit, "Sanity");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   445
  occupancy_map()->set_chunk_starts_at_address((MetaWord*)result, true);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   446
  do_update_in_use_info_for_chunk(result, true);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   447
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   448
  inc_container_count();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   449
53970
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   450
#ifdef ASSERT
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   451
  EVERY_NTH(VerifyMetaspaceInterval)
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   452
    chunk_manager->locked_verify(true);
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   453
    verify(true);
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   454
  END_EVERY_NTH
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   455
  do_verify_chunk(result);
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   456
#endif
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   457
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   458
  result->inc_use_count();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   459
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   460
  return result;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   461
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   462
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   463
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   464
// Expand the virtual space (commit more of the reserved space)
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   465
bool VirtualSpaceNode::expand_by(size_t min_words, size_t preferred_words) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   466
  size_t min_bytes = min_words * BytesPerWord;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   467
  size_t preferred_bytes = preferred_words * BytesPerWord;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   468
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   469
  size_t uncommitted = virtual_space()->reserved_size() - virtual_space()->actual_committed_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   470
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   471
  if (uncommitted < min_bytes) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   472
    return false;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   473
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   474
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   475
  size_t commit = MIN2(preferred_bytes, uncommitted);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   476
  bool result = virtual_space()->expand_by(commit, false);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   477
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   478
  if (result) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   479
    log_trace(gc, metaspace, freelist)("Expanded %s virtual space list node by " SIZE_FORMAT " words.",
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   480
        (is_class() ? "class" : "non-class"), commit);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   481
    DEBUG_ONLY(Atomic::inc(&g_internal_statistics.num_committed_space_expanded));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   482
  } else {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   483
    log_trace(gc, metaspace, freelist)("Failed to expand %s virtual space list node by " SIZE_FORMAT " words.",
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   484
        (is_class() ? "class" : "non-class"), commit);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   485
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   486
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   487
  assert(result, "Failed to commit memory");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   488
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   489
  return result;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   490
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   491
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   492
Metachunk* VirtualSpaceNode::get_chunk_vs(size_t chunk_word_size) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   493
  assert_lock_strong(MetaspaceExpand_lock);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   494
  Metachunk* result = take_from_committed(chunk_word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   495
  return result;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   496
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   497
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   498
bool VirtualSpaceNode::initialize() {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   499
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   500
  if (!_rs.is_reserved()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   501
    return false;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   502
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   503
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   504
  // These are necessary restriction to make sure that the virtual space always
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   505
  // grows in steps of Metaspace::commit_alignment(). If both base and size are
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   506
  // aligned only the middle alignment of the VirtualSpace is used.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   507
  assert_is_aligned(_rs.base(), Metaspace::commit_alignment());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   508
  assert_is_aligned(_rs.size(), Metaspace::commit_alignment());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   509
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   510
  // ReservedSpaces marked as special will have the entire memory
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   511
  // pre-committed. Setting a committed size will make sure that
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   512
  // committed_size and actual_committed_size agrees.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   513
  size_t pre_committed_size = _rs.special() ? _rs.size() : 0;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   514
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   515
  bool result = virtual_space()->initialize_with_granularity(_rs, pre_committed_size,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   516
      Metaspace::commit_alignment());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   517
  if (result) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   518
    assert(virtual_space()->committed_size() == virtual_space()->actual_committed_size(),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   519
        "Checking that the pre-committed memory was registered by the VirtualSpace");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   520
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   521
    set_top((MetaWord*)virtual_space()->low());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   522
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   523
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   524
  // Initialize Occupancy Map.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   525
  const size_t smallest_chunk_size = is_class() ? ClassSpecializedChunk : SpecializedChunk;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   526
  _occupancy_map = new OccupancyMap(bottom(), reserved_words(), smallest_chunk_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   527
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   528
  return result;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   529
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   530
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   531
void VirtualSpaceNode::print_on(outputStream* st, size_t scale) const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   532
  size_t used_words = used_words_in_vs();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   533
  size_t commit_words = committed_words();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   534
  size_t res_words = reserved_words();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   535
  VirtualSpace* vs = virtual_space();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   536
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   537
  st->print("node @" PTR_FORMAT ": ", p2i(this));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   538
  st->print("reserved=");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   539
  print_scaled_words(st, res_words, scale);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   540
  st->print(", committed=");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   541
  print_scaled_words_and_percentage(st, commit_words, res_words, scale);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   542
  st->print(", used=");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   543
  print_scaled_words_and_percentage(st, used_words, res_words, scale);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   544
  st->cr();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   545
  st->print("   [" PTR_FORMAT ", " PTR_FORMAT ", "
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   546
      PTR_FORMAT ", " PTR_FORMAT ")",
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   547
      p2i(bottom()), p2i(top()), p2i(end()),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   548
      p2i(vs->high_boundary()));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   549
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   550
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   551
#ifdef ASSERT
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   552
void VirtualSpaceNode::mangle() {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   553
  size_t word_size = capacity_words_in_vs();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   554
  Copy::fill_to_words((HeapWord*) low(), word_size, 0xf1f1f1f1);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   555
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   556
#endif // ASSERT
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   557
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   558
void VirtualSpaceNode::retire(ChunkManager* chunk_manager) {
53970
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   559
  assert(is_class() == chunk_manager->is_class(), "Wrong ChunkManager?");
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   560
#ifdef ASSERT
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   561
  verify(false);
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   562
  EVERY_NTH(VerifyMetaspaceInterval)
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   563
    verify(true);
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   564
  END_EVERY_NTH
1ad7c590a6e7 8218988: Improve metaspace verifications
stuefe
parents: 51334
diff changeset
   565
#endif
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   566
  for (int i = (int)MediumIndex; i >= (int)ZeroIndex; --i) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   567
    ChunkIndex index = (ChunkIndex)i;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   568
    size_t chunk_size = chunk_manager->size_by_index(index);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   569
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   570
    while (free_words_in_vs() >= chunk_size) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   571
      Metachunk* chunk = get_chunk_vs(chunk_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   572
      // Chunk will be allocated aligned, so allocation may require
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   573
      // additional padding chunks. That may cause above allocation to
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   574
      // fail. Just ignore the failed allocation and continue with the
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   575
      // next smaller chunk size. As the VirtualSpaceNode comitted
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   576
      // size should be a multiple of the smallest chunk size, we
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   577
      // should always be able to fill the VirtualSpace completely.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   578
      if (chunk == NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   579
        break;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   580
      }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   581
      chunk_manager->return_single_chunk(chunk);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   582
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   583
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   584
  assert(free_words_in_vs() == 0, "should be empty now");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   585
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   586
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   587
} // namespace metaspace
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   588