28 #include "classfile/vmSymbols.hpp"
29 #include "gc/shared/gcLocker.inline.hpp"
30 #include "gc/shared/genCollectedHeap.hpp"
31 #include "gc/shared/vmGCOperations.hpp"
32 #include "memory/resourceArea.hpp"
33 #include "memory/universe.hpp"
34 #include "oops/objArrayKlass.hpp"
35 #include "oops/objArrayOop.inline.hpp"
36 #include "oops/oop.inline.hpp"
37 #include "runtime/javaCalls.hpp"
38 #include "runtime/jniHandles.hpp"
39 #include "runtime/os.hpp"
40 #include "runtime/reflectionUtils.hpp"
41 #include "runtime/vframe.hpp"
42 #include "runtime/vmThread.hpp"
43 #include "runtime/vm_operations.hpp"
44 #include "services/heapDumper.hpp"
45 #include "services/threadService.hpp"
46 #include "utilities/macros.hpp"
47 #include "utilities/ostream.hpp"
48 #if INCLUDE_ALL_GCS
49 #include "gc/parallel/parallelScavengeHeap.hpp"
50 #endif // INCLUDE_ALL_GCS
51
52 /*
53 * HPROF binary format - description copied from:
54 * src/share/demo/jvmti/hprof/hprof_io.c
55 *
56 *
57 * header "JAVA PROFILE 1.0.2" (0-terminated)
58 *
59 * u4 size of identifiers. Identifiers are used to represent
60 * UTF8 strings, objects, stack traces, etc. They usually
61 * have the same size as host pointers. For example, on
62 * Solaris and Win32, the size is 4.
63 * u4 high word
64 * u4 low word number of milliseconds since 0:00 GMT, 1/1/70
65 * [record]* a sequence of records.
66 *
67 *
68 * Record format:
69 *
70 * u1 a TAG denoting the type of the 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 = 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.
|
28 #include "classfile/vmSymbols.hpp"
29 #include "gc/shared/gcLocker.inline.hpp"
30 #include "gc/shared/genCollectedHeap.hpp"
31 #include "gc/shared/vmGCOperations.hpp"
32 #include "memory/resourceArea.hpp"
33 #include "memory/universe.hpp"
34 #include "oops/objArrayKlass.hpp"
35 #include "oops/objArrayOop.inline.hpp"
36 #include "oops/oop.inline.hpp"
37 #include "runtime/javaCalls.hpp"
38 #include "runtime/jniHandles.hpp"
39 #include "runtime/os.hpp"
40 #include "runtime/reflectionUtils.hpp"
41 #include "runtime/vframe.hpp"
42 #include "runtime/vmThread.hpp"
43 #include "runtime/vm_operations.hpp"
44 #include "services/heapDumper.hpp"
45 #include "services/threadService.hpp"
46 #include "utilities/macros.hpp"
47 #include "utilities/ostream.hpp"
48
49 /*
50 * HPROF binary format - description copied from:
51 * src/share/demo/jvmti/hprof/hprof_io.c
52 *
53 *
54 * header "JAVA PROFILE 1.0.2" (0-terminated)
55 *
56 * u4 size of identifiers. Identifiers are used to represent
57 * UTF8 strings, objects, stack traces, etc. They usually
58 * have the same size as host pointers. For example, on
59 * Solaris and Win32, the size is 4.
60 * u4 high word
61 * u4 low word number of milliseconds since 0:00 GMT, 1/1/70
62 * [record]* a sequence of records.
63 *
64 *
65 * Record format:
66 *
67 * u1 a TAG denoting the type of the record
1732 // [HPROF_GC_CLASS_DUMP]*
1733 // [HPROF_HEAP_DUMP_SEGMENT]*
1734 // HPROF_HEAP_DUMP_END
1735 //
1736 // The HPROF_TRACE records represent the stack traces where the heap dump
1737 // is generated and a "dummy trace" record which does not include
1738 // any frames. The dummy trace record is used to be referenced as the
1739 // unknown object alloc site.
1740 //
1741 // Each HPROF_HEAP_DUMP_SEGMENT record has a length followed by sub-records.
1742 // To allow the heap dump be generated in a single pass we remember the position
1743 // of the dump length and fix it up after all sub-records have been written.
1744 // To generate the sub-records we iterate over the heap, writing
1745 // HPROF_GC_INSTANCE_DUMP, HPROF_GC_OBJ_ARRAY_DUMP, and HPROF_GC_PRIM_ARRAY_DUMP
1746 // records as we go. Once that is done we write records for some of the GC
1747 // roots.
1748
1749 void VM_HeapDumper::doit() {
1750
1751 HandleMark hm;
1752 CollectedHeap* ch = GC::gc()->heap();
1753
1754 ch->ensure_parsability(false); // must happen, even if collection does
1755 // not happen (e.g. due to GCLocker)
1756
1757 if (_gc_before_heap_dump) {
1758 if (GCLocker::is_active()) {
1759 warning("GC locker is held; pre-heapdump GC was skipped");
1760 } else {
1761 ch->collect_as_vm_thread(GCCause::_heap_dump);
1762 }
1763 }
1764
1765 // At this point we should be the only dumper active, so
1766 // the following should be safe.
1767 set_global_dumper();
1768 set_global_writer();
1769
1770 // Write the file header - we always use 1.0.2
1771 size_t used = ch->used();
1772 const char* header = "JAVA PROFILE 1.0.2";
1787
1788 // write HPROF_FRAME and HPROF_TRACE records
1789 // this must be called after _klass_map is built when iterating the classes above.
1790 dump_stack_traces();
1791
1792 // write HPROF_HEAP_DUMP_SEGMENT
1793 DumperSupport::write_dump_header(writer());
1794
1795 // Writes HPROF_GC_CLASS_DUMP records
1796 ClassLoaderDataGraph::classes_do(&do_class_dump);
1797 Universe::basic_type_classes_do(&do_basic_type_array_class_dump);
1798 check_segment_length();
1799
1800 // writes HPROF_GC_INSTANCE_DUMP records.
1801 // After each sub-record is written check_segment_length will be invoked
1802 // to check if the current segment exceeds a threshold. If so, a new
1803 // segment is started.
1804 // The HPROF_GC_CLASS_DUMP and HPROF_GC_INSTANCE_DUMP are the vast bulk
1805 // of the heap dump.
1806 HeapObjectDumper obj_dumper(this, writer());
1807 GC::gc()->heap()->safe_object_iterate(&obj_dumper);
1808
1809 // HPROF_GC_ROOT_THREAD_OBJ + frames + jni locals
1810 do_threads();
1811 check_segment_length();
1812
1813 // HPROF_GC_ROOT_MONITOR_USED
1814 MonitorUsedDumper mon_dumper(writer());
1815 ObjectSynchronizer::oops_do(&mon_dumper);
1816 check_segment_length();
1817
1818 // HPROF_GC_ROOT_JNI_GLOBAL
1819 JNIGlobalsDumper jni_dumper(writer());
1820 JNIHandles::oops_do(&jni_dumper);
1821 check_segment_length();
1822
1823 // HPROF_GC_ROOT_STICKY_CLASS
1824 StickyClassDumper class_dumper(writer());
1825 SystemDictionary::always_strong_classes_do(&class_dumper);
1826
1827 // fixes up the length of the dump record and writes the HPROF_HEAP_DUMP_END record.
|