22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "jvm.h"
27 #include "classfile/symbolTable.hpp"
28 #include "classfile/systemDictionary.hpp"
29 #include "classfile/vmSymbols.hpp"
30 #include "gc/shared/gcLocker.inline.hpp"
31 #include "gc/shared/genCollectedHeap.hpp"
32 #include "gc/shared/vmGCOperations.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "memory/universe.hpp"
35 #include "oops/objArrayKlass.hpp"
36 #include "oops/objArrayOop.inline.hpp"
37 #include "oops/oop.inline.hpp"
38 #include "runtime/javaCalls.hpp"
39 #include "runtime/jniHandles.hpp"
40 #include "runtime/os.hpp"
41 #include "runtime/reflectionUtils.hpp"
42 #include "runtime/vframe.hpp"
43 #include "runtime/vmThread.hpp"
44 #include "runtime/vm_operations.hpp"
45 #include "services/heapDumper.hpp"
46 #include "services/threadService.hpp"
47 #include "utilities/macros.hpp"
48 #include "utilities/ostream.hpp"
49 #if INCLUDE_ALL_GCS
50 #include "gc/parallel/parallelScavengeHeap.hpp"
51 #endif // INCLUDE_ALL_GCS
52
53 /*
54 * HPROF binary format - description copied from:
55 * src/share/demo/jvmti/hprof/hprof_io.c
56 *
57 *
58 * header "JAVA PROFILE 1.0.2" (0-terminated)
59 *
60 * u4 size of identifiers. Identifiers are used to represent
61 * UTF8 strings, objects, stack traces, etc. They usually
1878 StickyClassDumper class_dumper(writer());
1879 ClassLoaderData::the_null_class_loader_data()->classes_do(&class_dumper);
1880
1881 // fixes up the length of the dump record and writes the HPROF_HEAP_DUMP_END record.
1882 DumperSupport::end_of_dump(writer());
1883
1884 // Now we clear the global variables, so that a future dumper might run.
1885 clear_global_dumper();
1886 clear_global_writer();
1887 }
1888
1889 void VM_HeapDumper::dump_stack_traces() {
1890 // write a HPROF_TRACE record without any frames to be referenced as object alloc sites
1891 DumperSupport::write_header(writer(), HPROF_TRACE, 3*sizeof(u4));
1892 writer()->write_u4((u4) STACK_TRACE_ID);
1893 writer()->write_u4(0); // thread number
1894 writer()->write_u4(0); // frame count
1895
1896 _stack_traces = NEW_C_HEAP_ARRAY(ThreadStackTrace*, Threads::number_of_threads(), mtInternal);
1897 int frame_serial_num = 0;
1898 for (JavaThread* thread = Threads::first(); thread != NULL ; thread = thread->next()) {
1899 oop threadObj = thread->threadObj();
1900 if (threadObj != NULL && !thread->is_exiting() && !thread->is_hidden_from_external_view()) {
1901 // dump thread stack trace
1902 ThreadStackTrace* stack_trace = new ThreadStackTrace(thread, false);
1903 stack_trace->dump_stack_at_safepoint(-1);
1904 _stack_traces[_num_threads++] = stack_trace;
1905
1906 // write HPROF_FRAME records for this thread's stack trace
1907 int depth = stack_trace->get_stack_depth();
1908 int thread_frame_start = frame_serial_num;
1909 int extra_frames = 0;
1910 // write fake frame that makes it look like the thread, which caused OOME,
1911 // is in the OutOfMemoryError zero-parameter constructor
1912 if (thread == _oome_thread && _oome_constructor != NULL) {
1913 int oome_serial_num = _klass_map->find(_oome_constructor->method_holder());
1914 // the class serial number starts from 1
1915 assert(oome_serial_num > 0, "OutOfMemoryError class not found");
1916 DumperSupport::dump_stack_frame(writer(), ++frame_serial_num, oome_serial_num,
1917 _oome_constructor, 0);
1918 extra_frames++;
|
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "jvm.h"
27 #include "classfile/symbolTable.hpp"
28 #include "classfile/systemDictionary.hpp"
29 #include "classfile/vmSymbols.hpp"
30 #include "gc/shared/gcLocker.inline.hpp"
31 #include "gc/shared/genCollectedHeap.hpp"
32 #include "gc/shared/vmGCOperations.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "memory/universe.hpp"
35 #include "oops/objArrayKlass.hpp"
36 #include "oops/objArrayOop.inline.hpp"
37 #include "oops/oop.inline.hpp"
38 #include "runtime/javaCalls.hpp"
39 #include "runtime/jniHandles.hpp"
40 #include "runtime/os.hpp"
41 #include "runtime/reflectionUtils.hpp"
42 #include "runtime/thread.inline.hpp"
43 #include "runtime/threadSMR.hpp"
44 #include "runtime/vframe.hpp"
45 #include "runtime/vmThread.hpp"
46 #include "runtime/vm_operations.hpp"
47 #include "services/heapDumper.hpp"
48 #include "services/threadService.hpp"
49 #include "utilities/macros.hpp"
50 #include "utilities/ostream.hpp"
51 #if INCLUDE_ALL_GCS
52 #include "gc/parallel/parallelScavengeHeap.hpp"
53 #endif // INCLUDE_ALL_GCS
54
55 /*
56 * HPROF binary format - description copied from:
57 * src/share/demo/jvmti/hprof/hprof_io.c
58 *
59 *
60 * header "JAVA PROFILE 1.0.2" (0-terminated)
61 *
62 * u4 size of identifiers. Identifiers are used to represent
63 * UTF8 strings, objects, stack traces, etc. They usually
1880 StickyClassDumper class_dumper(writer());
1881 ClassLoaderData::the_null_class_loader_data()->classes_do(&class_dumper);
1882
1883 // fixes up the length of the dump record and writes the HPROF_HEAP_DUMP_END record.
1884 DumperSupport::end_of_dump(writer());
1885
1886 // Now we clear the global variables, so that a future dumper might run.
1887 clear_global_dumper();
1888 clear_global_writer();
1889 }
1890
1891 void VM_HeapDumper::dump_stack_traces() {
1892 // write a HPROF_TRACE record without any frames to be referenced as object alloc sites
1893 DumperSupport::write_header(writer(), HPROF_TRACE, 3*sizeof(u4));
1894 writer()->write_u4((u4) STACK_TRACE_ID);
1895 writer()->write_u4(0); // thread number
1896 writer()->write_u4(0); // frame count
1897
1898 _stack_traces = NEW_C_HEAP_ARRAY(ThreadStackTrace*, Threads::number_of_threads(), mtInternal);
1899 int frame_serial_num = 0;
1900 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) {
1901 oop threadObj = thread->threadObj();
1902 if (threadObj != NULL && !thread->is_exiting() && !thread->is_hidden_from_external_view()) {
1903 // dump thread stack trace
1904 ThreadStackTrace* stack_trace = new ThreadStackTrace(thread, false);
1905 stack_trace->dump_stack_at_safepoint(-1);
1906 _stack_traces[_num_threads++] = stack_trace;
1907
1908 // write HPROF_FRAME records for this thread's stack trace
1909 int depth = stack_trace->get_stack_depth();
1910 int thread_frame_start = frame_serial_num;
1911 int extra_frames = 0;
1912 // write fake frame that makes it look like the thread, which caused OOME,
1913 // is in the OutOfMemoryError zero-parameter constructor
1914 if (thread == _oome_thread && _oome_constructor != NULL) {
1915 int oome_serial_num = _klass_map->find(_oome_constructor->method_holder());
1916 // the class serial number starts from 1
1917 assert(oome_serial_num > 0, "OutOfMemoryError class not found");
1918 DumperSupport::dump_stack_frame(writer(), ++frame_serial_num, oome_serial_num,
1919 _oome_constructor, 0);
1920 extra_frames++;
|