Skip to content

[JDK-8348174] Adapt JDK-8334717: Add JVMCI support for APX EGPRs #11223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

"COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet",
"jdks": {
"galahad-jdk": {"name": "jpg-jdk", "version": "25", "build_id": "jdk-25+23-2725", "platformspecific": true, "extrabundles": ["static-libs"]},
"galahad-jdk": {"name": "jpg-jdk", "version": "25", "build_id": "jdk-25+24-2946", "platformspecific": true, "extrabundles": ["static-libs"]},

"oraclejdk17": {"name": "jpg-jdk", "version": "17.0.7", "build_id": "jdk-17.0.7+8", "platformspecific": true, "extrabundles": ["static-libs"]},
"labsjdk-ce-17": {"name": "labsjdk", "version": "ce-17.0.7+4-jvmci-23.1-b02", "platformspecific": true },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2025, 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
Expand Down Expand Up @@ -29,16 +29,16 @@

import java.util.EnumSet;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import jdk.graal.compiler.asm.aarch64.AArch64Address;
import jdk.graal.compiler.asm.aarch64.AArch64Assembler;
import jdk.graal.compiler.asm.aarch64.AArch64MacroAssembler;
import jdk.graal.compiler.core.aarch64.test.AArch64TestMacroAssembler;
import jdk.graal.compiler.core.common.NumUtil;
import jdk.graal.compiler.test.GraalTest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import jdk.vm.ci.aarch64.AArch64;
import jdk.vm.ci.aarch64.AArch64.CPUFeature;
import jdk.vm.ci.code.Architecture;
Expand All @@ -59,16 +59,11 @@ private static EnumSet<AArch64.CPUFeature> computeFeatures() {
return features;
}

private static EnumSet<AArch64.Flag> computeFlags() {
EnumSet<AArch64.Flag> flags = EnumSet.noneOf(AArch64.Flag.class);
return flags;
}

private static TargetDescription createTarget() {
final int stackFrameAlignment = 16;
final int implicitNullCheckLimit = 4096;
final boolean inlineObjects = true;
Architecture arch = new AArch64(computeFeatures(), computeFlags());
Architecture arch = new AArch64(computeFeatures());
return new TargetDescription(arch, true, stackFrameAlignment, implicitNullCheckLimit, inlineObjects);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
*/
package jdk.graal.compiler.core.test.ea;

import java.lang.ref.WeakReference;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -66,15 +66,15 @@ private static final class AllocatedObject {
public static String moveIntoBranchBox(int id) {
Double box = object1 + 1;
if (id == 0) {
obj1 = new WeakReference<>(box);
obj1 = new AtomicReference<>(box);
}
return "value";
}

public static String moveIntoBranch(int id) {
AllocatedObject box = new AllocatedObject(object2.value + 1);
if (id == 0) {
obj1 = new WeakReference<>(box);
obj1 = new AtomicReference<>(box);
}
return "value";
}
Expand Down Expand Up @@ -104,7 +104,7 @@ public static String noLoopIterationBox(int id) {
Double box = object1 + 1;
for (int i = 0; i < 100; i++) {
if (id == i) {
obj1 = new WeakReference<>(box);
obj1 = new AtomicReference<>(box);
}
}
return "value";
Expand All @@ -114,7 +114,7 @@ public static String noLoopIteration(int id) {
AllocatedObject box = new AllocatedObject(object2.value + 1);
for (int i = 0; i < 100; i++) {
if (id == i) {
obj1 = new WeakReference<>(box);
obj1 = new AtomicReference<>(box);
}
}
return "value";
Expand All @@ -124,7 +124,7 @@ public static String noLoopIterationEmpty(int id) {
AllocatedObject box = new AllocatedObject();
for (int i = 0; i < 100; i++) {
if (id == i) {
obj1 = new WeakReference<>(box);
obj1 = new AtomicReference<>(box);
}
}
return "value";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2025, 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
Expand Down Expand Up @@ -28,16 +28,14 @@

import java.util.Arrays;

import jdk.graal.compiler.core.test.GraalCompilerTest;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

import jdk.graal.compiler.asm.amd64.AMD64Assembler;

import jdk.graal.compiler.core.test.GraalCompilerTest;
import jdk.vm.ci.code.InstalledCode;
import jdk.vm.ci.code.Register;
import jdk.vm.ci.code.RegisterArray;
import jdk.vm.ci.code.TargetDescription;
import jdk.vm.ci.hotspot.HotSpotCallingConventionType;
import jdk.vm.ci.meta.JavaKind;
Expand Down Expand Up @@ -128,7 +126,6 @@ private void testHelper(String name, CodeGenerator gen) {
}

private Register getArgumentRegister(int index, JavaKind kind) {
RegisterArray regs = getCodeCache().getRegisterConfig().getCallingConventionRegisters(HotSpotCallingConventionType.JavaCall, kind);
return regs.get(index);
return getCodeCache().getRegisterConfig().getCallingConventionRegisters(HotSpotCallingConventionType.JavaCall, kind).get(index);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2025, 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
Expand Down Expand Up @@ -69,19 +69,16 @@ public int getAsInt() {
}

private static class CompilationFinalWeakReferenceTestNode extends AbstractTestNode {
@CompilationFinal private WeakReference<Integer> finalWeakRefInteger;
@CompilationFinal private WeakReference<Object> finalWeakRefNull;
@CompilationFinal private WeakReference<IntSupplier> finalWeakRef;

CompilationFinalWeakReferenceTestNode(IntSupplier data) {
this.finalWeakRefInteger = new WeakReference<>(0);
this.finalWeakRefNull = new WeakReference<>(null);
this.finalWeakRef = new WeakReference<>(data);
}

@Override
public int execute(VirtualFrame frame) {
partialEvaluationConstantAndEquals(finalWeakRefInteger.get(), Integer.valueOf(0));
partialEvaluationConstantAndEquals(finalWeakRefNull.get(), null);

IntSupplier supplier = finalWeakRef.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ private enum OpAssertion {
}

protected boolean checkOperands(AMD64Op op, OperandSize size, Register resultReg, Register inputReg) {
assert resultReg == null || resultCategory.equals(resultReg.getRegisterCategory()) : "invalid result register " + resultReg + " used in " + op;
assert inputReg == null || inputCategory.equals(inputReg.getRegisterCategory()) : "invalid input register " + inputReg + " used in " + op;
GraalError.guarantee(resultReg == null || resultCategory.equals(resultReg.getRegisterCategory()), "invalid result register %s used in %s ", resultReg, op);
GraalError.guarantee(inputReg == null || inputCategory.equals(inputReg.getRegisterCategory()), "invalid input register %s used in %s ", inputReg, op);
GraalError.guarantee(resultReg == null || !inRC(CPU, resultReg) || (resultReg.encoding < 16), "APX register %s used in %s is not yet supported", resultReg, op);
GraalError.guarantee(inputReg == null || !inRC(CPU, inputReg) || (inputReg.encoding < 16), "APX register %s used in %s is not yet supported", inputReg, op);

for (OperandSize s : allowedSizes) {
if (size == s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,9 @@ protected static int getRXB(Register reg, Register rm) {
* There is an SIB byte: In that case, X extends SIB.index and B extends SIB.base.
*/
protected static int getRXB(Register reg, AMD64Address rm) {
assert !isInvalidEncoding(reg);
GraalError.guarantee(!isInvalidEncoding(reg), "invalid encoding %s", reg);
GraalError.guarantee(rm.getBase() == null || rm.getBase().encoding < 16, "APX register used in %s not yet supported", rm);
GraalError.guarantee(rm.getIndex() == null || rm.getIndex().encoding < 16, "APX register used in %s not yet supported", rm);
int rxb = (reg == null ? 0 : reg.encoding & 0x08) >> 1;
if (!isInvalidEncoding(rm.getIndex())) {
rxb |= (rm.getIndex().encoding & 0x08) >> 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, 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
Expand All @@ -25,6 +25,7 @@
package jdk.graal.compiler.core.common.alloc;

import java.util.Arrays;
import java.util.List;

import org.graalvm.collections.EconomicMap;
import org.graalvm.collections.Equivalence;
Expand All @@ -33,7 +34,6 @@
import jdk.graal.compiler.debug.Assertions;
import jdk.vm.ci.code.Register;
import jdk.vm.ci.code.Register.RegisterCategory;
import jdk.vm.ci.code.RegisterArray;
import jdk.vm.ci.code.RegisterConfig;
import jdk.vm.ci.meta.PlatformKind;

Expand All @@ -44,18 +44,18 @@
public class RegisterAllocationConfig {

public static final class AllocatableRegisters {
public final Register[] allocatableRegisters;
public final List<Register> allocatableRegisters;
public final int minRegisterNumber;
public final int maxRegisterNumber;

public AllocatableRegisters(RegisterArray allocatableRegisters, int minRegisterNumber, int maxRegisterNumber) {
this.allocatableRegisters = allocatableRegisters.toArray();
public AllocatableRegisters(List<Register> allocatableRegisters, int minRegisterNumber, int maxRegisterNumber) {
this.allocatableRegisters = allocatableRegisters;
this.minRegisterNumber = minRegisterNumber;
this.maxRegisterNumber = maxRegisterNumber;
assert verify(allocatableRegisters, minRegisterNumber, maxRegisterNumber);
}

private static boolean verify(RegisterArray allocatableRegisters, int minRegisterNumber, int maxRegisterNumber) {
private static boolean verify(List<Register> allocatableRegisters, int minRegisterNumber, int maxRegisterNumber) {
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for (Register reg : allocatableRegisters) {
Expand All @@ -79,7 +79,7 @@ private static boolean verify(RegisterArray allocatableRegisters, int minRegiste
* after the register name in the {@code spec}. In this case, {@code null} is returned instead
* of throwing an exception.
*/
private static Register findRegister(String spec, RegisterArray all) {
private static Register findRegister(String spec, List<Register> all) {
boolean optional = false;
String name = spec;
if (spec.endsWith("?")) {
Expand All @@ -97,7 +97,7 @@ private static Register findRegister(String spec, RegisterArray all) {
throw new IllegalArgumentException("register " + name + " is not allocatable");
}

protected RegisterArray initAllocatable(RegisterArray registers) {
protected List<Register> initAllocatable(List<Register> registers) {
if (allocationRestrictedTo != null) {
Register[] regs = new Register[allocationRestrictedTo.length];
int i = 0;
Expand All @@ -109,7 +109,7 @@ protected RegisterArray initAllocatable(RegisterArray registers) {
regs[i++] = register;
}
}
return new RegisterArray(regs);
return List.of(regs);
}

return registers;
Expand All @@ -118,7 +118,7 @@ protected RegisterArray initAllocatable(RegisterArray registers) {
protected final RegisterConfig registerConfig;
private final EconomicMap<PlatformKind.Key, AllocatableRegisters> categorized = EconomicMap.create(Equivalence.DEFAULT);
private final String[] allocationRestrictedTo;
private RegisterArray cachedRegisters;
private List<Register> cachedRegisters;

/**
* @param allocationRestrictedTo if not {@code null}, register allocation will be restricted to
Expand Down Expand Up @@ -153,10 +153,10 @@ public AllocatableRegisters getAllocatableRegisters(PlatformKind kind) {
* @return {@code null} if there are no allocatable registers for the given kind
*/
public RegisterCategory getRegisterCategory(PlatformKind kind) {
return getAllocatableRegisters(kind).allocatableRegisters[0].getRegisterCategory();
return getAllocatableRegisters(kind).allocatableRegisters.get(0).getRegisterCategory();
}

private static AllocatableRegisters createAllocatableRegisters(RegisterArray registers) {
private static AllocatableRegisters createAllocatableRegisters(List<Register> registers) {
if (registers.size() == 0) {
return null;
}
Expand All @@ -177,7 +177,7 @@ private static AllocatableRegisters createAllocatableRegisters(RegisterArray reg
/**
* Gets the set of registers that can be used by the register allocator.
*/
public RegisterArray getAllocatableRegisters() {
public List<Register> getAllocatableRegisters() {
if (cachedRegisters == null) {
cachedRegisters = initAllocatable(registerConfig.getAllocatableRegisters());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2025, 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
Expand Down Expand Up @@ -27,10 +27,10 @@
import java.util.BitSet;
import java.util.List;

import jdk.graal.compiler.core.common.LibGraalSupport;
import org.graalvm.collections.EconomicMap;
import org.graalvm.collections.EconomicSet;

import jdk.graal.compiler.core.common.LibGraalSupport;
import jdk.graal.compiler.core.common.spi.ForeignCallDescriptor.CallSideEffect;
import jdk.graal.compiler.core.common.spi.ForeignCallLinkage;
import jdk.graal.compiler.core.common.spi.ForeignCallSignature;
Expand All @@ -54,7 +54,6 @@
import jdk.graal.compiler.serviceprovider.GlobalAtomicLong;
import jdk.internal.misc.Unsafe;
import jdk.vm.ci.code.Register;
import jdk.vm.ci.code.RegisterArray;
import jdk.vm.ci.meta.InvokeTarget;

/**
Expand Down Expand Up @@ -290,7 +289,7 @@ enum RegisterEffect {
* @param killedRegisters see {@link Stub#getDestroyedCallerRegisters()}
*/
record CodeInfo(long start, EconomicSet<Register> killedRegisters) {
public static CodeInfo fromMemory(long memory, RegisterArray allRegisters) {
public static CodeInfo fromMemory(long memory, List<Register> allRegisters) {
Unsafe unsafe = Unsafe.getUnsafe();
// @formatter:off
int offset = 0;
Expand Down Expand Up @@ -361,7 +360,7 @@ static HotSpotForeignCallLinkageImpl.CodeInfo getCodeInfo(Stub stub, Backend bac
data.set(codeInfo.toMemory());
return codeInfo;
}
RegisterArray allRegisters = backend.getCodeCache().getTarget().arch.getRegisters();
List<Register> allRegisters = backend.getCodeCache().getTarget().arch.getRegisters();
return HotSpotForeignCallLinkageImpl.CodeInfo.fromMemory(codeInfoInMemory, allRegisters);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -147,7 +147,7 @@ protected HotSpotLoweringProvider createLowerer(HotSpotGraalRuntimeProvider graa

@Override
protected Value[] createNativeABICallerSaveRegisters(@SuppressWarnings("unused") GraalHotSpotVMConfig config, RegisterConfig regConfig) {
List<Register> callerSave = new ArrayList<>(regConfig.getAllocatableRegisters().asList());
List<Register> callerSave = new ArrayList<>(regConfig.getAllocatableRegisters());
// Removing callee-saved registers.
/* General Purpose Registers. */
callerSave.remove(AArch64.r19);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public Variable emitForeignCall(ForeignCallLinkage linkage, LIRFrameState state,
AArch64SaveRegistersOp save = null;
Stub stub = getStub();
if (destroysRegisters && stub != null && stub.getLinkage().getEffect() == HotSpotForeignCallLinkage.RegisterEffect.COMPUTES_REGISTERS_KILLED) {
Register[] savedRegisters = getRegisterConfig().getAllocatableRegisters().toArray();
Register[] savedRegisters = getRegisterConfig().getAllocatableRegisters().toArray(Register[]::new);
save = emitSaveAllRegisters(savedRegisters);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, 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
Expand Down Expand Up @@ -102,7 +102,7 @@ protected void emitPrologue(StructuredGraph graph) {
Stub stub = result.getStub();
if (stub != null && stub.getLinkage().getEffect() == HotSpotForeignCallLinkage.RegisterEffect.KILLS_NO_REGISTERS) {
assert stub.getLinkage().getDescriptor().getTransition() != HotSpotForeignCallDescriptor.Transition.SAFEPOINT : stub;
Register[] savedRegisters = getGen().getRegisterConfig().getAllocatableRegisters().toArray();
Register[] savedRegisters = getGen().getRegisterConfig().getAllocatableRegisters().toArray(Register[]::new);
AArch64SaveRegistersOp saveOp = getGen().emitSaveAllRegisters(savedRegisters);
result.setSaveOnEntry(saveOp);
}
Expand Down
Loading
Loading