src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/InstanceOfTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/InstanceOfTest.java

Print this page




  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 package org.graalvm.compiler.replacements.test;
  24 
  25 import java.util.Arrays;
  26 import java.util.HashMap;
  27 import java.util.List;
  28 import java.util.Map;
  29 import java.util.TreeMap;
  30 
  31 import org.junit.Test;
  32 
  33 import org.graalvm.compiler.debug.Debug;
  34 import org.graalvm.compiler.debug.Debug.Scope;
  35 import org.graalvm.compiler.nodes.IfNode;
  36 import org.graalvm.compiler.nodes.ReturnNode;
  37 import org.graalvm.compiler.nodes.StructuredGraph;
  38 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  39 import org.graalvm.compiler.nodes.java.InstanceOfNode;
  40 import org.graalvm.compiler.phases.common.AbstractInliningPhase;

  41 
  42 import jdk.vm.ci.code.site.Call;
  43 import jdk.vm.ci.code.site.Mark;
  44 import jdk.vm.ci.code.site.Site;
  45 import jdk.vm.ci.meta.JavaTypeProfile;
  46 
  47 /**
  48  * Tests the implementation of instanceof, allowing profiling information to be manually specified.
  49  */
  50 public class InstanceOfTest extends TypeCheckTest {
  51 
  52     public InstanceOfTest() {
  53         createSuites(getInitialOptions()).getHighTier().findPhase(AbstractInliningPhase.class).remove();
  54     }
  55 
  56     @Override
  57     protected void replaceProfile(StructuredGraph graph, JavaTypeProfile profile) {
  58         InstanceOfNode ion = graph.getNodes().filter(InstanceOfNode.class).first();
  59         if (ion != null) {
  60             ion.setProfile(profile, graph.start());


 468     public void testTypeCheck() {
 469         testConstantReturn("exactlyObject", 0);
 470         testConstantReturn("exactlyObjectArray", 0);
 471         testConstantReturn("exactlyString", 0);
 472         testConstantReturn("exactlyStringArray", 0);
 473         testConstantReturn("instanceofString", 0);
 474         testConstantReturn("instanceofStringArray", 0);
 475     }
 476 
 477     private void testConstantReturn(String name, Object value) {
 478         StructuredGraph result = buildGraph(name);
 479         ReturnNode ret = result.getNodes(ReturnNode.TYPE).first();
 480         assertDeepEquals(1, result.getNodes(ReturnNode.TYPE).count());
 481 
 482         assertDeepEquals(true, ret.result().isConstant());
 483         assertDeepEquals(value, ret.result().asJavaConstant().asBoxedPrimitive());
 484     }
 485 
 486     @SuppressWarnings("try")
 487     protected StructuredGraph buildGraph(final String snippet) {
 488         try (Scope s = Debug.scope("InstanceOfTest", getMetaAccess().lookupJavaMethod(getMethod(snippet)))) {
 489             StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);

 490             compile(graph.method(), graph);
 491             Debug.dump(Debug.BASIC_LEVEL, graph, snippet);
 492             return graph;
 493         } catch (Throwable e) {
 494             throw Debug.handle(e);
 495         }
 496     }
 497 
 498     static class Depth1 implements Cloneable {
 499     }
 500 
 501     static class Depth2 extends Depth1 {
 502     }
 503 
 504     static class Depth3 extends Depth2 {
 505     }
 506 
 507     static class Depth4 extends Depth3 {
 508     }
 509 
 510     static class Depth5 extends Depth4 {
 511     }
 512 
 513     static class Depth6 extends Depth5 {
 514     }




  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 package org.graalvm.compiler.replacements.test;
  24 
  25 import java.util.Arrays;
  26 import java.util.HashMap;
  27 import java.util.List;
  28 import java.util.Map;
  29 import java.util.TreeMap;
  30 
  31 import org.graalvm.compiler.debug.DebugContext;



  32 import org.graalvm.compiler.nodes.IfNode;
  33 import org.graalvm.compiler.nodes.ReturnNode;
  34 import org.graalvm.compiler.nodes.StructuredGraph;
  35 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  36 import org.graalvm.compiler.nodes.java.InstanceOfNode;
  37 import org.graalvm.compiler.phases.common.AbstractInliningPhase;
  38 import org.junit.Test;
  39 
  40 import jdk.vm.ci.code.site.Call;
  41 import jdk.vm.ci.code.site.Mark;
  42 import jdk.vm.ci.code.site.Site;
  43 import jdk.vm.ci.meta.JavaTypeProfile;
  44 
  45 /**
  46  * Tests the implementation of instanceof, allowing profiling information to be manually specified.
  47  */
  48 public class InstanceOfTest extends TypeCheckTest {
  49 
  50     public InstanceOfTest() {
  51         createSuites(getInitialOptions()).getHighTier().findPhase(AbstractInliningPhase.class).remove();
  52     }
  53 
  54     @Override
  55     protected void replaceProfile(StructuredGraph graph, JavaTypeProfile profile) {
  56         InstanceOfNode ion = graph.getNodes().filter(InstanceOfNode.class).first();
  57         if (ion != null) {
  58             ion.setProfile(profile, graph.start());


 466     public void testTypeCheck() {
 467         testConstantReturn("exactlyObject", 0);
 468         testConstantReturn("exactlyObjectArray", 0);
 469         testConstantReturn("exactlyString", 0);
 470         testConstantReturn("exactlyStringArray", 0);
 471         testConstantReturn("instanceofString", 0);
 472         testConstantReturn("instanceofStringArray", 0);
 473     }
 474 
 475     private void testConstantReturn(String name, Object value) {
 476         StructuredGraph result = buildGraph(name);
 477         ReturnNode ret = result.getNodes(ReturnNode.TYPE).first();
 478         assertDeepEquals(1, result.getNodes(ReturnNode.TYPE).count());
 479 
 480         assertDeepEquals(true, ret.result().isConstant());
 481         assertDeepEquals(value, ret.result().asJavaConstant().asBoxedPrimitive());
 482     }
 483 
 484     @SuppressWarnings("try")
 485     protected StructuredGraph buildGraph(final String snippet) {
 486         DebugContext debug = getDebugContext();
 487         try (DebugContext.Scope s = debug.scope("InstanceOfTest", getMetaAccess().lookupJavaMethod(getMethod(snippet)))) {
 488             StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES, debug);
 489             compile(graph.method(), graph);
 490             debug.dump(DebugContext.BASIC_LEVEL, graph, snippet);
 491             return graph;
 492         } catch (Throwable e) {
 493             throw debug.handle(e);
 494         }
 495     }
 496 
 497     static class Depth1 implements Cloneable {
 498     }
 499 
 500     static class Depth2 extends Depth1 {
 501     }
 502 
 503     static class Depth3 extends Depth2 {
 504     }
 505 
 506     static class Depth4 extends Depth3 {
 507     }
 508 
 509     static class Depth5 extends Depth4 {
 510     }
 511 
 512     static class Depth6 extends Depth5 {
 513     }


src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/InstanceOfTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File