2020-11-23 11:00:38 +00:00
|
|
|
/*
|
2023-08-07 10:58:11 +00:00
|
|
|
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
|
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2020-11-23 11:00:38 +00:00
|
|
|
*
|
2023-08-07 10:58:11 +00:00
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
2020-11-23 11:00:38 +00:00
|
|
|
*
|
2023-08-07 10:58:11 +00:00
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
2020-11-23 11:00:38 +00:00
|
|
|
*
|
2023-08-07 10:58:11 +00:00
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
2020-11-23 11:00:38 +00:00
|
|
|
*
|
2023-08-07 10:58:11 +00:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2020-11-23 11:00:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2021-07-20 13:10:42 +00:00
|
|
|
* @test id=default_gc
|
2023-06-20 10:08:13 +00:00
|
|
|
* @requires vm.gc != "Z"
|
2020-11-23 11:00:38 +00:00
|
|
|
* @library /test/lib
|
2021-11-24 11:51:16 +00:00
|
|
|
* @library ../
|
2022-07-08 15:55:14 +00:00
|
|
|
* @build jdk.test.whitebox.WhiteBox
|
|
|
|
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
|
2020-11-23 11:00:38 +00:00
|
|
|
*
|
|
|
|
* @run main/othervm
|
|
|
|
* -Xbootclasspath/a:.
|
|
|
|
* -XX:+UnlockDiagnosticVMOptions
|
|
|
|
* -XX:+WhiteBoxAPI
|
2021-06-02 10:53:06 +00:00
|
|
|
* --enable-native-access=ALL-UNNAMED
|
2020-11-23 11:00:38 +00:00
|
|
|
* -Xbatch
|
|
|
|
* TestStackWalk
|
|
|
|
*/
|
|
|
|
|
2021-07-20 13:10:42 +00:00
|
|
|
/*
|
2024-10-30 11:05:07 +00:00
|
|
|
* @test id=Z
|
|
|
|
* @requires vm.gc.Z
|
2021-07-20 13:10:42 +00:00
|
|
|
* @library /test/lib
|
2021-11-24 11:51:16 +00:00
|
|
|
* @library ../
|
2022-07-08 15:55:14 +00:00
|
|
|
* @build jdk.test.whitebox.WhiteBox
|
|
|
|
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
|
2021-07-20 13:10:42 +00:00
|
|
|
*
|
|
|
|
* @run main/othervm
|
|
|
|
* -Xbootclasspath/a:.
|
|
|
|
* -XX:+UnlockDiagnosticVMOptions
|
|
|
|
* -XX:+WhiteBoxAPI
|
|
|
|
* --enable-native-access=ALL-UNNAMED
|
|
|
|
* -Xbatch
|
2024-10-30 11:05:07 +00:00
|
|
|
* -XX:+UseZGC
|
2023-06-20 10:08:13 +00:00
|
|
|
* TestStackWalk
|
|
|
|
*/
|
|
|
|
|
2021-07-20 13:10:42 +00:00
|
|
|
/*
|
|
|
|
* @test id=shenandoah
|
|
|
|
* @requires vm.gc.Shenandoah
|
|
|
|
* @library /test/lib
|
2021-11-24 11:51:16 +00:00
|
|
|
* @library ../
|
2022-07-08 15:55:14 +00:00
|
|
|
* @build jdk.test.whitebox.WhiteBox
|
|
|
|
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
|
2021-07-20 13:10:42 +00:00
|
|
|
*
|
|
|
|
* @run main/othervm
|
|
|
|
* -Xbootclasspath/a:.
|
|
|
|
* -XX:+UnlockDiagnosticVMOptions
|
|
|
|
* -XX:+WhiteBoxAPI
|
|
|
|
* --enable-native-access=ALL-UNNAMED
|
|
|
|
* -Xbatch
|
|
|
|
* -XX:+UseShenandoahGC
|
|
|
|
* TestStackWalk
|
|
|
|
*/
|
|
|
|
|
2022-12-05 13:49:53 +00:00
|
|
|
import java.lang.foreign.Arena;
|
2022-05-12 16:17:45 +00:00
|
|
|
import java.lang.foreign.Linker;
|
|
|
|
import java.lang.foreign.FunctionDescriptor;
|
2022-12-05 13:49:53 +00:00
|
|
|
import java.lang.foreign.MemorySegment;
|
2020-11-23 11:00:38 +00:00
|
|
|
|
|
|
|
import java.lang.invoke.MethodHandle;
|
|
|
|
import java.lang.invoke.MethodType;
|
|
|
|
import java.lang.ref.Reference;
|
|
|
|
|
2022-07-08 15:55:14 +00:00
|
|
|
import jdk.test.whitebox.WhiteBox;
|
2020-11-23 11:00:38 +00:00
|
|
|
|
|
|
|
import static java.lang.invoke.MethodHandles.lookup;
|
|
|
|
|
2021-11-24 11:51:16 +00:00
|
|
|
public class TestStackWalk extends NativeTestHelper {
|
2020-11-23 11:00:38 +00:00
|
|
|
static final WhiteBox WB = WhiteBox.getWhiteBox();
|
|
|
|
|
2022-05-12 16:17:45 +00:00
|
|
|
static final Linker linker = Linker.nativeLinker();
|
2020-11-23 11:00:38 +00:00
|
|
|
|
|
|
|
static final MethodHandle MH_foo;
|
|
|
|
static final MethodHandle MH_m;
|
|
|
|
|
|
|
|
static {
|
|
|
|
try {
|
2021-06-04 12:53:17 +00:00
|
|
|
System.loadLibrary("StackWalk");
|
2020-11-23 11:00:38 +00:00
|
|
|
MH_foo = linker.downcallHandle(
|
2022-05-12 16:17:45 +00:00
|
|
|
findNativeOrThrow("foo"),
|
2020-11-23 11:00:38 +00:00
|
|
|
FunctionDescriptor.ofVoid(C_POINTER));
|
|
|
|
MH_m = lookup().findStatic(TestStackWalk.class, "m", MethodType.methodType(void.class));
|
|
|
|
} catch (ReflectiveOperationException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static boolean armed;
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Throwable {
|
2023-04-27 09:00:58 +00:00
|
|
|
try (Arena arena = Arena.ofConfined()) {
|
|
|
|
MemorySegment stub = linker.upcallStub(MH_m, FunctionDescriptor.ofVoid(), arena);
|
2020-11-23 11:00:38 +00:00
|
|
|
armed = false;
|
|
|
|
for (int i = 0; i < 20_000; i++) {
|
2022-12-05 13:49:53 +00:00
|
|
|
payload(stub); // warmup
|
2020-11-23 11:00:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
armed = true;
|
2022-12-05 13:49:53 +00:00
|
|
|
payload(stub); // test
|
2020-11-23 11:00:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 13:49:53 +00:00
|
|
|
static void payload(MemorySegment cb) throws Throwable {
|
2021-11-24 11:51:16 +00:00
|
|
|
MH_foo.invoke(cb);
|
2020-11-23 11:00:38 +00:00
|
|
|
Reference.reachabilityFence(cb); // keep oop alive across call
|
|
|
|
}
|
|
|
|
|
|
|
|
static void m() {
|
|
|
|
if (armed) {
|
2021-06-02 10:53:06 +00:00
|
|
|
WB.verifyFrames(/*log=*/true, /*updateRegisterMap=*/true);
|
|
|
|
WB.verifyFrames(/*log=*/true, /*updateRegisterMap=*/false); // triggers different code paths
|
2020-11-23 11:00:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|