changeset 48859:5a4d08efbad9

6909265: assert(_OnDeck != Self->_MutexEvent,"invariant") with -XX:+PrintMallocFree Summary: Convert to logging without thread locking Reviewed-by: dholmes, zgu, hseigel
author coleenp
date Fri, 02 Feb 2018 09:34:11 -0500
parents e50e326a2bfc
children 5bce1b7e7800
files src/hotspot/share/logging/logTag.hpp src/hotspot/share/memory/allocation.cpp src/hotspot/share/memory/allocation.inline.hpp src/hotspot/share/memory/arena.cpp src/hotspot/share/runtime/arguments.cpp src/hotspot/share/runtime/globals.hpp src/hotspot/share/runtime/os.cpp src/hotspot/share/utilities/ostream.cpp
diffstat 8 files changed, 28 insertions(+), 87 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/logging/logTag.hpp	Wed Jan 31 16:10:23 2018 -0800
+++ b/src/hotspot/share/logging/logTag.hpp	Fri Feb 02 09:34:11 2018 -0500
@@ -66,6 +66,7 @@
   LOG_TAG(exceptions) \
   LOG_TAG(exit) \
   LOG_TAG(fingerprint) \
+  LOG_TAG(free) \
   LOG_TAG(freelist) \
   LOG_TAG(gc) \
   LOG_TAG(handshake) \
@@ -85,6 +86,7 @@
   LOG_TAG(load) /* Trace all classes loaded */ \
   LOG_TAG(loader) \
   LOG_TAG(logging) \
+  LOG_TAG(malloc) \
   LOG_TAG(mark) \
   LOG_TAG(marking) \
   LOG_TAG(membername) \
--- a/src/hotspot/share/memory/allocation.cpp	Wed Jan 31 16:10:23 2018 -0800
+++ b/src/hotspot/share/memory/allocation.cpp	Fri Feb 02 09:34:11 2018 -0500
@@ -210,18 +210,6 @@
 }
 #endif // ASSERT
 
-
-void trace_heap_malloc(size_t size, const char* name, void* p) {
-  // A lock is not needed here - tty uses a lock internally
-  tty->print_cr("Heap malloc " INTPTR_FORMAT " " SIZE_FORMAT " %s", p2i(p), size, name == NULL ? "" : name);
-}
-
-
-void trace_heap_free(void* p) {
-  // A lock is not needed here - tty uses a lock internally
-  tty->print_cr("Heap free   " INTPTR_FORMAT, p2i(p));
-}
-
 //--------------------------------------------------------------------------------------
 // Non-product code
 
--- a/src/hotspot/share/memory/allocation.inline.hpp	Wed Jan 31 16:10:23 2018 -0800
+++ b/src/hotspot/share/memory/allocation.inline.hpp	Fri Feb 02 09:34:11 2018 -0500
@@ -33,9 +33,6 @@
 
 // Explicit C-heap memory management
 
-void trace_heap_malloc(size_t size, const char* name, void *p);
-void trace_heap_free(void *p);
-
 #ifndef PRODUCT
 // Increments unsigned long value for statistics (not atomic on MP).
 inline void inc_stat_counter(volatile julong* dest, julong add_value) {
@@ -56,9 +53,6 @@
     const NativeCallStack& stack,
     AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
   char* p = (char*) os::malloc(size, flags, stack);
-  #ifdef ASSERT
-  if (PrintMallocFree) trace_heap_malloc(size, "AllocateHeap", p);
-  #endif
   if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) {
     vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "AllocateHeap");
   }
@@ -73,9 +67,6 @@
 ALWAYSINLINE char* ReallocateHeap(char *old, size_t size, MEMFLAGS flag,
     AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
   char* p = (char*) os::realloc(old, size, flag, CURRENT_PC);
-  #ifdef ASSERT
-  if (PrintMallocFree) trace_heap_malloc(size, "ReallocateHeap", p);
-  #endif
   if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) {
     vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "ReallocateHeap");
   }
@@ -83,20 +74,13 @@
 }
 
 inline void FreeHeap(void* p) {
-  #ifdef ASSERT
-  if (PrintMallocFree) trace_heap_free(p);
-  #endif
   os::free(p);
 }
 
 
 template <MEMFLAGS F> void* CHeapObj<F>::operator new(size_t size,
       const NativeCallStack& stack) throw() {
-  void* p = (void*)AllocateHeap(size, F, stack);
-#ifdef ASSERT
-  if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p);
-#endif
-  return p;
+  return (void*)AllocateHeap(size, F, stack);
 }
 
 template <MEMFLAGS F> void* CHeapObj<F>::operator new(size_t size) throw() {
@@ -104,14 +88,9 @@
 }
 
 template <MEMFLAGS F> void* CHeapObj<F>::operator new (size_t size,
-  const std::nothrow_t&  nothrow_constant, const NativeCallStack& stack) throw() {
-  void* p = (void*)AllocateHeap(size, F, stack,
-      AllocFailStrategy::RETURN_NULL);
-#ifdef ASSERT
-    if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p);
-#endif
-    return p;
-  }
+      const std::nothrow_t&  nothrow_constant, const NativeCallStack& stack) throw() {
+  return (void*)AllocateHeap(size, F, stack, AllocFailStrategy::RETURN_NULL);
+}
 
 template <MEMFLAGS F> void* CHeapObj<F>::operator new (size_t size,
   const std::nothrow_t& nothrow_constant) throw() {
--- a/src/hotspot/share/memory/arena.cpp	Wed Jan 31 16:10:23 2018 -0800
+++ b/src/hotspot/share/memory/arena.cpp	Fri Feb 02 09:34:11 2018 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, 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
@@ -299,23 +299,11 @@
 
   // dynamic memory type binding
 void* Arena::operator new(size_t size, MEMFLAGS flags) throw() {
-#ifdef ASSERT
-  void* p = (void*)AllocateHeap(size, flags, CALLER_PC);
-  if (PrintMallocFree) trace_heap_malloc(size, "Arena-new", p);
-  return p;
-#else
   return (void *) AllocateHeap(size, flags, CALLER_PC);
-#endif
 }
 
 void* Arena::operator new(size_t size, const std::nothrow_t& nothrow_constant, MEMFLAGS flags) throw() {
-#ifdef ASSERT
-  void* p = os::malloc(size, flags, CALLER_PC);
-  if (PrintMallocFree) trace_heap_malloc(size, "Arena-new", p);
-  return p;
-#else
-  return os::malloc(size, flags, CALLER_PC);
-#endif
+  return (void*)AllocateHeap(size, flags, CALLER_PC, AllocFailStrategy::RETURN_NULL);
 }
 
 void Arena::operator delete(void* p) {
--- a/src/hotspot/share/runtime/arguments.cpp	Wed Jan 31 16:10:23 2018 -0800
+++ b/src/hotspot/share/runtime/arguments.cpp	Fri Feb 02 09:34:11 2018 -0500
@@ -527,6 +527,8 @@
   { "ConvertYieldToSleep",           JDK_Version::jdk(9),      JDK_Version::jdk(10), JDK_Version::jdk(11) },
   { "MinSleepInterval",              JDK_Version::jdk(9),      JDK_Version::jdk(10), JDK_Version::jdk(11) },
   { "CheckAssertionStatusDirectives",JDK_Version::undefined(), JDK_Version::jdk(11), JDK_Version::jdk(12) },
+  { "PrintMallocFree",               JDK_Version::undefined(), JDK_Version::jdk(11), JDK_Version::jdk(12) },
+  { "PrintMalloc",                   JDK_Version::undefined(), JDK_Version::jdk(11), JDK_Version::jdk(12) },
   { "PermSize",                      JDK_Version::undefined(), JDK_Version::jdk(8),  JDK_Version::undefined() },
   { "MaxPermSize",                   JDK_Version::undefined(), JDK_Version::jdk(8),  JDK_Version::undefined() },
   { "SharedReadWriteSize",           JDK_Version::undefined(), JDK_Version::jdk(10), JDK_Version::undefined() },
--- a/src/hotspot/share/runtime/globals.hpp	Wed Jan 31 16:10:23 2018 -0800
+++ b/src/hotspot/share/runtime/globals.hpp	Fri Feb 02 09:34:11 2018 -0500
@@ -893,18 +893,12 @@
   develop(bool, TraceJavaAssertions, false,                                 \
           "Trace java language assertions")                                 \
                                                                             \
-  notproduct(bool, PrintMallocFree, false,                                  \
-          "Trace calls to C heap malloc/free allocation")                   \
-                                                                            \
   notproduct(bool, VerifyCodeCache, false,                                  \
           "Verify code cache on memory allocation/deallocation")            \
                                                                             \
   develop(bool, UseMallocOnly, false,                                       \
           "Use only malloc/free for allocation (no resource area/arena)")   \
                                                                             \
-  develop(bool, PrintMalloc, false,                                         \
-          "Print all malloc/free calls")                                    \
-                                                                            \
   develop(bool, PrintMallocStatistics, false,                               \
           "Print malloc/free statistics")                                   \
                                                                             \
--- a/src/hotspot/share/runtime/os.cpp	Wed Jan 31 16:10:23 2018 -0800
+++ b/src/hotspot/share/runtime/os.cpp	Fri Feb 02 09:34:11 2018 -0500
@@ -33,6 +33,7 @@
 #include "code/icBuffer.hpp"
 #include "code/vtableStubs.hpp"
 #include "gc/shared/vmGCOperations.hpp"
+#include "logging/log.hpp"
 #include "interpreter/interpreter.hpp"
 #include "logging/log.hpp"
 #include "logging/logStream.hpp"
@@ -610,9 +611,12 @@
 static void verify_memory(void* ptr) {
   GuardedMemory guarded(ptr);
   if (!guarded.verify_guards()) {
-    tty->print_cr("## nof_mallocs = " UINT64_FORMAT ", nof_frees = " UINT64_FORMAT, os::num_mallocs, os::num_frees);
-    tty->print_cr("## memory stomp:");
-    guarded.print_on(tty);
+    LogTarget(Warning, malloc, free) lt;
+    ResourceMark rm;
+    LogStream ls(lt);
+    ls.print_cr("## nof_mallocs = " UINT64_FORMAT ", nof_frees = " UINT64_FORMAT, os::num_mallocs, os::num_frees);
+    ls.print_cr("## memory stomp:");
+    guarded.print_on(&ls);
     fatal("memory stomping error");
   }
 }
@@ -684,13 +688,10 @@
   ptr = guarded.get_user_ptr();
 #endif
   if ((intptr_t)ptr == (intptr_t)MallocCatchPtr) {
-    tty->print_cr("os::malloc caught, " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, p2i(ptr));
+    log_warning(malloc, free)("os::malloc caught, " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, p2i(ptr));
     breakpoint();
   }
   debug_only(if (paranoid) verify_memory(ptr));
-  if (PrintMalloc && tty != NULL) {
-    tty->print_cr("os::malloc " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, p2i(ptr));
-  }
 
   // we do not track guard memory
   return MemTracker::record_malloc((address)ptr, size, memflags, stack, level);
@@ -727,7 +728,7 @@
     return os::malloc(size, memflags, stack);
   }
   if ((intptr_t)memblock == (intptr_t)MallocCatchPtr) {
-    tty->print_cr("os::realloc caught " PTR_FORMAT, p2i(memblock));
+    log_warning(malloc, free)("os::realloc caught " PTR_FORMAT, p2i(memblock));
     breakpoint();
   }
   // NMT support
@@ -735,18 +736,15 @@
   verify_memory(membase);
   // always move the block
   void* ptr = os::malloc(size, memflags, stack);
-  if (PrintMalloc && tty != NULL) {
-    tty->print_cr("os::realloc " SIZE_FORMAT " bytes, " PTR_FORMAT " --> " PTR_FORMAT, size, p2i(memblock), p2i(ptr));
-  }
   // Copy to new memory if malloc didn't fail
-  if ( ptr != NULL ) {
+  if (ptr != NULL ) {
     GuardedMemory guarded(MemTracker::malloc_base(memblock));
     // Guard's user data contains NMT header
     size_t memblock_size = guarded.get_user_size() - MemTracker::malloc_header_size(memblock);
     memcpy(ptr, memblock, MIN2(size, memblock_size));
     if (paranoid) verify_memory(MemTracker::malloc_base(ptr));
     if ((intptr_t)ptr == (intptr_t)MallocCatchPtr) {
-      tty->print_cr("os::realloc caught, " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, p2i(ptr));
+      log_warning(malloc, free)("os::realloc caught, " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, p2i(ptr));
       breakpoint();
     }
     os::free(memblock);
@@ -761,7 +759,7 @@
 #ifdef ASSERT
   if (memblock == NULL) return;
   if ((intptr_t)memblock == (intptr_t)MallocCatchPtr) {
-    if (tty != NULL) tty->print_cr("os::free caught " PTR_FORMAT, p2i(memblock));
+    log_warning(malloc, free)("os::free caught " PTR_FORMAT, p2i(memblock));
     breakpoint();
   }
   void* membase = MemTracker::record_free(memblock);
@@ -771,9 +769,6 @@
   size_t size = guarded.get_user_size();
   inc_stat_counter(&free_bytes, size);
   membase = guarded.release_for_freeing();
-  if (PrintMalloc && tty != NULL) {
-      fprintf(stderr, "os::free " SIZE_FORMAT " bytes --> " PTR_FORMAT "\n", size, (uintptr_t)membase);
-  }
   ::free(membase);
 #else
   void* membase = MemTracker::record_free(memblock);
--- a/src/hotspot/share/utilities/ostream.cpp	Wed Jan 31 16:10:23 2018 -0800
+++ b/src/hotspot/share/utilities/ostream.cpp	Fri Feb 02 09:34:11 2018 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -947,18 +947,11 @@
     delete classlist_file;
   }
 #endif
-  {
-      // we temporaly disable PrintMallocFree here
-      // as otherwise it'll lead to using of almost deleted
-      // tty or defaultStream::instance in logging facility
-      // of HeapFree(), see 6391258
-      DEBUG_ONLY(FlagSetting fs(PrintMallocFree, false);)
-      if (tty != defaultStream::instance) {
-          delete tty;
-      }
-      if (defaultStream::instance != NULL) {
-          delete defaultStream::instance;
-      }
+  if (tty != defaultStream::instance) {
+    delete tty;
+  }
+  if (defaultStream::instance != NULL) {
+    delete defaultStream::instance;
   }
   tty = NULL;
   xtty = NULL;