hotspot/src/share/vm/utilities/histogram.cpp
author mikael
Tue, 09 Oct 2012 10:09:34 -0700
changeset 13963 e5b53c306fb5
parent 13195 be27e1b6a4b9
child 25351 7c198a690050
permissions -rw-r--r--
7197424: update copyright year to match last edit in jdk8 hotspot repository Summary: Update copyright year to 2012 for relevant files Reviewed-by: dholmes, coleenp
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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "utilities/histogram.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
////////////////// HistogramElement ////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
HistogramElement::HistogramElement() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  _count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
int HistogramElement::count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  return _count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
const char* HistogramElement::name() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  return _name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
void HistogramElement::increment_count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // We can't use the accessor :-(.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  Atomic::inc(&_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
int HistogramElement::compare(HistogramElement* e1,HistogramElement* e2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  if(e1->count() > e2->count()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  } else if(e1->count() < e2->count()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
void HistogramElement::print_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  st->print("%10d   ",((HistogramElement*)this)->count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  st->print_cr("%s",((HistogramElement*)this)->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
////////////////// Histogram ////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
int Histogram::sort_helper(HistogramElement** e1, HistogramElement** e2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  return (*e1)->compare(*e1,*e2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
Histogram::Histogram(const char* title,int estimatedCount) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  _title = title;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    72
  _elements = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<HistogramElement*>(estimatedCount,true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
void Histogram::add_element(HistogramElement* element) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // Note, we need to add locking !
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  elements()->append(element);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
void Histogram::print_header(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  st->print_cr("%s",title());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  st->print_cr("--------------------------------------------------");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
void Histogram::print_elements(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  elements()->sort(Histogram::sort_helper);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  jint total = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  for(int i=0; i < elements()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    elements()->at(i)->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    total += elements()->at(i)->count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  st->print("%10d   ", total);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  st->print_cr("Total");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
void Histogram::print_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  ((Histogram*)this)->print_header(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  ((Histogram*)this)->print_elements(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
#endif