On Mon, 16 Sep 2024 01:06:27 GMT, David Holmes <dhol...@openjdk.org> wrote:

>> Jaikiran Pai has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   comment improvements
>
> src/java.base/macosx/native/libjli/java_md_macosx.m line 83:
> 
>> 81:  *    point of creating a new thread in CreateExecutionEnvironment, the 
>> CreateExecutionEnvironment will check for
>> 82:  *    the state flag to see if a new thread has already been spawned and 
>> upon noticing that it has, it will skip
>> 83:  *    spawning any more threads and will return back from 
>> CreateExecutionEnvironment.
> 
> My understanding was that this recursive invocation was only needed when 
> switching modes/models. I don't see why it would be needed now.

In the context of the 2 platforms - macosx and unix, the recursive invocation 
still continues to happen.

For macosx, the `CreateExecutionEnvironment` unconditionally, through an 
internal `MacOSXStartup` function, spawns a new thread (`pthread_create`). That 
thread is passed a function pointer pointing to the current executable/process' 
`main(...)` function (and thus made to execute afresh). That then triggers this 
recursion where `JLI_Launch` is called again and that then calls into 
`CreateExecutionEnvironment` all the way to `MacOSXStartup` function which has 
the necessary knowledge not to spawn another thread the second time.

For unix, in the `CreateExecutionEnvironment` function, there's a specific 
piece of code which determines whether or not `LD_LIBRARY_PATH` environment 
variable needs to be set or updated before loading the JVM. This decision of 
whether or not `LD_LIBRARY_PATH` needs to be updated or set is done in an 
internal function called `RequiresSetenv`. There are several rules which 
determine whether or not to set/update that environment variable. Rules like - 
is musl libc in use; or is the runtime environment AIX; or if the 
`LD_LIBRARY_PATH` is currently set, then whether the value in the environment 
variable matches some well known JVM library path patterns (like `lib/client`, 
`lib/server`). If any of these rules determine that the `LD_LIBRARY_PATH` needs 
to be set/updated, then the `CreateExecutionEnvironment` function will do the 
necessary updates to the environment variable value and and exec() the current 
process with that new value. This then triggers the recursion all the way from 
the `
 JLI_Launch` back into this `CreateExecutionEnvironment` (which has the 
necessary knowledge not to exec() once more).

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20997#discussion_r1761203849

Reply via email to