author | mr |
Tue, 29 Oct 2019 13:52:04 -0700 | |
changeset 58850 | f4290bf1cc21 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
25351
diff
changeset
|
2 |
* Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
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 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "oops/oop.inline.hpp" |
|
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
25351
diff
changeset
|
27 |
#include "runtime/atomic.hpp" |
7397 | 28 |
#include "utilities/histogram.hpp" |
1 | 29 |
|
30 |
#ifdef ASSERT |
|
31 |
||
32 |
////////////////// HistogramElement //////////////////////// |
|
33 |
||
34 |
HistogramElement::HistogramElement() { |
|
35 |
_count = 0; |
|
36 |
} |
|
37 |
||
38 |
int HistogramElement::count() { |
|
39 |
return _count; |
|
40 |
} |
|
41 |
||
42 |
const char* HistogramElement::name() { |
|
43 |
return _name; |
|
44 |
} |
|
45 |
||
46 |
void HistogramElement::increment_count() { |
|
47 |
// We can't use the accessor :-(. |
|
48 |
Atomic::inc(&_count); |
|
49 |
} |
|
50 |
||
51 |
int HistogramElement::compare(HistogramElement* e1,HistogramElement* e2) { |
|
52 |
if(e1->count() > e2->count()) { |
|
53 |
return -1; |
|
54 |
} else if(e1->count() < e2->count()) { |
|
55 |
return 1; |
|
56 |
} |
|
57 |
return 0; |
|
58 |
} |
|
59 |
||
60 |
void HistogramElement::print_on(outputStream* st) const { |
|
61 |
st->print("%10d ",((HistogramElement*)this)->count()); |
|
62 |
st->print_cr("%s",((HistogramElement*)this)->name()); |
|
63 |
} |
|
64 |
||
65 |
////////////////// Histogram //////////////////////// |
|
66 |
||
67 |
int Histogram::sort_helper(HistogramElement** e1, HistogramElement** e2) { |
|
68 |
return (*e1)->compare(*e1,*e2); |
|
69 |
} |
|
70 |
||
71 |
Histogram::Histogram(const char* title,int estimatedCount) { |
|
72 |
_title = title; |
|
13195 | 73 |
_elements = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<HistogramElement*>(estimatedCount,true); |
1 | 74 |
} |
75 |
||
76 |
void Histogram::add_element(HistogramElement* element) { |
|
77 |
// Note, we need to add locking ! |
|
78 |
elements()->append(element); |
|
79 |
} |
|
80 |
||
81 |
void Histogram::print_header(outputStream* st) { |
|
82 |
st->print_cr("%s",title()); |
|
83 |
st->print_cr("--------------------------------------------------"); |
|
84 |
} |
|
85 |
||
86 |
void Histogram::print_elements(outputStream* st) { |
|
87 |
elements()->sort(Histogram::sort_helper); |
|
88 |
jint total = 0; |
|
89 |
for(int i=0; i < elements()->length(); i++) { |
|
90 |
elements()->at(i)->print(); |
|
91 |
total += elements()->at(i)->count(); |
|
92 |
} |
|
93 |
st->print("%10d ", total); |
|
94 |
st->print_cr("Total"); |
|
95 |
} |
|
96 |
||
97 |
void Histogram::print_on(outputStream* st) const { |
|
98 |
((Histogram*)this)->print_header(st); |
|
99 |
((Histogram*)this)->print_elements(st); |
|
100 |
} |
|
101 |
||
102 |
#endif |