hotspot/src/share/vm/utilities/histogram.cpp
author goetz
Wed, 04 Jun 2014 11:56:44 +0200
changeset 25351 7c198a690050
parent 13963 e5b53c306fb5
child 40655 9f644073d3a0
permissions -rw-r--r--
8044775: Improve usage of umbrella header atomic.inline.hpp. Reviewed-by: stefank, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
13963
e5b53c306fb5 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 13195
diff changeset
     2
 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "oops/oop.inline.hpp"
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 13963
diff changeset
    27
#include "runtime/atomic.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "utilities/histogram.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
////////////////// HistogramElement ////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
HistogramElement::HistogramElement() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  _count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
int HistogramElement::count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  return _count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
const char* HistogramElement::name() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  return _name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
void HistogramElement::increment_count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // We can't use the accessor :-(.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  Atomic::inc(&_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
int HistogramElement::compare(HistogramElement* e1,HistogramElement* e2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  if(e1->count() > e2->count()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  } else if(e1->count() < e2->count()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
void HistogramElement::print_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  st->print("%10d   ",((HistogramElement*)this)->count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  st->print_cr("%s",((HistogramElement*)this)->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
////////////////// Histogram ////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
int Histogram::sort_helper(HistogramElement** e1, HistogramElement** e2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  return (*e1)->compare(*e1,*e2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
Histogram::Histogram(const char* title,int estimatedCount) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  _title = title;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    73
  _elements = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<HistogramElement*>(estimatedCount,true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
void Histogram::add_element(HistogramElement* element) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // Note, we need to add locking !
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  elements()->append(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
void Histogram::print_header(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  st->print_cr("%s",title());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  st->print_cr("--------------------------------------------------");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
void Histogram::print_elements(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  elements()->sort(Histogram::sort_helper);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  jint total = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  for(int i=0; i < elements()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    elements()->at(i)->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    total += elements()->at(i)->count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  st->print("%10d   ", total);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  st->print_cr("Total");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
void Histogram::print_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  ((Histogram*)this)->print_header(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  ((Histogram*)this)->print_elements(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
#endif