Path: blob/master/test/hotspot/gtest/runtime/test_safefetch.cpp
41144 views
/*1* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2020 SAP SE. 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324#include "precompiled.hpp"25#include "runtime/interfaceSupport.inline.hpp"26#include "runtime/safefetch.inline.hpp"27#include "runtime/vmOperations.hpp"28#include "runtime/vmThread.hpp"29#include "utilities/globalDefinitions.hpp"30#include "utilities/vmError.hpp"31#include "unittest.hpp"3233static const intptr_t pattern = LP64_ONLY(0xABCDABCDABCDABCDULL) NOT_LP64(0xABCDABCD);34static intptr_t* invalid_address = (intptr_t*)VMError::segfault_address;3536TEST_VM(os, safefetch_can_use) {37// Once VM initialization is through,38// safefetch should work on every platform.39ASSERT_TRUE(CanUseSafeFetch32());40}4142TEST_VM(os, safefetch_positive) {43intptr_t v = pattern;44intptr_t a = SafeFetchN(&v, 1);45ASSERT_EQ(v, a);46}4748TEST_VM(os, safefetch_negative) {49intptr_t a = SafeFetchN(invalid_address, pattern);50ASSERT_EQ(pattern, a);51a = SafeFetchN(invalid_address, ~pattern);52ASSERT_EQ(~pattern, a);53}5455class VM_TestSafeFetchAtSafePoint : public VM_GTestExecuteAtSafepoint {56public:57void doit() {58// Regression test for JDK-825782859// Should not crash.60intptr_t a = SafeFetchN(invalid_address, pattern);61ASSERT_EQ(pattern, a);62a = SafeFetchN(invalid_address, ~pattern);63ASSERT_EQ(~pattern, a);64}65};6667TEST_VM(os, safefetch_negative_at_safepoint) {68VM_TestSafeFetchAtSafePoint op;69ThreadInVMfromNative invm(JavaThread::current());70VMThread::execute(&op);71}727374