Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/JVM_RegisterJVMCINatives.java
64507 views
/*1* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 813642126* @requires vm.jvmci27* @library /test/lib /28* @ignore 824962129* @modules java.base/jdk.internal.misc:open30* @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot:open31* jdk.internal.vm.ci/jdk.vm.ci.runtime32* @run main/othervm -XX:+UnlockExperimentalVMOptions33* -Dcompiler.jvmci.compilerToVM.JVM_RegisterJVMCINatives.positive=true34* -XX:+EnableJVMCI35* compiler.jvmci.compilerToVM.JVM_RegisterJVMCINatives36* @run main/othervm -XX:+UnlockExperimentalVMOptions37* -Dcompiler.jvmci.compilerToVM.JVM_RegisterJVMCINatives.positive=false38* -XX:-EnableJVMCI -XX:-UseJVMCICompiler39* compiler.jvmci.compilerToVM.JVM_RegisterJVMCINatives40*/4142package compiler.jvmci.compilerToVM;4344import jdk.test.lib.Asserts;45import jdk.vm.ci.runtime.JVMCI;4647import java.lang.reflect.Method;4849public class JVM_RegisterJVMCINatives {50private static final boolean IS_POSITIVE = Boolean.getBoolean(51"compiler.jvmci.compilerToVM.JVM_RegisterJVMCINatives.positive");5253private final Method registerNatives;5455public static void main(String[] args) {56new JVM_RegisterJVMCINatives().runTest();57}5859private void runTest() {60Object result;61try {62result = invoke();63} catch (InternalError e) {64if (IS_POSITIVE) {65throw new AssertionError("unexpected exception", e);66}67return;68}69if (!IS_POSITIVE) {70throw new AssertionError("didn't get expected exception");71}72Asserts.assertNull(result,73"registerNatives()V returned non-null");74Asserts.assertEQ(result, invoke(),75"registerNatives returns different results");7677}78private Object invoke() {79Object result;80try {81result = registerNatives.invoke(JVMCI.class);82} catch (ReflectiveOperationException e) {83throw new Error("can't invoke registerNatives", e);84}85return result;86}8788private JVM_RegisterJVMCINatives() {89Method method;90try {91method = Class.forName("jdk.vm.ci.hotspot.CompilerToVM",92/* initialize = */ false,93this.getClass().getClassLoader())94.getDeclaredMethod("registerNatives");95method.setAccessible(true);96} catch (ReflectiveOperationException e) {97throw new Error("can't find CompilerToVM::registerNatives", e);98}99registerNatives = method;100}101}102103104