author | coleenp |
Tue, 19 Dec 2017 06:29:17 -0500 | |
changeset 48468 | 7cc7de9bf4a4 |
parent 48105 | 8d15b1369c7a |
child 48873 | 9536c39ac6de |
permissions | -rw-r--r-- |
1 | 1 |
/* |
46729 | 2 |
* Copyright (c) 1998, 2017, 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:
5403
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5403
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:
5403
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/systemDictionary.hpp" |
|
27 |
#include "code/codeCache.hpp" |
|
30764 | 28 |
#include "gc/shared/collectedHeap.inline.hpp" |
29 |
#include "gc/shared/generation.hpp" |
|
7397 | 30 |
#include "interpreter/oopMapCache.hpp" |
31 |
#include "memory/resourceArea.hpp" |
|
32 |
#include "runtime/handles.inline.hpp" |
|
33 |
#include "runtime/jniHandles.hpp" |
|
34 |
#include "runtime/memprofiler.hpp" |
|
35 |
#include "runtime/mutexLocker.hpp" |
|
36 |
#include "runtime/os.hpp" |
|
37 |
#include "runtime/task.hpp" |
|
14583
d70ee55535f4
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
13728
diff
changeset
|
38 |
#include "runtime/thread.inline.hpp" |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47216
diff
changeset
|
39 |
#include "runtime/threadSMR.hpp" |
7397 | 40 |
#include "runtime/vmThread.hpp" |
1 | 41 |
|
42 |
#ifndef PRODUCT |
|
43 |
||
44 |
// -------------------------------------------------------- |
|
45 |
// MemProfilerTask |
|
46 |
||
47 |
class MemProfilerTask : public PeriodicTask { |
|
48 |
public: |
|
49 |
MemProfilerTask(int interval_time) : PeriodicTask(interval_time) {} |
|
50 |
void task(); |
|
51 |
}; |
|
52 |
||
53 |
||
54 |
void MemProfilerTask::task() { |
|
55 |
MemProfiler::do_trace(); |
|
56 |
} |
|
57 |
||
58 |
||
59 |
//---------------------------------------------------------- |
|
60 |
// Implementation of MemProfiler |
|
61 |
||
62 |
MemProfilerTask* MemProfiler::_task = NULL; |
|
63 |
FILE* MemProfiler::_log_fp = NULL; |
|
64 |
||
65 |
||
66 |
bool MemProfiler::is_active() { |
|
67 |
return _task != NULL; |
|
68 |
} |
|
69 |
||
70 |
||
71 |
void MemProfiler::engage() { |
|
72 |
const char *log_name = "mprofile.log"; |
|
73 |
if (!is_active()) { |
|
74 |
// Create log file |
|
75 |
_log_fp = fopen(log_name , "w+"); |
|
76 |
if (_log_fp == NULL) { |
|
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
30764
diff
changeset
|
77 |
fatal("MemProfiler: Cannot create log file: %s", log_name); |
1 | 78 |
} |
79 |
fprintf(_log_fp, "MemProfiler: sizes are in Kb, time is in seconds since startup\n\n"); |
|
80 |
fprintf(_log_fp, " time, #thr, #cls, heap, heap, perm, perm, code, hndls, rescs, oopmp\n"); |
|
81 |
fprintf(_log_fp, " used, total, used, total, total, total, total, total\n"); |
|
82 |
fprintf(_log_fp, "--------------------------------------------------------------------------\n"); |
|
83 |
||
84 |
_task = new MemProfilerTask(MemProfilingInterval); |
|
85 |
_task->enroll(); |
|
86 |
} |
|
87 |
} |
|
88 |
||
89 |
||
90 |
void MemProfiler::disengage() { |
|
91 |
if (!is_active()) return; |
|
92 |
// Do one last trace at disengage time |
|
93 |
do_trace(); |
|
94 |
||
95 |
// Close logfile |
|
96 |
fprintf(_log_fp, "MemProfiler detached\n"); |
|
97 |
fclose(_log_fp); |
|
98 |
||
99 |
// remove MemProfilerTask |
|
100 |
assert(_task != NULL, "sanity check"); |
|
101 |
_task->disenroll(); |
|
102 |
delete _task; |
|
103 |
_task = NULL; |
|
104 |
} |
|
105 |
||
106 |
||
107 |
void MemProfiler::do_trace() { |
|
108 |
// Calculate thread local sizes |
|
109 |
size_t handles_memory_usage = VMThread::vm_thread()->handle_area()->size_in_bytes(); |
|
110 |
size_t resource_memory_usage = VMThread::vm_thread()->resource_area()->size_in_bytes(); |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47216
diff
changeset
|
111 |
{ |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47216
diff
changeset
|
112 |
JavaThreadIteratorWithHandle jtiwh; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47216
diff
changeset
|
113 |
for (; JavaThread *cur = jtiwh.next(); ) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47216
diff
changeset
|
114 |
handles_memory_usage += cur->handle_area()->size_in_bytes(); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47216
diff
changeset
|
115 |
resource_memory_usage += cur->resource_area()->size_in_bytes(); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47216
diff
changeset
|
116 |
} |
1 | 117 |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47216
diff
changeset
|
118 |
// Print trace line in log |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47216
diff
changeset
|
119 |
fprintf(_log_fp, "%6.1f,%5d,%5d," UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",", |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47216
diff
changeset
|
120 |
os::elapsedTime(), |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47216
diff
changeset
|
121 |
jtiwh.length(), |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47216
diff
changeset
|
122 |
InstanceKlass::number_of_instance_classes(), |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47216
diff
changeset
|
123 |
Universe::heap()->used() / K, |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47216
diff
changeset
|
124 |
Universe::heap()->capacity() / K); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47216
diff
changeset
|
125 |
} |
1 | 126 |
|
1889
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
127 |
fprintf(_log_fp, UINTX_FORMAT_W(6) ",", CodeCache::capacity() / K); |
1 | 128 |
|
1889
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
129 |
fprintf(_log_fp, UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",%6ld\n", |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
130 |
handles_memory_usage / K, |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
131 |
resource_memory_usage / K, |
46996 | 132 |
0L); |
1 | 133 |
fflush(_log_fp); |
134 |
} |
|
135 |
||
136 |
#endif |