# HG changeset patch # User Peter B. Kessler # Date 1448929497 28800 # Node ID 99b21d7f7ed64356d38ef4f175019df2d765aa63 # Parent cc904fd7b454f8da2bc09cecad8c95583dbb1a7f Implement a "pause" instruction for spin-loops. - Not implemented on SPARC, yet. diff -r cc904fd7b454 -r 99b21d7f7ed6 graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64Assembler.java --- a/graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64Assembler.java Sat Nov 21 09:24:29 2015 -0800 +++ b/graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64Assembler.java Mon Nov 30 16:24:57 2015 -0800 @@ -2315,6 +2315,11 @@ emitByte(0xCC); } + public final void pause() { + emitByte(0xF3); + emitByte(0x90); + } + private void emitx87(int b1, int b2, int i) { assert 0 <= i && i < 8 : "illegal stack offset"; emitByte(b1); diff -r cc904fd7b454 -r 99b21d7f7ed6 graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java --- a/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java Sat Nov 21 09:24:29 2015 -0800 +++ b/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java Mon Nov 30 16:24:57 2015 -0800 @@ -136,6 +136,7 @@ import jdk.vm.ci.code.Register; import jdk.vm.ci.code.RegisterConfig; import jdk.vm.ci.code.TargetDescription; +import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.PlatformKind; import jdk.vm.ci.sparc.SPARC; @@ -2449,6 +2450,13 @@ tcc(Icc, Always, trap); } + public void pause() { + // Maybe fmt10(rd=0b1_1011, op3=0b11_0000, rs1=0, i=1, simm13=1), or + // maybe op3(Wr, g0, 1, %pause). + // What should the count be? + JVMCIError.unimplemented("The SPARC pause instruction is not yet implemented."); + } + public void tcc(CC cc, ConditionFlag flag, int trap) { assert isImm(trap, 8); int b = cc.value << 11; diff -r cc904fd7b454 -r 99b21d7f7ed6 graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64NodeLIRBuilder.java --- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64NodeLIRBuilder.java Sat Nov 21 09:24:29 2015 -0800 +++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64NodeLIRBuilder.java Mon Nov 30 16:24:57 2015 -0800 @@ -33,6 +33,7 @@ import com.oracle.graal.lir.LIRFrameState; import com.oracle.graal.lir.amd64.AMD64BreakpointOp; import com.oracle.graal.lir.amd64.AMD64Call; +import com.oracle.graal.lir.amd64.AMD64PauseOp; import com.oracle.graal.lir.gen.LIRGeneratorTool; import com.oracle.graal.nodes.BreakpointNode; import com.oracle.graal.nodes.DeoptimizingNode; @@ -40,6 +41,7 @@ import com.oracle.graal.nodes.FixedWithNextNode; import com.oracle.graal.nodes.IfNode; import com.oracle.graal.nodes.IndirectCallTargetNode; +import com.oracle.graal.nodes.PauseNode; import com.oracle.graal.nodes.StructuredGraph; import com.oracle.graal.nodes.ValueNode; import com.oracle.graal.nodes.calc.FixedBinaryNode; @@ -114,6 +116,11 @@ } @Override + public void visitPauseNode(PauseNode node) { + append(new AMD64PauseOp()); + } + + @Override public AMD64LIRGenerator getLIRGeneratorTool() { return (AMD64LIRGenerator) gen; } diff -r cc904fd7b454 -r 99b21d7f7ed6 graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCNodeLIRBuilder.java --- a/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCNodeLIRBuilder.java Sat Nov 21 09:24:29 2015 -0800 +++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCNodeLIRBuilder.java Mon Nov 30 16:24:57 2015 -0800 @@ -33,7 +33,9 @@ import com.oracle.graal.lir.gen.LIRGeneratorTool; import com.oracle.graal.lir.sparc.SPARCBreakpointOp; import com.oracle.graal.lir.sparc.SPARCJumpOp; +import com.oracle.graal.lir.sparc.SPARCPauseOp; import com.oracle.graal.nodes.BreakpointNode; +import com.oracle.graal.nodes.PauseNode; import com.oracle.graal.nodes.StructuredGraph; import com.oracle.graal.nodes.ValueNode; @@ -65,6 +67,11 @@ } @Override + public void visitPauseNode(PauseNode node) { + append(new SPARCPauseOp()); + } + + @Override protected JumpOp newJumpOp(LabelRef ref) { return new SPARCJumpOp(ref); } diff -r cc904fd7b454 -r 99b21d7f7ed6 graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64PauseOp.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64PauseOp.java Mon Nov 30 16:24:57 2015 -0800 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2011, 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.lir.amd64; + +import com.oracle.graal.asm.amd64.AMD64MacroAssembler; +import com.oracle.graal.lir.LIRInstructionClass; +import com.oracle.graal.lir.Opcode; +import com.oracle.graal.lir.asm.CompilationResultBuilder; + +/** + * Emits a pause. + */ +@Opcode("PAUSE") +public final class AMD64PauseOp extends AMD64LIRInstruction { + public static final LIRInstructionClass TYPE = LIRInstructionClass.create(AMD64PauseOp.class); + + public AMD64PauseOp() { + super(TYPE); + } + + @Override + public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler asm) { + asm.pause(); + } +} diff -r cc904fd7b454 -r 99b21d7f7ed6 graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCPauseOp.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCPauseOp.java Mon Nov 30 16:24:57 2015 -0800 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012, 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.lir.sparc; + +import com.oracle.graal.asm.sparc.SPARCMacroAssembler; +import com.oracle.graal.lir.LIRInstructionClass; +import com.oracle.graal.lir.Opcode; +import com.oracle.graal.lir.asm.CompilationResultBuilder; + +/** + * Emits a pause. + */ +@Opcode("PAUSE") +public final class SPARCPauseOp extends SPARCLIRInstruction { + public static final LIRInstructionClass TYPE = LIRInstructionClass.create(SPARCPauseOp.class); + public static final SizeEstimate SIZE = SizeEstimate.create(1); + + public SPARCPauseOp() { + super(TYPE, SIZE); + } + + @Override + public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) { + masm.pause(); + } +} diff -r cc904fd7b454 -r 99b21d7f7ed6 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PauseNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PauseNode.java Mon Nov 30 16:24:57 2015 -0800 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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.nodes; + +import com.oracle.graal.compiler.common.type.StampFactory; +import com.oracle.graal.graph.NodeClass; +import com.oracle.graal.nodeinfo.NodeInfo; +import com.oracle.graal.nodes.spi.LIRLowerable; +import com.oracle.graal.nodes.spi.NodeLIRBuilderTool; + +/** A node that results in a platform dependent pause instruction being emitted. */ +@NodeInfo +public final class PauseNode extends FixedWithNextNode implements LIRLowerable { + + public static final NodeClass TYPE = NodeClass.create(PauseNode.class); + + public PauseNode() { + super(TYPE, StampFactory.forVoid()); + } + + @Override + public void generate(NodeLIRBuilderTool gen) { + gen.visitPauseNode(this); + } + + @NodeIntrinsic + public static native void pause(); +} diff -r cc904fd7b454 -r 99b21d7f7ed6 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/NodeLIRBuilderTool.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/NodeLIRBuilderTool.java Sat Nov 21 09:24:29 2015 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/NodeLIRBuilderTool.java Mon Nov 30 16:24:57 2015 -0800 @@ -44,6 +44,7 @@ import com.oracle.graal.nodes.IfNode; import com.oracle.graal.nodes.Invoke; import com.oracle.graal.nodes.LoopEndNode; +import com.oracle.graal.nodes.PauseNode; import com.oracle.graal.nodes.SafepointNode; import com.oracle.graal.nodes.StructuredGraph; import com.oracle.graal.nodes.ValueNode; @@ -77,6 +78,8 @@ void visitBreakpointNode(BreakpointNode i); + void visitPauseNode(PauseNode i); + void visitFullInfopointNode(FullInfopointNode i); void recordSimpleInfopoint(InfopointReason reason, BytecodePosition position);