diff --git a/doc/testing.html b/doc/testing.html
index 6285fab1682e..c1c0f15fed95 100644
--- a/doc/testing.html
+++ b/doc/testing.html
@@ -411,6 +411,13 @@ instrumentation
special target jcov-test instead of test, e.g.
make jcov-test TEST=jdk_lang. This will make sure the JCov
image is built, and that JCov reporting is enabled.
To include JCov coverage for just a subset of all modules, you can
+use the --with-jcov-modules arguments to
+configure, e.g.
+--with-jcov-modules=jdk.compiler,java.desktop.
For more fine-grained control, you can pass arbitrary filters to JCov
+using --with-jcov-filters, and you can specify a specific
+JDK to instrument using --with-jcov-input-jdk.
The JCov report is stored in
build/$BUILD/test-results/jcov-output/report.
Please note that running with JCov reporting can be very memory
diff --git a/doc/testing.md b/doc/testing.md
index 351690c5e601..f6a25457b5ea 100644
--- a/doc/testing.md
+++ b/doc/testing.md
@@ -345,6 +345,14 @@ The simplest way to run tests with JCov coverage report is to use the special
target `jcov-test` instead of `test`, e.g. `make jcov-test TEST=jdk_lang`. This
will make sure the JCov image is built, and that JCov reporting is enabled.
+To include JCov coverage for just a subset of all modules, you can use the
+`--with-jcov-modules` arguments to `configure`, e.g.
+`--with-jcov-modules=jdk.compiler,java.desktop`.
+
+For more fine-grained control, you can pass arbitrary filters to JCov using
+`--with-jcov-filters`, and you can specify a specific JDK to instrument
+using `--with-jcov-input-jdk`.
+
The JCov report is stored in `build/$BUILD/test-results/jcov-output/report`.
Please note that running with JCov reporting can be very memory intensive.
diff --git a/make/Coverage.gmk b/make/Coverage.gmk
index 2fd4e4ec6d45..a375c343185e 100644
--- a/make/Coverage.gmk
+++ b/make/Coverage.gmk
@@ -34,21 +34,28 @@ else
JCOV_INPUT_IMAGE_DIR := $(JDK_IMAGE_DIR)
endif
+JCOV_SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/jcov
+
#moving instrumented jdk image in and out of jcov_temp because of CODETOOLS-7902299
-JCOV_TEMP := $(SUPPORT_OUTPUTDIR)/jcov_temp
+JCOV_TEMP := $(JCOV_SUPPORT_DIR)/temp
+
+ifneq ($(JCOV_MODULES), )
+ JCOV_MODULES_FILTER := $(foreach m, $(JCOV_MODULES), -include_module $m)
+endif
$(JCOV_IMAGE_DIR)/release: $(JCOV_INPUT_IMAGE_DIR)/release
$(call LogWarn, Creating instrumented jdk image with JCov)
$(call MakeDir, $(JCOV_TEMP) $(IMAGES_OUTPUTDIR))
$(RM) -r $(JCOV_IMAGE_DIR) $(JCOV_TEMP)/*
$(CP) -r $(JCOV_INPUT_IMAGE_DIR) $(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR)
- $(JAVA) -Xmx3g -jar $(JCOV_HOME)/lib/jcov.jar JREInstr \
+ $(call ExecuteWithLog, $(JCOV_SUPPORT_DIR)/run-jcov, \
+ $(JAVA) -Xmx3g -jar $(JCOV_HOME)/lib/jcov.jar JREInstr \
-t $(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR)/template.xml \
-rt $(JCOV_HOME)/lib/jcov_network_saver.jar \
-exclude 'java.lang.Object' \
-exclude jdk.test.Main -exclude '**\$Proxy*' \
- $(JCOV_FILTERS) \
- $(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR)
+ $(JCOV_MODULES_FILTER) $(JCOV_FILTERS) \
+ $(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR))
$(MV) $(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR) $(JCOV_IMAGE_DIR)
$(RMDIR) $(JCOV_TEMP)
diff --git a/make/RunTests.gmk b/make/RunTests.gmk
index 4881d585e5cc..3c0280353a9a 100644
--- a/make/RunTests.gmk
+++ b/make/RunTests.gmk
@@ -115,6 +115,7 @@ JTREG_COV_OPTIONS :=
ifeq ($(TEST_OPTS_JCOV), true)
JCOV_OUTPUT_DIR := $(TEST_RESULTS_DIR)/jcov-output
+ JCOV_SUPPORT_DIR := $(TEST_SUPPORT_DIR)/jcov-support
JCOV_GRABBER_LOG := $(JCOV_OUTPUT_DIR)/grabber.log
JCOV_RESULT_FILE := $(JCOV_OUTPUT_DIR)/result.xml
JCOV_REPORT := $(JCOV_OUTPUT_DIR)/report
@@ -1363,6 +1364,10 @@ ifeq ($(TEST_OPTS_JCOV), true)
$(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -stop -stoptimeout 3600
JCOV_REPORT_TITLE := JDK code coverage report
+ ifneq ($(JCOV_MODULES), )
+ JCOV_MODULES_FILTER := $(foreach m, $(JCOV_MODULES), -include_module $m)
+ JCOV_REPORT_TITLE += Included modules: $(JCOV_MODULES)
+ endif
ifneq ($(JCOV_FILTERS), )
JCOV_REPORT_TITLE += Code filters: $(JCOV_FILTERS)
endif
@@ -1370,11 +1375,12 @@ ifeq ($(TEST_OPTS_JCOV), true)
jcov-gen-report: jcov-stop-grabber
$(call LogWarn, Generating JCov report ...)
- $(JAVA) $(JCOV_VM_OPTS) -jar $(JCOV_HOME)/lib/jcov.jar RepGen -sourcepath \
+ $(call ExecuteWithLog, $(JCOV_SUPPORT_DIR)/run-jcov-repgen, \
+ $(JAVA) $(JCOV_VM_OPTS) -jar $(JCOV_HOME)/lib/jcov.jar RepGen -sourcepath \
`$(ECHO) $(TOPDIR)/src/*/share/classes/ | $(TR) ' ' ':'` -fmt html \
- $(JCOV_FILTERS) \
+ $(JCOV_MODULES_FILTER) $(JCOV_FILTERS) \
-mainReportTitle "$(JCOV_REPORT_TITLE)" \
- -o $(JCOV_REPORT) $(JCOV_RESULT_FILE)
+ -o $(JCOV_REPORT) $(JCOV_RESULT_FILE))
TARGETS += jcov-do-start-grabber jcov-start-grabber jcov-stop-grabber \
jcov-gen-report
diff --git a/make/autoconf/jdk-options.m4 b/make/autoconf/jdk-options.m4
index f8a512f503d2..289ed935fdfe 100644
--- a/make/autoconf/jdk-options.m4
+++ b/make/autoconf/jdk-options.m4
@@ -405,10 +405,19 @@ AC_DEFUN_ONCE([JDKOPT_SETUP_CODE_COVERAGE],
JCOV_FILTERS="$with_jcov_filters"
fi
fi
+
+ UTIL_ARG_WITH(NAME: jcov-modules, TYPE: string,
+ DEFAULT: [], RESULT: JCOV_MODULES_COMMMA_SEPARATED,
+ DESC: [which modules to include in jcov (comma-separated)],
+ OPTIONAL: true)
+
+ # Replace "," with " ".
+ JCOV_MODULES=${JCOV_MODULES_COMMMA_SEPARATED//,/ }
AC_SUBST(JCOV_ENABLED)
AC_SUBST(JCOV_HOME)
AC_SUBST(JCOV_INPUT_JDK)
AC_SUBST(JCOV_FILTERS)
+ AC_SUBST(JCOV_MODULES)
])
################################################################################
diff --git a/make/autoconf/spec.gmk.template b/make/autoconf/spec.gmk.template
index ebaa487b40a1..e720916d88a4 100644
--- a/make/autoconf/spec.gmk.template
+++ b/make/autoconf/spec.gmk.template
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2025, 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
@@ -454,6 +454,7 @@ JCOV_ENABLED := @JCOV_ENABLED@
JCOV_HOME := @JCOV_HOME@
JCOV_INPUT_JDK := @JCOV_INPUT_JDK@
JCOV_FILTERS := @JCOV_FILTERS@
+JCOV_MODULES := @JCOV_MODULES@
# AddressSanitizer
ASAN_ENABLED := @ASAN_ENABLED@