# HG changeset patch # User ghaug # Date 1524817495 -7200 # Fri Apr 27 10:24:55 2018 +0200 # Node ID 8213b7d83de08f62953457dad83a3d9d66aa9a99 # Parent bfba4712d4ffbdb4b8c4e3551440a4f269a2f456 Thread Dump Extension (memory allocation) diff --git a/src/hotspot/share/classfile/klassFactory.cpp b/src/hotspot/share/classfile/klassFactory.cpp --- a/src/hotspot/share/classfile/klassFactory.cpp +++ b/src/hotspot/share/classfile/klassFactory.cpp @@ -193,6 +193,9 @@ ClassFileStream* old_stream = stream; + // increment counter + THREAD->statistic_info().incr_define_class_count(); + // Skip this processing for VM anonymous classes if (host_klass == NULL) { stream = check_class_file_load_hook(stream, diff --git a/src/hotspot/share/runtime/osThread.cpp b/src/hotspot/share/runtime/osThread.cpp --- a/src/hotspot/share/runtime/osThread.cpp +++ b/src/hotspot/share/runtime/osThread.cpp @@ -40,6 +40,18 @@ // Printing void OSThread::print_on(outputStream *st) const { st->print("nid=0x%x ", thread_id()); + +#ifdef _AIX + st->print("ktid=" UINT64_FORMAT " ", kernel_thread_id()); +#endif + +#if defined(LINUX) || defined(BSD) + st->print("pthread-id=0x%lx ", (unsigned long) pthread_id()); +#endif +#if defined(__sun) + st->print("lwp-id=0x%lx ", lwp_id()); +#endif + switch (_state) { case ALLOCATED: st->print("allocated "); break; case INITIALIZED: st->print("initialized "); break; diff --git a/src/hotspot/share/runtime/thread.cpp b/src/hotspot/share/runtime/thread.cpp --- a/src/hotspot/share/runtime/thread.cpp +++ b/src/hotspot/share/runtime/thread.cpp @@ -241,6 +241,9 @@ set_free_handle_block(NULL); set_last_handle_mark(NULL); + _statistic_info.setStartTime(os::javaTimeMillis()); + _statistic_info.setDefineClassCount(0); + // This initial value ==> never claimed. _oops_do_parity = 0; _threads_hazard_ptr = NULL; @@ -879,7 +882,23 @@ if (os::get_native_priority(this, &os_prio) == OS_OK) { st->print("os_prio=%d ", os_prio); } + + if (os::is_thread_cpu_time_supported()) { + st->print("cpu=%.2fms ", + os::thread_cpu_time(const_cast(this), true) / 1000000.0 + ); + st->print("elapsed=%.2fs ", + _statistic_info.getElepsedTime() / 1000.0); + } + + if (is_Java_thread()) { + jlong allocated_bytes = const_cast(this)->cooked_allocated_bytes(); + st->print("allocated=" JLONG_FORMAT "B ", allocated_bytes); + st->print("defined_classes=" INT64_FORMAT " ", _statistic_info.getDefineClassCount()); + } + st->print("tid=" INTPTR_FORMAT " ", p2i(this)); + osthread()->print_on(st); } if (_threads_hazard_ptr != NULL) { diff --git a/src/hotspot/share/runtime/thread.hpp b/src/hotspot/share/runtime/thread.hpp --- a/src/hotspot/share/runtime/thread.hpp +++ b/src/hotspot/share/runtime/thread.hpp @@ -51,6 +51,7 @@ #ifdef ZERO # include "stack_zero.hpp" #endif +#include "runtime/threadStatisticInfo.hpp" class ThreadSafepointState; class ThreadsList; @@ -344,6 +345,8 @@ jlong _allocated_bytes; // Cumulative number of bytes allocated on // the Java heap + ThreadStatisticInfo _statistic_info; // Statistic info about the thread + mutable TRACE_DATA _trace_data; // Thread-local data for tracing int _vm_operation_started_count; // VM_Operation support @@ -522,6 +525,8 @@ void incr_allocated_bytes(jlong size) { _allocated_bytes += size; } inline jlong cooked_allocated_bytes(); + ThreadStatisticInfo& statistic_info() { return _statistic_info; } + TRACE_DEFINE_THREAD_TRACE_DATA_OFFSET; TRACE_DATA* trace_data() const { return &_trace_data; } bool is_trace_suspend() { return (_suspend_flags & _trace_flag) != 0; } diff --git a/src/hotspot/share/runtime/threadStatisticInfo.hpp b/src/hotspot/share/runtime/threadStatisticInfo.hpp new file mode 100644 --- /dev/null +++ b/src/hotspot/share/runtime/threadStatisticInfo.hpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018 SAP SE. 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +class ThreadStatisticInfo { + // The time stamp the thread was started. + uint64_t _start_time_stamp; + uint64_t _define_class_count; + +public: + uint64_t getStartTime() const { return _start_time_stamp; } + void setStartTime(uint64_t timeStamp) { _start_time_stamp = timeStamp; } + uint64_t getDefineClassCount() const { return _define_class_count; } + void setDefineClassCount(uint64_t defineClassCount) { _define_class_count = defineClassCount; } + void incr_define_class_count() { _define_class_count += 1; } + uint64_t getElepsedTime() const { return os::javaTimeMillis() - getStartTime(); } +};