Mercurial > hg > graal-compiler
comparison src/share/vm/gc_interface/collectedHeap.cpp @ 10405:f2110083203d
8005849: JEP 167: Event-Based JVM Tracing
Reviewed-by: acorn, coleenp, sla
Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
author | sla |
---|---|
date | Mon, 10 Jun 2013 11:30:51 +0200 |
parents | f34d701e952e |
children | 27c53c9f3a7e |
comparison
equal
deleted
inserted
replaced
10404:d0add7016434 | 10405:f2110083203d |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 #include "precompiled.hpp" | 25 #include "precompiled.hpp" |
26 #include "classfile/systemDictionary.hpp" | 26 #include "classfile/systemDictionary.hpp" |
27 #include "gc_implementation/shared/gcHeapSummary.hpp" | |
28 #include "gc_implementation/shared/gcTrace.hpp" | |
29 #include "gc_implementation/shared/gcTraceTime.hpp" | |
30 #include "gc_implementation/shared/gcWhen.hpp" | |
27 #include "gc_implementation/shared/vmGCOperations.hpp" | 31 #include "gc_implementation/shared/vmGCOperations.hpp" |
32 #include "gc_interface/allocTracer.hpp" | |
28 #include "gc_interface/collectedHeap.hpp" | 33 #include "gc_interface/collectedHeap.hpp" |
29 #include "gc_interface/collectedHeap.inline.hpp" | 34 #include "gc_interface/collectedHeap.inline.hpp" |
35 #include "memory/metaspace.hpp" | |
30 #include "oops/oop.inline.hpp" | 36 #include "oops/oop.inline.hpp" |
31 #include "oops/instanceMirrorKlass.hpp" | 37 #include "oops/instanceMirrorKlass.hpp" |
32 #include "runtime/init.hpp" | 38 #include "runtime/init.hpp" |
33 #include "runtime/thread.inline.hpp" | 39 #include "runtime/thread.inline.hpp" |
34 #include "services/heapDumper.hpp" | 40 #include "services/heapDumper.hpp" |
63 } else { | 69 } else { |
64 Universe::print_heap_after_gc(&st, true); | 70 Universe::print_heap_after_gc(&st, true); |
65 } | 71 } |
66 } | 72 } |
67 | 73 |
74 VirtualSpaceSummary CollectedHeap::create_heap_space_summary() { | |
75 size_t capacity_in_words = capacity() / HeapWordSize; | |
76 | |
77 return VirtualSpaceSummary( | |
78 reserved_region().start(), reserved_region().start() + capacity_in_words, reserved_region().end()); | |
79 } | |
80 | |
81 GCHeapSummary CollectedHeap::create_heap_summary() { | |
82 VirtualSpaceSummary heap_space = create_heap_space_summary(); | |
83 return GCHeapSummary(heap_space, used()); | |
84 } | |
85 | |
86 MetaspaceSummary CollectedHeap::create_metaspace_summary() { | |
87 const MetaspaceSizes meta_space( | |
88 0, /*MetaspaceAux::capacity_in_bytes(),*/ | |
89 0, /*MetaspaceAux::used_in_bytes(),*/ | |
90 MetaspaceAux::reserved_in_bytes()); | |
91 const MetaspaceSizes data_space( | |
92 0, /*MetaspaceAux::capacity_in_bytes(Metaspace::NonClassType),*/ | |
93 0, /*MetaspaceAux::used_in_bytes(Metaspace::NonClassType),*/ | |
94 MetaspaceAux::reserved_in_bytes(Metaspace::NonClassType)); | |
95 const MetaspaceSizes class_space( | |
96 0, /*MetaspaceAux::capacity_in_bytes(Metaspace::ClassType),*/ | |
97 0, /*MetaspaceAux::used_in_bytes(Metaspace::ClassType),*/ | |
98 MetaspaceAux::reserved_in_bytes(Metaspace::ClassType)); | |
99 | |
100 return MetaspaceSummary(meta_space, data_space, class_space); | |
101 } | |
102 | |
103 void CollectedHeap::print_heap_before_gc() { | |
104 if (PrintHeapAtGC) { | |
105 Universe::print_heap_before_gc(); | |
106 } | |
107 if (_gc_heap_log != NULL) { | |
108 _gc_heap_log->log_heap_before(); | |
109 } | |
110 } | |
111 | |
112 void CollectedHeap::print_heap_after_gc() { | |
113 if (PrintHeapAtGC) { | |
114 Universe::print_heap_after_gc(); | |
115 } | |
116 if (_gc_heap_log != NULL) { | |
117 _gc_heap_log->log_heap_after(); | |
118 } | |
119 } | |
120 | |
121 void CollectedHeap::trace_heap(GCWhen::Type when, GCTracer* gc_tracer) { | |
122 const GCHeapSummary& heap_summary = create_heap_summary(); | |
123 const MetaspaceSummary& metaspace_summary = create_metaspace_summary(); | |
124 gc_tracer->report_gc_heap_summary(when, heap_summary, metaspace_summary); | |
125 } | |
126 | |
127 void CollectedHeap::trace_heap_before_gc(GCTracer* gc_tracer) { | |
128 trace_heap(GCWhen::BeforeGC, gc_tracer); | |
129 } | |
130 | |
131 void CollectedHeap::trace_heap_after_gc(GCTracer* gc_tracer) { | |
132 trace_heap(GCWhen::AfterGC, gc_tracer); | |
133 } | |
134 | |
68 // Memory state functions. | 135 // Memory state functions. |
69 | 136 |
70 | 137 |
71 CollectedHeap::CollectedHeap() : _n_par_threads(0) | 138 CollectedHeap::CollectedHeap() : _n_par_threads(0) |
72 | |
73 { | 139 { |
74 const size_t max_len = size_t(arrayOopDesc::max_array_length(T_INT)); | 140 const size_t max_len = size_t(arrayOopDesc::max_array_length(T_INT)); |
75 const size_t elements_per_word = HeapWordSize / sizeof(jint); | 141 const size_t elements_per_word = HeapWordSize / sizeof(jint); |
76 _filler_array_max_size = align_object_size(filler_array_hdr_size() + | 142 _filler_array_max_size = align_object_size(filler_array_hdr_size() + |
77 max_len / elements_per_word); | 143 max_len / elements_per_word); |
183 thread->check_for_valid_safepoint_state(true); | 249 thread->check_for_valid_safepoint_state(true); |
184 } | 250 } |
185 } | 251 } |
186 #endif | 252 #endif |
187 | 253 |
188 HeapWord* CollectedHeap::allocate_from_tlab_slow(Thread* thread, size_t size) { | 254 HeapWord* CollectedHeap::allocate_from_tlab_slow(KlassHandle klass, Thread* thread, size_t size) { |
189 | 255 |
190 // Retain tlab and allocate object in shared space if | 256 // Retain tlab and allocate object in shared space if |
191 // the amount free in the tlab is too large to discard. | 257 // the amount free in the tlab is too large to discard. |
192 if (thread->tlab().free() > thread->tlab().refill_waste_limit()) { | 258 if (thread->tlab().free() > thread->tlab().refill_waste_limit()) { |
193 thread->tlab().record_slow_allocation(size); | 259 thread->tlab().record_slow_allocation(size); |
207 // Allocate a new TLAB... | 273 // Allocate a new TLAB... |
208 HeapWord* obj = Universe::heap()->allocate_new_tlab(new_tlab_size); | 274 HeapWord* obj = Universe::heap()->allocate_new_tlab(new_tlab_size); |
209 if (obj == NULL) { | 275 if (obj == NULL) { |
210 return NULL; | 276 return NULL; |
211 } | 277 } |
278 | |
279 AllocTracer::send_allocation_in_new_tlab_event(klass, new_tlab_size * HeapWordSize, size * HeapWordSize); | |
280 | |
212 if (ZeroTLAB) { | 281 if (ZeroTLAB) { |
213 // ..and clear it. | 282 // ..and clear it. |
214 Copy::zero_to_words(obj, new_tlab_size); | 283 Copy::zero_to_words(obj, new_tlab_size); |
215 } else { | 284 } else { |
216 // ...and zap just allocated object. | 285 // ...and zap just allocated object. |
456 | 525 |
457 ThreadLocalAllocBuffer::resize_all_tlabs(); | 526 ThreadLocalAllocBuffer::resize_all_tlabs(); |
458 } | 527 } |
459 } | 528 } |
460 | 529 |
461 void CollectedHeap::pre_full_gc_dump() { | 530 void CollectedHeap::pre_full_gc_dump(GCTimer* timer) { |
462 if (HeapDumpBeforeFullGC) { | 531 if (HeapDumpBeforeFullGC) { |
463 TraceTime tt("Heap Dump (before full gc): ", PrintGCDetails, false, gclog_or_tty); | 532 GCTraceTime tt("Heap Dump (before full gc): ", PrintGCDetails, false, timer); |
464 // We are doing a "major" collection and a heap dump before | 533 // We are doing a "major" collection and a heap dump before |
465 // major collection has been requested. | 534 // major collection has been requested. |
466 HeapDumper::dump_heap(); | 535 HeapDumper::dump_heap(); |
467 } | 536 } |
468 if (PrintClassHistogramBeforeFullGC) { | 537 if (PrintClassHistogramBeforeFullGC) { |
469 TraceTime tt("Class Histogram (before full gc): ", PrintGCDetails, true, gclog_or_tty); | 538 GCTraceTime tt("Class Histogram (before full gc): ", PrintGCDetails, true, timer); |
470 VM_GC_HeapInspection inspector(gclog_or_tty, false /* ! full gc */, false /* ! prologue */); | 539 VM_GC_HeapInspection inspector(gclog_or_tty, false /* ! full gc */); |
471 inspector.doit(); | 540 inspector.doit(); |
472 } | 541 } |
473 } | 542 } |
474 | 543 |
475 void CollectedHeap::post_full_gc_dump() { | 544 void CollectedHeap::post_full_gc_dump(GCTimer* timer) { |
476 if (HeapDumpAfterFullGC) { | 545 if (HeapDumpAfterFullGC) { |
477 TraceTime tt("Heap Dump (after full gc): ", PrintGCDetails, false, gclog_or_tty); | 546 GCTraceTime tt("Heap Dump (after full gc): ", PrintGCDetails, false, timer); |
478 HeapDumper::dump_heap(); | 547 HeapDumper::dump_heap(); |
479 } | 548 } |
480 if (PrintClassHistogramAfterFullGC) { | 549 if (PrintClassHistogramAfterFullGC) { |
481 TraceTime tt("Class Histogram (after full gc): ", PrintGCDetails, true, gclog_or_tty); | 550 GCTraceTime tt("Class Histogram (after full gc): ", PrintGCDetails, true, timer); |
482 VM_GC_HeapInspection inspector(gclog_or_tty, false /* ! full gc */, false /* ! prologue */); | 551 VM_GC_HeapInspection inspector(gclog_or_tty, false /* ! full gc */); |
483 inspector.doit(); | 552 inspector.doit(); |
484 } | 553 } |
485 } | 554 } |
486 | 555 |
487 oop CollectedHeap::Class_obj_allocate(KlassHandle klass, int size, KlassHandle real_klass, TRAPS) { | 556 oop CollectedHeap::Class_obj_allocate(KlassHandle klass, int size, KlassHandle real_klass, TRAPS) { |
488 debug_only(check_for_valid_allocation_state()); | 557 debug_only(check_for_valid_allocation_state()); |
489 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); | 558 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
490 assert(size >= 0, "int won't convert to size_t"); | 559 assert(size >= 0, "int won't convert to size_t"); |
491 HeapWord* obj; | 560 HeapWord* obj; |
492 assert(ScavengeRootsInCode > 0, "must be"); | 561 assert(ScavengeRootsInCode > 0, "must be"); |
493 obj = common_mem_allocate_init(size, CHECK_NULL); | 562 obj = common_mem_allocate_init(real_klass, size, CHECK_NULL); |
494 post_allocation_setup_common(klass, obj); | 563 post_allocation_setup_common(klass, obj); |
495 assert(Universe::is_bootstrapping() || | 564 assert(Universe::is_bootstrapping() || |
496 !((oop)obj)->is_array(), "must not be an array"); | 565 !((oop)obj)->is_array(), "must not be an array"); |
497 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); | 566 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); |
498 oop mirror = (oop)obj; | 567 oop mirror = (oop)obj; |