1 /*
   2  * Copyright (c) 2016, 2016, 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 package org.graalvm.compiler.microbenchmarks.lir;
  24 
  25 import java.util.HashMap;
  26 
  27 import org.openjdk.jmh.annotations.Benchmark;
  28 
  29 import org.graalvm.compiler.core.common.GraalOptions;
  30 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
  31 import org.graalvm.compiler.lir.phases.LIRSuites;
  32 import org.graalvm.compiler.microbenchmarks.graal.GraalBenchmark;
  33 import org.graalvm.compiler.microbenchmarks.graal.util.MethodSpec;
  34 import org.graalvm.compiler.options.OptionValue;
  35 import org.graalvm.compiler.options.OptionValue.OverrideScope;
  36 
  37 public class RegisterAllocationTimeBenchmark extends GraalBenchmark {
  38 
  39     // Checkstyle: stop method name check
  40     public static class LSRA_Allocation extends GraalCompilerState.AllocationStage {
  41         @SuppressWarnings("try")
  42         @Override
  43         protected LIRSuites createLIRSuites() {
  44             try (OverrideScope os = OptionValue.override(GraalOptions.TraceRA, false)) {
  45                 return super.createLIRSuites();
  46             }
  47         }
  48     }
  49 
  50     @MethodSpec(declaringClass = String.class, name = "equals")
  51     public static class LSRA_StringEquals extends LSRA_Allocation {
  52     }
  53 
  54     @MethodSpec(declaringClass = HashMap.class, name = "computeIfAbsent")
  55     public static class LSRA_HashMapComputeIfAbsent extends LSRA_Allocation {
  56     }
  57 
  58     @Benchmark
  59     public LIRGenerationResult lsra_STRING_equals(LSRA_StringEquals s) {
  60         return s.compile();
  61     }
  62 
  63     @Benchmark
  64     public LIRGenerationResult lsra_HASHMAP_computeIfAbsent(LSRA_HashMapComputeIfAbsent s) {
  65         return s.compile();
  66     }
  67 
  68     public static class TraceRA_Allocation extends GraalCompilerState.AllocationStage {
  69         @SuppressWarnings("try")
  70         @Override
  71         protected LIRSuites createLIRSuites() {
  72             try (OverrideScope os = OptionValue.override(GraalOptions.TraceRA, true)) {
  73                 return super.createLIRSuites();
  74             }
  75         }
  76     }
  77 
  78     @MethodSpec(declaringClass = String.class, name = "equals")
  79     public static class TraceRA_StringEquals extends TraceRA_Allocation {
  80     }
  81 
  82     @MethodSpec(declaringClass = HashMap.class, name = "computeIfAbsent")
  83     public static class TraceRA_HashMapComputeIfAbsent extends TraceRA_Allocation {
  84     }
  85 
  86     @Benchmark
  87     public LIRGenerationResult tracera_STRING_equals(TraceRA_StringEquals s) {
  88         return s.compile();
  89     }
  90 
  91     @Benchmark
  92     public LIRGenerationResult tracera_HASHMAP_computeIfAbsent(TraceRA_HashMapComputeIfAbsent s) {
  93         return s.compile();
  94     }
  95     // Checkstyle: resume method name check
  96 }