1 #
  2 # Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
  3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4 #
  5 # This code is free software; you can redistribute it and/or modify it
  6 # under the terms of the GNU General Public License version 2 only, as
  7 # published by the Free Software Foundation.  Oracle designates this
  8 # particular file as subject to the "Classpath" exception as provided
  9 # by Oracle in the LICENSE file that accompanied this code.
 10 #
 11 # This code is distributed in the hope that it will be useful, but WITHOUT
 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14 # version 2 for more details (a copy is included in the LICENSE file that
 15 # accompanied this code).
 16 #
 17 # You should have received a copy of the GNU General Public License version
 18 # 2 along with this work; if not, write to the Free Software Foundation,
 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20 #
 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22 # or visit www.oracle.com if you need additional information or have any
 23 # questions.
 24 #
 25 
 26 # This must be the first rule
 27 default: all
 28 
 29 include $(SPEC)
 30 include MakeBase.gmk
 31 include JavaCompilation.gmk
 32 include TestFilesCompilation.gmk
 33 
 34 ifeq ($(JMH_CORE_JAR), )
 35   $(info Error: JMH is missing. Please use configure --with-jmh.)
 36   $(error Cannot continue)
 37 endif
 38 
 39 #### Variables
 40 
 41 MICROBENCHMARK_SRC := $(TOPDIR)/test/micro
 42 MICROBENCHMARK_IMAGE_DIR := $(TEST_IMAGE_DIR)/micro
 43 MICROBENCHMARK_JAR := $(MICROBENCHMARK_IMAGE_DIR)/benchmarks.jar
 44 
 45 MICROBENCHMARK_OUTPUT := $(SUPPORT_OUTPUTDIR)/test/micro
 46 MICROBENCHMARK_CLASSES := $(MICROBENCHMARK_OUTPUT)/classes
 47 MICROBENCHMARK_JAR_BIN := $(MICROBENCHMARK_OUTPUT)/jar
 48 
 49 MICROBENCHMARK_TOOLS_CLASSES := $(MICROBENCHMARK_OUTPUT)/tools-classes
 50 MICROBENCHMARK_INDIFY_DONE := $(MICROBENCHMARK_CLASSES)/_indify.marker
 51 
 52 JMH_UNPACKED_DIR := $(MICROBENCHMARK_OUTPUT)/jmh_jars
 53 JMH_UNPACKED_JARS_DONE := $(JMH_UNPACKED_DIR)/_unpacked.marker
 54 
 55 # External dependencies
 56 JMH_COMPILE_JARS := $(JMH_CORE_JAR) $(JMH_GENERATOR_JAR)
 57 JMH_RUNTIME_JARS := $(JMH_CORE_JAR) $(JMH_COMMONS_MATH_JAR) $(JMH_JOPT_SIMPLE_JAR)
 58 
 59 MICROBENCHMARK_CLASSPATH := $(call PathList, $(JMH_COMPILE_JARS))
 60 
 61 # Native dependencies
 62 MICROBENCHMARK_NATIVE_SRC_DIRS := $(MICROBENCHMARK_SRC)
 63 MICROBENCHMARK_NATIVE_OUTPUT := $(MICROBENCHMARK_OUTPUT)/native
 64 MICROBENCHMARK_NATIVE_EXCLUDE :=
 65 
 66 ###
 67 
 68 # Need double \n to get new lines and no trailing spaces
 69 MICROBENCHMARK_MANIFEST := Build: $(FULL_VERSION)\n\
 70 \nJMH-Version: $(JMH_VERSION)\n\
 71 \nName: OpenJDK Microbenchmark Suite
 72 
 73 #### Compile Indify tool
 74 
 75 $(eval $(call SetupJavaCompilation, BUILD_INDIFY, \
 76     TARGET_RELEASE := $(TARGET_RELEASE_BOOTJDK), \
 77     SRC := $(TOPDIR)/test/jdk/java/lang/invoke, \
 78     INCLUDE_FILES := indify/Indify.java, \
 79     DISABLED_WARNINGS := rawtypes serial options, \
 80     BIN := $(MICROBENCHMARK_TOOLS_CLASSES), \
 81     JAVAC_FLAGS := -XDstringConcat=inline -Xprefer:newer, \
 82 ))
 83 
 84 #### Compile Targets
 85 
 86 # Building microbenchmark requires the jdk.unsupported and java.management modules.
 87 # sun.security.util is required to compile Cache benchmark
 88 
 89 # Build microbenchmark suite for the current JDK
 90 $(eval $(call SetupJavaCompilation, BUILD_JDK_MICROBENCHMARK, \
 91     TARGET_RELEASE := $(TARGET_RELEASE_NEWJDK_UPGRADED), \
 92     SMALL_JAVA := false, \
 93     CLASSPATH := $(MICROBENCHMARK_CLASSPATH), \
 94     DISABLED_WARNINGS := processing rawtypes cast serial, \
 95     SRC := $(MICROBENCHMARK_SRC), \
 96     BIN := $(MICROBENCHMARK_CLASSES), \
 97     JAVAC_FLAGS := --add-exports java.base/sun.security.util=ALL-UNNAMED, \
 98     JAVA_FLAGS := --add-modules jdk.unsupported --limit-modules java.management, \
 99 ))
100 
101 $(BUILD_JDK_MICROBENCHMARK): $(JMH_COMPILE_JARS)
102 
103 # Run Indify
104 $(MICROBENCHMARK_INDIFY_DONE): $(BUILD_INDIFY) $(BUILD_JDK_MICROBENCHMARK)
105 	$(call LogWarn, Running Indify on microbenchmark classes)
106 	$(JAVA_SMALL) -cp $(MICROBENCHMARK_TOOLS_CLASSES) \
107 	    indify.Indify --overwrite $(MICROBENCHMARK_CLASSES) \
108 	    $(LOG_DEBUG) 2>&1
109 	$(TOUCH) $@
110 
111 # Unpacking dependencies for inclusion in the benchmark JARs
112 $(JMH_UNPACKED_JARS_DONE): $(JMH_RUNTIME_JARS)
113 	$(RM) -r $(JMH_UNPACKED_DIR)
114 	$(MKDIR) -p $(JMH_UNPACKED_DIR)
115 	$(foreach jar, $(JMH_RUNTIME_JARS), \
116             $$($(UNZIP) -oq $(jar) -d $(JMH_UNPACKED_DIR)))
117 	$(RM) -r $(JMH_UNPACKED_DIR)/META-INF
118 	$(RM) $(JMH_UNPACKED_DIR)/*.xml
119 	$(TOUCH) $@
120 
121 # Create benchmarks JAR file with benchmarks for both the old and new JDK
122 $(eval $(call SetupJarArchive, BUILD_JDK_JAR, \
123     DEPENDENCIES := $(BUILD_JDK_MICROBENCHMARK) $(JMH_UNPACKED_JARS_DONE) \
124         $(MICROBENCHMARK_INDIFY_DONE), \
125     SRCS := $(MICROBENCHMARK_CLASSES) $(JMH_UNPACKED_DIR), \
126     BIN := $(MICROBENCHMARK_JAR_BIN), \
127     SUFFIXES := .*, \
128     EXCLUDE_FILES:= _the.BUILD_JDK_MICROBENCHMARK_batch \
129         _the.BUILD_JDK_MICROBENCHMARK.vardeps _unpacked.marker, \
130     EXTRA_MANIFEST_ATTR := $(MICROBENCHMARK_MANIFEST), \
131     JARMAIN := org.openjdk.jmh.Main, \
132     JAR := $(MICROBENCHMARK_JAR), \
133 ))
134 
135 # Setup compilation of native library dependencies
136 $(eval $(call SetupTestFilesCompilation, BUILD_MICROBENCHMARK_LIBRARIES, \
137     TYPE := LIBRARY, \
138     SOURCE_DIRS := $(MICROBENCHMARK_NATIVE_SRC_DIRS), \
139     OUTPUT_DIR := $(MICROBENCHMARK_NATIVE_OUTPUT), \
140     EXCLUDE := $(MICROBENCHMARK_NATIVE_EXCLUDE), \
141 ))
142 
143 # Setup copy of native dependencies to image output dir
144 $(eval $(call SetupCopyFiles, COPY_MICROBENCHMARK_NATIVE, \
145     SRC := $(MICROBENCHMARK_NATIVE_OUTPUT), \
146     DEST := $(MICROBENCHMARK_IMAGE_DIR)/native, \
147     FILES := $(BUILD_MICROBENCHMARK_LIBRARIES), \
148     FLATTEN := true, \
149 ))
150 
151 all: $(MICROBENCHMARK_JAR) $(BUILD_MICROBENCHMARK_LIBRARIES) $(COPY_MICROBENCHMARK_NATIVE)
152 
153 .PHONY: all