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

8351322: Parameterize link option for pthreads #23930

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

snake66
Copy link

@snake66 snake66 commented Mar 6, 2025

Replace hardcoded instances of -lpthread with $(LIBPTHREAD), so that it's possible to parameterize this for platforms that use different flags for enabling posix threads.

This work is a continuation of the work done by Greg Lewis in 1, but generalized for the full JDK, and set at the configure stage.

Sponsored by: The FreeBSD Foundation
Co-authored-by: Greg Lewis [email protected]


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 2 Reviewers)

Issue

  • JDK-8351322: Parameterize link option for pthreads (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/23930/head:pull/23930
$ git checkout pull/23930

Update a local copy of the PR:
$ git checkout pull/23930
$ git pull https://git.openjdk.org/jdk.git pull/23930/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 23930

View PR using the GUI difftool:
$ git pr show -t 23930

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/23930.diff

Using Webrev

Link to Webrev Comment

Replace hardcoded instances of `-lpthread` with `$(LIBPTHREAD)`, so that
it's possible to parameterize this for platforms that use different
flags for enabling posix threads.

This work is a continuation of the work done by Greg Lewis in [1], but
generalized for the full JDK, and set at the configure stage.

Sponsored by: The FreeBSD Foundation
Co-authored-by: Greg Lewis <[email protected]>

[1]: battleblow/jdk23u@dbd90aa
@bridgekeeper
Copy link

bridgekeeper bot commented Mar 6, 2025

👋 Welcome back snake66! 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 Mar 6, 2025

@snake66 This change is no longer ready for integration - check the PR body for details.

@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 6, 2025
@openjdk
Copy link

openjdk bot commented Mar 6, 2025

@snake66 The following labels will be automatically applied to this pull request:

  • build
  • client
  • core-libs
  • net
  • serviceability

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

@mlbridge
Copy link

mlbridge bot commented Mar 6, 2025

Webrevs

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

Abstracting this out seems reasonable to me, though I should say I thought we already used -pthread rather than -lpthread.

Needs build team approval before integrating.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Mar 6, 2025
@snake66
Copy link
Author

snake66 commented Mar 6, 2025

Abstracting this out seems reasonable to me, though I should say I thought we already used -pthread rather than -lpthread.

I noticed there were a few places that used -pthread by default. I left these alone in this PR.

BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libnativeStack += -lpthread
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libTestUnloadedClass += -lpthread
BUILD_HOTSPOT_JTREG_EXECUTABLES_LIBS_exeGetCreatedJavaVMs := -lpthread
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libbootclssearch_agent += $(LIBPTREAD)
Copy link

Choose a reason for hiding this comment

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

Hi. Should this read $(LIBPTHREAD) instead (i.e., missing H)?
Could be me too, I need new reading glasses...

Copy link
Member

Choose a reason for hiding this comment

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

You're absolutely right.

@snake66 Making changes to makefiles is tricky, since a misspelled variable do not get any warning but is just silently ignored.

For a change like this, that is a pure refactoring that is not supposed to change the output, I highly recommend using the COMPARE_BUILD system. Unfortunately, this is severely underdocumented. There is a short paragraph at https://openjdk.org/groups/build/doc/building.html under "Developing the Build System Itself", but in short, what I'd do is to create a diff files of these changes compared to a baseline (e.g. master, a specific build or commit), make sure you have the baseline checked out, and then run make jdk-image test-image COMPARE_BUILD=PATCH=my_patch.diff. This will build the targets twice, one without the patch and one with the patch, and then automatically run the compare script to analyze any differences. For this particular patch, there should be none. This would likely have caught this typo. (Given that the test-image is actually compared; I suddenly got a bit uncertain about that...)

Copy link
Author

Choose a reason for hiding this comment

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

@vieiro Thanks! That's well spotted, I'll fix!

@magicus Thanks for this info! I'll give it a try without fixing the typo first, to see if it would catch it.

@erikj79
Copy link
Member

erikj79 commented Mar 6, 2025

/reviewers 2 reviewers

@openjdk
Copy link

openjdk bot commented Mar 6, 2025

@erikj79
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 2 Reviewers).

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Mar 6, 2025
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.

What is the intended way of using this? Do you run make with LIBPTHREAD=-pthread or do you apply a patch on libraries.m4 for the specific way of linking to pthread?

@@ -139,7 +139,7 @@ AC_DEFUN_ONCE([LIB_SETUP_LIBRARIES],
# Threading library
if test "x$OPENJDK_TARGET_OS" = xlinux || test "x$OPENJDK_TARGET_OS" = xaix; then
BASIC_JVM_LIBS="$BASIC_JVM_LIBS -lpthread"
BASIC_JVM_LIBS="$BASIC_JVM_LIBS $(LIBPTHREAD)"
Copy link
Member

Choose a reason for hiding this comment

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

If you specifically need this to be resolved in the makefile rather than here, then please add a comment explaining why, otherwise use a shell script variable reference.

Suggested change
BASIC_JVM_LIBS="$BASIC_JVM_LIBS $(LIBPTHREAD)"
BASIC_JVM_LIBS="$BASIC_JVM_LIBS $LIBPTHREAD"

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this is incorrect. Remember that m4 are shell scripts so you need to use shell syntax here. (I know it is confusing).

Copy link
Author

Choose a reason for hiding this comment

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

@erikj79 There will be a later patch to libraries.m4 that sets the variable based on the target platform, and then populates the LIBPTHREAD variable in spec.gmk. (https://github.com/openjdk/jdk/pull/23930/files#diff-56172cd2ec5804a5f764a6d0d5970da6144b024a06e008571f9822b2dc83cc36R147) That means the parenthesis should stay, right?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what you mean now. The link is to this very patch, which does what you describe -- sets LIBPTHREAD according to OS and stores it in spec.gmk.

And no, the paranthesis should not stay. If you keep them, the variable will be re-evaluated in make every time BASIC_JVM_LIBS is evaluated. That is not needed; by dropping the parenthesis the actual value to be used will be inserted as a string constant. Which is what we want, since we know the value at configure time.

@magicus
Copy link
Member

magicus commented Mar 6, 2025

What is the intended way of using this? Do you run make with LIBPTHREAD=-pthread or do you apply a patch on libraries.m4 for the specific way of linking to pthread?

This is in preparation of the upcoming BSD port, which uses -pthread instead of -pthread. It was me who suggested that this is done separately with the existing code, to minimize the patch of the BSD port.

@@ -127,7 +127,7 @@ ifeq ($(HSDIS_BACKEND), binutils)
HSDIS_LDFLAGS += -L$(MINGW_GCC_LIB_PATH) -L$(MINGW_SYSROOT_LIB_PATH)
MINGW_DLLCRT := $(MINGW_SYSROOT_LIB_PATH)/dllcrt2.o
HSDIS_TOOLCHAIN_LIBS := $(MINGW_DLLCRT) -lmingw32 -lgcc -lgcc_eh -lmoldname \
-lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32
-lmingwex -lmsvcrt $(LIBPTHREAD) -ladvapi32 -lshell32 -luser32 -lkernel32
else
Copy link
Member

Choose a reason for hiding this comment

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

The hsdis build is very weird and outside the normal integrated JDK build. I recommend you leave this instance alone. If you want to port hsdis to BSD you are likely to have to rewrite large parts of the compilation logic here anyway.

Copy link
Author

Choose a reason for hiding this comment

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

Ack, I'll drop that one from the patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants