8221851: Use of THIS_FILE in hotspot invalidates precompiled header on Linux/GCC
authorerikj
Wed, 10 Apr 2019 07:04:35 -0700
changeset 54490 bf07e140c49c
parent 54489 a84fefde0543
child 54491 a805bf992bf1
8221851: Use of THIS_FILE in hotspot invalidates precompiled header on Linux/GCC Reviewed-by: tbell, ysuenaga
make/autoconf/basics.m4
make/autoconf/flags-cflags.m4
make/autoconf/spec.gmk.in
make/common/NativeCompilation.gmk
make/hotspot/gensrc/GensrcAdlc.gmk
make/hotspot/gensrc/GensrcDtrace.gmk
make/hotspot/lib/CompileDtraceLibraries.gmk
make/hotspot/lib/CompileGtest.gmk
make/hotspot/lib/CompileJvm.gmk
src/hotspot/share/utilities/exceptions.hpp
--- a/make/autoconf/basics.m4	Wed Apr 10 13:21:38 2019 +0200
+++ b/make/autoconf/basics.m4	Wed Apr 10 07:04:35 2019 -0700
@@ -883,10 +883,11 @@
     fi
 
     if test "x$CUSTOM_ROOT" != x; then
-      OUTPUTDIR="${CUSTOM_ROOT}/build/${CONF_NAME}"
+      WORKSPACE_ROOT="${CUSTOM_ROOT}"
     else
-      OUTPUTDIR="${TOPDIR}/build/${CONF_NAME}"
+      WORKSPACE_ROOT="${TOPDIR}"
     fi
+    OUTPUTDIR="${WORKSPACE_ROOT}/build/${CONF_NAME}"
     $MKDIR -p "$OUTPUTDIR"
     if test ! -d "$OUTPUTDIR"; then
       AC_MSG_ERROR([Could not create build directory $OUTPUTDIR])
@@ -942,6 +943,7 @@
   AC_SUBST(SPEC)
   AC_SUBST(CONF_NAME)
   AC_SUBST(OUTPUTDIR)
+  AC_SUBST(WORKSPACE_ROOT)
   AC_SUBST(CONFIGURESUPPORT_OUTPUTDIR)
 
   # The spec.gmk file contains all variables for the make system.
--- a/make/autoconf/flags-cflags.m4	Wed Apr 10 13:21:38 2019 +0200
+++ b/make/autoconf/flags-cflags.m4	Wed Apr 10 07:04:35 2019 -0700
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -799,15 +799,29 @@
     $1_WARNING_CFLAGS_JVM="-Wno-format-zero-length -Wtype-limits -Wuninitialized"
   fi
 
+  if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
+    # Check if compiler supports -fmacro-prefix-map. If so, use that to make
+    # the __FILE__ macro resolve to paths relative to the workspace root.
+    workspace_root_trailing_slash="${WORKSPACE_ROOT%/}/"
+    FILE_MACRO_CFLAGS="-fmacro-prefix-map=${workspace_root_trailing_slash}="
+    FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${FILE_MACRO_CFLAGS}],
+        PREFIX: $3,
+        IF_FALSE: [
+            FILE_MACRO_CFLAGS=
+        ]
+    )
+  fi
+
   # EXPORT to API
   CFLAGS_JVM_COMMON="$ALWAYS_CFLAGS_JVM $ALWAYS_DEFINES_JVM \
       $TOOLCHAIN_CFLAGS_JVM ${$1_TOOLCHAIN_CFLAGS_JVM} \
       $OS_CFLAGS $OS_CFLAGS_JVM $CFLAGS_OS_DEF_JVM $DEBUG_CFLAGS_JVM \
-      $WARNING_CFLAGS $WARNING_CFLAGS_JVM $JVM_PICFLAG"
+      $WARNING_CFLAGS $WARNING_CFLAGS_JVM $JVM_PICFLAG $FILE_MACRO_CFLAGS"
 
   CFLAGS_JDK_COMMON="$ALWAYS_CFLAGS_JDK $ALWAYS_DEFINES_JDK $TOOLCHAIN_CFLAGS_JDK \
       $OS_CFLAGS $CFLAGS_OS_DEF_JDK $DEBUG_CFLAGS_JDK $DEBUG_OPTIONS_FLAGS_JDK \
-      $WARNING_CFLAGS $WARNING_CFLAGS_JDK $DEBUG_SYMBOLS_CFLAGS_JDK"
+      $WARNING_CFLAGS $WARNING_CFLAGS_JDK $DEBUG_SYMBOLS_CFLAGS_JDK \
+      $FILE_MACRO_CFLAGS"
 
   # Use ${$2EXTRA_CFLAGS} to block EXTRA_CFLAGS to be added to build flags.
   # (Currently we don't have any OPENJDK_BUILD_EXTRA_CFLAGS, but that might
--- a/make/autoconf/spec.gmk.in	Wed Apr 10 13:21:38 2019 +0200
+++ b/make/autoconf/spec.gmk.in	Wed Apr 10 07:04:35 2019 -0700
@@ -140,7 +140,9 @@
 
 # The top-level directory of the source repository
 TOPDIR:=@TOPDIR@
-
+# Usually the top level directory, but could be something else if a custom
+# root is defined.
+WORKSPACE_ROOT:=@WORKSPACE_ROOT@
 IMPORT_MODULES_CLASSES:=@IMPORT_MODULES_CLASSES@
 IMPORT_MODULES_CMDS:=@IMPORT_MODULES_CMDS@
 IMPORT_MODULES_LIBS:=@IMPORT_MODULES_LIBS@
--- a/make/common/NativeCompilation.gmk	Wed Apr 10 13:21:38 2019 +0200
+++ b/make/common/NativeCompilation.gmk	Wed Apr 10 07:04:35 2019 -0700
@@ -236,8 +236,10 @@
     # This is the definite source file to use for $1_FILENAME.
     $1_SRC_FILE := $$($1_FILE)
 
-    ifneq ($$($1_DISABLE_THIS_FILE_DEFINE), true)
-      $1_THIS_FILE = -DTHIS_FILE='"$$($1_FILENAME)"'
+    ifneq ($$($1_DEFINE_THIS_FILE), false)
+      ifneq ($$($$($1_BASE)_DEFINE_THIS_FILE), false)
+        $1_THIS_FILE = -DTHIS_FILE='"$$($1_FILENAME)"'
+      endif
     endif
 
     ifeq ($$($1_OPTIMIZATION), )
@@ -426,6 +428,7 @@
 #   STRIPFLAGS Optionally change the flags given to the strip command
 #   PRECOMPILED_HEADER Header file to use as precompiled header
 #   PRECOMPILED_HEADER_EXCLUDE List of source files that should not use PCH
+#   DEFINE_THIS_FILE Set to false to not set the THIS_FILE preprocessor macro
 #
 # After being called, some variables are exported from this macro, all prefixed
 # with parameter 1 followed by a '_':
@@ -703,7 +706,7 @@
             FILE := $$($1_GENERATED_PCH_SRC), \
             BASE := $1, \
             EXTRA_CXXFLAGS := -Fp$$($1_PCH_FILE) -Yc$$(notdir $$($1_PRECOMPILED_HEADER)), \
-            DISABLE_THIS_FILE_DEFINE := true, \
+            DEFINE_THIS_FILE := false, \
         ))
 
         $1_USE_PCH_FLAGS := \
--- a/make/hotspot/gensrc/GensrcAdlc.gmk	Wed Apr 10 13:21:38 2019 +0200
+++ b/make/hotspot/gensrc/GensrcAdlc.gmk	Wed Apr 10 07:04:35 2019 -0700
@@ -76,6 +76,7 @@
       DEBUG_SYMBOLS := false, \
       DISABLED_WARNINGS_clang := tautological-compare, \
       DISABLED_WARNINGS_solstudio := notemsource, \
+      DEFINE_THIS_FILE := false, \
   ))
 
   ADLC_TOOL := $(BUILD_ADLC_TARGET)
--- a/make/hotspot/gensrc/GensrcDtrace.gmk	Wed Apr 10 13:21:38 2019 +0200
+++ b/make/hotspot/gensrc/GensrcDtrace.gmk	Wed Apr 10 07:04:35 2019 -0700
@@ -80,6 +80,7 @@
         EXTRA_DEPS := $(JVMTI_H) $(JFR_FILES), \
         OBJECT_DIR := $(JVM_VARIANT_OUTPUTDIR)/tools/dtrace-gen-offsets/objs, \
         OUTPUT_DIR := $(JVM_VARIANT_OUTPUTDIR)/tools/dtrace-gen-offsets, \
+        DEFINE_THIS_FILE := false, \
     ))
 
     DTRACE_GEN_OFFSETS_TOOL := $(BUILD_DTRACE_GEN_OFFSETS_TARGET)
--- a/make/hotspot/lib/CompileDtraceLibraries.gmk	Wed Apr 10 13:21:38 2019 +0200
+++ b/make/hotspot/lib/CompileDtraceLibraries.gmk	Wed Apr 10 07:04:35 2019 -0700
@@ -42,6 +42,7 @@
         LDFLAGS := -m64 -mt -xnolib $(SHARED_LIBRARY_FLAGS), \
         LIBS := $(LIBDL) -lthread -ldoor, \
         OBJECT_DIR := $(LIBJVM_DTRACE_OUTPUTDIR)/objs, \
+        DEFINE_THIS_FILE := false, \
     ))
 
     # Note that libjvm_db.c has tests for COMPILER2, but this was never set by
@@ -54,6 +55,7 @@
         CFLAGS := -I$(DTRACE_GENSRC_DIR) $(JNI_INCLUDE_FLAGS) -m64 -G -mt -KPIC -xldscope=hidden, \
         LDFLAGS := -m64 -mt -xnolib $(SHARED_LIBRARY_FLAGS), \
         OBJECT_DIR := $(LIBJVM_DB_OUTPUTDIR)/objs, \
+        DEFINE_THIS_FILE := false, \
     ))
 
     TARGETS += $(BUILD_LIBJVM_DTRACE) $(BUILD_LIBJVM_DB)
--- a/make/hotspot/lib/CompileGtest.gmk	Wed Apr 10 13:21:38 2019 +0200
+++ b/make/hotspot/lib/CompileGtest.gmk	Wed Apr 10 07:04:35 2019 -0700
@@ -92,6 +92,7 @@
     STRIP_SYMBOLS := false, \
     PRECOMPILED_HEADER := $(JVM_PRECOMPILED_HEADER), \
     PRECOMPILED_HEADER_EXCLUDE := gtest-all.cc gtestMain.cpp, \
+    DEFINE_THIS_FILE := false, \
 ))
 
 TARGETS += $(BUILD_GTEST_LIBJVM)
@@ -115,6 +116,7 @@
     LIBS_windows := $(JVM_OUTPUTDIR)/gtest/objs/jvm.lib, \
     COPY_DEBUG_SYMBOLS := $(GTEST_COPY_DEBUG_SYMBOLS), \
     ZIP_EXTERNAL_DEBUG_SYMBOLS := false, \
+    DEFINE_THIS_FILE := false, \
 ))
 
 $(BUILD_GTEST_LAUNCHER): $(BUILD_GTEST_LIBJVM)
--- a/make/hotspot/lib/CompileJvm.gmk	Wed Apr 10 13:21:38 2019 +0200
+++ b/make/hotspot/lib/CompileJvm.gmk	Wed Apr 10 07:04:35 2019 -0700
@@ -202,6 +202,7 @@
     VERSIONINFO_RESOURCE := $(TOPDIR)/src/hotspot/os/windows/version.rc, \
     PRECOMPILED_HEADER := $(JVM_PRECOMPILED_HEADER), \
     PRECOMPILED_HEADER_EXCLUDE := $(JVM_PRECOMPILED_HEADER_EXCLUDE), \
+    DEFINE_THIS_FILE := false, \
 ))
 
 # Always recompile vm_version.cpp if libjvm needs to be relinked. This ensures
--- a/src/hotspot/share/utilities/exceptions.hpp	Wed Apr 10 13:21:38 2019 +0200
+++ b/src/hotspot/share/utilities/exceptions.hpp	Wed Apr 10 07:04:35 2019 -0700
@@ -237,11 +237,7 @@
 // visible within the scope containing the THROW. Usually this is achieved by declaring the function
 // with a TRAPS argument.
 
-#ifdef THIS_FILE
-#define THREAD_AND_LOCATION                      THREAD, THIS_FILE, __LINE__
-#else
 #define THREAD_AND_LOCATION                      THREAD, __FILE__, __LINE__
-#endif
 
 #define THROW_OOP(e)                                \
   { Exceptions::_throw_oop(THREAD_AND_LOCATION, e);                             return;  }