Skip to content

Commit

Permalink
Merge pull request #17986 from geoand/#17887
Browse files Browse the repository at this point in the history
Use the GraalVM API  instead of flag to force build-time init
  • Loading branch information
geoand authored Jun 18, 2021
2 parents 608c541 + a85c687 commit e4dbda5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ public NativeImageInvokerInfo build() {
}

handleAdditionalProperties(nativeConfig, nativeImageArgs, isContainerBuild, outputDir);
nativeImageArgs.add("--initialize-at-build-time=");
nativeImageArgs.add(
"-H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime"); //the default collection policy results in full GC's 50% of the time
nativeImageArgs.add("-H:+JNI");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class NativeImageAutoFeatureStep {
private static final String GRAAL_AUTOFEATURE = "io/quarkus/runner/AutoFeature";
private static final MethodDescriptor IMAGE_SINGLETONS_LOOKUP = ofMethod(ImageSingletons.class, "lookup", Object.class,
Class.class);
private static final MethodDescriptor BUILD_TIME_INITIALIZATION = ofMethod(
"org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport",
"initializeAtBuildTime", void.class, String.class, String.class);
private static final MethodDescriptor INITIALIZE_CLASSES_AT_RUN_TIME = ofMethod(RuntimeClassInitialization.class,
"initializeAtRunTime", void.class, Class[].class);
private static final MethodDescriptor INITIALIZE_PACKAGES_AT_RUN_TIME = ofMethod(RuntimeClassInitialization.class,
Expand Down Expand Up @@ -117,6 +120,13 @@ public void write(String s, byte[] bytes) {
cc.invokeVirtualMethod(ofMethod(Throwable.class, "printStackTrace", void.class), cc.getCaughtException());
}

ResultHandle imageSingleton = overallCatch.invokeStaticMethod(IMAGE_SINGLETONS_LOOKUP,
overallCatch.loadClass("org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport"));
overallCatch.invokeInterfaceMethod(BUILD_TIME_INITIALIZATION,
imageSingleton,
overallCatch.load(""), // empty string means everything
overallCatch.load("Quarkus build time init default"));

if (!runtimeInitializedClassBuildItems.isEmpty()) {
ResultHandle thisClass = overallCatch.loadClass(GRAAL_AUTOFEATURE);
ResultHandle cl = overallCatch.invokeVirtualMethod(ofMethod(Class.class, "getClassLoader", ClassLoader.class),
Expand Down Expand Up @@ -153,15 +163,13 @@ public void write(String s, byte[] bytes) {
ResultHandle thisClass = overallCatch.loadClass(GRAAL_AUTOFEATURE);
ResultHandle cl = overallCatch.invokeVirtualMethod(ofMethod(Class.class, "getClassLoader", ClassLoader.class),
thisClass);
ResultHandle initSingleton = overallCatch.invokeStaticMethod(IMAGE_SINGLETONS_LOOKUP,
overallCatch.loadClass("org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport"));
ResultHandle quarkus = overallCatch.load("Quarkus");
for (RuntimeReinitializedClassBuildItem runtimeReinitializedClass : runtimeReinitializedClassBuildItems) {
TryBlock tc = overallCatch.tryBlock();
ResultHandle clazz = tc.invokeStaticMethod(
ofMethod(Class.class, "forName", Class.class, String.class, boolean.class, ClassLoader.class),
tc.load(runtimeReinitializedClass.getClassName()), tc.load(false), cl);
tc.invokeInterfaceMethod(RERUN_INITIALIZATION, initSingleton, clazz, quarkus);
tc.invokeInterfaceMethod(RERUN_INITIALIZATION, imageSingleton, clazz, quarkus);

CatchBlockCreator cc = tc.addCatch(Throwable.class);
cc.invokeVirtualMethod(ofMethod(Throwable.class, "printStackTrace", void.class), cc.getCaughtException());
Expand Down

0 comments on commit e4dbda5

Please sign in to comment.