Return long option from Isolate parameters
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
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
No, I don't have a designated reviewer.
@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
@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 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: thanks! @oubidar-Abderrahim: can you merge this PR to master?
@oubidar-Abderrahim @christianwimmer Is there any review update?