test/hotspot/gtest/memory/test_virtualspace.cpp
author iignatyev
Fri, 19 Oct 2018 16:29:45 -0700
changeset 52203 5e894b0f5e63
parent 52202 d1a1a5af1239
child 58063 bdf136b8ae0e
permissions -rw-r--r--
8177709: Convert TestVirtualSpace_test to GTest Reviewed-by: stuefe, jcbeyler
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52202
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
     1
/*
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
     4
 *
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
     8
 *
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    13
 * accompanied this code).
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    14
 *
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    18
 *
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    21
 * questions.
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    22
 */
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    23
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    24
#include "precompiled.hpp"
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    25
#include "memory/virtualspace.hpp"
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    26
#include "runtime/os.hpp"
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    27
#include "oops/oop.hpp"
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    28
#include "utilities/align.hpp"
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    29
#include "unittest.hpp"
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    30
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    31
namespace {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    32
  class MemoryReleaser {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    33
    ReservedSpace* const _rs;
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    34
   public:
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    35
    MemoryReleaser(ReservedSpace* rs) : _rs(rs) { }
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    36
    ~MemoryReleaser() {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    37
      if (_rs->special()) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    38
        EXPECT_TRUE(os::release_memory_special(_rs->base(), _rs->size()));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    39
      } else {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    40
        EXPECT_TRUE(os::release_memory(_rs->base(), _rs->size()));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    41
      }
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    42
    }
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    43
  };
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    44
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    45
  static void small_page_write(void* addr, size_t size) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    46
    size_t page_size = os::vm_page_size();
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    47
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    48
    char* end = (char*) addr + size;
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    49
    for (char* p = (char*) addr; p < end; p += page_size) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    50
      *p = 1;
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    51
    }
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    52
  }
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    53
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    54
  // have to use these functions, as gtest's _PRED macros don't like is_aligned
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    55
  // nor (is_aligned<size_t, size_t>)
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    56
  static bool is_size_aligned(size_t size, size_t alignment) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    57
    return is_aligned(size, alignment);
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    58
  }
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    59
  static bool is_ptr_aligned(void* ptr, size_t alignment) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    60
    return is_aligned(ptr, alignment);
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    61
  }
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    62
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    63
  static void test_reserved_size(size_t size) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    64
    ASSERT_PRED2(is_size_aligned, size, os::vm_allocation_granularity());
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    65
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    66
    ReservedSpace rs(size);
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    67
    MemoryReleaser releaser(&rs);
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    68
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    69
    EXPECT_TRUE(rs.base() != NULL) << "rs.special: " << rs.special();
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    70
    EXPECT_EQ(size, rs.size()) << "rs.special: " << rs.special();
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    71
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    72
    if (rs.special()) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    73
      small_page_write(rs.base(), size);
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    74
    }
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    75
  }
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    76
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    77
  static void test_reserved_size_alignment(size_t size, size_t alignment) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    78
    ASSERT_PRED2(is_size_aligned, size, alignment) << "Incorrect input parameters";
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    79
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    80
    ReservedSpace rs(size, alignment, UseLargePages, (char *) NULL);
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    81
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    82
    ASSERT_TRUE(rs.base() != NULL) << "rs.special = " << rs.special();
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    83
    ASSERT_EQ(size, rs.size()) << "rs.special = " << rs.special();
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    84
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    85
    EXPECT_PRED2(is_ptr_aligned, rs.base(), alignment)
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    86
            << "aligned sizes should always give aligned addresses";
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    87
    EXPECT_PRED2(is_ptr_aligned, (void*) rs.size(), alignment)
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    88
            << "aligned sizes should always give aligned addresses";
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    89
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    90
    if (rs.special()) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    91
      small_page_write(rs.base(), size);
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    92
    }
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    93
  }
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    94
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    95
  static void test_reserved_size_alignment_page_type(size_t size, size_t alignment, bool maybe_large) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    96
    if (size < alignment) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    97
      // Tests might set -XX:LargePageSizeInBytes=<small pages> and cause unexpected input arguments for this test.
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    98
      ASSERT_EQ((size_t) os::vm_page_size(), os::large_page_size()) << "Test needs further refinement";
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
    99
      return;
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   100
    }
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   101
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   102
    ASSERT_PRED2(is_size_aligned, size, os::vm_allocation_granularity()) << "Must be at least AG aligned";
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   103
    ASSERT_PRED2(is_size_aligned, size, alignment) << "Must be at least AG aligned";
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   104
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   105
    bool large = maybe_large && UseLargePages && size >= os::large_page_size();
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   106
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   107
    ReservedSpace rs(size, alignment, large, false);
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   108
    MemoryReleaser releaser(&rs);
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   109
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   110
    EXPECT_TRUE(rs.base() != NULL) << "rs.special: " << rs.special();
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   111
    EXPECT_EQ(size, rs.size()) << "rs.special: " << rs.special();
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   112
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   113
    if (rs.special()) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   114
      small_page_write(rs.base(), size);
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   115
    }
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   116
  }
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   117
}
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   118
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   119
TEST_VM(ReservedSpace, size_alignment) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   120
  size_t size = 2 * 1024 * 1024;
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   121
  size_t ag   = os::vm_allocation_granularity();
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   122
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   123
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment(size,      ag));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   124
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment(size * 2,  ag));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   125
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment(size * 10, ag));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   126
}
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   127
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   128
TEST_VM(ReservedSpace, size) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   129
  size_t size = 2 * 1024 * 1024;
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   130
  size_t ag = os::vm_allocation_granularity();
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   131
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   132
  EXPECT_NO_FATAL_FAILURE(test_reserved_size(size * 1));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   133
  EXPECT_NO_FATAL_FAILURE(test_reserved_size(size * 2));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   134
  EXPECT_NO_FATAL_FAILURE(test_reserved_size(size * 10));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   135
  EXPECT_NO_FATAL_FAILURE(test_reserved_size(ag));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   136
  EXPECT_NO_FATAL_FAILURE(test_reserved_size(size - ag));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   137
  EXPECT_NO_FATAL_FAILURE(test_reserved_size(size));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   138
  EXPECT_NO_FATAL_FAILURE(test_reserved_size(size + ag));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   139
  EXPECT_NO_FATAL_FAILURE(test_reserved_size(size * 2));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   140
  EXPECT_NO_FATAL_FAILURE(test_reserved_size(size * 2 - ag));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   141
  EXPECT_NO_FATAL_FAILURE(test_reserved_size(size * 2 + ag));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   142
  EXPECT_NO_FATAL_FAILURE(test_reserved_size(size * 3));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   143
  EXPECT_NO_FATAL_FAILURE(test_reserved_size(size * 3 - ag));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   144
  EXPECT_NO_FATAL_FAILURE(test_reserved_size(size * 3 + ag));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   145
  EXPECT_NO_FATAL_FAILURE(test_reserved_size(size * 10));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   146
  EXPECT_NO_FATAL_FAILURE(test_reserved_size(size * 10 + size / 2));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   147
}
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   148
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   149
TEST_VM(ReservedSpace, size_alignment_page_type) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   150
  size_t ag = os::vm_allocation_granularity();
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   151
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   152
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(ag,      ag    , false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   153
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(ag * 2,  ag    , false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   154
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(ag * 3,  ag    , false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   155
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(ag * 2,  ag * 2, false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   156
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(ag * 4,  ag * 2, false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   157
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(ag * 8,  ag * 2, false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   158
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(ag * 4,  ag * 4, false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   159
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(ag * 8,  ag * 4, false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   160
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(ag * 16, ag * 4, false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   161
}
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   162
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   163
TEST_VM(ReservedSpace, size_alignment_page_type_large_page) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   164
  if (!UseLargePages) {
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   165
    return;
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   166
  }
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   167
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   168
  size_t ag = os::vm_allocation_granularity();
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   169
  size_t lp = os::large_page_size();
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   170
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   171
  // Without large pages
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   172
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp,     ag * 4, false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   173
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 2, ag * 4, false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   174
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 4, ag * 4, false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   175
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp,     lp    , false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   176
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 2, lp    , false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   177
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 3, lp    , false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   178
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 2, lp * 2, false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   179
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 4, lp * 2, false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   180
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 8, lp * 2, false));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   181
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   182
  // With large pages
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   183
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp, ag * 4    , true));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   184
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 2, ag * 4, true));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   185
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 4, ag * 4, true));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   186
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp, lp        , true));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   187
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 2, lp    , true));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   188
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 3, lp    , true));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   189
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 2, lp * 2, true));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   190
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 4, lp * 2, true));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   191
  EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 8, lp * 2, true));
d1a1a5af1239 8171097: Convert TestReservedSpace_test to Gtest
kzhaldyb
parents:
diff changeset
   192
}
52203
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   193
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   194
namespace {
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   195
  enum TestLargePages {
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   196
    Default,
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   197
    Disable,
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   198
    Reserve,
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   199
    Commit
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   200
  };
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   201
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   202
  class ReservedSpaceReleaser {
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   203
    ReservedSpace* const _rs;
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   204
   public:
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   205
    ReservedSpaceReleaser(ReservedSpace* rs) : _rs(rs) { }
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   206
    ~ReservedSpaceReleaser() {
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   207
      _rs->release();
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   208
    }
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   209
  };
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   210
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   211
  ReservedSpace reserve_memory(size_t reserve_size_aligned, TestLargePages mode) {
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   212
    switch(mode) {
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   213
      default:
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   214
      case Default:
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   215
      case Reserve:
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   216
        return ReservedSpace(reserve_size_aligned);
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   217
      case Disable:
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   218
      case Commit:
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   219
        return ReservedSpace(reserve_size_aligned,
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   220
                             os::vm_allocation_granularity(),
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   221
                             /* large */ false, /* exec */ false);
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   222
    }
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   223
  }
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   224
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   225
  bool initialize_virtual_space(VirtualSpace& vs, ReservedSpace rs, TestLargePages mode) {
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   226
    switch(mode) {
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   227
      default:
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   228
      case Default:
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   229
      case Reserve:
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   230
        return vs.initialize(rs, 0);
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   231
      case Disable:
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   232
        return vs.initialize_with_granularity(rs, 0, os::vm_page_size());
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   233
      case Commit:
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   234
        return vs.initialize_with_granularity(rs, 0, os::page_size_for_region_unaligned(rs.size(), 1));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   235
    }
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   236
  }
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   237
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   238
 void test_virtual_space_actual_committed_space(size_t reserve_size, size_t commit_size,
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   239
                                                TestLargePages mode = Default) {
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   240
    size_t granularity = os::vm_allocation_granularity();
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   241
    size_t reserve_size_aligned = align_up(reserve_size, granularity);
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   242
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   243
    ReservedSpace reserved = reserve_memory(reserve_size_aligned, mode);
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   244
    ReservedSpaceReleaser releaser(&reserved);
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   245
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   246
    ASSERT_TRUE(reserved.is_reserved());
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   247
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   248
    VirtualSpace vs;
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   249
    ASSERT_TRUE(initialize_virtual_space(vs, reserved, mode)) << "Failed to initialize VirtualSpace";
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   250
    vs.expand_by(commit_size, false);
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   251
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   252
    if (vs.special()) {
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   253
      EXPECT_EQ(reserve_size_aligned, vs.actual_committed_size());
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   254
    } else {
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   255
      EXPECT_GE(vs.actual_committed_size(), commit_size);
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   256
      // Approximate the commit granularity.
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   257
      // Make sure that we don't commit using large pages
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   258
      // if large pages has been disabled for this VirtualSpace.
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   259
      size_t commit_granularity = (mode == Disable || !UseLargePages) ?
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   260
                                   os::vm_page_size() : os::large_page_size();
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   261
      EXPECT_LT(vs.actual_committed_size(), commit_size + commit_granularity);
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   262
    }
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   263
  }
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   264
}
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   265
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   266
TEST_VM(VirtualSpace, actual_committed_space) {
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   267
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(4 * K,  0));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   268
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(4 * K,  4 * K));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   269
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(8 * K,  0));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   270
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(8 * K,  4 * K));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   271
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(8 * K,  8 * K));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   272
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(12 * K, 0));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   273
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(12 * K, 4 * K));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   274
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(12 * K, 8 * K));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   275
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(12 * K, 12 * K));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   276
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(64 * K, 0));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   277
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(64 * K, 32 * K));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   278
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(64 * K, 64 * K));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   279
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(2 * M,  0));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   280
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(2 * M,  4 * K));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   281
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(2 * M,  64 * K));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   282
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(2 * M,  1 * M));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   283
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(2 * M,  2 * M));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   284
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 0));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   285
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 4 * K));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   286
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 8 * K));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   287
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 1 * M));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   288
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 2 * M));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   289
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 5 * M));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   290
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 10 * M));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   291
}
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   292
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   293
TEST_VM(VirtualSpace, actual_committed_space_one_large_page) {
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   294
  if (!UseLargePages) {
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   295
    return;
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   296
  }
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   297
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   298
  size_t large_page_size = os::large_page_size();
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   299
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   300
  ReservedSpace reserved(large_page_size, large_page_size, true, false);
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   301
  ReservedSpaceReleaser releaser(&reserved);
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   302
  ASSERT_TRUE(reserved.is_reserved());
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   303
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   304
  VirtualSpace vs;
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   305
  ASSERT_TRUE(vs.initialize(reserved, 0)) << "Failed to initialize VirtualSpace";
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   306
  vs.expand_by(large_page_size, false);
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   307
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   308
  EXPECT_EQ(large_page_size, vs.actual_committed_size());
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   309
}
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   310
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   311
TEST_VM(VirtualSpace, disable_large_pages) {
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   312
  if (!UseLargePages) {
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   313
    return;
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   314
  }
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   315
  // These test cases verify that if we force VirtualSpace to disable large pages
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   316
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 0,      Disable));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   317
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 4 * K,  Disable));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   318
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 8 * K,  Disable));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   319
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 1 * M,  Disable));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   320
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 2 * M,  Disable));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   321
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 5 * M,  Disable));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   322
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 10 * M, Disable));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   323
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   324
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 0,      Reserve));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   325
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 4 * K,  Reserve));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   326
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 8 * K,  Reserve));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   327
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 1 * M,  Reserve));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   328
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 2 * M,  Reserve));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   329
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 5 * M,  Reserve));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   330
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 10 * M, Reserve));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   331
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   332
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 0,      Commit));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   333
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 4 * K,  Commit));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   334
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 8 * K,  Commit));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   335
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 1 * M,  Commit));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   336
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 2 * M,  Commit));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   337
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 5 * M,  Commit));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   338
  EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 10 * M, Commit));
5e894b0f5e63 8177709: Convert TestVirtualSpace_test to GTest
iignatyev
parents: 52202
diff changeset
   339
}