gcTrace.cpp 7.0 KB
Newer Older
S
sla 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

#include "precompiled.hpp"
26
#include "gc_implementation/shared/copyFailedInfo.hpp"
S
sla 已提交
27 28 29
#include "gc_implementation/shared/gcHeapSummary.hpp"
#include "gc_implementation/shared/gcTimer.hpp"
#include "gc_implementation/shared/gcTrace.hpp"
30
#include "gc_implementation/shared/objectCountEventSender.hpp"
S
sla 已提交
31 32
#include "memory/heapInspection.hpp"
#include "memory/referenceProcessorStats.hpp"
33
#include "runtime/os.hpp"
S
sla 已提交
34
#include "utilities/globalDefinitions.hpp"
35
#include "utilities/ticks.inline.hpp"
S
sla 已提交
36 37 38 39 40 41 42 43

#if INCLUDE_ALL_GCS
#include "gc_implementation/g1/evacuationInfo.hpp"
#endif

#define assert_unset_gc_id() assert(_shared_gc_info.id() == SharedGCInfo::UNSET_GCID, "GC already started?")
#define assert_set_gc_id() assert(_shared_gc_info.id() != SharedGCInfo::UNSET_GCID, "GC not started?")

44
static GCId GCTracer_next_gc_id = 0;
S
sla 已提交
45 46 47 48
static GCId create_new_gc_id() {
  return GCTracer_next_gc_id++;
}

49
void GCTracer::report_gc_start_impl(GCCause::Cause cause, const Ticks& timestamp) {
S
sla 已提交
50 51 52 53 54 55 56 57
  assert_unset_gc_id();

  GCId gc_id = create_new_gc_id();
  _shared_gc_info.set_id(gc_id);
  _shared_gc_info.set_cause(cause);
  _shared_gc_info.set_start_timestamp(timestamp);
}

58
void GCTracer::report_gc_start(GCCause::Cause cause, const Ticks& timestamp) {
S
sla 已提交
59 60 61 62 63 64 65 66 67
  assert_unset_gc_id();

  report_gc_start_impl(cause, timestamp);
}

bool GCTracer::has_reported_gc_start() const {
  return _shared_gc_info.id() != SharedGCInfo::UNSET_GCID;
}

68
void GCTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) {
S
sla 已提交
69 70 71 72 73 74 75 76 77 78
  assert_set_gc_id();

  _shared_gc_info.set_sum_of_pauses(time_partitions->sum_of_pauses());
  _shared_gc_info.set_longest_pause(time_partitions->longest_pause());
  _shared_gc_info.set_end_timestamp(timestamp);

  send_phase_events(time_partitions);
  send_garbage_collection_event();
}

79
void GCTracer::report_gc_end(const Ticks& timestamp, TimePartitions* time_partitions) {
S
sla 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
  assert_set_gc_id();

  report_gc_end_impl(timestamp, time_partitions);

  _shared_gc_info.set_id(SharedGCInfo::UNSET_GCID);
}

void GCTracer::report_gc_reference_stats(const ReferenceProcessorStats& rps) const {
  assert_set_gc_id();

  send_reference_stats_event(REF_SOFT, rps.soft_count());
  send_reference_stats_event(REF_WEAK, rps.weak_count());
  send_reference_stats_event(REF_FINAL, rps.final_count());
  send_reference_stats_event(REF_PHANTOM, rps.phantom_count());
}

#if INCLUDE_SERVICES
97 98 99 100
class ObjectCountEventSenderClosure : public KlassInfoClosure {
  const GCId _gc_id;
  const double _size_threshold_percentage;
  const size_t _total_size_in_words;
101
  const Ticks _timestamp;
102 103

 public:
104
  ObjectCountEventSenderClosure(GCId gc_id, size_t total_size_in_words, const Ticks& timestamp) :
105 106
    _gc_id(gc_id),
    _size_threshold_percentage(ObjectCountCutOffPercent / 100),
107 108
    _total_size_in_words(total_size_in_words),
    _timestamp(timestamp)
109 110 111 112
  {}

  virtual void do_cinfo(KlassInfoEntry* entry) {
    if (should_send_event(entry)) {
113
      ObjectCountEventSender::send(entry, _gc_id, _timestamp);
114
    }
S
sla 已提交
115 116
  }

117 118 119 120 121 122
 private:
  bool should_send_event(const KlassInfoEntry* entry) const {
    double percentage_of_heap = ((double) entry->words()) / _total_size_in_words;
    return percentage_of_heap >= _size_threshold_percentage;
  }
};
S
sla 已提交
123 124 125

void GCTracer::report_object_count_after_gc(BoolObjectClosure* is_alive_cl) {
  assert_set_gc_id();
126
  assert(is_alive_cl != NULL, "Must supply function to check liveness");
S
sla 已提交
127

128
  if (ObjectCountEventSender::should_send_event()) {
S
sla 已提交
129 130 131 132 133 134
    ResourceMark rm;

    KlassInfoTable cit(false);
    if (!cit.allocation_failed()) {
      HeapInspection hi(false, false, false, NULL);
      hi.populate_table(&cit, is_alive_cl);
135
      ObjectCountEventSenderClosure event_sender(_shared_gc_info.id(), cit.size_of_instances_in_words(), Ticks::now());
S
sla 已提交
136 137 138 139
      cit.iterate(&event_sender);
    }
  }
}
140
#endif // INCLUDE_SERVICES
S
sla 已提交
141 142 143 144 145 146 147 148

void GCTracer::report_gc_heap_summary(GCWhen::Type when, const GCHeapSummary& heap_summary, const MetaspaceSummary& meta_space_summary) const {
  assert_set_gc_id();

  send_gc_heap_summary_event(when, heap_summary);
  send_meta_space_summary_event(when, meta_space_summary);
}

149
void YoungGCTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) {
S
sla 已提交
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
  assert_set_gc_id();
  assert(_tenuring_threshold != UNSET_TENURING_THRESHOLD, "Tenuring threshold has not been reported");

  GCTracer::report_gc_end_impl(timestamp, time_partitions);
  send_young_gc_event();

  _tenuring_threshold = UNSET_TENURING_THRESHOLD;
}

void YoungGCTracer::report_promotion_failed(const PromotionFailedInfo& pf_info) {
  assert_set_gc_id();

  send_promotion_failed_event(pf_info);
}

void YoungGCTracer::report_tenuring_threshold(const uint tenuring_threshold) {
  _tenuring_threshold = tenuring_threshold;
}

169
void OldGCTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) {
S
sla 已提交
170 171 172 173 174 175
  assert_set_gc_id();

  GCTracer::report_gc_end_impl(timestamp, time_partitions);
  send_old_gc_event();
}

176
void ParallelOldTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) {
S
sla 已提交
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
  assert_set_gc_id();

  OldGCTracer::report_gc_end_impl(timestamp, time_partitions);
  send_parallel_old_event();
}

void ParallelOldTracer::report_dense_prefix(void* dense_prefix) {
  assert_set_gc_id();

  _parallel_old_gc_info.report_dense_prefix(dense_prefix);
}

void OldGCTracer::report_concurrent_mode_failure() {
  assert_set_gc_id();

  send_concurrent_mode_failure_event();
}

#if INCLUDE_ALL_GCS
void G1NewTracer::report_yc_type(G1YCType type) {
  assert_set_gc_id();

  _g1_young_gc_info.set_type(type);
}

202
void G1NewTracer::report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions) {
S
sla 已提交
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
  assert_set_gc_id();

  YoungGCTracer::report_gc_end_impl(timestamp, time_partitions);
  send_g1_young_gc_event();
}

void G1NewTracer::report_evacuation_info(EvacuationInfo* info) {
  assert_set_gc_id();

  send_evacuation_info_event(info);
}

void G1NewTracer::report_evacuation_failed(EvacuationFailedInfo& ef_info) {
  assert_set_gc_id();

  send_evacuation_failed_event(ef_info);
  ef_info.reset();
}
#endif