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 package org.graalvm.compiler.hotspot;
26
27 import static jdk.vm.ci.code.ValueUtil.isRegister;
28 import static org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant;
29 import static org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant;
30
31 import java.util.Arrays;
32
33 import jdk.internal.vm.compiler.collections.EconomicMap;
34 import org.graalvm.compiler.asm.Assembler;
35 import org.graalvm.compiler.core.common.NumUtil;
36 import org.graalvm.compiler.debug.GraalError;
37 import org.graalvm.compiler.hotspot.debug.BenchmarkCounters;
38 import org.graalvm.compiler.hotspot.meta.HotSpotRegistersProvider;
39 import org.graalvm.compiler.lir.LIRInstruction;
40 import org.graalvm.compiler.lir.LIRInstructionClass;
41
42 import jdk.vm.ci.code.Register;
43 import jdk.vm.ci.code.TargetDescription;
44 import jdk.vm.ci.meta.JavaConstant;
45 import jdk.vm.ci.meta.JavaKind;
46 import jdk.vm.ci.meta.Value;
47
48 public abstract class HotSpotCounterOp extends LIRInstruction {
49 public static final LIRInstructionClass<HotSpotCounterOp> TYPE = LIRInstructionClass.create(HotSpotCounterOp.class);
52 private final String[] groups;
53 protected final Register thread;
54 protected final GraalHotSpotVMConfig config;
55 @Alive({OperandFlag.CONST, OperandFlag.REG}) protected Value[] increments;
56
57 public HotSpotCounterOp(LIRInstructionClass<? extends HotSpotCounterOp> c, String name, String group, Value increment, HotSpotRegistersProvider registers, GraalHotSpotVMConfig config) {
58 this(c, new String[]{name}, new String[]{group}, new Value[]{increment}, registers, config);
59 }
60
61 public HotSpotCounterOp(LIRInstructionClass<? extends HotSpotCounterOp> c, String[] names, String[] groups, Value[] increments, HotSpotRegistersProvider registers, GraalHotSpotVMConfig config) {
62 super(c);
63
64 assert names.length == groups.length;
65 assert groups.length == increments.length;
66
67 this.names = names;
68 this.groups = groups;
69 this.increments = increments;
70 this.thread = registers.getThreadRegister();
71 this.config = config;
72 }
73
74 protected static int getDisplacementForLongIndex(TargetDescription target, long index) {
75 long finalDisp = index * target.arch.getPlatformKind(JavaKind.Long).getSizeInBytes();
76 if (!NumUtil.isInt(finalDisp)) {
77 throw GraalError.unimplemented("cannot deal with indices that big: " + index);
78 }
79 return (int) finalDisp;
80 }
81
82 protected interface CounterProcedure {
83 /**
84 * Lambda interface for iterating over counters declared in this op.
85 *
86 * @param counterIndex Index in this CounterOp object.
87 * @param increment Value for increment
88 * @param displacement Displacement in bytes in the counter array
89 */
90 void apply(int counterIndex, Value increment, int displacement);
91 }
|
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 package org.graalvm.compiler.hotspot;
26
27 import static jdk.vm.ci.code.ValueUtil.isRegister;
28 import static org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant;
29 import static org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant;
30 import static org.graalvm.compiler.nodes.debug.DynamicCounterNode.MAX_INCREMENT;
31 import static org.graalvm.compiler.nodes.debug.DynamicCounterNode.MIN_INCREMENT;
32
33 import java.util.Arrays;
34
35 import jdk.internal.vm.compiler.collections.EconomicMap;
36 import org.graalvm.compiler.asm.Assembler;
37 import org.graalvm.compiler.core.common.NumUtil;
38 import org.graalvm.compiler.debug.GraalError;
39 import org.graalvm.compiler.hotspot.debug.BenchmarkCounters;
40 import org.graalvm.compiler.hotspot.meta.HotSpotRegistersProvider;
41 import org.graalvm.compiler.lir.LIRInstruction;
42 import org.graalvm.compiler.lir.LIRInstructionClass;
43
44 import jdk.vm.ci.code.Register;
45 import jdk.vm.ci.code.TargetDescription;
46 import jdk.vm.ci.meta.JavaConstant;
47 import jdk.vm.ci.meta.JavaKind;
48 import jdk.vm.ci.meta.Value;
49
50 public abstract class HotSpotCounterOp extends LIRInstruction {
51 public static final LIRInstructionClass<HotSpotCounterOp> TYPE = LIRInstructionClass.create(HotSpotCounterOp.class);
54 private final String[] groups;
55 protected final Register thread;
56 protected final GraalHotSpotVMConfig config;
57 @Alive({OperandFlag.CONST, OperandFlag.REG}) protected Value[] increments;
58
59 public HotSpotCounterOp(LIRInstructionClass<? extends HotSpotCounterOp> c, String name, String group, Value increment, HotSpotRegistersProvider registers, GraalHotSpotVMConfig config) {
60 this(c, new String[]{name}, new String[]{group}, new Value[]{increment}, registers, config);
61 }
62
63 public HotSpotCounterOp(LIRInstructionClass<? extends HotSpotCounterOp> c, String[] names, String[] groups, Value[] increments, HotSpotRegistersProvider registers, GraalHotSpotVMConfig config) {
64 super(c);
65
66 assert names.length == groups.length;
67 assert groups.length == increments.length;
68
69 this.names = names;
70 this.groups = groups;
71 this.increments = increments;
72 this.thread = registers.getThreadRegister();
73 this.config = config;
74 checkIncrements();
75 }
76
77 private boolean checkIncrements() {
78 for (int i = 0; i < increments.length; i++) {
79 Value increment = increments[i];
80 if (isJavaConstant(increment)) {
81 long incValue = asLong(asJavaConstant(increment));
82 if (incValue < MIN_INCREMENT || incValue > MAX_INCREMENT) {
83 String message = String.format("Benchmark counter %s:%s has increment out of range [%d .. %d]: %d", groups[i], names[i], MIN_INCREMENT, MAX_INCREMENT, incValue);
84 assert false : message;
85 }
86 }
87 }
88 return true;
89 }
90
91 protected static int getDisplacementForLongIndex(TargetDescription target, long index) {
92 long finalDisp = index * target.arch.getPlatformKind(JavaKind.Long).getSizeInBytes();
93 if (!NumUtil.isInt(finalDisp)) {
94 throw GraalError.unimplemented("cannot deal with indices that big: " + index);
95 }
96 return (int) finalDisp;
97 }
98
99 protected interface CounterProcedure {
100 /**
101 * Lambda interface for iterating over counters declared in this op.
102 *
103 * @param counterIndex Index in this CounterOp object.
104 * @param increment Value for increment
105 * @param displacement Displacement in bytes in the counter array
106 */
107 void apply(int counterIndex, Value increment, int displacement);
108 }
|