7190089: NMT ON: NMT failed assertion on thread's stack base address
Summary: Solaris only, record stack info to NMT after stack size adjustment was made for primordial threads
Reviewed-by: kvn, acorn, coleenp
--- a/hotspot/src/os/solaris/vm/os_solaris.cpp Mon Sep 17 11:46:19 2012 +0200
+++ b/hotspot/src/os/solaris/vm/os_solaris.cpp Mon Sep 17 10:20:04 2012 -0400
@@ -1488,11 +1488,11 @@
// First crack at OS-specific initialization, from inside the new thread.
-void os::initialize_thread() {
+void os::initialize_thread(Thread* thr) {
int r = thr_main() ;
guarantee (r == 0 || r == 1, "CR6501650 or CR6493689") ;
if (r) {
- JavaThread* jt = (JavaThread *)Thread::current();
+ JavaThread* jt = (JavaThread *)thr;
assert(jt != NULL,"Sanity check");
size_t stack_size;
address base = jt->stack_base();
--- a/hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp Mon Sep 17 11:46:19 2012 +0200
+++ b/hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp Mon Sep 17 10:20:04 2012 -0400
@@ -297,7 +297,7 @@
return (char*) -1;
}
-void os::initialize_thread() {
+void os::initialize_thread(Thread* thr) {
// Nothing to do.
}
--- a/hotspot/src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp Mon Sep 17 11:46:19 2012 +0200
+++ b/hotspot/src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp Mon Sep 17 10:20:04 2012 -0400
@@ -103,7 +103,7 @@
#endif // SPARC
}
-void os::initialize_thread() {
+void os::initialize_thread(Thread* thr) {
// Nothing to do.
}
--- a/hotspot/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp Mon Sep 17 11:46:19 2012 +0200
+++ b/hotspot/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp Mon Sep 17 10:20:04 2012 -0400
@@ -225,7 +225,7 @@
return (char*) 0;
}
-void os::initialize_thread() {}
+void os::initialize_thread(Thread* thr) {}
void os::print_context(outputStream *st, void *context) {
if (context == NULL) return;
--- a/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp Mon Sep 17 11:46:19 2012 +0200
+++ b/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp Mon Sep 17 10:20:04 2012 -0400
@@ -114,7 +114,7 @@
return (char*) -1;
}
-void os::initialize_thread() {
+void os::initialize_thread(Thread* thr) {
// Nothing to do.
}
--- a/hotspot/src/os_cpu/linux_zero/vm/os_linux_zero.cpp Mon Sep 17 11:46:19 2012 +0200
+++ b/hotspot/src/os_cpu/linux_zero/vm/os_linux_zero.cpp Mon Sep 17 10:20:04 2012 -0400
@@ -98,7 +98,7 @@
#endif // SPARC
}
-void os::initialize_thread() {
+void os::initialize_thread(Thread * thr){
// Nothing to do.
}
--- a/hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.cpp Mon Sep 17 11:46:19 2012 +0200
+++ b/hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.cpp Mon Sep 17 10:20:04 2012 -0400
@@ -219,7 +219,7 @@
return true;
}
-void os::initialize_thread() {
+void os::initialize_thread(Thread* thr) {
// Nothing to do.
}
--- a/hotspot/src/share/vm/runtime/os.hpp Mon Sep 17 11:46:19 2012 +0200
+++ b/hotspot/src/share/vm/runtime/os.hpp Mon Sep 17 10:20:04 2012 -0400
@@ -387,7 +387,7 @@
static void pd_start_thread(Thread* thread);
static void start_thread(Thread* thread);
- static void initialize_thread();
+ static void initialize_thread(Thread* thr);
static void free_thread(OSThread* osthread);
// thread id on Linux/64bit is 64bit, on Windows and Solaris, it's 32bit
--- a/hotspot/src/share/vm/runtime/thread.cpp Mon Sep 17 11:46:19 2012 +0200
+++ b/hotspot/src/share/vm/runtime/thread.cpp Mon Sep 17 10:20:04 2012 -0400
@@ -308,19 +308,25 @@
// initialize structure dependent on thread local storage
ThreadLocalStorage::set_thread(this);
-
- // set up any platform-specific state.
- os::initialize_thread();
}
void Thread::record_stack_base_and_size() {
set_stack_base(os::current_stack_base());
set_stack_size(os::current_stack_size());
-
- // record thread's native stack, stack grows downward
- address low_stack_addr = stack_base() - stack_size();
- MemTracker::record_thread_stack(low_stack_addr, stack_size(), this,
- CURRENT_PC);
+ // CR 7190089: on Solaris, primordial thread's stack is adjusted
+ // in initialize_thread(). Without the adjustment, stack size is
+ // incorrect if stack is set to unlimited (ulimit -s unlimited).
+ // So far, only Solaris has real implementation of initialize_thread().
+ //
+ // set up any platform-specific state.
+ os::initialize_thread(this);
+
+ // record thread's native stack, stack grows downward
+ if (MemTracker::is_on()) {
+ address stack_low_addr = stack_base() - stack_size();
+ MemTracker::record_thread_stack(stack_low_addr, stack_size(), this,
+ CURRENT_PC);
+ }
}
--- a/hotspot/src/share/vm/services/memTracker.cpp Mon Sep 17 11:46:19 2012 +0200
+++ b/hotspot/src/share/vm/services/memTracker.cpp Mon Sep 17 10:20:04 2012 -0400
@@ -341,6 +341,7 @@
*/
void MemTracker::create_memory_record(address addr, MEMFLAGS flags,
size_t size, address pc, Thread* thread) {
+ assert(addr != NULL, "Sanity check");
if (!shutdown_in_progress()) {
// single thread, we just write records direct to global recorder,'
// with any lock
--- a/hotspot/src/share/vm/services/memTracker.hpp Mon Sep 17 11:46:19 2012 +0200
+++ b/hotspot/src/share/vm/services/memTracker.hpp Mon Sep 17 10:20:04 2012 -0400
@@ -185,6 +185,7 @@
static inline void record_malloc(address addr, size_t size, MEMFLAGS flags,
address pc = 0, Thread* thread = NULL) {
if (NMT_CAN_TRACK(flags)) {
+ assert(size > 0, "Sanity check");
create_memory_record(addr, (flags|MemPointerRecord::malloc_tag()), size, pc, thread);
}
}
@@ -198,6 +199,7 @@
static inline void record_realloc(address old_addr, address new_addr, size_t size,
MEMFLAGS flags, address pc = 0, Thread* thread = NULL) {
if (is_on()) {
+ assert(size > 0, "Sanity check");
record_free(old_addr, flags, thread);
record_malloc(new_addr, size, flags, pc, thread);
}
@@ -208,6 +210,7 @@
// we add a positive offset to arena address, so we can have arena size record
// sorted after arena record
if (is_on() && !UseMallocOnly) {
+ assert(addr != NULL, "Sanity check");
create_memory_record((addr + sizeof(void*)), MemPointerRecord::arena_size_tag(), size,
0, NULL);
}
@@ -217,7 +220,7 @@
static inline void record_virtual_memory_reserve(address addr, size_t size,
address pc = 0, Thread* thread = NULL) {
if (is_on()) {
- assert(size > 0, "reserve szero size");
+ assert(size > 0, "Sanity check");
create_memory_record(addr, MemPointerRecord::virtual_memory_reserve_tag(),
size, pc, thread);
}
@@ -248,6 +251,7 @@
static inline void record_virtual_memory_commit(address addr, size_t size,
address pc = 0, Thread* thread = NULL) {
if (is_on()) {
+ assert(size > 0, "Sanity check");
create_memory_record(addr, MemPointerRecord::virtual_memory_commit_tag(),
size, DEBUG_CALLER_PC, thread);
}
@@ -257,6 +261,7 @@
static inline void record_virtual_memory_uncommit(address addr, size_t size,
Thread* thread = NULL) {
if (is_on()) {
+ assert(size > 0, "Sanity check");
create_memory_record(addr, MemPointerRecord::virtual_memory_uncommit_tag(),
size, DEBUG_CALLER_PC, thread);
}
@@ -266,6 +271,7 @@
static inline void record_virtual_memory_release(address addr, size_t size,
Thread* thread = NULL) {
if (is_on()) {
+ assert(size > 0, "Sanity check");
create_memory_record(addr, MemPointerRecord::virtual_memory_release_tag(),
size, DEBUG_CALLER_PC, thread);
}