Re: RFR: 8333268: Fixes for static build [v4]

2024-06-21 Thread Jiangli Zhou
On Wed, 19 Jun 2024 15:15:43 GMT, Magnus Ihse Bursie  wrote:

>> This patch contains a set of changes to improve static builds. They will 
>> pave the way for implementing a full static-only java launcher. The changes 
>> here will:
>> 
>> 1) Make sure non-exported symbols are made local in the static libraries. 
>> This means that the risk of symbol conflict is the same for static libraries 
>> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
>> naming scheme is used for exported functions).
>> 
>> 2) Remove the work-arounds to exclude duplicated symbols.
>> 
>> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
>> with a static java launcher.
>> 
>> The latter fixes are copied from or inspired by the work done by 
>> @jianglizhou and her team as part of the Project Leyden [Hermetic 
>> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).
>
> Magnus Ihse Bursie has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Add dummy implementation of os::lookup_function for Windows

I've looked through all JDK and VM changes and left comments in various places. 
All the rest changes in PR look good. Thanks again for extracting these changes 
from the leyden/hermeticJava branch and integrating with mainline!

My other main question is why the `javastatic` linking work is not included in 
the PR together with these runtime changes. 

IIUC from our meetings and mailing list discussions, the initial integration PR 
needs to include the part for statically linking the `javastatic`. That's a 
minimum requirement for testing/verifying the runtime changes when integrating 
into the mainline, which is also the reason why we haven't starting integrating 
any of the runtime changes so far. Has that been changed?

-

PR Review: https://git.openjdk.org/jdk/pull/19478#pullrequestreview-2133328296


Re: RFR: 8333268: Fixes for static build [v4]

2024-06-21 Thread Jiangli Zhou
On Wed, 19 Jun 2024 15:15:43 GMT, Magnus Ihse Bursie  wrote:

>> This patch contains a set of changes to improve static builds. They will 
>> pave the way for implementing a full static-only java launcher. The changes 
>> here will:
>> 
>> 1) Make sure non-exported symbols are made local in the static libraries. 
>> This means that the risk of symbol conflict is the same for static libraries 
>> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
>> naming scheme is used for exported functions).
>> 
>> 2) Remove the work-arounds to exclude duplicated symbols.
>> 
>> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
>> with a static java launcher.
>> 
>> The latter fixes are copied from or inspired by the work done by 
>> @jianglizhou and her team as part of the Project Leyden [Hermetic 
>> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).
>
> Magnus Ihse Bursie has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Add dummy implementation of os::lookup_function for Windows

src/java.base/unix/native/libjli/java_md.c line 316:

> 314: SetExecname(*pargv);
> 315: 
> 316: if (!JLI_IsStaticallyLinked()) {

Any reason this is diverted from the change in hermetic Java branch, 
https://github.com/openjdk/leyden/blob/c1c5fc686c1452550e1b3663a320fba652248505/src/java.base/unix/native/libjli/java_md.c#L300?
 I think the setenv part below is not needed for static/hermetic support 
either. There is no $JRE/lib with a single executable image. All natives are 
statically linked with the executable image.

-

PR Review Comment: https://git.openjdk.org/jdk/pull/19478#discussion_r1649356484


Re: RFR: 8333268: Fixes for static build [v4]

2024-06-21 Thread Jiangli Zhou
On Wed, 19 Jun 2024 15:15:43 GMT, Magnus Ihse Bursie  wrote:

>> This patch contains a set of changes to improve static builds. They will 
>> pave the way for implementing a full static-only java launcher. The changes 
>> here will:
>> 
>> 1) Make sure non-exported symbols are made local in the static libraries. 
>> This means that the risk of symbol conflict is the same for static libraries 
>> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
>> naming scheme is used for exported functions).
>> 
>> 2) Remove the work-arounds to exclude duplicated symbols.
>> 
>> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
>> with a static java launcher.
>> 
>> The latter fixes are copied from or inspired by the work done by 
>> @jianglizhou and her team as part of the Project Leyden [Hermetic 
>> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).
>
> Magnus Ihse Bursie has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Add dummy implementation of os::lookup_function for Windows

src/java.base/macosx/native/libjli/java_md_macosx.m line 1:

> 1: /*

In the mailing list email discussion thread on hermetic Java, you mentioned 
running on macosx with a build from hermtic Java branch crashed for you during 
startup. Is that fully resolved with the changes in this PR? The hermetic Java 
branch does not have any changes for macosx port. What tests are done for the 
macosx port for static support?

-

PR Review Comment: https://git.openjdk.org/jdk/pull/19478#discussion_r1649348777


Re: RFR: 8333268: Fixes for static build [v4]

2024-06-21 Thread Jiangli Zhou
On Wed, 19 Jun 2024 15:15:43 GMT, Magnus Ihse Bursie  wrote:

>> This patch contains a set of changes to improve static builds. They will 
>> pave the way for implementing a full static-only java launcher. The changes 
>> here will:
>> 
>> 1) Make sure non-exported symbols are made local in the static libraries. 
>> This means that the risk of symbol conflict is the same for static libraries 
>> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
>> naming scheme is used for exported functions).
>> 
>> 2) Remove the work-arounds to exclude duplicated symbols.
>> 
>> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
>> with a static java launcher.
>> 
>> The latter fixes are copied from or inspired by the work done by 
>> @jianglizhou and her team as part of the Project Leyden [Hermetic 
>> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).
>
> Magnus Ihse Bursie has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Add dummy implementation of os::lookup_function for Windows

src/hotspot/share/utilities/zipLibrary.cpp line 63:

> 61: 
> 62: static void* dll_lookup(const char* name, const char* path, bool 
> vm_exit_on_failure) {
> 63:   if (vm_is_statically_linked()) {

I like this change. It is cleaner than the hermetic Java branch change that 
does the `if` static check in `store_function_pointers` 
(https://github.com/openjdk/leyden/blob/c1c5fc686c1452550e1b3663a320fba652248505/src/hotspot/share/utilities/zipLibrary.cpp#L75).

-

PR Review Comment: https://git.openjdk.org/jdk/pull/19478#discussion_r1649341844


Re: RFR: 8333268: Fixes for static build [v4]

2024-06-21 Thread Jiangli Zhou
On Wed, 19 Jun 2024 15:15:43 GMT, Magnus Ihse Bursie  wrote:

>> This patch contains a set of changes to improve static builds. They will 
>> pave the way for implementing a full static-only java launcher. The changes 
>> here will:
>> 
>> 1) Make sure non-exported symbols are made local in the static libraries. 
>> This means that the risk of symbol conflict is the same for static libraries 
>> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
>> naming scheme is used for exported functions).
>> 
>> 2) Remove the work-arounds to exclude duplicated symbols.
>> 
>> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
>> with a static java launcher.
>> 
>> The latter fixes are copied from or inspired by the work done by 
>> @jianglizhou and her team as part of the Project Leyden [Hermetic 
>> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).
>
> Magnus Ihse Bursie has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Add dummy implementation of os::lookup_function for Windows

src/hotspot/share/runtime/os.cpp line 521:

> 519: char ebuf[1024];
> 520: 
> 521: if (vm_is_statically_linked()) {

This block can be moved before the two variable declarations above, since they 
are not needed in the static case. 
https://github.com/openjdk/leyden/blob/c1c5fc686c1452550e1b3663a320fba652248505/src/hotspot/share/runtime/os.cpp#L507
 handles it that way.

-

PR Review Comment: https://git.openjdk.org/jdk/pull/19478#discussion_r164982


Re: RFR: 8333268: Fixes for static build [v4]

2024-06-21 Thread Jiangli Zhou
On Wed, 19 Jun 2024 15:15:43 GMT, Magnus Ihse Bursie  wrote:

>> This patch contains a set of changes to improve static builds. They will 
>> pave the way for implementing a full static-only java launcher. The changes 
>> here will:
>> 
>> 1) Make sure non-exported symbols are made local in the static libraries. 
>> This means that the risk of symbol conflict is the same for static libraries 
>> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
>> naming scheme is used for exported functions).
>> 
>> 2) Remove the work-arounds to exclude duplicated symbols.
>> 
>> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
>> with a static java launcher.
>> 
>> The latter fixes are copied from or inspired by the work done by 
>> @jianglizhou and her team as part of the Project Leyden [Hermetic 
>> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).
>
> Magnus Ihse Bursie has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Add dummy implementation of os::lookup_function for Windows

src/hotspot/os/bsd/os_bsd.cpp line 1:

> 1: /*

The changes in os_bsd.cpp are new and are not from 
https://github.com/openjdk/leyden/tree/hermetic-java-runtime/. Have you tested 
the bsd port?

-

PR Review Comment: https://git.openjdk.org/jdk/pull/19478#discussion_r1649312808


Re: RFR: 8333268: Fixes for static build [v4]

2024-06-20 Thread Jiangli Zhou
On Wed, 19 Jun 2024 15:15:43 GMT, Magnus Ihse Bursie  wrote:

>> This patch contains a set of changes to improve static builds. They will 
>> pave the way for implementing a full static-only java launcher. The changes 
>> here will:
>> 
>> 1) Make sure non-exported symbols are made local in the static libraries. 
>> This means that the risk of symbol conflict is the same for static libraries 
>> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
>> naming scheme is used for exported functions).
>> 
>> 2) Remove the work-arounds to exclude duplicated symbols.
>> 
>> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
>> with a static java launcher.
>> 
>> The latter fixes are copied from or inspired by the work done by 
>> @jianglizhou and her team as part of the Project Leyden [Hermetic 
>> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).
>
> Magnus Ihse Bursie has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Add dummy implementation of os::lookup_function for Windows

make/common/native/Link.gmk line 72:

> 70: define CreateStaticLibrary
> 71:   # Include partial linking when building the static library with clang 
> on linux
> 72:   ifeq ($(call isTargetOs, linux macosx), true)

Is this mainly for `clang` support for now?

-

PR Review Comment: https://git.openjdk.org/jdk/pull/19478#discussion_r1648293391


Re: RFR: 8333268: Fixes for static build [v4]

2024-06-20 Thread Jiangli Zhou
On Wed, 19 Jun 2024 15:15:43 GMT, Magnus Ihse Bursie  wrote:

>> This patch contains a set of changes to improve static builds. They will 
>> pave the way for implementing a full static-only java launcher. The changes 
>> here will:
>> 
>> 1) Make sure non-exported symbols are made local in the static libraries. 
>> This means that the risk of symbol conflict is the same for static libraries 
>> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
>> naming scheme is used for exported functions).
>> 
>> 2) Remove the work-arounds to exclude duplicated symbols.
>> 
>> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
>> with a static java launcher.
>> 
>> The latter fixes are copied from or inspired by the work done by 
>> @jianglizhou and her team as part of the Project Leyden [Hermetic 
>> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).
>
> Magnus Ihse Bursie has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Add dummy implementation of os::lookup_function for Windows

make/modules/java.desktop/lib/AwtLibraries.gmk line 257:

> 255:   JDK_LIBS := libawt java.base:libjava, \
> 256:   LIBS_unix := $(LIBDL) $(LIBM) $(X_LIBS) -lX11 -lXext -lXi 
> -lXrender \
> 257:   -lXtst, \

Same question as for the STATIC_LIB_EXCLUDE_OBJS change with `libjli`. Are the 
duplicate symbol issues resolved by symbol hiding?

I think it's still better to not include those .o files to avoid unnecessary 
footprint overhead in the binary.

-

PR Review Comment: https://git.openjdk.org/jdk/pull/19478#discussion_r1648292220


Re: RFR: 8333268: Fixes for static build [v4]

2024-06-20 Thread Jiangli Zhou
On Wed, 19 Jun 2024 15:15:43 GMT, Magnus Ihse Bursie  wrote:

>> This patch contains a set of changes to improve static builds. They will 
>> pave the way for implementing a full static-only java launcher. The changes 
>> here will:
>> 
>> 1) Make sure non-exported symbols are made local in the static libraries. 
>> This means that the risk of symbol conflict is the same for static libraries 
>> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
>> naming scheme is used for exported functions).
>> 
>> 2) Remove the work-arounds to exclude duplicated symbols.
>> 
>> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
>> with a static java launcher.
>> 
>> The latter fixes are copied from or inspired by the work done by 
>> @jianglizhou and her team as part of the Project Leyden [Hermetic 
>> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).
>
> Magnus Ihse Bursie has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Add dummy implementation of os::lookup_function for Windows

make/modules/java.base/lib/CoreLibraries.gmk line 148:

> 146:   $(LIBJLI_EXTRA_FILE_LIST))
> 147: 
> 148:   # Do not include these libz objects in the static libjli library.

Why this is no longer needed?

-

PR Review Comment: https://git.openjdk.org/jdk/pull/19478#discussion_r1648290693


Re: RFR: 8333268: Fixes for static build [v2]

2024-06-20 Thread Jiangli Zhou
On Tue, 18 Jun 2024 17:57:29 GMT, Magnus Ihse Bursie  wrote:

>> Magnus Ihse Bursie has updated the pull request with a new target base due 
>> to a merge or a rebase. The incremental webrev excludes the unrelated 
>> changes brought in by the merge/rebase. The pull request contains seven 
>> additional commits since the last revision:
>> 
>>  - Merge branch 'master' into static-linking-progress
>>  - Merge branch 'master' into static-linking-progress
>>  - Move the exported JVM_IsStaticallyLinked to a better location
>>  - Use runtime lookup of static vs dynamic instead of #ifdef STATIC_BUILD
>>  - Copy fix for init_system_properties_values on linux
>>  - Make sure we do not try to build static libraries on Windows
>>  - 8333268: Fixes for static build
>
> src/hotspot/os/linux/os_linux.cpp line 605:
> 
>> 603: 
>> 604:   // Get rid of /{client|server|hotspot}, if binary is libjvm.so.
>> 605:   // Or, cut off /.
> 
> @jianglizhou This code is based on changes in the Hermetic Java repo, but I 
> do not fully understand neither the comment nor what the purpose is. If you 
> could explain this a bit I'd be grateful.

The specific related commit in the hermetic Java branch is 
https://github.com/openjdk/leyden/commit/53aa8f0cf418ab5f435a4b9996c7754fb8505d4b.
 

The change in os_linux.cpp here is to make sure  that the libjvm.so related 
path manipulation is conditionally done only. The check at line 599 looks for 
"/libjvm.so" substring, so we only chop off (`*pslash = `\0` at line 601) that 
part when necessary. In the static JDK case, there is no `libjvm.so` and the 
path string is `/bin/javastatic`, which should not be affected. 
Otherwise, it could fail.

I found the code was not very easy to follow when running into problems and 
fixing for static support. So I added a bit more comments in the code here. The 
comment above about `/{client|server|hotspot}` was there originally. I think we 
no longer have those directories. We can cleanup that later, since it needs 
some more testing.

@magicus, thanks a lot for extracting/reworking/cleaning-up the static Java 
changes from the hermetic Java branch. That's a substantial amount of work!

I have one quick comment about the removal of `STATIC_LIB_EXCLUDE_OBJS` 
changes. Will post it as separate comment for the related code. 

I'll also look closely of the vm & jdk changes and compare those with the 
changes in the hermetic Java branch this week.

-

PR Review Comment: https://git.openjdk.org/jdk/pull/19478#discussion_r1648283151


Re: RFR: 8333268: Fixes for static build [v4]

2024-06-20 Thread Alan Bateman
On Wed, 19 Jun 2024 15:15:43 GMT, Magnus Ihse Bursie  wrote:

>> This patch contains a set of changes to improve static builds. They will 
>> pave the way for implementing a full static-only java launcher. The changes 
>> here will:
>> 
>> 1) Make sure non-exported symbols are made local in the static libraries. 
>> This means that the risk of symbol conflict is the same for static libraries 
>> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
>> naming scheme is used for exported functions).
>> 
>> 2) Remove the work-arounds to exclude duplicated symbols.
>> 
>> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
>> with a static java launcher.
>> 
>> The latter fixes are copied from or inspired by the work done by 
>> @jianglizhou and her team as part of the Project Leyden [Hermetic 
>> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).
>
> Magnus Ihse Bursie has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Add dummy implementation of os::lookup_function for Windows

The changes to the launcher look okay. The move from `ifdef STATIC_BUILD` to 
`JLI_IsStaticallyLinked` is quite nice.

Having libjdwp link to libjvm was a surprise but I think okay.

I think it would be useful to provide a brief summary on the when/where the 
static builds are tested to ensure that the changes don't bit rot. I realise we 
already have static builds but it isn't obvious where this is tested.

src/hotspot/share/runtime/linkType.cpp line 36:

> 34:   return JNI_TRUE;
> 35: #else
> 36:   return JNI_FALSE;

bool != jboolean, I assume you don't want that.

The naming is a bit unusual, a function that returns a boolean is usually name 
is_XXX, but maybe there is reason for this?

-

PR Comment: https://git.openjdk.org/jdk/pull/19478#issuecomment-2180635747
PR Review Comment: https://git.openjdk.org/jdk/pull/19478#discussion_r1647480992


Re: RFR: 8333268: Fixes for static build [v4]

2024-06-20 Thread Erik Joelsson
On Wed, 19 Jun 2024 15:15:43 GMT, Magnus Ihse Bursie  wrote:

>> This patch contains a set of changes to improve static builds. They will 
>> pave the way for implementing a full static-only java launcher. The changes 
>> here will:
>> 
>> 1) Make sure non-exported symbols are made local in the static libraries. 
>> This means that the risk of symbol conflict is the same for static libraries 
>> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
>> naming scheme is used for exported functions).
>> 
>> 2) Remove the work-arounds to exclude duplicated symbols.
>> 
>> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
>> with a static java launcher.
>> 
>> The latter fixes are copied from or inspired by the work done by 
>> @jianglizhou and her team as part of the Project Leyden [Hermetic 
>> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).
>
> Magnus Ihse Bursie has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Add dummy implementation of os::lookup_function for Windows

Build changes look ok.

-

Marked as reviewed by erikj (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/19478#pullrequestreview-2129807207


Re: RFR: 8333268: Fixes for static build [v4]

2024-06-19 Thread Magnus Ihse Bursie
On Wed, 19 Jun 2024 15:15:43 GMT, Magnus Ihse Bursie  wrote:

>> This patch contains a set of changes to improve static builds. They will 
>> pave the way for implementing a full static-only java launcher. The changes 
>> here will:
>> 
>> 1) Make sure non-exported symbols are made local in the static libraries. 
>> This means that the risk of symbol conflict is the same for static libraries 
>> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
>> naming scheme is used for exported functions).
>> 
>> 2) Remove the work-arounds to exclude duplicated symbols.
>> 
>> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
>> with a static java launcher.
>> 
>> The latter fixes are copied from or inspired by the work done by 
>> @jianglizhou and her team as part of the Project Leyden [Hermetic 
>> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).
>
> Magnus Ihse Bursie has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Add dummy implementation of os::lookup_function for Windows

The reason the gtest failed was that we build a static library libgtest.a, 
which is linked with the gtest libjvm.so. With the changes in this PR, 
libgtest.a was being built using the `ld -r` + `objcopy --localize-hidden` 
method. This caused some weird issues with gcc, related to C++ code and the 
`COMDAT` object info. 

I failed to track down any proper solution, so instead I added a patch where 
the libraries that we explicitly declare as `STATIC_LIBRARIES` are linked as 
before, without the partial linking step. These libraries are only intended for 
internal consumption (that is, they are linked to and used by another, 
"external" library), and so the extra protection added by the partial linking 
is not really needed.

It's a bit sad that this did not work, but it is no big deal. It won't affect 
files released in the image, and it will not be a regression as compared to now.

-

PR Comment: https://git.openjdk.org/jdk/pull/19478#issuecomment-2178961562


Re: RFR: 8333268: Fixes for static build [v4]

2024-06-19 Thread Magnus Ihse Bursie
> This patch contains a set of changes to improve static builds. They will pave 
> the way for implementing a full static-only java launcher. The changes here 
> will:
> 
> 1) Make sure non-exported symbols are made local in the static libraries. 
> This means that the risk of symbol conflict is the same for static libraries 
> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
> naming scheme is used for exported functions).
> 
> 2) Remove the work-arounds to exclude duplicated symbols.
> 
> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
> with a static java launcher.
> 
> The latter fixes are copied from or inspired by the work done by @jianglizhou 
> and her team as part of the Project Leyden [Hermetic 
> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).

Magnus Ihse Bursie has updated the pull request incrementally with one 
additional commit since the last revision:

  Add dummy implementation of os::lookup_function for Windows

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/19478/files
  - new: https://git.openjdk.org/jdk/pull/19478/files/4ab70df3..b88d813e

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=19478&range=03
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=19478&range=02-03

  Stats: 6 lines in 1 file changed: 6 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/19478.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/19478/head:pull/19478

PR: https://git.openjdk.org/jdk/pull/19478


Re: RFR: 8333268: Fixes for static build [v3]

2024-06-19 Thread Magnus Ihse Bursie
> This patch contains a set of changes to improve static builds. They will pave 
> the way for implementing a full static-only java launcher. The changes here 
> will:
> 
> 1) Make sure non-exported symbols are made local in the static libraries. 
> This means that the risk of symbol conflict is the same for static libraries 
> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
> naming scheme is used for exported functions).
> 
> 2) Remove the work-arounds to exclude duplicated symbols.
> 
> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
> with a static java launcher.
> 
> The latter fixes are copied from or inspired by the work done by @jianglizhou 
> and her team as part of the Project Leyden [Hermetic 
> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).

Magnus Ihse Bursie has updated the pull request incrementally with one 
additional commit since the last revision:

  Do not use partial linking when building static libraries for internal 
consumption

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/19478/files
  - new: https://git.openjdk.org/jdk/pull/19478/files/e1c46562..4ab70df3

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=19478&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=19478&range=01-02

  Stats: 7 lines in 1 file changed: 7 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/19478.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/19478/head:pull/19478

PR: https://git.openjdk.org/jdk/pull/19478


Re: RFR: 8333268: Fixes for static build [v2]

2024-06-18 Thread Magnus Ihse Bursie
On Tue, 18 Jun 2024 16:19:39 GMT, Magnus Ihse Bursie  wrote:

>> This patch contains a set of changes to improve static builds. They will 
>> pave the way for implementing a full static-only java launcher. The changes 
>> here will:
>> 
>> 1) Make sure non-exported symbols are made local in the static libraries. 
>> This means that the risk of symbol conflict is the same for static libraries 
>> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
>> naming scheme is used for exported functions).
>> 
>> 2) Remove the work-arounds to exclude duplicated symbols.
>> 
>> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
>> with a static java launcher.
>> 
>> The latter fixes are copied from or inspired by the work done by 
>> @jianglizhou and her team as part of the Project Leyden [Hermetic 
>> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).
>
> Magnus Ihse Bursie has updated the pull request with a new target base due to 
> a merge or a rebase. The incremental webrev excludes the unrelated changes 
> brought in by the merge/rebase. The pull request contains seven additional 
> commits since the last revision:
> 
>  - Merge branch 'master' into static-linking-progress
>  - Merge branch 'master' into static-linking-progress
>  - Move the exported JVM_IsStaticallyLinked to a better location
>  - Use runtime lookup of static vs dynamic instead of #ifdef STATIC_BUILD
>  - Copy fix for init_system_properties_values on linux
>  - Make sure we do not try to build static libraries on Windows
>  - 8333268: Fixes for static build

src/hotspot/os/linux/os_linux.cpp line 605:

> 603: 
> 604:   // Get rid of /{client|server|hotspot}, if binary is libjvm.so.
> 605:   // Or, cut off /.

@jianglizhou This code is based on changes in the Hermetic Java repo, but I do 
not fully understand neither the comment nor what the purpose is. If you could 
explain this a bit I'd be grateful.

-

PR Review Comment: https://git.openjdk.org/jdk/pull/19478#discussion_r1644855137


Re: RFR: 8333268: Fixes for static build

2024-06-18 Thread Magnus Ihse Bursie
On Thu, 30 May 2024 19:35:44 GMT, Magnus Ihse Bursie  wrote:

> Do os::lookup_function need to be implemented on Windows too, for symmetry, 
> even if it is only used on Unix platforms?

@AlanBateman suggested to add `lookup_function` to os_windows.cpp as well, but 
just let it contain ShouldNotReachHere. That sounds like a good solution to me.

-

PR Comment: https://git.openjdk.org/jdk/pull/19478#issuecomment-2176657975


Re: RFR: 8333268: Fixes for static build [v2]

2024-06-18 Thread Magnus Ihse Bursie
> This patch contains a set of changes to improve static builds. They will pave 
> the way for implementing a full static-only java launcher. The changes here 
> will:
> 
> 1) Make sure non-exported symbols are made local in the static libraries. 
> This means that the risk of symbol conflict is the same for static libraries 
> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
> naming scheme is used for exported functions).
> 
> 2) Remove the work-arounds to exclude duplicated symbols.
> 
> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
> with a static java launcher.
> 
> The latter fixes are copied from or inspired by the work done by @jianglizhou 
> and her team as part of the Project Leyden [Hermetic 
> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).

Magnus Ihse Bursie has updated the pull request with a new target base due to a 
merge or a rebase. The incremental webrev excludes the unrelated changes 
brought in by the merge/rebase. The pull request contains seven additional 
commits since the last revision:

 - Merge branch 'master' into static-linking-progress
 - Merge branch 'master' into static-linking-progress
 - Move the exported JVM_IsStaticallyLinked to a better location
 - Use runtime lookup of static vs dynamic instead of #ifdef STATIC_BUILD
 - Copy fix for init_system_properties_values on linux
 - Make sure we do not try to build static libraries on Windows
 - 8333268: Fixes for static build

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/19478/files
  - new: https://git.openjdk.org/jdk/pull/19478/files/6b24a789..e1c46562

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=19478&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=19478&range=00-01

  Stats: 2608 lines in 114 files changed: 1321 ins; 955 del; 332 mod
  Patch: https://git.openjdk.org/jdk/pull/19478.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/19478/head:pull/19478

PR: https://git.openjdk.org/jdk/pull/19478


Re: RFR: 8333268: Fixes for static build

2024-06-14 Thread Magnus Ihse Bursie
On Thu, 30 May 2024 13:00:21 GMT, Magnus Ihse Bursie  wrote:

> This patch contains a set of changes to improve static builds. They will pave 
> the way for implementing a full static-only java launcher. The changes here 
> will:
> 
> 1) Make sure non-exported symbols are made local in the static libraries. 
> This means that the risk of symbol conflict is the same for static libraries 
> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
> naming scheme is used for exported functions).
> 
> 2) Remove the work-arounds to exclude duplicated symbols.
> 
> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
> with a static java launcher.
> 
> The latter fixes are copied from or inspired by the work done by @jianglizhou 
> and her team as part of the Project Leyden [Hermetic 
> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).

The GHA tests fails when building gtest on Linux. This will require some 
investigation.

-

PR Comment: https://git.openjdk.org/jdk/pull/19478#issuecomment-2168647325


Re: RFR: 8333268: Fixes for static build

2024-06-14 Thread Magnus Ihse Bursie
On Thu, 30 May 2024 13:00:21 GMT, Magnus Ihse Bursie  wrote:

> This patch contains a set of changes to improve static builds. They will pave 
> the way for implementing a full static-only java launcher. The changes here 
> will:
> 
> 1) Make sure non-exported symbols are made local in the static libraries. 
> This means that the risk of symbol conflict is the same for static libraries 
> as for dynamic libraries (i.e. in practice zero, as long as a consistent 
> naming scheme is used for exported functions).
> 
> 2) Remove the work-arounds to exclude duplicated symbols.
> 
> 3) Fix some code in hotspot and the JDK libraries that did not work properly 
> with a static java launcher.
> 
> The latter fixes are copied from or inspired by the work done by @jianglizhou 
> and her team as part of the Project Leyden [Hermetic 
> Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).

Some open questions:

* Do `os::lookup_function` need to be implemented on Windows too, for symmetry, 
even if it is only used on Unix platforms?

* Many of the changes in Hotspot boils down to `os::dll_load` doing the wrong 
thing when running with a static build. Perhaps we should provide a better 
function that knows how to find and load a symbol for both static and dynamic 
builds, and use that instead of making a lot of tests for static/dynamic on 
each location we need to look up a symbol from some other JDK library.

* I managed to replace most of the #ifdef STATIC_BUILD with runtime checks. 
There are some places remaining though. Apart from the #ifdefs needed for 
JNI/JVMTI, which will need spec changes to address, there are code in 
java_md_macosx.m, jio.c and awt_Mlib.c that I did not manage to turn into 
runtime checks. They will need some more thorough work than just changing an 
`#ifdef` to an `if () {`.

* And of course, the code in the build system to share all .o files except the 
two linktype files is still under development...

I moved this away from Draft state, since I think it needs some visibility, 
especially since it touches several different parts of the code base, and such 
reviews tend to take time.

I think the code here is good and basically okay to integrate. This patch will 
not on it's own solve the entire problem of building a proper static launcher, 
but it takes several important steps along the way. I think the changes here 
are reasonable to integrate into mainline at this point.

-

PR Comment: https://git.openjdk.org/jdk/pull/19478#issuecomment-2140743300
PR Comment: https://git.openjdk.org/jdk/pull/19478#issuecomment-2168635393


RFR: 8333268: Fixes for static build

2024-06-14 Thread Magnus Ihse Bursie
This patch contains a set of changes to improve static builds. They will pave 
the way for implementing a full static-only java launcher. The changes here 
will:

1) Make sure non-exported symbols are made local in the static libraries. This 
means that the risk of symbol conflict is the same for static libraries as for 
dynamic libraries (i.e. in practice zero, as long as a consistent naming scheme 
is used for exported functions).

2) Remove the work-arounds to exclude duplicated symbols.

3) Fix some code in hotspot and the JDK libraries that did not work properly 
with a static java launcher.

The latter fixes are copied from or inspired by the work done by @jianglizhou 
and her team as part of the Project Leyden [Hermetic 
Java](https://github.com/openjdk/leyden/tree/hermetic-java-runtime).

-

Commit messages:
 - Merge branch 'master' into static-linking-progress
 - Move the exported JVM_IsStaticallyLinked to a better location
 - Use runtime lookup of static vs dynamic instead of #ifdef STATIC_BUILD
 - Copy fix for init_system_properties_values on linux
 - Make sure we do not try to build static libraries on Windows
 - 8333268: Fixes for static build

Changes: https://git.openjdk.org/jdk/pull/19478/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=19478&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8333268
  Stats: 440 lines in 28 files changed: 203 ins; 74 del; 163 mod
  Patch: https://git.openjdk.org/jdk/pull/19478.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/19478/head:pull/19478

PR: https://git.openjdk.org/jdk/pull/19478