RFR: 8350982: -server|-client causes fatal exception on static JDK

Jiangli Zhou jiangli at openjdk.org
Tue Mar 4 17:53:07 UTC 2025


On Tue, 4 Mar 2025 06:55:33 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> Please review the `Arguments::parse_each_vm_init_arg` change to ignore`-server|-client` options, which avoids unrecognized option error on static JDK. 
>> 
>> On regular JDK, '-server|-client' options are processed/removed from command-line arguments by `CheckJvmType` during `CreateExecutionEnvironment`. That happens before `Arguments::parse_each_vm_init_arg` is called. With jvm.cfg setting, only server vm is known and client is ignored. So specifying '-server' and '-client' in command-line is really a no-op. 
>> 
>> On static JDK, the VM is statically linked with the launcher, and `CreateExecutionEnvironment` & `CheckJvmType` are not called. As the result, `Arguments::parse_each_vm_init_arg` could see `-server|-client` when running on static JDK, if the options are specified in the command line.
>
> src/hotspot/share/runtime/arguments.cpp line 2812:
> 
>> 2810:       // On regular JDK, '-server|-client' options are processed and removed
>> 2811:       // from command-line arguments by CheckJvmType (see
>> 2812:       // src/java.base/share/native/libjli/java.c). When running on static JDK,
> 
> Why not remove this in the launcher?

@dholmes-ora @AlanBateman Thanks for taking a looking.

> Why not remove this in the launcher?

I made the change in `Arguments::parse_each_vm_init_arg` mainly because the error led me there. Taking another look at the related launcher code now, I think removing the options in launcher is also doable. On regular JDK,  `CheckJvmType` happens before `ParseArguments`. If we change `ParseArguments` to remove the options, we don't need to do an extra check to see if we are running on static or regular JDK.

> I think we have to wonder why anyone would specify -client or -server when using a statically linked image. There's isn't a choice when using a statically linked image.

I had given some thoughts on it back when making the related change. For users running a hermetic Java image, they would not be using any pre-existing scripts without modification. So `-client|-server` would not be a concern in that sense. 

Ignoring the options without failing on static JDK provides the same behavior as on regular JDK and avoids changing the tests to remove `-client|-server`.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/23881#discussion_r1979940279


More information about the hotspot-runtime-dev mailing list