|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * Copyright (c) 2020 SAP SE. All rights reserved. |
| 4 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | + * |
| 6 | + * This code is free software; you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU General Public License version 2 only, as |
| 8 | + * published by the Free Software Foundation. |
| 9 | + * |
| 10 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 11 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 14 | + * accompanied this code). |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License version |
| 17 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 18 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | + * |
| 20 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 21 | + * or visit www.oracle.com if you need additional information or have any |
| 22 | + * questions. |
| 23 | + */ |
| 24 | + |
| 25 | +#include "precompiled.hpp" |
| 26 | +#include "runtime/interfaceSupport.inline.hpp" |
| 27 | +#include "runtime/stubRoutines.hpp" |
| 28 | +#include "runtime/vmOperations.hpp" |
| 29 | +#include "runtime/vmThread.hpp" |
| 30 | +#include "utilities/globalDefinitions.hpp" |
| 31 | +#include "unittest.hpp" |
| 32 | + |
| 33 | +static const intptr_t pattern = LP64_ONLY(0xABCDABCDABCDABCDULL) NOT_LP64(0xABCDABCD); |
| 34 | +static intptr_t* invalid_address = (intptr_t*)(intptr_t) NOT_AIX(os::min_page_size()) AIX_ONLY(-1); |
| 35 | + |
| 36 | +TEST_VM(os, safefetch_positive) { |
| 37 | + intptr_t v = pattern; |
| 38 | + intptr_t a = SafeFetchN(&v, 1); |
| 39 | + ASSERT_EQ(v, a); |
| 40 | +} |
| 41 | + |
| 42 | +#ifndef _WIN32 |
| 43 | +// Needs JDK-8185734 to be solved |
| 44 | +TEST_VM(os, safefetch_negative) { |
| 45 | + intptr_t a = SafeFetchN(invalid_address, pattern); |
| 46 | + ASSERT_EQ(pattern, a); |
| 47 | + a = SafeFetchN(invalid_address, ~pattern); |
| 48 | + ASSERT_EQ(~pattern, a); |
| 49 | +} |
| 50 | +#endif // _WIN32 |
| 51 | + |
| 52 | +class VM_TestSafeFetchAtSafePoint : public VM_GTestExecuteAtSafepoint { |
| 53 | +public: |
| 54 | + void doit() { |
| 55 | + // Regression test for JDK-8257828 |
| 56 | + // Should not crash. |
| 57 | + intptr_t a = SafeFetchN(invalid_address, pattern); |
| 58 | + ASSERT_EQ(pattern, a); |
| 59 | + a = SafeFetchN(invalid_address, ~pattern); |
| 60 | + ASSERT_EQ(~pattern, a); |
| 61 | + } |
| 62 | +}; |
| 63 | + |
| 64 | +TEST_VM(os, safefetch_negative_at_safepoint) { |
| 65 | + VM_TestSafeFetchAtSafePoint op; |
| 66 | + ThreadInVMfromNative invm(JavaThread::current()); |
| 67 | + VMThread::execute(&op); |
| 68 | +} |
0 commit comments