Bug Summary

File:jdk/src/hotspot/share/code/codeHeapState.cpp
Warning:line 2422, column 16
Value stored to 'range_beg' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name codeHeapState.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/libjvm/objs/precompiled -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D _GNU_SOURCE -D _REENTRANT -D LIBC=gnu -D LINUX -D VM_LITTLE_ENDIAN -D _LP64=1 -D ASSERT -D CHECK_UNHANDLED_OOPS -D TARGET_ARCH_x86 -D INCLUDE_SUFFIX_OS=_linux -D INCLUDE_SUFFIX_CPU=_x86 -D INCLUDE_SUFFIX_COMPILER=_gcc -D TARGET_COMPILER_gcc -D AMD64 -D HOTSPOT_LIB_ARCH="amd64" -D COMPILER1 -D COMPILER2 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc/adfiles -I /home/daniel/Projects/java/jdk/src/hotspot/share -I /home/daniel/Projects/java/jdk/src/hotspot/os/linux -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix -I /home/daniel/Projects/java/jdk/src/hotspot/cpu/x86 -I /home/daniel/Projects/java/jdk/src/hotspot/os_cpu/linux_x86 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc -I /home/daniel/Projects/java/jdk/src/hotspot/share/precompiled -I /home/daniel/Projects/java/jdk/src/hotspot/share/include -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix/include -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base/linux -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libjimage -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc/adfiles -I /home/daniel/Projects/java/jdk/src/hotspot/share -I /home/daniel/Projects/java/jdk/src/hotspot/os/linux -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix -I /home/daniel/Projects/java/jdk/src/hotspot/cpu/x86 -I /home/daniel/Projects/java/jdk/src/hotspot/os_cpu/linux_x86 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc -D _FORTIFY_SOURCE=2 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-format-zero-length -Wno-unused-parameter -Wno-unused -Wno-parentheses -Wno-comment -Wno-unknown-pragmas -Wno-address -Wno-delete-non-virtual-dtor -Wno-char-subscripts -Wno-array-bounds -Wno-int-in-bool-context -Wno-ignored-qualifiers -Wno-missing-field-initializers -Wno-implicit-fallthrough -Wno-empty-body -Wno-strict-overflow -Wno-sequence-point -Wno-maybe-uninitialized -Wno-misleading-indentation -Wno-cast-function-type -Wno-shift-negative-value -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /home/daniel/Projects/java/jdk/make/hotspot -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -stack-protector 1 -fno-rtti -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /home/daniel/Projects/java/scan/2021-12-21-193737-8510-1 -x c++ /home/daniel/Projects/java/jdk/src/hotspot/share/code/codeHeapState.cpp
1/*
2 * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2018, 2019 SAP SE. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26#include "precompiled.hpp"
27#include "code/codeHeapState.hpp"
28#include "compiler/compileBroker.hpp"
29#include "oops/klass.inline.hpp"
30#include "runtime/safepoint.hpp"
31#include "runtime/sweeper.hpp"
32#include "utilities/powerOfTwo.hpp"
33
34// -------------------------
35// | General Description |
36// -------------------------
37// The CodeHeap state analytics are divided in two parts.
38// The first part examines the entire CodeHeap and aggregates all
39// information that is believed useful/important.
40//
41// Aggregation condenses the information of a piece of the CodeHeap
42// (4096 bytes by default) into an analysis granule. These granules
43// contain enough detail to gain initial insight while keeping the
44// internal structure sizes in check.
45//
46// The second part, which consists of several, independent steps,
47// prints the previously collected information with emphasis on
48// various aspects.
49//
50// The CodeHeap is a living thing. Therefore, protection against concurrent
51// modification (by acquiring the CodeCache_lock) is necessary. It has
52// to be provided by the caller of the analysis functions.
53// If the CodeCache_lock is not held, the analysis functions may print
54// less detailed information or may just do nothing. It is by intention
55// that an unprotected invocation is not abnormally terminated.
56//
57// Data collection and printing is done on an "on request" basis.
58// While no request is being processed, there is no impact on performance.
59// The CodeHeap state analytics do have some memory footprint.
60// The "aggregate" step allocates some data structures to hold the aggregated
61// information for later output. These data structures live until they are
62// explicitly discarded (function "discard") or until the VM terminates.
63// There is one exception: the function "all" does not leave any data
64// structures allocated.
65//
66// Requests for real-time, on-the-fly analysis can be issued via
67// jcmd <pid> Compiler.CodeHeap_Analytics [<function>] [<granularity>]
68//
69// If you are (only) interested in how the CodeHeap looks like after running
70// a sample workload, you can use the command line option
71// -XX:+PrintCodeHeapAnalytics
72// It will cause a full analysis to be written to tty. In addition, a full
73// analysis will be written the first time a "CodeCache full" condition is
74// detected.
75//
76// The command line option produces output identical to the jcmd function
77// jcmd <pid> Compiler.CodeHeap_Analytics all 4096
78// ---------------------------------------------------------------------------------
79
80// With this declaration macro, it is possible to switch between
81// - direct output into an argument-passed outputStream and
82// - buffered output into a bufferedStream with subsequent flush
83// of the filled buffer to the outputStream.
84#define USE_BUFFEREDSTREAM
85
86// There are instances when composing an output line or a small set of
87// output lines out of many tty->print() calls creates significant overhead.
88// Writing to a bufferedStream buffer first has a significant advantage:
89// It uses noticeably less cpu cycles and reduces (when writing to a
90// network file) the required bandwidth by at least a factor of ten. Observed on MacOS.
91// That clearly makes up for the increased code complexity.
92//
93// Conversion of existing code is easy and straightforward, if the code already
94// uses a parameterized output destination, e.g. "outputStream st".
95// - rename the formal parameter to any other name, e.g. out_st.
96// - at a suitable place in your code, insert
97// BUFFEREDSTEAM_DECL(buf_st, out_st)
98// This will provide all the declarations necessary. After that, all
99// buf_st->print() (and the like) calls will be directed to a bufferedStream object.
100// Once a block of output (a line or a small set of lines) is composed, insert
101// BUFFEREDSTREAM_FLUSH(termstring)
102// to flush the bufferedStream to the final destination out_st. termstring is just
103// an arbitrary string (e.g. "\n") which is appended to the bufferedStream before
104// being written to out_st. Be aware that the last character written MUST be a '\n'.
105// Otherwise, buf_st->position() does not correspond to out_st->position() any longer.
106// BUFFEREDSTREAM_FLUSH_LOCKED(termstring)
107// does the same thing, protected by the ttyLocker lock.
108// BUFFEREDSTREAM_FLUSH_IF(termstring, remSize)
109// does a flush only if the remaining buffer space is less than remSize.
110//
111// To activate, #define USE_BUFFERED_STREAM before including this header.
112// If not activated, output will directly go to the originally used outputStream
113// with no additional overhead.
114//
115#if defined(USE_BUFFEREDSTREAM)
116// All necessary declarations to print via a bufferedStream
117// This macro must be placed before any other BUFFEREDSTREAM*
118// macro in the function.
119#define BUFFEREDSTREAM_DECL_SIZE(_anyst, _outst, _capa)ResourceMark _rm; size_t _nflush = 0; size_t _nforcedflush = 0
; size_t _nsavedflush = 0; size_t _nlockedflush = 0; size_t _nflush_bytes
= 0; size_t _capacity = _capa; bufferedStream _sstobj(_capa)
; bufferedStream* _sstbuf = &_sstobj; outputStream* _outbuf
= _outst; bufferedStream* _anyst = &_sstobj;
\
120 ResourceMark _rm; \
121 /* _anyst name of the stream as used in the code */ \
122 /* _outst stream where final output will go to */ \
123 /* _capa allocated capacity of stream buffer */ \
124 size_t _nflush = 0; \
125 size_t _nforcedflush = 0; \
126 size_t _nsavedflush = 0; \
127 size_t _nlockedflush = 0; \
128 size_t _nflush_bytes = 0; \
129 size_t _capacity = _capa; \
130 bufferedStream _sstobj(_capa); \
131 bufferedStream* _sstbuf = &_sstobj; \
132 outputStream* _outbuf = _outst; \
133 bufferedStream* _anyst = &_sstobj; /* any stream. Use this to just print - no buffer flush. */
134
135// Same as above, but with fixed buffer size.
136#define BUFFEREDSTREAM_DECL(_anyst, _outst)ResourceMark _rm; size_t _nflush = 0; size_t _nforcedflush = 0
; size_t _nsavedflush = 0; size_t _nlockedflush = 0; size_t _nflush_bytes
= 0; size_t _capacity = 4*K; bufferedStream _sstobj(4*K); bufferedStream
* _sstbuf = &_sstobj; outputStream* _outbuf = _outst; bufferedStream
* _anyst = &_sstobj;;
\
137 BUFFEREDSTREAM_DECL_SIZE(_anyst, _outst, 4*K)ResourceMark _rm; size_t _nflush = 0; size_t _nforcedflush = 0
; size_t _nsavedflush = 0; size_t _nlockedflush = 0; size_t _nflush_bytes
= 0; size_t _capacity = 4*K; bufferedStream _sstobj(4*K); bufferedStream
* _sstbuf = &_sstobj; outputStream* _outbuf = _outst; bufferedStream
* _anyst = &_sstobj;
;
138
139// Flush the buffer contents unconditionally.
140// No action if the buffer is empty.
141#define BUFFEREDSTREAM_FLUSH(_termString)if (((_termString) != __null) && (strlen(_termString)
> 0)){ _sstbuf->print("%s", _termString); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } }
\
142 if (((_termString) != NULL__null) && (strlen(_termString) > 0)){\
143 _sstbuf->print("%s", _termString); \
144 } \
145 if (_sstbuf != _outbuf) { \
146 if (_sstbuf->size() != 0) { \
147 _nforcedflush++; _nflush_bytes += _sstbuf->size(); \
148 _outbuf->print("%s", _sstbuf->as_string()); \
149 _sstbuf->reset(); \
150 } \
151 }
152
153// Flush the buffer contents if the remaining capacity is
154// less than the given threshold.
155#define BUFFEREDSTREAM_FLUSH_IF(_termString, _remSize)if (((_termString) != __null) && (strlen(_termString)
> 0)){ _sstbuf->print("%s", _termString); } if (_sstbuf
!= _outbuf) { if ((_capacity - _sstbuf->size()) < (size_t
)(_remSize)){ _nflush++; _nforcedflush--; if ((("") != __null
) && (strlen("") > 0)){ _sstbuf->print("%s", ""
); } if (_sstbuf != _outbuf) { if (_sstbuf->size() != 0) {
_nforcedflush++; _nflush_bytes += _sstbuf->size(); _outbuf
->print("%s", _sstbuf->as_string()); _sstbuf->reset(
); } } } else { _nsavedflush++; } }
\
156 if (((_termString) != NULL__null) && (strlen(_termString) > 0)){\
157 _sstbuf->print("%s", _termString); \
158 } \
159 if (_sstbuf != _outbuf) { \
160 if ((_capacity - _sstbuf->size()) < (size_t)(_remSize)){\
161 _nflush++; _nforcedflush--; \
162 BUFFEREDSTREAM_FLUSH("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if (_sstbuf
->size() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf
->size(); _outbuf->print("%s", _sstbuf->as_string())
; _sstbuf->reset(); } }
\
163 } else { \
164 _nsavedflush++; \
165 } \
166 }
167
168// Flush the buffer contents if the remaining capacity is less
169// than the calculated threshold (256 bytes + capacity/16)
170// That should suffice for all reasonably sized output lines.
171#define BUFFEREDSTREAM_FLUSH_AUTO(_termString)if (((_termString) != __null) && (strlen(_termString)
> 0)){ _sstbuf->print("%s", _termString); } if (_sstbuf
!= _outbuf) { if ((_capacity - _sstbuf->size()) < (size_t
)(256+(_capacity>>4))){ _nflush++; _nforcedflush--; if (
(("") != __null) && (strlen("") > 0)){ _sstbuf->
print("%s", ""); } if (_sstbuf != _outbuf) { if (_sstbuf->
size() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->
size(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } } else { _nsavedflush++; } }
\
172 BUFFEREDSTREAM_FLUSH_IF(_termString, 256+(_capacity>>4))if (((_termString) != __null) && (strlen(_termString)
> 0)){ _sstbuf->print("%s", _termString); } if (_sstbuf
!= _outbuf) { if ((_capacity - _sstbuf->size()) < (size_t
)(256+(_capacity>>4))){ _nflush++; _nforcedflush--; if (
(("") != __null) && (strlen("") > 0)){ _sstbuf->
print("%s", ""); } if (_sstbuf != _outbuf) { if (_sstbuf->
size() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->
size(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } } else { _nsavedflush++; } }
173
174#define BUFFEREDSTREAM_FLUSH_LOCKED(_termString){ ttyLocker ttyl; _nlockedflush++; if (((_termString) != __null
) && (strlen(_termString) > 0)){ _sstbuf->print
("%s", _termString); } if (_sstbuf != _outbuf) { if (_sstbuf->
size() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->
size(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
\
175 { ttyLocker ttyl;/* keep this output block together */ \
176 _nlockedflush++; \
177 BUFFEREDSTREAM_FLUSH(_termString)if (((_termString) != __null) && (strlen(_termString)
> 0)){ _sstbuf->print("%s", _termString); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } }
\
178 }
179
180// #define BUFFEREDSTREAM_FLUSH_STAT() \
181// if (_sstbuf != _outbuf) { \
182// _outbuf->print_cr("%ld flushes (buffer full), %ld forced, %ld locked, %ld bytes total, %ld flushes saved", _nflush, _nforcedflush, _nlockedflush, _nflush_bytes, _nsavedflush); \
183// }
184
185#define BUFFEREDSTREAM_FLUSH_STAT()
186#else
187#define BUFFEREDSTREAM_DECL_SIZE(_anyst, _outst, _capa)ResourceMark _rm; size_t _nflush = 0; size_t _nforcedflush = 0
; size_t _nsavedflush = 0; size_t _nlockedflush = 0; size_t _nflush_bytes
= 0; size_t _capacity = _capa; bufferedStream _sstobj(_capa)
; bufferedStream* _sstbuf = &_sstobj; outputStream* _outbuf
= _outst; bufferedStream* _anyst = &_sstobj;
\
188 size_t _capacity = _capa; \
189 outputStream* _outbuf = _outst; \
190 outputStream* _anyst = _outst; /* any stream. Use this to just print - no buffer flush. */
191
192#define BUFFEREDSTREAM_DECL(_anyst, _outst)ResourceMark _rm; size_t _nflush = 0; size_t _nforcedflush = 0
; size_t _nsavedflush = 0; size_t _nlockedflush = 0; size_t _nflush_bytes
= 0; size_t _capacity = 4*K; bufferedStream _sstobj(4*K); bufferedStream
* _sstbuf = &_sstobj; outputStream* _outbuf = _outst; bufferedStream
* _anyst = &_sstobj;;
\
193 BUFFEREDSTREAM_DECL_SIZE(_anyst, _outst, 4*K)ResourceMark _rm; size_t _nflush = 0; size_t _nforcedflush = 0
; size_t _nsavedflush = 0; size_t _nlockedflush = 0; size_t _nflush_bytes
= 0; size_t _capacity = 4*K; bufferedStream _sstobj(4*K); bufferedStream
* _sstbuf = &_sstobj; outputStream* _outbuf = _outst; bufferedStream
* _anyst = &_sstobj;
194
195#define BUFFEREDSTREAM_FLUSH(_termString)if (((_termString) != __null) && (strlen(_termString)
> 0)){ _sstbuf->print("%s", _termString); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } }
\
196 if (((_termString) != NULL__null) && (strlen(_termString) > 0)){\
197 _outbuf->print("%s", _termString); \
198 }
199
200#define BUFFEREDSTREAM_FLUSH_IF(_termString, _remSize)if (((_termString) != __null) && (strlen(_termString)
> 0)){ _sstbuf->print("%s", _termString); } if (_sstbuf
!= _outbuf) { if ((_capacity - _sstbuf->size()) < (size_t
)(_remSize)){ _nflush++; _nforcedflush--; if ((("") != __null
) && (strlen("") > 0)){ _sstbuf->print("%s", ""
); } if (_sstbuf != _outbuf) { if (_sstbuf->size() != 0) {
_nforcedflush++; _nflush_bytes += _sstbuf->size(); _outbuf
->print("%s", _sstbuf->as_string()); _sstbuf->reset(
); } } } else { _nsavedflush++; } }
\
201 BUFFEREDSTREAM_FLUSH(_termString)if (((_termString) != __null) && (strlen(_termString)
> 0)){ _sstbuf->print("%s", _termString); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } }
202
203#define BUFFEREDSTREAM_FLUSH_AUTO(_termString)if (((_termString) != __null) && (strlen(_termString)
> 0)){ _sstbuf->print("%s", _termString); } if (_sstbuf
!= _outbuf) { if ((_capacity - _sstbuf->size()) < (size_t
)(256+(_capacity>>4))){ _nflush++; _nforcedflush--; if (
(("") != __null) && (strlen("") > 0)){ _sstbuf->
print("%s", ""); } if (_sstbuf != _outbuf) { if (_sstbuf->
size() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->
size(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } } else { _nsavedflush++; } }
\
204 BUFFEREDSTREAM_FLUSH(_termString)if (((_termString) != __null) && (strlen(_termString)
> 0)){ _sstbuf->print("%s", _termString); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } }
205
206#define BUFFEREDSTREAM_FLUSH_LOCKED(_termString){ ttyLocker ttyl; _nlockedflush++; if (((_termString) != __null
) && (strlen(_termString) > 0)){ _sstbuf->print
("%s", _termString); } if (_sstbuf != _outbuf) { if (_sstbuf->
size() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->
size(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
\
207 BUFFEREDSTREAM_FLUSH(_termString)if (((_termString) != __null) && (strlen(_termString)
> 0)){ _sstbuf->print("%s", _termString); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } }
208
209#define BUFFEREDSTREAM_FLUSH_STAT()
210#endif
211#define HEX32_FORMAT"0x%x" "0x%x" // just a helper format string used below multiple times
212
213const char blobTypeChar[] = {' ', 'C', 'N', 'I', 'X', 'Z', 'U', 'R', '?', 'D', 'T', 'E', 'S', 'A', 'M', 'B', 'L' };
214const char* blobTypeName[] = {"noType"
215 , "nMethod (under construction), cannot be observed"
216 , "nMethod (active)"
217 , "nMethod (inactive)"
218 , "nMethod (deopt)"
219 , "nMethod (zombie)"
220 , "nMethod (unloaded)"
221 , "runtime stub"
222 , "ricochet stub"
223 , "deopt stub"
224 , "uncommon trap stub"
225 , "exception stub"
226 , "safepoint stub"
227 , "adapter blob"
228 , "MH adapter blob"
229 , "buffer blob"
230 , "lastType"
231 };
232const char* compTypeName[] = { "none", "c1", "c2", "jvmci" };
233
234// Be prepared for ten different CodeHeap segments. Should be enough for a few years.
235const unsigned int nSizeDistElements = 31; // logarithmic range growth, max size: 2**32
236const unsigned int maxTopSizeBlocks = 100;
237const unsigned int tsbStopper = 2 * maxTopSizeBlocks;
238const unsigned int maxHeaps = 10;
239static unsigned int nHeaps = 0;
240static struct CodeHeapStat CodeHeapStatArray[maxHeaps];
241
242// static struct StatElement *StatArray = NULL;
243static StatElement* StatArray = NULL__null;
244static int log2_seg_size = 0;
245static size_t seg_size = 0;
246static size_t alloc_granules = 0;
247static size_t granule_size = 0;
248static bool segment_granules = false;
249static unsigned int nBlocks_t1 = 0; // counting "in_use" nmethods only.
250static unsigned int nBlocks_t2 = 0; // counting "in_use" nmethods only.
251static unsigned int nBlocks_alive = 0; // counting "not_used" and "not_entrant" nmethods only.
252static unsigned int nBlocks_dead = 0; // counting "zombie" and "unloaded" methods only.
253static unsigned int nBlocks_unloaded = 0; // counting "unloaded" nmethods only. This is a transient state.
254static unsigned int nBlocks_stub = 0;
255
256static struct FreeBlk* FreeArray = NULL__null;
257static unsigned int alloc_freeBlocks = 0;
258
259static struct TopSizeBlk* TopSizeArray = NULL__null;
260static unsigned int alloc_topSizeBlocks = 0;
261static unsigned int used_topSizeBlocks = 0;
262
263static struct SizeDistributionElement* SizeDistributionArray = NULL__null;
264
265// nMethod temperature (hotness) indicators.
266static int avgTemp = 0;
267static int maxTemp = 0;
268static int minTemp = 0;
269
270static unsigned int latest_compilation_id = 0;
271static volatile bool initialization_complete = false;
272
273const char* CodeHeapState::get_heapName(CodeHeap* heap) {
274 if (SegmentedCodeCache) {
275 return heap->name();
276 } else {
277 return "CodeHeap";
278 }
279}
280
281// returns the index for the heap being processed.
282unsigned int CodeHeapState::findHeapIndex(outputStream* out, const char* heapName) {
283 if (heapName == NULL__null) {
284 return maxHeaps;
285 }
286 if (SegmentedCodeCache) {
287 // Search for a pre-existing entry. If found, return that index.
288 for (unsigned int i = 0; i < nHeaps; i++) {
289 if (CodeHeapStatArray[i].heapName != NULL__null && strcmp(heapName, CodeHeapStatArray[i].heapName) == 0) {
290 return i;
291 }
292 }
293
294 // check if there are more code heap segments than we can handle.
295 if (nHeaps == maxHeaps) {
296 out->print_cr("Too many heap segments for current limit(%d).", maxHeaps);
297 return maxHeaps;
298 }
299
300 // allocate new slot in StatArray.
301 CodeHeapStatArray[nHeaps].heapName = heapName;
302 return nHeaps++;
303 } else {
304 nHeaps = 1;
305 CodeHeapStatArray[0].heapName = heapName;
306 return 0; // This is the default index if CodeCache is not segmented.
307 }
308}
309
310void CodeHeapState::get_HeapStatGlobals(outputStream* out, const char* heapName) {
311 unsigned int ix = findHeapIndex(out, heapName);
312 if (ix < maxHeaps) {
313 StatArray = CodeHeapStatArray[ix].StatArray;
314 seg_size = CodeHeapStatArray[ix].segment_size;
315 log2_seg_size = seg_size == 0 ? 0 : exact_log2(seg_size);
316 alloc_granules = CodeHeapStatArray[ix].alloc_granules;
317 granule_size = CodeHeapStatArray[ix].granule_size;
318 segment_granules = CodeHeapStatArray[ix].segment_granules;
319 nBlocks_t1 = CodeHeapStatArray[ix].nBlocks_t1;
320 nBlocks_t2 = CodeHeapStatArray[ix].nBlocks_t2;
321 nBlocks_alive = CodeHeapStatArray[ix].nBlocks_alive;
322 nBlocks_dead = CodeHeapStatArray[ix].nBlocks_dead;
323 nBlocks_unloaded = CodeHeapStatArray[ix].nBlocks_unloaded;
324 nBlocks_stub = CodeHeapStatArray[ix].nBlocks_stub;
325 FreeArray = CodeHeapStatArray[ix].FreeArray;
326 alloc_freeBlocks = CodeHeapStatArray[ix].alloc_freeBlocks;
327 TopSizeArray = CodeHeapStatArray[ix].TopSizeArray;
328 alloc_topSizeBlocks = CodeHeapStatArray[ix].alloc_topSizeBlocks;
329 used_topSizeBlocks = CodeHeapStatArray[ix].used_topSizeBlocks;
330 SizeDistributionArray = CodeHeapStatArray[ix].SizeDistributionArray;
331 avgTemp = CodeHeapStatArray[ix].avgTemp;
332 maxTemp = CodeHeapStatArray[ix].maxTemp;
333 minTemp = CodeHeapStatArray[ix].minTemp;
334 } else {
335 StatArray = NULL__null;
336 seg_size = 0;
337 log2_seg_size = 0;
338 alloc_granules = 0;
339 granule_size = 0;
340 segment_granules = false;
341 nBlocks_t1 = 0;
342 nBlocks_t2 = 0;
343 nBlocks_alive = 0;
344 nBlocks_dead = 0;
345 nBlocks_unloaded = 0;
346 nBlocks_stub = 0;
347 FreeArray = NULL__null;
348 alloc_freeBlocks = 0;
349 TopSizeArray = NULL__null;
350 alloc_topSizeBlocks = 0;
351 used_topSizeBlocks = 0;
352 SizeDistributionArray = NULL__null;
353 avgTemp = 0;
354 maxTemp = 0;
355 minTemp = 0;
356 }
357}
358
359void CodeHeapState::set_HeapStatGlobals(outputStream* out, const char* heapName) {
360 unsigned int ix = findHeapIndex(out, heapName);
361 if (ix < maxHeaps) {
362 CodeHeapStatArray[ix].StatArray = StatArray;
363 CodeHeapStatArray[ix].segment_size = seg_size;
364 CodeHeapStatArray[ix].alloc_granules = alloc_granules;
365 CodeHeapStatArray[ix].granule_size = granule_size;
366 CodeHeapStatArray[ix].segment_granules = segment_granules;
367 CodeHeapStatArray[ix].nBlocks_t1 = nBlocks_t1;
368 CodeHeapStatArray[ix].nBlocks_t2 = nBlocks_t2;
369 CodeHeapStatArray[ix].nBlocks_alive = nBlocks_alive;
370 CodeHeapStatArray[ix].nBlocks_dead = nBlocks_dead;
371 CodeHeapStatArray[ix].nBlocks_unloaded = nBlocks_unloaded;
372 CodeHeapStatArray[ix].nBlocks_stub = nBlocks_stub;
373 CodeHeapStatArray[ix].FreeArray = FreeArray;
374 CodeHeapStatArray[ix].alloc_freeBlocks = alloc_freeBlocks;
375 CodeHeapStatArray[ix].TopSizeArray = TopSizeArray;
376 CodeHeapStatArray[ix].alloc_topSizeBlocks = alloc_topSizeBlocks;
377 CodeHeapStatArray[ix].used_topSizeBlocks = used_topSizeBlocks;
378 CodeHeapStatArray[ix].SizeDistributionArray = SizeDistributionArray;
379 CodeHeapStatArray[ix].avgTemp = avgTemp;
380 CodeHeapStatArray[ix].maxTemp = maxTemp;
381 CodeHeapStatArray[ix].minTemp = minTemp;
382 }
383}
384
385//---< get a new statistics array >---
386void CodeHeapState::prepare_StatArray(outputStream* out, size_t nElem, size_t granularity, const char* heapName) {
387 if (StatArray == NULL__null) {
388 StatArray = new StatElement[nElem];
389 //---< reset some counts >---
390 alloc_granules = nElem;
391 granule_size = granularity;
392 }
393
394 if (StatArray == NULL__null) {
395 //---< just do nothing if allocation failed >---
396 out->print_cr("Statistics could not be collected for %s, probably out of memory.", heapName);
397 out->print_cr("Current granularity is " SIZE_FORMAT"%" "l" "u" " bytes. Try a coarser granularity.", granularity);
398 alloc_granules = 0;
399 granule_size = 0;
400 } else {
401 //---< initialize statistics array >---
402 memset((void*)StatArray, 0, nElem*sizeof(StatElement));
403 }
404}
405
406//---< get a new free block array >---
407void CodeHeapState::prepare_FreeArray(outputStream* out, unsigned int nElem, const char* heapName) {
408 if (FreeArray == NULL__null) {
409 FreeArray = new FreeBlk[nElem];
410 //---< reset some counts >---
411 alloc_freeBlocks = nElem;
412 }
413
414 if (FreeArray == NULL__null) {
415 //---< just do nothing if allocation failed >---
416 out->print_cr("Free space analysis cannot be done for %s, probably out of memory.", heapName);
417 alloc_freeBlocks = 0;
418 } else {
419 //---< initialize free block array >---
420 memset((void*)FreeArray, 0, alloc_freeBlocks*sizeof(FreeBlk));
421 }
422}
423
424//---< get a new TopSizeArray >---
425void CodeHeapState::prepare_TopSizeArray(outputStream* out, unsigned int nElem, const char* heapName) {
426 if (TopSizeArray == NULL__null) {
427 TopSizeArray = new TopSizeBlk[nElem];
428 //---< reset some counts >---
429 alloc_topSizeBlocks = nElem;
430 used_topSizeBlocks = 0;
431 }
432
433 if (TopSizeArray == NULL__null) {
434 //---< just do nothing if allocation failed >---
435 out->print_cr("Top-%d list of largest CodeHeap blocks can not be collected for %s, probably out of memory.", nElem, heapName);
436 alloc_topSizeBlocks = 0;
437 } else {
438 //---< initialize TopSizeArray >---
439 memset((void*)TopSizeArray, 0, nElem*sizeof(TopSizeBlk));
440 used_topSizeBlocks = 0;
441 }
442}
443
444//---< get a new SizeDistributionArray >---
445void CodeHeapState::prepare_SizeDistArray(outputStream* out, unsigned int nElem, const char* heapName) {
446 if (SizeDistributionArray == NULL__null) {
447 SizeDistributionArray = new SizeDistributionElement[nElem];
448 }
449
450 if (SizeDistributionArray == NULL__null) {
451 //---< just do nothing if allocation failed >---
452 out->print_cr("Size distribution can not be collected for %s, probably out of memory.", heapName);
453 } else {
454 //---< initialize SizeDistArray >---
455 memset((void*)SizeDistributionArray, 0, nElem*sizeof(SizeDistributionElement));
456 // Logarithmic range growth. First range starts at _segment_size.
457 SizeDistributionArray[log2_seg_size-1].rangeEnd = 1U;
458 for (unsigned int i = log2_seg_size; i < nElem; i++) {
459 SizeDistributionArray[i].rangeStart = 1U << (i - log2_seg_size);
460 SizeDistributionArray[i].rangeEnd = 1U << ((i+1) - log2_seg_size);
461 }
462 }
463}
464
465//---< get a new SizeDistributionArray >---
466void CodeHeapState::update_SizeDistArray(outputStream* out, unsigned int len) {
467 if (SizeDistributionArray != NULL__null) {
468 for (unsigned int i = log2_seg_size-1; i < nSizeDistElements; i++) {
469 if ((SizeDistributionArray[i].rangeStart <= len) && (len < SizeDistributionArray[i].rangeEnd)) {
470 SizeDistributionArray[i].lenSum += len;
471 SizeDistributionArray[i].count++;
472 break;
473 }
474 }
475 }
476}
477
478void CodeHeapState::discard_StatArray(outputStream* out) {
479 if (StatArray != NULL__null) {
480 delete StatArray;
481 StatArray = NULL__null;
482 alloc_granules = 0;
483 granule_size = 0;
484 }
485}
486
487void CodeHeapState::discard_FreeArray(outputStream* out) {
488 if (FreeArray != NULL__null) {
489 delete[] FreeArray;
490 FreeArray = NULL__null;
491 alloc_freeBlocks = 0;
492 }
493}
494
495void CodeHeapState::discard_TopSizeArray(outputStream* out) {
496 if (TopSizeArray != NULL__null) {
497 for (unsigned int i = 0; i < alloc_topSizeBlocks; i++) {
498 if (TopSizeArray[i].blob_name != NULL__null) {
499 os::free((void*)TopSizeArray[i].blob_name);
500 }
501 }
502 delete[] TopSizeArray;
503 TopSizeArray = NULL__null;
504 alloc_topSizeBlocks = 0;
505 used_topSizeBlocks = 0;
506 }
507}
508
509void CodeHeapState::discard_SizeDistArray(outputStream* out) {
510 if (SizeDistributionArray != NULL__null) {
511 delete[] SizeDistributionArray;
512 SizeDistributionArray = NULL__null;
513 }
514}
515
516// Discard all allocated internal data structures.
517// This should be done after an analysis session is completed.
518void CodeHeapState::discard(outputStream* out, CodeHeap* heap) {
519 if (!initialization_complete) {
520 return;
521 }
522
523 if (nHeaps > 0) {
524 for (unsigned int ix = 0; ix < nHeaps; ix++) {
525 get_HeapStatGlobals(out, CodeHeapStatArray[ix].heapName);
526 discard_StatArray(out);
527 discard_FreeArray(out);
528 discard_TopSizeArray(out);
529 discard_SizeDistArray(out);
530 set_HeapStatGlobals(out, CodeHeapStatArray[ix].heapName);
531 CodeHeapStatArray[ix].heapName = NULL__null;
532 }
533 nHeaps = 0;
534 }
535}
536
537void CodeHeapState::aggregate(outputStream* out, CodeHeap* heap, size_t granularity) {
538 unsigned int nBlocks_free = 0;
539 unsigned int nBlocks_used = 0;
540 unsigned int nBlocks_zomb = 0;
541 unsigned int nBlocks_disconn = 0;
542 unsigned int nBlocks_notentr = 0;
543
544 //---< max & min of TopSizeArray >---
545 // it is sufficient to have these sizes as 32bit unsigned ints.
546 // The CodeHeap is limited in size to 4GB. Furthermore, the sizes
547 // are stored in _segment_size units, scaling them down by a factor of 64 (at least).
548 unsigned int currMax = 0;
549 unsigned int currMin = 0;
550 unsigned int currMin_ix = 0;
551 unsigned long total_iterations = 0;
552
553 bool done = false;
554 const int min_granules = 256;
555 const int max_granules = 512*K; // limits analyzable CodeHeap (with segment_granules) to 32M..128M
556 // results in StatArray size of 24M (= max_granules * 48 Bytes per element)
557 // For a 1GB CodeHeap, the granule size must be at least 2kB to not violate the max_granles limit.
558 const char* heapName = get_heapName(heap);
559 BUFFEREDSTREAM_DECL(ast, out)ResourceMark _rm; size_t _nflush = 0; size_t _nforcedflush = 0
; size_t _nsavedflush = 0; size_t _nlockedflush = 0; size_t _nflush_bytes
= 0; size_t _capacity = 4*K; bufferedStream _sstobj(4*K); bufferedStream
* _sstbuf = &_sstobj; outputStream* _outbuf = out; bufferedStream
* ast = &_sstobj;;
560
561 if (!initialization_complete) {
562 memset(CodeHeapStatArray, 0, sizeof(CodeHeapStatArray));
563 initialization_complete = true;
564
565 printBox(ast, '=', "C O D E H E A P A N A L Y S I S (general remarks)", NULL__null);
566 ast->print_cr(" The code heap analysis function provides deep insights into\n"
567 " the inner workings and the internal state of the Java VM's\n"
568 " code cache - the place where all the JVM generated machine\n"
569 " code is stored.\n"
570 " \n"
571 " This function is designed and provided for support engineers\n"
572 " to help them understand and solve issues in customer systems.\n"
573 " It is not intended for use and interpretation by other persons.\n"
574 " \n");
575 BUFFEREDSTREAM_FLUSH("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if (_sstbuf
->size() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf
->size(); _outbuf->print("%s", _sstbuf->as_string())
; _sstbuf->reset(); } }
576 }
577 get_HeapStatGlobals(out, heapName);
578
579
580 // Since we are (and must be) analyzing the CodeHeap contents under the CodeCache_lock,
581 // all heap information is "constant" and can be safely extracted/calculated before we
582 // enter the while() loop. Actually, the loop will only be iterated once.
583 char* low_bound = heap->low_boundary();
584 size_t size = heap->capacity();
585 size_t res_size = heap->max_capacity();
586 seg_size = heap->segment_size();
587 log2_seg_size = seg_size == 0 ? 0 : exact_log2(seg_size); // This is a global static value.
588
589 if (seg_size == 0) {
590 printBox(ast, '-', "Heap not fully initialized yet, segment size is zero for segment ", heapName);
591 BUFFEREDSTREAM_FLUSH("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if (_sstbuf
->size() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf
->size(); _outbuf->print("%s", _sstbuf->as_string())
; _sstbuf->reset(); } }
592 return;
593 }
594
595 if (!holding_required_locks()) {
596 printBox(ast, '-', "Must be at safepoint or hold Compile_lock and CodeCache_lock when calling aggregate function for ", heapName);
597 BUFFEREDSTREAM_FLUSH("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if (_sstbuf
->size() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf
->size(); _outbuf->print("%s", _sstbuf->as_string())
; _sstbuf->reset(); } }
598 return;
599 }
600
601 // Calculate granularity of analysis (and output).
602 // The CodeHeap is managed (allocated) in segments (units) of CodeCacheSegmentSize.
603 // The CodeHeap can become fairly large, in particular in productive real-life systems.
604 //
605 // It is often neither feasible nor desirable to aggregate the data with the highest possible
606 // level of detail, i.e. inspecting and printing each segment on its own.
607 //
608 // The granularity parameter allows to specify the level of detail available in the analysis.
609 // It must be a positive multiple of the segment size and should be selected such that enough
610 // detail is provided while, at the same time, the printed output does not explode.
611 //
612 // By manipulating the granularity value, we enforce that at least min_granules units
613 // of analysis are available. We also enforce an upper limit of max_granules units to
614 // keep the amount of allocated storage in check.
615 //
616 // Finally, we adjust the granularity such that each granule covers at most 64k-1 segments.
617 // This is necessary to prevent an unsigned short overflow while accumulating space information.
618 //
619 assert(granularity > 0, "granularity should be positive.")do { if (!(granularity > 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/code/codeHeapState.cpp"
, 619, "assert(" "granularity > 0" ") failed", "granularity should be positive."
); ::breakpoint(); } } while (0)
;
620
621 if (granularity > size) {
622 granularity = size;
623 }
624 if (size/granularity < min_granules) {
625 granularity = size/min_granules; // at least min_granules granules
626 }
627 granularity = granularity & (~(seg_size - 1)); // must be multiple of seg_size
628 if (granularity < seg_size) {
629 granularity = seg_size; // must be at least seg_size
630 }
631 if (size/granularity > max_granules) {
632 granularity = size/max_granules; // at most max_granules granules
633 }
634 granularity = granularity & (~(seg_size - 1)); // must be multiple of seg_size
635 if (granularity>>log2_seg_size >= (1L<<sizeof(unsigned short)*8)) {
636 granularity = ((1L<<(sizeof(unsigned short)*8))-1)<<log2_seg_size; // Limit: (64k-1) * seg_size
637 }
638 segment_granules = granularity == seg_size;
639 size_t granules = (size + (granularity-1))/granularity;
640
641 printBox(ast, '=', "C O D E H E A P A N A L Y S I S (used blocks) for segment ", heapName);
642 ast->print_cr(" The aggregate step takes an aggregated snapshot of the CodeHeap.\n"
643 " Subsequent print functions create their output based on this snapshot.\n"
644 " The CodeHeap is a living thing, and every effort has been made for the\n"
645 " collected data to be consistent. Only the method names and signatures\n"
646 " are retrieved at print time. That may lead to rare cases where the\n"
647 " name of a method is no longer available, e.g. because it was unloaded.\n");
648 ast->print_cr(" CodeHeap committed size " SIZE_FORMAT"%" "l" "u" "K (" SIZE_FORMAT"%" "l" "u" "M), reserved size " SIZE_FORMAT"%" "l" "u" "K (" SIZE_FORMAT"%" "l" "u" "M), %d%% occupied.",
649 size/(size_t)K, size/(size_t)M, res_size/(size_t)K, res_size/(size_t)M, (unsigned int)(100.0*size/res_size));
650 ast->print_cr(" CodeHeap allocation segment size is " SIZE_FORMAT"%" "l" "u" " bytes. This is the smallest possible granularity.", seg_size);
651 ast->print_cr(" CodeHeap (committed part) is mapped to " SIZE_FORMAT"%" "l" "u" " granules of size " SIZE_FORMAT"%" "l" "u" " bytes.", granules, granularity);
652 ast->print_cr(" Each granule takes " SIZE_FORMAT"%" "l" "u" " bytes of C heap, that is " SIZE_FORMAT"%" "l" "u" "K in total for statistics data.", sizeof(StatElement), (sizeof(StatElement)*granules)/(size_t)K);
653 ast->print_cr(" The number of granules is limited to %dk, requiring a granules size of at least %d bytes for a 1GB heap.", (unsigned int)(max_granules/K), (unsigned int)(G/max_granules));
654 BUFFEREDSTREAM_FLUSH("\n")if ((("\n") != __null) && (strlen("\n") > 0)){ _sstbuf
->print("%s", "\n"); } if (_sstbuf != _outbuf) { if (_sstbuf
->size() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf
->size(); _outbuf->print("%s", _sstbuf->as_string())
; _sstbuf->reset(); } }
655
656
657 while (!done) {
658 //---< reset counters with every aggregation >---
659 nBlocks_t1 = 0;
660 nBlocks_t2 = 0;
661 nBlocks_alive = 0;
662 nBlocks_dead = 0;
663 nBlocks_unloaded = 0;
664 nBlocks_stub = 0;
665
666 nBlocks_free = 0;
667 nBlocks_used = 0;
668 nBlocks_zomb = 0;
669 nBlocks_disconn = 0;
670 nBlocks_notentr = 0;
671
672 //---< discard old arrays if size does not match >---
673 if (granules != alloc_granules) {
674 discard_StatArray(out);
675 discard_TopSizeArray(out);
676 }
677
678 //---< allocate arrays if they don't yet exist, initialize >---
679 prepare_StatArray(out, granules, granularity, heapName);
680 if (StatArray == NULL__null) {
681 set_HeapStatGlobals(out, heapName);
682 return;
683 }
684 prepare_TopSizeArray(out, maxTopSizeBlocks, heapName);
685 prepare_SizeDistArray(out, nSizeDistElements, heapName);
686
687 latest_compilation_id = CompileBroker::get_compilation_id();
688 unsigned int highest_compilation_id = 0;
689 size_t usedSpace = 0;
690 size_t t1Space = 0;
691 size_t t2Space = 0;
692 size_t aliveSpace = 0;
693 size_t disconnSpace = 0;
694 size_t notentrSpace = 0;
695 size_t deadSpace = 0;
696 size_t unloadedSpace = 0;
697 size_t stubSpace = 0;
698 size_t freeSpace = 0;
699 size_t maxFreeSize = 0;
700 HeapBlock* maxFreeBlock = NULL__null;
701 bool insane = false;
702
703 int64_t hotnessAccumulator = 0;
704 unsigned int n_methods = 0;
705 avgTemp = 0;
706 minTemp = (int)(res_size > M ? (res_size/M)*2 : 1);
707 maxTemp = -minTemp;
708
709 for (HeapBlock *h = heap->first_block(); h != NULL__null && !insane; h = heap->next_block(h)) {
710 unsigned int hb_len = (unsigned int)h->length(); // despite being size_t, length can never overflow an unsigned int.
711 size_t hb_bytelen = ((size_t)hb_len)<<log2_seg_size;
712 unsigned int ix_beg = (unsigned int)(((char*)h-low_bound)/granule_size);
713 unsigned int ix_end = (unsigned int)(((char*)h-low_bound+(hb_bytelen-1))/granule_size);
714 unsigned int compile_id = 0;
715 CompLevel comp_lvl = CompLevel_none;
716 compType cType = noComp;
717 blobType cbType = noType;
718
719 //---< some sanity checks >---
720 // Do not assert here, just check, print error message and return.
721 // This is a diagnostic function. It is not supposed to tear down the VM.
722 if ((char*)h < low_bound) {
723 insane = true; ast->print_cr("Sanity check: HeapBlock @%p below low bound (%p)", (char*)h, low_bound);
724 }
725 if ((char*)h > (low_bound + res_size)) {
726 insane = true; ast->print_cr("Sanity check: HeapBlock @%p outside reserved range (%p)", (char*)h, low_bound + res_size);
727 }
728 if ((char*)h > (low_bound + size)) {
729 insane = true; ast->print_cr("Sanity check: HeapBlock @%p outside used range (%p)", (char*)h, low_bound + size);
730 }
731 if (ix_end >= granules) {
732 insane = true; ast->print_cr("Sanity check: end index (%d) out of bounds (" SIZE_FORMAT"%" "l" "u" ")", ix_end, granules);
733 }
734 if (size != heap->capacity()) {
735 insane = true; ast->print_cr("Sanity check: code heap capacity has changed (" SIZE_FORMAT"%" "l" "u" "K to " SIZE_FORMAT"%" "l" "u" "K)", size/(size_t)K, heap->capacity()/(size_t)K);
736 }
737 if (ix_beg > ix_end) {
738 insane = true; ast->print_cr("Sanity check: end index (%d) lower than begin index (%d)", ix_end, ix_beg);
739 }
740 if (insane) {
741 BUFFEREDSTREAM_FLUSH("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if (_sstbuf
->size() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf
->size(); _outbuf->print("%s", _sstbuf->as_string())
; _sstbuf->reset(); } }
742 continue;
743 }
744
745 if (h->free()) {
746 nBlocks_free++;
747 freeSpace += hb_bytelen;
748 if (hb_bytelen > maxFreeSize) {
749 maxFreeSize = hb_bytelen;
750 maxFreeBlock = h;
751 }
752 } else {
753 update_SizeDistArray(out, hb_len);
754 nBlocks_used++;
755 usedSpace += hb_bytelen;
756 CodeBlob* cb = (CodeBlob*)heap->find_start(h);
757 cbType = get_cbType(cb); // Will check for cb == NULL and other safety things.
758 if (cbType != noType) {
759 const char* blob_name = os::strdup(cb->name());
760 unsigned int nm_size = 0;
761 int temperature = 0;
762 nmethod* nm = cb->as_nmethod_or_null();
763 if (nm != NULL__null) { // no is_readable check required, nm = (nmethod*)cb.
764 ResourceMark rm;
765 Method* method = nm->method();
766 if (nm->is_in_use()) {
767 blob_name = os::strdup(method->name_and_sig_as_C_string());
768 }
769 if (nm->is_not_entrant()) {
770 blob_name = os::strdup(method->name_and_sig_as_C_string());
771 }
772
773 nm_size = nm->total_size();
774 compile_id = nm->compile_id();
775 comp_lvl = (CompLevel)(nm->comp_level());
776 if (nm->is_compiled_by_c1()) {
777 cType = c1;
778 }
779 if (nm->is_compiled_by_c2()) {
780 cType = c2;
781 }
782 if (nm->is_compiled_by_jvmci()) {
783 cType = jvmci;
784 }
785 switch (cbType) {
786 case nMethod_inuse: { // only for executable methods!!!
787 // space for these cbs is accounted for later.
788 temperature = nm->hotness_counter();
789 hotnessAccumulator += temperature;
790 n_methods++;
791 maxTemp = (temperature > maxTemp) ? temperature : maxTemp;
792 minTemp = (temperature < minTemp) ? temperature : minTemp;
793 break;
794 }
795 case nMethod_notused:
796 nBlocks_alive++;
797 nBlocks_disconn++;
798 aliveSpace += hb_bytelen;
799 disconnSpace += hb_bytelen;
800 break;
801 case nMethod_notentrant: // equivalent to nMethod_alive
802 nBlocks_alive++;
803 nBlocks_notentr++;
804 aliveSpace += hb_bytelen;
805 notentrSpace += hb_bytelen;
806 break;
807 case nMethod_unloaded:
808 nBlocks_unloaded++;
809 unloadedSpace += hb_bytelen;
810 break;
811 case nMethod_dead:
812 nBlocks_dead++;
813 deadSpace += hb_bytelen;
814 break;
815 default:
816 break;
817 }
818 }
819
820 //------------------------------------------
821 //---< register block in TopSizeArray >---
822 //------------------------------------------
823 if (alloc_topSizeBlocks > 0) {
824 if (used_topSizeBlocks == 0) {
825 TopSizeArray[0].start = h;
826 TopSizeArray[0].blob_name = blob_name;
827 TopSizeArray[0].len = hb_len;
828 TopSizeArray[0].index = tsbStopper;
829 TopSizeArray[0].nm_size = nm_size;
830 TopSizeArray[0].temperature = temperature;
831 TopSizeArray[0].compiler = cType;
832 TopSizeArray[0].level = comp_lvl;
833 TopSizeArray[0].type = cbType;
834 currMax = hb_len;
835 currMin = hb_len;
836 currMin_ix = 0;
837 used_topSizeBlocks++;
838 blob_name = NULL__null; // indicate blob_name was consumed
839 // This check roughly cuts 5000 iterations (JVM98, mixed, dbg, termination stats):
840 } else if ((used_topSizeBlocks < alloc_topSizeBlocks) && (hb_len < currMin)) {
841 //---< all blocks in list are larger, but there is room left in array >---
842 TopSizeArray[currMin_ix].index = used_topSizeBlocks;
843 TopSizeArray[used_topSizeBlocks].start = h;
844 TopSizeArray[used_topSizeBlocks].blob_name = blob_name;
845 TopSizeArray[used_topSizeBlocks].len = hb_len;
846 TopSizeArray[used_topSizeBlocks].index = tsbStopper;
847 TopSizeArray[used_topSizeBlocks].nm_size = nm_size;
848 TopSizeArray[used_topSizeBlocks].temperature = temperature;
849 TopSizeArray[used_topSizeBlocks].compiler = cType;
850 TopSizeArray[used_topSizeBlocks].level = comp_lvl;
851 TopSizeArray[used_topSizeBlocks].type = cbType;
852 currMin = hb_len;
853 currMin_ix = used_topSizeBlocks;
854 used_topSizeBlocks++;
855 blob_name = NULL__null; // indicate blob_name was consumed
856 } else {
857 // This check cuts total_iterations by a factor of 6 (JVM98, mixed, dbg, termination stats):
858 // We don't need to search the list if we know beforehand that the current block size is
859 // smaller than the currently recorded minimum and there is no free entry left in the list.
860 if (!((used_topSizeBlocks == alloc_topSizeBlocks) && (hb_len <= currMin))) {
861 if (currMax < hb_len) {
862 currMax = hb_len;
863 }
864 unsigned int i;
865 unsigned int prev_i = tsbStopper;
866 unsigned int limit_i = 0;
867 for (i = 0; i != tsbStopper; i = TopSizeArray[i].index) {
868 if (limit_i++ >= alloc_topSizeBlocks) {
869 insane = true; break; // emergency exit
870 }
871 if (i >= used_topSizeBlocks) {
872 insane = true; break; // emergency exit
873 }
874 total_iterations++;
875 if (TopSizeArray[i].len < hb_len) {
876 //---< We want to insert here, element <i> is smaller than the current one >---
877 if (used_topSizeBlocks < alloc_topSizeBlocks) { // still room for a new entry to insert
878 // old entry gets moved to the next free element of the array.
879 // That's necessary to keep the entry for the largest block at index 0.
880 // This move might cause the current minimum to be moved to another place
881 if (i == currMin_ix) {
882 assert(TopSizeArray[i].len == currMin, "sort error")do { if (!(TopSizeArray[i].len == currMin)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/codeHeapState.cpp"
, 882, "assert(" "TopSizeArray[i].len == currMin" ") failed",
"sort error"); ::breakpoint(); } } while (0)
;
883 currMin_ix = used_topSizeBlocks;
884 }
885 memcpy((void*)&TopSizeArray[used_topSizeBlocks], (void*)&TopSizeArray[i], sizeof(TopSizeBlk));
886 TopSizeArray[i].start = h;
887 TopSizeArray[i].blob_name = blob_name;
888 TopSizeArray[i].len = hb_len;
889 TopSizeArray[i].index = used_topSizeBlocks;
890 TopSizeArray[i].nm_size = nm_size;
891 TopSizeArray[i].temperature = temperature;
892 TopSizeArray[i].compiler = cType;
893 TopSizeArray[i].level = comp_lvl;
894 TopSizeArray[i].type = cbType;
895 used_topSizeBlocks++;
896 blob_name = NULL__null; // indicate blob_name was consumed
897 } else { // no room for new entries, current block replaces entry for smallest block
898 //---< Find last entry (entry for smallest remembered block) >---
899 // We either want to insert right before the smallest entry, which is when <i>
900 // indexes the smallest entry. We then just overwrite the smallest entry.
901 // What's more likely:
902 // We want to insert somewhere in the list. The smallest entry (@<j>) then falls off the cliff.
903 // The element at the insert point <i> takes it's slot. The second-smallest entry now becomes smallest.
904 // Data of the current block is filled in at index <i>.
905 unsigned int j = i;
906 unsigned int prev_j = tsbStopper;
907 unsigned int limit_j = 0;
908 while (TopSizeArray[j].index != tsbStopper) {
909 if (limit_j++ >= alloc_topSizeBlocks) {
910 insane = true; break; // emergency exit
911 }
912 if (j >= used_topSizeBlocks) {
913 insane = true; break; // emergency exit
914 }
915 total_iterations++;
916 prev_j = j;
917 j = TopSizeArray[j].index;
918 }
919 if (!insane) {
920 if (TopSizeArray[j].blob_name != NULL__null) {
921 os::free((void*)TopSizeArray[j].blob_name);
922 }
923 if (prev_j == tsbStopper) {
924 //---< Above while loop did not iterate, we already are the min entry >---
925 //---< We have to just replace the smallest entry >---
926 currMin = hb_len;
927 currMin_ix = j;
928 TopSizeArray[j].start = h;
929 TopSizeArray[j].blob_name = blob_name;
930 TopSizeArray[j].len = hb_len;
931 TopSizeArray[j].index = tsbStopper; // already set!!
932 TopSizeArray[i].nm_size = nm_size;
933 TopSizeArray[i].temperature = temperature;
934 TopSizeArray[j].compiler = cType;
935 TopSizeArray[j].level = comp_lvl;
936 TopSizeArray[j].type = cbType;
937 } else {
938 //---< second-smallest entry is now smallest >---
939 TopSizeArray[prev_j].index = tsbStopper;
940 currMin = TopSizeArray[prev_j].len;
941 currMin_ix = prev_j;
942 //---< previously smallest entry gets overwritten >---
943 memcpy((void*)&TopSizeArray[j], (void*)&TopSizeArray[i], sizeof(TopSizeBlk));
944 TopSizeArray[i].start = h;
945 TopSizeArray[i].blob_name = blob_name;
946 TopSizeArray[i].len = hb_len;
947 TopSizeArray[i].index = j;
948 TopSizeArray[i].nm_size = nm_size;
949 TopSizeArray[i].temperature = temperature;
950 TopSizeArray[i].compiler = cType;
951 TopSizeArray[i].level = comp_lvl;
952 TopSizeArray[i].type = cbType;
953 }
954 blob_name = NULL__null; // indicate blob_name was consumed
955 } // insane
956 }
957 break;
958 }
959 prev_i = i;
960 }
961 if (insane) {
962 // Note: regular analysis could probably continue by resetting "insane" flag.
963 out->print_cr("Possible loop in TopSizeBlocks list detected. Analysis aborted.");
964 discard_TopSizeArray(out);
965 }
966 }
967 }
968 }
969 if (blob_name != NULL__null) {
970 os::free((void*)blob_name);
971 blob_name = NULL__null;
972 }
973 //----------------------------------------------
974 //---< END register block in TopSizeArray >---
975 //----------------------------------------------
976 } else {
977 nBlocks_zomb++;
978 }
979
980 if (ix_beg == ix_end) {
981 StatArray[ix_beg].type = cbType;
982 switch (cbType) {
983 case nMethod_inuse:
984 highest_compilation_id = (highest_compilation_id >= compile_id) ? highest_compilation_id : compile_id;
985 if (comp_lvl < CompLevel_full_optimization) {
986 nBlocks_t1++;
987 t1Space += hb_bytelen;
988 StatArray[ix_beg].t1_count++;
989 StatArray[ix_beg].t1_space += (unsigned short)hb_len;
990 StatArray[ix_beg].t1_age = StatArray[ix_beg].t1_age < compile_id ? compile_id : StatArray[ix_beg].t1_age;
991 } else {
992 nBlocks_t2++;
993 t2Space += hb_bytelen;
994 StatArray[ix_beg].t2_count++;
995 StatArray[ix_beg].t2_space += (unsigned short)hb_len;
996 StatArray[ix_beg].t2_age = StatArray[ix_beg].t2_age < compile_id ? compile_id : StatArray[ix_beg].t2_age;
997 }
998 StatArray[ix_beg].level = comp_lvl;
999 StatArray[ix_beg].compiler = cType;
1000 break;
1001 case nMethod_alive:
1002 StatArray[ix_beg].tx_count++;
1003 StatArray[ix_beg].tx_space += (unsigned short)hb_len;
1004 StatArray[ix_beg].tx_age = StatArray[ix_beg].tx_age < compile_id ? compile_id : StatArray[ix_beg].tx_age;
1005 StatArray[ix_beg].level = comp_lvl;
1006 StatArray[ix_beg].compiler = cType;
1007 break;
1008 case nMethod_dead:
1009 case nMethod_unloaded:
1010 StatArray[ix_beg].dead_count++;
1011 StatArray[ix_beg].dead_space += (unsigned short)hb_len;
1012 break;
1013 default:
1014 // must be a stub, if it's not a dead or alive nMethod
1015 nBlocks_stub++;
1016 stubSpace += hb_bytelen;
1017 StatArray[ix_beg].stub_count++;
1018 StatArray[ix_beg].stub_space += (unsigned short)hb_len;
1019 break;
1020 }
1021 } else {
1022 unsigned int beg_space = (unsigned int)(granule_size - ((char*)h - low_bound - ix_beg*granule_size));
1023 unsigned int end_space = (unsigned int)(hb_bytelen - beg_space - (ix_end-ix_beg-1)*granule_size);
1024 beg_space = beg_space>>log2_seg_size; // store in units of _segment_size
1025 end_space = end_space>>log2_seg_size; // store in units of _segment_size
1026 StatArray[ix_beg].type = cbType;
1027 StatArray[ix_end].type = cbType;
1028 switch (cbType) {
1029 case nMethod_inuse:
1030 highest_compilation_id = (highest_compilation_id >= compile_id) ? highest_compilation_id : compile_id;
1031 if (comp_lvl < CompLevel_full_optimization) {
1032 nBlocks_t1++;
1033 t1Space += hb_bytelen;
1034 StatArray[ix_beg].t1_count++;
1035 StatArray[ix_beg].t1_space += (unsigned short)beg_space;
1036 StatArray[ix_beg].t1_age = StatArray[ix_beg].t1_age < compile_id ? compile_id : StatArray[ix_beg].t1_age;
1037
1038 StatArray[ix_end].t1_count++;
1039 StatArray[ix_end].t1_space += (unsigned short)end_space;
1040 StatArray[ix_end].t1_age = StatArray[ix_end].t1_age < compile_id ? compile_id : StatArray[ix_end].t1_age;
1041 } else {
1042 nBlocks_t2++;
1043 t2Space += hb_bytelen;
1044 StatArray[ix_beg].t2_count++;
1045 StatArray[ix_beg].t2_space += (unsigned short)beg_space;
1046 StatArray[ix_beg].t2_age = StatArray[ix_beg].t2_age < compile_id ? compile_id : StatArray[ix_beg].t2_age;
1047
1048 StatArray[ix_end].t2_count++;
1049 StatArray[ix_end].t2_space += (unsigned short)end_space;
1050 StatArray[ix_end].t2_age = StatArray[ix_end].t2_age < compile_id ? compile_id : StatArray[ix_end].t2_age;
1051 }
1052 StatArray[ix_beg].level = comp_lvl;
1053 StatArray[ix_beg].compiler = cType;
1054 StatArray[ix_end].level = comp_lvl;
1055 StatArray[ix_end].compiler = cType;
1056 break;
1057 case nMethod_alive:
1058 StatArray[ix_beg].tx_count++;
1059 StatArray[ix_beg].tx_space += (unsigned short)beg_space;
1060 StatArray[ix_beg].tx_age = StatArray[ix_beg].tx_age < compile_id ? compile_id : StatArray[ix_beg].tx_age;
1061
1062 StatArray[ix_end].tx_count++;
1063 StatArray[ix_end].tx_space += (unsigned short)end_space;
1064 StatArray[ix_end].tx_age = StatArray[ix_end].tx_age < compile_id ? compile_id : StatArray[ix_end].tx_age;
1065
1066 StatArray[ix_beg].level = comp_lvl;
1067 StatArray[ix_beg].compiler = cType;
1068 StatArray[ix_end].level = comp_lvl;
1069 StatArray[ix_end].compiler = cType;
1070 break;
1071 case nMethod_dead:
1072 case nMethod_unloaded:
1073 StatArray[ix_beg].dead_count++;
1074 StatArray[ix_beg].dead_space += (unsigned short)beg_space;
1075 StatArray[ix_end].dead_count++;
1076 StatArray[ix_end].dead_space += (unsigned short)end_space;
1077 break;
1078 default:
1079 // must be a stub, if it's not a dead or alive nMethod
1080 nBlocks_stub++;
1081 stubSpace += hb_bytelen;
1082 StatArray[ix_beg].stub_count++;
1083 StatArray[ix_beg].stub_space += (unsigned short)beg_space;
1084 StatArray[ix_end].stub_count++;
1085 StatArray[ix_end].stub_space += (unsigned short)end_space;
1086 break;
1087 }
1088 for (unsigned int ix = ix_beg+1; ix < ix_end; ix++) {
1089 StatArray[ix].type = cbType;
1090 switch (cbType) {
1091 case nMethod_inuse:
1092 if (comp_lvl < CompLevel_full_optimization) {
1093 StatArray[ix].t1_count++;
1094 StatArray[ix].t1_space += (unsigned short)(granule_size>>log2_seg_size);
1095 StatArray[ix].t1_age = StatArray[ix].t1_age < compile_id ? compile_id : StatArray[ix].t1_age;
1096 } else {
1097 StatArray[ix].t2_count++;
1098 StatArray[ix].t2_space += (unsigned short)(granule_size>>log2_seg_size);
1099 StatArray[ix].t2_age = StatArray[ix].t2_age < compile_id ? compile_id : StatArray[ix].t2_age;
1100 }
1101 StatArray[ix].level = comp_lvl;
1102 StatArray[ix].compiler = cType;
1103 break;
1104 case nMethod_alive:
1105 StatArray[ix].tx_count++;
1106 StatArray[ix].tx_space += (unsigned short)(granule_size>>log2_seg_size);
1107 StatArray[ix].tx_age = StatArray[ix].tx_age < compile_id ? compile_id : StatArray[ix].tx_age;
1108 StatArray[ix].level = comp_lvl;
1109 StatArray[ix].compiler = cType;
1110 break;
1111 case nMethod_dead:
1112 case nMethod_unloaded:
1113 StatArray[ix].dead_count++;
1114 StatArray[ix].dead_space += (unsigned short)(granule_size>>log2_seg_size);
1115 break;
1116 default:
1117 // must be a stub, if it's not a dead or alive nMethod
1118 StatArray[ix].stub_count++;
1119 StatArray[ix].stub_space += (unsigned short)(granule_size>>log2_seg_size);
1120 break;
1121 }
1122 }
1123 }
1124 }
1125 }
1126 done = true;
1127
1128 if (!insane) {
1129 // There is a risk for this block (because it contains many print statements) to get
1130 // interspersed with print data from other threads. We take this risk intentionally.
1131 // Getting stalled waiting for tty_lock while holding the CodeCache_lock is not desirable.
1132 printBox(ast, '-', "Global CodeHeap statistics for segment ", heapName);
1133 ast->print_cr("freeSpace = " SIZE_FORMAT_W(8)"%" "8" "l" "u" "k, nBlocks_free = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", freeSpace/(size_t)K, nBlocks_free, (100.0*freeSpace)/size, (100.0*freeSpace)/res_size);
1134 ast->print_cr("usedSpace = " SIZE_FORMAT_W(8)"%" "8" "l" "u" "k, nBlocks_used = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", usedSpace/(size_t)K, nBlocks_used, (100.0*usedSpace)/size, (100.0*usedSpace)/res_size);
1135 ast->print_cr(" Tier1 Space = " SIZE_FORMAT_W(8)"%" "8" "l" "u" "k, nBlocks_t1 = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", t1Space/(size_t)K, nBlocks_t1, (100.0*t1Space)/size, (100.0*t1Space)/res_size);
1136 ast->print_cr(" Tier2 Space = " SIZE_FORMAT_W(8)"%" "8" "l" "u" "k, nBlocks_t2 = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", t2Space/(size_t)K, nBlocks_t2, (100.0*t2Space)/size, (100.0*t2Space)/res_size);
1137 ast->print_cr(" Alive Space = " SIZE_FORMAT_W(8)"%" "8" "l" "u" "k, nBlocks_alive = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", aliveSpace/(size_t)K, nBlocks_alive, (100.0*aliveSpace)/size, (100.0*aliveSpace)/res_size);
1138 ast->print_cr(" disconnected = " SIZE_FORMAT_W(8)"%" "8" "l" "u" "k, nBlocks_disconn = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", disconnSpace/(size_t)K, nBlocks_disconn, (100.0*disconnSpace)/size, (100.0*disconnSpace)/res_size);
1139 ast->print_cr(" not entrant = " SIZE_FORMAT_W(8)"%" "8" "l" "u" "k, nBlocks_notentr = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", notentrSpace/(size_t)K, nBlocks_notentr, (100.0*notentrSpace)/size, (100.0*notentrSpace)/res_size);
1140 ast->print_cr(" unloadedSpace = " SIZE_FORMAT_W(8)"%" "8" "l" "u" "k, nBlocks_unloaded = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", unloadedSpace/(size_t)K, nBlocks_unloaded, (100.0*unloadedSpace)/size, (100.0*unloadedSpace)/res_size);
1141 ast->print_cr(" deadSpace = " SIZE_FORMAT_W(8)"%" "8" "l" "u" "k, nBlocks_dead = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", deadSpace/(size_t)K, nBlocks_dead, (100.0*deadSpace)/size, (100.0*deadSpace)/res_size);
1142 ast->print_cr(" stubSpace = " SIZE_FORMAT_W(8)"%" "8" "l" "u" "k, nBlocks_stub = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", stubSpace/(size_t)K, nBlocks_stub, (100.0*stubSpace)/size, (100.0*stubSpace)/res_size);
1143 ast->print_cr("ZombieBlocks = %8d. These are HeapBlocks which could not be identified as CodeBlobs.", nBlocks_zomb);
1144 ast->cr();
1145 ast->print_cr("Segment start = " INTPTR_FORMAT"0x%016" "l" "x" ", used space = " SIZE_FORMAT_W(8)"%" "8" "l" "u""k", p2i(low_bound), size/K);
1146 ast->print_cr("Segment end (used) = " INTPTR_FORMAT"0x%016" "l" "x" ", remaining space = " SIZE_FORMAT_W(8)"%" "8" "l" "u""k", p2i(low_bound) + size, (res_size - size)/K);
1147 ast->print_cr("Segment end (reserved) = " INTPTR_FORMAT"0x%016" "l" "x" ", reserved space = " SIZE_FORMAT_W(8)"%" "8" "l" "u""k", p2i(low_bound) + res_size, res_size/K);
1148 ast->cr();
1149 ast->print_cr("latest allocated compilation id = %d", latest_compilation_id);
1150 ast->print_cr("highest observed compilation id = %d", highest_compilation_id);
1151 ast->print_cr("Building TopSizeList iterations = %ld", total_iterations);
1152 ast->cr();
1153
1154 int reset_val = NMethodSweeper::hotness_counter_reset_val();
1155 double reverse_free_ratio = (res_size > size) ? (double)res_size/(double)(res_size-size) : (double)res_size;
1156 printBox(ast, '-', "Method hotness information at time of this analysis", NULL__null);
1157 ast->print_cr("Highest possible method temperature: %12d", reset_val);
1158 ast->print_cr("Threshold for method to be considered 'cold': %12.3f", -reset_val + reverse_free_ratio * NmethodSweepActivity);
1159 if (n_methods > 0) {
1160 avgTemp = hotnessAccumulator/n_methods;
1161 ast->print_cr("min. hotness = %6d", minTemp);
1162 ast->print_cr("avg. hotness = %6d", avgTemp);
1163 ast->print_cr("max. hotness = %6d", maxTemp);
1164 } else {
1165 avgTemp = 0;
1166 ast->print_cr("No hotness data available");
1167 }
1168 BUFFEREDSTREAM_FLUSH("\n")if ((("\n") != __null) && (strlen("\n") > 0)){ _sstbuf
->print("%s", "\n"); } if (_sstbuf != _outbuf) { if (_sstbuf
->size() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf
->size(); _outbuf->print("%s", _sstbuf->as_string())
; _sstbuf->reset(); } }
1169
1170 // This loop is intentionally printing directly to "out".
1171 // It should not print anything, anyway.
1172 out->print("Verifying collected data...");
1173 size_t granule_segs = granule_size>>log2_seg_size;
1174 for (unsigned int ix = 0; ix < granules; ix++) {
1175 if (StatArray[ix].t1_count > granule_segs) {
1176 out->print_cr("t1_count[%d] = %d", ix, StatArray[ix].t1_count);
1177 }
1178 if (StatArray[ix].t2_count > granule_segs) {
1179 out->print_cr("t2_count[%d] = %d", ix, StatArray[ix].t2_count);
1180 }
1181 if (StatArray[ix].tx_count > granule_segs) {
1182 out->print_cr("tx_count[%d] = %d", ix, StatArray[ix].tx_count);
1183 }
1184 if (StatArray[ix].stub_count > granule_segs) {
1185 out->print_cr("stub_count[%d] = %d", ix, StatArray[ix].stub_count);
1186 }
1187 if (StatArray[ix].dead_count > granule_segs) {
1188 out->print_cr("dead_count[%d] = %d", ix, StatArray[ix].dead_count);
1189 }
1190 if (StatArray[ix].t1_space > granule_segs) {
1191 out->print_cr("t1_space[%d] = %d", ix, StatArray[ix].t1_space);
1192 }
1193 if (StatArray[ix].t2_space > granule_segs) {
1194 out->print_cr("t2_space[%d] = %d", ix, StatArray[ix].t2_space);
1195 }
1196 if (StatArray[ix].tx_space > granule_segs) {
1197 out->print_cr("tx_space[%d] = %d", ix, StatArray[ix].tx_space);
1198 }
1199 if (StatArray[ix].stub_space > granule_segs) {
1200 out->print_cr("stub_space[%d] = %d", ix, StatArray[ix].stub_space);
1201 }
1202 if (StatArray[ix].dead_space > granule_segs) {
1203 out->print_cr("dead_space[%d] = %d", ix, StatArray[ix].dead_space);
1204 }
1205 // this cast is awful! I need it because NT/Intel reports a signed/unsigned mismatch.
1206 if ((size_t)(StatArray[ix].t1_count+StatArray[ix].t2_count+StatArray[ix].tx_count+StatArray[ix].stub_count+StatArray[ix].dead_count) > granule_segs) {
1207 out->print_cr("t1_count[%d] = %d, t2_count[%d] = %d, tx_count[%d] = %d, stub_count[%d] = %d", ix, StatArray[ix].t1_count, ix, StatArray[ix].t2_count, ix, StatArray[ix].tx_count, ix, StatArray[ix].stub_count);
1208 }
1209 if ((size_t)(StatArray[ix].t1_space+StatArray[ix].t2_space+StatArray[ix].tx_space+StatArray[ix].stub_space+StatArray[ix].dead_space) > granule_segs) {
1210 out->print_cr("t1_space[%d] = %d, t2_space[%d] = %d, tx_space[%d] = %d, stub_space[%d] = %d", ix, StatArray[ix].t1_space, ix, StatArray[ix].t2_space, ix, StatArray[ix].tx_space, ix, StatArray[ix].stub_space);
1211 }
1212 }
1213
1214 // This loop is intentionally printing directly to "out".
1215 // It should not print anything, anyway.
1216 if (used_topSizeBlocks > 0) {
1217 unsigned int j = 0;
1218 if (TopSizeArray[0].len != currMax) {
1219 out->print_cr("currMax(%d) differs from TopSizeArray[0].len(%d)", currMax, TopSizeArray[0].len);
1220 }
1221 for (unsigned int i = 0; (TopSizeArray[i].index != tsbStopper) && (j++ < alloc_topSizeBlocks); i = TopSizeArray[i].index) {
1222 if (TopSizeArray[i].len < TopSizeArray[TopSizeArray[i].index].len) {
1223 out->print_cr("sort error at index %d: %d !>= %d", i, TopSizeArray[i].len, TopSizeArray[TopSizeArray[i].index].len);
1224 }
1225 }
1226 if (j >= alloc_topSizeBlocks) {
1227 out->print_cr("Possible loop in TopSizeArray chaining!\n allocBlocks = %d, usedBlocks = %d", alloc_topSizeBlocks, used_topSizeBlocks);
1228 for (unsigned int i = 0; i < alloc_topSizeBlocks; i++) {
1229 out->print_cr(" TopSizeArray[%d].index = %d, len = %d", i, TopSizeArray[i].index, TopSizeArray[i].len);
1230 }
1231 }
1232 }
1233 out->print_cr("...done\n\n");
1234 } else {
1235 // insane heap state detected. Analysis data incomplete. Just throw it away.
1236 discard_StatArray(out);
1237 discard_TopSizeArray(out);
1238 }
1239 }
1240
1241
1242 done = false;
1243 while (!done && (nBlocks_free > 0)) {
1244
1245 printBox(ast, '=', "C O D E H E A P A N A L Y S I S (free blocks) for segment ", heapName);
1246 ast->print_cr(" The aggregate step collects information about all free blocks in CodeHeap.\n"
1247 " Subsequent print functions create their output based on this snapshot.\n");
1248 ast->print_cr(" Free space in %s is distributed over %d free blocks.", heapName, nBlocks_free);
1249 ast->print_cr(" Each free block takes " SIZE_FORMAT"%" "l" "u" " bytes of C heap for statistics data, that is " SIZE_FORMAT"%" "l" "u" "K in total.", sizeof(FreeBlk), (sizeof(FreeBlk)*nBlocks_free)/K);
1250 BUFFEREDSTREAM_FLUSH("\n")if ((("\n") != __null) && (strlen("\n") > 0)){ _sstbuf
->print("%s", "\n"); } if (_sstbuf != _outbuf) { if (_sstbuf
->size() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf
->size(); _outbuf->print("%s", _sstbuf->as_string())
; _sstbuf->reset(); } }
1251
1252 //----------------------------------------
1253 //-- Prepare the FreeArray of FreeBlks --
1254 //----------------------------------------
1255
1256 //---< discard old array if size does not match >---
1257 if (nBlocks_free != alloc_freeBlocks) {
1258 discard_FreeArray(out);
1259 }
1260
1261 prepare_FreeArray(out, nBlocks_free, heapName);
1262 if (FreeArray == NULL__null) {
1263 done = true;
1264 continue;
1265 }
1266
1267 //----------------------------------------
1268 //-- Collect all FreeBlks in FreeArray --
1269 //----------------------------------------
1270
1271 unsigned int ix = 0;
1272 FreeBlock* cur = heap->freelist();
1273
1274 while (cur != NULL__null) {
1275 if (ix < alloc_freeBlocks) { // don't index out of bounds if _freelist has more blocks than anticipated
1276 FreeArray[ix].start = cur;
1277 FreeArray[ix].len = (unsigned int)(cur->length()<<log2_seg_size);
1278 FreeArray[ix].index = ix;
1279 }
1280 cur = cur->link();
1281 ix++;
1282 }
1283 if (ix != alloc_freeBlocks) {
1284 ast->print_cr("Free block count mismatch. Expected %d free blocks, but found %d.", alloc_freeBlocks, ix);
1285 ast->print_cr("I will update the counter and retry data collection");
1286 BUFFEREDSTREAM_FLUSH("\n")if ((("\n") != __null) && (strlen("\n") > 0)){ _sstbuf
->print("%s", "\n"); } if (_sstbuf != _outbuf) { if (_sstbuf
->size() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf
->size(); _outbuf->print("%s", _sstbuf->as_string())
; _sstbuf->reset(); } }
1287 nBlocks_free = ix;
1288 continue;
1289 }
1290 done = true;
1291 }
1292
1293 if (!done || (nBlocks_free == 0)) {
1294 if (nBlocks_free == 0) {
1295 printBox(ast, '-', "no free blocks found in ", heapName);
1296 } else if (!done) {
1297 ast->print_cr("Free block count mismatch could not be resolved.");
1298 ast->print_cr("Try to run \"aggregate\" function to update counters");
1299 }
1300 BUFFEREDSTREAM_FLUSH("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if (_sstbuf
->size() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf
->size(); _outbuf->print("%s", _sstbuf->as_string())
; _sstbuf->reset(); } }
1301
1302 //---< discard old array and update global values >---
1303 discard_FreeArray(out);
1304 set_HeapStatGlobals(out, heapName);
1305 return;
1306 }
1307
1308 //---< calculate and fill remaining fields >---
1309 if (FreeArray != NULL__null) {
1310 // This loop is intentionally printing directly to "out".
1311 // It should not print anything, anyway.
1312 for (unsigned int ix = 0; ix < alloc_freeBlocks-1; ix++) {
1313 size_t lenSum = 0;
1314 FreeArray[ix].gap = (unsigned int)((address)FreeArray[ix+1].start - ((address)FreeArray[ix].start + FreeArray[ix].len));
1315 for (HeapBlock *h = heap->next_block(FreeArray[ix].start); (h != NULL__null) && (h != FreeArray[ix+1].start); h = heap->next_block(h)) {
1316 CodeBlob *cb = (CodeBlob*)(heap->find_start(h));
1317 if ((cb != NULL__null) && !cb->is_nmethod()) { // checks equivalent to those in get_cbType()
1318 FreeArray[ix].stubs_in_gap = true;
1319 }
1320 FreeArray[ix].n_gapBlocks++;
1321 lenSum += h->length()<<log2_seg_size;
1322 if (((address)h < ((address)FreeArray[ix].start+FreeArray[ix].len)) || (h >= FreeArray[ix+1].start)) {
1323 out->print_cr("unsorted occupied CodeHeap block found @ %p, gap interval [%p, %p)", h, (address)FreeArray[ix].start+FreeArray[ix].len, FreeArray[ix+1].start);
1324 }
1325 }
1326 if (lenSum != FreeArray[ix].gap) {
1327 out->print_cr("Length mismatch for gap between FreeBlk[%d] and FreeBlk[%d]. Calculated: %d, accumulated: %d.", ix, ix+1, FreeArray[ix].gap, (unsigned int)lenSum);
1328 }
1329 }
1330 }
1331 set_HeapStatGlobals(out, heapName);
1332
1333 printBox(ast, '=', "C O D E H E A P A N A L Y S I S C O M P L E T E for segment ", heapName);
1334 BUFFEREDSTREAM_FLUSH("\n")if ((("\n") != __null) && (strlen("\n") > 0)){ _sstbuf
->print("%s", "\n"); } if (_sstbuf != _outbuf) { if (_sstbuf
->size() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf
->size(); _outbuf->print("%s", _sstbuf->as_string())
; _sstbuf->reset(); } }
1335}
1336
1337
1338void CodeHeapState::print_usedSpace(outputStream* out, CodeHeap* heap) {
1339 if (!initialization_complete) {
1340 return;
1341 }
1342
1343 const char* heapName = get_heapName(heap);
1344 get_HeapStatGlobals(out, heapName);
1345
1346 if ((StatArray == NULL__null) || (TopSizeArray == NULL__null) || (used_topSizeBlocks == 0)) {
1347 return;
1348 }
1349 BUFFEREDSTREAM_DECL(ast, out)ResourceMark _rm; size_t _nflush = 0; size_t _nforcedflush = 0
; size_t _nsavedflush = 0; size_t _nlockedflush = 0; size_t _nflush_bytes
= 0; size_t _capacity = 4*K; bufferedStream _sstobj(4*K); bufferedStream
* _sstbuf = &_sstobj; outputStream* _outbuf = out; bufferedStream
* ast = &_sstobj;;
1350
1351 {
1352 printBox(ast, '=', "U S E D S P A C E S T A T I S T I C S for ", heapName);
1353 ast->print_cr("Note: The Top%d list of the largest used blocks associates method names\n"
1354 " and other identifying information with the block size data.\n"
1355 "\n"
1356 " Method names are dynamically retrieved from the code cache at print time.\n"
1357 " Due to the living nature of the code cache and because the CodeCache_lock\n"
1358 " is not continuously held, the displayed name might be wrong or no name\n"
1359 " might be found at all. The likelihood for that to happen increases\n"
1360 " over time passed between analysis and print step.\n", used_topSizeBlocks);
1361 BUFFEREDSTREAM_FLUSH_LOCKED("\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n") != __null) &&
(strlen("\n") > 0)){ _sstbuf->print("%s", "\n"); } if (
_sstbuf != _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush
++; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } }
1362 }
1363
1364 //----------------------------
1365 //-- Print Top Used Blocks --
1366 //----------------------------
1367 {
1368 char* low_bound = heap->low_boundary();
1369
1370 printBox(ast, '-', "Largest Used Blocks in ", heapName);
1371 print_blobType_legend(ast);
1372
1373 ast->fill_to(51);
1374 ast->print("%4s", "blob");
1375 ast->fill_to(56);
1376 ast->print("%9s", "compiler");
1377 ast->fill_to(66);
1378 ast->print_cr("%6s", "method");
1379 ast->print_cr("%18s %13s %17s %4s %9s %5s %s", "Addr(module) ", "offset", "size", "type", " type lvl", " temp", "Name");
1380 BUFFEREDSTREAM_FLUSH_LOCKED(""){ ttyLocker ttyl; _nlockedflush++; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } }
1381
1382 //---< print Top Ten Used Blocks >---
1383 if (used_topSizeBlocks > 0) {
1384 unsigned int printed_topSizeBlocks = 0;
1385 for (unsigned int i = 0; i != tsbStopper; i = TopSizeArray[i].index) {
1386 printed_topSizeBlocks++;
1387 if (TopSizeArray[i].blob_name == NULL__null) {
1388 TopSizeArray[i].blob_name = os::strdup("unnamed blob or blob name unavailable");
1389 }
1390 // heap->find_start() is safe. Only works on _segmap.
1391 // Returns NULL or void*. Returned CodeBlob may be uninitialized.
1392 HeapBlock* heapBlock = TopSizeArray[i].start;
1393 CodeBlob* this_blob = (CodeBlob*)(heap->find_start(heapBlock));
1394 if (this_blob != NULL__null) {
1395 //---< access these fields only if we own the CodeCache_lock >---
1396 //---< blob address >---
1397 ast->print(INTPTR_FORMAT"0x%016" "l" "x", p2i(this_blob));
1398 ast->fill_to(19);
1399 //---< blob offset from CodeHeap begin >---
1400 ast->print("(+" PTR32_FORMAT"0x%08" "x" ")", (unsigned int)((char*)this_blob-low_bound));
1401 ast->fill_to(33);
1402 } else {
1403 //---< block address >---
1404 ast->print(INTPTR_FORMAT"0x%016" "l" "x", p2i(TopSizeArray[i].start));
1405 ast->fill_to(19);
1406 //---< block offset from CodeHeap begin >---
1407 ast->print("(+" PTR32_FORMAT"0x%08" "x" ")", (unsigned int)((char*)TopSizeArray[i].start-low_bound));
1408 ast->fill_to(33);
1409 }
1410
1411 //---< print size, name, and signature (for nMethods) >---
1412 bool is_nmethod = TopSizeArray[i].nm_size > 0;
1413 if (is_nmethod) {
1414 //---< nMethod size in hex >---
1415 ast->print(PTR32_FORMAT"0x%08" "x", TopSizeArray[i].nm_size);
1416 ast->print("(" SIZE_FORMAT_W(4)"%" "4" "l" "u" "K)", TopSizeArray[i].nm_size/K);
1417 ast->fill_to(51);
1418 ast->print(" %c", blobTypeChar[TopSizeArray[i].type]);
1419 //---< compiler information >---
1420 ast->fill_to(56);
1421 ast->print("%5s %3d", compTypeName[TopSizeArray[i].compiler], TopSizeArray[i].level);
1422 //---< method temperature >---
1423 ast->fill_to(67);
1424 ast->print("%5d", TopSizeArray[i].temperature);
1425 //---< name and signature >---
1426 ast->fill_to(67+6);
1427 if (TopSizeArray[i].type == nMethod_dead) {
1428 ast->print(" zombie method ");
1429 }
1430 ast->print("%s", TopSizeArray[i].blob_name);
1431 } else {
1432 //---< block size in hex >---
1433 ast->print(PTR32_FORMAT"0x%08" "x", (unsigned int)(TopSizeArray[i].len<<log2_seg_size));
1434 ast->print("(" SIZE_FORMAT_W(4)"%" "4" "l" "u" "K)", (TopSizeArray[i].len<<log2_seg_size)/K);
1435 //---< no compiler information >---
1436 ast->fill_to(56);
1437 //---< name and signature >---
1438 ast->fill_to(67+6);
1439 ast->print("%s", TopSizeArray[i].blob_name);
1440 }
1441 ast->cr();
1442 BUFFEREDSTREAM_FLUSH_AUTO("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if ((_capacity
- _sstbuf->size()) < (size_t)(256+(_capacity>>4)
)){ _nflush++; _nforcedflush--; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } } else {
_nsavedflush++; } }
1443 }
1444 if (used_topSizeBlocks != printed_topSizeBlocks) {
1445 ast->print_cr("used blocks: %d, printed blocks: %d", used_topSizeBlocks, printed_topSizeBlocks);
1446 for (unsigned int i = 0; i < alloc_topSizeBlocks; i++) {
1447 ast->print_cr(" TopSizeArray[%d].index = %d, len = %d", i, TopSizeArray[i].index, TopSizeArray[i].len);
1448 BUFFEREDSTREAM_FLUSH_AUTO("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if ((_capacity
- _sstbuf->size()) < (size_t)(256+(_capacity>>4)
)){ _nflush++; _nforcedflush--; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } } else {
_nsavedflush++; } }
1449 }
1450 }
1451 BUFFEREDSTREAM_FLUSH("\n\n")if ((("\n\n") != __null) && (strlen("\n\n") > 0)){
_sstbuf->print("%s", "\n\n"); } if (_sstbuf != _outbuf) {
if (_sstbuf->size() != 0) { _nforcedflush++; _nflush_bytes
+= _sstbuf->size(); _outbuf->print("%s", _sstbuf->as_string
()); _sstbuf->reset(); } }
1452 }
1453 }
1454
1455 //-----------------------------
1456 //-- Print Usage Histogram --
1457 //-----------------------------
1458
1459 if (SizeDistributionArray != NULL__null) {
1460 unsigned long total_count = 0;
1461 unsigned long total_size = 0;
1462 const unsigned long pctFactor = 200;
1463
1464 for (unsigned int i = 0; i < nSizeDistElements; i++) {
1465 total_count += SizeDistributionArray[i].count;
1466 total_size += SizeDistributionArray[i].lenSum;
1467 }
1468
1469 if ((total_count > 0) && (total_size > 0)) {
1470 printBox(ast, '-', "Block count histogram for ", heapName);
1471 ast->print_cr("Note: The histogram indicates how many blocks (as a percentage\n"
1472 " of all blocks) have a size in the given range.\n"
1473 " %ld characters are printed per percentage point.\n", pctFactor/100);
1474 ast->print_cr("total size of all blocks: %7ldM", (total_size<<log2_seg_size)/M);
1475 ast->print_cr("total number of all blocks: %7ld\n", total_count);
1476 BUFFEREDSTREAM_FLUSH_LOCKED(""){ ttyLocker ttyl; _nlockedflush++; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } }
1477
1478 ast->print_cr("[Size Range)------avg.-size-+----count-+");
1479 for (unsigned int i = 0; i < nSizeDistElements; i++) {
1480 if (SizeDistributionArray[i].rangeStart<<log2_seg_size < K) {
1481 ast->print("[" SIZE_FORMAT_W(5)"%" "5" "l" "u" " .." SIZE_FORMAT_W(5)"%" "5" "l" "u" " ): "
1482 ,(size_t)(SizeDistributionArray[i].rangeStart<<log2_seg_size)
1483 ,(size_t)(SizeDistributionArray[i].rangeEnd<<log2_seg_size)
1484 );
1485 } else if (SizeDistributionArray[i].rangeStart<<log2_seg_size < M) {
1486 ast->print("[" SIZE_FORMAT_W(5)"%" "5" "l" "u" "K.." SIZE_FORMAT_W(5)"%" "5" "l" "u" "K): "
1487 ,(SizeDistributionArray[i].rangeStart<<log2_seg_size)/K
1488 ,(SizeDistributionArray[i].rangeEnd<<log2_seg_size)/K
1489 );
1490 } else {
1491 ast->print("[" SIZE_FORMAT_W(5)"%" "5" "l" "u" "M.." SIZE_FORMAT_W(5)"%" "5" "l" "u" "M): "
1492 ,(SizeDistributionArray[i].rangeStart<<log2_seg_size)/M
1493 ,(SizeDistributionArray[i].rangeEnd<<log2_seg_size)/M
1494 );
1495 }
1496 ast->print(" %8d | %8d |",
1497 SizeDistributionArray[i].count > 0 ? (SizeDistributionArray[i].lenSum<<log2_seg_size)/SizeDistributionArray[i].count : 0,
1498 SizeDistributionArray[i].count);
1499
1500 unsigned int percent = pctFactor*SizeDistributionArray[i].count/total_count;
1501 for (unsigned int j = 1; j <= percent; j++) {
1502 ast->print("%c", (j%((pctFactor/100)*10) == 0) ? ('0'+j/(((unsigned int)pctFactor/100)*10)) : '*');
1503 }
1504 ast->cr();
1505 BUFFEREDSTREAM_FLUSH_AUTO("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if ((_capacity
- _sstbuf->size()) < (size_t)(256+(_capacity>>4)
)){ _nflush++; _nforcedflush--; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } } else {
_nsavedflush++; } }
1506 }
1507 ast->print_cr("----------------------------+----------+");
1508 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
1509
1510 printBox(ast, '-', "Contribution per size range to total size for ", heapName);
1511 ast->print_cr("Note: The histogram indicates how much space (as a percentage of all\n"
1512 " occupied space) is used by the blocks in the given size range.\n"
1513 " %ld characters are printed per percentage point.\n", pctFactor/100);
1514 ast->print_cr("total size of all blocks: %7ldM", (total_size<<log2_seg_size)/M);
1515 ast->print_cr("total number of all blocks: %7ld\n", total_count);
1516 BUFFEREDSTREAM_FLUSH_LOCKED(""){ ttyLocker ttyl; _nlockedflush++; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } }
1517
1518 ast->print_cr("[Size Range)------avg.-size-+----count-+");
1519 for (unsigned int i = 0; i < nSizeDistElements; i++) {
1520 if (SizeDistributionArray[i].rangeStart<<log2_seg_size < K) {
1521 ast->print("[" SIZE_FORMAT_W(5)"%" "5" "l" "u" " .." SIZE_FORMAT_W(5)"%" "5" "l" "u" " ): "
1522 ,(size_t)(SizeDistributionArray[i].rangeStart<<log2_seg_size)
1523 ,(size_t)(SizeDistributionArray[i].rangeEnd<<log2_seg_size)
1524 );
1525 } else if (SizeDistributionArray[i].rangeStart<<log2_seg_size < M) {
1526 ast->print("[" SIZE_FORMAT_W(5)"%" "5" "l" "u" "K.." SIZE_FORMAT_W(5)"%" "5" "l" "u" "K): "
1527 ,(SizeDistributionArray[i].rangeStart<<log2_seg_size)/K
1528 ,(SizeDistributionArray[i].rangeEnd<<log2_seg_size)/K
1529 );
1530 } else {
1531 ast->print("[" SIZE_FORMAT_W(5)"%" "5" "l" "u" "M.." SIZE_FORMAT_W(5)"%" "5" "l" "u" "M): "
1532 ,(SizeDistributionArray[i].rangeStart<<log2_seg_size)/M
1533 ,(SizeDistributionArray[i].rangeEnd<<log2_seg_size)/M
1534 );
1535 }
1536 ast->print(" %8d | %8d |",
1537 SizeDistributionArray[i].count > 0 ? (SizeDistributionArray[i].lenSum<<log2_seg_size)/SizeDistributionArray[i].count : 0,
1538 SizeDistributionArray[i].count);
1539
1540 unsigned int percent = pctFactor*(unsigned long)SizeDistributionArray[i].lenSum/total_size;
1541 for (unsigned int j = 1; j <= percent; j++) {
1542 ast->print("%c", (j%((pctFactor/100)*10) == 0) ? ('0'+j/(((unsigned int)pctFactor/100)*10)) : '*');
1543 }
1544 ast->cr();
1545 BUFFEREDSTREAM_FLUSH_AUTO("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if ((_capacity
- _sstbuf->size()) < (size_t)(256+(_capacity>>4)
)){ _nflush++; _nforcedflush--; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } } else {
_nsavedflush++; } }
1546 }
1547 ast->print_cr("----------------------------+----------+");
1548 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
1549 }
1550 }
1551}
1552
1553
1554void CodeHeapState::print_freeSpace(outputStream* out, CodeHeap* heap) {
1555 if (!initialization_complete) {
1556 return;
1557 }
1558
1559 const char* heapName = get_heapName(heap);
1560 get_HeapStatGlobals(out, heapName);
1561
1562 if ((StatArray == NULL__null) || (FreeArray == NULL__null) || (alloc_granules == 0)) {
1563 return;
1564 }
1565 BUFFEREDSTREAM_DECL(ast, out)ResourceMark _rm; size_t _nflush = 0; size_t _nforcedflush = 0
; size_t _nsavedflush = 0; size_t _nlockedflush = 0; size_t _nflush_bytes
= 0; size_t _capacity = 4*K; bufferedStream _sstobj(4*K); bufferedStream
* _sstbuf = &_sstobj; outputStream* _outbuf = out; bufferedStream
* ast = &_sstobj;;
1566
1567 {
1568 printBox(ast, '=', "F R E E S P A C E S T A T I S T I C S for ", heapName);
1569 ast->print_cr("Note: in this context, a gap is the occupied space between two free blocks.\n"
1570 " Those gaps are of interest if there is a chance that they become\n"
1571 " unoccupied, e.g. by class unloading. Then, the two adjacent free\n"
1572 " blocks, together with the now unoccupied space, form a new, large\n"
1573 " free block.");
1574 BUFFEREDSTREAM_FLUSH_LOCKED("\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n") != __null) &&
(strlen("\n") > 0)){ _sstbuf->print("%s", "\n"); } if (
_sstbuf != _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush
++; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } }
1575 }
1576
1577 {
1578 printBox(ast, '-', "List of all Free Blocks in ", heapName);
1579
1580 unsigned int ix = 0;
1581 for (ix = 0; ix < alloc_freeBlocks-1; ix++) {
1582 ast->print(INTPTR_FORMAT"0x%016" "l" "x" ": Len[%4d] = " HEX32_FORMAT"0x%x" ",", p2i(FreeArray[ix].start), ix, FreeArray[ix].len);
1583 ast->fill_to(38);
1584 ast->print("Gap[%4d..%4d]: " HEX32_FORMAT"0x%x" " bytes,", ix, ix+1, FreeArray[ix].gap);
1585 ast->fill_to(71);
1586 ast->print("block count: %6d", FreeArray[ix].n_gapBlocks);
1587 if (FreeArray[ix].stubs_in_gap) {
1588 ast->print(" !! permanent gap, contains stubs and/or blobs !!");
1589 }
1590 ast->cr();
1591 BUFFEREDSTREAM_FLUSH_AUTO("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if ((_capacity
- _sstbuf->size()) < (size_t)(256+(_capacity>>4)
)){ _nflush++; _nforcedflush--; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } } else {
_nsavedflush++; } }
1592 }
1593 ast->print_cr(INTPTR_FORMAT"0x%016" "l" "x" ": Len[%4d] = " HEX32_FORMAT"0x%x", p2i(FreeArray[ix].start), ix, FreeArray[ix].len);
1594 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n") != __null) &&
(strlen("\n\n") > 0)){ _sstbuf->print("%s", "\n\n"); }
if (_sstbuf != _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush
++; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } }
1595 }
1596
1597
1598 //-----------------------------------------
1599 //-- Find and Print Top Ten Free Blocks --
1600 //-----------------------------------------
1601
1602 //---< find Top Ten Free Blocks >---
1603 const unsigned int nTop = 10;
1604 unsigned int currMax10 = 0;
1605 struct FreeBlk* FreeTopTen[nTop];
1606 memset(FreeTopTen, 0, sizeof(FreeTopTen));
1607
1608 for (unsigned int ix = 0; ix < alloc_freeBlocks; ix++) {
1609 if (FreeArray[ix].len > currMax10) { // larger than the ten largest found so far
1610 unsigned int currSize = FreeArray[ix].len;
1611
1612 unsigned int iy;
1613 for (iy = 0; iy < nTop && FreeTopTen[iy] != NULL__null; iy++) {
1614 if (FreeTopTen[iy]->len < currSize) {
1615 for (unsigned int iz = nTop-1; iz > iy; iz--) { // make room to insert new free block
1616 FreeTopTen[iz] = FreeTopTen[iz-1];
1617 }
1618 FreeTopTen[iy] = &FreeArray[ix]; // insert new free block
1619 if (FreeTopTen[nTop-1] != NULL__null) {
1620 currMax10 = FreeTopTen[nTop-1]->len;
1621 }
1622 break; // done with this, check next free block
1623 }
1624 }
1625 if (iy >= nTop) {
1626 ast->print_cr("Internal logic error. New Max10 = %d detected, but could not be merged. Old Max10 = %d",
1627 currSize, currMax10);
1628 continue;
1629 }
1630 if (FreeTopTen[iy] == NULL__null) {
1631 FreeTopTen[iy] = &FreeArray[ix];
1632 if (iy == (nTop-1)) {
1633 currMax10 = currSize;
1634 }
1635 }
1636 }
1637 }
1638 BUFFEREDSTREAM_FLUSH_AUTO("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if ((_capacity
- _sstbuf->size()) < (size_t)(256+(_capacity>>4)
)){ _nflush++; _nforcedflush--; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } } else {
_nsavedflush++; } }
1639
1640 {
1641 printBox(ast, '-', "Top Ten Free Blocks in ", heapName);
1642
1643 //---< print Top Ten Free Blocks >---
1644 for (unsigned int iy = 0; (iy < nTop) && (FreeTopTen[iy] != NULL__null); iy++) {
1645 ast->print("Pos %3d: Block %4d - size " HEX32_FORMAT"0x%x" ",", iy+1, FreeTopTen[iy]->index, FreeTopTen[iy]->len);
1646 ast->fill_to(39);
1647 if (FreeTopTen[iy]->index == (alloc_freeBlocks-1)) {
1648 ast->print("last free block in list.");
1649 } else {
1650 ast->print("Gap (to next) " HEX32_FORMAT"0x%x" ",", FreeTopTen[iy]->gap);
1651 ast->fill_to(63);
1652 ast->print("#blocks (in gap) %d", FreeTopTen[iy]->n_gapBlocks);
1653 }
1654 ast->cr();
1655 BUFFEREDSTREAM_FLUSH_AUTO("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if ((_capacity
- _sstbuf->size()) < (size_t)(256+(_capacity>>4)
)){ _nflush++; _nforcedflush--; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } } else {
_nsavedflush++; } }
1656 }
1657 }
1658 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n") != __null) &&
(strlen("\n\n") > 0)){ _sstbuf->print("%s", "\n\n"); }
if (_sstbuf != _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush
++; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } }
1659
1660
1661 //--------------------------------------------------------
1662 //-- Find and Print Top Ten Free-Occupied-Free Triples --
1663 //--------------------------------------------------------
1664
1665 //---< find and print Top Ten Triples (Free-Occupied-Free) >---
1666 currMax10 = 0;
1667 struct FreeBlk *FreeTopTenTriple[nTop];
1668 memset(FreeTopTenTriple, 0, sizeof(FreeTopTenTriple));
1669
1670 for (unsigned int ix = 0; ix < alloc_freeBlocks-1; ix++) {
1671 // If there are stubs in the gap, this gap will never become completely free.
1672 // The triple will thus never merge to one free block.
1673 unsigned int lenTriple = FreeArray[ix].len + (FreeArray[ix].stubs_in_gap ? 0 : FreeArray[ix].gap + FreeArray[ix+1].len);
1674 FreeArray[ix].len = lenTriple;
1675 if (lenTriple > currMax10) { // larger than the ten largest found so far
1676
1677 unsigned int iy;
1678 for (iy = 0; (iy < nTop) && (FreeTopTenTriple[iy] != NULL__null); iy++) {
1679 if (FreeTopTenTriple[iy]->len < lenTriple) {
1680 for (unsigned int iz = nTop-1; iz > iy; iz--) {
1681 FreeTopTenTriple[iz] = FreeTopTenTriple[iz-1];
1682 }
1683 FreeTopTenTriple[iy] = &FreeArray[ix];
1684 if (FreeTopTenTriple[nTop-1] != NULL__null) {
1685 currMax10 = FreeTopTenTriple[nTop-1]->len;
1686 }
1687 break;
1688 }
1689 }
1690 if (iy == nTop) {
1691 ast->print_cr("Internal logic error. New Max10 = %d detected, but could not be merged. Old Max10 = %d",
1692 lenTriple, currMax10);
1693 continue;
1694 }
1695 if (FreeTopTenTriple[iy] == NULL__null) {
1696 FreeTopTenTriple[iy] = &FreeArray[ix];
1697 if (iy == (nTop-1)) {
1698 currMax10 = lenTriple;
1699 }
1700 }
1701 }
1702 }
1703 BUFFEREDSTREAM_FLUSH_AUTO("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if ((_capacity
- _sstbuf->size()) < (size_t)(256+(_capacity>>4)
)){ _nflush++; _nforcedflush--; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } } else {
_nsavedflush++; } }
1704
1705 {
1706 printBox(ast, '-', "Top Ten Free-Occupied-Free Triples in ", heapName);
1707 ast->print_cr(" Use this information to judge how likely it is that a large(r) free block\n"
1708 " might get created by code cache sweeping.\n"
1709 " If all the occupied blocks can be swept, the three free blocks will be\n"
1710 " merged into one (much larger) free block. That would reduce free space\n"
1711 " fragmentation.\n");
1712
1713 //---< print Top Ten Free-Occupied-Free Triples >---
1714 for (unsigned int iy = 0; (iy < nTop) && (FreeTopTenTriple[iy] != NULL__null); iy++) {
1715 ast->print("Pos %3d: Block %4d - size " HEX32_FORMAT"0x%x" ",", iy+1, FreeTopTenTriple[iy]->index, FreeTopTenTriple[iy]->len);
1716 ast->fill_to(39);
1717 ast->print("Gap (to next) " HEX32_FORMAT"0x%x" ",", FreeTopTenTriple[iy]->gap);
1718 ast->fill_to(63);
1719 ast->print("#blocks (in gap) %d", FreeTopTenTriple[iy]->n_gapBlocks);
1720 ast->cr();
1721 BUFFEREDSTREAM_FLUSH_AUTO("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if ((_capacity
- _sstbuf->size()) < (size_t)(256+(_capacity>>4)
)){ _nflush++; _nforcedflush--; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } } else {
_nsavedflush++; } }
1722 }
1723 }
1724 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n") != __null) &&
(strlen("\n\n") > 0)){ _sstbuf->print("%s", "\n\n"); }
if (_sstbuf != _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush
++; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } }
1725}
1726
1727
1728void CodeHeapState::print_count(outputStream* out, CodeHeap* heap) {
1729 if (!initialization_complete) {
1730 return;
1731 }
1732
1733 const char* heapName = get_heapName(heap);
1734 get_HeapStatGlobals(out, heapName);
1735
1736 if ((StatArray == NULL__null) || (alloc_granules == 0)) {
1737 return;
1738 }
1739 BUFFEREDSTREAM_DECL(ast, out)ResourceMark _rm; size_t _nflush = 0; size_t _nforcedflush = 0
; size_t _nsavedflush = 0; size_t _nlockedflush = 0; size_t _nflush_bytes
= 0; size_t _capacity = 4*K; bufferedStream _sstobj(4*K); bufferedStream
* _sstbuf = &_sstobj; outputStream* _outbuf = out; bufferedStream
* ast = &_sstobj;;
1740
1741 unsigned int granules_per_line = 32;
1742 char* low_bound = heap->low_boundary();
1743
1744 {
1745 printBox(ast, '=', "B L O C K C O U N T S for ", heapName);
1746 ast->print_cr(" Each granule contains an individual number of heap blocks. Large blocks\n"
1747 " may span multiple granules and are counted for each granule they touch.\n");
1748 if (segment_granules) {
1749 ast->print_cr(" You have selected granule size to be as small as segment size.\n"
1750 " As a result, each granule contains exactly one block (or a part of one block)\n"
1751 " or is displayed as empty (' ') if it's BlobType does not match the selection.\n"
1752 " Occupied granules show their BlobType character, see legend.\n");
1753 print_blobType_legend(ast);
1754 }
1755 BUFFEREDSTREAM_FLUSH_LOCKED(""){ ttyLocker ttyl; _nlockedflush++; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } }
1756 }
1757
1758 {
1759 if (segment_granules) {
1760 printBox(ast, '-', "Total (all types) count for granule size == segment size", NULL__null);
1761
1762 granules_per_line = 128;
1763 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1764 print_line_delim(out, ast, low_bound, ix, granules_per_line);
1765 print_blobType_single(ast, StatArray[ix].type);
1766 }
1767 } else {
1768 printBox(ast, '-', "Total (all tiers) count, 0x1..0xf. '*' indicates >= 16 blocks, ' ' indicates empty", NULL__null);
1769
1770 granules_per_line = 128;
1771 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1772 print_line_delim(out, ast, low_bound, ix, granules_per_line);
1773 unsigned int count = StatArray[ix].t1_count + StatArray[ix].t2_count + StatArray[ix].tx_count
1774 + StatArray[ix].stub_count + StatArray[ix].dead_count;
1775 print_count_single(ast, count);
1776 }
1777 }
1778 BUFFEREDSTREAM_FLUSH_LOCKED("|\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("|\n\n\n") != __null
) && (strlen("|\n\n\n") > 0)){ _sstbuf->print("%s"
, "|\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
1779 }
1780
1781 {
1782 if (nBlocks_t1 > 0) {
1783 printBox(ast, '-', "Tier1 nMethod count only, 0x1..0xf. '*' indicates >= 16 blocks, ' ' indicates empty", NULL__null);
1784
1785 granules_per_line = 128;
1786 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1787 print_line_delim(out, ast, low_bound, ix, granules_per_line);
1788 if (segment_granules && StatArray[ix].t1_count > 0) {
1789 print_blobType_single(ast, StatArray[ix].type);
1790 } else {
1791 print_count_single(ast, StatArray[ix].t1_count);
1792 }
1793 }
1794 ast->print("|");
1795 } else {
1796 ast->print("No Tier1 nMethods found in CodeHeap.");
1797 }
1798 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
1799 }
1800
1801 {
1802 if (nBlocks_t2 > 0) {
1803 printBox(ast, '-', "Tier2 nMethod count only, 0x1..0xf. '*' indicates >= 16 blocks, ' ' indicates empty", NULL__null);
1804
1805 granules_per_line = 128;
1806 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1807 print_line_delim(out, ast, low_bound, ix, granules_per_line);
1808 if (segment_granules && StatArray[ix].t2_count > 0) {
1809 print_blobType_single(ast, StatArray[ix].type);
1810 } else {
1811 print_count_single(ast, StatArray[ix].t2_count);
1812 }
1813 }
1814 ast->print("|");
1815 } else {
1816 ast->print("No Tier2 nMethods found in CodeHeap.");
1817 }
1818 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
1819 }
1820
1821 {
1822 if (nBlocks_alive > 0) {
1823 printBox(ast, '-', "not_used/not_entrant/not_installed nMethod count only, 0x1..0xf. '*' indicates >= 16 blocks, ' ' indicates empty", NULL__null);
1824
1825 granules_per_line = 128;
1826 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1827 print_line_delim(out, ast, low_bound, ix, granules_per_line);
1828 if (segment_granules && StatArray[ix].tx_count > 0) {
1829 print_blobType_single(ast, StatArray[ix].type);
1830 } else {
1831 print_count_single(ast, StatArray[ix].tx_count);
1832 }
1833 }
1834 ast->print("|");
1835 } else {
1836 ast->print("No not_used/not_entrant nMethods found in CodeHeap.");
1837 }
1838 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
1839 }
1840
1841 {
1842 if (nBlocks_stub > 0) {
1843 printBox(ast, '-', "Stub & Blob count only, 0x1..0xf. '*' indicates >= 16 blocks, ' ' indicates empty", NULL__null);
1844
1845 granules_per_line = 128;
1846 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1847 print_line_delim(out, ast, low_bound, ix, granules_per_line);
1848 if (segment_granules && StatArray[ix].stub_count > 0) {
1849 print_blobType_single(ast, StatArray[ix].type);
1850 } else {
1851 print_count_single(ast, StatArray[ix].stub_count);
1852 }
1853 }
1854 ast->print("|");
1855 } else {
1856 ast->print("No Stubs and Blobs found in CodeHeap.");
1857 }
1858 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
1859 }
1860
1861 {
1862 if (nBlocks_dead > 0) {
1863 printBox(ast, '-', "Dead nMethod count only, 0x1..0xf. '*' indicates >= 16 blocks, ' ' indicates empty", NULL__null);
1864
1865 granules_per_line = 128;
1866 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1867 print_line_delim(out, ast, low_bound, ix, granules_per_line);
1868 if (segment_granules && StatArray[ix].dead_count > 0) {
1869 print_blobType_single(ast, StatArray[ix].type);
1870 } else {
1871 print_count_single(ast, StatArray[ix].dead_count);
1872 }
1873 }
1874 ast->print("|");
1875 } else {
1876 ast->print("No dead nMethods found in CodeHeap.");
1877 }
1878 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
1879 }
1880
1881 {
1882 if (!segment_granules) { // Prevent totally redundant printouts
1883 printBox(ast, '-', "Count by tier (combined, no dead blocks): <#t1>:<#t2>:<#s>, 0x0..0xf. '*' indicates >= 16 blocks", NULL__null);
1884
1885 granules_per_line = 24;
1886 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1887 print_line_delim(out, ast, low_bound, ix, granules_per_line);
1888
1889 print_count_single(ast, StatArray[ix].t1_count);
1890 ast->print(":");
1891 print_count_single(ast, StatArray[ix].t2_count);
1892 ast->print(":");
1893 if (segment_granules && StatArray[ix].stub_count > 0) {
1894 print_blobType_single(ast, StatArray[ix].type);
1895 } else {
1896 print_count_single(ast, StatArray[ix].stub_count);
1897 }
1898 ast->print(" ");
1899 }
1900 BUFFEREDSTREAM_FLUSH_LOCKED("|\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("|\n\n\n") != __null
) && (strlen("|\n\n\n") > 0)){ _sstbuf->print("%s"
, "|\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
1901 }
1902 }
1903}
1904
1905
1906void CodeHeapState::print_space(outputStream* out, CodeHeap* heap) {
1907 if (!initialization_complete) {
1908 return;
1909 }
1910
1911 const char* heapName = get_heapName(heap);
1912 get_HeapStatGlobals(out, heapName);
1913
1914 if ((StatArray == NULL__null) || (alloc_granules == 0)) {
1915 return;
1916 }
1917 BUFFEREDSTREAM_DECL(ast, out)ResourceMark _rm; size_t _nflush = 0; size_t _nforcedflush = 0
; size_t _nsavedflush = 0; size_t _nlockedflush = 0; size_t _nflush_bytes
= 0; size_t _capacity = 4*K; bufferedStream _sstobj(4*K); bufferedStream
* _sstbuf = &_sstobj; outputStream* _outbuf = out; bufferedStream
* ast = &_sstobj;;
1918
1919 unsigned int granules_per_line = 32;
1920 char* low_bound = heap->low_boundary();
1921
1922 {
1923 printBox(ast, '=', "S P A C E U S A G E & F R A G M E N T A T I O N for ", heapName);
1924 ast->print_cr(" The heap space covered by one granule is occupied to a various extend.\n"
1925 " The granule occupancy is displayed by one decimal digit per granule.\n");
1926 if (segment_granules) {
1927 ast->print_cr(" You have selected granule size to be as small as segment size.\n"
1928 " As a result, each granule contains exactly one block (or a part of one block)\n"
1929 " or is displayed as empty (' ') if it's BlobType does not match the selection.\n"
1930 " Occupied granules show their BlobType character, see legend.\n");
1931 print_blobType_legend(ast);
1932 } else {
1933 ast->print_cr(" These digits represent a fill percentage range (see legend).\n");
1934 print_space_legend(ast);
1935 }
1936 BUFFEREDSTREAM_FLUSH_LOCKED(""){ ttyLocker ttyl; _nlockedflush++; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } }
1937 }
1938
1939 {
1940 if (segment_granules) {
1941 printBox(ast, '-', "Total (all types) space consumption for granule size == segment size", NULL__null);
1942
1943 granules_per_line = 128;
1944 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1945 print_line_delim(out, ast, low_bound, ix, granules_per_line);
1946 print_blobType_single(ast, StatArray[ix].type);
1947 }
1948 } else {
1949 printBox(ast, '-', "Total (all types) space consumption. ' ' indicates empty, '*' indicates full.", NULL__null);
1950
1951 granules_per_line = 128;
1952 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1953 print_line_delim(out, ast, low_bound, ix, granules_per_line);
1954 unsigned int space = StatArray[ix].t1_space + StatArray[ix].t2_space + StatArray[ix].tx_space
1955 + StatArray[ix].stub_space + StatArray[ix].dead_space;
1956 print_space_single(ast, space);
1957 }
1958 }
1959 BUFFEREDSTREAM_FLUSH_LOCKED("|\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("|\n\n\n") != __null
) && (strlen("|\n\n\n") > 0)){ _sstbuf->print("%s"
, "|\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
1960 }
1961
1962 {
1963 if (nBlocks_t1 > 0) {
1964 printBox(ast, '-', "Tier1 space consumption. ' ' indicates empty, '*' indicates full", NULL__null);
1965
1966 granules_per_line = 128;
1967 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1968 print_line_delim(out, ast, low_bound, ix, granules_per_line);
1969 if (segment_granules && StatArray[ix].t1_space > 0) {
1970 print_blobType_single(ast, StatArray[ix].type);
1971 } else {
1972 print_space_single(ast, StatArray[ix].t1_space);
1973 }
1974 }
1975 ast->print("|");
1976 } else {
1977 ast->print("No Tier1 nMethods found in CodeHeap.");
1978 }
1979 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
1980 }
1981
1982 {
1983 if (nBlocks_t2 > 0) {
1984 printBox(ast, '-', "Tier2 space consumption. ' ' indicates empty, '*' indicates full", NULL__null);
1985
1986 granules_per_line = 128;
1987 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1988 print_line_delim(out, ast, low_bound, ix, granules_per_line);
1989 if (segment_granules && StatArray[ix].t2_space > 0) {
1990 print_blobType_single(ast, StatArray[ix].type);
1991 } else {
1992 print_space_single(ast, StatArray[ix].t2_space);
1993 }
1994 }
1995 ast->print("|");
1996 } else {
1997 ast->print("No Tier2 nMethods found in CodeHeap.");
1998 }
1999 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
2000 }
2001
2002 {
2003 if (nBlocks_alive > 0) {
2004 printBox(ast, '-', "not_used/not_entrant/not_installed space consumption. ' ' indicates empty, '*' indicates full", NULL__null);
2005
2006 granules_per_line = 128;
2007 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
2008 print_line_delim(out, ast, low_bound, ix, granules_per_line);
2009 if (segment_granules && StatArray[ix].tx_space > 0) {
2010 print_blobType_single(ast, StatArray[ix].type);
2011 } else {
2012 print_space_single(ast, StatArray[ix].tx_space);
2013 }
2014 }
2015 ast->print("|");
2016 } else {
2017 ast->print("No Tier2 nMethods found in CodeHeap.");
2018 }
2019 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
2020 }
2021
2022 {
2023 if (nBlocks_stub > 0) {
2024 printBox(ast, '-', "Stub and Blob space consumption. ' ' indicates empty, '*' indicates full", NULL__null);
2025
2026 granules_per_line = 128;
2027 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
2028 print_line_delim(out, ast, low_bound, ix, granules_per_line);
2029 if (segment_granules && StatArray[ix].stub_space > 0) {
2030 print_blobType_single(ast, StatArray[ix].type);
2031 } else {
2032 print_space_single(ast, StatArray[ix].stub_space);
2033 }
2034 }
2035 ast->print("|");
2036 } else {
2037 ast->print("No Stubs and Blobs found in CodeHeap.");
2038 }
2039 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
2040 }
2041
2042 {
2043 if (nBlocks_dead > 0) {
2044 printBox(ast, '-', "Dead space consumption. ' ' indicates empty, '*' indicates full", NULL__null);
2045
2046 granules_per_line = 128;
2047 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
2048 print_line_delim(out, ast, low_bound, ix, granules_per_line);
2049 print_space_single(ast, StatArray[ix].dead_space);
2050 }
2051 ast->print("|");
2052 } else {
2053 ast->print("No dead nMethods found in CodeHeap.");
2054 }
2055 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
2056 }
2057
2058 {
2059 if (!segment_granules) { // Prevent totally redundant printouts
2060 printBox(ast, '-', "Space consumption by tier (combined): <t1%>:<t2%>:<s%>. ' ' indicates empty, '*' indicates full", NULL__null);
2061
2062 granules_per_line = 24;
2063 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
2064 print_line_delim(out, ast, low_bound, ix, granules_per_line);
2065
2066 if (segment_granules && StatArray[ix].t1_space > 0) {
2067 print_blobType_single(ast, StatArray[ix].type);
2068 } else {
2069 print_space_single(ast, StatArray[ix].t1_space);
2070 }
2071 ast->print(":");
2072 if (segment_granules && StatArray[ix].t2_space > 0) {
2073 print_blobType_single(ast, StatArray[ix].type);
2074 } else {
2075 print_space_single(ast, StatArray[ix].t2_space);
2076 }
2077 ast->print(":");
2078 if (segment_granules && StatArray[ix].stub_space > 0) {
2079 print_blobType_single(ast, StatArray[ix].type);
2080 } else {
2081 print_space_single(ast, StatArray[ix].stub_space);
2082 }
2083 ast->print(" ");
2084 }
2085 ast->print("|");
2086 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
2087 }
2088 }
2089}
2090
2091void CodeHeapState::print_age(outputStream* out, CodeHeap* heap) {
2092 if (!initialization_complete) {
2093 return;
2094 }
2095
2096 const char* heapName = get_heapName(heap);
2097 get_HeapStatGlobals(out, heapName);
2098
2099 if ((StatArray == NULL__null) || (alloc_granules == 0)) {
2100 return;
2101 }
2102 BUFFEREDSTREAM_DECL(ast, out)ResourceMark _rm; size_t _nflush = 0; size_t _nforcedflush = 0
; size_t _nsavedflush = 0; size_t _nlockedflush = 0; size_t _nflush_bytes
= 0; size_t _capacity = 4*K; bufferedStream _sstobj(4*K); bufferedStream
* _sstbuf = &_sstobj; outputStream* _outbuf = out; bufferedStream
* ast = &_sstobj;;
2103
2104 unsigned int granules_per_line = 32;
2105 char* low_bound = heap->low_boundary();
2106
2107 {
2108 printBox(ast, '=', "M E T H O D A G E by CompileID for ", heapName);
2109 ast->print_cr(" The age of a compiled method in the CodeHeap is not available as a\n"
2110 " time stamp. Instead, a relative age is deducted from the method's compilation ID.\n"
2111 " Age information is available for tier1 and tier2 methods only. There is no\n"
2112 " age information for stubs and blobs, because they have no compilation ID assigned.\n"
2113 " Information for the youngest method (highest ID) in the granule is printed.\n"
2114 " Refer to the legend to learn how method age is mapped to the displayed digit.");
2115 print_age_legend(ast);
2116 BUFFEREDSTREAM_FLUSH_LOCKED(""){ ttyLocker ttyl; _nlockedflush++; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } }
2117 }
2118
2119 {
2120 printBox(ast, '-', "Age distribution. '0' indicates youngest 1/256, '8': oldest half, ' ': no age information", NULL__null);
2121
2122 granules_per_line = 128;
2123 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
2124 print_line_delim(out, ast, low_bound, ix, granules_per_line);
2125 unsigned int age1 = StatArray[ix].t1_age;
2126 unsigned int age2 = StatArray[ix].t2_age;
2127 unsigned int agex = StatArray[ix].tx_age;
2128 unsigned int age = age1 > age2 ? age1 : age2;
2129 age = age > agex ? age : agex;
2130 print_age_single(ast, age);
2131 }
2132 ast->print("|");
2133 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
2134 }
2135
2136 {
2137 if (nBlocks_t1 > 0) {
2138 printBox(ast, '-', "Tier1 age distribution. '0' indicates youngest 1/256, '8': oldest half, ' ': no age information", NULL__null);
2139
2140 granules_per_line = 128;
2141 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
2142 print_line_delim(out, ast, low_bound, ix, granules_per_line);
2143 print_age_single(ast, StatArray[ix].t1_age);
2144 }
2145 ast->print("|");
2146 } else {
2147 ast->print("No Tier1 nMethods found in CodeHeap.");
2148 }
2149 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
2150 }
2151
2152 {
2153 if (nBlocks_t2 > 0) {
2154 printBox(ast, '-', "Tier2 age distribution. '0' indicates youngest 1/256, '8': oldest half, ' ': no age information", NULL__null);
2155
2156 granules_per_line = 128;
2157 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
2158 print_line_delim(out, ast, low_bound, ix, granules_per_line);
2159 print_age_single(ast, StatArray[ix].t2_age);
2160 }
2161 ast->print("|");
2162 } else {
2163 ast->print("No Tier2 nMethods found in CodeHeap.");
2164 }
2165 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
2166 }
2167
2168 {
2169 if (nBlocks_alive > 0) {
2170 printBox(ast, '-', "not_used/not_entrant/not_installed age distribution. '0' indicates youngest 1/256, '8': oldest half, ' ': no age information", NULL__null);
2171
2172 granules_per_line = 128;
2173 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
2174 print_line_delim(out, ast, low_bound, ix, granules_per_line);
2175 print_age_single(ast, StatArray[ix].tx_age);
2176 }
2177 ast->print("|");
2178 } else {
2179 ast->print("No Tier2 nMethods found in CodeHeap.");
2180 }
2181 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
2182 }
2183
2184 {
2185 if (!segment_granules) { // Prevent totally redundant printouts
2186 printBox(ast, '-', "age distribution by tier <a1>:<a2>. '0' indicates youngest 1/256, '8': oldest half, ' ': no age information", NULL__null);
2187
2188 granules_per_line = 32;
2189 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
2190 print_line_delim(out, ast, low_bound, ix, granules_per_line);
2191 print_age_single(ast, StatArray[ix].t1_age);
2192 ast->print(":");
2193 print_age_single(ast, StatArray[ix].t2_age);
2194 ast->print(" ");
2195 }
2196 ast->print("|");
2197 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n\n") != __null)
&& (strlen("\n\n\n") > 0)){ _sstbuf->print("%s"
, "\n\n\n"); } if (_sstbuf != _outbuf) { if (_sstbuf->size
() != 0) { _nforcedflush++; _nflush_bytes += _sstbuf->size
(); _outbuf->print("%s", _sstbuf->as_string()); _sstbuf
->reset(); } } }
2198 }
2199 }
2200}
2201
2202
2203void CodeHeapState::print_names(outputStream* out, CodeHeap* heap) {
2204 if (!initialization_complete) {
2205 return;
2206 }
2207
2208 const char* heapName = get_heapName(heap);
2209 get_HeapStatGlobals(out, heapName);
2210
2211 if ((StatArray == NULL__null) || (alloc_granules == 0)) {
2212 return;
2213 }
2214 BUFFEREDSTREAM_DECL(ast, out)ResourceMark _rm; size_t _nflush = 0; size_t _nforcedflush = 0
; size_t _nsavedflush = 0; size_t _nlockedflush = 0; size_t _nflush_bytes
= 0; size_t _capacity = 4*K; bufferedStream _sstobj(4*K); bufferedStream
* _sstbuf = &_sstobj; outputStream* _outbuf = out; bufferedStream
* ast = &_sstobj;;
2215
2216 unsigned int granules_per_line = 128;
2217 char* low_bound = heap->low_boundary();
2218 CodeBlob* last_blob = NULL__null;
2219 bool name_in_addr_range = true;
2220 bool have_locks = holding_required_locks();
2221
2222 //---< print at least 128K per block (i.e. between headers) >---
2223 if (granules_per_line*granule_size < 128*K) {
2224 granules_per_line = (unsigned int)((128*K)/granule_size);
2225 }
2226
2227 printBox(ast, '=', "M E T H O D N A M E S for ", heapName);
2228 ast->print_cr(" Method names are dynamically retrieved from the code cache at print time.\n"
2229 " Due to the living nature of the code heap and because the CodeCache_lock\n"
2230 " is not continuously held, the displayed name might be wrong or no name\n"
2231 " might be found at all. The likelihood for that to happen increases\n"
2232 " over time passed between aggregation and print steps.\n");
2233 BUFFEREDSTREAM_FLUSH_LOCKED(""){ ttyLocker ttyl; _nlockedflush++; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } }
2234
2235 for (unsigned int ix = 0; ix < alloc_granules; ix++) {
2236 //---< print a new blob on a new line >---
2237 if (ix%granules_per_line == 0) {
2238 if (!name_in_addr_range) {
2239 ast->print_cr("No methods, blobs, or stubs found in this address range");
2240 }
2241 name_in_addr_range = false;
2242
2243 size_t end_ix = (ix+granules_per_line <= alloc_granules) ? ix+granules_per_line : alloc_granules;
2244 ast->cr();
2245 ast->print_cr("--------------------------------------------------------------------");
2246 ast->print_cr("Address range [" INTPTR_FORMAT"0x%016" "l" "x" "," INTPTR_FORMAT"0x%016" "l" "x" "), " SIZE_FORMAT"%" "l" "u" "k", p2i(low_bound+ix*granule_size), p2i(low_bound + end_ix*granule_size), (end_ix - ix)*granule_size/(size_t)K);
2247 ast->print_cr("--------------------------------------------------------------------");
2248 BUFFEREDSTREAM_FLUSH_AUTO("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if ((_capacity
- _sstbuf->size()) < (size_t)(256+(_capacity>>4)
)){ _nflush++; _nforcedflush--; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } } else {
_nsavedflush++; } }
2249 }
2250 // Only check granule if it contains at least one blob.
2251 unsigned int nBlobs = StatArray[ix].t1_count + StatArray[ix].t2_count + StatArray[ix].tx_count +
2252 StatArray[ix].stub_count + StatArray[ix].dead_count;
2253 if (nBlobs > 0 ) {
2254 for (unsigned int is = 0; is < granule_size; is+=(unsigned int)seg_size) {
2255 // heap->find_start() is safe. Only works on _segmap.
2256 // Returns NULL or void*. Returned CodeBlob may be uninitialized.
2257 char* this_seg = low_bound + ix*granule_size + is;
2258 CodeBlob* this_blob = (CodeBlob*)(heap->find_start(this_seg));
2259 bool blob_is_safe = blob_access_is_safe(this_blob);
2260 // blob could have been flushed, freed, and merged.
2261 // this_blob < last_blob is an indicator for that.
2262 if (blob_is_safe && (this_blob > last_blob)) {
2263 last_blob = this_blob;
2264
2265 //---< get type and name >---
2266 blobType cbType = noType;
2267 if (segment_granules) {
2268 cbType = (blobType)StatArray[ix].type;
2269 } else {
2270 //---< access these fields only if we own the CodeCache_lock >---
2271 if (have_locks) {
2272 cbType = get_cbType(this_blob);
2273 }
2274 }
2275
2276 //---< access these fields only if we own the CodeCache_lock >---
2277 const char* blob_name = "<unavailable>";
2278 nmethod* nm = NULL__null;
2279 if (have_locks) {
2280 blob_name = this_blob->name();
2281 nm = this_blob->as_nmethod_or_null();
2282 // this_blob->name() could return NULL if no name was given to CTOR. Inlined, maybe invisible on stack
2283 if (blob_name == NULL__null) {
2284 blob_name = "<unavailable>";
2285 }
2286 }
2287
2288 //---< print table header for new print range >---
2289 if (!name_in_addr_range) {
2290 name_in_addr_range = true;
2291 ast->fill_to(51);
2292 ast->print("%9s", "compiler");
2293 ast->fill_to(61);
2294 ast->print_cr("%6s", "method");
2295 ast->print_cr("%18s %13s %17s %9s %5s %18s %s", "Addr(module) ", "offset", "size", " type lvl", " temp", "blobType ", "Name");
2296 BUFFEREDSTREAM_FLUSH_AUTO("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if ((_capacity
- _sstbuf->size()) < (size_t)(256+(_capacity>>4)
)){ _nflush++; _nforcedflush--; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } } else {
_nsavedflush++; } }
2297 }
2298
2299 //---< print line prefix (address and offset from CodeHeap start) >---
2300 ast->print(INTPTR_FORMAT"0x%016" "l" "x", p2i(this_blob));
2301 ast->fill_to(19);
2302 ast->print("(+" PTR32_FORMAT"0x%08" "x" ")", (unsigned int)((char*)this_blob-low_bound));
2303 ast->fill_to(33);
2304
2305 // access nmethod and Method fields only if we own the CodeCache_lock.
2306 // This fact is implicitly transported via nm != NULL.
2307 if (nmethod_access_is_safe(nm)) {
2308 Method* method = nm->method();
2309 ResourceMark rm;
2310 //---< collect all data to locals as quickly as possible >---
2311 unsigned int total_size = nm->total_size();
2312 int hotness = nm->hotness_counter();
2313 bool get_name = (cbType == nMethod_inuse) || (cbType == nMethod_notused);
2314 //---< nMethod size in hex >---
2315 ast->print(PTR32_FORMAT"0x%08" "x", total_size);
2316 ast->print("(" SIZE_FORMAT_W(4)"%" "4" "l" "u" "K)", total_size/K);
2317 //---< compiler information >---
2318 ast->fill_to(51);
2319 ast->print("%5s %3d", compTypeName[StatArray[ix].compiler], StatArray[ix].level);
2320 //---< method temperature >---
2321 ast->fill_to(62);
2322 ast->print("%5d", hotness);
2323 //---< name and signature >---
2324 ast->fill_to(62+6);
2325 ast->print("%s", blobTypeName[cbType]);
2326 ast->fill_to(82+6);
2327 if (cbType == nMethod_dead) {
2328 ast->print("%14s", " zombie method");
2329 }
2330
2331 if (get_name) {
2332 Symbol* methName = method->name();
2333 const char* methNameS = (methName == NULL__null) ? NULL__null : methName->as_C_string();
2334 methNameS = (methNameS == NULL__null) ? "<method name unavailable>" : methNameS;
2335 Symbol* methSig = method->signature();
2336 const char* methSigS = (methSig == NULL__null) ? NULL__null : methSig->as_C_string();
2337 methSigS = (methSigS == NULL__null) ? "<method signature unavailable>" : methSigS;
2338 Klass* klass = method->method_holder();
2339 assert(klass != nullptr, "No method holder")do { if (!(klass != nullptr)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/code/codeHeapState.cpp"
, 2339, "assert(" "klass != nullptr" ") failed", "No method holder"
); ::breakpoint(); } } while (0)
;
2340 const char* classNameS = (klass->name() == nullptr) ? "<class name unavailable>" : klass->external_name();
2341
2342 ast->print("%s.", classNameS);
2343 ast->print("%s", methNameS);
2344 ast->print("%s", methSigS);
2345 } else {
2346 ast->print("%s", blob_name);
2347 }
2348 } else if (blob_is_safe) {
2349 ast->fill_to(62+6);
2350 ast->print("%s", blobTypeName[cbType]);
2351 ast->fill_to(82+6);
2352 ast->print("%s", blob_name);
2353 } else {
2354 ast->fill_to(62+6);
2355 ast->print("<stale blob>");
2356 }
2357 ast->cr();
2358 BUFFEREDSTREAM_FLUSH_AUTO("")if ((("") != __null) && (strlen("") > 0)){ _sstbuf
->print("%s", ""); } if (_sstbuf != _outbuf) { if ((_capacity
- _sstbuf->size()) < (size_t)(256+(_capacity>>4)
)){ _nflush++; _nforcedflush--; if ((("") != __null) &&
(strlen("") > 0)){ _sstbuf->print("%s", ""); } if (_sstbuf
!= _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush++
; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } } else {
_nsavedflush++; } }
2359 } else if (!blob_is_safe && (this_blob != last_blob) && (this_blob != NULL__null)) {
2360 last_blob = this_blob;
2361 }
2362 }
2363 } // nBlobs > 0
2364 }
2365 BUFFEREDSTREAM_FLUSH_LOCKED("\n\n"){ ttyLocker ttyl; _nlockedflush++; if ((("\n\n") != __null) &&
(strlen("\n\n") > 0)){ _sstbuf->print("%s", "\n\n"); }
if (_sstbuf != _outbuf) { if (_sstbuf->size() != 0) { _nforcedflush
++; _nflush_bytes += _sstbuf->size(); _outbuf->print("%s"
, _sstbuf->as_string()); _sstbuf->reset(); } } }
2366}
2367
2368
2369void CodeHeapState::printBox(outputStream* ast, const char border, const char* text1, const char* text2) {
2370 unsigned int lineLen = 1 + 2 + 2 + 1;
2371 char edge, frame;
2372
2373 if (text1 != NULL__null) {
2374 lineLen += (unsigned int)strlen(text1); // text1 is much shorter than MAX_INT chars.
2375 }
2376 if (text2 != NULL__null) {
2377 lineLen += (unsigned int)strlen(text2); // text2 is much shorter than MAX_INT chars.
2378 }
2379 if (border == '-') {
2380 edge = '+';
2381 frame = '|';
2382 } else {
2383 edge = border;
2384 frame = border;
2385 }
2386
2387 ast->print("%c", edge);
2388 for (unsigned int i = 0; i < lineLen-2; i++) {
2389 ast->print("%c", border);
2390 }
2391 ast->print_cr("%c", edge);
2392
2393 ast->print("%c ", frame);
2394 if (text1 != NULL__null) {
2395 ast->print("%s", text1);
2396 }
2397 if (text2 != NULL__null) {
2398 ast->print("%s", text2);
2399 }
2400 ast->print_cr(" %c", frame);
2401
2402 ast->print("%c", edge);
2403 for (unsigned int i = 0; i < lineLen-2; i++) {
2404 ast->print("%c", border);
2405 }
2406 ast->print_cr("%c", edge);
2407}
2408
2409void CodeHeapState::print_blobType_legend(outputStream* out) {
2410 out->cr();
2411 printBox(out, '-', "Block types used in the following CodeHeap dump", NULL__null);
2412 for (int type = noType; type < lastType; type += 1) {
2413 out->print_cr(" %c - %s", blobTypeChar[type], blobTypeName[type]);
2414 }
2415 out->print_cr(" -----------------------------------------------------");
2416 out->cr();
2417}
2418
2419void CodeHeapState::print_space_legend(outputStream* out) {
2420 unsigned int indicator = 0;
2421 unsigned int age_range = 256;
2422 unsigned int range_beg = latest_compilation_id;
Value stored to 'range_beg' during its initialization is never read
2423 out->cr();
2424 printBox(out, '-', "Space ranges, based on granule occupancy", NULL__null);
2425 out->print_cr(" - 0%% == occupancy");
2426 for (int i=0; i<=9; i++) {
2427 out->print_cr(" %d - %3d%% < occupancy < %3d%%", i, 10*i, 10*(i+1));
2428 }
2429 out->print_cr(" * - 100%% == occupancy");
2430 out->print_cr(" ----------------------------------------------");
2431 out->cr();
2432}
2433
2434void CodeHeapState::print_age_legend(outputStream* out) {
2435 unsigned int indicator = 0;
2436 unsigned int age_range = 256;
2437 unsigned int range_beg = latest_compilation_id;
2438 out->cr();
2439 printBox(out, '-', "Age ranges, based on compilation id", NULL__null);
2440 while (age_range > 0) {
2441 out->print_cr(" %d - %6d to %6d", indicator, range_beg, latest_compilation_id - latest_compilation_id/age_range);
2442 range_beg = latest_compilation_id - latest_compilation_id/age_range;
2443 age_range /= 2;
2444 indicator += 1;
2445 }
2446 out->print_cr(" -----------------------------------------");
2447 out->cr();
2448}
2449
2450void CodeHeapState::print_blobType_single(outputStream* out, u2 /* blobType */ type) {
2451 out->print("%c", blobTypeChar[type]);
2452}
2453
2454void CodeHeapState::print_count_single(outputStream* out, unsigned short count) {
2455 if (count >= 16) out->print("*");
2456 else if (count > 0) out->print("%1.1x", count);
2457 else out->print(" ");
2458}
2459
2460void CodeHeapState::print_space_single(outputStream* out, unsigned short space) {
2461 size_t space_in_bytes = ((unsigned int)space)<<log2_seg_size;
2462 char fraction = (space == 0) ? ' ' : (space_in_bytes >= granule_size-1) ? '*' : char('0'+10*space_in_bytes/granule_size);
2463 out->print("%c", fraction);
2464}
2465
2466void CodeHeapState::print_age_single(outputStream* out, unsigned int age) {
2467 unsigned int indicator = 0;
2468 unsigned int age_range = 256;
2469 if (age > 0) {
2470 while ((age_range > 0) && (latest_compilation_id-age > latest_compilation_id/age_range)) {
2471 age_range /= 2;
2472 indicator += 1;
2473 }
2474 out->print("%c", char('0'+indicator));
2475 } else {
2476 out->print(" ");
2477 }
2478}
2479
2480void CodeHeapState::print_line_delim(outputStream* out, outputStream* ast, char* low_bound, unsigned int ix, unsigned int gpl) {
2481 if (ix % gpl == 0) {
2482 if (ix > 0) {
2483 ast->print("|");
2484 }
2485 ast->cr();
2486 assert(out == ast, "must use the same stream!")do { if (!(out == ast)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/code/codeHeapState.cpp"
, 2486, "assert(" "out == ast" ") failed", "must use the same stream!"
); ::breakpoint(); } } while (0)
;
2487
2488 ast->print(INTPTR_FORMAT"0x%016" "l" "x", p2i(low_bound + ix*granule_size));
2489 ast->fill_to(19);
2490 ast->print("(+" PTR32_FORMAT"0x%08" "x" "): |", (unsigned int)(ix*granule_size));
2491 }
2492}
2493
2494void CodeHeapState::print_line_delim(outputStream* out, bufferedStream* ast, char* low_bound, unsigned int ix, unsigned int gpl) {
2495 assert(out != ast, "must not use the same stream!")do { if (!(out != ast)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/code/codeHeapState.cpp"
, 2495, "assert(" "out != ast" ") failed", "must not use the same stream!"
); ::breakpoint(); } } while (0)
;
2496 if (ix % gpl == 0) {
2497 if (ix > 0) {
2498 ast->print("|");
2499 }
2500 ast->cr();
2501
2502 // can't use BUFFEREDSTREAM_FLUSH_IF("", 512) here.
2503 // can't use this expression. bufferedStream::capacity() does not exist.
2504 // if ((ast->capacity() - ast->size()) < 512) {
2505 // Assume instead that default bufferedStream capacity (4K) was used.
2506 if (ast->size() > 3*K) {
2507 ttyLocker ttyl;
2508 out->print("%s", ast->as_string());
2509 ast->reset();
2510 }
2511
2512 ast->print(INTPTR_FORMAT"0x%016" "l" "x", p2i(low_bound + ix*granule_size));
2513 ast->fill_to(19);
2514 ast->print("(+" PTR32_FORMAT"0x%08" "x" "): |", (unsigned int)(ix*granule_size));
2515 }
2516}
2517
2518// Find out which blob type we have at hand.
2519// Return "noType" if anything abnormal is detected.
2520CodeHeapState::blobType CodeHeapState::get_cbType(CodeBlob* cb) {
2521 if (cb != NULL__null) {
2522 if (cb->is_runtime_stub()) return runtimeStub;
2523 if (cb->is_deoptimization_stub()) return deoptimizationStub;
2524 if (cb->is_uncommon_trap_stub()) return uncommonTrapStub;
2525 if (cb->is_exception_stub()) return exceptionStub;
2526 if (cb->is_safepoint_stub()) return safepointStub;
2527 if (cb->is_adapter_blob()) return adapterBlob;
2528 if (cb->is_method_handles_adapter_blob()) return mh_adapterBlob;
2529 if (cb->is_buffer_blob()) return bufferBlob;
2530
2531 //---< access these fields only if we own CodeCache_lock and Compile_lock >---
2532 // Should be ensured by caller. aggregate() and print_names() do that.
2533 if (holding_required_locks()) {
2534 nmethod* nm = cb->as_nmethod_or_null();
2535 if (nm != NULL__null) { // no is_readable check required, nm = (nmethod*)cb.
2536 if (nm->is_zombie()) return nMethod_dead;
2537 if (nm->is_unloaded()) return nMethod_unloaded;
2538 if (nm->is_in_use()) return nMethod_inuse;
2539 if (nm->is_alive() && !(nm->is_not_entrant())) return nMethod_notused;
2540 if (nm->is_alive()) return nMethod_alive;
2541 return nMethod_dead;
2542 }
2543 }
2544 }
2545 return noType;
2546}
2547
2548// make sure the blob at hand is not garbage.
2549bool CodeHeapState::blob_access_is_safe(CodeBlob* this_blob) {
2550 return (this_blob != NULL__null) && // a blob must have been found, obviously
2551 (this_blob->header_size() >= 0) &&
2552 (this_blob->relocation_size() >= 0) &&
2553 ((address)this_blob + this_blob->header_size() == (address)(this_blob->relocation_begin())) &&
2554 ((address)this_blob + CodeBlob::align_code_offset(this_blob->header_size() + this_blob->relocation_size()) == (address)(this_blob->content_begin()));
2555}
2556
2557// make sure the nmethod at hand (and the linked method) is not garbage.
2558bool CodeHeapState::nmethod_access_is_safe(nmethod* nm) {
2559 Method* method = (nm == NULL__null) ? NULL__null : nm->method(); // nm->method() was found to be uninitialized, i.e. != NULL, but invalid.
2560 return (nm != NULL__null) && (method != NULL__null) && nm->is_alive() && (method->signature() != NULL__null);
2561}
2562
2563bool CodeHeapState::holding_required_locks() {
2564 return SafepointSynchronize::is_at_safepoint() ||
2565 (CodeCache_lock->owned_by_self() && Compile_lock->owned_by_self());
2566}