Skip to content

8346719: Add relaunchers to the static JDK image for missing executables #24380

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

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions make/Main.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ $(eval $(call SetupTarget, symbols-image, \
TARGET := symbols, \
))

$(eval $(call SetupTarget, static-launcher, \
$(eval $(call SetupTarget, static-launchers, \
MAKEFILE := StaticLibs, \
TARGET := static-launcher, \
TARGET := static-launchers, \
DEPS := hotspot-static-libs static-libs, \
))

Expand Down Expand Up @@ -1282,7 +1282,7 @@ ifeq ($(call isTargetOs, macosx), true)
legacy-images: mac-legacy-jre-bundle
endif

static-exploded-image: static-launcher exploded-image
static-exploded-image: static-launchers exploded-image

# These targets build the various documentation images
docs-jdk-image: docs-jdk
Expand Down
17 changes: 17 additions & 0 deletions make/ModuleWrapper.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ ifeq ($(MAKEFILE_PREFIX), Lib)
endif
endif

ifeq ($(MAKEFILE_PREFIX), Launcher)
# We need to keep track of which launchers are created by this module. This
# information is required for static builds, to know which relaunchers to
# create. The variable $(MODULE)_INCLUDED_LAUNCHERS is added to for each call
# to SetupBuildLauncher. The file module-included-launchers.txt is then read
# in StaticLibs.gmk.
ifneq ($($(MODULE)_INCLUDED_LAUNCHERS), )
LAUNCHERS_LIST := $(SUPPORT_OUTPUTDIR)/modules_static-launchers/$(MODULE)/module-included-launchers.txt

$(LAUNCHERS_LIST): $(TARGETS)
$(call MakeDir, $(@D))
$(ECHO) $($(MODULE)_INCLUDED_LAUNCHERS) > $@

TARGETS += $(LAUNCHERS_LIST)
endif
endif

# Setup copy rules from the modules directories to the jdk image directory.
ifeq ($(call isTargetOs, windows), true)
TO_BIN_FILTER := %$(SHARED_LIBRARY_SUFFIX) %.diz %.pdb %.map
Expand Down
71 changes: 61 additions & 10 deletions make/StaticLibs.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ ifneq ($(word 2, $(wildcard $(HOTSPOT_STATIC_LIB_PATH))), )
endif

# Find all modules with static libraries
STATIC_LIB_MODULES := $(patsubst $(SUPPORT_OUTPUTDIR)/modules_static-libs/%, \
%, $(wildcard $(SUPPORT_OUTPUTDIR)/modules_static-libs/*))
STATIC_LIB_MODULES := $(sort $(patsubst $(SUPPORT_OUTPUTDIR)/modules_static-libs/%, \
%, $(wildcard $(SUPPORT_OUTPUTDIR)/modules_static-libs/*)))

# Filter out known broken libraries. This is a temporary measure until
# proper support for these libraries can be provided.
Expand Down Expand Up @@ -120,13 +120,18 @@ else
$(error Unsupported platform)
endif

################################################################################
# Build the java static launcher
################################################################################
$(eval $(call SetupBuildLauncher, java, \
ENABLE_ARG_FILES := true, \
EXPAND_CLASSPATH_WILDCARDS := true, \
EXTRA_RCFLAGS := $(JAVA_RCFLAGS), \
VERSION_INFO_RESOURCE := $(JAVA_VERSION_INFO_RESOURCE), \
OPTIMIZATION := HIGH, \
MACOSX_PRIVILEGED := true, \
STATIC_LAUNCHER := true, \
CFLAGS := -DSTATIC_BUILD, \
LDFLAGS := $(LDFLAGS_STATIC_JDK), \
LIBS := $(STATIC_LIBS) $(EXTERNAL_LIBS), \
LINK_TYPE := C++, \
Expand All @@ -143,7 +148,53 @@ TARGETS += $(java)

JAVA_LAUNCHER := $(BUILD_LAUNCHER_java_TARGET)

static-launcher: $(java)
static-launchers: $(java)

################################################################################
# Build relaunchers (thin wrappers calling the java binary) for all other
# JDK launchers.
################################################################################

RELAUNCHER_SRC := $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/launcher

# $1: The module name
# $2: The launcher name
define SetupRelauncher
$1_$2_LAUNCHER_ARGS_LINE := $$(shell cat $$(SUPPORT_OUTPUTDIR)/static-native/relaunchers/$1/$2-relauncher-arguments.txt)
# Restore |||| with space
$1_$2_LAUNCHER_ARGS := '{ $$(subst ||||,$(SPACE),$$(strip $$(foreach a, $$($1_$2_LAUNCHER_ARGS_LINE), "-J$$a"$$(COMMA) )) ) }'

$$(eval $$(call SetupJdkExecutable, BUILD_relauncher_$2, \
NAME := $2, \
EXTRA_FILES := $$(RELAUNCHER_SRC)/relauncher.c, \
CFLAGS := -DLAUNCHER_ARGS=$$($1_$2_LAUNCHER_ARGS), \
LIBS_windows := shlwapi.lib, \
OUTPUT_DIR := $$(STATIC_LAUNCHER_OUTPUT_DIR), \
OBJECT_DIR := $$(STATIC_LAUNCHER_OUTPUT_DIR)/relaunchers/$2, \
))

TARGETS += $$(BUILD_relauncher_$2)

RELAUNCHERS += $$(BUILD_relauncher_$2_TARGET)
static-launchers: $$(BUILD_relauncher_$2)
endef

# Find all modules with launchers
LAUNCHER_MODULES := $(sort $(patsubst $(SUPPORT_OUTPUTDIR)/modules_static-launchers/%, \
%, $(wildcard $(SUPPORT_OUTPUTDIR)/modules_static-launchers/*)))

# Find launchers for each module
$(foreach module, $(LAUNCHER_MODULES), \
$(eval LAUNCHERS_$(module) := $(if $(wildcard \
$(SUPPORT_OUTPUTDIR)/modules_static-launchers/$(module)/module-included-launchers.txt), \
$(shell cat \
$(SUPPORT_OUTPUTDIR)/modules_static-launchers/$(module)/module-included-launchers.txt))) \
)

# For all launchers (except java and javaw), setup a relauncher build
$(foreach module, $(LAUNCHER_MODULES), \
$(foreach launcher, $(filter-out java javaw, $(LAUNCHERS_$(module))), \
$(eval $(call SetupRelauncher,$(module),$(launcher)))))

################################################################################
#
Expand Down Expand Up @@ -185,26 +236,26 @@ TARGETS += $(copy-from-jdk-image)

$(copy-from-jdk-image): | static-jdk-info

$(eval $(call SetupCopyFiles, copy-static-launcher, \
FILES := $(JAVA_LAUNCHER), \
$(eval $(call SetupCopyFiles, copy-static-launchers, \
FILES := $(JAVA_LAUNCHER) $(RELAUNCHERS), \
DEST := $(STATIC_JDK_IMAGE_DIR)/bin, \
))

TARGETS += $(copy-static-launcher)
TARGETS += $(copy-static-launchers)

$(eval $(call SetupCopyFiles, copy-static-launcher-debuginfo, \
$(eval $(call SetupCopyFiles, copy-static-launchers-debuginfo, \
SRC := $(STATIC_LAUNCHER_OUTPUT_DIR), \
DEST := $(STATIC_JDK_IMAGE_DIR)/bin, \
FILES := $(call FindDebuginfoFiles, $(STATIC_LAUNCHER_OUTPUT_DIR)), \
))

TARGETS += $(copy-static-launcher-debuginfo)
TARGETS += $(copy-static-launchers-debuginfo)

static-jdk-image: $(copy-from-jdk-image) $(copy-static-launcher) $(copy-static-launcher-debuginfo)
static-jdk-image: $(copy-from-jdk-image) $(copy-static-launchers) $(copy-static-launchers-debuginfo)

TARGETS += static-jdk-image

.PHONY: static-launcher static-jdk-image
.PHONY: static-launchers static-jdk-image

################################################################################

Expand Down
47 changes: 41 additions & 6 deletions make/common/modules/LauncherCommon.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,50 @@ define SetupBuildLauncherBody

$1_MAIN_MODULE := $(MODULE)

# Record the fact that this launcher is part of the current module. This
# variable stores information about all created launchers, and is read by
# ModuleWrapper.
$$(MODULE)_INCLUDED_LAUNCHERS += $1

$1_RELAUNCHER_ARGUMENTS :=

ifneq ($$($1_MAIN_CLASS), )
$1_JAVA_ARGS += -Xms8m
$1_LAUNCHER_CLASS := -m $$($1_MAIN_MODULE)/$$($1_MAIN_CLASS)
endif

ifeq ($$($1_EXPAND_CLASSPATH_WILDCARDS), true)
$1_CFLAGS += -DEXPAND_CLASSPATH_WILDCARDS
ifeq ($$($1_ENABLE_ARG_FILES), true)
$1_CFLAGS += -DDISABLE_ARGFILE=JNI_FALSE
else
$1_CFLAGS += -DDISABLE_ARGFILE=JNI_TRUE
# This must be the first argument given, if it should be present
$1_RELAUNCHER_ARGUMENTS += -DjavaLauncherArgFiles=false
endif

ifeq ($$($1_ENABLE_ARG_FILES), true)
$1_CFLAGS += -DENABLE_ARG_FILES
ifeq ($$($1_EXPAND_CLASSPATH_WILDCARDS), true)
$1_CFLAGS += -DCLASSPATH_WILDCARDS=JNI_TRUE
else
$1_CFLAGS += -DCLASSPATH_WILDCARDS=JNI_FALSE
$1_RELAUNCHER_ARGUMENTS += -DjavaLauncherWildcards=false
endif

$1_RELAUNCHER_ARGUMENTS += -DjavaLauncherProgname=$1

ifeq ($(call isTargetOs, windows), true)
ifeq ($$($1_WINDOWS_JAVAW), true)
$1_CFLAGS += -DJAVAW
endif
endif

ifneq ($$($1_JAVA_ARGS), )
$1_JAVA_ARGS_STR := '{ $$(strip $$(foreach a, \
$$(addprefix -J, $$($1_JAVA_ARGS)) $$($1_LAUNCHER_CLASS), "$$a"$(COMMA) )) }'
$1_PREFIXED_JAVA_ARGS := $$(addprefix -J, $$($1_JAVA_ARGS)) \
$$($1_LAUNCHER_CLASS)
$1_JAVA_ARGS_STR := '{ $$(strip $$(foreach a, $$($1_PREFIXED_JAVA_ARGS), \
"$$a"$(COMMA) )) }'
$1_CFLAGS += -DJAVA_ARGS=$$($1_JAVA_ARGS_STR)
# To preserve spaces, substitute them with a hopefully unique pattern
$1_RELAUNCHER_ARGUMENTS += \
-DjavaLauncherArgs=$$(subst $$(SPACE),||||,$$($1_PREFIXED_JAVA_ARGS))
endif

ifeq ($(call isTargetOs, macosx), true)
Expand Down Expand Up @@ -172,6 +193,20 @@ define SetupBuildLauncherBody
))

$1 += $$(BUILD_LAUNCHER_$1)

$1_RELAUNCHER_ARGUMENTS_FILE := \
$$(SUPPORT_OUTPUTDIR)/static-native/relaunchers/$$(MODULE)/$1-relauncher-arguments.txt

$1_VARDEPS := $$($1_RELAUNCHER_ARGUMENTS)
$1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
$$($1_RELAUNCHER_ARGUMENTS_FILE).vardeps)

$$($1_RELAUNCHER_ARGUMENTS_FILE):
$$(call MakeDir, $$(@D))
$$(ECHO) '$$($1_RELAUNCHER_ARGUMENTS)' > $$@

$1 += $$($1_RELAUNCHER_ARGUMENTS_FILE)

TARGETS += $$($1)

$$(BUILD_LAUNCHER_$1): $$(BUILD_PLIST_$1)
Expand Down
2 changes: 1 addition & 1 deletion make/modules/java.base/Launcher.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ifeq ($(call isTargetOs, linux), true)

$(eval $(call SetupJdkExecutable, BUILD_JEXEC, \
NAME := jexec, \
SRC := $(TOPDIR)/src/$(MODULE)/unix/native/launcher, \
EXTRA_FILES := $(TOPDIR)/src/$(MODULE)/unix/native/launcher/jexec.c, \
OPTIMIZATION := LOW, \
EXTRA_HEADER_DIRS := libjli, \
CFLAGS_linux := -fPIC, \
Expand Down
75 changes: 0 additions & 75 deletions src/java.base/share/native/launcher/defines.h

This file was deleted.

Loading