1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8136421 27 * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64") 28 * @library / /testlibrary 29 * @library ../common/patches 30 * @modules java.base/jdk.internal.misc 31 * @modules jdk.vm.ci/jdk.vm.ci.hotspot 32 * jdk.vm.ci/jdk.vm.ci.code 33 * jdk.vm.ci/jdk.vm.ci.meta 34 * jdk.vm.ci/jdk.vm.ci.runtime 35 * @build jdk.vm.ci/jdk.vm.ci.hotspot.MetaAccessWrapper 36 * @build compiler.jvmci.common.JVMCIHelpers 37 * compiler.jvmci.events.JvmciCreateMetaAccessContextTest 38 * @run main jdk.test.lib.FileInstaller ../common/services/ ./META-INF/services/ 39 * @run main jdk.test.lib.FileInstaller 40 * ./JvmciCreateMetaAccessContextTest.config 41 * ./META-INF/services/jdk.vm.ci.hotspot.services.HotSpotVMEventListener 42 * @run main ClassFileInstaller 43 * compiler.jvmci.common.JVMCIHelpers$EmptyHotspotCompiler 44 * compiler.jvmci.common.JVMCIHelpers$EmptyCompilerFactory 45 * compiler.jvmci.events.JvmciCreateMetaAccessContextTest 46 * jdk.test.lib.Asserts 47 * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI 48 * -Xbootclasspath/a:. 49 * -Dcompiler.jvmci.events.JvmciCreateMetaAccessContextTest.providenull=true 50 * compiler.jvmci.events.JvmciCreateMetaAccessContextTest 51 * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI 52 * -Xbootclasspath/a:. 53 * -Dcompiler.jvmci.events.JvmciCreateMetaAccessContextTest.providenull=false 54 * compiler.jvmci.events.JvmciCreateMetaAccessContextTest 55 */ 56 57 package compiler.jvmci.events; 58 59 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; 60 import jdk.vm.ci.hotspot.services.HotSpotVMEventListener; 61 import jdk.vm.ci.hotspot.MetaAccessWrapper; 62 import jdk.vm.ci.meta.JVMCIMetaAccessContext; 63 import jdk.test.lib.Asserts; 64 65 public class JvmciCreateMetaAccessContextTest 66 extends HotSpotVMEventListener { 67 private static final boolean PROVIDE_NULL_CONTEXT = Boolean.getBoolean( 68 "compiler.jvmci.events.JvmciCreateMetaAccessContextTest" 69 + ".providenull"); 70 private static volatile int createMetaAccessContextCount = 0; 71 private static volatile String errorMessage = ""; 72 73 public static void main(String args[]) { 74 if (createMetaAccessContextCount != 0) { 75 throw new Error("Unexpected createMetaAccessContextevents count" 76 + " at test start"); 77 } 78 JVMCIMetaAccessContext context; 79 context = HotSpotJVMCIRuntime.runtime().getMetaAccessContext(); 80 Asserts.assertNotNull(context, 81 "JVMCIMetaAccessContext is null after 1st request"); 82 Asserts.assertEQ(createMetaAccessContextCount, 1, 83 "Unexpected createMetaAccessContext events count after 1st" 84 + " JVMCI runtime request"); 85 context = HotSpotJVMCIRuntime.runtime().getMetaAccessContext(); 86 Asserts.assertNotNull(context, 87 "JVMCIMetaAccessContext is null after 2nd request"); 88 Asserts.assertEQ(createMetaAccessContextCount, 1, 89 "Unexpected createMetaAccessContext events count after 2nd" 90 + " JVMCI runtime request"); 91 Asserts.assertTrue(errorMessage.isEmpty(), errorMessage); 92 if (PROVIDE_NULL_CONTEXT) { 93 Asserts.assertFalse(context instanceof MetaAccessWrapper, 94 "Got unexpected context: " + context.getClass()); 95 } else { 96 Asserts.assertTrue(context instanceof MetaAccessWrapper, 97 "Got unexpected context: " + context.getClass()); 98 } 99 } 100 101 @Override 102 public JVMCIMetaAccessContext createMetaAccessContext(HotSpotJVMCIRuntime 103 hotSpotJVMCIRuntime) { 104 createMetaAccessContextCount++; 105 if (hotSpotJVMCIRuntime == null) { 106 errorMessage += " HotSpotJVMCIRuntime is null."; 107 } 108 if (PROVIDE_NULL_CONTEXT) { 109 return null; 110 } 111 return new MetaAccessWrapper(); 112 } 113 }