diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/GraalHotSpotVMConfig.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/GraalHotSpotVMConfig.java index 555baf10282e..835e4d384aa5 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/GraalHotSpotVMConfig.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/GraalHotSpotVMConfig.java @@ -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"); diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replacements/HotSpotInvocationPluginHelper.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replacements/HotSpotInvocationPluginHelper.java index d3c964bc6e88..68ce6d5bf205 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replacements/HotSpotInvocationPluginHelper.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replacements/HotSpotInvocationPluginHelper.java @@ -52,6 +52,7 @@ 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; @@ -59,6 +60,7 @@ 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; @@ -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), @@ -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 getter; @@ -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); } /** diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replacements/MonitorSnippets.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replacements/MonitorSnippets.java index c4c47022b2ab..a3fef028ea61 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replacements/MonitorSnippets.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replacements/MonitorSnippets.java @@ -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); diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replacements/RegisterFinalizerSnippets.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replacements/RegisterFinalizerSnippets.java index 60d7505caac1..e77b64cbb6ca 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replacements/RegisterFinalizerSnippets.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replacements/RegisterFinalizerSnippets.java @@ -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); @@ -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) {