Skip to content

Commit 60b4f58

Browse files
Yudi Zhengmarwan-hallaoui
authored andcommitted
8365218: [JVMCI] AArch64 CPU features are not computed correctly after 8364128
Reviewed-by: dnsimon (cherry picked from commit e320162)
1 parent 873bed5 commit 60b4f58

File tree

4 files changed

+20
-65
lines changed

4 files changed

+20
-65
lines changed

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIBackendFactory.java

Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
import java.util.List;
2828
import java.util.Map;
2929
import java.util.Map.Entry;
30+
import java.util.function.LongFunction;
3031

3132
import jdk.vm.ci.common.JVMCIError;
3233
import jdk.vm.ci.runtime.JVMCIBackend;
33-
import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE;
3434

3535
public interface HotSpotJVMCIBackendFactory {
3636

@@ -48,7 +48,8 @@ public interface HotSpotJVMCIBackendFactory {
4848
* @param enumType the class of {@code CPUFeatureType}
4949
* @param constants VM constants. Each entry whose key starts with {@code "VM_Version::CPU_"}
5050
* specifies a CPU feature and its value is a mask for a bit in {@code features}
51-
* @param features bits specifying CPU features
51+
* @param bitMaskSupplier supplier to get the bit mask for the corresponding VM constant
52+
* @param featuresSupplier supplier to get the bits specifying CPU features
5253
* @param renaming maps from VM feature names to enum constant names where the two differ
5354
* @throws IllegalArgumentException if any VM CPU feature constant cannot be converted to an
5455
* enum value
@@ -57,18 +58,19 @@ public interface HotSpotJVMCIBackendFactory {
5758
static <CPUFeatureType extends Enum<CPUFeatureType>> EnumSet<CPUFeatureType> convertFeatures(
5859
Class<CPUFeatureType> enumType,
5960
Map<String, Long> constants,
60-
long features,
61+
LongFunction<Long> bitMaskSupplier,
62+
LongFunction<Long> featuresSupplier,
6163
Map<String, String> renaming) {
6264
EnumSet<CPUFeatureType> outFeatures = EnumSet.noneOf(enumType);
6365
List<String> missing = new ArrayList<>();
6466
for (Entry<String, Long> e : constants.entrySet()) {
65-
long bitMask = e.getValue();
67+
long bitMask = bitMaskSupplier.apply(e.getValue());
6668
String key = e.getKey();
6769
if (key.startsWith("VM_Version::CPU_")) {
6870
String name = key.substring("VM_Version::CPU_".length());
6971
try {
7072
CPUFeatureType feature = Enum.valueOf(enumType, renaming.getOrDefault(name, name));
71-
if ((features & bitMask) != 0) {
73+
if ((featuresSupplier.apply(e.getValue()) & bitMask) != 0) {
7274
outFeatures.add(feature);
7375
}
7476
} catch (IllegalArgumentException iae) {
@@ -82,57 +84,4 @@ static <CPUFeatureType extends Enum<CPUFeatureType>> EnumSet<CPUFeatureType> con
8284
return outFeatures;
8385
}
8486

85-
/**
86-
* Converts CPU features bit map into enum constants.
87-
*
88-
* @param <CPUFeatureType> CPU feature enum type
89-
* @param enumType the class of {@code CPUFeatureType}
90-
* @param constants VM constants. Each entry whose key starts with {@code "VM_Version::CPU_"}
91-
* specifies a CPU feature and its value is a mask for a bit in {@code features}
92-
* @param featuresBitMapAddress pointer to {@code VM_Features::_features_bitmap} field of {@code VM_Version::_features}
93-
* @param featuresBitMapSize size of feature bit map in bytes
94-
* @param renaming maps from VM feature names to enum constant names where the two differ
95-
* @throws IllegalArgumentException if any VM CPU feature constant cannot be converted to an
96-
* enum value
97-
* @return the set of converted values
98-
*/
99-
static <CPUFeatureType extends Enum<CPUFeatureType>> EnumSet<CPUFeatureType> convertFeatures(
100-
Class<CPUFeatureType> enumType,
101-
Map<String, Long> constants,
102-
long featuresBitMapAddress,
103-
long featuresBitMapSize,
104-
Map<String, String> renaming) {
105-
EnumSet<CPUFeatureType> outFeatures = EnumSet.noneOf(enumType);
106-
List<String> missing = new ArrayList<>();
107-
108-
for (Entry<String, Long> e : constants.entrySet()) {
109-
String key = e.getKey();
110-
long bitIndex = e.getValue();
111-
if (key.startsWith("VM_Version::CPU_")) {
112-
String name = key.substring("VM_Version::CPU_".length());
113-
try {
114-
final long featuresElementShiftCount = 6; // log (# of bits per long)
115-
final long featuresElementMask = (1L << featuresElementShiftCount) - 1;
116-
117-
CPUFeatureType feature = Enum.valueOf(enumType, renaming.getOrDefault(name, name));
118-
119-
long featureIndex = bitIndex >>> featuresElementShiftCount;
120-
long featureBitMask = 1L << (bitIndex & featuresElementMask);
121-
assert featureIndex < featuresBitMapSize;
122-
123-
long featuresElement = UNSAFE.getLong(featuresBitMapAddress + featureIndex * Long.BYTES);
124-
125-
if ((featuresElement & featureBitMask) != 0) {
126-
outFeatures.add(feature);
127-
}
128-
} catch (IllegalArgumentException iae) {
129-
missing.add(name);
130-
}
131-
}
132-
}
133-
if (!missing.isEmpty()) {
134-
throw new JVMCIError("Missing CPU feature constants: %s", missing);
135-
}
136-
return outFeatures;
137-
}
13887
}

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotJVMCIBackendFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class AArch64HotSpotJVMCIBackendFactory implements HotSpotJVMCIBackendFac
4949
private static EnumSet<AArch64.CPUFeature> computeFeatures(AArch64HotSpotVMConfig config) {
5050
// Configure the feature set using the HotSpot flag settings.
5151
Map<String, Long> constants = config.getStore().getConstants();
52-
return HotSpotJVMCIBackendFactory.convertFeatures(CPUFeature.class, constants, config.vmVersionFeatures, emptyMap());
52+
return HotSpotJVMCIBackendFactory.convertFeatures(CPUFeature.class, constants, idx -> 1L << idx, _ -> config.vmVersionFeatures, emptyMap());
5353
}
5454

5555
private static TargetDescription createTarget(AArch64HotSpotVMConfig config) {

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/amd64/AMD64HotSpotJVMCIBackendFactory.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
import java.util.EnumSet;
2828
import java.util.Map;
29+
30+
import jdk.internal.misc.Unsafe;
2931
import jdk.internal.util.OperatingSystem;
3032
import jdk.vm.ci.amd64.AMD64;
3133
import jdk.vm.ci.amd64.AMD64.CPUFeature;
@@ -50,11 +52,15 @@ private static EnumSet<CPUFeature> computeFeatures(AMD64HotSpotVMConfig config)
5052
Map<String, Long> constants = config.getStore().getConstants();
5153
Map<String, String> renaming = Map.of("3DNOW_PREFETCH", "AMD_3DNOW_PREFETCH");
5254
long featuresBitMapAddress = config.vmVersionFeatures + config.vmFeaturesFeaturesOffset;
53-
EnumSet<CPUFeature> features = HotSpotJVMCIBackendFactory.convertFeatures(CPUFeature.class,
54-
constants,
55-
featuresBitMapAddress,
56-
config.vmFeaturesFeaturesSize,
57-
renaming);
55+
EnumSet<CPUFeature> features = HotSpotJVMCIBackendFactory.convertFeatures(CPUFeature.class, constants, idx -> {
56+
final long featuresElementShiftCount = 6; // log (# of bits per long)
57+
final long featuresElementMask = (1L << featuresElementShiftCount) - 1;
58+
return 1L << (idx & featuresElementMask);
59+
}, idx -> {
60+
final long featuresElementShiftCount = 6; // log (# of bits per long)
61+
long featureIndex = idx >>> featuresElementShiftCount;
62+
return Unsafe.getUnsafe().getLong(featuresBitMapAddress + featureIndex * Long.BYTES);
63+
}, renaming);
5864
assert features.contains(AMD64.CPUFeature.SSE) : "minimum config for x64";
5965
assert features.contains(AMD64.CPUFeature.SSE2) : "minimum config for x64";
6066
return features;

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/riscv64/RISCV64HotSpotJVMCIBackendFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class RISCV64HotSpotJVMCIBackendFactory implements HotSpotJVMCIBackendFac
4949
private static EnumSet<RISCV64.CPUFeature> computeFeatures(RISCV64HotSpotVMConfig config) {
5050
// Configure the feature set using the HotSpot flag settings.
5151
Map<String, Long> constants = config.getStore().getConstants();
52-
return HotSpotJVMCIBackendFactory.convertFeatures(CPUFeature.class, constants, config.vmVersionFeatures, emptyMap());
52+
return HotSpotJVMCIBackendFactory.convertFeatures(CPUFeature.class, constants, mask -> mask, _ -> config.vmVersionFeatures, emptyMap());
5353
}
5454

5555
private static TargetDescription createTarget(RISCV64HotSpotVMConfig config) {

0 commit comments

Comments
 (0)