author | coleenp |
Fri, 08 Mar 2013 11:47:57 -0500 | |
changeset 15928 | f9d5c6e4107f |
parent 15228 | e92acc84ade3 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
15228
e92acc84ade3
7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents:
13728
diff
changeset
|
2 |
* Copyright (c) 1997, 2013, 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 "classfile/systemDictionary.hpp" |
|
27 |
#include "gc_interface/collectedHeap.inline.hpp" |
|
28 |
#include "memory/resourceArea.hpp" |
|
29 |
#include "memory/space.hpp" |
|
30 |
#include "oops/oop.inline.hpp" |
|
31 |
#include "oops/oop.inline2.hpp" |
|
32 |
#include "runtime/aprofiler.hpp" |
|
1 | 33 |
|
34 |
||
35 |
bool AllocationProfiler::_active = false; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
36 |
GrowableArray<Klass*>* AllocationProfiler::_print_array = NULL; |
1 | 37 |
|
38 |
||
39 |
class AllocProfClosure : public ObjectClosure { |
|
40 |
public: |
|
41 |
void do_object(oop obj) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
42 |
Klass* k = obj->klass(); |
1 | 43 |
k->set_alloc_count(k->alloc_count() + 1); |
44 |
k->set_alloc_size(k->alloc_size() + obj->size()); |
|
45 |
} |
|
46 |
}; |
|
47 |
||
48 |
||
49 |
void AllocationProfiler::iterate_since_last_gc() { |
|
50 |
if (is_active()) { |
|
51 |
AllocProfClosure blk; |
|
52 |
GenCollectedHeap* heap = GenCollectedHeap::heap(); |
|
53 |
heap->object_iterate_since_last_GC(&blk); |
|
54 |
} |
|
55 |
} |
|
56 |
||
57 |
||
58 |
void AllocationProfiler::engage() { |
|
59 |
_active = true; |
|
60 |
} |
|
61 |
||
62 |
||
63 |
void AllocationProfiler::disengage() { |
|
64 |
_active = false; |
|
65 |
} |
|
66 |
||
67 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
68 |
void AllocationProfiler::add_class_to_array(Klass* k) { |
1 | 69 |
_print_array->append(k); |
70 |
} |
|
71 |
||
72 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
73 |
void AllocationProfiler::add_classes_to_array(Klass* k) { |
1 | 74 |
// Iterate over klass and all array klasses for klass |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
75 |
k->with_array_klasses_do(&AllocationProfiler::add_class_to_array); |
1 | 76 |
} |
77 |
||
78 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
79 |
int AllocationProfiler::compare_classes(Klass** k1, Klass** k2) { |
1 | 80 |
// Sort by total allocation size |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
81 |
return (*k2)->alloc_size() - (*k1)->alloc_size(); |
1 | 82 |
} |
83 |
||
84 |
||
85 |
int AllocationProfiler::average(size_t alloc_size, int alloc_count) { |
|
86 |
return (int) ((double) (alloc_size * BytesPerWord) / MAX2(alloc_count, 1) + 0.5); |
|
87 |
} |
|
88 |
||
89 |
||
90 |
void AllocationProfiler::sort_and_print_array(size_t cutoff) { |
|
91 |
_print_array->sort(&AllocationProfiler::compare_classes); |
|
92 |
tty->print_cr("________________Size" |
|
93 |
"__Instances" |
|
94 |
"__Average" |
|
95 |
"__Class________________"); |
|
96 |
size_t total_alloc_size = 0; |
|
97 |
int total_alloc_count = 0; |
|
98 |
for (int index = 0; index < _print_array->length(); index++) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
99 |
Klass* k = _print_array->at(index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
100 |
size_t alloc_size = k->alloc_size(); |
1 | 101 |
if (alloc_size > cutoff) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
102 |
int alloc_count = k->alloc_count(); |
1 | 103 |
#ifdef PRODUCT |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
104 |
const char* name = k->external_name(); |
1 | 105 |
#else |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
106 |
const char* name = k->internal_name(); |
1 | 107 |
#endif |
108 |
tty->print_cr("%20u %10u %8u %s", |
|
109 |
alloc_size * BytesPerWord, |
|
110 |
alloc_count, |
|
111 |
average(alloc_size, alloc_count), |
|
112 |
name); |
|
113 |
total_alloc_size += alloc_size; |
|
114 |
total_alloc_count += alloc_count; |
|
115 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
116 |
k->set_alloc_count(0); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
117 |
k->set_alloc_size(0); |
1 | 118 |
} |
119 |
tty->print_cr("%20u %10u %8u --total--", |
|
120 |
total_alloc_size * BytesPerWord, |
|
121 |
total_alloc_count, |
|
122 |
average(total_alloc_size, total_alloc_count)); |
|
123 |
tty->cr(); |
|
124 |
} |
|
125 |
||
126 |
||
127 |
void AllocationProfiler::print(size_t cutoff) { |
|
128 |
ResourceMark rm; |
|
129 |
assert(!is_active(), "AllocationProfiler cannot be active while printing profile"); |
|
130 |
||
131 |
tty->cr(); |
|
15228
e92acc84ade3
7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents:
13728
diff
changeset
|
132 |
tty->print_cr("Allocation profile (sizes in bytes, cutoff = " SIZE_FORMAT " bytes):", cutoff * BytesPerWord); |
1 | 133 |
tty->cr(); |
134 |
||
135 |
// Print regular instance klasses and basic type array klasses |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
136 |
_print_array = new GrowableArray<Klass*>(SystemDictionary::number_of_classes()*2); |
1 | 137 |
SystemDictionary::classes_do(&add_classes_to_array); |
138 |
Universe::basic_type_classes_do(&add_classes_to_array); |
|
139 |
sort_and_print_array(cutoff); |
|
140 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
141 |
// This used to print metadata in the permgen but since there isn't a permgen |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
142 |
// anymore, it is not yet implemented. |
1 | 143 |
} |