hotspot/test/native/runtime/test_os.cpp
author jwilhelm
Mon, 23 May 2016 19:46:43 +0200
changeset 42056 9296564b8c8b
parent 41705 332239c052cc
child 46587 6c97f34cb194
permissions -rw-r--r--
8157455: Convert TestOS_test to GTest Reviewed-by: dholmes, rehn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     1
/*
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     4
 *
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     8
 *
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    14
 *
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    18
 *
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    21
 * questions.
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    22
 */
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    23
39394
044a0eb96215 8159364: Gtest unit tests does not support PCH
ehelin
parents: 38255
diff changeset
    24
#include "precompiled.hpp"
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    25
#include "runtime/os.hpp"
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    26
#include "unittest.hpp"
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    27
42056
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    28
static size_t small_page_size() {
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    29
  return os::vm_page_size();
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    30
}
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    31
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    32
static size_t large_page_size() {
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    33
  const size_t large_page_size_example = 4 * M;
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    34
  return os::page_size_for_region_aligned(large_page_size_example, 1);
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    35
}
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    36
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    37
TEST_VM(os, page_size_for_region) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    38
  size_t large_page_example = 4 * M;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    39
  size_t large_page = os::page_size_for_region_aligned(large_page_example, 1);
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    40
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    41
  size_t small_page = os::vm_page_size();
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    42
  if (large_page > small_page) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    43
    size_t num_small_in_large = large_page / small_page;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    44
    size_t page = os::page_size_for_region_aligned(large_page, num_small_in_large);
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    45
    ASSERT_EQ(page, small_page) << "Did not get a small page";
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    46
  }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    47
}
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    48
42056
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    49
TEST_VM(os, page_size_for_region_aligned) {
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    50
  if (UseLargePages) {
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    51
    const size_t small_page = small_page_size();
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    52
    const size_t large_page = large_page_size();
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    53
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    54
    if (large_page > small_page) {
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    55
      size_t num_small_pages_in_large = large_page / small_page;
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    56
      size_t page = os::page_size_for_region_aligned(large_page, num_small_pages_in_large);
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    57
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    58
      ASSERT_EQ(page, small_page);
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    59
    }
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    60
  }
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    61
}
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    62
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    63
TEST_VM(os, page_size_for_region_alignment) {
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    64
  if (UseLargePages) {
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    65
    const size_t small_page = small_page_size();
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    66
    const size_t large_page = large_page_size();
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    67
    if (large_page > small_page) {
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    68
      const size_t unaligned_region = large_page + 17;
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    69
      size_t page = os::page_size_for_region_aligned(unaligned_region, 1);
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    70
      ASSERT_EQ(page, small_page);
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    71
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    72
      const size_t num_pages = 5;
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    73
      const size_t aligned_region = large_page * num_pages;
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    74
      page = os::page_size_for_region_aligned(aligned_region, num_pages);
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    75
      ASSERT_EQ(page, large_page);
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    76
    }
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    77
  }
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    78
}
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    79
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    80
TEST_VM(os, page_size_for_region_unaligned) {
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    81
  if (UseLargePages) {
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    82
    // Given exact page size, should return that page size.
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    83
    for (size_t i = 0; os::_page_sizes[i] != 0; i++) {
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    84
      size_t expected = os::_page_sizes[i];
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    85
      size_t actual = os::page_size_for_region_unaligned(expected, 1);
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    86
      ASSERT_EQ(expected, actual);
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    87
    }
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    88
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    89
    // Given slightly larger size than a page size, return the page size.
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    90
    for (size_t i = 0; os::_page_sizes[i] != 0; i++) {
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    91
      size_t expected = os::_page_sizes[i];
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    92
      size_t actual = os::page_size_for_region_unaligned(expected + 17, 1);
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    93
      ASSERT_EQ(expected, actual);
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    94
    }
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    95
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    96
    // Given a slightly smaller size than a page size,
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    97
    // return the next smaller page size.
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    98
    if (os::_page_sizes[1] > os::_page_sizes[0]) {
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
    99
      size_t expected = os::_page_sizes[0];
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
   100
      size_t actual = os::page_size_for_region_unaligned(os::_page_sizes[1] - 17, 1);
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
   101
      ASSERT_EQ(actual, expected);
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
   102
    }
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
   103
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
   104
    // Return small page size for values less than a small page.
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
   105
    size_t small_page = small_page_size();
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
   106
    size_t actual = os::page_size_for_region_unaligned(small_page - 17, 1);
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
   107
    ASSERT_EQ(small_page, actual);
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
   108
  }
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
   109
}
9296564b8c8b 8157455: Convert TestOS_test to GTest
jwilhelm
parents: 41705
diff changeset
   110
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   111
#ifdef ASSERT
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   112
TEST_VM_ASSERT_MSG(os, page_size_for_region_with_zero_min_pages, "sanity") {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   113
  size_t region_size = 16 * os::vm_page_size();
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   114
  os::page_size_for_region_aligned(region_size, 0); // should assert
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   115
}
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   116
#endif