Skip to content

Commit

Permalink
Merge tag 'vm-23.1.3' into mandrel-23.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jerboaa committed May 2, 2024
2 parents 6812ec7 + dda64b4 commit 76bc4f8
Show file tree
Hide file tree
Showing 488 changed files with 643 additions and 64,096 deletions.
4 changes: 2 additions & 2 deletions compiler/mx.compiler/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"sourceinprojectwhitelist" : [],

"groupId" : "org.graalvm.compiler",
"version" : "23.1.3.0",
"release" : True,
"version" : "23.1.3.1",
"release" : False,
"url" : "http://www.graalvm.org/",
"developer" : {
"name" : "GraalVM Development",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5097,6 +5097,18 @@ public void clflush(AMD64Address adr) {
emitOperandHelper(7, adr, 0);
}

public void wrpkru() {
emitByte(0x0F);
emitByte(0x01);
emitByte(0xEF);
}

public void rdpkru() {
emitByte(0x0F);
emitByte(0x01);
emitByte(0xEE);
}

public final void vpaddd(Register dst, Register nds, Register src, AVXSize size) {
VexRVMOp.VPADDD.emit(this, size, dst, nds, src);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,20 @@ public void emitSpeculationFence() {
append(new AMD64LFenceOp());
}

@Override
public void emitProtectionKeyRegisterWrite(Value value) {
RegisterValue rax = AMD64.rax.asValue(value.getValueKind());
emitMove(rax, value);
append(new AMD64WriteDataToUserPageKeyRegister(rax));
}

@Override
public Value emitProtectionKeyRegisterRead() {
AMD64ReadDataFromUserPageKeyRegister rdpkru = new AMD64ReadDataFromUserPageKeyRegister();
append(rdpkru);
return emitReadRegister(AMD64.rax, rdpkru.retVal.getValueKind());
}

@Override
public void emitZeroMemory(Value address, Value length, boolean isAligned) {
RegisterValue lengthReg = AMD64.rcx.asValue(length.getValueKind());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2023, 2024, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 org.graalvm.compiler.core.amd64;

import jdk.vm.ci.amd64.AMD64;
import jdk.vm.ci.amd64.AMD64Kind;
import jdk.vm.ci.code.ValueUtil;
import jdk.vm.ci.meta.AllocatableValue;
import jdk.vm.ci.meta.Value;
import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler;
import org.graalvm.compiler.core.common.LIRKind;
import org.graalvm.compiler.lir.LIRInstructionClass;
import org.graalvm.compiler.lir.Opcode;
import org.graalvm.compiler.lir.amd64.AMD64LIRInstruction;
import org.graalvm.compiler.lir.asm.CompilationResultBuilder;

import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;

/**
* Reads the value of PKRU into EAX and clears EDX. ECX must be 0 when RDPKRU is executed;
* otherwise, a general-protection exception (#GP) occurs. RDPKRU can be executed only if CR4.PKE =
* 1; otherwise, an invalid-opcode exception (#UD) occurs. Software can discover the value of
* CR4.PKE by examining CPUID.(EAX=07H,ECX=0H):ECX.OSPKE [bit 4]. On processors that support the
* Intel 64 Architecture, the high-order 32-bits of RCX are ignored and the high-order 32-bits of
* RDX and RAX are cleared.
*/
@Opcode("RDPKRU")
public class AMD64ReadDataFromUserPageKeyRegister extends AMD64LIRInstruction {
public static final LIRInstructionClass<AMD64ReadDataFromUserPageKeyRegister> TYPE = LIRInstructionClass.create(AMD64ReadDataFromUserPageKeyRegister.class);

// the result of the rdpkru is in eax
@Def protected Value retVal;

// edx will be cleared
@Temp({REG}) protected AllocatableValue edx;

// ecx must be zero
@Temp({REG}) protected AllocatableValue zeroArg1;

public AMD64ReadDataFromUserPageKeyRegister() {
super(TYPE);
this.retVal = AMD64.rax.asValue(LIRKind.value(AMD64Kind.DWORD));
this.edx = AMD64.rdx.asValue(LIRKind.value(AMD64Kind.DWORD));
this.zeroArg1 = AMD64.rcx.asValue(LIRKind.value(AMD64Kind.DWORD));
}

@Override
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
masm.xorl(ValueUtil.asRegister(zeroArg1), ValueUtil.asRegister(zeroArg1));
masm.rdpkru();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2023, 2024, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 org.graalvm.compiler.core.amd64;

import jdk.vm.ci.amd64.AMD64;
import jdk.vm.ci.amd64.AMD64Kind;
import jdk.vm.ci.code.RegisterValue;
import jdk.vm.ci.code.ValueUtil;
import jdk.vm.ci.meta.AllocatableValue;
import jdk.vm.ci.meta.Value;
import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler;
import org.graalvm.compiler.core.common.LIRKind;
import org.graalvm.compiler.lir.LIRInstructionClass;
import org.graalvm.compiler.lir.Opcode;
import org.graalvm.compiler.lir.amd64.AMD64LIRInstruction;
import org.graalvm.compiler.lir.asm.CompilationResultBuilder;

import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;

/**
* Writes the value of EAX into PKRU. ECX and EDX must be 0 when WRPKRU is executed; otherwise, a
* general protection exception (#GP) occurs. WRPKRU can be executed only if CR4.PKE = 1; otherwise,
* an invalid-opcode exception (#UD) occurs. Software can discover the value of CR4.PKE by examining
* CPUID.(EAX=07H,ECX=0H):ECX.OSPKE [bit 4]. On processors that support the Intel 64 Architecture,
* the high-order 32-bits of RCX, RDX and RAX are ignored.
*/
@Opcode("WRPKRU")
public class AMD64WriteDataToUserPageKeyRegister extends AMD64LIRInstruction {
public static final LIRInstructionClass<AMD64WriteDataToUserPageKeyRegister> TYPE = LIRInstructionClass.create(AMD64WriteDataToUserPageKeyRegister.class);

// the argument to wrpkru is in eax
@Use protected Value arg;
// ecx and edx need to be zero
@Temp({REG}) protected AllocatableValue zeroArg1;
@Temp({REG}) protected AllocatableValue zeroArg2;

public AMD64WriteDataToUserPageKeyRegister(RegisterValue arg) {
super(TYPE);
assert arg.getRegister().equals(AMD64.rax);
this.arg = arg;
zeroArg1 = AMD64.rcx.asValue(LIRKind.value(AMD64Kind.DWORD));
zeroArg2 = AMD64.rdx.asValue(LIRKind.value(AMD64Kind.DWORD));
}

@Override
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
masm.xorl(ValueUtil.asRegister(zeroArg1), ValueUtil.asRegister(zeroArg1));
masm.xorl(ValueUtil.asRegister(zeroArg2), ValueUtil.asRegister(zeroArg2));
masm.wrpkru();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2023, 2024, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 org.graalvm.compiler.core.amd64;

import jdk.vm.ci.meta.Value;
import org.graalvm.compiler.core.common.type.IntegerStamp;
import org.graalvm.compiler.graph.NodeClass;
import org.graalvm.compiler.nodeinfo.NodeCycles;
import org.graalvm.compiler.nodeinfo.NodeInfo;
import org.graalvm.compiler.nodeinfo.NodeSize;
import org.graalvm.compiler.nodes.FixedWithNextNode;
import org.graalvm.compiler.nodes.spi.LIRLowerable;
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;

@NodeInfo(cycles = NodeCycles.CYCLES_1, size = NodeSize.SIZE_4)
public class ReadProtectionKeyRegisterNode extends FixedWithNextNode implements LIRLowerable {
public static final NodeClass<ReadProtectionKeyRegisterNode> TYPE = NodeClass.create(ReadProtectionKeyRegisterNode.class);

public ReadProtectionKeyRegisterNode() {
super(TYPE, IntegerStamp.create(32));
}

@Override
public void generate(NodeLIRBuilderTool gen) {
Value result = gen.getLIRGeneratorTool().emitProtectionKeyRegisterRead();
gen.setResult(this, result);
}

@NodeIntrinsic
public static native int readProtectionKeyRegister();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2023, 2024, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 org.graalvm.compiler.core.amd64;

import org.graalvm.compiler.core.common.type.StampFactory;
import org.graalvm.compiler.graph.NodeClass;
import org.graalvm.compiler.nodeinfo.NodeCycles;
import org.graalvm.compiler.nodeinfo.NodeInfo;
import org.graalvm.compiler.nodeinfo.NodeSize;
import org.graalvm.compiler.nodes.FixedWithNextNode;
import org.graalvm.compiler.nodes.ValueNode;
import org.graalvm.compiler.nodes.spi.LIRLowerable;
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
import org.graalvm.word.WordBase;

@NodeInfo(cycles = NodeCycles.CYCLES_16, size = NodeSize.SIZE_4)
public class WriteProtectionKeyRegisterNode extends FixedWithNextNode implements LIRLowerable {
public static final NodeClass<WriteProtectionKeyRegisterNode> TYPE = NodeClass.create(WriteProtectionKeyRegisterNode.class);

@Input protected ValueNode value;

public WriteProtectionKeyRegisterNode(ValueNode value) {
super(TYPE, StampFactory.forVoid());
this.value = value;
}

@Override
public void generate(NodeLIRBuilderTool gen) {
gen.getLIRGeneratorTool().emitProtectionKeyRegisterWrite(gen.operand(value));
}

@NodeIntrinsic
public static native void writeProtectionKeyRegister(WordBase value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ private static ValueNode signExtend(ValueNode input, LoopEx loop) {
if (init >= 0 && extremum >= 0) {
long shortestTrip = (extremum - init) / stride + 1;
if (countedLoopInfo.constantMaxTripCount().equals(shortestTrip)) {
return graph.unique(new ZeroExtendNode(input, INT_BITS, ADDRESS_BITS, true));
return graph.unique(new ZeroExtendNode(input, INT_BITS, ADDRESS_BITS, false));
}
}
}
if (countedLoopInfo.getLimitCheckedIV() == inductionVariable &&
inductionVariable.direction() == InductionVariable.Direction.Up &&
(countedLoopInfo.getOverFlowGuard() != null || countedLoopInfo.counterNeverOverflows())) {
return graph.unique(new ZeroExtendNode(input, INT_BITS, ADDRESS_BITS, true));
return graph.unique(new ZeroExtendNode(input, INT_BITS, ADDRESS_BITS, false));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,24 @@ default void emitConvertZeroToNull(AllocatableValue result, Value input) {
*/
void emitSpeculationFence();

/**
* Write value to the protection key register.
*
* @param value to be written
*/
default void emitProtectionKeyRegisterWrite(Value value) {
throw new GraalError("Emitting code to write a value to the protection key register is not currently supported on %s", target().arch);
}

/**
* Read contents of the protection key register.
*
* @return value read from the register
*/
default Value emitProtectionKeyRegisterRead() {
throw new GraalError("Emitting code to read the contents of the protection key register is not currently supported on %s", target().arch);
}

default VirtualStackSlot allocateStackMemory(int sizeInBytes, int alignmentInBytes) {
return getResult().getFrameMapBuilder().allocateStackMemory(sizeInBytes, alignmentInBytes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ protected void run(StructuredGraph graph, MidTierContext context) {
final InductionVariable counter = counted.getLimitCheckedIV();
final Condition condition = ((CompareNode) counted.getLimitTest().condition()).condition().asCondition();
final boolean inverted = loop.counted().isInverted();
if ((((IntegerStamp) counter.valueNode().stamp(NodeView.DEFAULT)).getBits() == 32) &&
!counted.isUnsignedCheck() &&
((condition != NE && condition != EQ) || (counter.isConstantStride() && Math.abs(counter.constantStride()) == 1)) &&
if ((((IntegerStamp) counter.valueNode().stamp(NodeView.DEFAULT)).getBits() == 32) && !counted.isUnsignedCheck() &&
((condition != NE && condition != EQ) || (counter.isConstantStride() && LoopEx.absStrideIsOne(counter))) &&
(loop.loopBegin().isMainLoop() || loop.loopBegin().isSimpleLoop())) {
NodeIterable<GuardNode> guards = loop.whole().nodes().filter(GuardNode.class);
if (LoopPredicationMainPath.getValue(graph.getOptions())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static ValueNode canonical(SignExtendNode self, ValueNode forValue, int
if ((inputStamp.mayBeSet() & (1L << (inputBits - 1))) == 0L) {
// 0xxx -(sign-extend)-> 0000 0xxx
// ==> 0xxx -(zero-extend)-> 0000 0xxx
return ZeroExtendNode.create(forValue, inputBits, resultBits, view, true);
return ZeroExtendNode.create(forValue, inputBits, resultBits, view, false);
}
}
if (forValue instanceof NarrowNode) {
Expand Down
Loading

0 comments on commit 76bc4f8

Please sign in to comment.