Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8254702: jpackage app launcher crashes on CentOS #2320

Closed

Conversation

alexeysemenyukoracle
Copy link
Member

@alexeysemenyukoracle alexeysemenyukoracle commented Jan 29, 2021

Fix for https://bugs.openjdk.java.net/browse/JDK-8254702

The fix splits Linux app launcher in app launcher and launcher shared lib. App launcher is pure C and doesn't have C++ code. App launcher lib incorporates bulk of C++ code from app launcher.
At startup app launcher loads launcher shared lib and calls functions it provides to get data for launching JVM (path to jli lib and arguments for JLI_Launch function call).
App launcher unloads launcher shared lib before launching JVM to remove C++ runtime from the process memory.

Getting rid of C++ code from app launcher required to rewrite app installation location lookup code from C++ to C. LinuxPackage.c source is C alternative for https://github.com/openjdk/jdk/blob/master/src/jdk.jpackage/linux/native/applauncher/Package.cpp and https://github.com/openjdk/jdk/blob/master/src/jdk.jpackage/linux/native/applauncher/Executor.cpp.

Layout of jpackage's native code changed:

  • common: code shared between all jpackage binaries.
  • applauncher: launcher only code.
  • applauncherlib: launcher lib code on Linux and launcher code on other platforms.
  • applaunchercommon: code shared between launcher and launcher lib on Linux and launcher code on other platforms.

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/2320/head:pull/2320
$ git checkout pull/2320

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 29, 2021

👋 Welcome back asemenyuk! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jan 29, 2021

@alexeysemenyukoracle The following label will be automatically applied to this pull request:

  • build

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the build build-dev@openjdk.org label Jan 29, 2021
@@ -0,0 +1,9 @@
{
Copy link
Member Author

Choose a reason for hiding this comment

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

Linker script is "just in case" to guarantee that only controlled set of functions is exported from launcher lib. Current set of g++ OpenJDK command line options disables export of functions with external linkage by default. However in my local builds this was not the case and the whole C++ runtime statically linked in launcher lib got exported. This prevented it from unloading from launcher's process memory when it was dlclose()-ed. This linker script used in linkage of launcher lib will guarantee this will not happen.

@@ -52,13 +52,13 @@ tstring unsafe_format(tstring::const_pointer format, ...) {
#ifdef _MSC_VER
ret = _vsntprintf_s(&*fmtout.begin(), fmtout.size(), _TRUNCATE, format, args);
#else
#ifdef __GNUC__
Copy link
Member Author

Choose a reason for hiding this comment

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

Local build with older g++compiler bugfix.

@alexeysemenyukoracle alexeysemenyukoracle marked this pull request as ready for review January 29, 2021 21:45
@openjdk openjdk bot added the rfr Pull request is ready for review label Jan 29, 2021
@mlbridge
Copy link

mlbridge bot commented Jan 29, 2021

Webrevs

@prrace
Copy link
Contributor

prrace commented Jan 29, 2021

/label add core-libs

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Jan 29, 2021
@openjdk
Copy link

openjdk bot commented Jan 29, 2021

@prrace
The core-libs label was successfully added.

@prrace
Copy link
Contributor

prrace commented Jan 29, 2021

So after this change if you bundle and run an app on Linux and then do "ps" .. what is shown to be running ? Java or the app-name you expected ?

@alexeysemenyukoracle
Copy link
Member Author

"ps" will show app-name. It was never Java for jpackage apps before this patch and this patch doesn't change it.

Copy link
Member

@magicus magicus left a comment

Choose a reason for hiding this comment

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

This whole change seems very messy to me. :-(

I'm having a hard time even untangling the PR to understand what's going on. Are you creating two new directories, "applauncherlib" and "applauncherlibcommon"? First of all, for shared libraries, the norm is to have a "lib-" prefix, not a "-lib" suffix. Secondly, there is already a "common" directory, is that not enough?

src/jdk.jpackage/share/native/common/app.cpp Show resolved Hide resolved
))

$(BUILD_JPACKAGE_APPLAUNCHEREXE): $(call FindLib, java.base, java)
Copy link
Member

Choose a reason for hiding this comment

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

Why did you remove this dependency?

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved it to the bottom of the file making all artifacts produced by make/modules/jdk.jpackage/Lib.gmk depend on java.bas and java. There is $(JPACKAGE_TARGETS): $(call FindLib, java.base, java) at the bottom of the file.

make/modules/jdk.jpackage/Lib.gmk Outdated Show resolved Hide resolved
@alexeysemenyukoracle
Copy link
Member Author

"common" was perfectly enough until this change. Unfortunately we cant just drop new C sources in "common" dir because we don't want them to be compiled with g++. That is why need new common directory (applauncherlibcommon) for C sources.

I'll rename applauncherlibcommon in libapplaunchercommon and applauncherlib in libapplauncher in the next commit.

@erikj79
Copy link
Member

erikj79 commented Feb 1, 2021

"common" was perfectly enough until this change. Unfortunately we cant just drop new C sources in "common" dir because we don't want them to be compiled with g++. That is why need new common directory (applauncherlibcommon) for C sources.

We pick compiler based on file suffix, not directory, so it shouldn't matter where you put a .c file, it should always be compiled with gcc and .cpp files with g++. Which compiler is used to launch the linker can however differ. That's configured for each SetupNativeCompilation call with the different TOOLCHAIN settings.

@alexeysemenyukoracle
Copy link
Member Author

alexeysemenyukoracle commented Feb 1, 2021

Erik, thank you for explanation.

The launcher on Linux should not be linked with c++ runtime, that is why TOOLCHAIN_DEFAULT is used as a value for TOOLCHAIN property in BUILD_JPACKAGE_APPLAUNCHEREXE target on Linux.

Will SetupNativeCompilation work if TOOLCHAIN=TOOLCHAIN_DEFAULT and there are .cpp sources are in directories passed in SRC property of SetupNativeCompilation? Will it try to compile these sources? If it will ignore them and pick only .c files, that would be perfect.

@mlbridge
Copy link

mlbridge bot commented Feb 2, 2021

Mailing list message from erik.joelsson at oracle.com on build-dev:

On 2021-02-01 10:38, Alexey Semenyuk wrote:

On Mon, 1 Feb 2021 18:24:23 GMT, Erik Joelsson <erikj at openjdk.org> wrote:

"common" was perfectly enough until this change. Unfortunately we cant just drop new C sources in "common" dir because we don't want them to be compiled with g++. That is why need new common directory (applauncherlibcommon) for C sources.

I'll rename applauncherlibcommon in libapplaunchercommon and applauncherlib in libapplauncher in the next commit.
"common" was perfectly enough until this change. Unfortunately we cant just drop new C sources in "common" dir because we don't want them to be compiled with g++. That is why need new common directory (applauncherlibcommon) for C sources.
We pick compiler based on file suffix, not directory, so it shouldn't matter where you put a .c file, it should always be compiled with gcc and .cpp files with g++. Which compiler is used to launch the linker can however differ. That's configured for each SetupNativeCompilation call with the different TOOLCHAIN settings.
Erik, thank you for explanation.

The launcher on Linux should not be linked with c++ runtime, that is why TOOLCHAIN_DEFAULT is used at a value for TOOLCHAIN property in BUILD_JPACKAGE_APPLAUNCHEREXE target on Linux.

Will SetupNativeCompilation work if `TOOLCHAIN=TOOLCHAIN_DEFAULT` and there are .cpp sources are in directories passed in `SRC` property of SetupNativeCompilation? Will it try to compile these sources? If it will ignore them and pick only .c files, that would be perfect.

SetupNativeCompilation will by default include all src files found in
any directory given to SRC, recursively. You can use EXCLUDES,
EXCLUDE_FILES and EXCLUDE_PATTERN to exclude files or directories from
SRC. You can also use EXTRA_FILES to pick specific files outside of any
directory in SRC. Sorting files in separate directories or using
EXCLUDE*/EXTRA_FILES are both possible and picking the right solution is
mostly down to taste.

/Erik

@alexeysemenyukoracle
Copy link
Member Author

Reworked the fix to avoid creation of extra source directories and file renames.

Copy link
Member

@erikj79 erikj79 left a comment

Choose a reason for hiding this comment

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

I like this much better, thanks for taking the time! Build changes look ok.

@openjdk
Copy link

openjdk bot commented Feb 5, 2021

@alexeysemenyukoracle This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8254702: jpackage app launcher crashes on CentOS

Reviewed-by: almatvee, erikj, herrick

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 124 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 5, 2021
Copy link

@andyherrick andyherrick left a comment

Choose a reason for hiding this comment

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

looks ok if build team approves

@alexeysemenyukoracle
Copy link
Member Author

/integrate

@openjdk openjdk bot closed this Feb 5, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Feb 5, 2021
@openjdk
Copy link

openjdk bot commented Feb 5, 2021

@alexeysemenyukoracle Since your change was applied there have been 127 commits pushed to the master branch:

  • 7a6c176: 8260736: Shenandoah: Cleanup includes in ShenandoahGC and families
  • 4a89733: 8261198: [macOS] Incorrect JNI parameters in number conversion in A11Y code
  • 4a1814c: 8261179: Norwegian Bokmål Locale fallback issue
  • 0218917: 8258732: runtime/cds/appcds/dynamicArchive/DynamicArchiveRelocationTest.java fails
  • f9df366: 8242300: SystemDictionary::resolve_super_or_fail() should look for the super class first
  • 43ae0cf: 8261167: print_process_memory_info add a close call after fopen
  • 48f5220: 8260369: [PPC64] Add support for JDK-8200555
  • 224c166: 8261213: [BACKOUT] MutableSpace's end should be atomic
  • 3495feb: 8260296: SA's dumpreplaydata fails
  • 0791899: 8261154: Memory leak in Java_java_lang_ClassLoader_defineClass0 with long class names
  • ... and 117 more: https://git.openjdk.java.net/jdk/compare/20e7df506f06bb34de3d473baa180de1d22ba3d0...master

Your commit was automatically rebased without conflicts.

Pushed as commit fac3c2d.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@alexeysemenyukoracle alexeysemenyukoracle deleted the JDK-8254702 branch January 18, 2022 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build build-dev@openjdk.org core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

6 participants