|
20 | 20 | import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem;
|
21 | 21 | import io.quarkus.deployment.builditem.nativeimage.UnsafeAccessedFieldBuildItem;
|
22 | 22 | import io.quarkus.deployment.pkg.NativeConfig;
|
| 23 | +import io.quarkus.gizmo.AssignableResultHandle; |
23 | 24 | import io.quarkus.gizmo.BranchResult;
|
24 | 25 | import io.quarkus.gizmo.BytecodeCreator;
|
25 | 26 | import io.quarkus.gizmo.CatchBlockCreator;
|
@@ -176,29 +177,50 @@ public void write(String s, byte[] bytes) {
|
176 | 177 | // hack in reinitialization of process info classes
|
177 | 178 | if (!runtimeReinitializedClassBuildItems.isEmpty()) {
|
178 | 179 | MethodCreator runtimeReinitializedClasses = file
|
179 |
| - .getMethodCreator("runtimeReinitializedClasses", void.class) |
| 180 | + .getMethodCreator("runtimeReinitializedClasses", Class[].class) |
180 | 181 | .setModifiers(Modifier.PRIVATE | Modifier.STATIC);
|
181 | 182 |
|
182 | 183 | ResultHandle thisClass = runtimeReinitializedClasses.loadClassFromTCCL(GRAAL_FEATURE);
|
183 | 184 | ResultHandle cl = runtimeReinitializedClasses.invokeVirtualMethod(
|
184 | 185 | ofMethod(Class.class, "getClassLoader", ClassLoader.class),
|
185 | 186 | thisClass);
|
186 |
| - ResultHandle quarkus = runtimeReinitializedClasses.load("Quarkus"); |
187 |
| - ResultHandle imageSingleton = runtimeReinitializedClasses.invokeStaticMethod(IMAGE_SINGLETONS_LOOKUP, |
188 |
| - runtimeReinitializedClasses.loadClassFromTCCL(RUNTIME_CLASS_INITIALIZATION_SUPPORT)); |
189 |
| - for (RuntimeReinitializedClassBuildItem runtimeReinitializedClass : runtimeReinitializedClassBuildItems) { |
| 187 | + ResultHandle classesArray = runtimeReinitializedClasses.newArray(Class.class, |
| 188 | + runtimeReinitializedClasses.load(runtimeReinitializedClassBuildItems.size())); |
| 189 | + for (int i = 0; i < runtimeReinitializedClassBuildItems.size(); i++) { |
190 | 190 | TryBlock tc = runtimeReinitializedClasses.tryBlock();
|
191 | 191 | ResultHandle clazz = tc.invokeStaticMethod(
|
192 | 192 | ofMethod(Class.class, "forName", Class.class, String.class, boolean.class, ClassLoader.class),
|
193 |
| - tc.load(runtimeReinitializedClass.getClassName()), tc.load(false), cl); |
194 |
| - tc.invokeInterfaceMethod(RERUN_INITIALIZATION, imageSingleton, clazz, quarkus); |
195 |
| - |
| 193 | + tc.load(runtimeReinitializedClassBuildItems.get(i).getClassName()), tc.load(false), cl); |
| 194 | + tc.writeArrayValue(classesArray, i, clazz); |
196 | 195 | CatchBlockCreator cc = tc.addCatch(Throwable.class);
|
197 | 196 | cc.invokeVirtualMethod(ofMethod(Throwable.class, "printStackTrace", void.class), cc.getCaughtException());
|
198 | 197 | }
|
199 |
| - runtimeReinitializedClasses.returnVoid(); |
| 198 | + runtimeReinitializedClasses.returnValue(classesArray); |
200 | 199 |
|
201 |
| - overallCatch.invokeStaticMethod(runtimeReinitializedClasses.getMethodDescriptor()); |
| 200 | + ResultHandle classes = overallCatch.invokeStaticMethod(runtimeReinitializedClasses.getMethodDescriptor()); |
| 201 | + |
| 202 | + ResultHandle graalVMVersion = overallCatch.invokeStaticMethod(GRAALVM_VERSION_GET_CURRENT); |
| 203 | + BranchResult graalVm23_1Test = overallCatch |
| 204 | + .ifGreaterEqualZero(overallCatch.invokeVirtualMethod(GRAALVM_VERSION_COMPARE_TO, graalVMVersion, |
| 205 | + overallCatch.marshalAsArray(int.class, overallCatch.load(23), overallCatch.load(1)))); |
| 206 | + /* GraalVM >= 23.1 */ |
| 207 | + try (BytecodeCreator greaterEqual23_1 = graalVm23_1Test.trueBranch()) { |
| 208 | + greaterEqual23_1.invokeStaticMethod(INITIALIZE_CLASSES_AT_RUN_TIME, classes); |
| 209 | + } |
| 210 | + /* GraalVM < 23.1 */ |
| 211 | + try (BytecodeCreator less23_1 = graalVm23_1Test.falseBranch()) { |
| 212 | + ResultHandle quarkus = less23_1.load("Quarkus"); |
| 213 | + ResultHandle imageSingleton = less23_1.invokeStaticMethod(IMAGE_SINGLETONS_LOOKUP, |
| 214 | + less23_1.loadClassFromTCCL(RUNTIME_CLASS_INITIALIZATION_SUPPORT)); |
| 215 | + ResultHandle arraySize = less23_1.arrayLength(classes); |
| 216 | + AssignableResultHandle index = less23_1.createVariable(int.class); |
| 217 | + less23_1.assign(index, less23_1.load(0)); |
| 218 | + try (BytecodeCreator loop = less23_1.whileLoop(c -> c.ifIntegerLessThan(index, arraySize)).block()) { |
| 219 | + loop.invokeInterfaceMethod(RERUN_INITIALIZATION, imageSingleton, loop.readArrayValue(classes, index), |
| 220 | + quarkus); |
| 221 | + loop.assign(index, loop.increment(index)); |
| 222 | + } |
| 223 | + } |
202 | 224 | }
|
203 | 225 |
|
204 | 226 | // Ensure registration of fields being accessed through unsafe is done last to ensure that the class
|
|
0 commit comments