Skip to content

Commit

Permalink
8329862: libjli GetApplicationHome cleanups and enhance jli tracing
Browse files Browse the repository at this point in the history
Reviewed-by: clanger, stuefe
  • Loading branch information
MBaesken committed Apr 26, 2024
1 parent 006f090 commit 377f2e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 38 deletions.
18 changes: 5 additions & 13 deletions src/java.base/unix/native/libjli/java_md.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -495,27 +495,19 @@ GetJREPath(char *path, jint pathsize, jboolean speculative)
char libjava[MAXPATHLEN];
struct stat s;

JLI_TraceLauncher("Attempt to get JRE path from launcher executable path\n");

if (GetApplicationHome(path, pathsize)) {
/* Is JRE co-located with the application? */
JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/" JAVA_DLL, path);
if (access(libjava, F_OK) == 0) {
JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
}
/* ensure storage for path + /jre + NULL */
if ((JLI_StrLen(path) + 4 + 1) > (size_t) pathsize) {
JLI_TraceLauncher("Insufficient space to store JRE path\n");
return JNI_FALSE;
}
/* Does the app ship a private JRE in <apphome>/jre directory? */
JLI_Snprintf(libjava, sizeof(libjava), "%s/jre/lib/" JAVA_DLL, path);
if (access(libjava, F_OK) == 0) {
JLI_StrCat(path, "/jre");
JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
}
}

JLI_TraceLauncher("Attempt to get JRE path from shared lib of the image\n");

if (GetApplicationHomeFromDll(path, pathsize)) {
JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/" JAVA_DLL, path);
if (stat(libjava, &s) == 0) {
Expand Down
30 changes: 5 additions & 25 deletions src/java.base/windows/native/libjli/java_md.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -49,10 +49,6 @@ static jboolean GetJVMPath(const char *jrepath, const char *jvmtype,
char *jvmpath, jint jvmpathsize);
static jboolean GetJREPath(char *path, jint pathsize);

#ifdef USE_REGISTRY_LOOKUP
jboolean GetPublicJREHome(char *buf, jint bufsize);
#endif

/* We supports warmup for UI stack that is performed in parallel
* to VM initialization.
* This helps to improve startup of UI application as warmup phase
Expand Down Expand Up @@ -300,27 +296,19 @@ GetJREPath(char *path, jint pathsize)
char javadll[MAXPATHLEN];
struct stat s;

JLI_TraceLauncher("Attempt to get JRE path from launcher executable path\n");

if (GetApplicationHome(path, pathsize)) {
/* Is JRE co-located with the application? */
JLI_Snprintf(javadll, sizeof(javadll), "%s\\bin\\" JAVA_DLL, path);
if (stat(javadll, &s) == 0) {
JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
}
/* ensure storage for path + \jre + NULL */
if ((JLI_StrLen(path) + 4 + 1) > (size_t) pathsize) {
JLI_TraceLauncher("Insufficient space to store JRE path\n");
return JNI_FALSE;
}
/* Does this app ship a private JRE in <apphome>\jre directory? */
JLI_Snprintf(javadll, sizeof (javadll), "%s\\jre\\bin\\" JAVA_DLL, path);
if (stat(javadll, &s) == 0) {
JLI_StrCat(path, "\\jre");
JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
}
}

JLI_TraceLauncher("Attempt to get JRE path from shared lib of the image\n");

/* Try getting path to JRE from path to JLI.DLL */
if (GetApplicationHomeFromDll(path, pathsize)) {
JLI_Snprintf(javadll, sizeof(javadll), "%s\\bin\\" JAVA_DLL, path);
Expand All @@ -330,14 +318,6 @@ GetJREPath(char *path, jint pathsize)
}
}

#ifdef USE_REGISTRY_LOOKUP
/* Lookup public JRE using Windows registry. */
if (GetPublicJREHome(path, pathsize)) {
JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
}
#endif

JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
return JNI_FALSE;
}
Expand Down

7 comments on commit 377f2e5

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk22u

@openjdk
Copy link

@openjdk openjdk bot commented on 377f2e5 May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken the backport was successfully created on the branch backport-MBaesken-377f2e53 in my personal fork of openjdk/jdk22u. To create a pull request with this backport targeting openjdk/jdk22u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 377f2e53 from the openjdk/jdk repository.

The commit being backported was authored by Matthias Baesken on 26 Apr 2024 and was reviewed by Christoph Langer and Thomas Stuefe.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk22u:

$ git fetch https://github.com/openjdk-bots/jdk22u.git backport-MBaesken-377f2e53:backport-MBaesken-377f2e53
$ git checkout backport-MBaesken-377f2e53
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk22u.git backport-MBaesken-377f2e53

@MBaesken
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 377f2e5 May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken the backport was successfully created on the branch backport-MBaesken-377f2e53 in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 377f2e53 from the openjdk/jdk repository.

The commit being backported was authored by Matthias Baesken on 26 Apr 2024 and was reviewed by Christoph Langer and Thomas Stuefe.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-MBaesken-377f2e53:backport-MBaesken-377f2e53
$ git checkout backport-MBaesken-377f2e53
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-MBaesken-377f2e53

@MBaesken
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 377f2e5 Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken Could not automatically backport 377f2e53 to openjdk/jdk17u-dev due to conflicts in the following files:

  • src/java.base/unix/native/libjli/java_md.c
  • src/java.base/windows/native/libjli/java_md.c

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk17u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk17u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b backport-MBaesken-377f2e53-master

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 377f2e538ae0fc94fc5483700a3ae70175017741

# Backport the commit
$ git cherry-pick --no-commit 377f2e538ae0fc94fc5483700a3ae70175017741
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 377f2e538ae0fc94fc5483700a3ae70175017741'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u-dev with the title Backport 377f2e538ae0fc94fc5483700a3ae70175017741.

Below you can find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 377f2e53 from the openjdk/jdk repository.

The commit being backported was authored by Matthias Baesken on 26 Apr 2024 and was reviewed by Christoph Langer and Thomas Stuefe.

Thanks!

Please sign in to comment.