Skip to content

Commit ece2abc

Browse files
committed
[JDK-8364585] Adapt JDK-8343218: Add option to disable allocating interface and abstract classes in non-class metaspace
PullRequest: graal/21748
2 parents 64a8a79 + 712da9e commit ece2abc

File tree

5 files changed

+27
-49
lines changed

5 files changed

+27
-49
lines changed

common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
"COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet",
1010
"jdks": {
11-
"galahad-jdk": {"name": "jpg-jdk", "version": "26", "build_id": "jdk-26+10-966", "platformspecific": true, "extrabundles": ["static-libs"]},
11+
"galahad-jdk": {"name": "jpg-jdk", "version": "26", "build_id": "jdk-26+10-1012", "platformspecific": true, "extrabundles": ["static-libs"]},
1212

1313
"oraclejdk17": {"name": "jpg-jdk", "version": "17.0.7", "build_id": "jdk-17.0.7+8", "platformspecific": true, "extrabundles": ["static-libs"]},
1414
"labsjdk-ce-17": {"name": "labsjdk", "version": "ce-17.0.7+4-jvmci-23.1-b02", "platformspecific": true },

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/HotSpotCompressedKlassPointerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,7 +40,7 @@ public class HotSpotCompressedKlassPointerTest extends HotSpotGraalCompilerTest
4040
@Before
4141
public void setUp() {
4242
GraalHotSpotVMConfig config = runtime().getVMConfig();
43-
assumeTrue("compressed class pointers specific tests", config.useCompressedClassPointers);
43+
assumeTrue("compressed class pointers specific tests", config.useCompressedClassPointers && !config.useClassMetaspaceForAllClasses);
4444
}
4545

4646
// Non-abstract class

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/GraalHotSpotVMConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ public long gcTotalCollectionsAddress() {
195195
// Compressed Oops related values.
196196
public final boolean useCompressedOops = getFlag("UseCompressedOops", Boolean.class);
197197
public final boolean useCompressedClassPointers = getFlag("UseCompressedClassPointers", Boolean.class);
198+
199+
public final boolean useClassMetaspaceForAllClasses = getFlag("UseClassMetaspaceForAllClasses", Boolean.class);
200+
198201
// JDK-8305895 allows storing the compressed class pointer in the upper 22 bits of the mark
199202
// word. This runtime optimization is guarded by the flag UseCompactObjectHeaders. It depends
200203
// on compressed class pointers, meaning that if useCompactObjectHeaders is true,

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/nodes/HotSpotCompressionNode.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -44,7 +44,6 @@
4444
import jdk.vm.ci.meta.Constant;
4545
import jdk.vm.ci.meta.ConstantReflectionProvider;
4646
import jdk.vm.ci.meta.JavaConstant;
47-
import jdk.vm.ci.meta.ResolvedJavaType;
4847

4948
@NodeInfo(nameTemplate = "{p#op/s}", cycles = CYCLES_2, size = SIZE_2)
5049
public final class HotSpotCompressionNode extends CompressionNode {
@@ -74,9 +73,7 @@ private static CompressionNode uncompress(ValueNode input, CompressEncoding enco
7473
@Override
7574
public boolean isCompressible(Constant constant) {
7675
if (constant instanceof HotSpotMetaspaceConstant mc) {
77-
ResolvedJavaType type = mc.asResolvedJavaType();
78-
// As of JDK-8338526, interface and abstract types are not compressible.
79-
return type.isArray() || (!type.isAbstract() && !type.isInterface());
76+
return mc.isCompressible();
8077
}
8178
return true;
8279
}
@@ -103,14 +100,10 @@ protected Constant uncompress(Constant c) {
103100

104101
@Override
105102
public ValueNode reverse(ValueNode input) {
106-
switch (op) {
107-
case Compress:
108-
return uncompress(input, encoding);
109-
case Uncompress:
110-
return compress(input, encoding);
111-
default:
112-
throw GraalError.shouldNotReachHereUnexpectedValue(op); // ExcludeFromJacocoGeneratedReport
113-
}
103+
return switch (op) {
104+
case Compress -> uncompress(input, encoding);
105+
case Uncompress -> compress(input, encoding);
106+
};
114107
}
115108

116109
@Override

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/CompressionNode.java

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,7 +30,6 @@
3030
import jdk.graal.compiler.core.common.CompressEncoding;
3131
import jdk.graal.compiler.core.common.type.AbstractObjectStamp;
3232
import jdk.graal.compiler.core.common.type.Stamp;
33-
import jdk.graal.compiler.debug.GraalError;
3433
import jdk.graal.compiler.graph.NodeClass;
3534
import jdk.graal.compiler.lir.gen.LIRGeneratorTool;
3635
import jdk.graal.compiler.nodeinfo.NodeInfo;
@@ -83,26 +82,18 @@ public JavaConstant nullConstant() {
8382

8483
@Override
8584
public Constant convert(Constant c, ConstantReflectionProvider constantReflection) {
86-
switch (op) {
87-
case Compress:
88-
return compress(c);
89-
case Uncompress:
90-
return uncompress(c);
91-
default:
92-
throw GraalError.shouldNotReachHereUnexpectedValue(op); // ExcludeFromJacocoGeneratedReport
93-
}
85+
return switch (op) {
86+
case Compress -> compress(c);
87+
case Uncompress -> uncompress(c);
88+
};
9489
}
9590

9691
@Override
9792
public Constant reverse(Constant c, ConstantReflectionProvider constantReflection) {
98-
switch (op) {
99-
case Compress:
100-
return uncompress(c);
101-
case Uncompress:
102-
return compress(c);
103-
default:
104-
throw GraalError.shouldNotReachHereUnexpectedValue(op); // ExcludeFromJacocoGeneratedReport
105-
}
93+
return switch (op) {
94+
case Compress -> uncompress(c);
95+
case Uncompress -> compress(c);
96+
};
10697
}
10798

10899
/**
@@ -138,14 +129,12 @@ public boolean isCompressible(Constant constant) {
138129

139130
@Override
140131
public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) {
141-
if (forValue.isConstant()) {
142-
ConstantNode constant = (ConstantNode) forValue;
132+
if (forValue instanceof ConstantNode constant) {
143133
if (isCompressible(constant.getValue())) {
144134
return ConstantNode.forConstant(stamp(NodeView.DEFAULT), convert(constant.getValue(), tool.getConstantReflection()), constant.getStableDimension(),
145135
constant.isDefaultStable(), tool.getMetaAccess());
146136
}
147-
} else if (forValue instanceof CompressionNode) {
148-
CompressionNode other = (CompressionNode) forValue;
137+
} else if (forValue instanceof CompressionNode other) {
149138
if (op != other.op && encoding.equals(other.encoding)) {
150139
return other.getValue();
151140
}
@@ -164,17 +153,10 @@ public void generate(NodeLIRBuilderTool gen) {
164153
}
165154

166155
LIRGeneratorTool tool = gen.getLIRGeneratorTool();
167-
Value result;
168-
switch (op) {
169-
case Compress:
170-
result = tool.emitCompress(gen.operand(value), encoding, nonNull);
171-
break;
172-
case Uncompress:
173-
result = tool.emitUncompress(gen.operand(value), encoding, nonNull);
174-
break;
175-
default:
176-
throw GraalError.shouldNotReachHereUnexpectedValue(op); // ExcludeFromJacocoGeneratedReport
177-
}
156+
Value result = switch (op) {
157+
case Compress -> tool.emitCompress(gen.operand(value), encoding, nonNull);
158+
case Uncompress -> tool.emitUncompress(gen.operand(value), encoding, nonNull);
159+
};
178160

179161
gen.setResult(this, result);
180162
}

0 commit comments

Comments
 (0)