25
25
import static jdk .vm .ci .common .InitTimer .timer ;
26
26
import static jdk .vm .ci .services .Services .IS_IN_NATIVE_IMAGE ;
27
27
28
- import java .io .IOException ;
29
28
import java .io .ByteArrayOutputStream ;
30
29
import java .io .OutputStream ;
31
30
import java .io .PrintStream ;
@@ -90,7 +89,6 @@ public final class HotSpotJVMCIRuntime implements JVMCIRuntime {
90
89
private HotSpotResolvedObjectTypeImpl constantCallSiteType ;
91
90
private HotSpotResolvedObjectTypeImpl callSiteType ;
92
91
private HotSpotResolvedObjectTypeImpl javaLangString ;
93
- private HotSpotResolvedObjectTypeImpl javaLangClass ;
94
92
private HotSpotResolvedObjectTypeImpl throwableType ;
95
93
private HotSpotResolvedObjectTypeImpl serializableType ;
96
94
private HotSpotResolvedObjectTypeImpl cloneableType ;
@@ -118,13 +116,6 @@ HotSpotResolvedObjectTypeImpl getJavaLangString() {
118
116
return javaLangString ;
119
117
}
120
118
121
- HotSpotResolvedObjectTypeImpl getJavaLangClass () {
122
- if (javaLangClass == null ) {
123
- javaLangClass = (HotSpotResolvedObjectTypeImpl ) fromClass (Class .class );
124
- }
125
- return javaLangClass ;
126
- }
127
-
128
119
HotSpotResolvedObjectTypeImpl getJavaLangCloneable () {
129
120
if (cloneableType == null ) {
130
121
cloneableType = (HotSpotResolvedObjectTypeImpl ) fromClass (Cloneable .class );
@@ -188,7 +179,7 @@ public static HotSpotJVMCIRuntime runtime() {
188
179
synchronized (JVMCI .class ) {
189
180
result = instance ;
190
181
if (result == null ) {
191
- try (InitTimer t = timer ("HotSpotJVMCIRuntime.<init>" )) {
182
+ try (InitTimer _ = timer ("HotSpotJVMCIRuntime.<init>" )) {
192
183
instance = result = new HotSpotJVMCIRuntime ();
193
184
194
185
// Can only do eager initialization of the JVMCI compiler
@@ -426,8 +417,6 @@ static float stringSimiliarity(String str1, String str2) {
426
417
/**
427
418
* Parses all system properties starting with {@value #JVMCI_OPTION_PROPERTY_PREFIX} and
428
419
* initializes the options based on their values.
429
- *
430
- * @param runtime
431
420
*/
432
421
static void parse (HotSpotJVMCIRuntime runtime ) {
433
422
Map <String , String > savedProps = jdk .vm .ci .services .Services .getSavedProperties ();
@@ -452,9 +441,8 @@ static void parse(HotSpotJVMCIRuntime runtime) {
452
441
}
453
442
}
454
443
msg .format ("%nError: A fatal exception has occurred. Program will exit.%n" );
455
- runtime .exitHotSpotWithMessage (1 , msg .toString ());
456
- } else if (value instanceof Option ) {
457
- Option option = (Option ) value ;
444
+ throw runtime .exitHotSpotWithMessage (1 , msg .toString ());
445
+ } else if (value instanceof Option option ) {
458
446
option .init (e .getValue ());
459
447
}
460
448
}
@@ -491,15 +479,15 @@ public static JavaKind getHostWordKind() {
491
479
return runtime ().getHostJVMCIBackend ().getCodeCache ().getTarget ().wordJavaKind ;
492
480
}
493
481
494
- protected final CompilerToVM compilerToVm ;
482
+ final CompilerToVM compilerToVm ;
495
483
496
- protected final HotSpotVMConfigStore configStore ;
497
- protected final HotSpotVMConfig config ;
484
+ final HotSpotVMConfigStore configStore ;
485
+ final HotSpotVMConfig config ;
498
486
private final JVMCIBackend hostBackend ;
499
487
500
488
private final JVMCICompilerFactory compilerFactory ;
501
489
private volatile JVMCICompiler compiler ;
502
- protected final HotSpotJVMCIReflection reflection ;
490
+ final HotSpotJVMCIReflection reflection ;
503
491
504
492
private volatile boolean creatingCompiler ;
505
493
@@ -571,7 +559,7 @@ public KlassWeakReference(Long klassPointer, HotSpotResolvedObjectTypeImpl refer
571
559
private HotSpotJVMCIRuntime () {
572
560
compilerToVm = new CompilerToVM ();
573
561
574
- try (InitTimer t = timer ("HotSpotVMConfig<init>" )) {
562
+ try (InitTimer _ = timer ("HotSpotVMConfig<init>" )) {
575
563
configStore = new HotSpotVMConfigStore (compilerToVm );
576
564
config = new HotSpotVMConfig (configStore );
577
565
}
@@ -589,7 +577,7 @@ private HotSpotJVMCIRuntime() {
589
577
// Initialize the Option values.
590
578
Option .parse (this );
591
579
592
- try (InitTimer t = timer ("create JVMCI backend:" , backendFactory .getArchitecture ())) {
580
+ try (InitTimer _ = timer ("create JVMCI backend:" , backendFactory .getArchitecture ())) {
593
581
hostBackend = registerBackend (backendFactory .createJVMCIBackend (this , null ));
594
582
}
595
583
@@ -744,11 +732,11 @@ public HotSpotVMConfigStore getConfigStore() {
744
732
return configStore ;
745
733
}
746
734
747
- public HotSpotVMConfig getConfig () {
735
+ HotSpotVMConfig getConfig () {
748
736
return config ;
749
737
}
750
738
751
- public CompilerToVM getCompilerToVM () {
739
+ CompilerToVM getCompilerToVM () {
752
740
return compilerToVm ;
753
741
}
754
742
@@ -764,15 +752,11 @@ HotSpotJVMCIReflection getReflection() {
764
752
* compiler.
765
753
*/
766
754
public Predicate <ResolvedJavaType > getIntrinsificationTrustPredicate (Class <?>... compilerLeafClasses ) {
767
- return new Predicate <>() {
768
- @ Override
769
- public boolean test (ResolvedJavaType type ) {
770
- if (type instanceof HotSpotResolvedObjectTypeImpl ) {
771
- HotSpotResolvedObjectTypeImpl hsType = (HotSpotResolvedObjectTypeImpl ) type ;
772
- return compilerToVm .isTrustedForIntrinsics (hsType );
773
- } else {
774
- return false ;
775
- }
755
+ return type -> {
756
+ if (type instanceof HotSpotResolvedObjectTypeImpl hsType ) {
757
+ return compilerToVm .isTrustedForIntrinsics (hsType );
758
+ } else {
759
+ return false ;
776
760
}
777
761
};
778
762
}
@@ -822,23 +806,18 @@ public Field getMirror(ResolvedJavaField field) {
822
806
return null ;
823
807
}
824
808
825
- static class ErrorCreatingCompiler implements JVMCICompiler {
826
- private final RuntimeException t ;
827
-
828
- ErrorCreatingCompiler (RuntimeException t ) {
829
- this .t = t ;
830
- }
809
+ record ErrorCreatingCompiler (RuntimeException t ) implements JVMCICompiler {
831
810
832
811
@ Override
833
812
public CompilationRequestResult compileMethod (CompilationRequest request ) {
834
- throw t ;
835
- }
813
+ throw t ;
814
+ }
836
815
837
816
@ Override
838
817
public boolean isGCSupported (int gcIdentifier ) {
839
- return false ;
818
+ return false ;
819
+ }
840
820
}
841
- }
842
821
843
822
@ Override
844
823
public JVMCICompiler getCompiler () {
@@ -867,7 +846,7 @@ public JVMCICompiler getCompiler() {
867
846
* Converts a name to a Java type. This method attempts to resolve {@code name} to a
868
847
* {@link ResolvedJavaType}.
869
848
*
870
- * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format
849
+ * @param name a well- formed Java type in {@linkplain JavaType#getName() internal} format
871
850
* @param accessingType the context of resolution which must be non-null
872
851
* @param resolve specifies whether resolution failure results in an unresolved type being
873
852
* return or a {@link LinkageError} being thrown
@@ -913,7 +892,7 @@ JavaType lookupTypeInternal(String name, HotSpotResolvedObjectType accessingType
913
892
final HotSpotResolvedJavaType klass = compilerToVm .lookupType (name , hsAccessingType , resolve );
914
893
915
894
if (klass == null ) {
916
- assert resolve == false : name ;
895
+ assert ! resolve : name ;
917
896
return UnresolvedJavaType .create (name );
918
897
}
919
898
return klass ;
@@ -994,7 +973,7 @@ private boolean isIntrinsicSupported(int intrinsicIdentifier) {
994
973
* Shuts down the runtime.
995
974
*/
996
975
@ VMEntryPoint
997
- private void shutdown () throws Exception {
976
+ private void shutdown () {
998
977
if (isShutdown .compareAndSet (false , true )) {
999
978
// Cleaners are normally only processed when a new Cleaner is
1000
979
// instantiated so process all remaining cleaners now.
@@ -1010,18 +989,14 @@ private void shutdown() throws Exception {
1010
989
* Notify on completion of a bootstrap.
1011
990
*/
1012
991
@ VMEntryPoint
1013
- private void bootstrapFinished () throws Exception {
992
+ private void bootstrapFinished () {
1014
993
for (HotSpotVMEventListener vmEventListener : vmEventListeners ) {
1015
994
vmEventListener .notifyBootstrapFinished ();
1016
995
}
1017
996
}
1018
997
1019
998
/**
1020
- * Notify on successful install into the CodeCache.
1021
- *
1022
- * @param hotSpotCodeCacheProvider
1023
- * @param installedCode
1024
- * @param compiledCode
999
+ * Notify on successful installation into the CodeCache.
1025
1000
*/
1026
1001
void notifyInstall (HotSpotCodeCacheProvider hotSpotCodeCacheProvider , InstalledCode installedCode , CompiledCode compiledCode ) {
1027
1002
for (HotSpotVMEventListener vmEventListener : vmEventListeners ) {
@@ -1092,7 +1067,7 @@ public OutputStream getLogStream() {
1092
1067
return new OutputStream () {
1093
1068
1094
1069
@ Override
1095
- public void write (byte [] b , int off , int len ) throws IOException {
1070
+ public void write (byte [] b , int off , int len ) {
1096
1071
if (b == null ) {
1097
1072
throw new NullPointerException ();
1098
1073
} else if (off < 0 || off > b .length || len < 0 || (off + len ) > b .length || (off + len ) < 0 ) {
@@ -1104,12 +1079,12 @@ public void write(byte[] b, int off, int len) throws IOException {
1104
1079
}
1105
1080
1106
1081
@ Override
1107
- public void write (int b ) throws IOException {
1082
+ public void write (int b ) {
1108
1083
write (new byte []{(byte ) b }, 0 , 1 );
1109
1084
}
1110
1085
1111
1086
@ Override
1112
- public void flush () throws IOException {
1087
+ public void flush () {
1113
1088
compilerToVm .flushDebugOutput ();
1114
1089
}
1115
1090
};
@@ -1135,7 +1110,6 @@ public int getCountersSize() {
1135
1110
* Attempt to enlarge the number of per thread counters available. Requires a safepoint so
1136
1111
* resizing should be rare to avoid performance effects.
1137
1112
*
1138
- * @param newSize
1139
1113
* @return false if the resizing failed
1140
1114
*/
1141
1115
public boolean setCountersSize (int newSize ) {
@@ -1148,28 +1122,18 @@ public boolean setCountersSize(int newSize) {
1148
1122
* @return the offset in bytes
1149
1123
*/
1150
1124
public int getArrayBaseOffset (JavaKind kind ) {
1151
- switch (kind ) {
1152
- case Boolean :
1153
- return compilerToVm .ARRAY_BOOLEAN_BASE_OFFSET ;
1154
- case Byte :
1155
- return compilerToVm .ARRAY_BYTE_BASE_OFFSET ;
1156
- case Char :
1157
- return compilerToVm .ARRAY_CHAR_BASE_OFFSET ;
1158
- case Short :
1159
- return compilerToVm .ARRAY_SHORT_BASE_OFFSET ;
1160
- case Int :
1161
- return compilerToVm .ARRAY_INT_BASE_OFFSET ;
1162
- case Long :
1163
- return compilerToVm .ARRAY_LONG_BASE_OFFSET ;
1164
- case Float :
1165
- return compilerToVm .ARRAY_FLOAT_BASE_OFFSET ;
1166
- case Double :
1167
- return compilerToVm .ARRAY_DOUBLE_BASE_OFFSET ;
1168
- case Object :
1169
- return compilerToVm .ARRAY_OBJECT_BASE_OFFSET ;
1170
- default :
1171
- throw new JVMCIError ("%s" , kind );
1172
- }
1125
+ return switch (kind ) {
1126
+ case Boolean -> compilerToVm .ARRAY_BOOLEAN_BASE_OFFSET ;
1127
+ case Byte -> compilerToVm .ARRAY_BYTE_BASE_OFFSET ;
1128
+ case Char -> compilerToVm .ARRAY_CHAR_BASE_OFFSET ;
1129
+ case Short -> compilerToVm .ARRAY_SHORT_BASE_OFFSET ;
1130
+ case Int -> compilerToVm .ARRAY_INT_BASE_OFFSET ;
1131
+ case Long -> compilerToVm .ARRAY_LONG_BASE_OFFSET ;
1132
+ case Float -> compilerToVm .ARRAY_FLOAT_BASE_OFFSET ;
1133
+ case Double -> compilerToVm .ARRAY_DOUBLE_BASE_OFFSET ;
1134
+ case Object -> compilerToVm .ARRAY_OBJECT_BASE_OFFSET ;
1135
+ default -> throw new JVMCIError ("%s" , kind );
1136
+ };
1173
1137
1174
1138
}
1175
1139
@@ -1179,29 +1143,18 @@ public int getArrayBaseOffset(JavaKind kind) {
1179
1143
* @return the scale in order to convert the index into a byte offset
1180
1144
*/
1181
1145
public int getArrayIndexScale (JavaKind kind ) {
1182
- switch (kind ) {
1183
- case Boolean :
1184
- return compilerToVm .ARRAY_BOOLEAN_INDEX_SCALE ;
1185
- case Byte :
1186
- return compilerToVm .ARRAY_BYTE_INDEX_SCALE ;
1187
- case Char :
1188
- return compilerToVm .ARRAY_CHAR_INDEX_SCALE ;
1189
- case Short :
1190
- return compilerToVm .ARRAY_SHORT_INDEX_SCALE ;
1191
- case Int :
1192
- return compilerToVm .ARRAY_INT_INDEX_SCALE ;
1193
- case Long :
1194
- return compilerToVm .ARRAY_LONG_INDEX_SCALE ;
1195
- case Float :
1196
- return compilerToVm .ARRAY_FLOAT_INDEX_SCALE ;
1197
- case Double :
1198
- return compilerToVm .ARRAY_DOUBLE_INDEX_SCALE ;
1199
- case Object :
1200
- return compilerToVm .ARRAY_OBJECT_INDEX_SCALE ;
1201
- default :
1202
- throw new JVMCIError ("%s" , kind );
1203
-
1204
- }
1146
+ return switch (kind ) {
1147
+ case Boolean -> compilerToVm .ARRAY_BOOLEAN_INDEX_SCALE ;
1148
+ case Byte -> compilerToVm .ARRAY_BYTE_INDEX_SCALE ;
1149
+ case Char -> compilerToVm .ARRAY_CHAR_INDEX_SCALE ;
1150
+ case Short -> compilerToVm .ARRAY_SHORT_INDEX_SCALE ;
1151
+ case Int -> compilerToVm .ARRAY_INT_INDEX_SCALE ;
1152
+ case Long -> compilerToVm .ARRAY_LONG_INDEX_SCALE ;
1153
+ case Float -> compilerToVm .ARRAY_FLOAT_INDEX_SCALE ;
1154
+ case Double -> compilerToVm .ARRAY_DOUBLE_INDEX_SCALE ;
1155
+ case Object -> compilerToVm .ARRAY_OBJECT_INDEX_SCALE ;
1156
+ default -> throw new JVMCIError ("%s" , kind );
1157
+ };
1205
1158
}
1206
1159
1207
1160
/**
@@ -1334,22 +1287,26 @@ static void postTranslation(Object translatedObject) {
1334
1287
String value = Option .ForceTranslateFailure .getString ();
1335
1288
String toMatch ;
1336
1289
String type ;
1337
- if (translatedObject instanceof HotSpotResolvedJavaMethodImpl ) {
1338
- toMatch = ((HotSpotResolvedJavaMethodImpl ) translatedObject ).format ("%H.%n" );
1339
- type = "method" ;
1340
- } else if (translatedObject instanceof HotSpotResolvedObjectTypeImpl ) {
1341
- toMatch = ((HotSpotResolvedObjectTypeImpl ) translatedObject ).toJavaName ();
1342
- type = "type" ;
1343
- } else if (translatedObject instanceof HotSpotNmethod ) {
1344
- HotSpotNmethod nmethod = (HotSpotNmethod ) translatedObject ;
1345
- if (nmethod .getMethod () != null ) {
1346
- toMatch = nmethod .getMethod ().format ("%H.%n" );
1347
- } else {
1348
- toMatch = String .valueOf (nmethod .getName ());
1290
+ switch (translatedObject ) {
1291
+ case HotSpotResolvedJavaMethodImpl hotSpotResolvedJavaMethod -> {
1292
+ toMatch = hotSpotResolvedJavaMethod .format ("%H.%n" );
1293
+ type = "method" ;
1294
+ }
1295
+ case HotSpotResolvedObjectTypeImpl hotSpotResolvedObjectType -> {
1296
+ toMatch = hotSpotResolvedObjectType .toJavaName ();
1297
+ type = "type" ;
1298
+ }
1299
+ case HotSpotNmethod nmethod -> {
1300
+ if (nmethod .getMethod () != null ) {
1301
+ toMatch = nmethod .getMethod ().format ("%H.%n" );
1302
+ } else {
1303
+ toMatch = String .valueOf (nmethod .getName ());
1304
+ }
1305
+ type = "nmethod" ;
1306
+ }
1307
+ case null , default -> {
1308
+ return ;
1349
1309
}
1350
- type = "nmethod" ;
1351
- } else {
1352
- return ;
1353
1310
}
1354
1311
String [] filters = value .split ("," );
1355
1312
for (String filter : filters ) {
0 commit comments