graal icon indicating copy to clipboard operation
graal copied to clipboard

[GR-53929] How to create and load SVM auxiliary image?

Open JiangWork opened this issue 1 year ago • 5 comments

Hi, All.

From the link , it says:

Oracle GraalVM supports persisting code data structures to disk. This enables to almost eliminate warmup time for the first run of an application in an isolate/process. The SVM auxiliary image feature is used to persist and load the necessary data structures to the disk. Persisting the image can take a significant amount of time as compilation needs to be performed. However, loading is designed to be as fast as possible, typically almost instantaneous.

This is exactly what i want, I want to load different the auxiliary images when creating different Isolates. I know we can put required data in image heap when building the image. But in my case, the data is large than 2GB and each isolate needs a small portion of the data. I found the API exists: https://github.com/oracle/graal/blob/master/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/Isolates.java#L124

  public Builder auxiliaryImagePath(String filePath) {
                this.auxiliaryImagePath = filePath;
                return this;
            }

If i persist the data into image heap, it will resulting following exception:

Caused by: java.lang.NegativeArraySizeException: -2091511808
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.RelocatableBuffer.<init>(RelocatableBuffer.java:56)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.image.NativeImage.build(NativeImage.java:465)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:708)
        ... 5 more

My question is, is there any guide to instruct me to create such auxiliary images and load them?

JiangWork avatar Apr 14 '24 13:04 JiangWork

Hi @JiangWork, Thank you for reaching out to us! Does this guide answer your need? https://www.graalvm.org/latest/graalvm-as-a-platform/language-implementation-framework/AuxiliaryEngineCachingEnterprise/

selhagani avatar Apr 15 '24 16:04 selhagani

Hi, @selhagani Thanks for replying. I have already checked this doc. It uses JS framework, and underlying how to create the image is still black box. I am working on Java project.

JiangWork avatar Apr 16 '24 11:04 JiangWork

Hi @JiangWork, This is an EE-only feature. Mind that the auxiliary images must be created at image runtime and are compatible only with the same primary native-image that they were created with.

selhagani avatar Apr 24 '24 09:04 selhagani

Thanks, @selhagani Where can i found the code?

JiangWork avatar May 06 '24 06:05 JiangWork

Unfortunately, I'm unable to share the code with you as it's an EE-only feature. However, I understand the importance of this information for your needs. I'll make sure to relay your request to our team to develop documentation for this particular use case. Rest assured, I'll keep you informed about any updates regarding this matter.

selhagani avatar May 06 '24 15:05 selhagani

hi, @selhagani & @peter-hofer any update for this asking?

JiangWork avatar Sep 13 '24 07:09 JiangWork

We currently do not have such a guide. The images that this feature deals with are created from objects at image runtime, unlike the way that "regular" images (executables, shared libraries) are generated.

peter-hofer avatar Sep 17 '24 06:09 peter-hofer