Skip to content

Commit

Permalink
8182285: Speeding up incremental build by hashing module APIs
Browse files Browse the repository at this point in the history
Reviewed-by: ihse
Contributed-by: [email protected], [email protected]
  • Loading branch information
erikj committed Oct 20, 2017
1 parent 3613f9b commit 16571ae
Show file tree
Hide file tree
Showing 6 changed files with 880 additions and 16 deletions.
13 changes: 12 additions & 1 deletion make/BuildNashorn.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,18 @@ $(eval $(call SetupJavaCompilation, jdk.scripting.nashorn, \
MODULE := jdk.scripting.nashorn, \
SRC := $(TOPDIR)/src/jdk.scripting.nashorn/share/classes, \
COPY := .properties .js, \
BIN := $(SUPPORT_OUTPUTDIR)/special_classes))
BIN := $(SUPPORT_OUTPUTDIR)/special_classes, \
CREATE_API_DIGEST := true, \
))

# Declare dependencies between java compilations of different modules.
# Since the other modules are declared in different invocations of this file,
# use the macro to find the correct target file to depend on.
# Only the javac compilation actually depends on other modules so limit
# dependency declaration to that by using the *_COMPILE_TARGET variable.
$(jdk.scripting.nashorn_COMPILE_TARGET): $(foreach d, $(call FindDepsForModule, jdk.scripting.nashorn), \
$(call SetupJavaCompilationApiTarget, $d, \
$(if $($d_BIN), $($d_BIN), $(JDK_OUTPUTDIR)/modules/$d)))

NASGEN_SRC := $(TOPDIR)/make/nashorn/buildtools/nasgen/src
ASM_SRC := $(TOPDIR)/src/java.base/share/classes/jdk/internal/org/objectweb/asm
Expand Down
3 changes: 2 additions & 1 deletion make/CompileJavaModules.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ $(eval $(call SetupJavaCompilation, $(MODULE), \
FAIL_NO_SRC := $(FAIL_NO_SRC), \
BIN := $(if $($(MODULE)_BIN), $($(MODULE)_BIN), $(JDK_OUTPUTDIR)/modules), \
HEADERS := $(SUPPORT_OUTPUTDIR)/headers, \
CREATE_API_DIGEST := true, \
ADD_JAVAC_FLAGS := \
$($(MODULE)_ADD_JAVAC_FLAGS) \
--module-source-path $(MODULESOURCEPATH) \
Expand All @@ -645,7 +646,7 @@ TARGETS += $($(MODULE)) $($(MODULE)_COPY_EXTRA)
# Only the javac compilation actually depends on other modules so limit
# dependency declaration to that by using the *_COMPILE_TARGET variable.
$($(MODULE)_COMPILE_TARGET): $(foreach d, $(call FindDepsForModule, $(MODULE)), \
$(call SetupJavaCompilationCompileTarget, $d, \
$(call SetupJavaCompilationApiTarget, $d, \
$(if $($d_BIN), $($d_BIN), $(JDK_OUTPUTDIR)/modules/$d)))

################################################################################
Expand Down
20 changes: 19 additions & 1 deletion make/CompileToolsJdk.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ BUILD_TOOLS_SRC_DIRS += \
$(BUILDTOOLS_OUTPUTDIR)/interim_cldrconverter_classes \
#

$(eval $(call SetupJavaCompilation, BUILD_TOOLS_JDK, \
$(eval $(call SetupJavaCompilation,BUILD_TOOLS_JDK, \
SETUP := GENERATE_OLDBYTECODE, \
SRC := $(BUILD_TOOLS_SRC_DIRS), \
EXCLUDES := \
build/tools/deps \
build/tools/docs \
build/tools/jigsaw \
build/tools/depend \
, \
BIN := $(BUILDTOOLS_OUTPUTDIR)/jdk_tools_classes, \
ADD_JAVAC_FLAGS := \
Expand All @@ -70,4 +71,21 @@ TARGETS += $(COPY_NIMBUS_TEMPLATES)

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

$(eval $(call SetupJavaCompilation, COMPILE_DEPEND, \
SETUP := GENERATE_OLDBYTECODE, \
SRC := $(TOPDIR)/make/jdk/src/classes, \
INCLUDES := build/tools/depend, \
BIN := $(BUILDTOOLS_OUTPUTDIR)/depend, \
))

DEPEND_SERVICE_PROVIDER := $(BUILDTOOLS_OUTPUTDIR)/depend/META-INF/services/com.sun.source.util.Plugin

$(DEPEND_SERVICE_PROVIDER):
$(call MakeDir, $(BUILDTOOLS_OUTPUTDIR)/depend/META-INF/services)
$(ECHO) build.tools.depend.Depend > $@

TARGETS += $(COMPILE_DEPEND) $(DEPEND_SERVICE_PROVIDER)

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

all: $(TARGETS)
42 changes: 29 additions & 13 deletions make/common/JavaCompilation.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ endef
# Parameter 1 is the name of the rule. This name is used as variable prefix,
# and the targets generated are listed in a variable by that name.
#
# The target for public API digest is returned in $1_API_TARGET.
#
# Remaining parameters are named arguments. These include:
# SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC
# JVM:=path to ..bin/java
Expand Down Expand Up @@ -175,6 +177,9 @@ endef
# FAIL_NO_SRC:=Set to false to not fail the build if no source files are found,
# default is true.
# DEBUG_SYMBOLS:=Set to false to disable generation of debug symbols.
# CREATE_API_DIGEST:=Set to true to use a javac plugin to generate a public API
# hash which can be used for down stream dependencies to only rebuild
# when the API changes. Implicitly used in sjavac.
SetupJavaCompilation = $(NamedParamsMacroTemplate)
define SetupJavaCompilationBody

Expand Down Expand Up @@ -327,6 +332,7 @@ define SetupJavaCompilationBody
$$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC))))

$1_COMPILE_TARGET := $$($1_BIN)$$($1_MODULE_SUBDIR)/_the.$1_batch
$1_API_TARGET := $$($1_BIN)$$($1_MODULE_SUBDIR)/_the.$1_pubapi

ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes)
# Using sjavac to compile.
Expand Down Expand Up @@ -386,13 +392,11 @@ define SetupJavaCompilationBody
# Create a pubapi file that only changes when the pubapi changes. Dependent
# compilations can use this file to only get recompiled when pubapi has changed.
# Grep returns 1 if no matching lines are found. Do not fail for this.
$(GREP) -e "^I" $$($1_BIN)$$($1_MODULE_SUBDIR)/javac_state > $$($1_BIN)$$($1_MODULE_SUBDIR)/_the.$1_pubapi.tmp \
|| test "$$$$?" = "1"
if [ ! -f $$($1_BIN)$$($1_MODULE_SUBDIR)/_the.$1_pubapi ] \
|| [ "`$(DIFF) $$($1_BIN)$$($1_MODULE_SUBDIR)/_the.$1_pubapi \
$$($1_BIN)$$($1_MODULE_SUBDIR)/_the.$1_pubapi.tmp`" != "" ]; then \
$(MV) $$($1_BIN)$$($1_MODULE_SUBDIR)/_the.$1_pubapi.tmp \
$$($1_BIN)$$($1_MODULE_SUBDIR)/_the.$1_pubapi; \
$(GREP) -e "^I" $$($1_BIN)$$($1_MODULE_SUBDIR)/javac_state \
> $$($1_API_TARGET).tmp || test "$$$$?" = "1"
if [ ! -f $$($1_API_TARGET) ] \
|| [ "`$(DIFF) $$($1_API_TARGET) $$($1_API_TARGET).tmp`" != "" ]; then \
$(MV) $$($1_API_TARGET).tmp $$($1_API_TARGET); \
fi

else
Expand Down Expand Up @@ -432,15 +436,26 @@ define SetupJavaCompilationBody
$1_JAVAC_CMD := $$($1_JAVAC)
endif

ifeq ($$($1_CREATE_API_DIGEST), true)
$1_API_DIGEST_FLAGS := \
-classpath $(BUILDTOOLS_OUTPUTDIR)/depend \
-Xplugin:"depend $$($1_API_TARGET)" \
#

$1_EXTRA_DEPS := $(BUILDTOOLS_OUTPUTDIR)/depend/_the.COMPILE_DEPEND_batch
endif

# When not using sjavac, pass along all sources to javac using an @file.
$$($1_COMPILE_TARGET): $$($1_SRCS) $$($1_DEPENDS) $$($1_VARDEPS_FILE)
$$($1_COMPILE_TARGET): $$($1_SRCS) $$($1_DEPENDS) $$($1_VARDEPS_FILE) \
$$($1_EXTRA_DEPS)
$$(call MakeDir, $$(@D))
$$(eval $$(call ListPathsSafely,$1_SRCS, [email protected]))
$$(call LogWarn, Compiling $$(words $$($1_SRCS)) files for $1)
$$(call ExecuteWithLog, $$($1_BIN)$$($1_MODULE_SUBDIR)/_the.$$($1_SAFE_NAME)_batch, \
$$($1_JVM) $$($1_JAVAC_CMD) $$($1_FLAGS) \
-implicit:none \
-d $$($1_BIN) $$($1_HEADERS_ARG) @[email protected]) && \
$$($1_API_DIGEST_FLAGS) \
-d $$($1_BIN) $$($1_HEADERS_ARG) @[email protected]) && \
$(MV) [email protected] $$@
endif

Expand Down Expand Up @@ -497,9 +512,10 @@ endef
# to declare and evaluate it again.
# param 1 is for example BUILD_MYPACKAGE
# param 2 is the output directory (BIN)
define SetupJavaCompilationCompileTarget
$(if $(findstring yes, $(ENABLE_SJAVAC)), $(strip $2)/_the.$(strip $1)_pubapi, \
$(strip $2)/_the.$(strip $1)_batch)
endef
SetupJavaCompilationCompileTarget = \
$(strip $2)/_the.$(strip $1)_batch

SetupJavaCompilationApiTarget = \
$(strip $2)/_the.$(strip $1)_pubapi

endif # _JAVA_COMPILATION_GMK
Loading

0 comments on commit 16571ae

Please sign in to comment.