2727import java .util .List ;
2828import java .util .Map ;
2929import java .util .Map .Entry ;
30+ import java .util .function .LongFunction ;
3031
3132import jdk .vm .ci .common .JVMCIError ;
3233import jdk .vm .ci .runtime .JVMCIBackend ;
33- import static jdk .vm .ci .hotspot .UnsafeAccess .UNSAFE ;
3434
3535public 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}
0 commit comments