Skip to content

Commit ec77126

Browse files
committed
[GR-35831] Intrinsify recursive ObjectMonitor locking.
PullRequest: graal/11147
2 parents 500dcd5 + 4f3b7d8 commit ec77126

File tree

6 files changed

+468
-1
lines changed

6 files changed

+468
-1
lines changed

compiler/src/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64/AMD64ArithmeticLIRGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ private Variable emitBinaryConst(LIRKind resultKind, AMD64BinaryArithmetic op, O
262262
}
263263
}
264264

265-
private static AMD64MOp getMOp(AMD64BinaryArithmetic op, int constant) {
265+
public static AMD64MOp getMOp(AMD64BinaryArithmetic op, int constant) {
266266
if (constant == 1) {
267267
if (op.equals(AMD64BinaryArithmetic.ADD)) {
268268
return AMD64MOp.INC;

compiler/src/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64/AMD64NodeMatchRules.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@
6262
import org.graalvm.compiler.lir.LIRValueUtil;
6363
import org.graalvm.compiler.lir.LabelRef;
6464
import org.graalvm.compiler.lir.amd64.AMD64AddressValue;
65+
import org.graalvm.compiler.lir.amd64.AMD64BinaryConsumer;
6566
import org.graalvm.compiler.lir.amd64.AMD64ControlFlow.TestBranchOp;
6667
import org.graalvm.compiler.lir.amd64.AMD64ControlFlow.TestConstBranchOp;
68+
import org.graalvm.compiler.lir.amd64.AMD64UnaryConsumer;
6769
import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
6870
import org.graalvm.compiler.nodes.ConstantNode;
6971
import org.graalvm.compiler.nodes.DeoptimizingNode;
@@ -83,6 +85,7 @@
8385
import org.graalvm.compiler.nodes.memory.AddressableMemoryAccess;
8486
import org.graalvm.compiler.nodes.memory.LIRLowerableAccess;
8587
import org.graalvm.compiler.nodes.memory.MemoryAccess;
88+
import org.graalvm.compiler.nodes.memory.ReadNode;
8689
import org.graalvm.compiler.nodes.memory.WriteNode;
8790
import org.graalvm.compiler.nodes.util.GraphUtil;
8891

@@ -577,6 +580,59 @@ public ComplexMatchResult xorMemory(ValueNode value, LIRLowerableAccess access)
577580
}
578581
}
579582

583+
private ComplexMatchResult emitMemoryConsumer(WriteNode write, AMD64Assembler.AMD64BinaryArithmetic arithmeticOp, ReadNode read, ValueNode value) {
584+
if (getMemoryKind(write).isInteger() && !write.canDeoptimize() && !read.canDeoptimize()) {
585+
OperandSize size = getMemorySize(write);
586+
if (write.getAddress() == read.getAddress()) {
587+
if (value.isJavaConstant()) {
588+
long valueCst = value.asJavaConstant().asLong();
589+
if (NumUtil.isInt(valueCst)) {
590+
AMD64Assembler.AMD64MOp mop = AMD64ArithmeticLIRGenerator.getMOp(arithmeticOp, (int) valueCst);
591+
if (mop != null) {
592+
return builder -> {
593+
AMD64AddressValue addressValue = (AMD64AddressValue) operand(write.getAddress());
594+
builder.append(new AMD64UnaryConsumer.MemoryOp(mop, size, addressValue));
595+
return null;
596+
};
597+
} else {
598+
return builder -> {
599+
AMD64AddressValue addressValue = (AMD64AddressValue) operand(write.getAddress());
600+
builder.append(new AMD64BinaryConsumer.MemoryConstOp(arithmeticOp.getMIOpcode(size, NumUtil.isByte(valueCst)), size, addressValue, (int) valueCst, state(write)));
601+
return null;
602+
};
603+
}
604+
}
605+
}
606+
return builder -> {
607+
AMD64AddressValue addressValue = (AMD64AddressValue) operand(write.getAddress());
608+
builder.append(new AMD64BinaryConsumer.MemoryMROp(arithmeticOp.getMROpcode(size), size, addressValue, builder.getLIRGeneratorTool().asAllocatable(operand(value)), state(write)));
609+
return null;
610+
};
611+
}
612+
}
613+
return null;
614+
}
615+
616+
@MatchRule("(Write=write object (Add Read=read value))")
617+
public ComplexMatchResult addToMemory(WriteNode write, ReadNode read, ValueNode value) {
618+
return emitMemoryConsumer(write, ADD, read, value);
619+
}
620+
621+
@MatchRule("(Write=write object (Sub Read=read value))")
622+
public ComplexMatchResult subToMemory(WriteNode write, ReadNode read, ValueNode value) {
623+
return emitMemoryConsumer(write, SUB, read, value);
624+
}
625+
626+
@MatchRule("(Write=write object (Or Read=read value))")
627+
public ComplexMatchResult orToMemory(WriteNode write, ReadNode read, ValueNode value) {
628+
return emitMemoryConsumer(write, OR, read, value);
629+
}
630+
631+
@MatchRule("(Write=write object (Xor Read=read value))")
632+
public ComplexMatchResult xorToMemory(WriteNode write, ReadNode read, ValueNode value) {
633+
return emitMemoryConsumer(write, XOR, read, value);
634+
}
635+
580636
@MatchRule("(Write object Narrow=narrow)")
581637
public ComplexMatchResult writeNarrow(WriteNode root, NarrowNode narrow) {
582638
return builder -> {

0 commit comments

Comments
 (0)