1 #
   2 # Copyright (c) 1999, 2015, 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 include $(GAMMADIR)/make/altsrc.make
  32 
  33 default: build
  34 
  35 #----------------------------------------------------------------------
  36 # Defs
  37 
  38 GENERATED     = ../generated
  39 DEP_DIR       = $(GENERATED)/dependencies
  40 
  41 # reads the generated files defining the set of .o's and the .o .h dependencies
  42 -include $(DEP_DIR)/*.d
  43 
  44 # read machine-specific adjustments (%%% should do this via buildtree.make?)
  45 ifeq ($(findstring true, $(JVM_VARIANT_ZERO) $(JVM_VARIANT_ZEROSHARK)), true)
  46   include $(MAKEFILES_DIR)/zeroshark.make
  47 else
  48   include $(MAKEFILES_DIR)/$(BUILDARCH).make
  49 endif
  50 
  51 # set VPATH so make knows where to look for source files
  52 # Src_Dirs_V is everything in src/share/vm/*, plus the right os/*/vm and cpu/*/vm
  53 # The adfiles directory contains ad_<arch>.[ch]pp.
  54 # The jvmtifiles directory contains jvmti*.[ch]pp
  55 Src_Dirs_V += $(GENERATED)/adfiles $(GENERATED)/jvmtifiles $(GENERATED)/tracefiles
  56 VPATH += $(Src_Dirs_V:%=%:)
  57 
  58 # set INCLUDES for C preprocessor.
  59 Src_Dirs_I += $(GENERATED)
  60 # The order is important for the precompiled headers to work.
  61 INCLUDES += $(PRECOMPILED_HEADER_DIR:%=-I%) $(Src_Dirs_I:%=-I%)
  62 
  63 # SYMFLAG is used by jsig.make
  64 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
  65   # always build with debug info when we can create .dSYM/.debuginfo files
  66   SYMFLAG = -g
  67 else
  68   ifeq (${VERSION}, debug)
  69     SYMFLAG = -g
  70   else
  71     SYMFLAG =
  72   endif
  73 endif
  74 
  75 # The following variables are defined in the generated flags.make file.
  76 JDK_VER_DEFS  = -DVERSION_MAJOR=$(VERSION_MAJOR) \
  77                 -DVERSION_MINOR=$(VERSION_MINOR) \
  78                 -DVERSION_SECURITY=$(VERSION_SECURITY) \
  79                 -DVERSION_PATCH=$(VERSION_PATCH) \
  80                 -DVERSION_BUILD=$(VERSION_BUILD)
  81 VM_VER_DEFS   = -DHOTSPOT_VERSION_STRING="\"$(HOTSPOT_VERSION_STRING)\"" \
  82                 -DVERSION_STRING="\"$(VERSION_STRING)\""  \
  83                 -DDEBUG_LEVEL="\"$(DEBUG_LEVEL)\"" \
  84                 $(JDK_VER_DEFS)
  85 HS_LIB_ARCH   = -DHOTSPOT_LIB_ARCH=\"$(LIBARCH)\"
  86 BUILD_USER    = -DHOTSPOT_BUILD_USER="\"$(HOTSPOT_BUILD_USER)\""
  87 VM_DISTRO     = -DHOTSPOT_VM_DISTRO="\"$(HOTSPOT_VM_DISTRO)\""
  88 
  89 CXXFLAGS =           \
  90   ${SYSDEFS}         \
  91   ${INCLUDES}        \
  92   ${BUILD_USER}      \
  93   ${HS_LIB_ARCH}     \
  94   ${VM_DISTRO}
  95 
  96 # This is VERY important! The version define must only be supplied to vm_version.o
  97 # If not, ccache will not re-use the cache at all, since the version string might contain
  98 # a time and date.
  99 CXXFLAGS/vm_version.o += ${VM_VER_DEFS}
 100 
 101 CXXFLAGS/BYFILE = $(CXXFLAGS/$@)
 102 
 103 # File specific flags
 104 CXXFLAGS += $(CXXFLAGS/BYFILE)
 105 
 106 ifdef DEFAULT_LIBPATH
 107 CXXFLAGS += -DDEFAULT_LIBPATH="\"$(DEFAULT_LIBPATH)\""
 108 endif
 109 
 110 # CFLAGS_WARN holds compiler options to suppress/enable warnings.
 111 CFLAGS += $(CFLAGS_WARN/BYFILE)
 112 
 113 # Do not use C++ exception handling
 114 CFLAGS += $(CFLAGS/NOEX)
 115 
 116 # Extra flags from gnumake's invocation or environment
 117 CFLAGS += $(EXTRA_CFLAGS)
 118 LFLAGS += $(EXTRA_CFLAGS)
 119 
 120 # Don't set excutable bit on stack segment
 121 # the same could be done by separate execstack command
 122 # Darwin is non-executable-stack by default
 123 ifneq ($(OS_VENDOR), Darwin)
 124 LFLAGS += -Xlinker -z -Xlinker noexecstack
 125 endif
 126 
 127 LIBS += -lm
 128 
 129 ifeq ($(USE_CLANG),)
 130   LIBS += -pthread











 131 endif
 132 
 133 # By default, link the *.o into the library, not the executable.
 134 LINK_INTO$(LINK_INTO) = LIBJVM
 135 
 136 JDK_LIBDIR = $(JAVA_HOME)/lib/$(LIBARCH)
 137 
 138 #----------------------------------------------------------------------
 139 # jvm_db & dtrace
 140 include $(MAKEFILES_DIR)/dtrace.make
 141 
 142 #----------------------------------------------------------------------
 143 # JVM
 144 
 145 JVM    = jvm
 146 ifeq ($(OS_VENDOR), Darwin)
 147   LIBJVM   = lib$(JVM).$(LIBRARY_SUFFIX)
 148   CFLAGS  += -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE
 149 
 150   LIBJVM_DEBUGINFO   = lib$(JVM).$(LIBRARY_SUFFIX).dSYM
 151   LIBJVM_DIZ         = lib$(JVM).diz
 152 else
 153   LIBJVM   = lib$(JVM).so
 154 
 155   LIBJVM_DEBUGINFO   = lib$(JVM).debuginfo
 156   LIBJVM_DIZ         = lib$(JVM).diz
 157 endif
 158 
 159 SPECIAL_PATHS:=adlc c1 gc opto shark libadt
 160 
 161 SOURCE_PATHS=\
 162   $(shell find $(HS_COMMON_SRC)/share/vm/* -type d \! \
 163       \( -name DUMMY $(foreach dir,$(SPECIAL_PATHS),-o -name $(dir)) \))
 164 SOURCE_PATHS+=$(HS_COMMON_SRC)/os/$(Platform_os_family)/vm
 165 SOURCE_PATHS+=$(HS_COMMON_SRC)/os/posix/vm
 166 SOURCE_PATHS+=$(HS_COMMON_SRC)/cpu/$(Platform_arch)/vm
 167 SOURCE_PATHS+=$(HS_COMMON_SRC)/os_cpu/$(Platform_os_arch)/vm
 168 
 169 CORE_PATHS=$(foreach path,$(SOURCE_PATHS),$(call altsrc,$(path)) $(path))
 170 CORE_PATHS+=$(GENERATED)/jvmtifiles $(GENERATED)/tracefiles
 171 
 172 ifneq ($(INCLUDE_TRACE), false)
 173 CORE_PATHS+=$(shell if [ -d $(HS_ALT_SRC)/share/vm/jfr ]; then \
 174   find $(HS_ALT_SRC)/share/vm/jfr -type d; \
 175   fi)
 176 endif
 177 
 178 COMPILER1_PATHS := $(call altsrc,$(HS_COMMON_SRC)/share/vm/c1)
 179 COMPILER1_PATHS += $(HS_COMMON_SRC)/share/vm/c1
 180 
 181 COMPILER2_PATHS := $(call altsrc,$(HS_COMMON_SRC)/share/vm/opto)
 182 COMPILER2_PATHS += $(call altsrc,$(HS_COMMON_SRC)/share/vm/libadt)
 183 COMPILER2_PATHS += $(HS_COMMON_SRC)/share/vm/opto
 184 COMPILER2_PATHS += $(HS_COMMON_SRC)/share/vm/libadt
 185 COMPILER2_PATHS += $(GENERATED)/adfiles
 186 
 187 SHARK_PATHS := $(GAMMADIR)/src/share/vm/shark
 188 
 189 # Include dirs per type.
 190 Src_Dirs/CORE      := $(CORE_PATHS)
 191 Src_Dirs/COMPILER1 := $(CORE_PATHS) $(COMPILER1_PATHS)
 192 Src_Dirs/COMPILER2 := $(CORE_PATHS) $(COMPILER2_PATHS)
 193 Src_Dirs/TIERED    := $(CORE_PATHS) $(COMPILER1_PATHS) $(COMPILER2_PATHS)
 194 Src_Dirs/ZERO      := $(CORE_PATHS)
 195 Src_Dirs/SHARK     := $(CORE_PATHS) $(SHARK_PATHS)
 196 Src_Dirs := $(Src_Dirs/$(TYPE))
 197 
 198 COMPILER2_SPECIFIC_FILES := opto libadt bcEscapeAnalyzer.cpp c2_\* runtime_\*
 199 COMPILER1_SPECIFIC_FILES := c1_\*
 200 SHARK_SPECIFIC_FILES     := shark
 201 ZERO_SPECIFIC_FILES      := zero
 202 
 203 # Always exclude these.
 204 Src_Files_EXCLUDE += jsig.c jvmtiEnvRecommended.cpp jvmtiEnvStub.cpp
 205 
 206 # Exclude per type.
 207 Src_Files_EXCLUDE/CORE      := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
 208 Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
 209 Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES)
 210 Src_Files_EXCLUDE/TIERED    := $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES)
 211 Src_Files_EXCLUDE/ZERO      := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
 212 Src_Files_EXCLUDE/SHARK     := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES)
 213 
 214 Src_Files_EXCLUDE +=  $(Src_Files_EXCLUDE/$(TYPE))
 215 
 216 # Special handling of arch model.
 217 ifeq ($(Platform_arch_model), x86_32)
 218 Src_Files_EXCLUDE += \*x86_64\*
 219 endif
 220 ifeq ($(Platform_arch_model), x86_64)
 221 Src_Files_EXCLUDE += \*x86_32\*
 222 endif
 223 
 224 # Locate all source files in the given directory, excluding files in Src_Files_EXCLUDE.
 225 define findsrc
 226         $(notdir $(shell find $(1)/. ! -name . -prune \
 227                 -a \( -name \*.c -o -name \*.cpp -o -name \*.s \) \
 228                 -a ! \( -name DUMMY $(addprefix -o -name ,$(Src_Files_EXCLUDE)) \)))
 229 endef
 230 
 231 Src_Files := $(foreach e,$(Src_Dirs),$(call findsrc,$(e)))
 232 
 233 Obj_Files = $(sort $(addsuffix .o,$(basename $(Src_Files))))
 234 
 235 JVM_OBJ_FILES = $(Obj_Files)
 236 
 237 vm_version.o: $(filter-out vm_version.o,$(JVM_OBJ_FILES))
 238 
 239 MAPFILE_SHARE  := $(GAMMADIR)/make/share/makefiles/mapfile-vers
 240 
 241 MAPFILE_EXT_SRC := $(HS_ALT_MAKE)/share/makefiles/mapfile-ext
 242 ifneq ("$(wildcard $(MAPFILE_EXT_SRC))","")
 243 MAPFILE_EXT     := $(MAPFILE_EXT_SRC)
 244 endif
 245 
 246 # For Darwin: add _ prefix and remove trailing ;
 247 mapfile_extra: $(MAPFILE_SHARE) $(MAPFILE_EXT)
 248         rm -f $@
 249 ifeq ($(OS_VENDOR), Darwin)
 250         cat $(MAPFILE_SHARE) $(MAPFILE_EXT) | \
 251             sed -e 's/#.*//g' -e 's/[ ]*//g' -e 's/;//g' | \
 252             awk '{ if ($$0 ~ ".") { print "\t\t_" $$0 } }' \
 253          > $@
 254 else
 255         cat $(MAPFILE_SHARE) $(MAPFILE_EXT) > $@
 256 endif
 257 
 258 mapfile : $(MAPFILE) mapfile_extra vm.def
 259         rm -f $@
 260         awk '{ if ($$0 ~ "INSERT VTABLE SYMBOLS HERE")  \
 261                  { system ("cat mapfile_extra vm.def"); } \
 262                else                                     \
 263                  { print $$0 }                          \
 264              }' > $@ < $(MAPFILE)
 265 
 266 ifeq ($(STATIC_BUILD),true)
 267 EXPORTED_SYMBOLS = libjvm.symbols
 268 
 269 libjvm.symbols : mapfile
 270         $(CP) mapfile libjvm.symbols
 271 
 272 else
 273 EXPORTED_SYMBOLS =
 274 endif
 275 
 276 mapfile_reorder : mapfile $(REORDERFILE)
 277         rm -f $@
 278         cat $^ > $@
 279 
 280 vm.def: $(Res_Files) $(Obj_Files)
 281         sh $(GAMMADIR)/make/bsd/makefiles/build_vm_def.sh *.o > $@
 282 
 283 mapfile_ext:
 284         rm -f $@
 285         touch $@
 286         if [ -f $(HS_ALT_MAKE)/bsd/makefiles/mapfile-ext ]; then \
 287           cat $(HS_ALT_MAKE)/bsd/makefiles/mapfile-ext > $@; \
 288         fi
 289 
 290 STATIC_CXX = false
 291 
 292 ifeq ($(LINK_INTO),AOUT)
 293   LIBJVM.o                 =
 294   LIBJVM_MAPFILE           =
 295   LIBS_VM                  = $(LIBS)
 296 else
 297   LIBJVM.o                 = $(JVM_OBJ_FILES)
 298   LIBJVM_MAPFILE$(LDNOMAP) = mapfile_reorder
 299   LFLAGS_VM$(LDNOMAP)      += $(MAPFLAG:FILENAME=$(LIBJVM_MAPFILE))
 300   LFLAGS_VM                += $(SONAMEFLAG:SONAME=$(LIBJVM))
 301 
 302   ifeq ($(OS_VENDOR), Darwin)
 303     ifneq ($(STATIC_BUILD),true)
 304     LFLAGS_VM += -Xlinker -rpath -Xlinker @loader_path/.
 305     LFLAGS_VM += -Xlinker -rpath -Xlinker @loader_path/..
 306     LFLAGS_VM += -Xlinker -install_name -Xlinker @rpath/$(@F)
 307     endif
 308   else


 309     LFLAGS_VM                += -Wl,-z,defs

 310   endif
 311 
 312   # JVM is statically linked with libgcc[_s] and libstdc++; this is needed to
 313   # get around library dependency and compatibility issues. Must use gcc not
 314   # g++ to link.
 315   ifeq ($(STATIC_CXX), true)
 316     LFLAGS_VM              += $(STATIC_LIBGCC)
 317     LIBS_VM                += $(STATIC_STDCXX)
 318     LINK_VM                = $(LINK_LIB.CC)
 319   else
 320     LINK_VM                = $(LINK_LIB.CXX)
 321   endif
 322 
 323   LIBS_VM                  += $(LIBS)
 324 endif
 325 ifeq ($(JVM_VARIANT_ZERO), true)
 326   LIBS_VM += $(LIBFFI_LIBS)
 327 endif
 328 ifeq ($(JVM_VARIANT_ZEROSHARK), true)
 329   LIBS_VM   += $(LIBFFI_LIBS) $(LLVM_LIBS)
 330   LFLAGS_VM += $(LLVM_LDFLAGS)
 331 endif
 332 
 333 
 334 # rule for building precompiled header
 335 $(PRECOMPILED_HEADER):
 336         $(QUIETLY) echo $(LOG_INFO) Generating precompiled header $@
 337         $(QUIETLY) mkdir -p $(PRECOMPILED_HEADER_DIR)
 338         $(QUIETLY) rm -f $@
 339         $(QUIETLY) $(COMPILE.CXX) $(DEPFLAGS) -x c++-header $(PRECOMPILED_HEADER_SRC) -o $@ $(COMPILE_DONE)
 340 
 341 # making the library:
 342 
 343 ifneq ($(JVM_BASE_ADDR),)
 344 # By default shared library is linked at base address == 0. Modify the
 345 # linker script if JVM prefers a different base location. It can also be
 346 # implemented with 'prelink -r'. But 'prelink' is not (yet) available on
 347 # our build platform (AS-2.1).
 348 LD_SCRIPT = libjvm.so.lds
 349 $(LD_SCRIPT): $(LIBJVM_MAPFILE)
 350         $(QUIETLY) {                                                \
 351           rm -rf $@;                                                \
 352           $(LINK_VM) -Wl,--verbose $(LFLAGS_VM) 2>&1             |  \
 353             sed -e '/^======/,/^======/!d'                          \
 354                 -e '/^======/d'                                     \
 355                 -e 's/0\( + SIZEOF_HEADERS\)/$(JVM_BASE_ADDR)\1/'   \
 356                 > $@;                                               \
 357         }
 358 LD_SCRIPT_FLAG = -Wl,-T,$(LD_SCRIPT)
 359 endif
 360 
 361 $(LIBJVM): $(LIBJVM.o) $(LIBJVM_MAPFILE) $(LD_SCRIPT)
 362 ifeq ($(STATIC_BUILD),true)
 363         echo Linking static vm...;
 364         $(LINK_LIB.CC) $@ $(LIBJVM.o)
 365 else
 366         $(QUIETLY) {                                                    \
 367             echo $(LOG_INFO) Linking vm...;                                         \
 368             $(LINK_LIB.CXX/PRE_HOOK)                                     \
 369             $(LINK_VM) $(LD_SCRIPT_FLAG)                                \
 370                        $(LFLAGS_VM) -o $@ $(sort $(LIBJVM.o)) $(LIBS_VM); \
 371             $(LINK_LIB.CXX/POST_HOOK)                                    \
 372             rm -f $@.1; ln -s $@ $@.1;                                  \
 373         }
 374 
 375 endif
 376 
 377 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
 378   ifeq ($(OS_VENDOR), Darwin)
 379         $(DSYMUTIL) $@
 380     ifeq ($(ZIP_DEBUGINFO_FILES),1)
 381         $(ZIPEXE) -q -r -y $(LIBJVM_DIZ) $(LIBJVM_DEBUGINFO)
 382         $(RM) -r $(LIBJVM_DEBUGINFO)
 383     endif
 384   else
 385         $(QUIETLY) $(OBJCOPY) --only-keep-debug $@ $(LIBJVM_DEBUGINFO)
 386         $(QUIETLY) $(OBJCOPY) --add-gnu-debuglink=$(LIBJVM_DEBUGINFO) $@
 387     ifeq ($(STRIP_POLICY),all_strip)
 388         $(QUIETLY) $(STRIP) $@
 389     else
 390       ifeq ($(STRIP_POLICY),min_strip)
 391         $(QUIETLY) $(STRIP) -g $@
 392       # implied else here is no stripping at all
 393       endif
 394     endif
 395     ifeq ($(ZIP_DEBUGINFO_FILES),1)
 396         $(ZIPEXE) -q -y $(LIBJVM_DIZ) $(LIBJVM_DEBUGINFO)
 397         $(RM) $(LIBJVM_DEBUGINFO)
 398     endif
 399   endif
 400 endif
 401 
 402 DEST_SUBDIR        = $(JDK_LIBDIR)/$(VM_SUBDIR)
 403 DEST_JVM           = $(DEST_SUBDIR)/$(LIBJVM)
 404 DEST_JVM_DEBUGINFO = $(DEST_SUBDIR)/$(LIBJVM_DEBUGINFO)
 405 DEST_JVM_DIZ       = $(DEST_SUBDIR)/$(LIBJVM_DIZ)
 406 
 407 install_jvm: $(LIBJVM)
 408         @echo "Copying $(LIBJVM) to $(DEST_JVM)"
 409 ifeq ($(OS_VENDOR), Darwin)
 410         $(QUIETLY) test ! -d $(LIBJVM_DEBUGINFO) || \
 411             $(CP) -f -r $(LIBJVM_DEBUGINFO) $(DEST_JVM_DEBUGINFO)
 412 else
 413         $(QUIETLY) test ! -f $(LIBJVM_DEBUGINFO) || \
 414             $(CP) -f $(LIBJVM_DEBUGINFO) $(DEST_JVM_DEBUGINFO)
 415 endif
 416         $(QUIETLY) test ! -f $(LIBJVM_DIZ) || \
 417             $(CP) -f $(LIBJVM_DIZ) $(DEST_JVM_DIZ)
 418         $(QUIETLY) $(CP) -f $(LIBJVM) $(DEST_JVM) && echo "Done"
 419 
 420 #----------------------------------------------------------------------
 421 # Other files
 422 
 423 # Signal interposition library
 424 include $(MAKEFILES_DIR)/jsig.make
 425 
 426 #----------------------------------------------------------------------
 427 
 428 ifeq ($(OS_VENDOR), Darwin)
 429 # no libjvm_db for macosx
 430 build: $(LIBJVM) $(LAUNCHER) $(LIBJSIG) dtraceCheck $(EXPORTED_SYMBOLS)
 431         echo "Doing vm.make build:"
 432 else
 433 build: $(LIBJVM) $(LAUNCHER) $(LIBJSIG) $(LIBJVM_DB) $(EXPORTED_SYMBOLS)
 434 endif
 435 
 436 install: install_jvm install_jsigs
 437 
 438 .PHONY: default build install install_jvm
--- EOF ---