src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/org/graalvm/compiler/microbenchmarks/graal/GraphCopyBenchmark.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.microbenchmarks/src/org/graalvm/compiler/microbenchmarks/graal

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/org/graalvm/compiler/microbenchmarks/graal/GraphCopyBenchmark.java

Print this page




  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.microbenchmarks.graal;
  24 
  25 import org.openjdk.jmh.annotations.Benchmark;
  26 import org.openjdk.jmh.annotations.Warmup;
  27 
  28 import org.graalvm.compiler.graph.Graph;
  29 import org.graalvm.compiler.microbenchmarks.graal.util.GraalState;
  30 import org.graalvm.compiler.microbenchmarks.graal.util.GraphState;
  31 import org.graalvm.compiler.microbenchmarks.graal.util.MethodSpec;
  32 import org.graalvm.compiler.nodes.StructuredGraph;
  33 
  34 /**
  35  * Benchmarks the performance of {@link Graph#copy()}.
  36  */
  37 public class GraphCopyBenchmark extends GraalBenchmark {
  38 
  39     @MethodSpec(declaringClass = ConditionalEliminationBenchmark.class, name = "nullnessSnippet")
  40     public static class Nullness extends GraphState {
  41     }
  42 
  43     @SuppressWarnings("unused")
  44     public static int nullnessSnippet(Object a, Object b) {
  45         if (a == null) {
  46             if (a == b) {
  47                 if (b == null) {
  48                     return 1;
  49                 } else {
  50                     return -2;
  51                 }
  52             } else {
  53                 if (b == null) {
  54                     return -3;
  55                 } else {


  58             }
  59         } else {
  60             if (a == b) {
  61                 if (b == null) {
  62                     return -5;
  63                 } else {
  64                     return 6;
  65                 }
  66             } else {
  67                 if (b == null) {
  68                     return 7;
  69                 } else {
  70                     return 8;
  71                 }
  72             }
  73         }
  74     }
  75 
  76     @Benchmark
  77     @Warmup(iterations = 20)
  78     public StructuredGraph nullness(Nullness s, @SuppressWarnings("unused") GraalState g) {
  79         return (StructuredGraph) s.graph.copy();
  80     }
  81 
  82     @MethodSpec(declaringClass = GraphCopyBenchmark.class, name = "searchSnippet")
  83     public static class Search extends GraphState {
  84     }
  85 
  86     static class Entry {
  87         final String name;
  88 
  89         Entry(String name) {
  90             this.name = name;
  91         }
  92     }
  93 
  94     static class EntryWithNext extends Entry {
  95         EntryWithNext(String name, Entry next) {
  96             super(name);
  97             this.next = next;
  98         }
  99 


 110                     Entry next = ((EntryWithNext) current).next;
 111                     current = next;
 112                 }
 113             }
 114 
 115             if (current != null) {
 116                 if (current.name.equals(name)) {
 117                     return current;
 118                 }
 119             }
 120             if (current == alternative) {
 121                 return null;
 122             }
 123             current = alternative;
 124 
 125         } while (true);
 126     }
 127 
 128     @Benchmark
 129     @Warmup(iterations = 20)
 130     public StructuredGraph search(Search s, @SuppressWarnings("unused") GraalState g) {
 131         return (StructuredGraph) s.graph.copy();
 132     }
 133 }


  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.microbenchmarks.graal;
  24 
  25 import org.openjdk.jmh.annotations.Benchmark;
  26 import org.openjdk.jmh.annotations.Warmup;
  27 
  28 import org.graalvm.compiler.graph.Graph;
  29 import org.graalvm.compiler.microbenchmarks.graal.util.GraalState;
  30 import org.graalvm.compiler.microbenchmarks.graal.util.GraphState;
  31 import org.graalvm.compiler.microbenchmarks.graal.util.MethodSpec;
  32 import org.graalvm.compiler.nodes.StructuredGraph;
  33 
  34 /**
  35  * Benchmarks the performance of {@link Graph#copy(org.graalvm.compiler.debug.DebugContext)}.
  36  */
  37 public class GraphCopyBenchmark extends GraalBenchmark {
  38 
  39     @MethodSpec(declaringClass = ConditionalEliminationBenchmark.class, name = "nullnessSnippet")
  40     public static class Nullness extends GraphState {
  41     }
  42 
  43     @SuppressWarnings("unused")
  44     public static int nullnessSnippet(Object a, Object b) {
  45         if (a == null) {
  46             if (a == b) {
  47                 if (b == null) {
  48                     return 1;
  49                 } else {
  50                     return -2;
  51                 }
  52             } else {
  53                 if (b == null) {
  54                     return -3;
  55                 } else {


  58             }
  59         } else {
  60             if (a == b) {
  61                 if (b == null) {
  62                     return -5;
  63                 } else {
  64                     return 6;
  65                 }
  66             } else {
  67                 if (b == null) {
  68                     return 7;
  69                 } else {
  70                     return 8;
  71                 }
  72             }
  73         }
  74     }
  75 
  76     @Benchmark
  77     @Warmup(iterations = 20)
  78     public StructuredGraph nullness(Nullness s, GraalState g) {
  79         return (StructuredGraph) s.graph.copy(g.debug);
  80     }
  81 
  82     @MethodSpec(declaringClass = GraphCopyBenchmark.class, name = "searchSnippet")
  83     public static class Search extends GraphState {
  84     }
  85 
  86     static class Entry {
  87         final String name;
  88 
  89         Entry(String name) {
  90             this.name = name;
  91         }
  92     }
  93 
  94     static class EntryWithNext extends Entry {
  95         EntryWithNext(String name, Entry next) {
  96             super(name);
  97             this.next = next;
  98         }
  99 


 110                     Entry next = ((EntryWithNext) current).next;
 111                     current = next;
 112                 }
 113             }
 114 
 115             if (current != null) {
 116                 if (current.name.equals(name)) {
 117                     return current;
 118                 }
 119             }
 120             if (current == alternative) {
 121                 return null;
 122             }
 123             current = alternative;
 124 
 125         } while (true);
 126     }
 127 
 128     @Benchmark
 129     @Warmup(iterations = 20)
 130     public StructuredGraph search(Search s, GraalState g) {
 131         return (StructuredGraph) s.graph.copy(g.debug);
 132     }
 133 }
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/org/graalvm/compiler/microbenchmarks/graal/GraphCopyBenchmark.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File