From 21bc139de867a6f3c8db9a58a40557957acc1c93 Mon Sep 17 00:00:00 2001 From: Yudi Zheng Date: Mon, 9 Dec 2024 16:31:47 +0100 Subject: [PATCH 1/2] Adapt JDK-8339113: AccessFlags can be u2 in metadata --- .../hotspot/GraalHotSpotVMConfig.java | 4 +-- .../meta/HotSpotGraphBuilderPlugins.java | 6 +++- .../HotSpotInvocationPluginHelper.java | 29 +++++++++++++------ .../hotspot/replacements/MonitorSnippets.java | 2 +- .../RegisterFinalizerSnippets.java | 5 ++-- 5 files changed, 31 insertions(+), 15 deletions(-) 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 303634396d64..04c0e66d9534 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"); @@ -277,7 +277,7 @@ public final int arrayOopDescLengthOffset() { public final int arrayClassElementOffset = getFieldOffset("ObjArrayKlass::_element_klass", Integer.class, "Klass*"); - public final int jvmAccWrittenFlags = getConstant("JVM_ACC_WRITTEN_FLAGS", Integer.class); + public final int jvmAccWrittenFlags = getConstant("JVM_ACC_WRITTEN_FLAGS", Integer.class, -1, JDK == 21); public final int jvmAccIsHiddenClass = JDK >= 24 ? getConstant("KlassFlags::_misc_is_hidden_class", Integer.class) : getConstant("JVM_ACC_IS_HIDDEN_CLASS", Integer.class); public final int jvmAccIsValueBasedClass = JDK >= 24 ? getConstant("KlassFlags::_misc_is_value_based_class", Integer.class) : getConstant("JVM_ACC_IS_VALUE_BASED_CLASS", Integer.class); public final int jvmAccHasFinalizer = JDK >= 24 ? getConstant("KlassFlags::_misc_has_finalizer", Integer.class) : getConstant("JVM_ACC_HAS_FINALIZER", Integer.class); diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java index 7946b2260ddc..19b7b7141a6f 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java @@ -498,7 +498,11 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec ValueNode klassNonNull = helper.emitNullReturnGuard(klass, ConstantNode.forInt(Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC), GraalDirectives.UNLIKELY_PROBABILITY); // Return (Klass::_access_flags & jvmAccWrittenFlags) ValueNode accessFlags = helper.readKlassAccessFlags(klassNonNull); - helper.emitFinalReturn(JavaKind.Int, new AndNode(accessFlags, ConstantNode.forInt(config.jvmAccWrittenFlags))); + if (JavaVersionUtil.JAVA_SPEC == 21) { + helper.emitFinalReturn(JavaKind.Int, new AndNode(accessFlags, ConstantNode.forInt(config.jvmAccWrittenFlags))); + } else { + helper.emitFinalReturn(JavaKind.Int, accessFlags); + } } return true; } 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 c09135552928..0f684996b3f7 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 @@ -241,7 +241,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) { From 2cd4529f77039f05a49cd02d695997db61503bb0 Mon Sep 17 00:00:00 2001 From: Yudi Zheng Date: Wed, 18 Dec 2024 10:22:57 +0100 Subject: [PATCH 2/2] Update galahad jdk. --- common.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.json b/common.json index 3e4d76abaf7e..8d575ed6cfb9 100644 --- a/common.json +++ b/common.json @@ -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+2-128", "platformspecific": true, "extrabundles": ["static-libs"]}, + "galahad-jdk": {"name": "jpg-jdk", "version": "25", "build_id": "2024-12-18-0917387.yudi.zheng.jdk", "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 },