|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, 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 "compiler/compiler_globals.hpp" |
| 26 | +#include "runtime/arguments.hpp" |
| 27 | +#include "runtime/flags/jvmFlag.hpp" |
| 28 | +#include "runtime/globals.hpp" |
| 29 | +#include "unittest.hpp" |
| 30 | + |
| 31 | +class LargeOptionsTest : public ::testing::Test { |
| 32 | +public: |
| 33 | + static bool test_option_value(const char* option, intx value) { |
| 34 | + char buffer[100]; |
| 35 | + UnlockDiagnosticVMOptions = true; |
| 36 | + os::snprintf(buffer, 100, "%s=" INTX_FORMAT, option, value); |
| 37 | + return Arguments::parse_argument(buffer, JVMFlagOrigin::COMMAND_LINE); |
| 38 | + } |
| 39 | + |
| 40 | + static bool test_option_value(const char* option) { |
| 41 | + UnlockDiagnosticVMOptions = true; |
| 42 | + return Arguments::parse_argument(option, JVMFlagOrigin::COMMAND_LINE); |
| 43 | + } |
| 44 | +}; |
| 45 | + |
| 46 | + |
| 47 | +// CompilerDirectivesLimit is a diagnostic int option. |
| 48 | +TEST_VM(LARGE_OPTION, large_ints) { |
| 49 | + for (intx x = max_jint - 1; x <= (intx)max_jint + 1; x++) { |
| 50 | + bool result = LargeOptionsTest::test_option_value("CompilerDirectivesLimit", x); |
| 51 | + if (x > max_jint) { |
| 52 | + ASSERT_FALSE(result); |
| 53 | + } else { |
| 54 | + ASSERT_TRUE(result); |
| 55 | + ASSERT_EQ(CompilerDirectivesLimit, x); |
| 56 | + } |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | + |
| 61 | +TEST_VM(LARGE_OPTION, small_ints) { |
| 62 | + for (intx x = min_jint + 1; x >= (intx)min_jint - 1; x--) { |
| 63 | + bool result = LargeOptionsTest::test_option_value("CompilerDirectivesLimit", x); |
| 64 | + if (x < min_jint) { |
| 65 | + ASSERT_FALSE(result); |
| 66 | + } else { |
| 67 | + ASSERT_TRUE(result); |
| 68 | + ASSERT_EQ(CompilerDirectivesLimit, x); |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | + |
| 74 | +TEST_VM(LARGE_OPTION, large_int_overflow) { // Test 0x100000000 |
| 75 | + ASSERT_FALSE(LargeOptionsTest::test_option_value("CompilerDirectivesLimit", 4294967296)); |
| 76 | +} |
| 77 | + |
| 78 | + |
| 79 | +// HandshakeTimeout is a diagnostic uint option. |
| 80 | +TEST_VM(LARGE_OPTION, large_uints) { |
| 81 | + for (uintx x = max_juint - 1; x <= (uintx)max_juint + 1; x++) { |
| 82 | + bool result = LargeOptionsTest::test_option_value("HandshakeTimeout", x); |
| 83 | + if (x <= max_juint) { |
| 84 | + ASSERT_TRUE(result); |
| 85 | + ASSERT_EQ(HandshakeTimeout, x); |
| 86 | + } else { |
| 87 | + ASSERT_FALSE(result); |
| 88 | + } |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | + |
| 93 | +// MaxJNILocalCapacity is an intx option. |
| 94 | +TEST_VM(LARGE_OPTION, large_intxs) { |
| 95 | + // max_intx + 1 equals min_intx! |
| 96 | + for (julong x = max_intx - 1; x <= (julong)max_intx + 1; x++) { |
| 97 | + ASSERT_TRUE(LargeOptionsTest::test_option_value("MaxJNILocalCapacity", x)); |
| 98 | + ASSERT_EQ((julong)MaxJNILocalCapacity, x); |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | + |
| 103 | +TEST_VM(LARGE_OPTION, small_intxs) { |
| 104 | + ASSERT_TRUE(LargeOptionsTest::test_option_value("MaxJNILocalCapacity", min_intx + 1)); |
| 105 | + ASSERT_EQ(MaxJNILocalCapacity, -9223372036854775807); |
| 106 | + ASSERT_TRUE(LargeOptionsTest::test_option_value("MaxJNILocalCapacity", min_intx)); |
| 107 | + ASSERT_EQ(MaxJNILocalCapacity, min_intx); |
| 108 | + // Test value that's less than min_intx (-0x8000000000000001). |
| 109 | + ASSERT_FALSE(LargeOptionsTest::test_option_value("MaxJNILocalCapacity=-9223372036854775809")); |
| 110 | +} |
0 commit comments