1 #
   2 # Copyright (c) 1999, 2010, 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.
   8 #
   9 # This code is distributed in the hope that it will be useful, but WITHOUT
  10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12 # version 2 for more details (a copy is included in the LICENSE file that
  13 # accompanied this code).
  14 #
  15 # You should have received a copy of the GNU General Public License version
  16 # 2 along with this work; if not, write to the Free Software Foundation,
  17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18 #
  19 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20 # or visit www.oracle.com if you need additional information or have any
  21 # questions.
  22 #  
  23 #
  24 
  25 # Rules to build JVM and related libraries, included from vm.make in the build
  26 # directory.
  27 
  28 # Common build rules.
  29 MAKEFILES_DIR=$(GAMMADIR)/make/$(Platform_os_family)/makefiles
  30 include $(MAKEFILES_DIR)/rules.make
  31 
  32 default: build
  33 
  34 #----------------------------------------------------------------------
  35 # Defs
  36 
  37 GENERATED     = ../generated
  38 DEP_DIR       = $(GENERATED)/dependencies
  39 
  40 # reads the generated files defining the set of .o's and the .o .h dependencies
  41 -include $(DEP_DIR)/*.d
  42 
  43 # read machine-specific adjustments (%%% should do this via buildtree.make?)
  44 ifeq ($(ZERO_BUILD), true)
  45   include $(MAKEFILES_DIR)/zeroshark.make
  46 else
  47   include $(MAKEFILES_DIR)/$(BUILDARCH).make
  48 endif
  49 
  50 # set VPATH so make knows where to look for source files
  51 # Src_Dirs is everything in src/share/vm/*, plus the right os/*/vm and cpu/*/vm
  52 # The adfiles directory contains ad_<arch>.[ch]pp.
  53 # The jvmtifiles directory contains jvmti*.[ch]pp
  54 Src_Dirs_V = $(GENERATED)/adfiles $(GENERATED)/jvmtifiles ${Src_Dirs}
  55 VPATH    += $(Src_Dirs_V:%=%:)
  56 
  57 # set INCLUDES for C preprocessor
  58 Src_Dirs_I = $(PRECOMPILED_HEADER_DIR) $(GENERATED)/adfiles $(GENERATED)/jvmtifiles ${Src_Dirs} $(GAMMADIR)/src/share/vm $(GENERATED)
  59 INCLUDES += $(Src_Dirs_I:%=-I%)
  60 
  61 ifeq (${VERSION}, debug)
  62   SYMFLAG = -g
  63 else
  64   SYMFLAG =
  65 endif
  66 
  67 # HOTSPOT_RELEASE_VERSION and HOTSPOT_BUILD_VERSION are defined 
  68 # in $(GAMMADIR)/make/defs.make
  69 ifeq ($(HOTSPOT_BUILD_VERSION),)
  70   BUILD_VERSION = -DHOTSPOT_RELEASE_VERSION="\"$(HOTSPOT_RELEASE_VERSION)\""
  71 else
  72   BUILD_VERSION = -DHOTSPOT_RELEASE_VERSION="\"$(HOTSPOT_RELEASE_VERSION)-$(HOTSPOT_BUILD_VERSION)\""
  73 endif
  74 
  75 # The following variables are defined in the generated flags.make file.
  76 BUILD_VERSION = -DHOTSPOT_RELEASE_VERSION="\"$(HS_BUILD_VER)\""
  77 JRE_VERSION   = -DJRE_RELEASE_VERSION="\"$(JRE_RELEASE_VER)\""
  78 HS_LIB_ARCH   = -DHOTSPOT_LIB_ARCH=\"$(LIBARCH)\"
  79 BUILD_TARGET  = -DHOTSPOT_BUILD_TARGET="\"$(TARGET)\""
  80 BUILD_USER    = -DHOTSPOT_BUILD_USER="\"$(HOTSPOT_BUILD_USER)\""
  81 VM_DISTRO     = -DHOTSPOT_VM_DISTRO="\"$(HOTSPOT_VM_DISTRO)\""
  82 
  83 CPPFLAGS =           \
  84   ${SYSDEFS}         \
  85   ${INCLUDES}        \
  86   ${BUILD_VERSION}   \
  87   ${BUILD_TARGET}    \
  88   ${BUILD_USER}      \
  89   ${HS_LIB_ARCH}     \
  90   ${JRE_VERSION}     \
  91   ${VM_DISTRO}
  92 
  93 # CFLAGS_WARN holds compiler options to suppress/enable warnings.
  94 CFLAGS += $(CFLAGS_WARN/BYFILE)
  95 
  96 # Do not use C++ exception handling
  97 CFLAGS += $(CFLAGS/NOEX)
  98 
  99 # Extra flags from gnumake's invocation or environment
 100 CFLAGS += $(EXTRA_CFLAGS)
 101 LFLAGS += $(EXTRA_CFLAGS)
 102 
 103 LIBS += -lm -ldl -lpthread
 104 
 105 # By default, link the *.o into the library, not the executable.
 106 LINK_INTO$(LINK_INTO) = LIBJVM
 107 
 108 JDK_LIBDIR = $(JAVA_HOME)/jre/lib/$(LIBARCH)
 109 
 110 #----------------------------------------------------------------------
 111 # jvm_db & dtrace
 112 include $(MAKEFILES_DIR)/dtrace.make
 113 
 114 #----------------------------------------------------------------------
 115 # JVM
 116 
 117 JVM      = jvm
 118 LIBJVM   = lib$(JVM).so
 119 LIBJVM_G = lib$(JVM)$(G_SUFFIX).so
 120 
 121 BASE_PATHS := $(shell find $(GAMMADIR)/src/share/vm/* -prune -type d \! \( -name adlc -o -name c1 -o -name gc_implementation -o -name opto -o -name shark -o -name libadt \))
 122 BASE_PATHS += $(GAMMADIR)/src/share/vm/gc_implementation/shared
 123 BASE_PATHS += $(GAMMADIR)/src/os/$(Platform_os_family)/vm
 124 BASE_PATHS += $(GAMMADIR)/src/cpu/$(Platform_arch)/vm
 125 BASE_PATHS += $(GAMMADIR)/src/os_cpu/$(Platform_os_arch)/vm
 126 BASE_PATHS += $(GENERATED)/jvmtifiles
 127 
 128 CORE_PATHS := $(BASE_PATHS)
 129 # shared is already in BASE_PATHS. Should add vm/memory but that one is also in BASE_PATHS.
 130 CORE_PATHS += $(shell find $(GAMMADIR)/src/share/vm/gc_implementation/* -prune -type d \! -name shared)
 131 
 132 COMPILER1_PATHS := $(GAMMADIR)/src/share/vm/c1
 133 
 134 COMPILER2_PATHS := $(GAMMADIR)/src/share/vm/opto
 135 COMPILER2_PATHS += $(GAMMADIR)/src/share/vm/libadt
 136 COMPILER2_PATHS +=  $(GENERATED)/adfiles
 137 
 138 # Include dirs per type.
 139 Src_Dirs/CORE      := $(CORE_PATHS)
 140 Src_Dirs/KERNEL    := $(BASE_PATHS) $(COMPILER1_PATHS)
 141 Src_Dirs/COMPILER1 := $(CORE_PATHS) $(COMPILER1_PATHS)
 142 Src_Dirs/COMPILER2 := $(CORE_PATHS) $(COMPILER2_PATHS)
 143 Src_Dirs/TIERED    := $(CORE_PATHS) $(COMPILER1_PATHS) $(COMPILER2_PATHS)
 144 Src_Dirs/ZERO      := $(CORE_PATHS)
 145 Src_Dirs/SHARK     := $(CORE_PATHS)
 146 Src_Dirs := $(Src_Dirs/$(TYPE))
 147 
 148 COMPILER2_SPECIFIC_FILES := opto libadt bcEscapeAnalyzer.cpp chaitin c2_\* runtime_\*
 149 COMPILER1_SPECIFIC_FILES := c1_\*
 150 SHARK_SPECIFIC_FILES     := shark
 151 ZERO_SPECIFIC_FILES      := zero
 152 
 153 # These files need to be excluded when building the kernel target.
 154 KERNEL_EXCLUDED_FILES := attachListener.cpp attachListener_${Platform_os_family}.cpp dump.cpp dump_$(Platform_arch_model).cpp forte.cpp fprofiler.cpp heapDumper.cpp heapInspection.cpp jniCheck.cpp jvmtiCodeBlobEvents.cpp jvmtiExtensions.cpp jvmtiImpl.cpp jvmtiTagMap.cpp jvmtiTrace.cpp restore.cpp serialize.cpp vmStructs.cpp g1MemoryPool.cpp psMemoryPool.cpp gcAdaptivePolicyCounters.cpp concurrentGCThread.cpp mutableNUMASpace.cpp allocationStats.cpp gSpaceCounters.cpp immutableSpace.cpp mutableSpace.cpp spaceCounters.cpp yieldingWorkgroup.cpp
 155 
 156 # Always exclude these.
 157 Src_Files_EXCLUDE := jsig.c jvmtiEnvRecommended.cpp jvmtiEnvStub.cpp
 158 
 159 # Exclude per type.
 160 Src_Files_EXCLUDE/CORE      := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
 161 Src_Files_EXCLUDE/KERNEL    := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(KERNEL_EXCLUDED_FILES) ciTypeFlow.cpp
 162 Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
 163 Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES)
 164 Src_Files_EXCLUDE/TIERED    := $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES)
 165 Src_Files_EXCLUDE/ZERO      := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
 166 Src_Files_EXCLUDE/SHARK     := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES)
 167 
 168 Src_Files_EXCLUDE +=  $(Src_Files_EXCLUDE/$(TYPE))
 169 
 170 # Special handling of arch model.
 171 ifeq ($(Platform_arch_model), x86_32)
 172 Src_Files_EXCLUDE += \*x86_64\*
 173 endif
 174 ifeq ($(Platform_arch_model), x86_64)
 175 Src_Files_EXCLUDE += \*x86_32\*
 176 endif
 177 
 178 define findsrc
 179         $(notdir $(shell find $(1) \( -name \*.c -o -name \*.cpp -o -name \*.s \) -a \! \( -name DUMMY $(addprefix -o -name ,$(Src_Files_EXCLUDE)) \) ))
 180 endef
 181 
 182 Src_Files := $(foreach e,$(Src_Dirs),$(call findsrc,$(e)))
 183 
 184 Obj_Files = $(addsuffix .o,$(basename $(Src_Files)))
 185 
 186 JVM_OBJ_FILES = $(Obj_Files)
 187 
 188 vm_version.o: $(filter-out vm_version.o,$(JVM_OBJ_FILES))
 189 
 190 mapfile : $(MAPFILE) vm.def
 191         rm -f $@
 192         awk '{ if ($$0 ~ "INSERT VTABLE SYMBOLS HERE")  \
 193                  { system ("cat vm.def"); }             \
 194                else                                     \
 195                  { print $$0 }                          \
 196              }' > $@ < $(MAPFILE)
 197 
 198 mapfile_reorder : mapfile $(REORDERFILE)
 199         rm -f $@
 200         cat $^ > $@
 201 
 202 vm.def: $(Res_Files) $(Obj_Files)
 203         sh $(GAMMADIR)/make/linux/makefiles/build_vm_def.sh *.o > $@
 204 
 205 ifeq ($(SHARK_BUILD), true)
 206   STATIC_CXX = false
 207 else
 208   ifeq ($(ZERO_LIBARCH), ppc64)
 209     STATIC_CXX = false
 210   else
 211     STATIC_CXX = true
 212   endif
 213 endif
 214 
 215 ifeq ($(LINK_INTO),AOUT)
 216   LIBJVM.o                 =
 217   LIBJVM_MAPFILE           =
 218   LIBS_VM                  = $(LIBS)
 219 else
 220   LIBJVM.o                 = $(JVM_OBJ_FILES)
 221   LIBJVM_MAPFILE$(LDNOMAP) = mapfile_reorder
 222   LFLAGS_VM$(LDNOMAP)      += $(MAPFLAG:FILENAME=$(LIBJVM_MAPFILE))
 223   LFLAGS_VM                += $(SONAMEFLAG:SONAME=$(LIBJVM))
 224 
 225   # JVM is statically linked with libgcc[_s] and libstdc++; this is needed to
 226   # get around library dependency and compatibility issues. Must use gcc not
 227   # g++ to link.
 228   ifeq ($(STATIC_CXX), true)
 229     LFLAGS_VM              += $(STATIC_LIBGCC)
 230     LIBS_VM                += $(STATIC_STDCXX)
 231   else
 232     LIBS_VM                += -lstdc++
 233   endif
 234 
 235   LIBS_VM                  += $(LIBS)
 236 endif
 237 ifeq ($(ZERO_BUILD), true)
 238   LIBS_VM += $(LIBFFI_LIBS)
 239 endif
 240 ifeq ($(SHARK_BUILD), true)
 241   LFLAGS_VM += $(LLVM_LDFLAGS)
 242   LIBS_VM   += $(LLVM_LIBS)
 243 endif
 244 
 245 LINK_VM = $(LINK_LIB.c)
 246 
 247 # rule for building precompiled header
 248 $(PRECOMPILED_HEADER):
 249         $(QUIETLY) echo Generating precompiled header $@
 250         $(QUIETLY) mkdir -p $(PRECOMPILED_HEADER_DIR)
 251         $(QUIETLY) $(COMPILE.CC) -x c++-header -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d) -MT '$@' -c $(PRECOMPILED_HEADER_SRC) -o $@ $(COMPILE_DONE)
 252 
 253 # making the library:
 254 
 255 ifneq ($(JVM_BASE_ADDR),)
 256 # By default shared library is linked at base address == 0. Modify the
 257 # linker script if JVM prefers a different base location. It can also be
 258 # implemented with 'prelink -r'. But 'prelink' is not (yet) available on
 259 # our build platform (AS-2.1).
 260 LD_SCRIPT = libjvm.so.lds
 261 $(LD_SCRIPT): $(LIBJVM_MAPFILE)
 262         $(QUIETLY) {                                                \
 263           rm -rf $@;                                                \
 264           $(LINK_VM) -Wl,--verbose $(LFLAGS_VM) 2>&1             |  \
 265             sed -e '/^======/,/^======/!d'                          \
 266                 -e '/^======/d'                                     \
 267                 -e 's/0\( + SIZEOF_HEADERS\)/$(JVM_BASE_ADDR)\1/'   \
 268                 > $@;                                               \
 269         }
 270 LD_SCRIPT_FLAG = -Wl,-T,$(LD_SCRIPT)
 271 endif
 272 
 273 # With more recent Redhat releases (or the cutting edge version Fedora), if
 274 # SELinux is configured to be enabled, the runtime linker will fail to apply
 275 # the text relocation to libjvm.so considering that it is built as a non-PIC
 276 # DSO. To workaround that, we run chcon to libjvm.so after it is built. See 
 277 # details in bug 6538311.
 278 $(LIBJVM): $(LIBJVM.o) $(LIBJVM_MAPFILE) $(LD_SCRIPT)
 279         $(QUIETLY) {                                                    \
 280             echo Linking vm...;                                         \
 281             $(LINK_LIB.CC/PRE_HOOK)                                     \
 282             $(LINK_VM) $(LD_SCRIPT_FLAG)                                \
 283                        $(LFLAGS_VM) -o $@ $(LIBJVM.o) $(LIBS_VM);       \
 284             $(LINK_LIB.CC/POST_HOOK)                                    \
 285             rm -f $@.1; ln -s $@ $@.1;                                  \
 286             [ -f $(LIBJVM_G) ] || { ln -s $@ $(LIBJVM_G); ln -s $@.1 $(LIBJVM_G).1; }; \
 287             if [ \"$(CROSS_COMPILE_ARCH)\" = \"\" ] ; then                    \
 288               if [ -x /usr/sbin/selinuxenabled ] ; then                 \
 289                 /usr/sbin/selinuxenabled;                               \
 290                 if [ $$? = 0 ] ; then                                   \
 291                   /usr/bin/chcon -t textrel_shlib_t $@;                 \
 292                   if [ $$? != 0 ]; then                                 \
 293                     echo "ERROR: Cannot chcon $@";                      \
 294                   fi                                                    \
 295                 fi                                                      \
 296               fi                                                        \
 297             fi                                                          \
 298         }
 299 
 300 DEST_JVM = $(JDK_LIBDIR)/$(VM_SUBDIR)/$(LIBJVM)
 301 
 302 install_jvm: $(LIBJVM)
 303         @echo "Copying $(LIBJVM) to $(DEST_JVM)"
 304         $(QUIETLY) cp -f $(LIBJVM) $(DEST_JVM) && echo "Done"
 305 
 306 #----------------------------------------------------------------------
 307 # Other files
 308 
 309 # Gamma launcher
 310 include $(MAKEFILES_DIR)/launcher.make
 311 
 312 # Signal interposition library
 313 include $(MAKEFILES_DIR)/jsig.make
 314 
 315 # Serviceability agent
 316 include $(MAKEFILES_DIR)/saproc.make
 317 
 318 #----------------------------------------------------------------------
 319 
 320 build: $(LIBJVM) $(LAUNCHER) $(LIBJSIG) $(LIBJVM_DB) checkAndBuildSA
 321 
 322 install: install_jvm install_jsig install_saproc
 323 
 324 .PHONY: default build install install_jvm