From feac5dc3ce9ca67cff24956c7f61c79113565426 Mon Sep 17 00:00:00 2001 From: Yudi Zheng Date: Mon, 4 Aug 2025 19:53:44 +0200 Subject: [PATCH 1/2] Adapt JDK-8343218: Add option to disable allocating interface and abstract classes in non-class metaspace --- .../HotSpotCompressedKlassPointerTest.java | 4 +- .../hotspot/GraalHotSpotVMConfig.java | 3 ++ .../hotspot/nodes/HotSpotCompressionNode.java | 19 +++----- .../graal/compiler/nodes/CompressionNode.java | 48 ++++++------------- 4 files changed, 26 insertions(+), 48 deletions(-) diff --git a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/HotSpotCompressedKlassPointerTest.java b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/HotSpotCompressedKlassPointerTest.java index 99984d3c4c8a..e12281fb22a8 100644 --- a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/HotSpotCompressedKlassPointerTest.java +++ b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/HotSpotCompressedKlassPointerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 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 @@ -40,7 +40,7 @@ public class HotSpotCompressedKlassPointerTest extends HotSpotGraalCompilerTest @Before public void setUp() { GraalHotSpotVMConfig config = runtime().getVMConfig(); - assumeTrue("compressed class pointers specific tests", config.useCompressedClassPointers); + assumeTrue("compressed class pointers specific tests", config.useCompressedClassPointers && !config.useClassMetaspaceForAllClasses); } // Non-abstract class 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 a3d323714cd0..7909fa1a0811 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 @@ -195,6 +195,9 @@ public long gcTotalCollectionsAddress() { // Compressed Oops related values. public final boolean useCompressedOops = getFlag("UseCompressedOops", Boolean.class); public final boolean useCompressedClassPointers = getFlag("UseCompressedClassPointers", Boolean.class); + + public final boolean useClassMetaspaceForAllClasses = getFlag("UseClassMetaspaceForAllClasses", Boolean.class); + // JDK-8305895 allows storing the compressed class pointer in the upper 22 bits of the mark // word. This runtime optimization is guarded by the flag UseCompactObjectHeaders. It depends // on compressed class pointers, meaning that if useCompactObjectHeaders is true, diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/nodes/HotSpotCompressionNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/nodes/HotSpotCompressionNode.java index 5cf32565dbff..2d020086757e 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/nodes/HotSpotCompressionNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/nodes/HotSpotCompressionNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -44,7 +44,6 @@ import jdk.vm.ci.meta.Constant; import jdk.vm.ci.meta.ConstantReflectionProvider; import jdk.vm.ci.meta.JavaConstant; -import jdk.vm.ci.meta.ResolvedJavaType; @NodeInfo(nameTemplate = "{p#op/s}", cycles = CYCLES_2, size = SIZE_2) public final class HotSpotCompressionNode extends CompressionNode { @@ -74,9 +73,7 @@ private static CompressionNode uncompress(ValueNode input, CompressEncoding enco @Override public boolean isCompressible(Constant constant) { if (constant instanceof HotSpotMetaspaceConstant mc) { - ResolvedJavaType type = mc.asResolvedJavaType(); - // As of JDK-8338526, interface and abstract types are not compressible. - return type.isArray() || (!type.isAbstract() && !type.isInterface()); + return mc.isCompressible(); } return true; } @@ -103,14 +100,10 @@ protected Constant uncompress(Constant c) { @Override public ValueNode reverse(ValueNode input) { - switch (op) { - case Compress: - return uncompress(input, encoding); - case Uncompress: - return compress(input, encoding); - default: - throw GraalError.shouldNotReachHereUnexpectedValue(op); // ExcludeFromJacocoGeneratedReport - } + return switch (op) { + case Compress -> uncompress(input, encoding); + case Uncompress -> compress(input, encoding); + }; } @Override diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/CompressionNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/CompressionNode.java index ed108c4c9686..d08b3be2e22e 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/CompressionNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/CompressionNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 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 @@ -30,7 +30,6 @@ import jdk.graal.compiler.core.common.CompressEncoding; import jdk.graal.compiler.core.common.type.AbstractObjectStamp; import jdk.graal.compiler.core.common.type.Stamp; -import jdk.graal.compiler.debug.GraalError; import jdk.graal.compiler.graph.NodeClass; import jdk.graal.compiler.lir.gen.LIRGeneratorTool; import jdk.graal.compiler.nodeinfo.NodeInfo; @@ -83,26 +82,18 @@ public JavaConstant nullConstant() { @Override public Constant convert(Constant c, ConstantReflectionProvider constantReflection) { - switch (op) { - case Compress: - return compress(c); - case Uncompress: - return uncompress(c); - default: - throw GraalError.shouldNotReachHereUnexpectedValue(op); // ExcludeFromJacocoGeneratedReport - } + return switch (op) { + case Compress -> compress(c); + case Uncompress -> uncompress(c); + }; } @Override public Constant reverse(Constant c, ConstantReflectionProvider constantReflection) { - switch (op) { - case Compress: - return uncompress(c); - case Uncompress: - return compress(c); - default: - throw GraalError.shouldNotReachHereUnexpectedValue(op); // ExcludeFromJacocoGeneratedReport - } + return switch (op) { + case Compress -> uncompress(c); + case Uncompress -> compress(c); + }; } /** @@ -138,14 +129,12 @@ public boolean isCompressible(Constant constant) { @Override public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { - if (forValue.isConstant()) { - ConstantNode constant = (ConstantNode) forValue; + if (forValue instanceof ConstantNode constant) { if (isCompressible(constant.getValue())) { return ConstantNode.forConstant(stamp(NodeView.DEFAULT), convert(constant.getValue(), tool.getConstantReflection()), constant.getStableDimension(), constant.isDefaultStable(), tool.getMetaAccess()); } - } else if (forValue instanceof CompressionNode) { - CompressionNode other = (CompressionNode) forValue; + } else if (forValue instanceof CompressionNode other) { if (op != other.op && encoding.equals(other.encoding)) { return other.getValue(); } @@ -164,17 +153,10 @@ public void generate(NodeLIRBuilderTool gen) { } LIRGeneratorTool tool = gen.getLIRGeneratorTool(); - Value result; - switch (op) { - case Compress: - result = tool.emitCompress(gen.operand(value), encoding, nonNull); - break; - case Uncompress: - result = tool.emitUncompress(gen.operand(value), encoding, nonNull); - break; - default: - throw GraalError.shouldNotReachHereUnexpectedValue(op); // ExcludeFromJacocoGeneratedReport - } + Value result = switch (op) { + case Compress -> tool.emitCompress(gen.operand(value), encoding, nonNull); + case Uncompress -> tool.emitUncompress(gen.operand(value), encoding, nonNull); + }; gen.setResult(this, result); } From 712da9eced74b872591f8b402795f2f762ea5771 Mon Sep 17 00:00:00 2001 From: Yudi Zheng Date: Mon, 4 Aug 2025 19:54:14 +0200 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 8716f3c4f1d3..e9f6d85da5a8 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": "26", "build_id": "jdk-26+10-966", "platformspecific": true, "extrabundles": ["static-libs"]}, + "galahad-jdk": {"name": "jpg-jdk", "version": "26", "build_id": "jdk-26+10-1012", "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 },