< prev index next >

src/share/vm/gc_implementation/shenandoah/shenandoahUtils.cpp

Print this page
rev 10498 : [backport] Move heuristics from ShCollectorPolicy to ShHeap
rev 10546 : [backport] Wrap worker id in thread local worker session
rev 10612 : [backport] Wiring GC events to JFR + Restore heap occupancy in GC logs after JFR changes
rev 10615 : [backport] Wiring heap and metaspace info to JFR


  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #include "precompiled.hpp"
  25 
  26 #include "gc_implementation/shenandoah/shenandoahAllocTracker.hpp"
  27 #include "gc_implementation/shenandoah/shenandoahCollectorPolicy.hpp"
  28 #include "gc_implementation/shenandoah/shenandoahMarkCompact.hpp"
  29 #include "gc_implementation/shenandoah/shenandoahHeap.hpp"

  30 #include "gc_implementation/shenandoah/shenandoahUtils.hpp"
  31 #include "gc_implementation/shenandoah/shenandoahLogging.hpp"

  32 #include "gc_implementation/shared/gcTimer.hpp"


  33 
  34 
  35 ShenandoahGCSession::ShenandoahGCSession() {


  36   ShenandoahHeap* sh = ShenandoahHeap::heap();
  37   _timer = sh->gc_timer();
  38   _timer->register_gc_start();



  39   sh->shenandoahPolicy()->record_cycle_start();

  40   _trace_cycle.initialize(false, sh->gc_cause(),
  41           /* recordGCBeginTime = */       true,
  42           /* recordPreGCUsage = */        true,
  43           /* recordPeakUsage = */         true,
  44           /* recordPostGCUsage = */       true,
  45           /* recordAccumulatedGCTime = */ true,
  46           /* recordGCEndTime = */         true,
  47           /* countCollection = */         true
  48   );
  49 }
  50 
  51 ShenandoahGCSession::~ShenandoahGCSession() {
  52   ShenandoahHeap::heap()->shenandoahPolicy()->record_cycle_end();

  53   _timer->register_gc_end();
  54 }
  55 
  56 ShenandoahGCPauseMark::ShenandoahGCPauseMark(SvcGCMarker::reason_type type) :
  57         _svc_gc_mark(type), _is_gc_active_mark() {
  58   ShenandoahHeap* sh = ShenandoahHeap::heap();
  59   sh->shenandoahPolicy()->record_gc_start();
  60 



  61   _trace_pause.initialize(true, sh->gc_cause(),
  62           /* recordGCBeginTime = */       true,
  63           /* recordPreGCUsage = */        false,
  64           /* recordPeakUsage = */         false,
  65           /* recordPostGCUsage = */       false,
  66           /* recordAccumulatedGCTime = */ true,
  67           /* recordGCEndTime = */         true,
  68           /* countCollection = */         true
  69   );


  70 }
  71 
  72 ShenandoahGCPauseMark::~ShenandoahGCPauseMark() {
  73   ShenandoahHeap* sh = ShenandoahHeap::heap();
  74   sh->shenandoahPolicy()->record_gc_end();

  75 }
  76 
  77 ShenandoahGCPhase::ShenandoahGCPhase(const ShenandoahPhaseTimings::Phase phase) :
  78   _phase(phase) {
  79   ShenandoahHeap::heap()->phase_timings()->record_phase_start(_phase);
  80 }
  81 
  82 ShenandoahGCPhase::~ShenandoahGCPhase() {
  83   ShenandoahHeap::heap()->phase_timings()->record_phase_end(_phase);
  84 }
  85 
  86 ShenandoahAllocTrace::ShenandoahAllocTrace(size_t words_size, ShenandoahHeap::AllocType alloc_type) {
  87   if (ShenandoahAllocationTrace) {
  88     _start = os::elapsedTime();
  89     _size = words_size;
  90     _alloc_type = alloc_type;
  91   } else {
  92     _start = 0;
  93     _size = 0;
  94     _alloc_type = ShenandoahHeap::AllocType(0);
  95   }
  96 }
  97 
  98 ShenandoahAllocTrace::~ShenandoahAllocTrace() {
  99   if (ShenandoahAllocationTrace) {
 100     double stop = os::elapsedTime();
 101     double duration_sec = stop - _start;
 102     double duration_us = duration_sec * 1000000;
 103     ShenandoahAllocTracker* tracker = ShenandoahHeap::heap()->alloc_tracker();
 104     assert(tracker != NULL, "Must be");
 105     tracker->record_alloc_latency(_size, _alloc_type, duration_us);
 106     if (duration_us > ShenandoahAllocationStallThreshold) {
 107       log_warning(gc)("Allocation stall: %.0f us (threshold: " INTX_FORMAT " us)",
 108                       duration_us, ShenandoahAllocationStallThreshold);
 109     }
 110   }
 111 }

















  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #include "precompiled.hpp"
  25 
  26 #include "gc_implementation/shenandoah/shenandoahAllocTracker.hpp"
  27 #include "gc_implementation/shenandoah/shenandoahCollectorPolicy.hpp"
  28 #include "gc_implementation/shenandoah/shenandoahMarkCompact.hpp"
  29 #include "gc_implementation/shenandoah/shenandoahHeap.hpp"
  30 #include "gc_implementation/shenandoah/shenandoahHeuristics.hpp"
  31 #include "gc_implementation/shenandoah/shenandoahUtils.hpp"
  32 #include "gc_implementation/shenandoah/shenandoahLogging.hpp"
  33 #include "gc_interface/gcCause.hpp"
  34 #include "gc_implementation/shared/gcTimer.hpp"
  35 #include "gc_implementation/shared/gcWhen.hpp"
  36 #include "gc_implementation/shared/gcTrace.hpp"
  37 
  38 
  39 ShenandoahGCSession::ShenandoahGCSession(GCCause::Cause cause) :
  40   _timer(ShenandoahHeap::heap()->gc_timer()),
  41   _tracer(ShenandoahHeap::heap()->tracer()) {
  42   ShenandoahHeap* sh = ShenandoahHeap::heap();
  43 
  44   _timer->register_gc_start();
  45   _tracer->report_gc_start(cause, _timer->gc_start());
  46   sh->trace_heap(GCWhen::BeforeGC, _tracer);
  47 
  48   sh->shenandoahPolicy()->record_cycle_start();
  49   sh->heuristics()->record_cycle_start();
  50   _trace_cycle.initialize(false, sh->gc_cause(),
  51           /* recordGCBeginTime = */       true,
  52           /* recordPreGCUsage = */        true,
  53           /* recordPeakUsage = */         true,
  54           /* recordPostGCUsage = */       true,
  55           /* recordAccumulatedGCTime = */ true,
  56           /* recordGCEndTime = */         true,
  57           /* countCollection = */         true
  58   );
  59 }
  60 
  61 ShenandoahGCSession::~ShenandoahGCSession() {
  62   ShenandoahHeap::heap()->heuristics()->record_cycle_end();
  63   _tracer->report_gc_end(_timer->gc_end(), _timer->time_partitions());
  64   _timer->register_gc_end();
  65 }
  66 
  67 ShenandoahGCPauseMark::ShenandoahGCPauseMark(SvcGCMarker::reason_type type) :
  68         _svc_gc_mark(type), _is_gc_active_mark() {
  69   ShenandoahHeap* sh = ShenandoahHeap::heap();

  70 
  71   // FIXME: It seems that JMC throws away level 0 events, which are the Shenandoah
  72   // pause events. Create this pseudo level 0 event to push real events to level 1.
  73   sh->gc_timer()->register_gc_phase_start("Shenandoah", Ticks::now());
  74   _trace_pause.initialize(true, sh->gc_cause(),
  75           /* recordGCBeginTime = */       true,
  76           /* recordPreGCUsage = */        false,
  77           /* recordPeakUsage = */         false,
  78           /* recordPostGCUsage = */       false,
  79           /* recordAccumulatedGCTime = */ true,
  80           /* recordGCEndTime = */         true,
  81           /* countCollection = */         true
  82   );
  83 
  84   sh->heuristics()->record_gc_start();
  85 }
  86 
  87 ShenandoahGCPauseMark::~ShenandoahGCPauseMark() {
  88   ShenandoahHeap* sh = ShenandoahHeap::heap();
  89   sh->gc_timer()->register_gc_phase_end(Ticks::now());
  90   sh->heuristics()->record_gc_end();
  91 }
  92 
  93 ShenandoahGCPhase::ShenandoahGCPhase(const ShenandoahPhaseTimings::Phase phase) :
  94   _phase(phase) {
  95   ShenandoahHeap::heap()->phase_timings()->record_phase_start(_phase);
  96 }
  97 
  98 ShenandoahGCPhase::~ShenandoahGCPhase() {
  99   ShenandoahHeap::heap()->phase_timings()->record_phase_end(_phase);
 100 }
 101 
 102 ShenandoahAllocTrace::ShenandoahAllocTrace(size_t words_size, ShenandoahHeap::AllocType alloc_type) {
 103   if (ShenandoahAllocationTrace) {
 104     _start = os::elapsedTime();
 105     _size = words_size;
 106     _alloc_type = alloc_type;
 107   } else {
 108     _start = 0;
 109     _size = 0;
 110     _alloc_type = ShenandoahHeap::AllocType(0);
 111   }
 112 }
 113 
 114 ShenandoahAllocTrace::~ShenandoahAllocTrace() {
 115   if (ShenandoahAllocationTrace) {
 116     double stop = os::elapsedTime();
 117     double duration_sec = stop - _start;
 118     double duration_us = duration_sec * 1000000;
 119     ShenandoahAllocTracker* tracker = ShenandoahHeap::heap()->alloc_tracker();
 120     assert(tracker != NULL, "Must be");
 121     tracker->record_alloc_latency(_size, _alloc_type, duration_us);
 122     if (duration_us > ShenandoahAllocationStallThreshold) {
 123       log_warning(gc)("Allocation stall: %.0f us (threshold: " INTX_FORMAT " us)",
 124                       duration_us, ShenandoahAllocationStallThreshold);
 125     }
 126   }
 127 }
 128 
 129 ShenandoahWorkerSession::ShenandoahWorkerSession(uint worker_id) {
 130   Thread* thr = Thread::current();
 131   assert(thr->worker_id() == INVALID_WORKER_ID, "Already set");
 132   thr->set_worker_id(worker_id);
 133 }
 134 
 135 ShenandoahWorkerSession::~ShenandoahWorkerSession() {
 136 #ifdef ASSERT
 137   Thread* thr = Thread::current();
 138   assert(thr->worker_id() != INVALID_WORKER_ID, "Must be set");
 139   thr->set_worker_id(INVALID_WORKER_ID);
 140 #endif
 141 }
 142 
< prev index next >