src/hotspot/share/gc/shared/gcTimer.cpp
author stefank
Thu, 22 Feb 2018 18:36:07 +0100
changeset 49047 8f004146e407
parent 49020 6d61be5959e0
child 50113 caf115bb98ad
permissions -rw-r--r--
8198515: Extract SoftReferencePolicy code out of CollectorPolicy Reviewed-by: pliden, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
     1
/*
49020
6d61be5959e0 8198268: Add time argument to ConcurrentGCTimer::register_gc_pause_start/_end
pliden
parents: 47216
diff changeset
     2
 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
     4
 *
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
     8
 *
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    13
 * accompanied this code).
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    14
 *
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    18
 *
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    21
 * questions.
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    22
 *
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    23
 */
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    24
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 21767
diff changeset
    26
#include "gc/shared/gcTimer.hpp"
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    27
#include "utilities/growableArray.hpp"
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
    28
#include "utilities/ticks.inline.hpp"
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    29
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
    30
// the "time" parameter for most functions
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
    31
// has a default value set by Ticks::now()
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
    32
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
    33
void GCTimer::register_gc_start(const Ticks& time) {
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    34
  _time_partitions.clear();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    35
  _gc_start = time;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    36
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    37
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
    38
void GCTimer::register_gc_end(const Ticks& time) {
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    39
  assert(!_time_partitions.has_active_phases(),
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    40
      "We should have ended all started phases, before ending the GC");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    41
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    42
  _gc_end = time;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    43
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    44
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
    45
void GCTimer::register_gc_pause_start(const char* name, const Ticks& time) {
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    46
  _time_partitions.report_gc_phase_start(name, time);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    47
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    48
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
    49
void GCTimer::register_gc_pause_end(const Ticks& time) {
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    50
  _time_partitions.report_gc_phase_end(time);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    51
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    52
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
    53
void GCTimer::register_gc_phase_start(const char* name, const Ticks& time) {
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    54
  _time_partitions.report_gc_phase_start(name, time);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    55
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    56
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
    57
void GCTimer::register_gc_phase_end(const Ticks& time) {
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    58
  _time_partitions.report_gc_phase_end(time);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    59
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    60
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
    61
void STWGCTimer::register_gc_start(const Ticks& time) {
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    62
  GCTimer::register_gc_start(time);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    63
  register_gc_pause_start("GC Pause", time);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    64
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    65
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
    66
void STWGCTimer::register_gc_end(const Ticks& time) {
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    67
  register_gc_pause_end(time);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    68
  GCTimer::register_gc_end(time);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    69
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    70
49020
6d61be5959e0 8198268: Add time argument to ConcurrentGCTimer::register_gc_pause_start/_end
pliden
parents: 47216
diff changeset
    71
void ConcurrentGCTimer::register_gc_pause_start(const char* name, const Ticks& time) {
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
    72
  assert(!_is_concurrent_phase_active, "A pause phase can't be started while a concurrent phase is active.");
49020
6d61be5959e0 8198268: Add time argument to ConcurrentGCTimer::register_gc_pause_start/_end
pliden
parents: 47216
diff changeset
    73
  GCTimer::register_gc_pause_start(name, time);
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    74
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    75
49020
6d61be5959e0 8198268: Add time argument to ConcurrentGCTimer::register_gc_pause_start/_end
pliden
parents: 47216
diff changeset
    76
void ConcurrentGCTimer::register_gc_pause_end(const Ticks& time) {
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
    77
  assert(!_is_concurrent_phase_active, "A pause phase can't be ended while a concurrent phase is active.");
49020
6d61be5959e0 8198268: Add time argument to ConcurrentGCTimer::register_gc_pause_start/_end
pliden
parents: 47216
diff changeset
    78
  GCTimer::register_gc_pause_end(time);
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    79
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    80
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
    81
void ConcurrentGCTimer::register_gc_concurrent_start(const char* name, const Ticks& time) {
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
    82
  assert(!_is_concurrent_phase_active, "A concurrent phase is already active.");
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
    83
  _time_partitions.report_gc_phase_start(name, time, GCPhase::ConcurrentPhaseType);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
    84
  _is_concurrent_phase_active = true;
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
    85
}
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
    86
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
    87
void ConcurrentGCTimer::register_gc_concurrent_end(const Ticks& time) {
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
    88
  assert(_is_concurrent_phase_active, "A concurrent phase is not active.");
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
    89
  _time_partitions.report_gc_phase_end(time, GCPhase::ConcurrentPhaseType);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
    90
  _is_concurrent_phase_active = false;
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
    91
}
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
    92
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    93
void PhasesStack::clear() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    94
  _next_phase_level = 0;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    95
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    96
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    97
void PhasesStack::push(int phase_index) {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    98
  assert(_next_phase_level < PHASE_LEVELS, "Overflow");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
    99
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   100
  _phase_indices[_next_phase_level] = phase_index;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   101
  _next_phase_level++;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   102
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   103
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   104
int PhasesStack::pop() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   105
  assert(_next_phase_level > 0, "Underflow");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   106
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   107
  _next_phase_level--;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   108
  return _phase_indices[_next_phase_level];
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   109
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   110
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   111
int PhasesStack::count() const {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   112
  return _next_phase_level;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   113
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   114
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   115
TimePartitions::TimePartitions() {
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   116
  _phases = new (ResourceObj::C_HEAP, mtGC) GrowableArray<GCPhase>(INITIAL_CAPACITY, true, mtGC);
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   117
  clear();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   118
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   119
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   120
TimePartitions::~TimePartitions() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   121
  delete _phases;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   122
  _phases = NULL;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   123
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   124
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   125
void TimePartitions::clear() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   126
  _phases->clear();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   127
  _active_phases.clear();
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
   128
  _sum_of_pauses = Tickspan();
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
   129
  _longest_pause = Tickspan();
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   130
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   131
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   132
void TimePartitions::report_gc_phase_start(const char* name, const Ticks& time, GCPhase::PhaseType type) {
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   133
  assert(_phases->length() <= 1000, "Too many recored phases?");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   134
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   135
  int level = _active_phases.count();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   136
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   137
  GCPhase phase;
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   138
  phase.set_type(type);
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   139
  phase.set_level(level);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   140
  phase.set_name(name);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   141
  phase.set_start(time);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   142
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   143
  int index = _phases->append(phase);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   144
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   145
  _active_phases.push(index);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   146
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   147
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   148
void TimePartitions::update_statistics(GCPhase* phase) {
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   149
  if ((phase->type() == GCPhase::PausePhaseType) && (phase->level() == 0)) {
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
   150
    const Tickspan pause = phase->end() - phase->start();
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   151
    _sum_of_pauses += pause;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   152
    _longest_pause = MAX2(pause, _longest_pause);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   153
  }
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   154
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   155
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   156
void TimePartitions::report_gc_phase_end(const Ticks& time, GCPhase::PhaseType type) {
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   157
  int phase_index = _active_phases.pop();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   158
  GCPhase* phase = _phases->adr_at(phase_index);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   159
  phase->set_end(time);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   160
  update_statistics(phase);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   161
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   162
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   163
int TimePartitions::num_phases() const {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   164
  return _phases->length();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   165
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   166
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   167
GCPhase* TimePartitions::phase_at(int index) const {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   168
  assert(index >= 0, "Out of bounds");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   169
  assert(index < _phases->length(), "Out of bounds");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   170
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   171
  return _phases->adr_at(index);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   172
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   173
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   174
bool TimePartitions::has_active_phases() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   175
  return _active_phases.count() > 0;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   176
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   177
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   178
bool TimePartitionPhasesIterator::has_next() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   179
  return _next < _time_partitions->num_phases();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   180
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   181
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   182
GCPhase* TimePartitionPhasesIterator::next() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   183
  assert(has_next(), "Must have phases left");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   184
  return _time_partitions->phase_at(_next++);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   185
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   186
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   187
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   188
/////////////// Unit tests ///////////////
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   189
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   190
#ifndef PRODUCT
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   191
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   192
class TimePartitionPhasesIteratorTest {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   193
 public:
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   194
  static void all() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   195
    one_pause();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   196
    two_pauses();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   197
    one_sub_pause_phase();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   198
    many_sub_pause_phases();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   199
    many_sub_pause_phases2();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   200
    max_nested_pause_phases();
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   201
    one_concurrent();
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   202
  }
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   203
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   204
  static void validate_gc_phase(GCPhase* phase, int level, const char* name, const Ticks& start, const Ticks& end) {
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   205
    assert(phase->level() == level, "Incorrect level");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   206
    assert(strcmp(phase->name(), name) == 0, "Incorrect name");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   207
    assert(phase->start() == start, "Incorrect start");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   208
    assert(phase->end() == end, "Incorrect end");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   209
  }
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   210
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   211
  static void one_pause() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   212
    TimePartitions time_partitions;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   213
    time_partitions.report_gc_phase_start("PausePhase", 2);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   214
    time_partitions.report_gc_phase_end(8);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   215
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   216
    TimePartitionPhasesIterator iter(&time_partitions);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   217
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   218
    validate_gc_phase(iter.next(), 0, "PausePhase", 2, 8);
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
   219
    assert(time_partitions.sum_of_pauses() == Ticks(8) - Ticks(2), "Incorrect");
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
   220
    assert(time_partitions.longest_pause() == Ticks(8) - Ticks(2), "Incorrect");
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   221
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   222
    assert(!iter.has_next(), "Too many elements");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   223
  }
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   224
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   225
  static void two_pauses() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   226
    TimePartitions time_partitions;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   227
    time_partitions.report_gc_phase_start("PausePhase1", 2);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   228
    time_partitions.report_gc_phase_end(3);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   229
    time_partitions.report_gc_phase_start("PausePhase2", 4);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   230
    time_partitions.report_gc_phase_end(6);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   231
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   232
    TimePartitionPhasesIterator iter(&time_partitions);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   233
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   234
    validate_gc_phase(iter.next(), 0, "PausePhase1", 2, 3);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   235
    validate_gc_phase(iter.next(), 0, "PausePhase2", 4, 6);
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   236
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
   237
    assert(time_partitions.sum_of_pauses() == Ticks(3) - Ticks(0), "Incorrect");
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
   238
    assert(time_partitions.longest_pause() == Ticks(2) - Ticks(0), "Incorrect");
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   239
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   240
    assert(!iter.has_next(), "Too many elements");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   241
  }
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   242
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   243
  static void one_sub_pause_phase() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   244
    TimePartitions time_partitions;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   245
    time_partitions.report_gc_phase_start("PausePhase", 2);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   246
    time_partitions.report_gc_phase_start("SubPhase", 3);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   247
    time_partitions.report_gc_phase_end(4);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   248
    time_partitions.report_gc_phase_end(5);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   249
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   250
    TimePartitionPhasesIterator iter(&time_partitions);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   251
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   252
    validate_gc_phase(iter.next(), 0, "PausePhase", 2, 5);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   253
    validate_gc_phase(iter.next(), 1, "SubPhase", 3, 4);
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   254
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
   255
    assert(time_partitions.sum_of_pauses() == Ticks(3) - Ticks(0), "Incorrect");
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
   256
    assert(time_partitions.longest_pause() == Ticks(3) - Ticks(0), "Incorrect");
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   257
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   258
    assert(!iter.has_next(), "Too many elements");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   259
  }
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   260
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   261
  static void max_nested_pause_phases() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   262
    TimePartitions time_partitions;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   263
    time_partitions.report_gc_phase_start("PausePhase", 2);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   264
    time_partitions.report_gc_phase_start("SubPhase1", 3);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   265
    time_partitions.report_gc_phase_start("SubPhase2", 4);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   266
    time_partitions.report_gc_phase_start("SubPhase3", 5);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   267
    time_partitions.report_gc_phase_end(6);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   268
    time_partitions.report_gc_phase_end(7);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   269
    time_partitions.report_gc_phase_end(8);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   270
    time_partitions.report_gc_phase_end(9);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   271
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   272
    TimePartitionPhasesIterator iter(&time_partitions);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   273
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   274
    validate_gc_phase(iter.next(), 0, "PausePhase", 2, 9);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   275
    validate_gc_phase(iter.next(), 1, "SubPhase1", 3, 8);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   276
    validate_gc_phase(iter.next(), 2, "SubPhase2", 4, 7);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   277
    validate_gc_phase(iter.next(), 3, "SubPhase3", 5, 6);
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   278
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
   279
    assert(time_partitions.sum_of_pauses() == Ticks(7) - Ticks(0), "Incorrect");
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
   280
    assert(time_partitions.longest_pause() == Ticks(7) - Ticks(0), "Incorrect");
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   281
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   282
    assert(!iter.has_next(), "Too many elements");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   283
  }
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   284
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   285
  static void many_sub_pause_phases() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   286
    TimePartitions time_partitions;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   287
    time_partitions.report_gc_phase_start("PausePhase", 2);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   288
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   289
    time_partitions.report_gc_phase_start("SubPhase1", 3);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   290
    time_partitions.report_gc_phase_end(4);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   291
    time_partitions.report_gc_phase_start("SubPhase2", 5);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   292
    time_partitions.report_gc_phase_end(6);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   293
    time_partitions.report_gc_phase_start("SubPhase3", 7);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   294
    time_partitions.report_gc_phase_end(8);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   295
    time_partitions.report_gc_phase_start("SubPhase4", 9);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   296
    time_partitions.report_gc_phase_end(10);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   297
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   298
    time_partitions.report_gc_phase_end(11);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   299
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   300
    TimePartitionPhasesIterator iter(&time_partitions);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   301
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   302
    validate_gc_phase(iter.next(), 0, "PausePhase", 2, 11);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   303
    validate_gc_phase(iter.next(), 1, "SubPhase1", 3, 4);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   304
    validate_gc_phase(iter.next(), 1, "SubPhase2", 5, 6);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   305
    validate_gc_phase(iter.next(), 1, "SubPhase3", 7, 8);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   306
    validate_gc_phase(iter.next(), 1, "SubPhase4", 9, 10);
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   307
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
   308
    assert(time_partitions.sum_of_pauses() == Ticks(9) - Ticks(0), "Incorrect");
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
   309
    assert(time_partitions.longest_pause() == Ticks(9) - Ticks(0), "Incorrect");
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   310
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   311
    assert(!iter.has_next(), "Too many elements");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   312
  }
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   313
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   314
  static void many_sub_pause_phases2() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   315
    TimePartitions time_partitions;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   316
    time_partitions.report_gc_phase_start("PausePhase", 2);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   317
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   318
    time_partitions.report_gc_phase_start("SubPhase1", 3);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   319
    time_partitions.report_gc_phase_start("SubPhase11", 4);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   320
    time_partitions.report_gc_phase_end(5);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   321
    time_partitions.report_gc_phase_start("SubPhase12", 6);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   322
    time_partitions.report_gc_phase_end(7);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   323
    time_partitions.report_gc_phase_end(8);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   324
    time_partitions.report_gc_phase_start("SubPhase2", 9);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   325
    time_partitions.report_gc_phase_start("SubPhase21", 10);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   326
    time_partitions.report_gc_phase_end(11);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   327
    time_partitions.report_gc_phase_start("SubPhase22", 12);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   328
    time_partitions.report_gc_phase_end(13);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   329
    time_partitions.report_gc_phase_end(14);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   330
    time_partitions.report_gc_phase_start("SubPhase3", 15);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   331
    time_partitions.report_gc_phase_end(16);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   332
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   333
    time_partitions.report_gc_phase_end(17);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   334
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   335
    TimePartitionPhasesIterator iter(&time_partitions);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   336
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   337
    validate_gc_phase(iter.next(), 0, "PausePhase", 2, 17);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   338
    validate_gc_phase(iter.next(), 1, "SubPhase1", 3, 8);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   339
    validate_gc_phase(iter.next(), 2, "SubPhase11", 4, 5);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   340
    validate_gc_phase(iter.next(), 2, "SubPhase12", 6, 7);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   341
    validate_gc_phase(iter.next(), 1, "SubPhase2", 9, 14);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   342
    validate_gc_phase(iter.next(), 2, "SubPhase21", 10, 11);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   343
    validate_gc_phase(iter.next(), 2, "SubPhase22", 12, 13);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   344
    validate_gc_phase(iter.next(), 1, "SubPhase3", 15, 16);
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   345
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
   346
    assert(time_partitions.sum_of_pauses() == Ticks(15) - Ticks(0), "Incorrect");
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 18025
diff changeset
   347
    assert(time_partitions.longest_pause() == Ticks(15) - Ticks(0), "Incorrect");
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   348
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   349
    assert(!iter.has_next(), "Too many elements");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   350
  }
35204
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   351
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   352
  static void one_concurrent() {
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   353
    TimePartitions time_partitions;
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   354
    time_partitions.report_gc_phase_start("ConcurrentPhase", 2, GCPhase::ConcurrentPhaseType);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   355
    time_partitions.report_gc_phase_end(8, GCPhase::ConcurrentPhaseType);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   356
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   357
    TimePartitionPhasesIterator iter(&time_partitions);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   358
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   359
    validate_gc_phase(iter.next(), 0, "ConcurrentPhase", 2, 8);
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   360
    // ConcurrentPhaseType should not affect to both 'sum_of_pauses()' and 'longest_pause()'.
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   361
    assert(time_partitions.sum_of_pauses() == Tickspan(), "Incorrect");
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   362
    assert(time_partitions.longest_pause() == Tickspan(), "Incorrect");
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   363
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   364
    assert(!iter.has_next(), "Too many elements");
78a0fd90a70f 8068394: Trace event for concurrent GC phases
sangheki
parents: 30764
diff changeset
   365
  }
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   366
};
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   367
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   368
class GCTimerTest {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   369
public:
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   370
  static void all() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   371
    gc_start();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   372
    gc_end();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   373
  }
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   374
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   375
  static void gc_start() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   376
    GCTimer gc_timer;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   377
    gc_timer.register_gc_start(1);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   378
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   379
    assert(gc_timer.gc_start() == 1, "Incorrect");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   380
  }
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   381
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   382
  static void gc_end() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   383
    GCTimer gc_timer;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   384
    gc_timer.register_gc_start(1);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   385
    gc_timer.register_gc_end(2);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   386
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   387
    assert(gc_timer.gc_end() == 2, "Incorrect");
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   388
  }
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   389
};
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   390
35529
39376b4613b5 8147012: Fix includes in internalVMTests.cpp
ehelin
parents: 35204
diff changeset
   391
void GCTimer_test() {
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   392
  GCTimerTest::all();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   393
  TimePartitionPhasesIteratorTest::all();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   394
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   395
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents:
diff changeset
   396
#endif