gcTraceSend.cpp 16.5 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"
A
apetushkov 已提交
26
#include "jfr/jfrEvents.hpp"
S
sla 已提交
27 28 29 30 31
#include "gc_implementation/shared/gcHeapSummary.hpp"
#include "gc_implementation/shared/gcTimer.hpp"
#include "gc_implementation/shared/gcTrace.hpp"
#include "gc_implementation/shared/gcWhen.hpp"
#include "gc_implementation/shared/copyFailedInfo.hpp"
32
#include "runtime/os.hpp"
S
sla 已提交
33 34 35 36 37 38 39 40 41 42
#if INCLUDE_ALL_GCS
#include "gc_implementation/g1/evacuationInfo.hpp"
#include "gc_implementation/g1/g1YCTypes.hpp"
#endif

// All GC dependencies against the trace framework is contained within this file.

typedef uintptr_t TraceAddress;

void GCTracer::send_garbage_collection_event() const {
A
apetushkov 已提交
43
  EventGarbageCollection event(UNTIMED);
S
sla 已提交
44
  if (event.should_commit()) {
45
    event.set_gcId(_shared_gc_info.gc_id().id());
S
sla 已提交
46 47 48 49 50 51 52 53 54 55 56
    event.set_name(_shared_gc_info.name());
    event.set_cause((u2) _shared_gc_info.cause());
    event.set_sumOfPauses(_shared_gc_info.sum_of_pauses());
    event.set_longestPause(_shared_gc_info.longest_pause());
    event.set_starttime(_shared_gc_info.start_timestamp());
    event.set_endtime(_shared_gc_info.end_timestamp());
    event.commit();
  }
}

void GCTracer::send_reference_stats_event(ReferenceType type, size_t count) const {
57
  EventGCReferenceStatistics e;
S
sla 已提交
58
  if (e.should_commit()) {
59
      e.set_gcId(_shared_gc_info.gc_id().id());
S
sla 已提交
60 61 62 63 64 65
      e.set_type((u1)type);
      e.set_count(count);
      e.commit();
  }
}

66 67 68 69
void GCTracer::send_metaspace_chunk_free_list_summary(GCWhen::Type when, Metaspace::MetadataType mdtype,
                                                      const MetaspaceChunkFreeListSummary& summary) const {
  EventMetaspaceChunkFreeListSummary e;
  if (e.should_commit()) {
70
    e.set_gcId(_shared_gc_info.gc_id().id());
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    e.set_when(when);
    e.set_metadataType(mdtype);

    e.set_specializedChunks(summary.num_specialized_chunks());
    e.set_specializedChunksTotalSize(summary.specialized_chunks_size_in_bytes());

    e.set_smallChunks(summary.num_small_chunks());
    e.set_smallChunksTotalSize(summary.small_chunks_size_in_bytes());

    e.set_mediumChunks(summary.num_medium_chunks());
    e.set_mediumChunksTotalSize(summary.medium_chunks_size_in_bytes());

    e.set_humongousChunks(summary.num_humongous_chunks());
    e.set_humongousChunksTotalSize(summary.humongous_chunks_size_in_bytes());

    e.commit();
  }
}

S
sla 已提交
90
void ParallelOldTracer::send_parallel_old_event() const {
A
apetushkov 已提交
91
  EventParallelOldGarbageCollection e(UNTIMED);
S
sla 已提交
92
  if (e.should_commit()) {
93
    e.set_gcId(_shared_gc_info.gc_id().id());
S
sla 已提交
94 95 96 97 98 99 100 101
    e.set_densePrefix((TraceAddress)_parallel_old_gc_info.dense_prefix());
    e.set_starttime(_shared_gc_info.start_timestamp());
    e.set_endtime(_shared_gc_info.end_timestamp());
    e.commit();
  }
}

void YoungGCTracer::send_young_gc_event() const {
A
apetushkov 已提交
102
  EventYoungGarbageCollection e(UNTIMED);
S
sla 已提交
103
  if (e.should_commit()) {
104
    e.set_gcId(_shared_gc_info.gc_id().id());
S
sla 已提交
105 106 107 108 109 110 111
    e.set_tenuringThreshold(_tenuring_threshold);
    e.set_starttime(_shared_gc_info.start_timestamp());
    e.set_endtime(_shared_gc_info.end_timestamp());
    e.commit();
  }
}

A
apetushkov 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
bool YoungGCTracer::should_send_promotion_in_new_plab_event() const {
  return EventPromoteObjectInNewPLAB::is_enabled();
}

bool YoungGCTracer::should_send_promotion_outside_plab_event() const {
  return EventPromoteObjectOutsidePLAB::is_enabled();
}

void YoungGCTracer::send_promotion_in_new_plab_event(Klass* klass, size_t obj_size,
                                                     uint age, bool tenured,
                                                     size_t plab_size) const {

  EventPromoteObjectInNewPLAB event;
  if (event.should_commit()) {
    event.set_gcId(_shared_gc_info.gc_id().id());
    event.set_objectClass(klass);
    event.set_objectSize(obj_size);
    event.set_tenured(tenured);
    event.set_tenuringAge(age);
    event.set_plabSize(plab_size);
    event.commit();
  }
}

void YoungGCTracer::send_promotion_outside_plab_event(Klass* klass, size_t obj_size,
                                                      uint age, bool tenured) const {

  EventPromoteObjectOutsidePLAB event;
  if (event.should_commit()) {
    event.set_gcId(_shared_gc_info.gc_id().id());
    event.set_objectClass(klass);
    event.set_objectSize(obj_size);
    event.set_tenured(tenured);
    event.set_tenuringAge(age);
    event.commit();
  }
}

S
sla 已提交
150
void OldGCTracer::send_old_gc_event() const {
A
apetushkov 已提交
151
  EventOldGarbageCollection e(UNTIMED);
S
sla 已提交
152
  if (e.should_commit()) {
153
    e.set_gcId(_shared_gc_info.gc_id().id());
S
sla 已提交
154 155 156 157 158 159
    e.set_starttime(_shared_gc_info.start_timestamp());
    e.set_endtime(_shared_gc_info.end_timestamp());
    e.commit();
  }
}

A
apetushkov 已提交
160 161
static JfrStructCopyFailed to_struct(const CopyFailedInfo& cf_info) {
  JfrStructCopyFailed failed_info;
S
sla 已提交
162 163 164 165 166 167 168 169
  failed_info.set_objectCount(cf_info.failed_count());
  failed_info.set_firstSize(cf_info.first_size());
  failed_info.set_smallestSize(cf_info.smallest_size());
  failed_info.set_totalSize(cf_info.total_size());
  return failed_info;
}

void YoungGCTracer::send_promotion_failed_event(const PromotionFailedInfo& pf_info) const {
170
  EventPromotionFailed e;
S
sla 已提交
171
  if (e.should_commit()) {
172
    e.set_gcId(_shared_gc_info.gc_id().id());
A
apetushkov 已提交
173
    e.set_promotionFailed(to_struct(pf_info));
S
sla 已提交
174 175 176 177 178 179 180
    e.set_thread(pf_info.thread()->thread_id());
    e.commit();
  }
}

// Common to CMS and G1
void OldGCTracer::send_concurrent_mode_failure_event() {
181
  EventConcurrentModeFailure e;
S
sla 已提交
182
  if (e.should_commit()) {
183
    e.set_gcId(_shared_gc_info.gc_id().id());
S
sla 已提交
184 185 186 187 188 189
    e.commit();
  }
}

#if INCLUDE_ALL_GCS
void G1NewTracer::send_g1_young_gc_event() {
A
apetushkov 已提交
190
  EventG1GarbageCollection e(UNTIMED);
S
sla 已提交
191
  if (e.should_commit()) {
192
    e.set_gcId(_shared_gc_info.gc_id().id());
S
sla 已提交
193 194 195 196 197 198 199
    e.set_type(_g1_young_gc_info.type());
    e.set_starttime(_shared_gc_info.start_timestamp());
    e.set_endtime(_shared_gc_info.end_timestamp());
    e.commit();
  }
}

A
apetushkov 已提交
200 201 202 203 204 205 206 207 208 209 210
void G1MMUTracer::send_g1_mmu_event(double time_slice_ms, double gc_time_ms, double max_time_ms) {
  EventG1MMU e;
  if (e.should_commit()) {
    e.set_gcId(GCId::peek().id());
    e.set_timeSlice((s8)time_slice_ms);
    e.set_gcTime((s8)gc_time_ms);
    e.set_pauseTarget((s8)max_time_ms);
    e.commit();
  }
}

S
sla 已提交
211
void G1NewTracer::send_evacuation_info_event(EvacuationInfo* info) {
A
apetushkov 已提交
212
  EventEvacuationInformation e;
S
sla 已提交
213
  if (e.should_commit()) {
214
    e.set_gcId(_shared_gc_info.gc_id().id());
S
sla 已提交
215 216 217 218
    e.set_cSetRegions(info->collectionset_regions());
    e.set_cSetUsedBefore(info->collectionset_used_before());
    e.set_cSetUsedAfter(info->collectionset_used_after());
    e.set_allocationRegions(info->allocation_regions());
A
apetushkov 已提交
219 220
    e.set_allocationRegionsUsedBefore(info->alloc_regions_used_before());
    e.set_allocationRegionsUsedAfter(info->alloc_regions_used_before() + info->bytes_copied());
S
sla 已提交
221 222 223 224 225 226 227
    e.set_bytesCopied(info->bytes_copied());
    e.set_regionsFreed(info->regions_freed());
    e.commit();
  }
}

void G1NewTracer::send_evacuation_failed_event(const EvacuationFailedInfo& ef_info) const {
228
  EventEvacuationFailed e;
S
sla 已提交
229
  if (e.should_commit()) {
230
    e.set_gcId(_shared_gc_info.gc_id().id());
A
apetushkov 已提交
231
    e.set_evacuationFailed(to_struct(ef_info));
S
sla 已提交
232 233 234 235
    e.commit();
  }
}

A
apetushkov 已提交
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
// XXX
//static JfrStructG1EvacuationStatistics
//create_g1_evacstats(unsigned gcid, const G1EvacSummary& summary) {
//  JfrStructG1EvacuationStatistics s;
//  s.set_gcId(gcid);
//  s.set_allocated(summary.allocated() * HeapWordSize);
//  s.set_wasted(summary.wasted() * HeapWordSize);
//  s.set_used(summary.used() * HeapWordSize);
//  s.set_undoWaste(summary.undo_wasted() * HeapWordSize);
//  s.set_regionEndWaste(summary.region_end_waste() * HeapWordSize);
//  s.set_regionsRefilled(summary.regions_filled());
//  s.set_directAllocated(summary.direct_allocated() * HeapWordSize);
//  s.set_failureUsed(summary.failure_used() * HeapWordSize);
//  s.set_failureWaste(summary.failure_waste() * HeapWordSize);
//  return s;
//}
//
//void G1NewTracer::send_young_evacuation_statistics(const G1EvacSummary& summary) const {
//  EventG1EvacuationYoungStatistics surv_evt;
//  if (surv_evt.should_commit()) {
//    surv_evt.set_statistics(create_g1_evacstats(_shared_gc_info.gc_id().id(), summary));
//    surv_evt.commit();
//  }
//}
//
//void G1NewTracer::send_old_evacuation_statistics(const G1EvacSummary& summary) const {
//  EventG1EvacuationOldStatistics old_evt;
//  if (old_evt.should_commit()) {
//    old_evt.set_statistics(create_g1_evacstats(_shared_gc_info.gc_id().id(), summary));
//    old_evt.commit();
//  }
//}
//
//void G1NewTracer::send_basic_ihop_statistics(size_t threshold,
//                                             size_t target_occupancy,
//                                             size_t current_occupancy,
//                                             size_t last_allocation_size,
//                                             double last_allocation_duration,
//                                             double last_marking_length) {
//  EventG1BasicIHOP evt;
//  if (evt.should_commit()) {
//    evt.set_gcId(_shared_gc_info.gc_id().id());
//    evt.set_threshold(threshold);
//    evt.set_targetOccupancy(target_occupancy);
//    evt.set_thresholdPercentage(target_occupancy > 0 ? ((double)threshold / target_occupancy) : 0.0);
//    evt.set_currentOccupancy(current_occupancy);
//    evt.set_recentMutatorAllocationSize(last_allocation_size);
//    evt.set_recentMutatorDuration(last_allocation_duration * MILLIUNITS);
//    evt.set_recentAllocationRate(last_allocation_duration != 0.0 ? last_allocation_size / last_allocation_duration : 0.0);
//    evt.set_lastMarkingDuration(last_marking_length * MILLIUNITS);
//    evt.commit();
//  }
//}
//
//void G1NewTracer::send_adaptive_ihop_statistics(size_t threshold,
//                                                size_t internal_target_occupancy,
//                                                size_t current_occupancy,
//                                                size_t additional_buffer_size,
//                                                double predicted_allocation_rate,
//                                                double predicted_marking_length,
//                                                bool prediction_active) {
//  EventG1AdaptiveIHOP evt;
//  if (evt.should_commit()) {
//    evt.set_gcId(_shared_gc_info.gc_id().id());
//    evt.set_threshold(threshold);
//    evt.set_thresholdPercentage(internal_target_occupancy > 0 ? ((double)threshold / internal_target_occupancy) : 0.0);
//    evt.set_ihopTargetOccupancy(internal_target_occupancy);
//    evt.set_currentOccupancy(current_occupancy);
//    evt.set_additionalBufferSize(additional_buffer_size);
//    evt.set_predictedAllocationRate(predicted_allocation_rate);
//    evt.set_predictedMarkingDuration(predicted_marking_length * MILLIUNITS);
//    evt.set_predictionActive(prediction_active);
//    evt.commit();
//  }
//}

#endif // INCLUDE_ALL_GCS

static JfrStructVirtualSpace to_struct(const VirtualSpaceSummary& summary) {
  JfrStructVirtualSpace space;
S
sla 已提交
316 317 318 319 320 321 322 323
  space.set_start((TraceAddress)summary.start());
  space.set_committedEnd((TraceAddress)summary.committed_end());
  space.set_committedSize(summary.committed_size());
  space.set_reservedEnd((TraceAddress)summary.reserved_end());
  space.set_reservedSize(summary.reserved_size());
  return space;
}

A
apetushkov 已提交
324 325
static JfrStructObjectSpace to_struct(const SpaceSummary& summary) {
  JfrStructObjectSpace space;
S
sla 已提交
326 327 328 329 330 331 332 333
  space.set_start((TraceAddress)summary.start());
  space.set_end((TraceAddress)summary.end());
  space.set_used(summary.used());
  space.set_size(summary.size());
  return space;
}

class GCHeapSummaryEventSender : public GCHeapSummaryVisitor {
334
  GCId _gc_id;
S
sla 已提交
335 336
  GCWhen::Type _when;
 public:
337
  GCHeapSummaryEventSender(GCId gc_id, GCWhen::Type when) : _gc_id(gc_id), _when(when) {}
S
sla 已提交
338 339 340 341

  void visit(const GCHeapSummary* heap_summary) const {
    const VirtualSpaceSummary& heap_space = heap_summary->heap();

342
    EventGCHeapSummary e;
S
sla 已提交
343
    if (e.should_commit()) {
344
      e.set_gcId(_gc_id.id());
S
sla 已提交
345
      e.set_when((u1)_when);
A
apetushkov 已提交
346
      e.set_heapSpace(to_struct(heap_space));
S
sla 已提交
347 348 349 350 351
      e.set_heapUsed(heap_summary->used());
      e.commit();
    }
  }

352 353 354 355 356 357 358 359 360 361 362 363 364 365
  void visit(const G1HeapSummary* g1_heap_summary) const {
    visit((GCHeapSummary*)g1_heap_summary);

    EventG1HeapSummary e;
    if (e.should_commit()) {
      e.set_gcId(_gc_id.id());
      e.set_when((u1)_when);
      e.set_edenUsedSize(g1_heap_summary->edenUsed());
      e.set_edenTotalSize(g1_heap_summary->edenCapacity());
      e.set_survivorUsedSize(g1_heap_summary->survivorUsed());
      e.set_numberOfRegions(g1_heap_summary->numberOfRegions());
      e.commit();
    }
  }
A
apetushkov 已提交
366

S
sla 已提交
367 368 369 370 371 372 373 374 375 376
  void visit(const PSHeapSummary* ps_heap_summary) const {
    visit((GCHeapSummary*)ps_heap_summary);

    const VirtualSpaceSummary& old_summary = ps_heap_summary->old();
    const SpaceSummary& old_space = ps_heap_summary->old_space();
    const VirtualSpaceSummary& young_summary = ps_heap_summary->young();
    const SpaceSummary& eden_space = ps_heap_summary->eden();
    const SpaceSummary& from_space = ps_heap_summary->from();
    const SpaceSummary& to_space = ps_heap_summary->to();

377
    EventPSHeapSummary e;
S
sla 已提交
378
    if (e.should_commit()) {
379
      e.set_gcId(_gc_id.id());
S
sla 已提交
380 381
      e.set_when((u1)_when);

A
apetushkov 已提交
382 383 384 385 386 387
      e.set_oldSpace(to_struct(ps_heap_summary->old()));
      e.set_oldObjectSpace(to_struct(ps_heap_summary->old_space()));
      e.set_youngSpace(to_struct(ps_heap_summary->young()));
      e.set_edenSpace(to_struct(ps_heap_summary->eden()));
      e.set_fromSpace(to_struct(ps_heap_summary->from()));
      e.set_toSpace(to_struct(ps_heap_summary->to()));
S
sla 已提交
388 389 390 391 392 393
      e.commit();
    }
  }
};

void GCTracer::send_gc_heap_summary_event(GCWhen::Type when, const GCHeapSummary& heap_summary) const {
394
  GCHeapSummaryEventSender visitor(_shared_gc_info.gc_id(), when);
S
sla 已提交
395 396 397
  heap_summary.accept(&visitor);
}

A
apetushkov 已提交
398 399
static JfrStructMetaspaceSizes to_struct(const MetaspaceSizes& sizes) {
  JfrStructMetaspaceSizes meta_sizes;
S
sla 已提交
400

401
  meta_sizes.set_committed(sizes.committed());
S
sla 已提交
402 403 404 405 406 407 408
  meta_sizes.set_used(sizes.used());
  meta_sizes.set_reserved(sizes.reserved());

  return meta_sizes;
}

void GCTracer::send_meta_space_summary_event(GCWhen::Type when, const MetaspaceSummary& meta_space_summary) const {
409
  EventMetaspaceSummary e;
S
sla 已提交
410
  if (e.should_commit()) {
411
    e.set_gcId(_shared_gc_info.gc_id().id());
S
sla 已提交
412
    e.set_when((u1) when);
413
    e.set_gcThreshold(meta_space_summary.capacity_until_GC());
A
apetushkov 已提交
414 415 416
    e.set_metaspace(to_struct(meta_space_summary.meta_space()));
    e.set_dataSpace(to_struct(meta_space_summary.data_space()));
    e.set_classSpace(to_struct(meta_space_summary.class_space()));
S
sla 已提交
417 418 419 420 421 422 423 424 425
    e.commit();
  }
}

class PhaseSender : public PhaseVisitor {
  GCId _gc_id;
 public:
  PhaseSender(GCId gc_id) : _gc_id(gc_id) {}

A
apetushkov 已提交
426 427
   template<typename T>
  void send_phase(GCPhase* phase) {
S
sla 已提交
428 429
    T event(UNTIMED);
    if (event.should_commit()) {
430
      event.set_gcId(_gc_id.id());
A
apetushkov 已提交
431 432 433
      event.set_name(phase->name());
      event.set_starttime(phase->start());
      event.set_endtime(phase->end());
S
sla 已提交
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
      event.commit();
    }
  }

  void visit(GCPhase* pause) { ShouldNotReachHere(); }
  void visit(ConcurrentPhase* pause) { Unimplemented(); }
  void visit(PausePhase* pause) {
    assert(PhasesStack::PHASE_LEVELS == 5, "Need more event types");

    switch (pause->level()) {
      case 0: send_phase<EventGCPhasePause>(pause); break;
      case 1: send_phase<EventGCPhasePauseLevel1>(pause); break;
      case 2: send_phase<EventGCPhasePauseLevel2>(pause); break;
      case 3: send_phase<EventGCPhasePauseLevel3>(pause); break;
      default: /* Ignore sending this phase */ break;
    }
  }
};

void GCTracer::send_phase_events(TimePartitions* time_partitions) const {
454
  PhaseSender phase_reporter(_shared_gc_info.gc_id());
S
sla 已提交
455 456 457 458 459 460 461

  TimePartitionPhasesIterator iter(time_partitions);
  while (iter.has_next()) {
    GCPhase* phase = iter.next();
    phase->accept(&phase_reporter);
  }
}