1 # 2 # Copyright (c) 2013, 2017, 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 ################################################################################ 27 # Support for dtrace integration with libjvm, and stand-alone dtrace library 28 # compilation. 29 30 ifeq ($(call check-jvm-feature, dtrace), true) 31 ############################################################################## 32 33 ifeq ($(OPENJDK_TARGET_OS), solaris) 34 ############################################################################ 35 # Integrate with libjvm. Here we generate three object files which are 36 # linked with libjvm.so. This step is complicated from a dependency 37 # perspective, since it needs the rest of the compiled object files from the 38 # libjvm compilation, but the output is object files that are to be included 39 # when linking libjvm.so. So this generation must happen as a part of the 40 # libjvm compilation. 41 42 # First we need to generate the dtraceGenOffsets tool. When run, this will 43 # produce more header files and a C++ file. 44 45 # Note that generateJvmOffsets.cpp must be compiled as if it were a file 46 # in the libjvm.so, using JVM_CFLAGS as setup in CompileJvm.gmk. Otherwise 47 # this would preferrably have been done as a part of GensrcDtrace.gmk. 48 $(eval $(call SetupNativeCompilation, BUILD_DTRACE_GEN_OFFSETS, \ 49 SRC := $(TOPDIR)/make/hotspot/src/native/dtrace, \ 50 CC := $(BUILD_CXX), \ 51 CXX := $(BUILD_CXX), \ 52 LDEXE := $(BUILD_CXX), \ 53 generateJvmOffsets.cpp_CXXFLAGS := $(JVM_CFLAGS) -mt -xnolib -norunpath, \ 54 generateJvmOffsetsMain.c_CFLAGS := -mt -m64 -norunpath -z nodefs, \ 55 LDFLAGS := -m64, \ 56 LIBS := -lc, \ 57 OBJECT_DIR := $(JVM_VARIANT_OUTPUTDIR)/tools/dtrace-gen-offsets/objs, \ 58 OUTPUT_DIR := $(JVM_VARIANT_OUTPUTDIR)/tools/dtrace-gen-offsets, \ 59 PROGRAM := dtraceGenOffsets, \ 60 )) 61 62 DTRACE_GEN_OFFSETS_TOOL := $(BUILD_DTRACE_GEN_OFFSETS_TARGET) 63 64 # Argument 1: Output filename 65 # Argument 2: dtrace-gen-offset tool command line option 66 define SetupDtraceOffsetsGeneration 67 $1: $$(BUILD_DTRACE_GEN_OFFSETS) 68 $$(call LogInfo, Generating dtrace $2 file $$(@F)) 69 $$(call MakeDir, $$(@D)) 70 $$(call ExecuteWithLog, $$@, ( $$(DTRACE_GEN_OFFSETS_TOOL) -$$(strip $2) > $$@ ) ) 71 72 TARGETS += $1 73 endef 74 75 JVM_OFFSETS_H := $(DTRACE_SUPPORT_DIR)/JvmOffsets.h 76 JVM_OFFSETS_CPP := $(DTRACE_SUPPORT_DIR)/JvmOffsets.cpp 77 JVM_OFFSETS_INDEX_H := $(DTRACE_SUPPORT_DIR)/JvmOffsetsIndex.h 78 79 # Run the dtrace-gen-offset tool to generate these three files. 80 $(eval $(call SetupDtraceOffsetsGeneration, $(JVM_OFFSETS_H), header)) 81 $(eval $(call SetupDtraceOffsetsGeneration, $(JVM_OFFSETS_INDEX_H), index)) 82 $(eval $(call SetupDtraceOffsetsGeneration, $(JVM_OFFSETS_CPP), table)) 83 84 ############################################################################ 85 # Compile JVM_OFFSETS_OBJ which is linked with libjvm.so. 86 87 # JvmOffsets.cpp is compiled without the common JVM_CFLAGS. Otherwise, the 88 # natural way would have been to included this source code in BUILD_LIBJVM. 89 JVM_OFFSETS_CFLAGS := -m64 90 ifeq ($(OPENJDK_TARGET_CPU), sparcv9) 91 JVM_OFFSETS_CFLAGS += -xarch=sparc 92 endif 93 94 $(JVM_OFFSETS_OBJ): $(JVM_OFFSETS_CPP) $(JVM_OFFSETS_H) 95 $(call LogInfo, Compiling dtrace file JvmOffsets.cpp (for libjvm.so)) 96 $(call ExecuteWithLog, $@, $(CXX) -c -I$(<D) -o $@ $(JVM_OFFSETS_CFLAGS) $<) 97 98 ############################################################################ 99 # Generate DTRACE_OBJ which is linked with libjvm.so. 100 101 # Concatenate all *.d files into a single file 102 DTRACE_SOURCE_FILES := $(addprefix $(TOPDIR)/src/hotspot/os/posix/dtrace/, \ 103 hotspot_jni.d \ 104 hotspot.d \ 105 hs_private.d \ 106 ) 107 108 $(JVM_OUTPUTDIR)/objs/dtrace.d: $(DTRACE_SOURCE_FILES) 109 $(call LogInfo, Generating $(@F)) 110 $(call MakeDir, $(@D)) 111 $(CAT) $^ > $@ 112 113 DTRACE_INSTRUMENTED_OBJS := $(addprefix $(JVM_OUTPUTDIR)/objs/, \ 114 ciEnv.o \ 115 classLoadingService.o \ 116 compileBroker.o \ 117 hashtable.o \ 118 instanceKlass.o \ 119 java.o \ 120 jni.o \ 121 jvm.o \ 122 memoryManager.o \ 123 nmethod.o \ 124 objectMonitor.o \ 125 runtimeService.o \ 126 sharedRuntime.o \ 127 synchronizer.o \ 128 thread.o \ 129 unsafe.o \ 130 vmThread.o \ 131 vmGCOperations.o \ 132 ) 133 134 ifeq ($(call check-jvm-feature, all-gcs), true) 135 DTRACE_INSTRUMENTED_OBJS += $(addprefix $(JVM_OUTPUTDIR)/objs/, \ 136 vmCMSOperations.o \ 137 vmPSOperations.o \ 138 ) 139 endif 140 141 DTRACE_FLAGS := -64 -G 142 DTRACE_CPP_FLAGS := -D_LP64 143 144 # Make sure we run our selected compiler for preprocessing instead of letting 145 # the dtrace tool pick it on it's own. 146 $(DTRACE_OBJ): $(JVM_OUTPUTDIR)/objs/dtrace.d $(DTRACE_INSTRUMENTED_OBJS) 147 $(call LogInfo, Generating $(@F) from $(<F) and object files) 148 $(call MakeDir, $(DTRACE_SUPPORT_DIR)) 149 $(call ExecuteWithLog, $(DTRACE_SUPPORT_DIR)/$(@F).d, $(CC) -E \ 150 $(DTRACE_CPP_FLAGS) $< > $(DTRACE_SUPPORT_DIR)/$(@F).d) 151 $(call ExecuteWithLog, $@, $(DTRACE) $(DTRACE_FLAGS) -xlazyload -o $@ \ 152 -s $(DTRACE_SUPPORT_DIR)/$(@F).d $(sort $(DTRACE_INSTRUMENTED_OBJS))) 153 154 ############################################################################ 155 # Generate DTRACE_JHELPER_OBJ which is linked with libjvm.so. 156 157 # Unfortunately dtrace generates incorrect types for some symbols in 158 # dtrace_jhelper.o, resulting in "warning: symbol X has differing types" 159 # This is tracked in JDK-6890703. 160 $(DTRACE_JHELPER_OBJ): $(TOPDIR)/src/hotspot/os/solaris/dtrace/jhelper.d \ 161 $(JVM_OFFSETS_INDEX_H) 162 $(call LogInfo, Running dtrace for $(<F)) 163 $(call ExecuteWithLog, $@, $(DTRACE) $(DTRACE_FLAGS) $(DTRACE_CPP_FLAGS) -C \ 164 -I$(DTRACE_SUPPORT_DIR) -o $@ -s $<) 165 166 # NOTE: We should really do something like this, but unfortunately this 167 # results in a compilation error. :-( 168 # $(call MakeDir, $(DTRACE_SUPPORT_DIR)) 169 # $(call ExecuteWithLog, $(DTRACE_SUPPORT_DIR)/$(@F).d, $(CC) -E \ 170 # $(DTRACE_CPP_FLAGS) -I$(DTRACE_SUPPORT_DIR) $^ \ 171 # > $(DTRACE_SUPPORT_DIR)/$(@F).d) 172 # $(call ExecuteWithLog, $@, $(DTRACE) $(DTRACE_FLAGS) -o $@ \ 173 # -s $(DTRACE_SUPPORT_DIR)/$(@F).d) 174 175 ############################################################################ 176 # Build the stand-alone dtrace libraries 177 178 LIBJVM_DTRACE_OUTPUTDIR := $(JVM_VARIANT_OUTPUTDIR)/libjvm_dtrace 179 180 $(eval $(call SetupNativeCompilation, BUILD_LIBJVM_DTRACE, \ 181 LIBRARY := jvm_dtrace, \ 182 OUTPUT_DIR := $(JVM_LIB_OUTPUTDIR), \ 183 SRC := $(TOPDIR)/src/java.base/solaris/native/libjvm_dtrace, \ 184 CFLAGS := -m64 -G -mt -KPIC, \ 185 LDFLAGS := -m64 -mt -xnolib $(SHARED_LIBRARY_FLAGS), \ 186 LIBS := $(LIBDL) -lc -lthread -ldoor, \ 187 MAPFILE := $(TOPDIR)/make/mapfiles/libjvm_dtrace/mapfile-vers, \ 188 OBJECT_DIR := $(LIBJVM_DTRACE_OUTPUTDIR)/objs, \ 189 )) 190 191 LIBJVM_DB_OUTPUTDIR := $(JVM_VARIANT_OUTPUTDIR)/libjvm_db 192 193 # Note that libjvm_db.c has tests for COMPILER2, but this was never set by 194 # the old build. 195 $(eval $(call SetupNativeCompilation, BUILD_LIBJVM_DB, \ 196 LIBRARY := jvm_db, \ 197 OUTPUT_DIR := $(JVM_LIB_OUTPUTDIR), \ 198 SRC := $(TOPDIR)/src/java.base/solaris/native/libjvm_db, \ 199 CFLAGS := -I$(JVM_VARIANT_OUTPUTDIR)/gensrc -I$(DTRACE_SUPPORT_DIR) \ 200 -m64 -G -mt -KPIC, \ 201 LDFLAGS := -m64 -mt -xnolib $(SHARED_LIBRARY_FLAGS), \ 202 LIBS := -lc, \ 203 MAPFILE := $(TOPDIR)/make/mapfiles/libjvm_db/mapfile-vers, \ 204 OBJECT_DIR := $(LIBJVM_DB_OUTPUTDIR)/objs, \ 205 )) 206 207 # We need the generated JvmOffsets.h before we can compile the libjvm_db source code. 208 $(BUILD_LIBJVM_DB_ALL_OBJS): $(JVM_OFFSETS_H) 209 210 TARGETS += $(BUILD_LIBJVM_DTRACE) $(BUILD_LIBJVM_DB) 211 endif 212 endif