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 ;
@@ -188,7 +187,7 @@ public static HotSpotJVMCIRuntime runtime() {
188
187
synchronized (JVMCI .class ) {
189
188
result = instance ;
190
189
if (result == null ) {
191
- try (InitTimer t = timer ("HotSpotJVMCIRuntime.<init>" )) {
190
+ try (InitTimer _ = timer ("HotSpotJVMCIRuntime.<init>" )) {
192
191
instance = result = new HotSpotJVMCIRuntime ();
193
192
194
193
// Can only do eager initialization of the JVMCI compiler
@@ -426,8 +425,6 @@ static float stringSimiliarity(String str1, String str2) {
426
425
/**
427
426
* Parses all system properties starting with {@value #JVMCI_OPTION_PROPERTY_PREFIX} and
428
427
* initializes the options based on their values.
429
- *
430
- * @param runtime
431
428
*/
432
429
static void parse (HotSpotJVMCIRuntime runtime ) {
433
430
Map <String , String > savedProps = jdk .vm .ci .services .Services .getSavedProperties ();
@@ -452,9 +449,8 @@ static void parse(HotSpotJVMCIRuntime runtime) {
452
449
}
453
450
}
454
451
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 ;
452
+ throw runtime .exitHotSpotWithMessage (1 , msg .toString ());
453
+ } else if (value instanceof Option option ) {
458
454
option .init (e .getValue ());
459
455
}
460
456
}
@@ -491,15 +487,15 @@ public static JavaKind getHostWordKind() {
491
487
return runtime ().getHostJVMCIBackend ().getCodeCache ().getTarget ().wordJavaKind ;
492
488
}
493
489
494
- protected final CompilerToVM compilerToVm ;
490
+ final CompilerToVM compilerToVm ;
495
491
496
- protected final HotSpotVMConfigStore configStore ;
497
- protected final HotSpotVMConfig config ;
492
+ final HotSpotVMConfigStore configStore ;
493
+ final HotSpotVMConfig config ;
498
494
private final JVMCIBackend hostBackend ;
499
495
500
496
private final JVMCICompilerFactory compilerFactory ;
501
497
private volatile JVMCICompiler compiler ;
502
- protected final HotSpotJVMCIReflection reflection ;
498
+ final HotSpotJVMCIReflection reflection ;
503
499
504
500
private volatile boolean creatingCompiler ;
505
501
@@ -571,7 +567,7 @@ public KlassWeakReference(Long klassPointer, HotSpotResolvedObjectTypeImpl refer
571
567
private HotSpotJVMCIRuntime () {
572
568
compilerToVm = new CompilerToVM ();
573
569
574
- try (InitTimer t = timer ("HotSpotVMConfig<init>" )) {
570
+ try (InitTimer _ = timer ("HotSpotVMConfig<init>" )) {
575
571
configStore = new HotSpotVMConfigStore (compilerToVm );
576
572
config = new HotSpotVMConfig (configStore );
577
573
}
@@ -589,7 +585,7 @@ private HotSpotJVMCIRuntime() {
589
585
// Initialize the Option values.
590
586
Option .parse (this );
591
587
592
- try (InitTimer t = timer ("create JVMCI backend:" , backendFactory .getArchitecture ())) {
588
+ try (InitTimer _ = timer ("create JVMCI backend:" , backendFactory .getArchitecture ())) {
593
589
hostBackend = registerBackend (backendFactory .createJVMCIBackend (this , null ));
594
590
}
595
591
@@ -744,11 +740,11 @@ public HotSpotVMConfigStore getConfigStore() {
744
740
return configStore ;
745
741
}
746
742
747
- public HotSpotVMConfig getConfig () {
743
+ HotSpotVMConfig getConfig () {
748
744
return config ;
749
745
}
750
746
751
- public CompilerToVM getCompilerToVM () {
747
+ CompilerToVM getCompilerToVM () {
752
748
return compilerToVm ;
753
749
}
754
750
@@ -764,15 +760,11 @@ HotSpotJVMCIReflection getReflection() {
764
760
* compiler.
765
761
*/
766
762
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
- }
763
+ return type -> {
764
+ if (type instanceof HotSpotResolvedObjectTypeImpl hsType ) {
765
+ return compilerToVm .isTrustedForIntrinsics (hsType );
766
+ } else {
767
+ return false ;
776
768
}
777
769
};
778
770
}
@@ -822,23 +814,18 @@ public Field getMirror(ResolvedJavaField field) {
822
814
return null ;
823
815
}
824
816
825
- static class ErrorCreatingCompiler implements JVMCICompiler {
826
- private final RuntimeException t ;
827
-
828
- ErrorCreatingCompiler (RuntimeException t ) {
829
- this .t = t ;
830
- }
817
+ record ErrorCreatingCompiler (RuntimeException t ) implements JVMCICompiler {
831
818
832
819
@ Override
833
- public CompilationRequestResult compileMethod (CompilationRequest request ) {
834
- throw t ;
835
- }
820
+ public CompilationRequestResult compileMethod (CompilationRequest request ) {
821
+ throw t ;
822
+ }
836
823
837
- @ Override
838
- public boolean isGCSupported (int gcIdentifier ) {
839
- return false ;
824
+ @ Override
825
+ public boolean isGCSupported (int gcIdentifier ) {
826
+ return false ;
827
+ }
840
828
}
841
- }
842
829
843
830
@ Override
844
831
public JVMCICompiler getCompiler () {
@@ -913,7 +900,7 @@ JavaType lookupTypeInternal(String name, HotSpotResolvedObjectType accessingType
913
900
final HotSpotResolvedJavaType klass = compilerToVm .lookupType (name , hsAccessingType , resolve );
914
901
915
902
if (klass == null ) {
916
- assert resolve == false : name ;
903
+ assert ! resolve : name ;
917
904
return UnresolvedJavaType .create (name );
918
905
}
919
906
return klass ;
@@ -994,7 +981,7 @@ private boolean isIntrinsicSupported(int intrinsicIdentifier) {
994
981
* Shuts down the runtime.
995
982
*/
996
983
@ VMEntryPoint
997
- private void shutdown () throws Exception {
984
+ private void shutdown () {
998
985
if (isShutdown .compareAndSet (false , true )) {
999
986
// Cleaners are normally only processed when a new Cleaner is
1000
987
// instantiated so process all remaining cleaners now.
@@ -1010,18 +997,14 @@ private void shutdown() throws Exception {
1010
997
* Notify on completion of a bootstrap.
1011
998
*/
1012
999
@ VMEntryPoint
1013
- private void bootstrapFinished () throws Exception {
1000
+ private void bootstrapFinished () {
1014
1001
for (HotSpotVMEventListener vmEventListener : vmEventListeners ) {
1015
1002
vmEventListener .notifyBootstrapFinished ();
1016
1003
}
1017
1004
}
1018
1005
1019
1006
/**
1020
- * Notify on successful install into the CodeCache.
1021
- *
1022
- * @param hotSpotCodeCacheProvider
1023
- * @param installedCode
1024
- * @param compiledCode
1007
+ * Notify on successful installation into the CodeCache.
1025
1008
*/
1026
1009
void notifyInstall (HotSpotCodeCacheProvider hotSpotCodeCacheProvider , InstalledCode installedCode , CompiledCode compiledCode ) {
1027
1010
for (HotSpotVMEventListener vmEventListener : vmEventListeners ) {
@@ -1092,7 +1075,7 @@ public OutputStream getLogStream() {
1092
1075
return new OutputStream () {
1093
1076
1094
1077
@ Override
1095
- public void write (byte [] b , int off , int len ) throws IOException {
1078
+ public void write (byte [] b , int off , int len ) {
1096
1079
if (b == null ) {
1097
1080
throw new NullPointerException ();
1098
1081
} else if (off < 0 || off > b .length || len < 0 || (off + len ) > b .length || (off + len ) < 0 ) {
@@ -1104,12 +1087,12 @@ public void write(byte[] b, int off, int len) throws IOException {
1104
1087
}
1105
1088
1106
1089
@ Override
1107
- public void write (int b ) throws IOException {
1090
+ public void write (int b ) {
1108
1091
write (new byte []{(byte ) b }, 0 , 1 );
1109
1092
}
1110
1093
1111
1094
@ Override
1112
- public void flush () throws IOException {
1095
+ public void flush () {
1113
1096
compilerToVm .flushDebugOutput ();
1114
1097
}
1115
1098
};
@@ -1135,7 +1118,6 @@ public int getCountersSize() {
1135
1118
* Attempt to enlarge the number of per thread counters available. Requires a safepoint so
1136
1119
* resizing should be rare to avoid performance effects.
1137
1120
*
1138
- * @param newSize
1139
1121
* @return false if the resizing failed
1140
1122
*/
1141
1123
public boolean setCountersSize (int newSize ) {
@@ -1148,28 +1130,18 @@ public boolean setCountersSize(int newSize) {
1148
1130
* @return the offset in bytes
1149
1131
*/
1150
1132
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
- }
1133
+ return switch (kind ) {
1134
+ case Boolean -> compilerToVm .ARRAY_BOOLEAN_BASE_OFFSET ;
1135
+ case Byte -> compilerToVm .ARRAY_BYTE_BASE_OFFSET ;
1136
+ case Char -> compilerToVm .ARRAY_CHAR_BASE_OFFSET ;
1137
+ case Short -> compilerToVm .ARRAY_SHORT_BASE_OFFSET ;
1138
+ case Int -> compilerToVm .ARRAY_INT_BASE_OFFSET ;
1139
+ case Long -> compilerToVm .ARRAY_LONG_BASE_OFFSET ;
1140
+ case Float -> compilerToVm .ARRAY_FLOAT_BASE_OFFSET ;
1141
+ case Double -> compilerToVm .ARRAY_DOUBLE_BASE_OFFSET ;
1142
+ case Object -> compilerToVm .ARRAY_OBJECT_BASE_OFFSET ;
1143
+ default -> throw new JVMCIError ("%s" , kind );
1144
+ };
1173
1145
1174
1146
}
1175
1147
@@ -1179,29 +1151,18 @@ public int getArrayBaseOffset(JavaKind kind) {
1179
1151
* @return the scale in order to convert the index into a byte offset
1180
1152
*/
1181
1153
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
- }
1154
+ return switch (kind ) {
1155
+ case Boolean -> compilerToVm .ARRAY_BOOLEAN_INDEX_SCALE ;
1156
+ case Byte -> compilerToVm .ARRAY_BYTE_INDEX_SCALE ;
1157
+ case Char -> compilerToVm .ARRAY_CHAR_INDEX_SCALE ;
1158
+ case Short -> compilerToVm .ARRAY_SHORT_INDEX_SCALE ;
1159
+ case Int -> compilerToVm .ARRAY_INT_INDEX_SCALE ;
1160
+ case Long -> compilerToVm .ARRAY_LONG_INDEX_SCALE ;
1161
+ case Float -> compilerToVm .ARRAY_FLOAT_INDEX_SCALE ;
1162
+ case Double -> compilerToVm .ARRAY_DOUBLE_INDEX_SCALE ;
1163
+ case Object -> compilerToVm .ARRAY_OBJECT_INDEX_SCALE ;
1164
+ default -> throw new JVMCIError ("%s" , kind );
1165
+ };
1205
1166
}
1206
1167
1207
1168
/**
@@ -1334,22 +1295,26 @@ static void postTranslation(Object translatedObject) {
1334
1295
String value = Option .ForceTranslateFailure .getString ();
1335
1296
String toMatch ;
1336
1297
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 ());
1298
+ switch (translatedObject ) {
1299
+ case HotSpotResolvedJavaMethodImpl hotSpotResolvedJavaMethod -> {
1300
+ toMatch = hotSpotResolvedJavaMethod .format ("%H.%n" );
1301
+ type = "method" ;
1302
+ }
1303
+ case HotSpotResolvedObjectTypeImpl hotSpotResolvedObjectType -> {
1304
+ toMatch = hotSpotResolvedObjectType .toJavaName ();
1305
+ type = "type" ;
1306
+ }
1307
+ case HotSpotNmethod nmethod -> {
1308
+ if (nmethod .getMethod () != null ) {
1309
+ toMatch = nmethod .getMethod ().format ("%H.%n" );
1310
+ } else {
1311
+ toMatch = String .valueOf (nmethod .getName ());
1312
+ }
1313
+ type = "nmethod" ;
1314
+ }
1315
+ case null , default -> {
1316
+ return ;
1349
1317
}
1350
- type = "nmethod" ;
1351
- } else {
1352
- return ;
1353
1318
}
1354
1319
String [] filters = value .split ("," );
1355
1320
for (String filter : filters ) {
0 commit comments