1 #
   2 # Copyright (c) 1999, 2016, 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 else
 132   # For non-Darwin BSD we also want pthread even with clang.
 133   ifneq ($(OS_VENDOR), Darwin)
 134     LIBS += -pthread
 135   endif
 136 endif
 137 
 138 ifeq ($(USE_CLANG), true)
 139   ifeq ($(OS_VENDOR), OpenBSD)
 140     LIBS += -lc
 141   endif
 142 endif
 143 
 144 # By default, link the *.o into the library, not the executable.
 145 LINK_INTO$(LINK_INTO) = LIBJVM
 146 
 147 JDK_LIBDIR = $(JAVA_HOME)/lib/$(LIBARCH)
 148 
 149 #----------------------------------------------------------------------
 150 # jvm_db & dtrace
 151 include $(MAKEFILES_DIR)/dtrace.make
 152 
 153 #----------------------------------------------------------------------
 154 # JVM
 155 
 156 JVM    = jvm
 157 ifeq ($(OS_VENDOR), Darwin)
 158   LIBJVM   = lib$(JVM).$(LIBRARY_SUFFIX)
 159   CFLAGS  += -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE
 160 
 161   LIBJVM_DEBUGINFO   = lib$(JVM).$(LIBRARY_SUFFIX).dSYM
 162   LIBJVM_DIZ         = lib$(JVM).diz
 163 else
 164   LIBJVM   = lib$(JVM).so
 165 
 166   LIBJVM_DEBUGINFO   = lib$(JVM).debuginfo
 167   LIBJVM_DIZ         = lib$(JVM).diz
 168 endif
 169 
 170 SPECIAL_PATHS:=adlc c1 gc opto shark libadt
 171 
 172 SOURCE_PATHS=\
 173   $(shell find $(HS_COMMON_SRC)/share/vm/* -type d \! \
 174       \( -name DUMMY $(foreach dir,$(SPECIAL_PATHS),-o -name $(dir)) \))
 175 SOURCE_PATHS+=$(HS_COMMON_SRC)/os/$(Platform_os_family)/vm
 176 SOURCE_PATHS+=$(HS_COMMON_SRC)/os/posix/vm
 177 SOURCE_PATHS+=$(HS_COMMON_SRC)/cpu/$(Platform_arch)/vm
 178 SOURCE_PATHS+=$(HS_COMMON_SRC)/os_cpu/$(Platform_os_arch)/vm
 179 
 180 CORE_PATHS=$(foreach path,$(SOURCE_PATHS),$(call altsrc,$(path)) $(path))
 181 CORE_PATHS+=$(GENERATED)/jvmtifiles $(GENERATED)/tracefiles
 182 
 183 ifneq ($(INCLUDE_TRACE), false)
 184 CORE_PATHS+=$(shell if [ -d $(HS_ALT_SRC)/share/vm/jfr ]; then \
 185   find $(HS_ALT_SRC)/share/vm/jfr -type d; \
 186   fi)
 187 endif
 188 
 189 COMPILER1_PATHS := $(call altsrc,$(HS_COMMON_SRC)/share/vm/c1)
 190 COMPILER1_PATHS += $(HS_COMMON_SRC)/share/vm/c1
 191 
 192 COMPILER2_PATHS := $(call altsrc,$(HS_COMMON_SRC)/share/vm/opto)
 193 COMPILER2_PATHS += $(call altsrc,$(HS_COMMON_SRC)/share/vm/libadt)
 194 COMPILER2_PATHS += $(HS_COMMON_SRC)/share/vm/opto
 195 COMPILER2_PATHS += $(HS_COMMON_SRC)/share/vm/libadt
 196 COMPILER2_PATHS += $(GENERATED)/adfiles
 197 
 198 SHARK_PATHS := $(GAMMADIR)/src/share/vm/shark
 199 
 200 # Include dirs per type.
 201 Src_Dirs/CORE      := $(CORE_PATHS)
 202 Src_Dirs/COMPILER1 := $(CORE_PATHS) $(COMPILER1_PATHS)
 203 Src_Dirs/COMPILER2 := $(CORE_PATHS) $(COMPILER2_PATHS)
 204 Src_Dirs/TIERED    := $(CORE_PATHS) $(COMPILER1_PATHS) $(COMPILER2_PATHS)
 205 Src_Dirs/ZERO      := $(CORE_PATHS)
 206 Src_Dirs/SHARK     := $(CORE_PATHS) $(SHARK_PATHS)
 207 Src_Dirs := $(Src_Dirs/$(TYPE))
 208 
 209 COMPILER2_SPECIFIC_FILES := opto libadt bcEscapeAnalyzer.cpp c2_\* runtime_\*
 210 COMPILER1_SPECIFIC_FILES := c1_\*
 211 SHARK_SPECIFIC_FILES     := shark
 212 ZERO_SPECIFIC_FILES      := zero
 213 
 214 # Always exclude these.
 215 Src_Files_EXCLUDE += jsig.c jvmtiEnvRecommended.cpp jvmtiEnvStub.cpp
 216 
 217 # Exclude per type.
 218 Src_Files_EXCLUDE/CORE      := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
 219 Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
 220 Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES)
 221 Src_Files_EXCLUDE/TIERED    := $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES)
 222 Src_Files_EXCLUDE/ZERO      := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
 223 Src_Files_EXCLUDE/SHARK     := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES)
 224 
 225 Src_Files_EXCLUDE +=  $(Src_Files_EXCLUDE/$(TYPE))
 226 
 227 # Special handling of arch model.
 228 ifeq ($(Platform_arch_model), x86_32)
 229 Src_Files_EXCLUDE += \*x86_64\*
 230 endif
 231 ifeq ($(Platform_arch_model), x86_64)
 232 Src_Files_EXCLUDE += \*x86_32\*
 233 endif
 234 
 235 # Locate all source files in the given directory, excluding files in Src_Files_EXCLUDE.
 236 define findsrc
 237         $(notdir $(shell find $(1)/. ! -name . -prune \
 238                 -a \( -name \*.c -o -name \*.cpp -o -name \*.s \) \
 239                 -a ! \( -name DUMMY $(addprefix -o -name ,$(Src_Files_EXCLUDE)) \)))
 240 endef
 241 
 242 Src_Files := $(foreach e,$(Src_Dirs),$(call findsrc,$(e)))
 243 
 244 Obj_Files = $(sort $(addsuffix .o,$(basename $(Src_Files))))
 245 
 246 JVM_OBJ_FILES = $(Obj_Files)
 247 
 248 vm_version.o: $(filter-out vm_version.o,$(JVM_OBJ_FILES))
 249 
 250 MAPFILE_SHARE  := $(GAMMADIR)/make/share/makefiles/mapfile-vers
 251 
 252 MAPFILE_EXT_SRC := $(HS_ALT_MAKE)/share/makefiles/mapfile-ext
 253 ifneq ("$(wildcard $(MAPFILE_EXT_SRC))","")
 254 MAPFILE_EXT     := $(MAPFILE_EXT_SRC)
 255 endif
 256 
 257 # For Darwin: add _ prefix and remove trailing ;
 258 mapfile_extra: $(MAPFILE_SHARE) $(MAPFILE_EXT)
 259         rm -f $@
 260 ifeq ($(OS_VENDOR), Darwin)
 261         cat $(MAPFILE_SHARE) $(MAPFILE_EXT) | \
 262             sed -e 's/#.*//g' -e 's/[ ]*//g' -e 's/;//g' | \
 263             awk '{ if ($$0 ~ ".") { print "\t\t_" $$0 } }' \
 264          > $@
 265 else
 266         cat $(MAPFILE_SHARE) $(MAPFILE_EXT) > $@
 267 endif
 268 
 269 mapfile : $(MAPFILE) mapfile_extra vm.def
 270         rm -f $@
 271         awk '{ if ($$0 ~ "INSERT VTABLE SYMBOLS HERE")  \
 272                  { system ("cat mapfile_extra vm.def"); } \
 273                else                                     \
 274                  { print $$0 }                          \
 275              }' > $@ < $(MAPFILE)
 276 
 277 ifeq ($(STATIC_BUILD),true)
 278 EXPORTED_SYMBOLS = libjvm.symbols
 279 
 280 libjvm.symbols : mapfile
 281         $(CP) mapfile libjvm.symbols
 282 
 283 else
 284 EXPORTED_SYMBOLS =
 285 endif
 286 
 287 mapfile_reorder : mapfile $(REORDERFILE)
 288         rm -f $@
 289         cat $^ > $@
 290 
 291 vm.def: $(Res_Files) $(Obj_Files)
 292         sh $(GAMMADIR)/make/bsd/makefiles/build_vm_def.sh *.o > $@
 293 
 294 mapfile_ext:
 295         rm -f $@
 296         touch $@
 297         if [ -f $(HS_ALT_MAKE)/bsd/makefiles/mapfile-ext ]; then \
 298           cat $(HS_ALT_MAKE)/bsd/makefiles/mapfile-ext > $@; \
 299         fi
 300 
 301 STATIC_CXX = false
 302 
 303 ifeq ($(LINK_INTO),AOUT)
 304   LIBJVM.o                 =
 305   LIBJVM_MAPFILE           =
 306   LIBS_VM                  = $(LIBS)
 307 else
 308   LIBJVM.o                 = $(JVM_OBJ_FILES)
 309   LIBJVM_MAPFILE$(LDNOMAP) = mapfile_reorder
 310   LFLAGS_VM$(LDNOMAP)      += $(MAPFLAG:FILENAME=$(LIBJVM_MAPFILE))
 311   LFLAGS_VM                += $(SONAMEFLAG:SONAME=$(LIBJVM))
 312 
 313   ifeq ($(OS_VENDOR), Darwin)
 314     ifneq ($(STATIC_BUILD),true)
 315     LFLAGS_VM += -Xlinker -rpath -Xlinker @loader_path/.
 316     LFLAGS_VM += -Xlinker -rpath -Xlinker @loader_path/..
 317     LFLAGS_VM += -Xlinker -install_name -Xlinker @rpath/$(@F)
 318     endif
 319   else
 320     # On FreeBSD/OpenBSD "environ" is intentionally undefined, so we can't use -z defs.
 321     ifeq ($(filter $(OS_VENDOR), FreeBSD OpenBSD), )
 322       LFLAGS_VM                += -Wl,-z,defs
 323     endif
 324   endif
 325 
 326   # JVM is statically linked with libgcc[_s] and libstdc++; this is needed to
 327   # get around library dependency and compatibility issues. Must use gcc not
 328   # g++ to link.
 329   ifeq ($(STATIC_CXX), true)
 330     LFLAGS_VM              += $(STATIC_LIBGCC)
 331     LIBS_VM                += $(STATIC_STDCXX)
 332     LINK_VM                = $(LINK_LIB.CC)
 333   else
 334     LINK_VM                = $(LINK_LIB.CXX)
 335   endif
 336 
 337   LIBS_VM                  += $(LIBS)
 338 endif
 339 ifeq ($(JVM_VARIANT_ZERO), true)
 340   LIBS_VM += $(LIBFFI_LIBS)
 341 endif
 342 ifeq ($(JVM_VARIANT_ZEROSHARK), true)
 343   LIBS_VM   += $(LIBFFI_LIBS) $(LLVM_LIBS)
 344   LFLAGS_VM += $(LLVM_LDFLAGS)
 345 endif
 346 
 347 
 348 # rule for building precompiled header
 349 $(PRECOMPILED_HEADER):
 350         $(QUIETLY) echo $(LOG_INFO) Generating precompiled header $@
 351         $(QUIETLY) mkdir -p $(PRECOMPILED_HEADER_DIR)
 352         $(QUIETLY) rm -f $@
 353         $(QUIETLY) $(COMPILE.CXX) $(DEPFLAGS) -x c++-header $(PRECOMPILED_HEADER_SRC) -o $@ $(COMPILE_DONE)
 354 
 355 # making the library:
 356 
 357 ifneq ($(JVM_BASE_ADDR),)
 358 # By default shared library is linked at base address == 0. Modify the
 359 # linker script if JVM prefers a different base location. It can also be
 360 # implemented with 'prelink -r'. But 'prelink' is not (yet) available on
 361 # our build platform (AS-2.1).
 362 LD_SCRIPT = libjvm.so.lds
 363 $(LD_SCRIPT): $(LIBJVM_MAPFILE)
 364         $(QUIETLY) {                                                \
 365           rm -rf $@;                                                \
 366           $(LINK_VM) -Wl,--verbose $(LFLAGS_VM) 2>&1             |  \
 367             sed -e '/^======/,/^======/!d'                          \
 368                 -e '/^======/d'                                     \
 369                 -e 's/0\( + SIZEOF_HEADERS\)/$(JVM_BASE_ADDR)\1/'   \
 370                 > $@;                                               \
 371         }
 372 LD_SCRIPT_FLAG = -Wl,-T,$(LD_SCRIPT)
 373 endif
 374 
 375 $(LIBJVM): $(LIBJVM.o) $(LIBJVM_MAPFILE) $(LD_SCRIPT)
 376 ifeq ($(STATIC_BUILD),true)
 377         echo Linking static vm...;
 378         $(LINK_LIB.CC) $@ $(LIBJVM.o)
 379 else
 380         $(QUIETLY) {                                                    \
 381             echo $(LOG_INFO) Linking vm...;                                         \
 382             $(LINK_LIB.CXX/PRE_HOOK)                                     \
 383             $(LINK_VM) $(LD_SCRIPT_FLAG)                                \
 384                        $(LFLAGS_VM) -o $@ $(sort $(LIBJVM.o)) $(LIBS_VM); \
 385             $(LINK_LIB.CXX/POST_HOOK)                                    \
 386             rm -f $@.1; ln -s $@ $@.1;                                  \
 387         }
 388 
 389 endif
 390 
 391 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
 392   ifeq ($(OS_VENDOR), Darwin)
 393         $(DSYMUTIL) $@
 394     ifeq ($(ZIP_DEBUGINFO_FILES),1)
 395         $(ZIPEXE) -q -r -y $(LIBJVM_DIZ) $(LIBJVM_DEBUGINFO)
 396         $(RM) -r $(LIBJVM_DEBUGINFO)
 397     endif
 398   else
 399         $(QUIETLY) $(OBJCOPY) --only-keep-debug $@ $(LIBJVM_DEBUGINFO)
 400         $(QUIETLY) $(OBJCOPY) --add-gnu-debuglink=$(LIBJVM_DEBUGINFO) $@
 401     ifeq ($(STRIP_POLICY),all_strip)
 402         $(QUIETLY) $(STRIP) $@
 403     else
 404       ifeq ($(STRIP_POLICY),min_strip)
 405         $(QUIETLY) $(STRIP) -g $@
 406       # implied else here is no stripping at all
 407       endif
 408     endif
 409     ifeq ($(ZIP_DEBUGINFO_FILES),1)
 410         $(ZIPEXE) -q -y $(LIBJVM_DIZ) $(LIBJVM_DEBUGINFO)
 411         $(RM) $(LIBJVM_DEBUGINFO)
 412     endif
 413   endif
 414 endif
 415 
 416 DEST_SUBDIR        = $(JDK_LIBDIR)/$(VM_SUBDIR)
 417 DEST_JVM           = $(DEST_SUBDIR)/$(LIBJVM)
 418 DEST_JVM_DEBUGINFO = $(DEST_SUBDIR)/$(LIBJVM_DEBUGINFO)
 419 DEST_JVM_DIZ       = $(DEST_SUBDIR)/$(LIBJVM_DIZ)
 420 
 421 install_jvm: $(LIBJVM)
 422         @echo "Copying $(LIBJVM) to $(DEST_JVM)"
 423 ifeq ($(OS_VENDOR), Darwin)
 424         $(QUIETLY) test ! -d $(LIBJVM_DEBUGINFO) || \
 425             $(CP) -f -r $(LIBJVM_DEBUGINFO) $(DEST_JVM_DEBUGINFO)
 426 else
 427         $(QUIETLY) test ! -f $(LIBJVM_DEBUGINFO) || \
 428             $(CP) -f $(LIBJVM_DEBUGINFO) $(DEST_JVM_DEBUGINFO)
 429 endif
 430         $(QUIETLY) test ! -f $(LIBJVM_DIZ) || \
 431             $(CP) -f $(LIBJVM_DIZ) $(DEST_JVM_DIZ)
 432         $(QUIETLY) $(CP) -f $(LIBJVM) $(DEST_JVM) && echo "Done"
 433 
 434 #----------------------------------------------------------------------
 435 # Other files
 436 
 437 # Signal interposition library
 438 include $(MAKEFILES_DIR)/jsig.make
 439 
 440 #----------------------------------------------------------------------
 441 
 442 ifeq ($(OS_VENDOR), Darwin)
 443 # no libjvm_db for macosx
 444 build: $(LIBJVM) $(LAUNCHER) $(LIBJSIG) dtraceCheck $(EXPORTED_SYMBOLS)
 445         echo "Doing vm.make build:"
 446 else
 447 build: $(LIBJVM) $(LAUNCHER) $(LIBJSIG) $(LIBJVM_DB) $(EXPORTED_SYMBOLS)
 448 endif
 449 
 450 install: install_jvm install_jsigs
 451 
 452 .PHONY: default build install install_jvm