2015-10-08 12:49:30 -10:00
|
|
|
/*
|
2019-05-01 12:31:29 -07:00
|
|
|
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
2015-10-08 12:49:30 -10:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @test
|
|
|
|
* @bug 8136421
|
2019-06-06 15:12:37 -07:00
|
|
|
* @requires vm.jvmci & !vm.graal.enabled
|
2016-08-19 10:06:30 -04:00
|
|
|
* @library / /test/lib
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
* @library ../common/patches
|
2016-05-01 12:47:00 +03:00
|
|
|
* @modules java.base/jdk.internal.misc
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
* @modules java.base/jdk.internal.org.objectweb.asm
|
|
|
|
* java.base/jdk.internal.org.objectweb.asm.tree
|
2017-02-16 15:46:09 -08:00
|
|
|
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
|
|
|
|
* jdk.internal.vm.ci/jdk.vm.ci.code
|
|
|
|
* jdk.internal.vm.ci/jdk.vm.ci.code.site
|
|
|
|
* jdk.internal.vm.ci/jdk.vm.ci.meta
|
|
|
|
* jdk.internal.vm.ci/jdk.vm.ci.runtime
|
|
|
|
* jdk.internal.vm.ci/jdk.vm.ci.services
|
2016-07-08 21:26:02 +03:00
|
|
|
*
|
2017-02-16 15:46:09 -08:00
|
|
|
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
|
2015-10-08 12:49:30 -10:00
|
|
|
* @build compiler.jvmci.common.JVMCIHelpers
|
2016-07-08 21:26:02 +03:00
|
|
|
* @run driver jdk.test.lib.FileInstaller ./JvmciNotifyInstallEventTest.config
|
2016-10-11 00:08:20 +02:00
|
|
|
* ./META-INF/services/jdk.vm.ci.services.JVMCIServiceLocator
|
2016-07-08 21:26:02 +03:00
|
|
|
* @run driver ClassFileInstaller
|
|
|
|
* compiler.jvmci.common.JVMCIHelpers$EmptyHotspotCompiler
|
|
|
|
* compiler.jvmci.common.JVMCIHelpers$EmptyCompilerFactory
|
|
|
|
* compiler.jvmci.common.JVMCIHelpers$EmptyCompilationRequestResult
|
2016-08-19 10:06:30 -04:00
|
|
|
* compiler.jvmci.common.JVMCIHelpers$EmptyVMEventListener
|
2016-07-20 22:18:13 +00:00
|
|
|
* @run main/othervm -XX:+UnlockExperimentalVMOptions
|
2017-04-28 02:54:05 -07:00
|
|
|
* -Djvmci.Compiler=EmptyCompiler -Xbootclasspath/a:. -Xmixed
|
2015-10-08 12:49:30 -10:00
|
|
|
* -XX:+UseJVMCICompiler -XX:-BootstrapJVMCI
|
2016-04-01 16:56:49 +03:00
|
|
|
* compiler.jvmci.events.JvmciNotifyInstallEventTest
|
2016-07-20 22:18:13 +00:00
|
|
|
* @run main/othervm -XX:+UnlockExperimentalVMOptions
|
2017-04-28 02:54:05 -07:00
|
|
|
* -Djvmci.Compiler=EmptyCompiler -Xbootclasspath/a:. -Xmixed
|
2016-04-01 16:56:49 +03:00
|
|
|
* -XX:+UseJVMCICompiler -XX:-BootstrapJVMCI -XX:JVMCINMethodSizeLimit=0
|
2015-10-08 12:49:30 -10:00
|
|
|
* compiler.jvmci.events.JvmciNotifyInstallEventTest
|
|
|
|
*/
|
|
|
|
|
|
|
|
package compiler.jvmci.events;
|
|
|
|
|
|
|
|
import compiler.jvmci.common.CTVMUtilities;
|
|
|
|
import compiler.jvmci.common.testcases.SimpleClass;
|
|
|
|
import jdk.test.lib.Asserts;
|
2016-04-01 16:56:49 +03:00
|
|
|
import jdk.test.lib.Utils;
|
2016-10-11 00:08:20 +02:00
|
|
|
import jdk.vm.ci.services.JVMCIServiceLocator;
|
2016-01-20 14:22:46 +01:00
|
|
|
import jdk.vm.ci.code.CompiledCode;
|
2015-10-08 12:49:30 -10:00
|
|
|
import jdk.vm.ci.code.InstalledCode;
|
2016-01-20 14:22:46 +01:00
|
|
|
import jdk.vm.ci.code.site.DataPatch;
|
|
|
|
import jdk.vm.ci.code.site.Site;
|
2015-10-08 12:49:30 -10:00
|
|
|
import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
|
2016-01-20 14:22:46 +01:00
|
|
|
import jdk.vm.ci.hotspot.HotSpotCompiledCode;
|
|
|
|
import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;
|
2019-05-01 12:31:29 -07:00
|
|
|
import jdk.vm.ci.hotspot.HotSpotCompiledNmethod;
|
2015-10-08 12:49:30 -10:00
|
|
|
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
|
2015-11-04 07:23:23 -10:00
|
|
|
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
|
2016-10-11 00:08:20 +02:00
|
|
|
import jdk.vm.ci.hotspot.HotSpotVMEventListener;
|
2016-07-12 18:24:48 +03:00
|
|
|
import jdk.vm.ci.meta.Assumptions.Assumption;
|
|
|
|
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
2015-10-08 12:49:30 -10:00
|
|
|
|
2016-10-11 00:08:20 +02:00
|
|
|
public class JvmciNotifyInstallEventTest extends JVMCIServiceLocator implements HotSpotVMEventListener {
|
2015-10-08 12:49:30 -10:00
|
|
|
private static final String METHOD_NAME = "testMethod";
|
|
|
|
private static volatile int gotInstallNotification = 0;
|
|
|
|
|
|
|
|
public static void main(String args[]) {
|
|
|
|
new JvmciNotifyInstallEventTest().runTest();
|
|
|
|
}
|
|
|
|
|
2016-10-11 00:08:20 +02:00
|
|
|
@Override
|
|
|
|
public <S> S getProvider(Class<S> service) {
|
|
|
|
if (service == HotSpotVMEventListener.class) {
|
|
|
|
return service.cast(this);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-10-08 12:49:30 -10:00
|
|
|
private void runTest() {
|
|
|
|
if (gotInstallNotification != 0) {
|
|
|
|
throw new Error("Got install notification before test actions");
|
|
|
|
}
|
2016-04-01 16:56:49 +03:00
|
|
|
HotSpotCodeCacheProvider codeCache;
|
2015-10-08 12:49:30 -10:00
|
|
|
try {
|
|
|
|
codeCache = (HotSpotCodeCacheProvider) HotSpotJVMCIRuntime.runtime()
|
|
|
|
.getHostJVMCIBackend().getCodeCache();
|
|
|
|
} catch (InternalError ie) {
|
|
|
|
// passed
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Method testMethod;
|
|
|
|
try {
|
|
|
|
testMethod = SimpleClass.class.getDeclaredMethod(METHOD_NAME);
|
|
|
|
} catch (NoSuchMethodException e) {
|
|
|
|
throw new Error("TEST BUG: Can't find " + METHOD_NAME, e);
|
|
|
|
}
|
2015-11-04 07:23:23 -10:00
|
|
|
HotSpotResolvedJavaMethod method = CTVMUtilities
|
2015-10-08 12:49:30 -10:00
|
|
|
.getResolvedMethod(SimpleClass.class, testMethod);
|
2019-05-01 12:31:29 -07:00
|
|
|
HotSpotCompiledCode compiledCode = new HotSpotCompiledNmethod(METHOD_NAME,
|
2016-04-01 16:56:49 +03:00
|
|
|
new byte[0], 0, new Site[0], new Assumption[0],
|
|
|
|
new ResolvedJavaMethod[]{method}, new Comment[0], new byte[0],
|
2019-05-01 12:31:29 -07:00
|
|
|
16, new DataPatch[0], false, 0, null,
|
|
|
|
method, 0, 1, 0L, false);
|
2016-04-01 16:56:49 +03:00
|
|
|
codeCache.installCode(method, compiledCode, /* installedCode = */ null,
|
|
|
|
/* speculationLog = */ null, /* isDefault = */ false);
|
2015-10-08 12:49:30 -10:00
|
|
|
Asserts.assertEQ(gotInstallNotification, 1,
|
|
|
|
"Got unexpected event count after 1st install attempt");
|
|
|
|
// since "empty" compilation result is ok, a second attempt should be ok
|
2016-04-01 16:56:49 +03:00
|
|
|
codeCache.installCode(method, compiledCode, /* installedCode = */ null,
|
|
|
|
/* speculationLog = */ null, /* isDefault = */ false);
|
2015-10-08 12:49:30 -10:00
|
|
|
Asserts.assertEQ(gotInstallNotification, 2,
|
|
|
|
"Got unexpected event count after 2nd install attempt");
|
2016-04-01 16:56:49 +03:00
|
|
|
// and an incorrect cases
|
|
|
|
Utils.runAndCheckException(() -> {
|
|
|
|
codeCache.installCode(method, null, null, null, true);
|
|
|
|
}, NullPointerException.class);
|
|
|
|
Asserts.assertEQ(gotInstallNotification, 2,
|
|
|
|
"Got unexpected event count after 3rd install attempt");
|
|
|
|
Utils.runAndCheckException(() -> {
|
|
|
|
codeCache.installCode(null, null, null, null, true);
|
|
|
|
}, NullPointerException.class);
|
|
|
|
Asserts.assertEQ(gotInstallNotification, 2,
|
|
|
|
"Got unexpected event count after 4th install attempt");
|
2015-10-08 12:49:30 -10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyInstall(HotSpotCodeCacheProvider hotSpotCodeCacheProvider,
|
2016-01-20 14:22:46 +01:00
|
|
|
InstalledCode installedCode, CompiledCode compiledCode) {
|
2015-10-08 12:49:30 -10:00
|
|
|
gotInstallNotification++;
|
|
|
|
}
|
|
|
|
}
|