< prev index next >

src/hotspot/share/services/heapDumper.cpp

Print this page

2375 }
2376 
2377 void VM_HeapDumper::dump_stack_traces() {
2378   // write a HPROF_TRACE record without any frames to be referenced as object alloc sites
2379   DumperSupport::write_header(writer(), HPROF_TRACE, 3*sizeof(u4));
2380   writer()->write_u4((u4) STACK_TRACE_ID);
2381   writer()->write_u4(0);                    // thread number
2382   writer()->write_u4(0);                    // frame count
2383 
2384   _stack_traces = NEW_C_HEAP_ARRAY(ThreadStackTrace*, Threads::number_of_threads(), mtInternal);
2385   int frame_serial_num = 0;
2386   for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) {
2387     oop threadObj = thread->threadObj();
2388     if (threadObj != NULL && !thread->is_exiting() && !thread->is_hidden_from_external_view()) {
2389       // dump thread stack trace
2390       Thread* current_thread = Thread::current();
2391       ResourceMark rm(current_thread);
2392       HandleMark hm(current_thread);
2393 
2394       ThreadStackTrace* stack_trace = new ThreadStackTrace(thread, false);
2395       stack_trace->dump_stack_at_safepoint(-1);
2396       _stack_traces[_num_threads++] = stack_trace;
2397 
2398       // write HPROF_FRAME records for this thread's stack trace
2399       int depth = stack_trace->get_stack_depth();
2400       int thread_frame_start = frame_serial_num;
2401       int extra_frames = 0;
2402       // write fake frame that makes it look like the thread, which caused OOME,
2403       // is in the OutOfMemoryError zero-parameter constructor
2404       if (thread == _oome_thread && _oome_constructor != NULL) {
2405         int oome_serial_num = _klass_map->find(_oome_constructor->method_holder());
2406         // the class serial number starts from 1
2407         assert(oome_serial_num > 0, "OutOfMemoryError class not found");
2408         DumperSupport::dump_stack_frame(writer(), ++frame_serial_num, oome_serial_num,
2409                                         _oome_constructor, 0);
2410         extra_frames++;
2411       }
2412       for (int j=0; j < depth; j++) {
2413         StackFrameInfo* frame = stack_trace->stack_frame_at(j);
2414         Method* m = frame->method();
2415         int class_serial_num = _klass_map->find(m->method_holder());

2375 }
2376 
2377 void VM_HeapDumper::dump_stack_traces() {
2378   // write a HPROF_TRACE record without any frames to be referenced as object alloc sites
2379   DumperSupport::write_header(writer(), HPROF_TRACE, 3*sizeof(u4));
2380   writer()->write_u4((u4) STACK_TRACE_ID);
2381   writer()->write_u4(0);                    // thread number
2382   writer()->write_u4(0);                    // frame count
2383 
2384   _stack_traces = NEW_C_HEAP_ARRAY(ThreadStackTrace*, Threads::number_of_threads(), mtInternal);
2385   int frame_serial_num = 0;
2386   for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) {
2387     oop threadObj = thread->threadObj();
2388     if (threadObj != NULL && !thread->is_exiting() && !thread->is_hidden_from_external_view()) {
2389       // dump thread stack trace
2390       Thread* current_thread = Thread::current();
2391       ResourceMark rm(current_thread);
2392       HandleMark hm(current_thread);
2393 
2394       ThreadStackTrace* stack_trace = new ThreadStackTrace(thread, false);
2395       stack_trace->dump_stack_at_safepoint(-1, true);
2396       _stack_traces[_num_threads++] = stack_trace;
2397 
2398       // write HPROF_FRAME records for this thread's stack trace
2399       int depth = stack_trace->get_stack_depth();
2400       int thread_frame_start = frame_serial_num;
2401       int extra_frames = 0;
2402       // write fake frame that makes it look like the thread, which caused OOME,
2403       // is in the OutOfMemoryError zero-parameter constructor
2404       if (thread == _oome_thread && _oome_constructor != NULL) {
2405         int oome_serial_num = _klass_map->find(_oome_constructor->method_holder());
2406         // the class serial number starts from 1
2407         assert(oome_serial_num > 0, "OutOfMemoryError class not found");
2408         DumperSupport::dump_stack_frame(writer(), ++frame_serial_num, oome_serial_num,
2409                                         _oome_constructor, 0);
2410         extra_frames++;
2411       }
2412       for (int j=0; j < depth; j++) {
2413         StackFrameInfo* frame = stack_trace->stack_frame_at(j);
2414         Method* m = frame->method();
2415         int class_serial_num = _klass_map->find(m->method_holder());
< prev index next >