Skip to content

Commit

Permalink
Adapt JDK-8339113: AccessFlags can be u2 in metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
mur47x111 committed Dec 11, 2024
1 parent d4f3e6c commit a4893ca
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public final int logMinObjAlignment() {
public final int classMirrorOffset = getFieldOffset("Klass::_java_mirror", Integer.class, "OopHandle");

public final int klassSuperKlassOffset = getFieldOffset("Klass::_super", Integer.class, "Klass*");
public final int klassModifierFlagsOffset = getFieldOffset("Klass::_modifier_flags", Integer.class, "jint");
public final int klassModifierFlagsOffset = getFieldOffset("Klass::_modifier_flags", Integer.class, JDK == 21? "jint" : "u2");
public final int klassAccessFlagsOffset = getFieldOffset("Klass::_access_flags", Integer.class, "AccessFlags");
public final int klassMiscFlagsOffset = getFieldOffset("Klass::_misc_flags._flags", Integer.class, "u1", 0, JDK >= 24);
public final int klassLayoutHelperOffset = getFieldOffset("Klass::_layout_helper", Integer.class, "jint");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@
import jdk.graal.compiler.nodes.PiNode;
import jdk.graal.compiler.nodes.ValueNode;
import jdk.graal.compiler.nodes.calc.IsNullNode;
import jdk.graal.compiler.nodes.calc.ZeroExtendNode;
import jdk.graal.compiler.nodes.extended.GuardingNode;
import jdk.graal.compiler.nodes.gc.BarrierSet;
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext;
import jdk.graal.compiler.nodes.memory.ReadNode;
import jdk.graal.compiler.nodes.memory.address.AddressNode;
import jdk.graal.compiler.nodes.type.StampTool;
import jdk.graal.compiler.replacements.InvocationPluginHelper;
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;
Expand Down Expand Up @@ -115,7 +117,10 @@ private ValueNode readLocation(ValueNode base, int offset, LocationIdentity loca
* An abstraction for fields of {@link GraalHotSpotVMConfig}.
*/
enum HotSpotVMConfigField {
KLASS_MODIFIER_FLAGS_OFFSET(config -> config.klassModifierFlagsOffset, KLASS_MODIFIER_FLAGS_LOCATION, StampFactory.forKind(JavaKind.Int)),
KLASS_MODIFIER_FLAGS_OFFSET(
config -> config.klassModifierFlagsOffset,
KLASS_MODIFIER_FLAGS_LOCATION,
JavaVersionUtil.JAVA_SPEC == 21 ? StampFactory.forKind(JavaKind.Int) : StampFactory.forInteger(JavaKind.Char.getBitCount())),
KLASS_SUPER_KLASS_OFFSET(config -> config.klassSuperKlassOffset, KLASS_SUPER_KLASS_LOCATION, KlassPointerStamp.klass()),
CLASS_ARRAY_KLASS_OFFSET(config -> config.arrayKlassOffset, CLASS_ARRAY_KLASS_LOCATION, KlassPointerStamp.klassNonNull()),
JAVA_THREAD_OSTHREAD_OFFSET(config -> config.osThreadOffset, JAVA_THREAD_OSTHREAD_LOCATION),
Expand All @@ -124,8 +129,14 @@ enum HotSpotVMConfigField {
/** JavaThread::_threadObj. */
JAVA_THREAD_CARRIER_THREAD_OBJECT(config -> config.threadCarrierThreadObjectOffset, JAVA_THREAD_CARRIER_THREAD_OBJECT_LOCATION, null),
JAVA_THREAD_SCOPED_VALUE_CACHE_OFFSET(config -> config.threadScopedValueCacheOffset, JAVA_THREAD_SCOPED_VALUE_CACHE_LOCATION, null),
KLASS_ACCESS_FLAGS_OFFSET(config -> config.klassAccessFlagsOffset, KLASS_ACCESS_FLAGS_LOCATION, StampFactory.forKind(JavaKind.Int)),
KLASS_MISC_FLAGS_OFFSET(config -> config.klassMiscFlagsOffset, KLASS_MISC_FLAGS_LOCATION, StampFactory.forKind(JavaKind.Int)),
KLASS_ACCESS_FLAGS_OFFSET(
config -> config.klassAccessFlagsOffset,
KLASS_ACCESS_FLAGS_LOCATION,
JavaVersionUtil.JAVA_SPEC == 21 ? StampFactory.forKind(JavaKind.Int) : StampFactory.forInteger(JavaKind.Char.getBitCount())),
KLASS_MISC_FLAGS_OFFSET(
config -> config.klassMiscFlagsOffset,
KLASS_MISC_FLAGS_LOCATION,
JavaVersionUtil.JAVA_SPEC == 21 ? StampFactory.forKind(JavaKind.Int) : StampFactory.forInteger(JavaKind.Byte.getBitCount())),
HOTSPOT_OOP_HANDLE_VALUE(config -> 0, HOTSPOT_OOP_HANDLE_LOCATION, StampFactory.forKind(JavaKind.Object));

private final Function<GraalHotSpotVMConfig, Integer> getter;
Expand Down Expand Up @@ -162,24 +173,24 @@ public Stamp getStamp(JavaKind wordKind) {
}

/**
* Read {@code Klass::_modifier_flags}.
* Read {@code Klass::_modifier_flags} as int.
*/
public ValueNode readKlassModifierFlags(ValueNode klass) {
return readLocation(klass, HotSpotVMConfigField.KLASS_MODIFIER_FLAGS_OFFSET);
return ZeroExtendNode.create(readLocation(klass, HotSpotVMConfigField.KLASS_MODIFIER_FLAGS_OFFSET), JavaKind.Int.getBitCount(), NodeView.DEFAULT);
}

/**
* Read {@code Klass::_access_flags}.
* Read {@code Klass::_access_flags} as int.
*/
public ValueNode readKlassAccessFlags(ValueNode klass) {
return readLocation(klass, HotSpotVMConfigField.KLASS_ACCESS_FLAGS_OFFSET);
return ZeroExtendNode.create(readLocation(klass, HotSpotVMConfigField.KLASS_ACCESS_FLAGS_OFFSET), JavaKind.Int.getBitCount(), NodeView.DEFAULT);
}

/**
* Read {@code Klass::_misc_flags}.
* Read {@code Klass::_misc_flags} as int.
*/
public ValueNode readKlassMiscFlags(ValueNode klass) {
return readLocation(klass, HotSpotVMConfigField.KLASS_MISC_FLAGS_OFFSET);
return ZeroExtendNode.create(readLocation(klass, HotSpotVMConfigField.KLASS_MISC_FLAGS_OFFSET), JavaKind.Int.getBitCount(), NodeView.DEFAULT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public static void monitorenter(Object object, KlassPointer hub, @ConstantParame
incCounter();

if (diagnoseSyncOnValueBasedClasses(INJECTED_VMCONFIG)) {
int flags = shouldUseKlassMiscFlags() ? hub.readInt(klassMiscFlagsOffset(INJECTED_VMCONFIG), KLASS_MISC_FLAGS_LOCATION)
int flags = shouldUseKlassMiscFlags() ? hub.readByte(klassMiscFlagsOffset(INJECTED_VMCONFIG), KLASS_MISC_FLAGS_LOCATION)
: hub.readInt(klassAccessFlagsOffset(INJECTED_VMCONFIG), KLASS_ACCESS_FLAGS_LOCATION);
if (probability(SLOW_PATH_PROBABILITY, (flags & jvmAccIsValueBasedClass(INJECTED_VMCONFIG)) != 0)) {
monitorenterStubC(MONITORENTER, object, lock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class RegisterFinalizerSnippets implements Snippets {
public static void registerFinalizerSnippet(final Object thisObj) {
KlassPointer klass = HotSpotReplacementsUtil.loadHub(thisObj);

int flags = shouldUseKlassMiscFlags() ? klass.readInt(klassMiscFlagsOffset(INJECTED_VMCONFIG), KLASS_MISC_FLAGS_LOCATION)
int flags = shouldUseKlassMiscFlags() ? klass.readByte(klassMiscFlagsOffset(INJECTED_VMCONFIG), KLASS_MISC_FLAGS_LOCATION)
: klass.readInt(klassAccessFlagsOffset(INJECTED_VMCONFIG), KLASS_ACCESS_FLAGS_LOCATION);
if (probability(SLOW_PATH_PROBABILITY, (flags & jvmAccHasFinalizer(INJECTED_VMCONFIG)) != 0)) {
LoweredRegisterFinalizerNode.registerFinalizer(thisObj);
Expand All @@ -76,7 +76,8 @@ public static class Templates extends AbstractTemplates {
public Templates(OptionValues options, HotSpotProviders providers) {
super(options, providers);

this.registerFinalizerSnippet = snippet(providers, RegisterFinalizerSnippets.class, "registerFinalizerSnippet", KLASS_ACCESS_FLAGS_LOCATION);
this.registerFinalizerSnippet = snippet(providers, RegisterFinalizerSnippets.class, "registerFinalizerSnippet",
shouldUseKlassMiscFlags() ? KLASS_MISC_FLAGS_LOCATION : KLASS_ACCESS_FLAGS_LOCATION);
}

public void lower(RegisterFinalizerNode node, LoweringTool tool) {
Expand Down

0 comments on commit a4893ca

Please sign in to comment.