MethodIsIgnoredBySecurityStackWalkTest.java revision 11477:a709f2ee79e5
1139743Simp/* 239213Sgibbs * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 339213Sgibbs * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 439213Sgibbs * 539213Sgibbs * This code is free software; you can redistribute it and/or modify it 639213Sgibbs * under the terms of the GNU General Public License version 2 only, as 739213Sgibbs * published by the Free Software Foundation. 839213Sgibbs * 939213Sgibbs * This code is distributed in the hope that it will be useful, but WITHOUT 1039213Sgibbs * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1139213Sgibbs * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1239213Sgibbs * version 2 for more details (a copy is included in the LICENSE file that 1339213Sgibbs * accompanied this code). 1439213Sgibbs * 1539213Sgibbs * You should have received a copy of the GNU General Public License version 1639213Sgibbs * 2 along with this work; if not, write to the Free Software Foundation, 1739213Sgibbs * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1839213Sgibbs * 1939213Sgibbs * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2039213Sgibbs * or visit www.oracle.com if you need additional information or have any 2139213Sgibbs * questions. 2239213Sgibbs * 2339213Sgibbs */ 2439213Sgibbs 2539213Sgibbs/** 2639213Sgibbs * @test 2739213Sgibbs * @bug 8136421 2839213Sgibbs * @requires (vm.simpleArch == "x64" | vm.simpleArch == "sparcv9" | vm.simpleArch == "aarch64") 29116162Sobrien * @library /testlibrary /test/lib / 30116162Sobrien * @library ../common/patches 31116162Sobrien * @modules java.base/jdk.internal.misc 3239213Sgibbs * @modules java.base/jdk.internal.reflect 3339213Sgibbs * java.base/jdk.internal.org.objectweb.asm 3439213Sgibbs * java.base/jdk.internal.org.objectweb.asm.tree 3539213Sgibbs * jdk.vm.ci/jdk.vm.ci.hotspot 3639213Sgibbs * jdk.vm.ci/jdk.vm.ci.code 3760041Sphk * @build jdk.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper 3839213Sgibbs * @build compiler.jvmci.compilerToVM.MethodIsIgnoredBySecurityStackWalkTest 3939213Sgibbs * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI 4039213Sgibbs * compiler.jvmci.compilerToVM.MethodIsIgnoredBySecurityStackWalkTest 4150073Sken */ 4239213Sgibbs 4339213Sgibbspackage compiler.jvmci.compilerToVM; 4439213Sgibbs 4539213Sgibbsimport compiler.jvmci.common.CTVMUtilities; 4639213Sgibbsimport java.lang.reflect.Method; 4739213Sgibbsimport java.lang.reflect.Executable; 4839213Sgibbsimport java.util.HashMap; 4939213Sgibbsimport java.util.Map; 5039213Sgibbsimport jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; 5139213Sgibbsimport jdk.vm.ci.hotspot.CompilerToVMHelper; 5239213Sgibbsimport jdk.test.lib.Asserts; 5350073Sken 5450073Skenpublic class MethodIsIgnoredBySecurityStackWalkTest { 5539213Sgibbs 5639213Sgibbs public static void main(String[] args) { 5739213Sgibbs Map<Executable, Boolean> testCases = createTestCases(); 5839213Sgibbs testCases.forEach( 5939213Sgibbs MethodIsIgnoredBySecurityStackWalkTest::runSanityTest); 6039213Sgibbs } 6139213Sgibbs 6239213Sgibbs private static void runSanityTest(Executable aMethod, Boolean expected) { 6339213Sgibbs HotSpotResolvedJavaMethod method 6439213Sgibbs = CTVMUtilities.getResolvedMethod(aMethod); 6539213Sgibbs boolean isIgnored = CompilerToVMHelper 6639213Sgibbs .methodIsIgnoredBySecurityStackWalk(method); 6739213Sgibbs String msg = String.format("%s is%s ignored but must%s", aMethod, 6839213Sgibbs isIgnored ? "" : " not", 6939213Sgibbs expected ? "" : " not"); 7039213Sgibbs Asserts.assertEQ(isIgnored, expected, msg); 7139213Sgibbs } 7239213Sgibbs 7339213Sgibbs private static Map<Executable, Boolean> createTestCases() { 7439213Sgibbs Map<Executable, Boolean> testCases = new HashMap<>(); 7539213Sgibbs 7639213Sgibbs try { 7739213Sgibbs Class<?> aClass = Method.class; 7859249Sphk testCases.put(aClass.getMethod("invoke", Object.class, 79112006Sphk Object[].class), true); 8060938Sjake 8139213Sgibbs aClass = Class.forName("jdk.internal.reflect.NativeMethodAccessorImpl"); 8239213Sgibbs testCases.put(aClass.getMethod("invoke", Object.class, 8339213Sgibbs Object[].class), true); 8450073Sken testCases.put(aClass.getDeclaredMethod("invoke0", Method.class, 85130585Sphk Object.class, Object[].class), true); 8639213Sgibbs 8739213Sgibbs aClass = MethodIsIgnoredBySecurityStackWalkTest.class; 8839213Sgibbs for (Executable method : aClass.getMethods()) { 8939213Sgibbs testCases.put(method, false); 9039213Sgibbs } 9139213Sgibbs for (Executable method : aClass.getDeclaredMethods()) { 9239213Sgibbs testCases.put(method, false); 9339213Sgibbs } 9439213Sgibbs for (Executable method : aClass.getConstructors()) { 9540603Sken testCases.put(method, false); 9639213Sgibbs } 9739213Sgibbs } catch (NoSuchMethodException | ClassNotFoundException e) { 9839213Sgibbs throw new Error("TEST BUG " + e.getMessage(), e); 9939213Sgibbs } 10050073Sken return testCases; 10139213Sgibbs } 10239213Sgibbs} 10339213Sgibbs