6909265: assert(_OnDeck != Self->_MutexEvent,"invariant") with -XX:+PrintMallocFree

Convert to logging without thread locking

Reviewed-by: dholmes, zgu, hseigel
This commit is contained in:
Coleen Phillimore 2018-02-02 09:34:11 -05:00
parent ce205655fe
commit 191a1f80a1
8 changed files with 28 additions and 87 deletions

View File

@ -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) \

View File

@ -210,18 +210,6 @@ ResourceObj::~ResourceObj() {
}
#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

View File

@ -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 @@ inline char* AllocateHeap(size_t size, MEMFLAGS flags,
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* AllocateHeap(size_t size, MEMFLAGS flags,
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 @@ ALWAYSINLINE char* ReallocateHeap(char *old, size_t size, MEMFLAGS flag,
}
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) throw() {
}
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() {

View File

@ -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 @@ void* Arena::operator new (size_t size, const std::nothrow_t& nothrow_constant)
// 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) {

View File

@ -527,6 +527,8 @@ static SpecialFlag const special_jvm_flags[] = {
{ "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() },

View File

@ -893,18 +893,12 @@ public:
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") \
\

View File

@ -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 @@ char* os::strdup_check_oom(const char* str, MEMFLAGS flags) {
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 @@ void* os::malloc(size_t size, MEMFLAGS memflags, const NativeCallStack& stack) {
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 @@ void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, const NativeCa
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 @@ void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, const NativeCa
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 @@ void os::free(void *memblock) {
#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 @@ void os::free(void *memblock) {
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);

View File

@ -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 @@ void ostream_exit() {
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;