1 #
   2 # Copyright (c) 2013, 2018, 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 ifeq ($(call check-jvm-feature, dtrace), true)
  27   ifeq ($(OPENJDK_TARGET_OS), solaris)
  28 
  29     ############################################################################
  30     # Integrate with libjvm. Here we generate two object files which are
  31     # linked with libjvm.so. This step is complicated from a dependency
  32     # perspective. We add these two files to the linking of libjvm using
  33     # EXTRA_OBJECT_FILES, but they need to be created outside the call to
  34     # SetupNativeCompilation. Also, one of the files is dependent on compiled
  35     # object files from the libjvm compilation, so this generation must happen
  36     # as a part of the libjvm compilation.
  37 
  38     DTRACE_OBJ := $(JVM_OUTPUTDIR)/objs/dtrace.o
  39     DTRACE_JHELPER_OBJ := $(JVM_OUTPUTDIR)/objs/dtrace_jhelper.o
  40 
  41     DTRACE_EXTRA_OBJECT_FILES := $(DTRACE_OBJ) $(DTRACE_JHELPER_OBJ)
  42 
  43     ############################################################################
  44     # Generate DTRACE_OBJ which is linked with libjvm.so. It depends on a set of
  45     # object files from the compilation.
  46 
  47     # Concatenate all *.d files into a single file
  48     DTRACE_SOURCE_FILES := $(addprefix $(TOPDIR)/src/hotspot/os/posix/dtrace/, \
  49         hotspot_jni.d \
  50         hotspot.d \
  51         hs_private.d \
  52     )
  53 
  54     $(JVM_OUTPUTDIR)/objs/dtrace.d: $(DTRACE_SOURCE_FILES)
  55         $(call LogInfo, Generating $(@F))
  56         $(call MakeDir, $(@D))
  57         $(CAT) $^ > $@
  58 
  59     DTRACE_INSTRUMENTED_OBJS := $(addprefix $(JVM_OUTPUTDIR)/objs/, \
  60         ciEnv.o \
  61         classLoadingService.o \
  62         compileBroker.o \
  63         hashtable.o \
  64         instanceKlass.o \
  65         java.o \
  66         jni.o \
  67         jvm.o \
  68         memoryManager.o \
  69         nmethod.o \
  70         objectMonitor.o \
  71         runtimeService.o \
  72         sharedRuntime.o \
  73         synchronizer.o \
  74         thread.o \
  75         unsafe.o \
  76         vmThread.o \
  77         vmGCOperations.o \
  78     )
  79 
  80     ifeq ($(call check-jvm-feature, all-gcs), true)
  81       DTRACE_INSTRUMENTED_OBJS += $(addprefix $(JVM_OUTPUTDIR)/objs/, \
  82           vmCMSOperations.o \
  83           vmPSOperations.o \
  84       )
  85     endif
  86 
  87     DTRACE_FLAGS := -64 -G
  88     DTRACE_CPP_FLAGS := -D_LP64
  89 
  90     # Make sure we run our selected compiler for preprocessing instead of letting
  91     # the dtrace tool pick it on it's own.
  92     $(DTRACE_OBJ): $(JVM_OUTPUTDIR)/objs/dtrace.d $(DTRACE_INSTRUMENTED_OBJS)
  93         $(call LogInfo, Generating $(@F) from $(<F) and object files)
  94         $(call MakeDir, $(DTRACE_SUPPORT_DIR))
  95         $(call ExecuteWithLog, $(DTRACE_SUPPORT_DIR)/$(@F).d, \
  96             ($(CPP) $(DTRACE_CPP_FLAGS) $< > $(DTRACE_SUPPORT_DIR)/$(@F).d))
  97         $(call ExecuteWithLog, $@, $(DTRACE) $(DTRACE_FLAGS) -xlazyload -o $@ \
  98             -s $(DTRACE_SUPPORT_DIR)/$(@F).d $(sort $(DTRACE_INSTRUMENTED_OBJS)))
  99 
 100     ############################################################################
 101     # Generate DTRACE_JHELPER_OBJ which is linked with libjvm.so.
 102 
 103     JHELPER_DTRACE_SRC := $(TOPDIR)/src/hotspot/os/solaris/dtrace/jhelper.d
 104 
 105     # jhelper.d includes JvmOffsetsIndex.h which was created by the gensrc step.
 106     DTRACE_GENSRC_DIR := $(JVM_VARIANT_OUTPUTDIR)/gensrc/dtracefiles
 107     JVM_OFFSETS_INDEX_H := $(DTRACE_GENSRC_DIR)/JvmOffsetsIndex.h
 108 
 109     # Unfortunately dtrace generates incorrect types for some symbols in
 110     # dtrace_jhelper.o, resulting in "warning: symbol X has differing types"
 111     # See JDK-6890703 for details.
 112     # We work around this by fixing the types for these symbols using elfedit,
 113     # after dtrace has generated the .o file.
 114     GetElfeditCommands = \
 115       $(foreach symbol, \
 116           $(shell $(GREP) ^extern $(JHELPER_DTRACE_SRC) | $(AWK) '{ gsub(";","") ; print $$3 }'), \
 117           -e 'sym:st_type $(symbol) 1')
 118 
 119     # Make sure we run our selected compiler for preprocessing instead of letting
 120     # the dtrace tool pick it on it's own.
 121     $(DTRACE_JHELPER_OBJ): $(JHELPER_DTRACE_SRC) $(JVM_OFFSETS_INDEX_H)
 122         $(call LogInfo, Running dtrace for $(<F))
 123         $(call MakeDir, $(DTRACE_SUPPORT_DIR))
 124         $(call ExecuteWithLog, $(DTRACE_SUPPORT_DIR)/$(@F).d, \
 125             ($(CPP) $(DTRACE_CPP_FLAGS) -I$(DTRACE_GENSRC_DIR) $^ \
 126             > $(DTRACE_SUPPORT_DIR)/$(@F).d))
 127         $(call ExecuteWithLog, $@, $(DTRACE) $(DTRACE_FLAGS) -o $@ \
 128             -s $(DTRACE_SUPPORT_DIR)/$(@F).d)
 129         ifeq ($(OPENJDK_TARGET_CPU_ARCH), sparc)
 130           $(call ExecuteWithLog, $@.elfedit, $(ELFEDIT) $(call GetElfeditCommands) $@)
 131         endif
 132 
 133   endif
 134 endif