graal icon indicating copy to clipboard operation
graal copied to clipboard

Return long option from Isolate parameters

Open ziyilin opened this issue 3 years ago • 3 comments

Add an API to return long typed option values (-Xmx,-Xms and -Xmn) that are setting in Isolate parameters.

This PR fixes the issue https://github.com/oracle/graal/issues/4851

ziyilin avatar Aug 29 '22 07:08 ziyilin

Hi @ziyilin, Thank you for contributing to GraalVM, have you discussed these changes with a member of the GraalVM team already and want them to review your PR? if yes, please tag them here

oubidar-Abderrahim avatar Sep 05 '22 09:09 oubidar-Abderrahim

No, I don't have a designated reviewer.

ziyilin avatar Sep 06 '22 02:09 ziyilin

@christianhaeubl can you please review this? or suggest someone who can review? let me know if you want me to mirror this to bitbucket. Thank you

oubidar-Abderrahim avatar Sep 06 '22 10:09 oubidar-Abderrahim

@ziyilin : do you need this method for any particular use case? I think that the method getIntOptionValue() is unused at the moment, so I would like to remove this method.

christianhaeubl avatar Oct 03 '22 10:10 christianhaeubl

@christianhaeubl Yes, we are using it to set the Xmx, Xms and Xmn for native image library at runtime when the isolate is created, so that the users don't have to reset the memory by building the image again. This is the code to create an isolate with parameters:

    @Uninterruptible(reason = "Thread state not set up yet.", calleeMustBe = false)
    @CEntryPointOptions(prologue = CEntryPointOptions.NoPrologue.class, epilogue = CEntryPointOptions.NoEpilogue.class)
    @CEntryPoint(name = "create_isolate_with_params")
    public static int createIsolateWithParams(int argc, CCharPointerPointer argv, CEntryPointNativeFunctions.IsolatePointer isolatePr, CEntryPointNativeFunctions.IsolateThreadPointer thread) {
        CEntryPointCreateIsolateParameters args = StackValue.get(CEntryPointCreateIsolateParameters.class);
        args.setVersion(4);
        args.setArgc(argc);
        args.setArgv(argv);
        args.setIgnoreUnrecognizedArguments(false);
        args.setExitWhenArgumentParsingFails(true);
        int result = CEntryPointActions.enterCreateIsolate(args);
        if (result != 0) {
            return result;
        } else {
            if (isolatePr.isNonNull()) {
                isolatePr.write(CurrentIsolate.getIsolate());
            }
            if (thread.isNonNull()) {
                thread.write(CurrentIsolate.getCurrentThread());
            }
            int Xmx = IsolateArgumentParser.getIntOptionValue(IsolateArgumentParser.getOptionIndex(SubstrateGCOptions.MaxHeapSize));
            SubstrateGCOptions.MaxHeapSize.update((long) Xmx);
            int Xms = IsolateArgumentParser.getIntOptionValue(IsolateArgumentParser.getOptionIndex(SubstrateGCOptions.MinHeapSize));
            SubstrateGCOptions.MaxHeapSize.update((long) Xms);
            int Xmn = IsolateArgumentParser.getIntOptionValue(IsolateArgumentParser.getOptionIndex(SubstrateGCOptions.MaxNewSize));
            SubstrateGCOptions.MaxHeapSize.update((long) Xmn);
            return CEntryPointActions.leave();
        }
    }

Currently, we have to get the int option value and cast it to long, which is not safe.

ziyilin avatar Oct 10 '22 02:10 ziyilin

@ziyilin: thanks! @oubidar-Abderrahim: can you merge this PR to master?

christianhaeubl avatar Oct 10 '22 07:10 christianhaeubl

@oubidar-Abderrahim @christianwimmer Is there any review update?

ziyilin avatar Nov 03 '22 03:11 ziyilin