< prev index next >

test/compiler/jvmci/compilerToVM/MaterializeVirtualObjectTest.java

Print this page




  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.arch != "aarch64"
  28  * @library / /testlibrary /../../test/lib
  29  * @compile ../common/CompilerToVMHelper.java
  30  * @build sun.hotspot.WhiteBox MaterializeVirtualObjectTest
  31  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  32  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  33  *                              jdk.vm.ci.hotspot.CompilerToVMHelper
  34  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  35  *     -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
  36  *     -XX:CompileCommand=exclude,*::check -XX:+DoEscapeAnalysis






  37  *     compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest
  38  */
  39 
  40 package compiler.jvmci.compilerToVM;
  41 
  42 import compiler.jvmci.common.CTVMUtilities;

  43 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  44 import jdk.test.lib.Asserts;
  45 import jdk.test.lib.Utils;
  46 import sun.hotspot.WhiteBox;
  47 import java.lang.reflect.Method;
  48 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl;
  49 import jdk.vm.ci.hotspot.HotSpotStackFrameReference;
  50 
  51 public class MaterializeVirtualObjectTest {
  52     private static final WhiteBox WB = WhiteBox.getWhiteBox();
  53     private static final int INVOCATIONS = 100_000;
  54     private static final Method METHOD;
  55     private static final HotSpotResolvedJavaMethodImpl RESOLVED_METHOD;
  56     private final boolean invalidate;

  57 
  58     static {
  59         try {
  60             METHOD = MaterializeVirtualObjectTest.class.getDeclaredMethod(
  61                     "testFrame", String.class, Integer.class);
  62         } catch (NoSuchMethodException e) {
  63             throw new Error("Can't get executable for test method", e);
  64         }
  65         RESOLVED_METHOD = CTVMUtilities.getResolvedMethod(METHOD);
  66     }
  67 
  68     public MaterializeVirtualObjectTest(boolean invalidate) {
  69         this.invalidate = invalidate;







  70     }
  71 
  72     public static void main(String[] args) {
  73         new MaterializeVirtualObjectTest(true).test();
  74         new MaterializeVirtualObjectTest(false).test();
  75     }
  76 
  77     private void test() {
  78         System.out.printf("CASE: invalidate=%b%n", invalidate);
  79         for (int i = 0; i < INVOCATIONS; i++) {
  80             testFrame("someString", i);
  81         }
  82         Utils.waitForCondition(() -> WB.isMethodCompiled(METHOD), 100L);
  83         Asserts.assertTrue(WB.isMethodCompiled(METHOD));
  84         testFrame("someString", INVOCATIONS);




  85     }
  86 
  87     private void testFrame(String str, Integer iteration) {
  88         Helper helper = new Helper(str);
  89         check(iteration);
  90         Asserts.assertTrue((helper.string != null) && (this != null)
  91                 && (helper != null), "Some locals are null");
  92     }
  93 
  94     private void check(int iteration) {
  95         // Materialize virtual objects on last invocation
  96         if (iteration == INVOCATIONS) {
  97             HotSpotStackFrameReference hsFrame = CompilerToVMHelper
  98                     .getNextStackFrame(/* topmost frame */ null,
  99                             new HotSpotResolvedJavaMethodImpl[]{
 100                                 RESOLVED_METHOD}, /* don't skip any */ 0);
 101             Asserts.assertNotNull(hsFrame, "Got null frame");
 102             Asserts.assertTrue(WB.isMethodCompiled(METHOD),
 103                     "Expected test method to be compiled");
 104             Asserts.assertTrue(hsFrame.hasVirtualObjects(),
 105                     "Has no virtual object before materialization");
 106             CompilerToVMHelper.materializeVirtualObjects(hsFrame, invalidate);
 107             Asserts.assertFalse(hsFrame.hasVirtualObjects(),
 108                     "Has virtual object after materialization");
 109             Asserts.assertEQ(WB.isMethodCompiled(METHOD), !invalidate,
 110                     "Unexpected compiled status");
 111         }
 112     }
 113 
 114     private class Helper {
 115         public String string;
 116 
 117         public Helper(String s) {
 118             this.string = s;
 119         }
 120     }
 121 }


  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.arch != "aarch64"
  28  * @library / /testlibrary /../../test/lib
  29  * @compile ../common/CompilerToVMHelper.java
  30  * @build sun.hotspot.WhiteBox MaterializeVirtualObjectTest
  31  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  32  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  33  *                              jdk.vm.ci.hotspot.CompilerToVMHelper
  34  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  35  *     -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
  36  *     -XX:CompileCommand=exclude,*::check -XX:+DoEscapeAnalysis -Xbatch
  37  *     -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=false
  38  *     compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest
  39  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  40  *     -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
  41  *     -XX:CompileCommand=exclude,*::check -XX:+DoEscapeAnalysis -Xbatch
  42  *     -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=true
  43  *     compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest
  44  */
  45 
  46 package compiler.jvmci.compilerToVM;
  47 
  48 import compiler.jvmci.common.CTVMUtilities;
  49 import compiler.testlibrary.CompilerUtils;
  50 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  51 import jdk.test.lib.Asserts;

  52 import sun.hotspot.WhiteBox;
  53 import java.lang.reflect.Method;
  54 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl;
  55 import jdk.vm.ci.hotspot.HotSpotStackFrameReference;
  56 
  57 public class MaterializeVirtualObjectTest {
  58     private static final WhiteBox WB = WhiteBox.getWhiteBox();

  59     private static final Method METHOD;
  60     private static final HotSpotResolvedJavaMethodImpl RESOLVED_METHOD;
  61     private static final boolean INVALIDATE = Boolean.getBoolean(
  62             "compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate");
  63 
  64     static {
  65         try {
  66             METHOD = MaterializeVirtualObjectTest.class.getDeclaredMethod(
  67                     "testFrame", String.class, Integer.class);
  68         } catch (NoSuchMethodException e) {
  69             throw new Error("Can't get executable for test method", e);
  70         }
  71         RESOLVED_METHOD = CTVMUtilities.getResolvedMethod(METHOD);
  72     }
  73 
  74     public static void main(String[] args) {
  75         int levels[] = CompilerUtils.getAvailableCompilationLevels();
  76         // we need compilation level 4 to use EscapeAnalysis
  77         if (levels.length < 1 || levels[levels.length - 1] != 4) {
  78             System.out.println("INFO: Test needs compilation level 4 to"
  79                     + " be available. Skipping.");
  80         } else {
  81             new MaterializeVirtualObjectTest().test();
  82         }
  83     }
  84 
  85     private static String getName() {
  86         return "CASE: invalidate=" + INVALIDATE;

  87     }
  88 
  89     private void test() {
  90         System.out.println(getName());
  91         Asserts.assertFalse(WB.isMethodCompiled(METHOD), getName()
  92                 + " : method unexpectedly compiled");
  93         /* need to call testFrame at least once to be able to compile it, so
  94            calling with materialize=false, because testFrame is not compiled */
  95         testFrame("someString", /* materialize= */ false);
  96         WB.enqueueMethodForCompilation(METHOD, 4);
  97         Asserts.assertTrue(WB.isMethodCompiled(METHOD), getName()
  98                 + "Method unexpectedly not compiled");
  99         // calling with materialize=true to materialize compiled testFrame
 100         testFrame("someString", /* materialize= */ true);
 101     }
 102 
 103     private void testFrame(String str, boolean materialize) {
 104         Helper helper = new Helper(str);
 105         check(materialize);
 106         Asserts.assertTrue((helper.string != null) && (this != null)
 107                 && (helper != null), getName() + " : some locals are null");
 108     }
 109 
 110     private void check(boolean materialize) {
 111         // Materialize virtual objects on last invocation
 112         if (materialize) {
 113             HotSpotStackFrameReference hsFrame = CompilerToVMHelper
 114                     .getNextStackFrame(/* topmost frame */ null,
 115                             new HotSpotResolvedJavaMethodImpl[]{
 116                                 RESOLVED_METHOD}, /* don't skip any */ 0);
 117             Asserts.assertNotNull(hsFrame, getName() + " : got null frame");
 118             Asserts.assertTrue(WB.isMethodCompiled(METHOD), getName()
 119                     + " : test method should be compiled");
 120             Asserts.assertTrue(hsFrame.hasVirtualObjects(), getName()
 121                     + " : has no virtual object before materialization");
 122             CompilerToVMHelper.materializeVirtualObjects(hsFrame, INVALIDATE);
 123             Asserts.assertFalse(hsFrame.hasVirtualObjects(), getName()
 124                     + " : has virtual object after materialization");
 125             Asserts.assertEQ(WB.isMethodCompiled(METHOD), !INVALIDATE, getName()
 126                     + " : unexpected compiled status");
 127         }
 128     }
 129 
 130     private class Helper {
 131         public String string;
 132 
 133         public Helper(String s) {
 134             this.string = s;
 135         }
 136     }
 137 }
< prev index next >