test/hotspot/gtest/memory/test_spaceManager.cpp
author herrick
Mon, 17 Jun 2019 15:18:52 -0400
branchJDK-8200758-branch
changeset 57412 02034583f4dc
parent 50193 49c3e91c424f
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
     1
/*
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
     4
 *
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
     7
 * published by the Free Software Foundation.
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
     8
 *
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    13
 * accompanied this code).
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    14
 *
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    18
 *
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    21
 * questions.
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    22
 */
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    23
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    24
#include "precompiled.hpp"
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    25
#include "memory/metaspace/spaceManager.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    26
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    27
using metaspace::SpaceManager;
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    28
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    29
// The test function is only available in debug builds
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    30
#ifdef ASSERT
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    31
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    32
#include "unittest.hpp"
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    33
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    34
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    35
static void test_adjust_initial_chunk_size(bool is_class) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    36
  const size_t smallest = SpaceManager::smallest_chunk_size(is_class);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    37
  const size_t normal   = SpaceManager::small_chunk_size(is_class);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    38
  const size_t medium   = SpaceManager::medium_chunk_size(is_class);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    39
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    40
#define do_test(value, expected, is_class_value)                                 \
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    41
    do {                                                                         \
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    42
      size_t v = value;                                                          \
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    43
      size_t e = expected;                                                       \
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    44
      assert(SpaceManager::adjust_initial_chunk_size(v, (is_class_value)) == e,  \
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    45
             "Expected: " SIZE_FORMAT " got: " SIZE_FORMAT, e, v);               \
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    46
    } while (0)
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    47
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    48
    // Smallest (specialized)
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    49
    do_test(1,            smallest, is_class);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    50
    do_test(smallest - 1, smallest, is_class);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    51
    do_test(smallest,     smallest, is_class);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    52
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    53
    // Small
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    54
    do_test(smallest + 1, normal, is_class);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    55
    do_test(normal - 1,   normal, is_class);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    56
    do_test(normal,       normal, is_class);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    57
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    58
    // Medium
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    59
    do_test(normal + 1, medium, is_class);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    60
    do_test(medium - 1, medium, is_class);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    61
    do_test(medium,     medium, is_class);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    62
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    63
    // Humongous
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    64
    do_test(medium + 1, medium + 1, is_class);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    65
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    66
#undef test_adjust_initial_chunk_size
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    67
}
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    68
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    69
TEST(SpaceManager, adjust_initial_chunk_size) {
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    70
  test_adjust_initial_chunk_size(true);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 47216
diff changeset
    71
  test_adjust_initial_chunk_size(false);
42615
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    72
}
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    73
86c4562176fa 8170395: Metaspace initialization queries the wrong chunk freelist
stefank
parents:
diff changeset
    74
#endif // ASSERT