2525import static jdk .vm .ci .common .InitTimer .timer ;
2626import static jdk .vm .ci .services .Services .IS_IN_NATIVE_IMAGE ;
2727
28- import java .io .IOException ;
2928import java .io .ByteArrayOutputStream ;
3029import java .io .OutputStream ;
3130import java .io .PrintStream ;
@@ -188,7 +187,7 @@ public static HotSpotJVMCIRuntime runtime() {
188187 synchronized (JVMCI .class ) {
189188 result = instance ;
190189 if (result == null ) {
191- try (InitTimer t = timer ("HotSpotJVMCIRuntime.<init>" )) {
190+ try (InitTimer _ = timer ("HotSpotJVMCIRuntime.<init>" )) {
192191 instance = result = new HotSpotJVMCIRuntime ();
193192
194193 // Can only do eager initialization of the JVMCI compiler
@@ -426,8 +425,6 @@ static float stringSimiliarity(String str1, String str2) {
426425 /**
427426 * Parses all system properties starting with {@value #JVMCI_OPTION_PROPERTY_PREFIX} and
428427 * initializes the options based on their values.
429- *
430- * @param runtime
431428 */
432429 static void parse (HotSpotJVMCIRuntime runtime ) {
433430 Map <String , String > savedProps = jdk .vm .ci .services .Services .getSavedProperties ();
@@ -452,9 +449,8 @@ static void parse(HotSpotJVMCIRuntime runtime) {
452449 }
453450 }
454451 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 ) {
458454 option .init (e .getValue ());
459455 }
460456 }
@@ -491,15 +487,15 @@ public static JavaKind getHostWordKind() {
491487 return runtime ().getHostJVMCIBackend ().getCodeCache ().getTarget ().wordJavaKind ;
492488 }
493489
494- protected final CompilerToVM compilerToVm ;
490+ final CompilerToVM compilerToVm ;
495491
496- protected final HotSpotVMConfigStore configStore ;
497- protected final HotSpotVMConfig config ;
492+ final HotSpotVMConfigStore configStore ;
493+ final HotSpotVMConfig config ;
498494 private final JVMCIBackend hostBackend ;
499495
500496 private final JVMCICompilerFactory compilerFactory ;
501497 private volatile JVMCICompiler compiler ;
502- protected final HotSpotJVMCIReflection reflection ;
498+ final HotSpotJVMCIReflection reflection ;
503499
504500 private volatile boolean creatingCompiler ;
505501
@@ -571,7 +567,7 @@ public KlassWeakReference(Long klassPointer, HotSpotResolvedObjectTypeImpl refer
571567 private HotSpotJVMCIRuntime () {
572568 compilerToVm = new CompilerToVM ();
573569
574- try (InitTimer t = timer ("HotSpotVMConfig<init>" )) {
570+ try (InitTimer _ = timer ("HotSpotVMConfig<init>" )) {
575571 configStore = new HotSpotVMConfigStore (compilerToVm );
576572 config = new HotSpotVMConfig (configStore );
577573 }
@@ -589,7 +585,7 @@ private HotSpotJVMCIRuntime() {
589585 // Initialize the Option values.
590586 Option .parse (this );
591587
592- try (InitTimer t = timer ("create JVMCI backend:" , backendFactory .getArchitecture ())) {
588+ try (InitTimer _ = timer ("create JVMCI backend:" , backendFactory .getArchitecture ())) {
593589 hostBackend = registerBackend (backendFactory .createJVMCIBackend (this , null ));
594590 }
595591
@@ -744,11 +740,11 @@ public HotSpotVMConfigStore getConfigStore() {
744740 return configStore ;
745741 }
746742
747- public HotSpotVMConfig getConfig () {
743+ HotSpotVMConfig getConfig () {
748744 return config ;
749745 }
750746
751- public CompilerToVM getCompilerToVM () {
747+ CompilerToVM getCompilerToVM () {
752748 return compilerToVm ;
753749 }
754750
@@ -764,15 +760,11 @@ HotSpotJVMCIReflection getReflection() {
764760 * compiler.
765761 */
766762 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 ;
776768 }
777769 };
778770 }
@@ -822,23 +814,18 @@ public Field getMirror(ResolvedJavaField field) {
822814 return null ;
823815 }
824816
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 {
831818
832819 @ Override
833- public CompilationRequestResult compileMethod (CompilationRequest request ) {
834- throw t ;
835- }
820+ public CompilationRequestResult compileMethod (CompilationRequest request ) {
821+ throw t ;
822+ }
836823
837- @ Override
838- public boolean isGCSupported (int gcIdentifier ) {
839- return false ;
824+ @ Override
825+ public boolean isGCSupported (int gcIdentifier ) {
826+ return false ;
827+ }
840828 }
841- }
842829
843830 @ Override
844831 public JVMCICompiler getCompiler () {
@@ -913,7 +900,7 @@ JavaType lookupTypeInternal(String name, HotSpotResolvedObjectType accessingType
913900 final HotSpotResolvedJavaType klass = compilerToVm .lookupType (name , hsAccessingType , resolve );
914901
915902 if (klass == null ) {
916- assert resolve == false : name ;
903+ assert ! resolve : name ;
917904 return UnresolvedJavaType .create (name );
918905 }
919906 return klass ;
@@ -994,7 +981,7 @@ private boolean isIntrinsicSupported(int intrinsicIdentifier) {
994981 * Shuts down the runtime.
995982 */
996983 @ VMEntryPoint
997- private void shutdown () throws Exception {
984+ private void shutdown () {
998985 if (isShutdown .compareAndSet (false , true )) {
999986 // Cleaners are normally only processed when a new Cleaner is
1000987 // instantiated so process all remaining cleaners now.
@@ -1010,18 +997,14 @@ private void shutdown() throws Exception {
1010997 * Notify on completion of a bootstrap.
1011998 */
1012999 @ VMEntryPoint
1013- private void bootstrapFinished () throws Exception {
1000+ private void bootstrapFinished () {
10141001 for (HotSpotVMEventListener vmEventListener : vmEventListeners ) {
10151002 vmEventListener .notifyBootstrapFinished ();
10161003 }
10171004 }
10181005
10191006 /**
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.
10251008 */
10261009 void notifyInstall (HotSpotCodeCacheProvider hotSpotCodeCacheProvider , InstalledCode installedCode , CompiledCode compiledCode ) {
10271010 for (HotSpotVMEventListener vmEventListener : vmEventListeners ) {
@@ -1092,7 +1075,7 @@ public OutputStream getLogStream() {
10921075 return new OutputStream () {
10931076
10941077 @ Override
1095- public void write (byte [] b , int off , int len ) throws IOException {
1078+ public void write (byte [] b , int off , int len ) {
10961079 if (b == null ) {
10971080 throw new NullPointerException ();
10981081 } 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 {
11041087 }
11051088
11061089 @ Override
1107- public void write (int b ) throws IOException {
1090+ public void write (int b ) {
11081091 write (new byte []{(byte ) b }, 0 , 1 );
11091092 }
11101093
11111094 @ Override
1112- public void flush () throws IOException {
1095+ public void flush () {
11131096 compilerToVm .flushDebugOutput ();
11141097 }
11151098 };
@@ -1135,7 +1118,6 @@ public int getCountersSize() {
11351118 * Attempt to enlarge the number of per thread counters available. Requires a safepoint so
11361119 * resizing should be rare to avoid performance effects.
11371120 *
1138- * @param newSize
11391121 * @return false if the resizing failed
11401122 */
11411123 public boolean setCountersSize (int newSize ) {
@@ -1148,28 +1130,18 @@ public boolean setCountersSize(int newSize) {
11481130 * @return the offset in bytes
11491131 */
11501132 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+ };
11731145
11741146 }
11751147
@@ -1179,29 +1151,18 @@ public int getArrayBaseOffset(JavaKind kind) {
11791151 * @return the scale in order to convert the index into a byte offset
11801152 */
11811153 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+ };
12051166 }
12061167
12071168 /**
@@ -1334,22 +1295,26 @@ static void postTranslation(Object translatedObject) {
13341295 String value = Option .ForceTranslateFailure .getString ();
13351296 String toMatch ;
13361297 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 ;
13491317 }
1350- type = "nmethod" ;
1351- } else {
1352- return ;
13531318 }
13541319 String [] filters = value .split ("," );
13551320 for (String filter : filters ) {
0 commit comments