|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, 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 | +/* |
| 25 | + * @test |
| 26 | + * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64" |
| 27 | + * @library /test/lib |
| 28 | + * @build sun.hotspot.WhiteBox |
| 29 | + * @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox |
| 30 | + * |
| 31 | + * @run main/othervm |
| 32 | + * -Xbootclasspath/a:. |
| 33 | + * -XX:+UnlockDiagnosticVMOptions |
| 34 | + * -XX:+WhiteBoxAPI |
| 35 | + * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true |
| 36 | + * --enable-native-access=ALL-UNNAMED |
| 37 | + * -Xbatch |
| 38 | + * TestAsyncStackWalk |
| 39 | + * |
| 40 | + * @run main/othervm |
| 41 | + * -Xbootclasspath/a:. |
| 42 | + * -XX:+UnlockDiagnosticVMOptions |
| 43 | + * -XX:+WhiteBoxAPI |
| 44 | + * -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false |
| 45 | + * --enable-native-access=ALL-UNNAMED |
| 46 | + * -Xbatch |
| 47 | + * TestAsyncStackWalk |
| 48 | + */ |
| 49 | + |
| 50 | +import jdk.incubator.foreign.CLinker; |
| 51 | +import jdk.incubator.foreign.FunctionDescriptor; |
| 52 | +import jdk.incubator.foreign.SymbolLookup; |
| 53 | +import jdk.incubator.foreign.MemoryAddress; |
| 54 | + |
| 55 | +import java.lang.invoke.MethodHandle; |
| 56 | +import java.lang.invoke.MethodType; |
| 57 | + |
| 58 | +import jdk.incubator.foreign.ResourceScope; |
| 59 | +import sun.hotspot.WhiteBox; |
| 60 | + |
| 61 | +import static java.lang.invoke.MethodHandles.lookup; |
| 62 | +import static jdk.incubator.foreign.CLinker.C_POINTER; |
| 63 | +import static jdk.test.lib.Asserts.assertTrue; |
| 64 | + |
| 65 | +public class TestAsyncStackWalk { |
| 66 | + static final WhiteBox WB = WhiteBox.getWhiteBox(); |
| 67 | + |
| 68 | + static final CLinker linker = CLinker.getInstance(); |
| 69 | + |
| 70 | + static final MethodHandle MH_asyncStackWalk; |
| 71 | + static final MethodHandle MH_m; |
| 72 | + |
| 73 | + static { |
| 74 | + try { |
| 75 | + System.loadLibrary("AsyncStackWalk"); |
| 76 | + SymbolLookup lookup = SymbolLookup.loaderLookup(); |
| 77 | + MH_asyncStackWalk = linker.downcallHandle( |
| 78 | + lookup.lookup("asyncStackWalk").get(), |
| 79 | + MethodType.methodType(void.class, MemoryAddress.class), |
| 80 | + FunctionDescriptor.ofVoid(C_POINTER)); |
| 81 | + MH_m = lookup().findStatic(TestAsyncStackWalk.class, "m", MethodType.methodType(void.class)); |
| 82 | + } catch (ReflectiveOperationException e) { |
| 83 | + throw new RuntimeException(e); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + static int invocations; |
| 88 | + static boolean didStackWalk; |
| 89 | + |
| 90 | + public static void main(String[] args) throws Throwable { |
| 91 | + try (ResourceScope scope = ResourceScope.newConfinedScope()) { |
| 92 | + MemoryAddress stub = linker.upcallStub(MH_m, FunctionDescriptor.ofVoid(), scope); |
| 93 | + MemoryAddress stubAddress = stub.address(); |
| 94 | + invocations = 0; |
| 95 | + didStackWalk = false; |
| 96 | + payload(stubAddress); |
| 97 | + assertTrue(didStackWalk); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + static void payload(MemoryAddress cb) throws Throwable { |
| 102 | + MH_asyncStackWalk.invokeExact(cb); |
| 103 | + } |
| 104 | + |
| 105 | + static void m() { |
| 106 | + if (invocations++ >= 20000) { // warmup |
| 107 | + didStackWalk = true; |
| 108 | + WB.verifyFrames(/*log=*/true, /*updateRegisterMap=*/true); |
| 109 | + WB.verifyFrames(/*log=*/true, /*updateRegisterMap=*/false); // triggers different code paths |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | +} |
0 commit comments