author | manc |
Mon, 14 Oct 2019 18:48:10 -0700 | |
changeset 58652 | 9b67dd88a931 |
parent 57875 | 427b38332f20 |
permissions | -rw-r--r-- |
42641 | 1 |
/* |
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
#include "precompiled.hpp" |
|
25 |
#include "runtime/os.hpp" |
|
26 |
#include "unittest.hpp" |
|
57875
427b38332f20
8229836: Remove include of globals.hpp from allocation.hpp
stefank
parents:
53386
diff
changeset
|
27 |
#include "utilities/align.hpp" |
42641 | 28 |
#include "utilities/globalDefinitions.hpp" |
29 |
||
30 |
static ::testing::AssertionResult testPageAddress( |
|
31 |
const char* expected_addr_expr, |
|
32 |
const char* addr_expr, |
|
33 |
const char* page_addr_expr, |
|
34 |
const char* page_size_expr, |
|
35 |
const char* actual_addr_expr, |
|
36 |
address expected_addr, |
|
37 |
address addr, |
|
38 |
address page_addr, |
|
39 |
intptr_t page_size, |
|
40 |
address actual_addr) { |
|
41 |
if (expected_addr == actual_addr) { |
|
42 |
return ::testing::AssertionSuccess(); |
|
43 |
} |
|
44 |
||
45 |
return ::testing::AssertionFailure() |
|
46 |
<< actual_addr_expr << " returned unexpected address " << (void*) actual_addr << std::endl |
|
47 |
<< "Expected " << expected_addr_expr << ": " << (void*) expected_addr << std::endl |
|
48 |
<< "where" << std::endl |
|
49 |
<< addr_expr << ": " << (void*) addr << std::endl |
|
50 |
<< page_addr_expr << ": " << (void*) page_addr << std::endl |
|
51 |
<< page_size_expr << ": " << page_size; |
|
52 |
} |
|
53 |
||
54 |
TEST_VM(globalDefinitions, clamp_address_in_page) { |
|
55 |
const intptr_t page_sizes[] = {os::vm_page_size(), 4096, 8192, 65536, 2 * 1024 * 1024}; |
|
56 |
const int num_page_sizes = sizeof(page_sizes) / sizeof(page_sizes[0]); |
|
57 |
||
58 |
for (int i = 0; i < num_page_sizes; i++) { |
|
59 |
intptr_t page_size = page_sizes[i]; |
|
60 |
address page_address = (address) (10 * page_size); |
|
61 |
||
62 |
const intptr_t within_page_offsets[] = {0, 128, page_size - 1}; |
|
63 |
const int num_within_page_offsets = sizeof(within_page_offsets) / sizeof(within_page_offsets[0]); |
|
64 |
||
65 |
for (int k = 0; k < num_within_page_offsets; ++k) { |
|
66 |
address addr = page_address + within_page_offsets[k]; |
|
67 |
address expected_address = addr; |
|
68 |
EXPECT_PRED_FORMAT5(testPageAddress, expected_address, addr, page_address, page_size, |
|
69 |
clamp_address_in_page(addr, page_address, page_size)) |
|
70 |
<< "Expect that address within page is returned as is"; |
|
71 |
} |
|
72 |
||
73 |
const intptr_t above_page_offsets[] = {page_size, page_size + 1, 5 * page_size + 1}; |
|
74 |
const int num_above_page_offsets = sizeof(above_page_offsets) / sizeof(above_page_offsets[0]); |
|
75 |
||
76 |
for (int k = 0; k < num_above_page_offsets; ++k) { |
|
77 |
address addr = page_address + above_page_offsets[k]; |
|
78 |
address expected_address = page_address + page_size; |
|
79 |
EXPECT_PRED_FORMAT5(testPageAddress, expected_address, addr, page_address, page_size, |
|
80 |
clamp_address_in_page(addr, page_address, page_size)) |
|
81 |
<< "Expect that address above page returns start of next page"; |
|
82 |
} |
|
83 |
||
84 |
const intptr_t below_page_offsets[] = {1, 2 * page_size + 1, 5 * page_size + 1}; |
|
85 |
const int num_below_page_offsets = sizeof(below_page_offsets) / sizeof(below_page_offsets[0]); |
|
86 |
||
87 |
for (int k = 0; k < num_below_page_offsets; ++k) { |
|
88 |
address addr = page_address - below_page_offsets[k]; |
|
89 |
address expected_address = page_address; |
|
90 |
EXPECT_PRED_FORMAT5(testPageAddress, expected_address, addr, page_address, page_size, |
|
91 |
clamp_address_in_page(addr, page_address, page_size)) |
|
92 |
<< "Expect that address below page returns start of page"; |
|
93 |
} |
|
94 |
} |
|
95 |
} |
|
96 |
||
53386
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
97 |
TEST(globalDefinitions, proper_unit) { |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
98 |
EXPECT_EQ(0u, byte_size_in_proper_unit(0u)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
99 |
EXPECT_STREQ("B", proper_unit_for_byte_size(0u)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
100 |
|
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
101 |
EXPECT_EQ(1u, byte_size_in_proper_unit(1u)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
102 |
EXPECT_STREQ("B", proper_unit_for_byte_size(1u)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
103 |
|
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
104 |
EXPECT_EQ(1023u, byte_size_in_proper_unit(K - 1)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
105 |
EXPECT_STREQ("B", proper_unit_for_byte_size(K - 1)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
106 |
|
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
107 |
EXPECT_EQ(1024u, byte_size_in_proper_unit(K)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
108 |
EXPECT_STREQ("B", proper_unit_for_byte_size(K)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
109 |
|
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
110 |
EXPECT_EQ(1025u, byte_size_in_proper_unit(K + 1)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
111 |
EXPECT_STREQ("B", proper_unit_for_byte_size(K + 1)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
112 |
|
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
113 |
EXPECT_EQ(51200u, byte_size_in_proper_unit(50*K)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
114 |
EXPECT_STREQ("B", proper_unit_for_byte_size(50*K)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
115 |
|
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
116 |
EXPECT_EQ(1023u, byte_size_in_proper_unit(M - 1)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
117 |
EXPECT_STREQ("K", proper_unit_for_byte_size(M - 1)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
118 |
|
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
119 |
EXPECT_EQ(1024u, byte_size_in_proper_unit(M)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
120 |
EXPECT_STREQ("K", proper_unit_for_byte_size(M)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
121 |
|
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
122 |
EXPECT_EQ(1024u, byte_size_in_proper_unit(M + 1)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
123 |
EXPECT_STREQ("K", proper_unit_for_byte_size(M + 1)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
124 |
|
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
125 |
EXPECT_EQ(1025u, byte_size_in_proper_unit(M + K)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
126 |
EXPECT_STREQ("K", proper_unit_for_byte_size(M + K)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
127 |
|
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
128 |
EXPECT_EQ(51200u, byte_size_in_proper_unit(50*M)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
129 |
EXPECT_STREQ("K", proper_unit_for_byte_size(50*M)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
130 |
|
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
131 |
#ifdef _LP64 |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
132 |
EXPECT_EQ(1023u, byte_size_in_proper_unit(G - 1)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
133 |
EXPECT_STREQ("M", proper_unit_for_byte_size(G - 1)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
134 |
|
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
135 |
EXPECT_EQ(1024u, byte_size_in_proper_unit(G)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
136 |
EXPECT_STREQ("M", proper_unit_for_byte_size(G)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
137 |
|
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
138 |
EXPECT_EQ(1024u, byte_size_in_proper_unit(G + 1)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
139 |
EXPECT_STREQ("M", proper_unit_for_byte_size(G + 1)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
140 |
|
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
141 |
EXPECT_EQ(1024u, byte_size_in_proper_unit(G + K)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
142 |
EXPECT_STREQ("M", proper_unit_for_byte_size(G + K)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
143 |
|
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
144 |
EXPECT_EQ(1025u, byte_size_in_proper_unit(G + M)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
145 |
EXPECT_STREQ("M", proper_unit_for_byte_size(G + M)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
146 |
|
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
147 |
EXPECT_EQ(51200u, byte_size_in_proper_unit(50*G)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
148 |
EXPECT_STREQ("M", proper_unit_for_byte_size(50*G)); |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
149 |
#endif |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
150 |
} |
d5f6540c6bb1
8217315: Proper units should print more significant digits
shade
parents:
53375
diff
changeset
|
151 |
|
42641 | 152 |
TEST(globalDefinitions, exact_unit_for_byte_size) { |
153 |
EXPECT_STREQ("B", exact_unit_for_byte_size(0)); |
|
154 |
EXPECT_STREQ("B", exact_unit_for_byte_size(1)); |
|
155 |
EXPECT_STREQ("B", exact_unit_for_byte_size(K - 1)); |
|
156 |
EXPECT_STREQ("K", exact_unit_for_byte_size(K)); |
|
157 |
EXPECT_STREQ("B", exact_unit_for_byte_size(K + 1)); |
|
158 |
EXPECT_STREQ("B", exact_unit_for_byte_size(M - 1)); |
|
159 |
EXPECT_STREQ("M", exact_unit_for_byte_size(M)); |
|
160 |
EXPECT_STREQ("B", exact_unit_for_byte_size(M + 1)); |
|
161 |
EXPECT_STREQ("K", exact_unit_for_byte_size(M + K)); |
|
53375
ae4295a6a01e
8217321: [TESTBUG] utilities/test_globalDefinitions.cpp should use _LP64, not LP64
shade
parents:
47216
diff
changeset
|
162 |
#ifdef _LP64 |
42641 | 163 |
EXPECT_STREQ("B", exact_unit_for_byte_size(G - 1)); |
164 |
EXPECT_STREQ("G", exact_unit_for_byte_size(G)); |
|
165 |
EXPECT_STREQ("B", exact_unit_for_byte_size(G + 1)); |
|
166 |
EXPECT_STREQ("K", exact_unit_for_byte_size(G + K)); |
|
167 |
EXPECT_STREQ("M", exact_unit_for_byte_size(G + M)); |
|
168 |
EXPECT_STREQ("K", exact_unit_for_byte_size(G + M + K)); |
|
169 |
#endif |
|
170 |
} |
|
171 |
||
172 |
TEST(globalDefinitions, byte_size_in_exact_unit) { |
|
173 |
EXPECT_EQ(0u, byte_size_in_exact_unit(0)); |
|
174 |
EXPECT_EQ(1u, byte_size_in_exact_unit(1)); |
|
175 |
EXPECT_EQ(K - 1, byte_size_in_exact_unit(K - 1)); |
|
176 |
EXPECT_EQ(1u, byte_size_in_exact_unit(K)); |
|
177 |
EXPECT_EQ(K + 1, byte_size_in_exact_unit(K + 1)); |
|
178 |
EXPECT_EQ(M - 1, byte_size_in_exact_unit(M - 1)); |
|
179 |
EXPECT_EQ(1u, byte_size_in_exact_unit(M)); |
|
180 |
EXPECT_EQ(M + 1, byte_size_in_exact_unit(M + 1)); |
|
181 |
EXPECT_EQ(K + 1, byte_size_in_exact_unit(M + K)); |
|
53375
ae4295a6a01e
8217321: [TESTBUG] utilities/test_globalDefinitions.cpp should use _LP64, not LP64
shade
parents:
47216
diff
changeset
|
182 |
#ifdef _LP64 |
42641 | 183 |
EXPECT_EQ(G - 1, byte_size_in_exact_unit(G - 1)); |
184 |
EXPECT_EQ(1u, byte_size_in_exact_unit(G)); |
|
185 |
EXPECT_EQ(G + 1, byte_size_in_exact_unit(G + 1)); |
|
186 |
EXPECT_EQ(M + 1, byte_size_in_exact_unit(G + K)); |
|
187 |
EXPECT_EQ(K + 1, byte_size_in_exact_unit(G + M)); |
|
188 |
EXPECT_EQ(M + K + 1, byte_size_in_exact_unit(G + M + K)); |
|
189 |
#endif |
|
190 |
} |