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 package org.graalvm.compiler.replacements; 26 27 import java.util.ArrayList; 28 import java.util.Collections; 29 import java.util.List; 30 31 import org.graalvm.compiler.core.common.GraalOptions; 32 33 /** 34 * A counter that can (only) be {@linkplain #inc() incremented} from within a snippet for gathering 35 * snippet specific metrics. 36 */ 37 public final class SnippetCounter implements Comparable<SnippetCounter> { 38 /** 39 * A group of related counters. 40 */ 41 public static class Group { 42 43 public interface Factory { 44 /** 45 * If snippet counters are {@linkplain GraalOptions#SnippetCounters enabled}, creates 46 * and registers a {@link Group} with the given name. Otherwise, returns null. 47 * 48 * @param name name of the counter group 49 */ 50 Group createSnippetCounterGroup(String name); 51 } 52 53 public static final Factory NullFactory = new Factory() { 54 55 @Override 56 public Group createSnippetCounterGroup(String name) { 57 return null; 113 */ 114 public SnippetCounter(Group group, String name, String description) { 115 this.group = group; 116 this.name = name; 117 this.description = description; 118 if (group != null) { 119 List<SnippetCounter> counters = group.counters; 120 counters.add(this); 121 } 122 } 123 124 public Group getGroup() { 125 return group; 126 } 127 128 /** 129 * Increments the value of this counter. This method can only be used in a snippet on a 130 * compile-time constant {@link SnippetCounter} object. 131 */ 132 public void inc() { 133 if (group != null) { 134 SnippetCounterNode.increment(this); 135 } 136 } 137 138 /** 139 * Increments the value of this counter. This method can only be used in a snippet on a 140 * compile-time constant {@link SnippetCounter} object. 141 */ 142 public void add(int increment) { 143 if (group != null) { 144 SnippetCounterNode.add(this, increment); 145 } 146 } 147 148 /** 149 * Gets the value of this counter. 150 */ 151 public long value() { 152 return value; 153 } 154 155 @Override 156 public String toString() { 157 if (group != null) { 158 return "SnippetCounter-" + group.name + ":" + name; 159 } 160 return super.toString(); 161 } 162 } | 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 package org.graalvm.compiler.replacements; 26 27 import java.util.ArrayList; 28 import java.util.Collections; 29 import java.util.List; 30 31 import org.graalvm.compiler.core.common.GraalOptions; 32 33 /** 34 * A counter that can (only) be {@linkplain #inc() incremented} from within a snippet for gathering 35 * snippet specific metrics. 36 */ 37 public final class SnippetCounter implements Comparable<SnippetCounter> { 38 39 public static final SnippetCounter DISABLED_COUNTER = new SnippetCounter(null, "Disabled", "Disabled"); 40 41 /** 42 * A group of related counters. 43 */ 44 public static class Group { 45 46 public interface Factory { 47 /** 48 * If snippet counters are {@linkplain GraalOptions#SnippetCounters enabled}, creates 49 * and registers a {@link Group} with the given name. Otherwise, returns null. 50 * 51 * @param name name of the counter group 52 */ 53 Group createSnippetCounterGroup(String name); 54 } 55 56 public static final Factory NullFactory = new Factory() { 57 58 @Override 59 public Group createSnippetCounterGroup(String name) { 60 return null; 116 */ 117 public SnippetCounter(Group group, String name, String description) { 118 this.group = group; 119 this.name = name; 120 this.description = description; 121 if (group != null) { 122 List<SnippetCounter> counters = group.counters; 123 counters.add(this); 124 } 125 } 126 127 public Group getGroup() { 128 return group; 129 } 130 131 /** 132 * Increments the value of this counter. This method can only be used in a snippet on a 133 * compile-time constant {@link SnippetCounter} object. 134 */ 135 public void inc() { 136 if (getGroup() != null) { 137 SnippetCounterNode.increment(this); 138 } 139 } 140 141 /** 142 * Increments the value of this counter. This method can only be used in a snippet on a 143 * compile-time constant {@link SnippetCounter} object. 144 */ 145 public void add(int increment) { 146 if (getGroup() != null) { 147 SnippetCounterNode.add(this, increment); 148 } 149 } 150 151 /** 152 * Gets the value of this counter. 153 */ 154 public long value() { 155 return value; 156 } 157 158 @Override 159 public String toString() { 160 if (group != null) { 161 return "SnippetCounter-" + group.name + ":" + name; 162 } 163 return super.toString(); 164 } 165 } |