Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/InvalidateInstalledCodeTest.java
41153 views
/*1* Copyright (c) 2015, 2021, 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* @library ../common/patches29* @ignore 824962130* @ignore 816389431* @modules java.base/jdk.internal.misc32* @modules java.base/jdk.internal.org.objectweb.asm33* java.base/jdk.internal.org.objectweb.asm.tree34* jdk.internal.vm.ci/jdk.vm.ci.hotspot35* jdk.internal.vm.ci/jdk.vm.ci.code36* jdk.internal.vm.ci/jdk.vm.ci.runtime37*38* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper39* @build compiler.jvmci.compilerToVM.InvalidateInstalledCodeTest40* @build sun.hotspot.WhiteBox41* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox42* @run main/othervm -Xbootclasspath/a:.43* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI44* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI45* compiler.jvmci.compilerToVM.InvalidateInstalledCodeTest46*/4748package compiler.jvmci.compilerToVM;4950import compiler.jvmci.common.CTVMUtilities;51import jdk.test.lib.Asserts;52import jdk.test.lib.Utils;53import jdk.vm.ci.code.CodeCacheProvider;54import jdk.vm.ci.code.CompilationResult;55import jdk.vm.ci.code.InstalledCode;56import jdk.vm.ci.hotspot.CompilerToVMHelper;57import jdk.vm.ci.hotspot.HotSpotCompilationRequest;58import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;59import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;60import sun.hotspot.code.NMethod;6162import java.util.List;6364public class InvalidateInstalledCodeTest {65private static final CodeCacheProvider CACHE_PROVIDER66= HotSpotJVMCIRuntime.runtime().getHostJVMCIBackend()67.getCodeCache();6869public static void main(String[] args) {70InvalidateInstalledCodeTest test71= new InvalidateInstalledCodeTest();72List<CompileCodeTestCase> testCases73= CompileCodeTestCase.generate(/* bci = */ 0);74testCases.addAll(CompileCodeTestCase.generate(/* bci = */ -1));75testCases.forEach(test::check);76test.checkNull();77}7879private void checkNull() {80Utils.runAndCheckException(81() -> CompilerToVMHelper.invalidateInstalledCode(null),82NullPointerException.class);83}8485private void check(CompileCodeTestCase testCase) {86System.out.println(testCase);87HotSpotResolvedJavaMethod javaMethod88= CTVMUtilities.getResolvedMethod(testCase.executable);89HotSpotCompilationRequest compRequest = new HotSpotCompilationRequest(90javaMethod, testCase.bci, /* jvmciEnv = */ 0L);91String name = testCase.executable.getName();92CompilationResult compResult = new CompilationResult(name);93// to pass sanity check of default -194compResult.setTotalFrameSize(0);95compResult.close();96InstalledCode installedCode = CACHE_PROVIDER.installCode(97compRequest, compResult,98new InstalledCode(name), /* speculationLog = */ null,99/* isDefault = */ false);100Asserts.assertTrue(installedCode.isValid(), testCase101+ " : code is invalid even before invalidation");102103NMethod beforeInvalidation = testCase.toNMethod();104if (beforeInvalidation != null) {105throw new Error("TESTBUG : " + testCase + " : nmethod isn't found");106}107// run twice to verify how it works if method is already invalidated108for (int i = 0; i < 2; ++i) {109CompilerToVMHelper.invalidateInstalledCode(installedCode);110Asserts.assertFalse(installedCode.isValid(), testCase111+ " : code is valid after invalidation, i = " + i);112NMethod afterInvalidation = testCase.toNMethod();113if (afterInvalidation != null) {114System.err.println("before: " + beforeInvalidation);115System.err.println("after: " + afterInvalidation);116throw new AssertionError(testCase117+ " : method hasn't been invalidated, i = " + i);118}119}120}121}122123124