# HG changeset patch # User Roland Schatz # Date 1422015088 -3600 # Node ID 76553fa0f02b131154077b9876e97defd5f08684 # Parent a4292401de0f5689644878ec5261c964cc6735b8 Compiler intrinsic for JMH blackhole. diff -r a4292401de0f -r 76553fa0f02b graal/com.oracle.graal.lir/src/com/oracle/graal/lir/StandardOp.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/StandardOp.java Thu Jan 22 16:35:37 2015 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/StandardOp.java Fri Jan 23 13:11:28 2015 +0100 @@ -206,4 +206,19 @@ } } } + + @Opcode("BLACKHOLE") + public static class BlackholeOp extends LIRInstructionBase { + + @Use({REG, STACK}) private Value value; + + public BlackholeOp(Value value) { + this.value = value; + } + + @Override + public void emitCode(CompilationResultBuilder crb) { + // do nothing, just keep value alive until at least here + } + } } diff -r a4292401de0f -r 76553fa0f02b graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java Thu Jan 22 16:35:37 2015 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java Fri Jan 23 13:11:28 2015 +0100 @@ -393,4 +393,8 @@ public LIRGenerationResult getResult() { return res; } + + public void emitBlackhole(Value operand) { + append(new StandardOp.BlackholeOp(operand)); + } } diff -r a4292401de0f -r 76553fa0f02b graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java Thu Jan 22 16:35:37 2015 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java Fri Jan 23 13:11:28 2015 +0100 @@ -189,6 +189,8 @@ Value emitArrayEquals(Kind kind, Value array1, Value array2, Value length); + void emitBlackhole(Value operand); + @SuppressWarnings("unused") default Value emitCountLeadingZeros(Value value) { throw GraalInternalError.unimplemented(); diff -r a4292401de0f -r 76553fa0f02b graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/BlackholeSubstitutions.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/BlackholeSubstitutions.java Fri Jan 23 13:11:28 2015 +0100 @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.replacements; + +import com.oracle.graal.api.replacements.*; +import com.oracle.graal.replacements.nodes.*; + +@ClassSubstitution(className = "org.openjdk.jmh.infra.Blackhole", optional = true) +public class BlackholeSubstitutions { + + @SuppressWarnings("unused") + @MethodSubstitution(isStatic = false, forced = true) + public static void consume(final Object thisObj, Object v) { + BlackholeNode.consume(v); + } + + @SuppressWarnings("unused") + @MethodSubstitution(isStatic = false, forced = true) + public static void consume(final Object thisObj, Object[] v) { + BlackholeNode.consume(v); + } + + @SuppressWarnings("unused") + @MethodSubstitution(isStatic = false, forced = true) + public static void consume(final Object thisObj, byte v) { + BlackholeNode.consume(v); + } + + @SuppressWarnings("unused") + @MethodSubstitution(isStatic = false, forced = true) + public static void consume(final Object thisObj, boolean v) { + BlackholeNode.consume(v); + } + + @SuppressWarnings("unused") + @MethodSubstitution(isStatic = false, forced = true) + public static void consume(final Object thisObj, char v) { + BlackholeNode.consume(v); + } + + @SuppressWarnings("unused") + @MethodSubstitution(isStatic = false, forced = true) + public static void consume(final Object thisObj, short v) { + BlackholeNode.consume(v); + } + + @SuppressWarnings("unused") + @MethodSubstitution(isStatic = false, forced = true) + public static void consume(final Object thisObj, int v) { + BlackholeNode.consume(v); + } + + @SuppressWarnings("unused") + @MethodSubstitution(isStatic = false, forced = true) + public static void consume(final Object thisObj, long v) { + BlackholeNode.consume(v); + } + + @SuppressWarnings("unused") + @MethodSubstitution(isStatic = false, forced = true) + public static void consume(final Object thisObj, float v) { + BlackholeNode.consume(v); + } + + @SuppressWarnings("unused") + @MethodSubstitution(isStatic = false, forced = true) + public static void consume(final Object thisObj, double v) { + BlackholeNode.consume(v); + } +} diff -r a4292401de0f -r 76553fa0f02b graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/GraalMethodSubstitutions.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/GraalMethodSubstitutions.java Thu Jan 22 16:35:37 2015 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/GraalMethodSubstitutions.java Fri Jan 23 13:11:28 2015 +0100 @@ -33,6 +33,7 @@ import com.oracle.graal.api.runtime.*; import com.oracle.graal.graph.*; import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.options.*; /** * Method substitutions that are VM-independent. @@ -40,6 +41,10 @@ @ServiceProvider(ReplacementsProvider.class) public class GraalMethodSubstitutions implements ReplacementsProvider { + static class Options { + @Option(help = "") public static final OptionValue UseBlackholeSubstitution = new OptionValue<>(true); + } + public void registerReplacements(MetaAccessProvider metaAccess, LoweringProvider loweringProvider, SnippetReflectionProvider snippetReflection, Replacements replacements, TargetDescription target) { BoxingSubstitutions.registerReplacements(replacements); if (Intrinsify.getValue()) { @@ -55,6 +60,13 @@ replacements.registerSubstitutions(Short.class, ShortSubstitutions.class); replacements.registerSubstitutions(UnsignedMath.class, UnsignedMathSubstitutions.class); replacements.registerSubstitutions(Edges.class, EdgesSubstitutions.class); + if (Options.UseBlackholeSubstitution.getValue()) { + replacements.registerSubstitutions(new Type() { + public String getTypeName() { + return "org.openjdk.jmh.infra.Blackhole"; + } + }, BlackholeSubstitutions.class); + } } } } diff -r a4292401de0f -r 76553fa0f02b graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/BlackholeNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/BlackholeNode.java Fri Jan 23 13:11:28 2015 +0100 @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.replacements.nodes; + +import com.oracle.graal.compiler.common.type.*; +import com.oracle.graal.nodeinfo.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.spi.*; + +@NodeInfo +public class BlackholeNode extends FixedWithNextNode implements LIRLowerable { + + @Input ValueNode value; + + public BlackholeNode(ValueNode value) { + super(StampFactory.forVoid()); + this.value = value; + } + + @Override + public void generate(NodeLIRBuilderTool gen) { + gen.getLIRGeneratorTool().emitBlackhole(gen.operand(value)); + } + + @NodeIntrinsic + @SuppressWarnings("unused") + public static void consume(boolean v) { + } + + @NodeIntrinsic + @SuppressWarnings("unused") + public static void consume(byte v) { + } + + @NodeIntrinsic + @SuppressWarnings("unused") + public static void consume(short v) { + } + + @NodeIntrinsic + @SuppressWarnings("unused") + public static void consume(char v) { + } + + @NodeIntrinsic + @SuppressWarnings("unused") + public static void consume(int v) { + } + + @NodeIntrinsic + @SuppressWarnings("unused") + public static void consume(long v) { + } + + @NodeIntrinsic + @SuppressWarnings("unused") + public static void consume(float v) { + } + + @NodeIntrinsic + @SuppressWarnings("unused") + public static void consume(double v) { + } + + @NodeIntrinsic + @SuppressWarnings("unused") + public static void consume(Object v) { + } +}