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 ;
@@ -90,7 +89,6 @@ public final class HotSpotJVMCIRuntime implements JVMCIRuntime {
9089 private HotSpotResolvedObjectTypeImpl constantCallSiteType ;
9190 private HotSpotResolvedObjectTypeImpl callSiteType ;
9291 private HotSpotResolvedObjectTypeImpl javaLangString ;
93- private HotSpotResolvedObjectTypeImpl javaLangClass ;
9492 private HotSpotResolvedObjectTypeImpl throwableType ;
9593 private HotSpotResolvedObjectTypeImpl serializableType ;
9694 private HotSpotResolvedObjectTypeImpl cloneableType ;
@@ -118,13 +116,6 @@ HotSpotResolvedObjectTypeImpl getJavaLangString() {
118116 return javaLangString ;
119117 }
120118
121- HotSpotResolvedObjectTypeImpl getJavaLangClass () {
122- if (javaLangClass == null ) {
123- javaLangClass = (HotSpotResolvedObjectTypeImpl ) fromClass (Class .class );
124- }
125- return javaLangClass ;
126- }
127-
128119 HotSpotResolvedObjectTypeImpl getJavaLangCloneable () {
129120 if (cloneableType == null ) {
130121 cloneableType = (HotSpotResolvedObjectTypeImpl ) fromClass (Cloneable .class );
@@ -188,7 +179,7 @@ public static HotSpotJVMCIRuntime runtime() {
188179 synchronized (JVMCI .class ) {
189180 result = instance ;
190181 if (result == null ) {
191- try (InitTimer t = timer ("HotSpotJVMCIRuntime.<init>" )) {
182+ try (InitTimer _ = timer ("HotSpotJVMCIRuntime.<init>" )) {
192183 instance = result = new HotSpotJVMCIRuntime ();
193184
194185 // Can only do eager initialization of the JVMCI compiler
@@ -426,8 +417,6 @@ static float stringSimiliarity(String str1, String str2) {
426417 /**
427418 * Parses all system properties starting with {@value #JVMCI_OPTION_PROPERTY_PREFIX} and
428419 * initializes the options based on their values.
429- *
430- * @param runtime
431420 */
432421 static void parse (HotSpotJVMCIRuntime runtime ) {
433422 Map <String , String > savedProps = jdk .vm .ci .services .Services .getSavedProperties ();
@@ -452,9 +441,8 @@ static void parse(HotSpotJVMCIRuntime runtime) {
452441 }
453442 }
454443 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 ) {
458446 option .init (e .getValue ());
459447 }
460448 }
@@ -491,15 +479,15 @@ public static JavaKind getHostWordKind() {
491479 return runtime ().getHostJVMCIBackend ().getCodeCache ().getTarget ().wordJavaKind ;
492480 }
493481
494- protected final CompilerToVM compilerToVm ;
482+ final CompilerToVM compilerToVm ;
495483
496- protected final HotSpotVMConfigStore configStore ;
497- protected final HotSpotVMConfig config ;
484+ final HotSpotVMConfigStore configStore ;
485+ final HotSpotVMConfig config ;
498486 private final JVMCIBackend hostBackend ;
499487
500488 private final JVMCICompilerFactory compilerFactory ;
501489 private volatile JVMCICompiler compiler ;
502- protected final HotSpotJVMCIReflection reflection ;
490+ final HotSpotJVMCIReflection reflection ;
503491
504492 private volatile boolean creatingCompiler ;
505493
@@ -571,7 +559,7 @@ public KlassWeakReference(Long klassPointer, HotSpotResolvedObjectTypeImpl refer
571559 private HotSpotJVMCIRuntime () {
572560 compilerToVm = new CompilerToVM ();
573561
574- try (InitTimer t = timer ("HotSpotVMConfig<init>" )) {
562+ try (InitTimer _ = timer ("HotSpotVMConfig<init>" )) {
575563 configStore = new HotSpotVMConfigStore (compilerToVm );
576564 config = new HotSpotVMConfig (configStore );
577565 }
@@ -589,7 +577,7 @@ private HotSpotJVMCIRuntime() {
589577 // Initialize the Option values.
590578 Option .parse (this );
591579
592- try (InitTimer t = timer ("create JVMCI backend:" , backendFactory .getArchitecture ())) {
580+ try (InitTimer _ = timer ("create JVMCI backend:" , backendFactory .getArchitecture ())) {
593581 hostBackend = registerBackend (backendFactory .createJVMCIBackend (this , null ));
594582 }
595583
@@ -744,11 +732,11 @@ public HotSpotVMConfigStore getConfigStore() {
744732 return configStore ;
745733 }
746734
747- public HotSpotVMConfig getConfig () {
735+ HotSpotVMConfig getConfig () {
748736 return config ;
749737 }
750738
751- public CompilerToVM getCompilerToVM () {
739+ CompilerToVM getCompilerToVM () {
752740 return compilerToVm ;
753741 }
754742
@@ -764,15 +752,11 @@ HotSpotJVMCIReflection getReflection() {
764752 * compiler.
765753 */
766754 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 ;
776760 }
777761 };
778762 }
@@ -822,23 +806,18 @@ public Field getMirror(ResolvedJavaField field) {
822806 return null ;
823807 }
824808
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 {
831810
832811 @ Override
833812 public CompilationRequestResult compileMethod (CompilationRequest request ) {
834- throw t ;
835- }
813+ throw t ;
814+ }
836815
837816 @ Override
838817 public boolean isGCSupported (int gcIdentifier ) {
839- return false ;
818+ return false ;
819+ }
840820 }
841- }
842821
843822 @ Override
844823 public JVMCICompiler getCompiler () {
@@ -867,7 +846,7 @@ public JVMCICompiler getCompiler() {
867846 * Converts a name to a Java type. This method attempts to resolve {@code name} to a
868847 * {@link ResolvedJavaType}.
869848 *
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
871850 * @param accessingType the context of resolution which must be non-null
872851 * @param resolve specifies whether resolution failure results in an unresolved type being
873852 * return or a {@link LinkageError} being thrown
@@ -913,7 +892,7 @@ JavaType lookupTypeInternal(String name, HotSpotResolvedObjectType accessingType
913892 final HotSpotResolvedJavaType klass = compilerToVm .lookupType (name , hsAccessingType , resolve );
914893
915894 if (klass == null ) {
916- assert resolve == false : name ;
895+ assert ! resolve : name ;
917896 return UnresolvedJavaType .create (name );
918897 }
919898 return klass ;
@@ -994,7 +973,7 @@ private boolean isIntrinsicSupported(int intrinsicIdentifier) {
994973 * Shuts down the runtime.
995974 */
996975 @ VMEntryPoint
997- private void shutdown () throws Exception {
976+ private void shutdown () {
998977 if (isShutdown .compareAndSet (false , true )) {
999978 // Cleaners are normally only processed when a new Cleaner is
1000979 // instantiated so process all remaining cleaners now.
@@ -1010,18 +989,14 @@ private void shutdown() throws Exception {
1010989 * Notify on completion of a bootstrap.
1011990 */
1012991 @ VMEntryPoint
1013- private void bootstrapFinished () throws Exception {
992+ private void bootstrapFinished () {
1014993 for (HotSpotVMEventListener vmEventListener : vmEventListeners ) {
1015994 vmEventListener .notifyBootstrapFinished ();
1016995 }
1017996 }
1018997
1019998 /**
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.
10251000 */
10261001 void notifyInstall (HotSpotCodeCacheProvider hotSpotCodeCacheProvider , InstalledCode installedCode , CompiledCode compiledCode ) {
10271002 for (HotSpotVMEventListener vmEventListener : vmEventListeners ) {
@@ -1092,7 +1067,7 @@ public OutputStream getLogStream() {
10921067 return new OutputStream () {
10931068
10941069 @ Override
1095- public void write (byte [] b , int off , int len ) throws IOException {
1070+ public void write (byte [] b , int off , int len ) {
10961071 if (b == null ) {
10971072 throw new NullPointerException ();
10981073 } 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 {
11041079 }
11051080
11061081 @ Override
1107- public void write (int b ) throws IOException {
1082+ public void write (int b ) {
11081083 write (new byte []{(byte ) b }, 0 , 1 );
11091084 }
11101085
11111086 @ Override
1112- public void flush () throws IOException {
1087+ public void flush () {
11131088 compilerToVm .flushDebugOutput ();
11141089 }
11151090 };
@@ -1135,7 +1110,6 @@ public int getCountersSize() {
11351110 * Attempt to enlarge the number of per thread counters available. Requires a safepoint so
11361111 * resizing should be rare to avoid performance effects.
11371112 *
1138- * @param newSize
11391113 * @return false if the resizing failed
11401114 */
11411115 public boolean setCountersSize (int newSize ) {
@@ -1148,28 +1122,18 @@ public boolean setCountersSize(int newSize) {
11481122 * @return the offset in bytes
11491123 */
11501124 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+ };
11731137
11741138 }
11751139
@@ -1179,29 +1143,18 @@ public int getArrayBaseOffset(JavaKind kind) {
11791143 * @return the scale in order to convert the index into a byte offset
11801144 */
11811145 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+ };
12051158 }
12061159
12071160 /**
@@ -1334,22 +1287,26 @@ static void postTranslation(Object translatedObject) {
13341287 String value = Option .ForceTranslateFailure .getString ();
13351288 String toMatch ;
13361289 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 ;
13491309 }
1350- type = "nmethod" ;
1351- } else {
1352- return ;
13531310 }
13541311 String [] filters = value .split ("," );
13551312 for (String filter : filters ) {
0 commit comments