--- a/doc/testing.html Wed Oct 17 22:47:59 2018 +0200
+++ b/doc/testing.html Wed Oct 17 23:28:08 2018 +0200
@@ -24,11 +24,13 @@
<li><a href="#test-selection">Test selection</a><ul>
<li><a href="#jtreg">JTReg</a></li>
<li><a href="#gtest">Gtest</a></li>
+<li><a href="#microbenchmarks">Microbenchmarks</a></li>
</ul></li>
<li><a href="#test-results-and-summary">Test results and summary</a></li>
<li><a href="#test-suite-control">Test suite control</a><ul>
<li><a href="#jtreg-keywords">JTReg keywords</a></li>
<li><a href="#gtest-keywords">Gtest keywords</a></li>
+<li><a href="#microbenchmark-keywords">Microbenchmark keywords</a></li>
</ul></li>
</ul>
</nav>
@@ -42,9 +44,11 @@
$ make run-test-only TEST="gtest:LogTagSet gtest:LogTagSetDescriptions" GTEST="REPEAT=-1"
$ make run-test TEST="hotspot:hotspot_gc" JTREG="JOBS=1;TIMEOUT=8;VM_OPTIONS=-XshowSettings -Xlog:gc+ref=debug"
$ make run-test TEST="jtreg:test/hotspot:hotspot_gc test/hotspot/jtreg/native_sanity/JniVersion.java"
+$ make run-test TEST="micro:java.lang.reflect" MICRO="FORK=1;WARMUP_ITER=2"
$ make exploded-run-test TEST=tier2</code></pre>
<h3 id="configuration">Configuration</h3>
<p>To be able to run JTReg tests, <code>configure</code> needs to know where to find the JTReg test framework. If it is not picked up automatically by configure, use the <code>--with-jtreg=<path to jtreg home></code> option to point to the JTReg framework. Note that this option should point to the JTReg home, i.e. the top directory, containing <code>lib/jtreg.jar</code> etc. (An alternative is to set the <code>JT_HOME</code> environment variable to point to the JTReg home before running <code>configure</code>.)</p>
+<p>To be able to run microbenchmarks, <code>configure</code> needs to know where to find the JMH dependency. Use <code>--with-jmh=<path to JMH jars></code> to point to a directory containing the core JMH and transitive dependencies. The recommended dependencies can be retrieved by running <code>sh make/devkit/createJMHBundle.sh</code>, after which <code>--with-jmh=build/jmh/jars</code> should work.</p>
<h2 id="test-selection">Test selection</h2>
<p>All functionality is available using the run-test make target. In this use case, the test or tests to be executed is controlled using the <code>TEST</code> variable. To speed up subsequent test runs with no source code changes, run-test-only can be used instead, which do not depend on the source and test image build.</p>
<p>For some common top-level tests, direct make targets have been generated. This includes all JTReg test groups, the hotspot gtest, and custom tests (if present). This means that <code>make run-test-tier1</code> is equivalent to <code>make run-test TEST="tier1"</code>, but the latter is more tab-completion friendly. For more complex test runs, the <code>run-test TEST="x"</code> solution needs to be used.</p>
@@ -59,6 +63,9 @@
<p>Since the Hotspot Gtest suite is so quick, the default is to run all tests. This is specified by just <code>gtest</code>, or as a fully qualified test descriptor <code>gtest:all</code>.</p>
<p>If you want, you can single out an individual test or a group of tests, for instance <code>gtest:LogDecorations</code> or <code>gtest:LogDecorations.level_test_vm</code>. This can be particularly useful if you want to run a shaky test repeatedly.</p>
<p>For Gtest, there is a separate test suite for each JVM variant. The JVM variant is defined by adding <code>/<variant></code> to the test descriptor, e.g. <code>gtest:Log/client</code>. If you specify no variant, gtest will run once for each JVM variant present (e.g. server, client). So if you only have the server JVM present, then <code>gtest:all</code> will be equivalent to <code>gtest:all/server</code>.</p>
+<h3 id="microbenchmarks">Microbenchmarks</h3>
+<p>Which microbenchmarks to run is selected using a regular expression following the <code>micro:</code> test descriptor, e.g., <code>micro:java.lang.reflect</code>. This delegates the test selection to JMH, meaning package name, class name and even benchmark method names can be used to select tests.</p>
+<p>Using special characters like <code>|</code> in the regular expression is possible, but needs to be escaped multiple times: <code>micro:ArrayCopy\\\\\|reflect</code>.</p>
<h2 id="test-results-and-summary">Test results and summary</h2>
<p>At the end of the test run, a summary of all tests run will be presented. This will have a consistent look, regardless of what test suites were used. This is a sample summary:</p>
<pre><code>==============================
@@ -118,5 +125,22 @@
<h4 id="options-1">OPTIONS</h4>
<p>Additional options to the Gtest test framework.</p>
<p>Use <code>GTEST="OPTIONS=--help"</code> to see all available Gtest options.</p>
+<h3 id="microbenchmark-keywords">Microbenchmark keywords</h3>
+<h4 id="fork">FORK</h4>
+<p>Override the number of benchmark forks to spawn. Same as specifying <code>-f <num></code>.</p>
+<h4 id="iter">ITER</h4>
+<p>Number of measurement iterations per fork. Same as specifying <code>-i <num></code>.</p>
+<h4 id="time">TIME</h4>
+<p>Amount of time to spend in each measurement iteration, in seconds. Same as specifying <code>-r <num></code></p>
+<h4 id="warmup_iter">WARMUP_ITER</h4>
+<p>Number of warmup iterations to run before the measurement phase in each fork. Same as specifying <code>-wi <num></code>.</p>
+<h4 id="warmup_time">WARMUP_TIME</h4>
+<p>Amount of time to spend in each warmup iteration. Same as specifying <code>-w <num></code>.</p>
+<h4 id="results_format">RESULTS_FORMAT</h4>
+<p>Specify to have the test run save a log of the values. Accepts the same values as <code>-rff</code>, i.e., <code>text</code>, <code>csv</code>, <code>scsv</code>, <code>json</code>, or <code>latex</code>.</p>
+<h4 id="vm_options-1">VM_OPTIONS</h4>
+<p>Additional VM arguments to provide to forked off VMs. Same as <code>-jvmArgs <args></code></p>
+<h4 id="options-2">OPTIONS</h4>
+<p>Additional arguments to send to JMH.</p>
</body>
</html>
--- a/doc/testing.md Wed Oct 17 22:47:59 2018 +0200
+++ b/doc/testing.md Wed Oct 17 23:28:08 2018 +0200
@@ -20,6 +20,7 @@
$ make run-test-only TEST="gtest:LogTagSet gtest:LogTagSetDescriptions" GTEST="REPEAT=-1"
$ make run-test TEST="hotspot:hotspot_gc" JTREG="JOBS=1;TIMEOUT=8;VM_OPTIONS=-XshowSettings -Xlog:gc+ref=debug"
$ make run-test TEST="jtreg:test/hotspot:hotspot_gc test/hotspot/jtreg/native_sanity/JniVersion.java"
+ $ make run-test TEST="micro:java.lang.reflect" MICRO="FORK=1;WARMUP_ITER=2"
$ make exploded-run-test TEST=tier2
### Configuration
@@ -31,6 +32,12 @@
containing `lib/jtreg.jar` etc. (An alternative is to set the `JT_HOME`
environment variable to point to the JTReg home before running `configure`.)
+To be able to run microbenchmarks, `configure` needs to know where to find
+the JMH dependency. Use `--with-jmh=<path to JMH jars>` to point to a directory
+containing the core JMH and transitive dependencies. The recommended dependencies
+can be retrieved by running `sh make/devkit/createJMHBundle.sh`, after which
+`--with-jmh=build/jmh/jars` should work.
+
## Test selection
All functionality is available using the run-test make target. In this use
@@ -98,6 +105,16 @@
variant present (e.g. server, client). So if you only have the server JVM
present, then `gtest:all` will be equivalent to `gtest:all/server`.
+### Microbenchmarks
+
+Which microbenchmarks to run is selected using a regular expression
+following the `micro:` test descriptor, e.g., `micro:java.lang.reflect`. This
+delegates the test selection to JMH, meaning package name, class name and even
+benchmark method names can be used to select tests.
+
+Using special characters like `|` in the regular expression is possible, but
+needs to be escaped multiple times: `micro:ArrayCopy\\\\\|reflect`.
+
## Test results and summary
At the end of the test run, a summary of all tests run will be presented. This
@@ -230,6 +247,35 @@
Use `GTEST="OPTIONS=--help"` to see all available Gtest options.
+### Microbenchmark keywords
+
+#### FORK
+Override the number of benchmark forks to spawn. Same as specifying `-f <num>`.
+
+#### ITER
+Number of measurement iterations per fork. Same as specifying `-i <num>`.
+
+#### TIME
+Amount of time to spend in each measurement iteration, in seconds. Same as
+specifying `-r <num>`
+
+#### WARMUP_ITER
+Number of warmup iterations to run before the measurement phase in each fork.
+Same as specifying `-wi <num>`.
+
+#### WARMUP_TIME
+Amount of time to spend in each warmup iteration. Same as specifying `-w <num>`.
+
+#### RESULTS_FORMAT
+Specify to have the test run save a log of the values. Accepts the same values
+as `-rff`, i.e., `text`, `csv`, `scsv`, `json`, or `latex`.
+
+#### VM_OPTIONS
+Additional VM arguments to provide to forked off VMs. Same as `-jvmArgs <args>`
+
+#### OPTIONS
+Additional arguments to send to JMH.
+
---
# Override some definitions in the global css file that are not optimal for
# this document.
--- a/make/Help.gmk Wed Oct 17 22:47:59 2018 +0200
+++ b/make/Help.gmk Wed Oct 17 23:28:08 2018 +0200
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2012, 2018, 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
@@ -103,6 +103,7 @@
$(info $(_) # make test TEST="jdk_lang jdk_net")
$(info $(_) JTREG="OPT1=x;OPT2=y" # Control the JTREG test harness for run-test)
$(info $(_) GTEST="OPT1=x;OPT2=y" # Control the GTEST test harness for run-test)
+ $(info $(_) MICRO="OPT1=x;OPT2=y" # Control the MICRO test harness for run-test)
$(info )
$(if $(all_confs), $(info Available configurations in $(build_dir):) $(foreach var,$(all_confs),$(info * $(var))),\
$(info No configurations were found in $(build_dir).) $(info Run 'bash configure' to create a configuration.))
--- a/make/InitSupport.gmk Wed Oct 17 22:47:59 2018 +0200
+++ b/make/InitSupport.gmk Wed Oct 17 23:28:08 2018 +0200
@@ -50,7 +50,7 @@
# Make control variables, handled by Init.gmk
INIT_CONTROL_VARIABLES += LOG CONF CONF_NAME SPEC JOBS TEST_JOBS CONF_CHECK \
- COMPARE_BUILD JTREG GTEST TEST_OPTS TEST_VM_OPTS
+ COMPARE_BUILD JTREG GTEST MICRO TEST_OPTS TEST_VM_OPTS
# All known make control variables
MAKE_CONTROL_VARIABLES := $(INIT_CONTROL_VARIABLES) TEST JDK_FILTER
--- a/make/Main.gmk Wed Oct 17 22:47:59 2018 +0200
+++ b/make/Main.gmk Wed Oct 17 23:28:08 2018 +0200
@@ -490,7 +490,7 @@
ALL_TARGETS += $(ALL_TEST_TARGETS) $(ALL_EXPLODED_TEST_TARGETS)
################################################################################
-# Build tests
+# Build tests and microbenchmarks
#
prepare-test-image:
@@ -552,12 +552,15 @@
-f BuildFailureHandler.gmk images)
endif
+build-microbenchmark:
+ +($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f test/BuildMicrobenchmark.gmk)
+
ALL_TARGETS += prepare-test-image build-test-hotspot-jtreg-native \
test-image-hotspot-jtreg-native build-test-jdk-jtreg-native \
test-image-jdk-jtreg-native build-test-lib build-test-failure-handler \
test-failure-handler test-image-failure-handler test-image-hotspot-gtest \
test-image-hotspot-jtreg-graal build-test-hotspot-jtreg-graal \
- run-test exploded-run-test
+ build-microbenchmark run-test exploded-run-test
################################################################################
# Run tests
@@ -818,6 +821,8 @@
jrtfs-jar: interim-langtools
+ build-microbenchmark: interim-langtools jdk.unsupported java.management
+
ifeq ($(ENABLE_GENERATE_CLASSLIST), true)
ifeq ($(CREATE_BUILDJDK), true)
# If creating a buildjdk, the interim image needs to be based on that.
@@ -1060,6 +1065,10 @@
test-image-jdk-jtreg-native test-image-failure-handler \
test-image-demos-jdk $(JVM_TEST_IMAGE_TARGETS)
+ifneq ($(JMH_CORE_JAR), )
+ test-image: build-microbenchmark
+endif
+
################################################################################
# all-images builds all our deliverables as images.
--- a/make/RunTests.gmk Wed Oct 17 22:47:59 2018 +0200
+++ b/make/RunTests.gmk Wed Oct 17 23:28:08 2018 +0200
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2016, 2018, 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
@@ -137,10 +137,10 @@
$(info Running tests using TEST_OPTS control variable '$(TEST_OPTS)')
endif
+### Jtreg
+
$(eval $(call SetTestOpt,VM_OPTIONS,JTREG))
$(eval $(call SetTestOpt,JAVA_OPTIONS,JTREG))
-$(eval $(call SetTestOpt,VM_OPTIONS,GTEST))
-$(eval $(call SetTestOpt,JAVA_OPTIONS,GTEST))
$(eval $(call SetTestOpt,JOBS,JTREG))
$(eval $(call SetTestOpt,TIMEOUT_FACTOR,JTREG))
@@ -156,6 +156,11 @@
$(info Running tests using JTREG control variable '$(JTREG)')
endif
+### Gtest
+
+$(eval $(call SetTestOpt,VM_OPTIONS,GTEST))
+$(eval $(call SetTestOpt,JAVA_OPTIONS,GTEST))
+
$(eval $(call ParseKeywordVariable, GTEST, \
SINGLE_KEYWORDS := REPEAT, \
STRING_KEYWORDS := OPTIONS VM_OPTIONS JAVA_OPTIONS, \
@@ -166,6 +171,21 @@
$(info Running tests using GTEST control variable '$(GTEST)')
endif
+### Microbenchmarks
+
+$(eval $(call SetTestOpt,VM_OPTIONS,MICRO))
+$(eval $(call SetTestOpt,JAVA_OPTIONS,MICRO))
+
+$(eval $(call ParseKeywordVariable, MICRO, \
+ SINGLE_KEYWORDS := ITER FORK TIME WARMUP_ITER WARMUP_TIME, \
+ STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS RESULTS_FORMAT TEST_JDK BENCHMARKS_JAR, \
+))
+
+ifneq ($(MICRO), )
+ # Inform the user
+ $(info Running tests using MICRO control variable '$(MICRO)')
+endif
+
################################################################################
# Component-specific Jtreg settings
@@ -222,6 +242,24 @@
)
endef
+# Helper function to determine if a test specification is a microbenchmark test
+#
+# It is a microbenchmark test if it is either "micro", or "micro:" followed by an optional
+# test filter string.
+define ParseMicroTestSelection
+ $(if $(filter micro%, $1), \
+ $(if $(filter micro, $1), \
+ micro:all \
+ , \
+ $(if $(filter micro:, $1), \
+ micro:all \
+ , \
+ $1 \
+ ) \
+ ) \
+ )
+endef
+
# Helper function that removes the TOPDIR part
CleanupJtregPath = \
$(strip $(patsubst %/, %, $(subst $(JTREG_TOPDIR)/,, $1)))
@@ -319,6 +357,9 @@
$(eval PARSED_TESTS += $(call ParseGtestTestSelection, $(test))) \
) \
$(if $(strip $(PARSED_TESTS)), , \
+ $(eval PARSED_TESTS += $(call ParseMicroTestSelection, $(test))) \
+ ) \
+ $(if $(strip $(PARSED_TESTS)), , \
$(eval PARSED_TESTS += $(call ParseJtregTestSelection, $(test))) \
) \
$(if $(strip $(PARSED_TESTS)), , \
@@ -434,6 +475,113 @@
################################################################################
+### Rules for Microbenchmarks
+
+# Helper function for SetupRunMicroTest. Set a MICRO_* variable from, in order:
+# 1) Specified by user on command line
+# 2) Generic default
+#
+# Note: No spaces are allowed around the arguments.
+# Arg $1 The test ID (i.e. $1 in SetupRunMicroTest)
+# Arg $2 Base variable, e.g. MICRO_TEST_JDK
+# Arg $3 The default value (optional)
+define SetMicroValue
+ ifneq ($$($2), )
+ $1_$2 := $$($2)
+ else
+ ifneq ($3, )
+ $1_$2 := $3
+ endif
+ endif
+endef
+
+SetupRunMicroTest = $(NamedParamsMacroTemplate)
+define SetupRunMicroTestBody
+ $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
+ $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
+ $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
+
+ $1_TEST_NAME := $$(strip $$(patsubst micro:%, %, $$($1_TEST)))
+
+ $$(eval $$(call SetMicroValue,$1,MICRO_BENCHMARKS_JAR,$$(TEST_IMAGE_DIR)/micro/microbenchmarks.jar))
+ $$(eval $$(call SetMicroValue,$1,MICRO_TEST_JDK,$$(JDK_IMAGE_DIR)))
+ $$(eval $$(call SetMicroValue,$1,MICRO_JAVA_OPTIONS))
+
+ # Current tests needs to open java.io
+ $1_MICRO_JAVA_OPTIONS += --add-opens=java.base/java.io=ALL-UNNAMED
+
+ # Save output as JSON or CSV file
+ ifneq ($$(MICRO_RESULTS_FORMAT), )
+ $1_MICRO_BASIC_OPTIONS += -rf $$(MICRO_RESULTS_FORMAT) -rff $$($1_TEST_RESULTS_DIR)/jmh-result.$(MICRO_RESULTS_FORMAT)
+ endif
+
+ ifneq ($$(MICRO_VM_OPTIONS)$$(MICRO_JAVA_OPTIONS), )
+ $1_MICRO_VM_OPTIONS := -jvmArgs $$(MICRO_VM_OPTIONS) $$(MICRO_JAVA_OPTIONS)
+ endif
+
+ ifneq ($$(MICRO_ITER), )
+ $1_MICRO_ITER := -i $$(MICRO_ITER)
+ endif
+ ifneq ($$(MICRO_FORK), )
+ $1_MICRO_FORK := -f $$(MICRO_FORK)
+ endif
+ ifneq ($$(MICRO_TIME), )
+ $1_MICRO_TIME := -r $$(MICRO_TIME)
+ endif
+ ifneq ($$(MICRO_WARMUP_ITER), )
+ $1_MICRO_WARMUP_ITER := -wi $$(MICRO_WARMUP_ITER)
+ endif
+ ifneq ($$(MICRO_WARMUP_TIME), )
+ $1_MICRO_WARMUP_TIME := -w $$(MICRO_WARMUP_TIME)
+ endif
+
+ run-test-$1:
+ $$(call LogWarn)
+ $$(call LogWarn, Running test '$$($1_TEST)')
+ $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
+ $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/micro, \
+ $$($1_MICRO_TEST_JDK)/bin/java $$($1_MICRO_JAVA_OPTIONS) -jar $$($1_MICRO_BENCHMARKS_JAR) \
+ $$($1_MICRO_ITER) $$($1_MICRO_FORK) $$($1_MICRO_TIME) \
+ $$($1_MICRO_WARMUP_ITER) $$($1_MICRO_WARMUP_TIME) \
+ $$($1_MICRO_VM_OPTIONS) $$($1_MICRO_BASIC_OPTIONS) $$(MICRO_OPTIONS) \
+ $$($1_TEST_NAME) \
+ > >($(TEE) $$($1_TEST_RESULTS_DIR)/micro.txt) \
+ && $$(ECHO) $$$$? > $$($1_EXITCODE) \
+ || $$(ECHO) $$$$? > $$($1_EXITCODE) \
+ )
+
+ $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/micro.txt
+
+ parse-test-$1: run-test-$1
+ $$(call LogWarn, Finished running test '$$($1_TEST)')
+ $$(call LogWarn, Test report is stored in $$(strip \
+ $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
+ $$(if $$(wildcard $$($1_EXITCODE)), \
+ $$(eval $1_EXIT_CODE := $$(shell $$(CAT) $$($1_EXITCODE))) \
+ $$(if $$(filter 0, $$($1_EXIT_CODE)), \
+ $$(eval $1_PASSED := 1) \
+ $$(eval $1_ERROR := 0) \
+ , \
+ $$(eval $1_PASSED := 0) \
+ $$(eval $1_ERROR := 1) \
+ ) \
+ $$(eval $1_FAILED := 0) \
+ $$(eval $1_TOTAL := $$(shell \
+ $$(EXPR) $$($1_PASSED) + $$($1_ERROR))) \
+ , \
+ $$(eval $1_PASSED := 0) \
+ $$(eval $1_FAILED := 0) \
+ $$(eval $1_ERROR := 1) \
+ $$(eval $1_TOTAL := 1) \
+ )
+
+ $1: run-test-$1 parse-test-$1
+
+ TARGETS += $1
+endef
+
+################################################################################
+
### Rules for Jtreg
# Helper function for SetupRunJtregTest. Set a JTREG_* variable from, in order:
@@ -707,6 +855,9 @@
UseGtestTestHandler = \
$(if $(filter gtest:%, $1), true)
+UseMicroTestHandler = \
+ $(if $(filter micro:%, $1), true)
+
UseJtregTestHandler = \
$(if $(filter jtreg:%, $1), true)
@@ -728,6 +879,11 @@
TEST := $(test), \
)) \
) \
+ $(if $(call UseMicroTestHandler, $(test)), \
+ $(eval $(call SetupRunMicroTest, $(TEST_ID), \
+ TEST := $(test), \
+ )) \
+ ) \
$(if $(call UseJtregTestHandler, $(test)), \
$(eval $(call SetupRunJtregTest, $(TEST_ID), \
TEST := $(test), \
--- a/make/autoconf/configure.ac Wed Oct 17 22:47:59 2018 +0200
+++ b/make/autoconf/configure.ac Wed Oct 17 23:28:08 2018 +0200
@@ -180,6 +180,9 @@
# Setup the JTReg Regression Test Harness.
TOOLCHAIN_SETUP_JTREG
+# Setup the Java Microbenchmark Harness (JMH)
+LIB_TESTS_SETUP_JMH
+
# Setup Jib dependency tool
TOOLCHAIN_SETUP_JIB
--- a/make/autoconf/lib-tests.m4 Wed Oct 17 22:47:59 2018 +0200
+++ b/make/autoconf/lib-tests.m4 Wed Oct 17 23:28:08 2018 +0200
@@ -55,3 +55,65 @@
AC_SUBST(GRAALUNIT_LIB)
])
+###############################################################################
+#
+# Setup and check the Java Microbenchmark Harness
+#
+AC_DEFUN_ONCE([LIB_TESTS_SETUP_JMH],
+[
+ AC_ARG_WITH(jmh, [AS_HELP_STRING([--with-jmh],
+ [Java Microbenchmark Harness for building the OpenJDK Microbenchmark Suite])])
+
+ AC_MSG_CHECKING([for jmh (Java Microbenchmark Harness)])
+ if test "x$with_jmh" = xno || test "x$with_jmh" = x; then
+ AC_MSG_RESULT([no, disabled])
+ elif test "x$with_jmh" = xyes; then
+ AC_MSG_RESULT([no, error])
+ AC_MSG_ERROR([--with-jmh requires a directory containing all jars needed by JMH])
+ else
+ # Path specified
+ JMH_HOME="$with_jmh"
+ if test ! -d [$JMH_HOME]; then
+ AC_MSG_RESULT([no, error])
+ AC_MSG_ERROR([$JMH_HOME does not exist or is not a directory])
+ fi
+ BASIC_FIXUP_PATH([JMH_HOME])
+
+ jar_names="jmh-core jmh-generator-annprocess jopt-simple commons-math3"
+ for jar in $jar_names; do
+ found_jar_files=$($ECHO $(ls $JMH_HOME/$jar-*.jar 2> /dev/null))
+
+ if test "x$found_jar_files" = x; then
+ AC_MSG_RESULT([no])
+ AC_MSG_ERROR([--with-jmh does not contain $jar-*.jar])
+ elif ! test -e "$found_jar_files"; then
+ AC_MSG_RESULT([no])
+ AC_MSG_ERROR([--with-jmh contain multiple $jar-*.jar: $found_jar_files])
+ fi
+
+ found_jar_var_name=found_${jar//-/_}
+ eval $found_jar_var_name='"'$found_jar_files'"'
+ done
+ AC_MSG_RESULT([yes])
+
+ JMH_CORE_JAR=$found_jmh_core
+ JMH_GENERATOR_JAR=$found_jmh_generator_annprocess
+ JMH_JOPT_SIMPLE_JAR=$found_jopt_simple
+ JMH_COMMONS_MATH_JAR=$found_commons_math3
+
+
+ if [ [[ "$JMH_CORE_JAR" =~ jmh-core-(.*)\.jar$ ]] ] ; then
+ JMH_VERSION=${BASH_REMATCH[[1]]}
+ else
+ JMH_VERSION=unknown
+ fi
+
+ AC_MSG_NOTICE([JMH core version: $JMH_VERSION])
+ fi
+
+ AC_SUBST(JMH_CORE_JAR)
+ AC_SUBST(JMH_GENERATOR_JAR)
+ AC_SUBST(JMH_JOPT_SIMPLE_JAR)
+ AC_SUBST(JMH_COMMONS_MATH_JAR)
+ AC_SUBST(JMH_VERSION)
+])
--- a/make/autoconf/spec.gmk.in Wed Oct 17 22:47:59 2018 +0200
+++ b/make/autoconf/spec.gmk.in Wed Oct 17 23:28:08 2018 +0200
@@ -355,6 +355,12 @@
LIBFFI_LIB_FILE:=@LIBFFI_LIB_FILE@
GRAALUNIT_LIB := @GRAALUNIT_LIB@
+JMH_CORE_JAR := @JMH_CORE_JAR@
+JMH_GENERATOR_JAR := @JMH_GENERATOR_JAR@
+JMH_JOPT_SIMPLE_JAR := @JMH_JOPT_SIMPLE_JAR@
+JMH_COMMONS_MATH_JAR := @JMH_COMMONS_MATH_JAR@
+JMH_VERSION := @JMH_VERSION@
+
# Source file for cacerts
CACERTS_FILE=@CACERTS_FILE@
--- a/make/common/FindTests.gmk Wed Oct 17 22:47:59 2018 +0200
+++ b/make/common/FindTests.gmk Wed Oct 17 23:28:08 2018 +0200
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2017, 2018, 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
@@ -72,6 +72,9 @@
# Add Gtest
ALL_NAMED_TESTS += gtest
+# Add microbenchmarks
+ALL_NAMED_TESTS += micro
+
################################################################################
endif # _FIND_TESTS_GMK
--- a/make/common/JarArchive.gmk Wed Oct 17 22:47:59 2018 +0200
+++ b/make/common/JarArchive.gmk Wed Oct 17 23:28:08 2018 +0200
@@ -43,6 +43,7 @@
# For this to work, the source files must exist when the makefile is
# parsed.
# SRCS:=List of directories in where to find files to add to archive
+# BIN:=Directory where to store build control files
# SUFFIXES:=File suffixes to include in jar
# INCLUDES:=List of directories/packages in SRCS that should be included
# EXCLUDES:=List of directories/packages in SRCS that should be excluded
@@ -62,10 +63,11 @@
$1_JARMAIN:=$(strip $$($1_JARMAIN))
$1_JARNAME:=$$(notdir $$($1_JAR))
- $1_MANIFEST_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_manifest
- $1_DELETESS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletess
- $1_DELETES_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletes
- $1_BIN:=$$(dir $$($1_JAR))
+ $1_JAR_OUTPUT_DIR := $$(patsubst %/, %, $$(dir $$($1_JAR)))
+ $$(call SetIfEmpty, $1_BIN, $$($1_JAR_OUTPUT_DIR))
+ $1_MANIFEST_FILE:=$$($1_BIN)/_the.$$($1_JARNAME)_manifest
+ $1_DELETESS_FILE:=$$($1_BIN)/_the.$$($1_JARNAME)_deletess
+ $1_DELETES_FILE:=$$($1_BIN)/_the.$$($1_JARNAME)_deletes
$$(call SetIfEmpty, $1_JAR_CMD, $$(JAR))
ifeq (,$$($1_SUFFIXES))
@@ -231,11 +233,12 @@
$1_VARDEPS := $$($1_JAR_CMD) $$($1_JAR_CREATE_OPTIONS) $$($1_MANIFEST) \
$$($1_JARMAIN) $$($1_EXTRA_MANIFEST_ATTR) $$($1_ORIG_DEPS) $$($1_SRCS) \
$$($1_INCLUDES) $$($1_EXCLUDES) $$($1_EXCLUDE_FILES) $$($1_EXTRA_FILES)
- $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$(dir $$($1_JAR))_the.$$($1_JARNAME).vardeps)
+ $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_BIN)/_the.$$($1_JARNAME).vardeps)
# Here is the rule that creates/updates the jar file.
$$($1_JAR) : $$($1_DEPENDENCIES) $$($1_MANIFEST) $$($1_VARDEPS_FILE)
$$(call MakeTargetDir)
+ $$(call MakeDir, $$($1_BIN))
$$($1_GREP_INCLUDE_OUTPUT)
$$($1_GREP_EXCLUDE_OUTPUT)
# If the vardeps file is part of the newer prereq list, it means that
--- a/make/conf/jib-profiles.js Wed Oct 17 22:47:59 2018 +0200
+++ b/make/conf/jib-profiles.js Wed Oct 17 23:28:08 2018 +0200
@@ -239,7 +239,7 @@
// These are the base setttings for all the main build profiles.
common.main_profile_base = {
- dependencies: ["boot_jdk", "gnumake", "jtreg", "jib", "autoconf"],
+ dependencies: ["boot_jdk", "gnumake", "jtreg", "jib", "autoconf", "jmh"],
default_make_targets: ["product-bundles", "test-bundles"],
configure_args: concat(["--enable-jtreg-failure-handler"],
"--with-exclude-translations=de,es,fr,it,ko,pt_BR,sv,ca,tr,cs,sk,ja_JP_A,ja_JP_HA,ja_JP_HI,ja_JP_I,zh_TW,zh_HK",
@@ -916,6 +916,12 @@
environment_path: input.get("jtreg", "install_path") + "/jtreg/bin"
},
+ jmh: {
+ organization: common.organization,
+ ext: "tar.gz",
+ revision: "1.21+1.0"
+ },
+
gnumake: {
organization: common.organization,
ext: "tar.gz",
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/make/devkit/createJMHBundle.sh Wed Oct 17 23:28:08 2018 +0200
@@ -0,0 +1,50 @@
+#!/bin/bash -e
+#
+# Copyright (c) 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation. Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+# Create a bundle in the build directory, containing what's needed to
+# build and run JMH microbenchmarks from the OpenJDK build.
+
+JMH_VERSION=1.21
+COMMONS_MATH3_VERSION=3.2
+JOPT_SIMPLE_VERSION=4.6
+
+BUNDLE_NAME=jmh-$JMH_VERSION.tar.gz
+
+SCRIPT_DIR="$(cd "$(dirname $0)" > /dev/null && pwd)"
+BUILD_DIR="${SCRIPT_DIR}/../../build/jmh"
+JAR_DIR="$BUILD_DIR/jars"
+
+mkdir -p $BUILD_DIR $JAR_DIR
+cd $JAR_DIR
+rm -f *
+
+wget http://central.maven.org/maven2/org/apache/commons/commons-math3/$COMMONS_MATH3_VERSION/commons-math3-$COMMONS_MATH3_VERSION.jar
+wget http://central.maven.org/maven2/net/sf/jopt-simple/jopt-simple/$JOPT_SIMPLE_VERSION/jopt-simple-$JOPT_SIMPLE_VERSION.jar
+wget http://central.maven.org/maven2/org/openjdk/jmh/jmh-core/$JMH_VERSION/jmh-core-$JMH_VERSION.jar
+wget http://central.maven.org/maven2/org/openjdk/jmh/jmh-generator-annprocess/$JMH_VERSION/jmh-generator-annprocess-$JMH_VERSION.jar
+
+tar -cvzf ../$BUNDLE_NAME *
+
+echo "Created $BUILD_DIR/$BUNDLE_NAME"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/make/test/BuildMicrobenchmark.gmk Wed Oct 17 23:28:08 2018 +0200
@@ -0,0 +1,114 @@
+#
+# Copyright (c) 2018, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation. Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# This must be the first rule
+default: all
+
+include $(SPEC)
+include MakeBase.gmk
+include JavaCompilation.gmk
+include SetupJavaCompilers.gmk
+
+ifeq ($(JMH_CORE_JAR), )
+ $(info Error: JMH is missing. Please use configure --with-jmh.)
+ $(error Cannot continue)
+endif
+
+#### Variables
+
+MICROBENCHMARK_SRC := $(TOPDIR)/test/micro/classes
+MICROBENCHMARK_RES := $(TOPDIR)/test/micro/resources
+MICROBENCHMARK_JAR := $(IMAGES_OUTPUTDIR)/test/micro/microbenchmarks.jar
+
+MICROBENCHMARK_OUTPUT := $(SUPPORT_OUTPUTDIR)/test/micro
+MICROBENCHMARK_CLASSES := $(MICROBENCHMARK_OUTPUT)/classes
+MICROBENCHMARK_JAR_BIN := $(MICROBENCHMARK_OUTPUT)/jar
+
+JMH_UNPACKED_DIR := $(MICROBENCHMARK_OUTPUT)/jmh_jars
+JMH_UNPACKED_JARS_DONE := $(JMH_UNPACKED_DIR)/_unpacked.marker
+
+# External dependencies
+JMH_COMPILE_JARS := $(JMH_CORE_JAR) $(JMH_GENERATOR_JAR)
+JMH_RUNTIME_JARS := $(JMH_CORE_JAR) $(JMH_COMMONS_MATH_JAR) $(JMH_JOPT_SIMPLE_JAR)
+
+MICROBENCHMARK_CLASSPATH := $(call PathList, $(JMH_COMPILE_JARS))
+
+###
+
+# Need double \n to get new lines and no trailing spaces
+MICROBENCHMARK_MANIFEST := Build: $(FULL_VERSION)\n\
+\nJMH-Version: $(JMH_VERSION)\n\
+\nName: OpenJDK Microbenchmark Suite
+
+
+#### Compile Targets
+
+# Building microbenchmark requires the jdk.unsupported and java.management modules,
+# and to have sjavac disabled.
+$(eval $(call SetupJavaCompiler, MICROBENCHMARK_JAVA_COMPILER, \
+ JVM := $(JAVA_SMALL) --add-modules jdk.unsupported --limit-modules java.management, \
+ JAVAC := $(NEW_JAVAC), \
+ DISABLE_SJAVAC := true, \
+ FLAGS := --upgrade-module-path $(JDK_OUTPUTDIR)/modules --system none $(DISABLE_WARNINGS), \
+ SERVER_DIR := $(SJAVAC_SERVER_DIR), \
+ SERVER_JVM := $(SJAVAC_SERVER_JAVA), \
+))
+
+# Build microbenchmark suite for the current JDK
+$(eval $(call SetupJavaCompilation, BUILD_JDK_MICROBENCHMARK, \
+ SETUP := MICROBENCHMARK_JAVA_COMPILER, \
+ ADD_JAVAC_FLAGS := -cp $(MICROBENCHMARK_CLASSPATH) -Xlint -Werror, \
+ SRC := $(MICROBENCHMARK_SRC), \
+ BIN := $(MICROBENCHMARK_CLASSES), \
+))
+
+$(BUILD_JDK_MICROBENCHMARK): $(JMH_COMPILE_JARS)
+
+# Unpacking dependencies for inclusion in the benchmark JARs
+$(JMH_UNPACKED_JARS_DONE): $(JMH_RUNTIME_JARS)
+ $(RM) -r $(JMH_UNPACKED_DIR)
+ $(MKDIR) -p $(JMH_UNPACKED_DIR)
+ $(foreach jar, $(JMH_RUNTIME_JARS), \
+ $$($(UNZIP) -oq $(jar) -d $(JMH_UNPACKED_DIR)))
+ $(RM) -r $(JMH_UNPACKED_DIR)/META-INF
+ $(RM) $(JMH_UNPACKED_DIR)/*.xml
+ $(TOUCH) $@
+
+# Create benchmarks JAR file with benchmarks for both the old and new JDK
+$(eval $(call SetupJarArchive, BUILD_JDK_JAR, \
+ DEPENDENCIES := $(BUILD_JDK_MICROBENCHMARK) $(JMH_UNPACKED_JARS_DONE), \
+ SRCS := $(MICROBENCHMARK_CLASSES) $(JMH_UNPACKED_DIR) $(MICROBENCHMARK_RES), \
+ BIN := $(MICROBENCHMARK_JAR_BIN), \
+ SUFFIXES := .*, \
+ EXCLUDE_FILES:= _the.BUILD_JDK_MICROBENCHMARK_batch \
+ _the.BUILD_JDK_MICROBENCHMARK.vardeps _unpacked.marker, \
+ EXTRA_MANIFEST_ATTR := $(MICROBENCHMARK_MANIFEST), \
+ JARMAIN := org.openjdk.jmh.Main, \
+ JAR := $(MICROBENCHMARK_JAR), \
+))
+
+all: $(MICROBENCHMARK_JAR)
+
+.PHONY: all
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/micro/classes/org/openjdk/bench/java/lang/ArrayCopy.java Wed Oct 17 23:28:08 2018 +0200
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2014 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.bench.java.lang;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OperationsPerInvocation;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Benchmark measuring System.arraycopy in different ways.
+ */
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@State(Scope.Thread)
+public class ArrayCopy {
+
+ private static final byte[] TEST_BYTES = "HTTP/1.0".getBytes();
+ private static final char[] TEST_CHARS = new char[46];
+ private static final Object[] TEST_OBJECTS = new Object[200]; // Uses a minimum of 160 internal positions for internal copying
+
+ // a length which the compiler cannot prove is a constant
+ public static int nonConstCharLength = TEST_CHARS.length;
+ public static int nonConstByteLength = TEST_BYTES.length;
+ public static int nonConstObjectLength = TEST_OBJECTS.length;
+
+ // Use this array to copy objects in.
+ public char[] dummyCharArray = new char[TEST_CHARS.length];
+ public byte[] dummyByteArray = new byte[TEST_BYTES.length];
+ public Object[] dummyObjectArray = new Object[TEST_OBJECTS.length];
+
+ @Setup
+ public void setup() {
+ for (int i = 0; i < TEST_OBJECTS.length; i++) {
+ TEST_OBJECTS[i] = new Object();
+ dummyObjectArray[i] = new Object();
+ }
+ }
+
+ /**
+ * This test case do the same work as testArrayCopy. We should make sure
+ * testArrayCopy is equally fast or better. Compare the two and you measure
+ * the system call versus explicit copy for-loop.
+ */
+ @Benchmark
+ public void copyLoop() {
+ for (int j = 0; j < dummyByteArray.length; j++) {
+ dummyByteArray[j] = TEST_BYTES[j];
+ }
+ }
+
+ /**
+ * Test that we can optimize away the code since it should not have any side
+ * effects
+ */
+ @Benchmark
+ public void copyLoopLocalArray() {
+ byte[] localDummyByteArray = new byte[TEST_BYTES.length];
+ for (int j = 0; j < localDummyByteArray.length; j++) {
+ localDummyByteArray[j] = TEST_BYTES[j];
+ }
+ }
+
+ /**
+ * This test case do the same work as testArrayCopy. We should make sure
+ * testArrayCopy is equally fast or better. Compare the two and you measure
+ * the system call versus explicit copy for-loop.
+ * <p/>
+ * Uses non-provable constant length.
+ */
+ @Benchmark
+ public void copyLoopNonConst() {
+ for (int i = 0; i < nonConstByteLength; i++) {
+ dummyByteArray[i] = TEST_BYTES[i];
+ }
+ }
+
+ /**
+ * This test case do the same work as testCopyLoop. We should make sure
+ * testArrayCopy is equally fast or better. Compare the two and you measure
+ * the system call versus explicit copy for-loop.
+ */
+ @Benchmark
+ public void arrayCopy() {
+ System.arraycopy(TEST_BYTES, 0, dummyByteArray, 0, dummyByteArray.length);
+ }
+
+ /**
+ * Test that we can optimize away the code since it should not have any side
+ * effects
+ */
+ @Benchmark
+ public void arrayCopyLocalArray() {
+ byte[] localDummyByteArray = new byte[TEST_BYTES.length];
+ System.arraycopy(TEST_BYTES, 0, localDummyByteArray, 0, localDummyByteArray.length);
+ }
+
+ /**
+ * This test case do the same work as testCopyLoop. We should make sure
+ * testArrayCopy is equally fast or better. Compare the two and you measure
+ * the system call versus explicit copy for-loop.
+ * <p/>
+ * Uses non-provable constant length.
+ */
+ @Benchmark
+ public void arrayCopyNonConst() {
+ System.arraycopy(TEST_BYTES, 0, dummyByteArray, 0, nonConstByteLength);
+ }
+
+ @Benchmark
+ public void arrayCopyChar() {
+ System.arraycopy(TEST_CHARS, 0, dummyCharArray, 0, dummyCharArray.length);
+ }
+
+ @Benchmark
+ public void arrayCopyCharNonConst() {
+ System.arraycopy(TEST_CHARS, 0, dummyCharArray, 0, nonConstCharLength);
+ }
+
+ @Benchmark
+ public void arrayCopyObject() {
+ System.arraycopy(TEST_OBJECTS, 0, dummyObjectArray, 0, dummyObjectArray.length);
+ }
+
+ @Benchmark
+ public void arrayCopyObjectNonConst() {
+ System.arraycopy(TEST_OBJECTS, 0, dummyObjectArray, 0, nonConstObjectLength);
+ }
+
+ /**
+ * This test copies inside a object array, that is same source array as dest
+ * array. Copies backwards in the array.
+ */
+ @Benchmark
+ @OperationsPerInvocation(40)
+ public void arrayCopyObjectSameArraysBackward() {
+ for (int i = 0; i < 40; i++) {
+ System.arraycopy(dummyObjectArray, i, dummyObjectArray, i + 40, 80);
+ }
+ }
+
+ /**
+ * This test copies inside a object array, that is same source array as dest
+ * array. Copies forward in the array. There is a special version for this
+ * in JRockit.
+ */
+ @Benchmark
+ @OperationsPerInvocation(40)
+ public void arrayCopyObjectSameArraysForward() {
+ for (int i = 0; i < 40; i++) {
+ System.arraycopy(dummyObjectArray, i + 40, dummyObjectArray, i, 80);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/micro/classes/org/openjdk/bench/java/lang/reflect/Clazz.java Wed Oct 17 23:28:08 2018 +0200
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2014 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.bench.java.lang.reflect;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.concurrent.TimeUnit;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+public class Clazz {
+
+ /**
+ * Get constructor for this class through reflection
+ *
+ * @return
+ * @throws NoSuchMethodException
+ */
+ @Benchmark
+ public Constructor getConstructor() throws NoSuchMethodException {
+ return Clazz.class.getConstructor();
+ }
+
+ /**
+ * Get constructor for the String class through reflection, forcing full
+ * security check
+ *
+ * @return
+ * @throws NoSuchMethodException
+ */
+ @Benchmark
+ public Constructor getConstructorDifferentClassLoader() throws NoSuchMethodException {
+ return String.class.getConstructor();
+ }
+
+ /**
+ * Get the toString method through reflection on Clazz
+ *
+ * @return
+ */
+ @Benchmark
+ public Method getMethod() throws NoSuchMethodException {
+ return Clazz.class.getMethod("toString");
+ }
+
+ /**
+ * Get the toString method through reflection on String, forcing full
+ * security check
+ *
+ * @return
+ * @throws NoSuchMethodException
+ */
+ @Benchmark
+ public Method getMethodDifferentClassLoader() throws NoSuchMethodException {
+ return String.class.getMethod("toString");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/micro/classes/org/openjdk/bench/java/lang/reflect/ClazzWithSecurityManager.java Wed Oct 17 23:28:08 2018 +0200
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2014 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.bench.java.lang.reflect;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.NoSuchAlgorithmException;
+import java.security.Policy;
+import java.security.URIParameter;
+
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+
+/**
+ * Reflection benchmark
+ *
+ * @author sfriberg
+ */
+@State(Scope.Benchmark)
+public class ClazzWithSecurityManager extends Clazz {
+
+ @Setup
+ public void setup() throws IOException, NoSuchAlgorithmException, URISyntaxException {
+ URI policyFile = ClazzWithSecurityManager.class.getResource("/jmh-security.policy").toURI();
+ Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(policyFile)));
+ System.setSecurityManager(new SecurityManager());
+ }
+}