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 /**
  26  * @test
  27  * @bug 8136421
  28  * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64")
  29  * @library /testlibrary /
  30  * @run main/othervm -XX:+UnlockExperimentalVMOptions
  31  *      -Dcompiler.jvmci.JVM_GetJVMCIRuntimeTest.positive=true
  32  *      -XX:+EnableJVMCI
  33  *      compiler.jvmci.JVM_GetJVMCIRuntimeTest
  34  * @run main/othervm -XX:+UnlockExperimentalVMOptions
  35  *      -Dcompiler.jvmci.JVM_GetJVMCIRuntimeTest.positive=false
  36  *      -XX:-EnableJVMCI
  37  *      compiler.jvmci.JVM_GetJVMCIRuntimeTest
  38  * @run main/othervm -XX:+UnlockExperimentalVMOptions
  39  *      -Dcompiler.jvmci.JVM_GetJVMCIRuntimeTest.positive=true
  40  *      -Dcompiler.jvmci.JVM_GetJVMCIRuntimeTest.threaded=true
  41  *      -XX:+EnableJVMCI
  42  *      compiler.jvmci.JVM_GetJVMCIRuntimeTest
  43  * @run main/othervm -XX:+UnlockExperimentalVMOptions
  44  *      -Dcompiler.jvmci.JVM_GetJVMCIRuntimeTest.positive=false
  45  *      -Dcompiler.jvmci.JVM_GetJVMCIRuntimeTest.threaded=true
  46  *      -XX:-EnableJVMCI
  47  *      compiler.jvmci.JVM_GetJVMCIRuntimeTest
  48 
  49  */
  50 
  51 package compiler.jvmci;
  52 
  53 import jdk.vm.ci.runtime.JVMCI;
  54 import jdk.test.lib.Asserts;
  55 
  56 public class JVM_GetJVMCIRuntimeTest implements Runnable {
  57     private static final boolean IS_POSITIVE = Boolean.getBoolean(
  58             "compiler.jvmci.JVM_GetJVMCIRuntimeTest.positive");
  59     private static final boolean IN_THREAD = Boolean.getBoolean(
  60             "compiler.jvmci.JVM_GetJVMCIRuntimeTest.threaded");
  61 
  62     public static void main(String[] args) throws Throwable {
  63         JVM_GetJVMCIRuntimeTest instance = new JVM_GetJVMCIRuntimeTest();
  64         if (IN_THREAD) {
  65             Thread t = new Thread(instance);
  66             t.start();
  67             t.join();
  68         } else {
  69             instance.run();
  70         }
  71     }
  72 
  73     public void run() {
  74         Object result;
  75         try {
  76             result = JVMCI.getRuntime();
  77         } catch (InternalError e) {
  78             if (IS_POSITIVE) {
  79                 throw new AssertionError("unexpected exception", e);
  80             }
  81             return;
  82         }
  83         if (!IS_POSITIVE) {
  84             throw new AssertionError("didn't get expected exception");
  85         }
  86         Asserts.assertNotNull(result,
  87                 "initializeRuntime returned null");
  88         Asserts.assertEQ(result, JVMCI.getRuntime(),
  89                 "initializeRuntime returns different results");
  90 
  91     }
  92 }