hotspot/src/share/vm/memory/metachunk.cpp
author brutisso
Mon, 01 Dec 2014 14:37:25 +0100
changeset 27904 d606512952cc
parent 24424 2658d7834c6e
child 29800 fa5f7a2bf717
permissions -rw-r--r--
8065993: Merge OneContigSpaceCardGeneration with TenuredGeneration Reviewed-by: mgerdin, kbarrett
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
/*
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 20730
diff changeset
     2
 * Copyright (c) 2012, 2014, 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
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 20730
diff changeset
    31
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 20730
diff changeset
    32
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    33
class VirtualSpaceNode;
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    34
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    35
const size_t metadata_chunk_initialize = 0xf7f7f7f7;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    36
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    37
size_t Metachunk::object_alignment() {
20730
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    38
  // Must align pointers and sizes to 8,
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    39
  // so that 64 bit types get correctly aligned.
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    40
  const size_t alignment = 8;
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
  // Make sure that the Klass alignment also agree.
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    43
  STATIC_ASSERT(alignment == (size_t)KlassAlignmentInBytes);
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    44
59f433c86d9d 8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents: 20729
diff changeset
    45
  return alignment;
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    46
}
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    47
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    48
size_t Metachunk::overhead() {
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    49
  return align_size_up(sizeof(Metachunk), object_alignment()) / BytesPerWord;
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    50
}
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    51
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    52
// Metachunk methods
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    53
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    54
Metachunk::Metachunk(size_t word_size,
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    55
                     VirtualSpaceNode* container)
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    56
    : Metabase<Metachunk>(word_size),
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    57
    _top(NULL),
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    58
    _container(container)
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    59
{
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    60
  _top = initial_top();
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    61
#ifdef ASSERT
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    62
  set_is_tagged_free(false);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    63
  size_t data_word_size = pointer_delta(end(),
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    64
                                        _top,
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    65
                                        sizeof(MetaWord));
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    66
  Copy::fill_to_words((HeapWord*)_top,
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    67
                      data_word_size,
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 15086
diff changeset
    68
                      metadata_chunk_initialize);
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    69
#endif
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
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    72
MetaWord* Metachunk::allocate(size_t word_size) {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    73
  MetaWord* result = NULL;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    74
  // If available, bump the pointer to allocate.
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    75
  if (free_word_size() >= word_size) {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    76
    result = _top;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    77
    _top = _top + word_size;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    78
  }
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    79
  return result;
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
// _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
    83
size_t Metachunk::used_word_size() const {
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    84
  return pointer_delta(_top, bottom(), sizeof(MetaWord));
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    85
}
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    86
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14635
diff changeset
    87
size_t Metachunk::free_word_size() const {
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    88
  return pointer_delta(end(), _top, sizeof(MetaWord));
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    89
}
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    90
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    91
void Metachunk::print_on(outputStream* st) const {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    92
  st->print_cr("Metachunk:"
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    93
               " bottom " PTR_FORMAT " top " PTR_FORMAT
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
    94
               " end " PTR_FORMAT " size " SIZE_FORMAT,
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
    95
               bottom(), _top, end(), word_size());
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14635
diff changeset
    96
  if (Verbose) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14635
diff changeset
    97
    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
    98
                 used_word_size(), free_word_size());
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14635
diff changeset
    99
  }
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
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   102
#ifndef PRODUCT
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   103
void Metachunk::mangle() {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   104
  // Mangle the payload of the chunk and not the links that
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   105
  // maintain list of chunks.
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   106
  HeapWord* start = (HeapWord*)(bottom() + overhead());
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   107
  size_t size = word_size() - overhead();
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   108
  Copy::fill_to_words(start, size, metadata_chunk_initialize);
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   109
}
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   110
#endif // PRODUCT
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   111
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   112
void Metachunk::verify() {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   113
#ifdef ASSERT
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   114
  // 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
   115
  // headers with sizes.
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   116
  assert(bottom() <= _top &&
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   117
         _top <= (MetaWord*)end(),
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   118
         "Chunk has been smashed");
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   119
#endif
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   120
  return;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff changeset
   121
}
20729
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   122
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   123
/////////////// Unit tests ///////////////
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   124
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   125
#ifndef PRODUCT
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   126
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   127
class TestMetachunk {
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   128
 public:
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   129
  static void test() {
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   130
    size_t size = 2 * 1024 * 1024;
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   131
    void* memory = malloc(size);
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   132
    assert(memory != NULL, "Failed to malloc 2MB");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   133
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   134
    Metachunk* metachunk = ::new (memory) Metachunk(size / BytesPerWord, NULL);
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   135
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   136
    assert(metachunk->bottom() == (MetaWord*)metachunk, "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   137
    assert(metachunk->end() == (uintptr_t*)metachunk + metachunk->size(), "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   138
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   139
    // Check sizes
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   140
    assert(metachunk->size() == metachunk->word_size(), "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   141
    assert(metachunk->word_size() == pointer_delta(metachunk->end(), metachunk->bottom(),
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   142
        sizeof(MetaWord*)), "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   143
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   144
    // Check usage
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   145
    assert(metachunk->used_word_size() == metachunk->overhead(), "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   146
    assert(metachunk->free_word_size() == metachunk->word_size() - metachunk->used_word_size(), "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   147
    assert(metachunk->top() == metachunk->initial_top(), "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   148
    assert(metachunk->is_empty(), "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   149
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   150
    // Allocate
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   151
    size_t alloc_size = 64; // Words
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   152
    assert(is_size_aligned(alloc_size, Metachunk::object_alignment()), "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   153
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   154
    MetaWord* mem = metachunk->allocate(alloc_size);
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   155
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   156
    // Check post alloc
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   157
    assert(mem == metachunk->initial_top(), "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   158
    assert(mem + alloc_size == metachunk->top(), "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   159
    assert(metachunk->used_word_size() == metachunk->overhead() + alloc_size, "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   160
    assert(metachunk->free_word_size() == metachunk->word_size() - metachunk->used_word_size(), "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   161
    assert(!metachunk->is_empty(), "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   162
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   163
    // Clear chunk
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   164
    metachunk->reset_empty();
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   165
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   166
    // Check post clear
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   167
    assert(metachunk->used_word_size() == metachunk->overhead(), "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   168
    assert(metachunk->free_word_size() == metachunk->word_size() - metachunk->used_word_size(), "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   169
    assert(metachunk->top() == metachunk->initial_top(), "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   170
    assert(metachunk->is_empty(), "assert");
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   171
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   172
    free(memory);
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   173
  }
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   174
};
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   175
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   176
void TestMetachunk_test() {
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   177
  TestMetachunk::test();
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   178
}
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   179
0a687ee7097d 8026391: The Metachunk header wastes memory
stefank
parents: 17101
diff changeset
   180
#endif