Path: blob/master/test/hotspot/jtreg/compiler/jvmci/events/JvmciNotifyInstallEventTest.java
41153 views
/*1* Copyright (c) 2015, 2019, 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.jvmci & !vm.graal.enabled & vm.compMode == "Xmixed"27* @library / /test/lib28* @library ../common/patches29* @modules java.base/jdk.internal.misc30* @modules java.base/jdk.internal.org.objectweb.asm31* java.base/jdk.internal.org.objectweb.asm.tree32* jdk.internal.vm.ci/jdk.vm.ci.hotspot33* jdk.internal.vm.ci/jdk.vm.ci.code34* jdk.internal.vm.ci/jdk.vm.ci.code.site35* jdk.internal.vm.ci/jdk.vm.ci.meta36* jdk.internal.vm.ci/jdk.vm.ci.runtime37* jdk.internal.vm.ci/jdk.vm.ci.services38*39* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper40* @build compiler.jvmci.common.JVMCIHelpers41* @run driver jdk.test.lib.FileInstaller ./JvmciNotifyInstallEventTest.config42* ./META-INF/services/jdk.vm.ci.services.JVMCIServiceLocator43* @run driver jdk.test.lib.helpers.ClassFileInstaller44* compiler.jvmci.common.JVMCIHelpers$EmptyHotspotCompiler45* compiler.jvmci.common.JVMCIHelpers$EmptyCompilerFactory46* compiler.jvmci.common.JVMCIHelpers$EmptyCompilationRequestResult47* compiler.jvmci.common.JVMCIHelpers$EmptyVMEventListener48* @run main/othervm -XX:+UnlockExperimentalVMOptions49* -Djvmci.Compiler=EmptyCompiler -Xbootclasspath/a:.50* -XX:+UseJVMCICompiler -XX:-BootstrapJVMCI -XX:-UseJVMCINativeLibrary51* compiler.jvmci.events.JvmciNotifyInstallEventTest52* @run main/othervm -XX:+UnlockExperimentalVMOptions53* -Djvmci.Compiler=EmptyCompiler -Xbootclasspath/a:.54* -XX:+UseJVMCICompiler -XX:-BootstrapJVMCI -XX:JVMCINMethodSizeLimit=055* -XX:-UseJVMCINativeLibrary56* compiler.jvmci.events.JvmciNotifyInstallEventTest57*/5859package compiler.jvmci.events;6061import compiler.jvmci.common.CTVMUtilities;62import compiler.jvmci.common.testcases.SimpleClass;63import jdk.test.lib.Asserts;64import jdk.test.lib.Utils;65import jdk.vm.ci.services.JVMCIServiceLocator;66import jdk.vm.ci.code.CompiledCode;67import jdk.vm.ci.code.InstalledCode;68import jdk.vm.ci.code.site.DataPatch;69import jdk.vm.ci.code.site.Site;70import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;71import jdk.vm.ci.hotspot.HotSpotCompiledCode;72import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;73import jdk.vm.ci.hotspot.HotSpotCompiledNmethod;74import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;75import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;76import jdk.vm.ci.hotspot.HotSpotVMEventListener;77import jdk.vm.ci.meta.Assumptions.Assumption;78import jdk.vm.ci.meta.ResolvedJavaMethod;7980import java.lang.reflect.Method;8182public class JvmciNotifyInstallEventTest extends JVMCIServiceLocator implements HotSpotVMEventListener {83private static final String METHOD_NAME = "testMethod";84private static volatile int gotInstallNotification = 0;8586public static void main(String args[]) {87new JvmciNotifyInstallEventTest().runTest();88}8990@Override91public <S> S getProvider(Class<S> service) {92if (service == HotSpotVMEventListener.class) {93return service.cast(this);94}95return null;96}9798private void runTest() {99if (gotInstallNotification != 0) {100throw new Error("Got install notification before test actions");101}102HotSpotCodeCacheProvider codeCache;103try {104codeCache = (HotSpotCodeCacheProvider) HotSpotJVMCIRuntime.runtime()105.getHostJVMCIBackend().getCodeCache();106} catch (InternalError ie) {107// passed108return;109}110Method testMethod;111try {112testMethod = SimpleClass.class.getDeclaredMethod(METHOD_NAME);113} catch (NoSuchMethodException e) {114throw new Error("TEST BUG: Can't find " + METHOD_NAME, e);115}116HotSpotResolvedJavaMethod method = CTVMUtilities117.getResolvedMethod(SimpleClass.class, testMethod);118HotSpotCompiledCode compiledCode = new HotSpotCompiledNmethod(METHOD_NAME,119new byte[0], 0, new Site[0], new Assumption[0],120new ResolvedJavaMethod[]{method}, new Comment[0], new byte[0],12116, new DataPatch[0], false, 0, null,122method, 0, 1, 0L, false);123codeCache.installCode(method, compiledCode, /* installedCode = */ null,124/* speculationLog = */ null, /* isDefault = */ false);125Asserts.assertEQ(gotInstallNotification, 1,126"Got unexpected event count after 1st install attempt");127// since "empty" compilation result is ok, a second attempt should be ok128codeCache.installCode(method, compiledCode, /* installedCode = */ null,129/* speculationLog = */ null, /* isDefault = */ false);130Asserts.assertEQ(gotInstallNotification, 2,131"Got unexpected event count after 2nd install attempt");132// and an incorrect cases133Utils.runAndCheckException(() -> {134codeCache.installCode(method, null, null, null, true);135}, NullPointerException.class);136Asserts.assertEQ(gotInstallNotification, 2,137"Got unexpected event count after 3rd install attempt");138Utils.runAndCheckException(() -> {139codeCache.installCode(null, null, null, null, true);140}, NullPointerException.class);141Asserts.assertEQ(gotInstallNotification, 2,142"Got unexpected event count after 4th install attempt");143}144145@Override146public void notifyInstall(HotSpotCodeCacheProvider hotSpotCodeCacheProvider,147InstalledCode installedCode, CompiledCode compiledCode) {148gotInstallNotification++;149}150}151152153