< prev index next >

src/share/vm/services/heapDumper.cpp

Print this page
rev 11777 : [mq]: gcinterface.patch


1735 //  [HPROF_GC_CLASS_DUMP]*
1736 //  [HPROF_HEAP_DUMP_SEGMENT]*
1737 //  HPROF_HEAP_DUMP_END
1738 //
1739 // The HPROF_TRACE records represent the stack traces where the heap dump
1740 // is generated and a "dummy trace" record which does not include
1741 // any frames. The dummy trace record is used to be referenced as the
1742 // unknown object alloc site.
1743 //
1744 // Each HPROF_HEAP_DUMP_SEGMENT record has a length followed by sub-records.
1745 // To allow the heap dump be generated in a single pass we remember the position
1746 // of the dump length and fix it up after all sub-records have been written.
1747 // To generate the sub-records we iterate over the heap, writing
1748 // HPROF_GC_INSTANCE_DUMP, HPROF_GC_OBJ_ARRAY_DUMP, and HPROF_GC_PRIM_ARRAY_DUMP
1749 // records as we go. Once that is done we write records for some of the GC
1750 // roots.
1751 
1752 void VM_HeapDumper::doit() {
1753 
1754   HandleMark hm;
1755   CollectedHeap* ch = Universe::heap();
1756 
1757   ch->ensure_parsability(false); // must happen, even if collection does
1758                                  // not happen (e.g. due to GCLocker)
1759 
1760   if (_gc_before_heap_dump) {
1761     if (GCLocker::is_active()) {
1762       warning("GC locker is held; pre-heapdump GC was skipped");
1763     } else {
1764       ch->collect_as_vm_thread(GCCause::_heap_dump);
1765     }
1766   }
1767 
1768   // At this point we should be the only dumper active, so
1769   // the following should be safe.
1770   set_global_dumper();
1771   set_global_writer();
1772 
1773   // Write the file header - we always use 1.0.2
1774   size_t used = ch->used();
1775   const char* header = "JAVA PROFILE 1.0.2";


1790 
1791   // write HPROF_FRAME and HPROF_TRACE records
1792   // this must be called after _klass_map is built when iterating the classes above.
1793   dump_stack_traces();
1794 
1795   // write HPROF_HEAP_DUMP_SEGMENT
1796   DumperSupport::write_dump_header(writer());
1797 
1798   // Writes HPROF_GC_CLASS_DUMP records
1799   ClassLoaderDataGraph::classes_do(&do_class_dump);
1800   Universe::basic_type_classes_do(&do_basic_type_array_class_dump);
1801   check_segment_length();
1802 
1803   // writes HPROF_GC_INSTANCE_DUMP records.
1804   // After each sub-record is written check_segment_length will be invoked
1805   // to check if the current segment exceeds a threshold. If so, a new
1806   // segment is started.
1807   // The HPROF_GC_CLASS_DUMP and HPROF_GC_INSTANCE_DUMP are the vast bulk
1808   // of the heap dump.
1809   HeapObjectDumper obj_dumper(this, writer());
1810   Universe::heap()->safe_object_iterate(&obj_dumper);
1811 
1812   // HPROF_GC_ROOT_THREAD_OBJ + frames + jni locals
1813   do_threads();
1814   check_segment_length();
1815 
1816   // HPROF_GC_ROOT_MONITOR_USED
1817   MonitorUsedDumper mon_dumper(writer());
1818   ObjectSynchronizer::oops_do(&mon_dumper);
1819   check_segment_length();
1820 
1821   // HPROF_GC_ROOT_JNI_GLOBAL
1822   JNIGlobalsDumper jni_dumper(writer());
1823   JNIHandles::oops_do(&jni_dumper);
1824   check_segment_length();
1825 
1826   // HPROF_GC_ROOT_STICKY_CLASS
1827   StickyClassDumper class_dumper(writer());
1828   SystemDictionary::always_strong_classes_do(&class_dumper);
1829 
1830   // fixes up the length of the dump record and writes the HPROF_HEAP_DUMP_END record.




1735 //  [HPROF_GC_CLASS_DUMP]*
1736 //  [HPROF_HEAP_DUMP_SEGMENT]*
1737 //  HPROF_HEAP_DUMP_END
1738 //
1739 // The HPROF_TRACE records represent the stack traces where the heap dump
1740 // is generated and a "dummy trace" record which does not include
1741 // any frames. The dummy trace record is used to be referenced as the
1742 // unknown object alloc site.
1743 //
1744 // Each HPROF_HEAP_DUMP_SEGMENT record has a length followed by sub-records.
1745 // To allow the heap dump be generated in a single pass we remember the position
1746 // of the dump length and fix it up after all sub-records have been written.
1747 // To generate the sub-records we iterate over the heap, writing
1748 // HPROF_GC_INSTANCE_DUMP, HPROF_GC_OBJ_ARRAY_DUMP, and HPROF_GC_PRIM_ARRAY_DUMP
1749 // records as we go. Once that is done we write records for some of the GC
1750 // roots.
1751 
1752 void VM_HeapDumper::doit() {
1753 
1754   HandleMark hm;
1755   CollectedHeap* ch = GC::gc()->heap();
1756 
1757   ch->ensure_parsability(false); // must happen, even if collection does
1758                                  // not happen (e.g. due to GCLocker)
1759 
1760   if (_gc_before_heap_dump) {
1761     if (GCLocker::is_active()) {
1762       warning("GC locker is held; pre-heapdump GC was skipped");
1763     } else {
1764       ch->collect_as_vm_thread(GCCause::_heap_dump);
1765     }
1766   }
1767 
1768   // At this point we should be the only dumper active, so
1769   // the following should be safe.
1770   set_global_dumper();
1771   set_global_writer();
1772 
1773   // Write the file header - we always use 1.0.2
1774   size_t used = ch->used();
1775   const char* header = "JAVA PROFILE 1.0.2";


1790 
1791   // write HPROF_FRAME and HPROF_TRACE records
1792   // this must be called after _klass_map is built when iterating the classes above.
1793   dump_stack_traces();
1794 
1795   // write HPROF_HEAP_DUMP_SEGMENT
1796   DumperSupport::write_dump_header(writer());
1797 
1798   // Writes HPROF_GC_CLASS_DUMP records
1799   ClassLoaderDataGraph::classes_do(&do_class_dump);
1800   Universe::basic_type_classes_do(&do_basic_type_array_class_dump);
1801   check_segment_length();
1802 
1803   // writes HPROF_GC_INSTANCE_DUMP records.
1804   // After each sub-record is written check_segment_length will be invoked
1805   // to check if the current segment exceeds a threshold. If so, a new
1806   // segment is started.
1807   // The HPROF_GC_CLASS_DUMP and HPROF_GC_INSTANCE_DUMP are the vast bulk
1808   // of the heap dump.
1809   HeapObjectDumper obj_dumper(this, writer());
1810   GC::gc()->heap()->safe_object_iterate(&obj_dumper);
1811 
1812   // HPROF_GC_ROOT_THREAD_OBJ + frames + jni locals
1813   do_threads();
1814   check_segment_length();
1815 
1816   // HPROF_GC_ROOT_MONITOR_USED
1817   MonitorUsedDumper mon_dumper(writer());
1818   ObjectSynchronizer::oops_do(&mon_dumper);
1819   check_segment_length();
1820 
1821   // HPROF_GC_ROOT_JNI_GLOBAL
1822   JNIGlobalsDumper jni_dumper(writer());
1823   JNIHandles::oops_do(&jni_dumper);
1824   check_segment_length();
1825 
1826   // HPROF_GC_ROOT_STICKY_CLASS
1827   StickyClassDumper class_dumper(writer());
1828   SystemDictionary::always_strong_classes_do(&class_dumper);
1829 
1830   // fixes up the length of the dump record and writes the HPROF_HEAP_DUMP_END record.


< prev index next >