--- a/make/Help.gmk Tue Oct 09 11:44:00 2018 +0100
+++ b/make/Help.gmk Tue Oct 09 14:37:59 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 Tue Oct 09 11:44:00 2018 +0100
+++ b/make/InitSupport.gmk Tue Oct 09 14:37:59 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 Tue Oct 09 11:44:00 2018 +0100
+++ b/make/Main.gmk Tue Oct 09 14:37:59 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 Tue Oct 09 11:44:00 2018 +0100
+++ b/make/RunTests.gmk Tue Oct 09 14:37:59 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
@@ -107,12 +107,15 @@
# Parse control variables
################################################################################
+### Jtreg
+
ifneq ($(TEST_OPTS), )
# Inform the user
$(info Running tests using TEST_OPTS control variable '$(TEST_OPTS)')
$(eval $(call SetTestOpt,VM_OPTIONS,JTREG))
$(eval $(call SetTestOpt,VM_OPTIONS,GTEST))
+ $(eval $(call SetTestOpt,VM_OPTIONS,MICRO))
$(eval $(call SetTestOpt,JOBS,JTREG))
$(eval $(call SetTestOpt,TIMEOUT,JTREG))
@@ -128,6 +131,8 @@
$(info Running tests using JTREG control variable '$(JTREG)')
endif
+### Gtest
+
$(eval $(call ParseKeywordVariable, GTEST, \
KEYWORDS := REPEAT, \
STRING_KEYWORDS := OPTIONS VM_OPTIONS, \
@@ -138,6 +143,18 @@
$(info Running tests using GTEST control variable '$(GTEST)')
endif
+### Microbenchmarks
+
+$(eval $(call ParseKeywordVariable, MICRO, \
+ 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
@@ -203,6 +220,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)))
@@ -300,6 +335,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)), , \
@@ -414,6 +452,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), )
+ $1_MICRO_VM_OPTIONS := -jvmArgs $$(MICRO_VM_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:
@@ -668,6 +813,9 @@
UseGtestTestHandler = \
$(if $(filter gtest:%, $1), true)
+UseMicroTestHandler = \
+ $(if $(filter micro:%, $1), true)
+
UseJtregTestHandler = \
$(if $(filter jtreg:%, $1), true)
@@ -689,6 +837,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 Tue Oct 09 11:44:00 2018 +0100
+++ b/make/autoconf/configure.ac Tue Oct 09 14:37:59 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 Tue Oct 09 11:44:00 2018 +0100
+++ b/make/autoconf/lib-tests.m4 Tue Oct 09 14:37:59 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 Tue Oct 09 11:44:00 2018 +0100
+++ b/make/autoconf/spec.gmk.in Tue Oct 09 14:37:59 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 Tue Oct 09 11:44:00 2018 +0100
+++ b/make/common/FindTests.gmk Tue Oct 09 14:37:59 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 Tue Oct 09 11:44:00 2018 +0100
+++ b/make/common/JarArchive.gmk Tue Oct 09 14:37:59 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,14 @@
$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)
$(MKDIR) -p $$($1_BIN)
+ ifneq ($$($1_JAR_OUTPUT_DIR), $$($1_BIN))
+ $(MKDIR) -p $$($1_JAR_OUTPUT_DIR)
+ endif
$$($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 Tue Oct 09 11:44:00 2018 +0100
+++ b/make/conf/jib-profiles.js Tue Oct 09 14:37:59 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",
@@ -896,6 +896,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 Tue Oct 09 14:37:59 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 Tue Oct 09 14:37:59 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 Tue Oct 09 14:37:59 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 Tue Oct 09 14:37:59 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 Tue Oct 09 14:37:59 2018 +0200
@@ -0,0 +1,66 @@
+/*
+ * 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.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 {
+ File policyFile = File.createTempFile("security", "policy");
+ policyFile.deleteOnExit();
+
+ PrintWriter writer = new PrintWriter(policyFile);
+ BufferedReader reader = new BufferedReader(new InputStreamReader(
+ ClazzWithSecurityManager.class.getResourceAsStream("/org/openjdk/bench/java/security/security.policy")));
+ for (String line = reader.readLine(); line != null; line = reader.readLine()) {
+ writer.println(line);
+ }
+ reader.close();
+ writer.close();
+
+ Policy policy = Policy.getInstance("JavaPolicy", new URIParameter(policyFile.toURI()));
+ Policy.setPolicy(policy);
+ System.setSecurityManager(new SecurityManager());
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/micro/resources/org/openjdk/bench/java/security/security.policy Tue Oct 09 14:37:59 2018 +0200
@@ -0,0 +1,37 @@
+// Copyright (c) 2014, 2017 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.
+grant {
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.misc";
+ permission java.lang.RuntimePermission "accessDeclaredMembers";
+ permission java.lang.RuntimePermission "createSecurityManager";
+ permission java.lang.RuntimePermission "getProtectionDomain";
+ permission java.lang.RuntimePermission "modifyThread";
+ permission java.lang.RuntimePermission "setSecurityManager";
+ permission java.security.SecurityPermission "createPolicy.JavaPolicy";
+ permission java.security.SecurityPermission "setPolicy";
+ permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
+ permission java.util.PropertyPermission "*", "read, write";
+ permission java.lang.management.ManagementPermission "monitor";
+ permission java.io.FilePermission "/-", "read,write,execute,delete";
+ permission java.net.SocketPermission "*", "connect,resolve,accept,listen";
+};
\ No newline at end of file