< prev index next >

test/compiler/jvmci/compilerToVM/MaterializeVirtualObjectTest.java

Print this page




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

  57 
  58 import sun.hotspot.WhiteBox;
  59 
  60 public class MaterializeVirtualObjectTest {
  61     private static final WhiteBox WB = WhiteBox.getWhiteBox();
  62     private static final Method METHOD;
  63     private static final ResolvedJavaMethod RESOLVED_METHOD;
  64     private static final boolean INVALIDATE = Boolean.getBoolean(
  65             "compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate");
  66 
  67     static {

  68         try {
  69             METHOD = MaterializeVirtualObjectTest.class.getDeclaredMethod(
  70                     "testFrame", String.class, boolean.class);
  71         } catch (NoSuchMethodException e) {
  72             throw new Error("Can't get executable for test method", e);
  73         }
  74         RESOLVED_METHOD = CTVMUtilities.getResolvedMethod(METHOD);


  75     }
  76 
  77     public static void main(String[] args) {
  78         int levels[] = CompilerUtils.getAvailableCompilationLevels();
  79         // we need compilation level 4 to use EscapeAnalysis
  80         if (levels.length < 1 || levels[levels.length - 1] != 4) {
  81             System.out.println("INFO: Test needs compilation level 4 to"
  82                     + " be available. Skipping.");
  83         } else {
  84             new MaterializeVirtualObjectTest().test();
  85         }
  86     }
  87 
  88     private static String getName() {
  89         return "CASE: invalidate=" + INVALIDATE;
  90     }
  91 
  92     private void test() {
  93         System.out.println(getName());
  94         Asserts.assertFalse(WB.isMethodCompiled(METHOD), getName()
  95                 + " : method unexpectedly compiled");
  96         /* need to call testFrame at least once to be able to compile it, so
  97            calling with materialize=false, because testFrame is not compiled */
  98         testFrame("someString", /* materialize= */ false);
  99         WB.enqueueMethodForCompilation(METHOD, 4);

 100         Asserts.assertTrue(WB.isMethodCompiled(METHOD), getName()
 101                 + "Method unexpectedly not compiled");
 102         // calling with materialize=true to materialize compiled testFrame
 103         testFrame("someString", /* materialize= */ true);
 104     }
 105 
 106     private void testFrame(String str, boolean materialize) {
 107         Helper helper = new Helper(str);
 108         check(materialize);
 109         Asserts.assertTrue((helper.string != null) && (this != null)
 110                 && (helper != null), getName() + " : some locals are null");
 111     }
 112 
 113     private void check(boolean materialize) {
 114         // Materialize virtual objects on last invocation
 115         if (materialize) {
 116             HotSpotStackFrameReference hsFrame = CompilerToVMHelper
 117                     .getNextStackFrame(/* topmost frame */ null,
 118                             new ResolvedJavaMethod[]{
 119                                 RESOLVED_METHOD}, /* don't skip any */ 0);
 120             Asserts.assertNotNull(hsFrame, getName() + " : got null frame");
 121             Asserts.assertTrue(WB.isMethodCompiled(METHOD), getName()
 122                     + "Test method should be compiled");
 123             Asserts.assertTrue(hsFrame.hasVirtualObjects(), getName()
 124                     + ": has no virtual object before materialization");
 125             CompilerToVMHelper.materializeVirtualObjects(hsFrame, INVALIDATE);
 126             Asserts.assertFalse(hsFrame.hasVirtualObjects(), getName()
 127                     + " : has virtual object after materialization");
 128             Asserts.assertEQ(WB.isMethodCompiled(METHOD), !INVALIDATE, getName()
 129                     + " : unexpected compiled status");
 130         }
 131     }
 132 
 133     private class Helper {
 134         public String string;
 135 


   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 /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 -Xmixed -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 -Xmixed -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 java.lang.reflect.Method;
  49 import jdk.vm.ci.hotspot.HotSpotStackFrameReference;
  50 import jdk.vm.ci.meta.ResolvedJavaMethod;
  51 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  52 import jdk.test.lib.Asserts;
  53 
  54 import compiler.jvmci.common.CTVMUtilities;
  55 import compiler.testlibrary.CompilerUtils;
  56 import compiler.whitebox.CompilerWhiteBoxTest;
  57 
  58 import sun.hotspot.WhiteBox;
  59 
  60 public class MaterializeVirtualObjectTest {
  61     private static final WhiteBox WB;
  62     private static final Method METHOD;
  63     private static final ResolvedJavaMethod RESOLVED_METHOD;
  64     private static final boolean INVALIDATE;

  65 
  66     static {
  67         WB = WhiteBox.getWhiteBox();
  68         try {
  69             METHOD = MaterializeVirtualObjectTest.class.getDeclaredMethod(
  70                     "testFrame", String.class, int.class);
  71         } catch (NoSuchMethodException e) {
  72             throw new Error("Can't get executable for test method", e);
  73         }
  74         RESOLVED_METHOD = CTVMUtilities.getResolvedMethod(METHOD);
  75         INVALIDATE = Boolean.getBoolean(
  76             "compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate");
  77     }
  78 
  79     public static void main(String[] args) {
  80         int levels[] = CompilerUtils.getAvailableCompilationLevels();
  81         // we need compilation level 4 to use EscapeAnalysis
  82         if (levels.length < 1 || levels[levels.length - 1] != 4) {
  83             System.out.println("INFO: Test needs compilation level 4 to"
  84                     + " be available. Skipping.");
  85         } else {
  86             new MaterializeVirtualObjectTest().test();
  87         }
  88     }
  89 
  90     private static String getName() {
  91         return "CASE: invalidate=" + INVALIDATE;
  92     }
  93 
  94     private void test() {
  95         System.out.println(getName());
  96         Asserts.assertFalse(WB.isMethodCompiled(METHOD), getName()
  97                 + " : method unexpectedly compiled");
  98         /* need to trigger compilation by multiple method invocations
  99            in order to have method profile data to be gathered */
 100         for (int i = 0; i < CompilerWhiteBoxTest.THRESHOLD; i++) {
 101             testFrame("someString", i);
 102         }
 103         Asserts.assertTrue(WB.isMethodCompiled(METHOD), getName()
 104                 + "Method unexpectedly not compiled");
 105         testFrame("someString", CompilerWhiteBoxTest.THRESHOLD);

 106     }
 107 
 108     private void testFrame(String str, int iteration) {
 109         Helper helper = new Helper(str);
 110         check(iteration);
 111         Asserts.assertTrue((helper.string != null) && (this != null)
 112                 && (helper != null), getName() + " : some locals are null");
 113     }
 114 
 115     private void check(int iteration) {
 116         // Materialize virtual objects on last invocation
 117         if (iteration == CompilerWhiteBoxTest.THRESHOLD) {
 118             HotSpotStackFrameReference hsFrame = CompilerToVMHelper
 119                     .getNextStackFrame(/* topmost frame */ null,
 120                             new ResolvedJavaMethod[]{
 121                                 RESOLVED_METHOD}, /* don't skip any */ 0);
 122             Asserts.assertNotNull(hsFrame, getName() + " : got null frame");
 123             Asserts.assertTrue(WB.isMethodCompiled(METHOD), getName()
 124                     + "Test method should be compiled");
 125             Asserts.assertTrue(hsFrame.hasVirtualObjects(), getName()
 126                     + ": has no virtual object before materialization");
 127             CompilerToVMHelper.materializeVirtualObjects(hsFrame, INVALIDATE);
 128             Asserts.assertFalse(hsFrame.hasVirtualObjects(), getName()
 129                     + " : has virtual object after materialization");
 130             Asserts.assertEQ(WB.isMethodCompiled(METHOD), !INVALIDATE, getName()
 131                     + " : unexpected compiled status");
 132         }
 133     }
 134 
 135     private class Helper {
 136         public String string;
 137 
< prev index next >