2828import java .util .List ;
2929
3030import org .graalvm .compiler .core .common .alloc .RegisterAllocationConfig ;
31+ import org .graalvm .compiler .core .riscv64 .RISCV64ReflectionUtil ;
3132import org .graalvm .compiler .debug .GraalError ;
3233import org .graalvm .compiler .hotspot .GraalHotSpotVMConfig ;
3334import org .graalvm .compiler .hotspot .HotSpotBackend ;
5253import org .graalvm .compiler .nodes .spi .CoreProviders ;
5354import org .graalvm .compiler .options .OptionValues ;
5455import org .graalvm .compiler .phases .BasePhase ;
55- import org .graalvm .compiler .phases .common .AddressLoweringByUsePhase ;
56+ import org .graalvm .compiler .phases .common .AddressLoweringPhase ;
5657import org .graalvm .compiler .phases .tiers .CompilerConfiguration ;
5758import org .graalvm .compiler .serviceprovider .ServiceProvider ;
5859
@@ -75,10 +76,10 @@ public String getName() {
7576
7677 @ Override
7778 public Class <? extends Architecture > getArchitecture () {
78- try {
79- return Class . forName ( "jdk.vm.ci. riscv64.RISCV64" ). asSubclass ( Architecture . class );
80- } catch ( ClassNotFoundException e ) {
81- // Running Native Image for RISC-V requires a JDK with JVMCI for RISC-V
79+ Class <?> riscv64 = RISCV64ReflectionUtil . lookupClass ( true , "jdk.vm.ci.riscv64.RISCV64" );
80+ if ( riscv64 != null ) {
81+ return riscv64 . asSubclass ( Architecture . class );
82+ } else {
8283 return null ;
8384 }
8485 }
@@ -118,17 +119,12 @@ public ReferenceMapBuilder newReferenceMapBuilder(int totalFrameSize) {
118119
119120 @ Override
120121 protected HotSpotRegistersProvider createRegisters () {
121- try {
122- Class <?> riscv64 = Class .forName ("jdk.vm.ci.riscv64.RISCV64" );
123- Class <?> riscv64HotSpotRegisterConfig = Class .forName ("jdk.vm.ci.hotspot.riscv64.RISCV64HotSpotRegisterConfig" );
124- Register tp = (Register ) riscv64HotSpotRegisterConfig .getField ("tp" ).get (null );
125- Register x27 = (Register ) riscv64 .getField ("x27" ).get (null );
126- Register sp = (Register ) riscv64HotSpotRegisterConfig .getField ("sp" ).get (null );
127- return new HotSpotRegisters (tp , x27 , sp );
128- } catch (IllegalAccessException | ClassNotFoundException | NoSuchFieldException e ) {
129- e .printStackTrace ();
130- throw GraalError .shouldNotReachHere ("Running Native Image for RISC-V requires a JDK with JVMCI for RISC-V" );
131- }
122+ Class <?> riscv64 = RISCV64ReflectionUtil .lookupClass (false , "jdk.vm.ci.riscv64.RISCV64" );
123+ Class <?> riscv64HotSpotRegisterConfig = RISCV64ReflectionUtil .lookupClass (false , "jdk.vm.ci.hotspot.riscv64.RISCV64HotSpotRegisterConfig" );
124+ Register tp = RISCV64ReflectionUtil .readStaticField (riscv64HotSpotRegisterConfig , "tp" );
125+ Register x27 = RISCV64ReflectionUtil .readStaticField (riscv64 , "x27" );
126+ Register sp = RISCV64ReflectionUtil .readStaticField (riscv64HotSpotRegisterConfig , "sp" );
127+ return new HotSpotRegisters (tp , x27 , sp );
132128 }
133129
134130 @ Override
@@ -141,7 +137,7 @@ protected HotSpotHostForeignCallsProvider createForeignCalls(HotSpotJVMCIRuntime
141137 protected HotSpotSuitesProvider createSuites (GraalHotSpotVMConfig config , HotSpotGraalRuntimeProvider runtime , CompilerConfiguration compilerConfiguration , Plugins plugins ,
142138 HotSpotRegistersProvider registers , HotSpotReplacementsImpl replacements , OptionValues options ) {
143139 DefaultSuitesCreator suitesCreator = new DefaultSuitesCreator (compilerConfiguration , plugins );
144- BasePhase <CoreProviders > addressLoweringPhase = new AddressLoweringByUsePhase (null );
140+ BasePhase <CoreProviders > addressLoweringPhase = new AddressLoweringPhase (null );
145141 return new AddressLoweringHotSpotSuitesProvider (suitesCreator , config , runtime , addressLoweringPhase );
146142 }
147143
@@ -156,39 +152,34 @@ protected HotSpotLoweringProvider createLowerer(HotSpotGraalRuntimeProvider graa
156152 protected Value [] createNativeABICallerSaveRegisters (@ SuppressWarnings ("unused" ) GraalHotSpotVMConfig config , RegisterConfig regConfig ) {
157153 List <Register > callerSave = new ArrayList <>(regConfig .getAllocatableRegisters ().asList ());
158154 // Removing callee-saved registers.
159- try {
160- Class <?> riscv64 = Class .forName ("jdk.vm.ci.riscv64.RISCV64" );
161- /* General Purpose Registers. */
162- callerSave .remove (riscv64 .getField ("x2" ).get (null ));
163- callerSave .remove (riscv64 .getField ("x8" ).get (null ));
164- callerSave .remove (riscv64 .getField ("x9" ).get (null ));
165- callerSave .remove (riscv64 .getField ("x10" ).get (null ));
166- callerSave .remove (riscv64 .getField ("x19" ).get (null ));
167- callerSave .remove (riscv64 .getField ("x20" ).get (null ));
168- callerSave .remove (riscv64 .getField ("x21" ).get (null ));
169- callerSave .remove (riscv64 .getField ("x22" ).get (null ));
170- callerSave .remove (riscv64 .getField ("x23" ).get (null ));
171- callerSave .remove (riscv64 .getField ("x24" ).get (null ));
172- callerSave .remove (riscv64 .getField ("x25" ).get (null ));
173- callerSave .remove (riscv64 .getField ("x26" ).get (null ));
174- callerSave .remove (riscv64 .getField ("x27" ).get (null ));
175- /* Floating-Point Registers. */
176- callerSave .remove (riscv64 .getField ("f8" ).get (null ));
177- callerSave .remove (riscv64 .getField ("f9" ).get (null ));
178- callerSave .remove (riscv64 .getField ("f10" ).get (null ));
179- callerSave .remove (riscv64 .getField ("f19" ).get (null ));
180- callerSave .remove (riscv64 .getField ("f20" ).get (null ));
181- callerSave .remove (riscv64 .getField ("f21" ).get (null ));
182- callerSave .remove (riscv64 .getField ("f22" ).get (null ));
183- callerSave .remove (riscv64 .getField ("f23" ).get (null ));
184- callerSave .remove (riscv64 .getField ("f24" ).get (null ));
185- callerSave .remove (riscv64 .getField ("f25" ).get (null ));
186- callerSave .remove (riscv64 .getField ("f26" ).get (null ));
187- callerSave .remove (riscv64 .getField ("f27" ).get (null ));
188- } catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException e ) {
189- e .printStackTrace ();
190- throw GraalError .shouldNotReachHere ("Running Native Image for RISC-V requires a JDK with JVMCI for RISC-V" );
191- }
155+ Class <?> riscv64 = RISCV64ReflectionUtil .lookupClass (false , "jdk.vm.ci.riscv64.RISCV64" );
156+ /* General Purpose Registers. */
157+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "x2" ));
158+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "x8" ));
159+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "x9" ));
160+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "x10" ));
161+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "x19" ));
162+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "x20" ));
163+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "x21" ));
164+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "x22" ));
165+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "x23" ));
166+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "x24" ));
167+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "x25" ));
168+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "x26" ));
169+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "x27" ));
170+ /* Floating-Point Registers. */
171+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "f8" ));
172+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "f9" ));
173+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "f10" ));
174+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "f19" ));
175+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "f20" ));
176+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "f21" ));
177+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "f22" ));
178+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "f23" ));
179+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "f24" ));
180+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "f25" ));
181+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "f26" ));
182+ callerSave .remove (RISCV64ReflectionUtil .readStaticField (riscv64 , "f27" ));
192183
193184 Value [] nativeABICallerSaveRegisters = new Value [callerSave .size ()];
194185 for (int i = 0 ; i < callerSave .size (); i ++) {
0 commit comments