< prev index next >

test/jdk/java/foreign/stackwalk/TestStackWalk.java

Print this page

  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 id=default_gc
 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  *   TestStackWalk
 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  *   TestStackWalk
 48  */
 49 
 50 /*
 51  * @test id=zgc
 52  * @requires (((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64")
 53  * @requires vm.gc.Z
 54  * @library /test/lib

 55  * @build sun.hotspot.WhiteBox
 56  * @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
 57  *
 58  * @run main/othervm
 59  *   -Xbootclasspath/a:.
 60  *   -XX:+UnlockDiagnosticVMOptions
 61  *   -XX:+WhiteBoxAPI
 62  *   -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true
 63  *   --enable-native-access=ALL-UNNAMED
 64  *   -Xbatch
 65  *   -XX:+UseZGC
 66  *   TestStackWalk
 67  *
 68  * @run main/othervm
 69  *   -Xbootclasspath/a:.
 70  *   -XX:+UnlockDiagnosticVMOptions
 71  *   -XX:+WhiteBoxAPI
 72  *   -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false
 73  *   --enable-native-access=ALL-UNNAMED
 74  *   -Xbatch
 75  *   -XX:+UseZGC
 76  *   TestStackWalk
 77  */
 78 /*
 79  * @test id=shenandoah
 80  * @requires (((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64")
 81  * @requires vm.gc.Shenandoah
 82  * @library /test/lib

 83  * @build sun.hotspot.WhiteBox
 84  * @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
 85  *
 86  * @run main/othervm
 87  *   -Xbootclasspath/a:.
 88  *   -XX:+UnlockDiagnosticVMOptions
 89  *   -XX:+WhiteBoxAPI
 90  *   -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true
 91  *   --enable-native-access=ALL-UNNAMED
 92  *   -Xbatch
 93  *   -XX:+UseShenandoahGC
 94  *   TestStackWalk
 95  *
 96  * @run main/othervm
 97  *   -Xbootclasspath/a:.
 98  *   -XX:+UnlockDiagnosticVMOptions
 99  *   -XX:+WhiteBoxAPI
100  *   -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false
101  *   --enable-native-access=ALL-UNNAMED
102  *   -Xbatch
103  *   -XX:+UseShenandoahGC
104  *   TestStackWalk
105  */
106 
107 import jdk.incubator.foreign.CLinker;
108 import jdk.incubator.foreign.FunctionDescriptor;

109 import jdk.incubator.foreign.SymbolLookup;
110 import jdk.incubator.foreign.MemoryAddress;
111 
112 import java.lang.invoke.MethodHandle;
113 import java.lang.invoke.MethodType;
114 import java.lang.ref.Reference;
115 
116 import jdk.incubator.foreign.ResourceScope;
117 import sun.hotspot.WhiteBox;
118 
119 import static java.lang.invoke.MethodHandles.lookup;
120 import static jdk.incubator.foreign.CLinker.C_POINTER;
121 
122 public class TestStackWalk {
123     static final WhiteBox WB = WhiteBox.getWhiteBox();
124 
125     static final CLinker linker = CLinker.getInstance();
126 
127     static final MethodHandle MH_foo;
128     static final MethodHandle MH_m;
129 
130     static {
131         try {
132             System.loadLibrary("StackWalk");
133             SymbolLookup lookup = SymbolLookup.loaderLookup();
134             MH_foo = linker.downcallHandle(
135                     lookup.lookup("foo").get(),
136                     MethodType.methodType(void.class, MemoryAddress.class),
137                     FunctionDescriptor.ofVoid(C_POINTER));
138             MH_m = lookup().findStatic(TestStackWalk.class, "m", MethodType.methodType(void.class));
139         } catch (ReflectiveOperationException e) {
140             throw new RuntimeException(e);
141         }
142     }
143 
144     static boolean armed;
145 
146     public static void main(String[] args) throws Throwable {
147         try (ResourceScope scope = ResourceScope.newConfinedScope()) {
148             MemoryAddress stub = linker.upcallStub(MH_m, FunctionDescriptor.ofVoid(), scope);
149             MemoryAddress stubAddress = stub.address();
150             armed = false;
151             for (int i = 0; i < 20_000; i++) {
152                 payload(stubAddress); // warmup
153             }
154 
155             armed = true;
156             payload(stubAddress); // test
157         }
158     }
159 
160     static void payload(MemoryAddress cb) throws Throwable {
161         MH_foo.invokeExact(cb);
162         Reference.reachabilityFence(cb); // keep oop alive across call
163     }
164 
165     static void m() {
166         if (armed) {
167             WB.verifyFrames(/*log=*/true, /*updateRegisterMap=*/true);
168             WB.verifyFrames(/*log=*/true, /*updateRegisterMap=*/false); // triggers different code paths
169         }
170     }
171 
172 }

  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 id=default_gc
 26  * @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"
 27  * @library /test/lib
 28  * @library ../
 29  * @build sun.hotspot.WhiteBox
 30  * @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
 31  *
 32  * @run main/othervm
 33  *   -Xbootclasspath/a:.
 34  *   -XX:+UnlockDiagnosticVMOptions
 35  *   -XX:+WhiteBoxAPI
 36  *   -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true
 37  *   --enable-native-access=ALL-UNNAMED
 38  *   -Xbatch
 39  *   TestStackWalk
 40  *
 41  * @run main/othervm
 42  *   -Xbootclasspath/a:.
 43  *   -XX:+UnlockDiagnosticVMOptions
 44  *   -XX:+WhiteBoxAPI
 45  *   -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false
 46  *   --enable-native-access=ALL-UNNAMED
 47  *   -Xbatch
 48  *   TestStackWalk
 49  */
 50 
 51 /*
 52  * @test id=zgc
 53  * @requires (((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64")
 54  * @requires vm.gc.Z
 55  * @library /test/lib
 56  * @library ../
 57  * @build sun.hotspot.WhiteBox
 58  * @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
 59  *
 60  * @run main/othervm
 61  *   -Xbootclasspath/a:.
 62  *   -XX:+UnlockDiagnosticVMOptions
 63  *   -XX:+WhiteBoxAPI
 64  *   -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true
 65  *   --enable-native-access=ALL-UNNAMED
 66  *   -Xbatch
 67  *   -XX:+UseZGC
 68  *   TestStackWalk
 69  *
 70  * @run main/othervm
 71  *   -Xbootclasspath/a:.
 72  *   -XX:+UnlockDiagnosticVMOptions
 73  *   -XX:+WhiteBoxAPI
 74  *   -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false
 75  *   --enable-native-access=ALL-UNNAMED
 76  *   -Xbatch
 77  *   -XX:+UseZGC
 78  *   TestStackWalk
 79  */
 80 /*
 81  * @test id=shenandoah
 82  * @requires (((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64")
 83  * @requires vm.gc.Shenandoah
 84  * @library /test/lib
 85  * @library ../
 86  * @build sun.hotspot.WhiteBox
 87  * @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
 88  *
 89  * @run main/othervm
 90  *   -Xbootclasspath/a:.
 91  *   -XX:+UnlockDiagnosticVMOptions
 92  *   -XX:+WhiteBoxAPI
 93  *   -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=true
 94  *   --enable-native-access=ALL-UNNAMED
 95  *   -Xbatch
 96  *   -XX:+UseShenandoahGC
 97  *   TestStackWalk
 98  *
 99  * @run main/othervm
100  *   -Xbootclasspath/a:.
101  *   -XX:+UnlockDiagnosticVMOptions
102  *   -XX:+WhiteBoxAPI
103  *   -Djdk.internal.foreign.ProgrammableInvoker.USE_INTRINSICS=false
104  *   --enable-native-access=ALL-UNNAMED
105  *   -Xbatch
106  *   -XX:+UseShenandoahGC
107  *   TestStackWalk
108  */
109 
110 import jdk.incubator.foreign.CLinker;
111 import jdk.incubator.foreign.FunctionDescriptor;
112 import jdk.incubator.foreign.NativeSymbol;
113 import jdk.incubator.foreign.SymbolLookup;
114 import jdk.incubator.foreign.MemoryAddress;
115 
116 import java.lang.invoke.MethodHandle;
117 import java.lang.invoke.MethodType;
118 import java.lang.ref.Reference;
119 
120 import jdk.incubator.foreign.ResourceScope;
121 import sun.hotspot.WhiteBox;
122 
123 import static java.lang.invoke.MethodHandles.lookup;

124 
125 public class TestStackWalk extends NativeTestHelper {
126     static final WhiteBox WB = WhiteBox.getWhiteBox();
127 
128     static final CLinker linker = CLinker.systemCLinker();
129 
130     static final MethodHandle MH_foo;
131     static final MethodHandle MH_m;
132 
133     static {
134         try {
135             System.loadLibrary("StackWalk");
136             SymbolLookup lookup = SymbolLookup.loaderLookup();
137             MH_foo = linker.downcallHandle(
138                     lookup.lookup("foo").get(),

139                     FunctionDescriptor.ofVoid(C_POINTER));
140             MH_m = lookup().findStatic(TestStackWalk.class, "m", MethodType.methodType(void.class));
141         } catch (ReflectiveOperationException e) {
142             throw new RuntimeException(e);
143         }
144     }
145 
146     static boolean armed;
147 
148     public static void main(String[] args) throws Throwable {
149         try (ResourceScope scope = ResourceScope.newConfinedScope()) {
150             NativeSymbol stub = linker.upcallStub(MH_m, FunctionDescriptor.ofVoid(), scope);
151             MemoryAddress stubAddress = stub.address();
152             armed = false;
153             for (int i = 0; i < 20_000; i++) {
154                 payload(stubAddress); // warmup
155             }
156 
157             armed = true;
158             payload(stubAddress); // test
159         }
160     }
161 
162     static void payload(MemoryAddress cb) throws Throwable {
163         MH_foo.invoke(cb);
164         Reference.reachabilityFence(cb); // keep oop alive across call
165     }
166 
167     static void m() {
168         if (armed) {
169             WB.verifyFrames(/*log=*/true, /*updateRegisterMap=*/true);
170             WB.verifyFrames(/*log=*/true, /*updateRegisterMap=*/false); // triggers different code paths
171         }
172     }
173 
174 }
< prev index next >