duke@1
|
1 /*
|
coleenp@46271
|
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
|
duke@1
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
duke@1
|
4 *
|
duke@1
|
5 * This code is free software; you can redistribute it and/or modify it
|
duke@1
|
6 * under the terms of the GNU General Public License version 2 only, as
|
duke@1
|
7 * published by the Free Software Foundation.
|
duke@1
|
8 *
|
duke@1
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
duke@1
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
duke@1
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
duke@1
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
duke@1
|
13 * accompanied this code).
|
duke@1
|
14 *
|
duke@1
|
15 * You should have received a copy of the GNU General Public License version
|
duke@1
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
duke@1
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
duke@1
|
18 *
|
trims@5547
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
trims@5547
|
20 * or visit www.oracle.com if you need additional information or have any
|
trims@5547
|
21 * questions.
|
duke@1
|
22 *
|
duke@1
|
23 */
|
duke@1
|
24
|
stefank@7397
|
25 #include "precompiled.hpp"
|
kvn@42650
|
26 #include "aot/aotLoader.hpp"
|
stefank@7397
|
27 #include "classfile/classLoader.hpp"
|
gziemski@24426
|
28 #include "classfile/stringTable.hpp"
|
stefank@7397
|
29 #include "classfile/systemDictionary.hpp"
|
stefank@7397
|
30 #include "code/codeCache.hpp"
|
stefank@7397
|
31 #include "compiler/compileBroker.hpp"
|
stefank@7397
|
32 #include "compiler/compilerOracle.hpp"
|
pliden@30764
|
33 #include "gc/shared/genCollectedHeap.hpp"
|
stefank@7397
|
34 #include "interpreter/bytecodeHistogram.hpp"
|
twisti@33160
|
35 #if INCLUDE_JVMCI
|
twisti@33160
|
36 #include "jvmci/jvmciCompiler.hpp"
|
twisti@33160
|
37 #include "jvmci/jvmciRuntime.hpp"
|
twisti@33160
|
38 #endif
|
brutisso@35061
|
39 #include "logging/log.hpp"
|
stefank@7397
|
40 #include "memory/oopFactory.hpp"
|
jprovino@37248
|
41 #include "memory/resourceArea.hpp"
|
stefank@7397
|
42 #include "memory/universe.hpp"
|
coleenp@13728
|
43 #include "oops/constantPool.hpp"
|
stefank@7397
|
44 #include "oops/generateOopMap.hpp"
|
stefank@7397
|
45 #include "oops/instanceKlass.hpp"
|
stefank@7397
|
46 #include "oops/instanceOop.hpp"
|
coleenp@13728
|
47 #include "oops/method.hpp"
|
stefank@7397
|
48 #include "oops/objArrayOop.hpp"
|
stefank@7397
|
49 #include "oops/oop.inline.hpp"
|
coleenp@8076
|
50 #include "oops/symbol.hpp"
|
kbarrett@46560
|
51 #include "prims/jvm.h"
|
stefank@7397
|
52 #include "prims/jvmtiExport.hpp"
|
stefank@7397
|
53 #include "runtime/arguments.hpp"
|
stefank@7397
|
54 #include "runtime/biasedLocking.hpp"
|
stefank@7397
|
55 #include "runtime/compilationPolicy.hpp"
|
coleenp@34230
|
56 #include "runtime/deoptimization.hpp"
|
stefank@7397
|
57 #include "runtime/fprofiler.hpp"
|
stefank@7397
|
58 #include "runtime/init.hpp"
|
stefank@7397
|
59 #include "runtime/interfaceSupport.hpp"
|
stefank@7397
|
60 #include "runtime/java.hpp"
|
stefank@7397
|
61 #include "runtime/memprofiler.hpp"
|
stefank@7397
|
62 #include "runtime/sharedRuntime.hpp"
|
stefank@7397
|
63 #include "runtime/statSampler.hpp"
|
anoll@22210
|
64 #include "runtime/sweeper.hpp"
|
stefank@7397
|
65 #include "runtime/task.hpp"
|
stefank@14583
|
66 #include "runtime/thread.inline.hpp"
|
stefank@7397
|
67 #include "runtime/timer.hpp"
|
stefank@7397
|
68 #include "runtime/vm_operations.hpp"
|
zgu@13861
|
69 #include "services/memTracker.hpp"
|
mgronlun@36384
|
70 #include "trace/traceMacros.hpp"
|
phh@11480
|
71 #include "trace/tracing.hpp"
|
stefank@7397
|
72 #include "utilities/dtrace.hpp"
|
stefank@7397
|
73 #include "utilities/globalDefinitions.hpp"
|
stefank@7397
|
74 #include "utilities/histogram.hpp"
|
jprovino@15482
|
75 #include "utilities/macros.hpp"
|
stefank@7397
|
76 #include "utilities/vmError.hpp"
|
jprovino@15482
|
77 #if INCLUDE_ALL_GCS
|
pliden@30764
|
78 #include "gc/cms/concurrentMarkSweepThread.hpp"
|
pliden@30764
|
79 #include "gc/parallel/psScavenge.hpp"
|
jprovino@15482
|
80 #endif // INCLUDE_ALL_GCS
|
stefank@7397
|
81 #ifdef COMPILER1
|
stefank@7397
|
82 #include "c1/c1_Compiler.hpp"
|
stefank@7397
|
83 #include "c1/c1_Runtime1.hpp"
|
stefank@7397
|
84 #endif
|
stefank@7397
|
85 #ifdef COMPILER2
|
stefank@7397
|
86 #include "code/compiledIC.hpp"
|
stefank@7397
|
87 #include "compiler/methodLiveness.hpp"
|
stefank@7397
|
88 #include "opto/compile.hpp"
|
stefank@7397
|
89 #include "opto/indexSet.hpp"
|
stefank@7397
|
90 #include "opto/runtime.hpp"
|
stefank@7397
|
91 #endif
|
duke@1
|
92
|
roland@23526
|
93 GrowableArray<Method*>* collected_profiled_methods;
|
duke@1
|
94
|
roland@23526
|
95 int compare_methods(Method** a, Method** b) {
|
roland@23526
|
96 // %%% there can be 32-bit overflow here
|
roland@23526
|
97 return ((*b)->invocation_count() + (*b)->compiled_invocation_count())
|
roland@23526
|
98 - ((*a)->invocation_count() + (*a)->compiled_invocation_count());
|
duke@1
|
99 }
|
duke@1
|
100
|
coleenp@13728
|
101 void collect_profiled_methods(Method* m) {
|
coleenp@13728
|
102 Thread* thread = Thread::current();
|
coleenp@13728
|
103 methodHandle mh(thread, m);
|
duke@1
|
104 if ((m->method_data() != NULL) &&
|
duke@1
|
105 (PrintMethodData || CompilerOracle::should_print(mh))) {
|
duke@1
|
106 collected_profiled_methods->push(m);
|
duke@1
|
107 }
|
duke@1
|
108 }
|
duke@1
|
109
|
roland@23526
|
110 void print_method_profiling_data() {
|
coleenp@24658
|
111 if (ProfileInterpreter COMPILER1_PRESENT(|| C1UpdateMethodData) &&
|
coleenp@24658
|
112 (PrintMethodData || CompilerOracle::should_print_methods())) {
|
roland@23526
|
113 ResourceMark rm;
|
roland@23526
|
114 HandleMark hm;
|
roland@23526
|
115 collected_profiled_methods = new GrowableArray<Method*>(1024);
|
coleenp@46380
|
116 SystemDictionary::methods_do(collect_profiled_methods);
|
roland@23526
|
117 collected_profiled_methods->sort(&compare_methods);
|
duke@1
|
118
|
roland@23526
|
119 int count = collected_profiled_methods->length();
|
roland@23526
|
120 int total_size = 0;
|
roland@23526
|
121 if (count > 0) {
|
roland@23526
|
122 for (int index = 0; index < count; index++) {
|
roland@23526
|
123 Method* m = collected_profiled_methods->at(index);
|
roland@23526
|
124 ttyLocker ttyl;
|
roland@23526
|
125 tty->print_cr("------------------------------------------------------------------------");
|
roland@23526
|
126 m->print_invocation_count();
|
roland@23526
|
127 tty->print_cr(" mdo size: %d bytes", m->method_data()->size_in_bytes());
|
roland@23526
|
128 tty->cr();
|
roland@23526
|
129 // Dump data on parameters if any
|
roland@23526
|
130 if (m->method_data() != NULL && m->method_data()->parameters_type_data() != NULL) {
|
roland@23526
|
131 tty->fill_to(2);
|
roland@23526
|
132 m->method_data()->parameters_type_data()->print_data_on(tty);
|
roland@23526
|
133 }
|
roland@23526
|
134 m->print_codes();
|
roland@23526
|
135 total_size += m->method_data()->size_in_bytes();
|
roland@23526
|
136 }
|
roland@23526
|
137 tty->print_cr("------------------------------------------------------------------------");
|
roland@23526
|
138 tty->print_cr("Total MDO size: %d bytes", total_size);
|
roland@23526
|
139 }
|
roland@23526
|
140 }
|
duke@1
|
141 }
|
duke@1
|
142
|
duke@1
|
143
|
roland@23526
|
144 #ifndef PRODUCT
|
roland@23526
|
145
|
roland@23526
|
146 // Statistics printing (method invocation histogram)
|
roland@23526
|
147
|
roland@23526
|
148 GrowableArray<Method*>* collected_invoked_methods;
|
roland@23526
|
149
|
roland@23526
|
150 void collect_invoked_methods(Method* m) {
|
roland@23526
|
151 if (m->invocation_count() + m->compiled_invocation_count() >= 1 ) {
|
roland@23526
|
152 collected_invoked_methods->push(m);
|
roland@23526
|
153 }
|
roland@23526
|
154 }
|
roland@23526
|
155
|
roland@23526
|
156
|
roland@23526
|
157
|
roland@23526
|
158
|
duke@1
|
159 void print_method_invocation_histogram() {
|
duke@1
|
160 ResourceMark rm;
|
duke@1
|
161 HandleMark hm;
|
coleenp@13728
|
162 collected_invoked_methods = new GrowableArray<Method*>(1024);
|
duke@1
|
163 SystemDictionary::methods_do(collect_invoked_methods);
|
duke@1
|
164 collected_invoked_methods->sort(&compare_methods);
|
duke@1
|
165 //
|
duke@1
|
166 tty->cr();
|
coleenp@46380
|
167 tty->print_cr("Histogram Over Method Invocation Counters (cutoff = " INTX_FORMAT "):", MethodHistogramCutoff);
|
duke@1
|
168 tty->cr();
|
duke@1
|
169 tty->print_cr("____Count_(I+C)____Method________________________Module_________________");
|
duke@1
|
170 unsigned total = 0, int_total = 0, comp_total = 0, static_total = 0, final_total = 0,
|
duke@1
|
171 synch_total = 0, nativ_total = 0, acces_total = 0;
|
duke@1
|
172 for (int index = 0; index < collected_invoked_methods->length(); index++) {
|
coleenp@13728
|
173 Method* m = collected_invoked_methods->at(index);
|
duke@1
|
174 int c = m->invocation_count() + m->compiled_invocation_count();
|
duke@1
|
175 if (c >= MethodHistogramCutoff) m->print_invocation_count();
|
duke@1
|
176 int_total += m->invocation_count();
|
duke@1
|
177 comp_total += m->compiled_invocation_count();
|
duke@1
|
178 if (m->is_final()) final_total += c;
|
duke@1
|
179 if (m->is_static()) static_total += c;
|
duke@1
|
180 if (m->is_synchronized()) synch_total += c;
|
duke@1
|
181 if (m->is_native()) nativ_total += c;
|
duke@1
|
182 if (m->is_accessor()) acces_total += c;
|
duke@1
|
183 }
|
duke@1
|
184 tty->cr();
|
duke@1
|
185 total = int_total + comp_total;
|
duke@1
|
186 tty->print_cr("Invocations summary:");
|
duke@1
|
187 tty->print_cr("\t%9d (%4.1f%%) interpreted", int_total, 100.0 * int_total / total);
|
duke@1
|
188 tty->print_cr("\t%9d (%4.1f%%) compiled", comp_total, 100.0 * comp_total / total);
|
duke@1
|
189 tty->print_cr("\t%9d (100%%) total", total);
|
duke@1
|
190 tty->print_cr("\t%9d (%4.1f%%) synchronized", synch_total, 100.0 * synch_total / total);
|
duke@1
|
191 tty->print_cr("\t%9d (%4.1f%%) final", final_total, 100.0 * final_total / total);
|
duke@1
|
192 tty->print_cr("\t%9d (%4.1f%%) static", static_total, 100.0 * static_total / total);
|
duke@1
|
193 tty->print_cr("\t%9d (%4.1f%%) native", nativ_total, 100.0 * nativ_total / total);
|
duke@1
|
194 tty->print_cr("\t%9d (%4.1f%%) accessor", acces_total, 100.0 * acces_total / total);
|
duke@1
|
195 tty->cr();
|
duke@1
|
196 SharedRuntime::print_call_statistics(comp_total);
|
duke@1
|
197 }
|
duke@1
|
198
|
duke@1
|
199 void print_bytecode_count() {
|
duke@1
|
200 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
|
duke@1
|
201 tty->print_cr("[BytecodeCounter::counter_value = %d]", BytecodeCounter::counter_value());
|
duke@1
|
202 }
|
duke@1
|
203 }
|
duke@1
|
204
|
duke@1
|
205 AllocStats alloc_stats;
|
duke@1
|
206
|
duke@1
|
207
|
duke@1
|
208
|
duke@1
|
209 // General statistics printing (profiling ...)
|
duke@1
|
210 void print_statistics() {
|
duke@1
|
211 #ifdef ASSERT
|
duke@1
|
212
|
duke@1
|
213 if (CountRuntimeCalls) {
|
duke@1
|
214 extern Histogram *RuntimeHistogram;
|
duke@1
|
215 RuntimeHistogram->print();
|
duke@1
|
216 }
|
duke@1
|
217
|
duke@1
|
218 if (CountJNICalls) {
|
duke@1
|
219 extern Histogram *JNIHistogram;
|
duke@1
|
220 JNIHistogram->print();
|
duke@1
|
221 }
|
duke@1
|
222
|
duke@1
|
223 if (CountJVMCalls) {
|
duke@1
|
224 extern Histogram *JVMHistogram;
|
duke@1
|
225 JVMHistogram->print();
|
duke@1
|
226 }
|
duke@1
|
227
|
duke@1
|
228 #endif
|
duke@1
|
229
|
duke@1
|
230 if (MemProfiling) {
|
duke@1
|
231 MemProfiler::disengage();
|
duke@1
|
232 }
|
duke@1
|
233
|
duke@1
|
234 if (CITime) {
|
duke@1
|
235 CompileBroker::print_times();
|
duke@1
|
236 }
|
duke@1
|
237
|
duke@1
|
238 #ifdef COMPILER1
|
duke@1
|
239 if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) {
|
duke@1
|
240 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics);
|
duke@1
|
241 Runtime1::print_statistics();
|
duke@1
|
242 Deoptimization::print_statistics();
|
never@10254
|
243 SharedRuntime::print_statistics();
|
duke@1
|
244 }
|
duke@1
|
245 #endif /* COMPILER1 */
|
duke@1
|
246
|
duke@1
|
247 #ifdef COMPILER2
|
duke@1
|
248 if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) {
|
duke@1
|
249 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics);
|
duke@1
|
250 Compile::print_statistics();
|
duke@1
|
251 #ifndef COMPILER1
|
duke@1
|
252 Deoptimization::print_statistics();
|
never@10254
|
253 SharedRuntime::print_statistics();
|
duke@1
|
254 #endif //COMPILER1
|
duke@1
|
255 os::print_statistics();
|
duke@1
|
256 }
|
duke@1
|
257
|
kvn@23491
|
258 if (PrintLockStatistics || PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) {
|
duke@1
|
259 OptoRuntime::print_named_counters();
|
duke@1
|
260 }
|
duke@1
|
261
|
duke@1
|
262 if (TimeLivenessAnalysis) {
|
duke@1
|
263 MethodLiveness::print_times();
|
duke@1
|
264 }
|
duke@1
|
265 #ifdef ASSERT
|
duke@1
|
266 if (CollectIndexSetStatistics) {
|
duke@1
|
267 IndexSet::print_statistics();
|
duke@1
|
268 }
|
duke@1
|
269 #endif // ASSERT
|
twisti@33160
|
270 #else
|
twisti@33160
|
271 #ifdef INCLUDE_JVMCI
|
twisti@33160
|
272 #ifndef COMPILER1
|
twisti@33160
|
273 if ((TraceDeoptimization || LogVMOutput || LogCompilation) && UseCompiler) {
|
twisti@33160
|
274 FlagSetting fs(DisplayVMOutput, DisplayVMOutput && TraceDeoptimization);
|
twisti@33160
|
275 Deoptimization::print_statistics();
|
twisti@33160
|
276 SharedRuntime::print_statistics();
|
twisti@33160
|
277 }
|
twisti@33160
|
278 #endif
|
twisti@33160
|
279 #endif
|
twisti@33160
|
280 #endif
|
twisti@33160
|
281
|
kvn@42650
|
282 if (PrintAOTStatistics) {
|
kvn@42650
|
283 AOTLoader::print_statistics();
|
kvn@42650
|
284 }
|
kvn@42650
|
285
|
twisti@33160
|
286 if (PrintNMethodStatistics) {
|
twisti@33160
|
287 nmethod::print_statistics();
|
twisti@33160
|
288 }
|
duke@1
|
289 if (CountCompiledCalls) {
|
duke@1
|
290 print_method_invocation_histogram();
|
duke@1
|
291 }
|
roland@23526
|
292
|
roland@23526
|
293 print_method_profiling_data();
|
roland@23526
|
294
|
duke@1
|
295 if (TimeCompilationPolicy) {
|
duke@1
|
296 CompilationPolicy::policy()->print_time();
|
duke@1
|
297 }
|
duke@1
|
298 if (TimeOopMap) {
|
duke@1
|
299 GenerateOopMap::print_time();
|
duke@1
|
300 }
|
duke@1
|
301 if (ProfilerCheckIntervals) {
|
duke@1
|
302 PeriodicTask::print_intervals();
|
duke@1
|
303 }
|
duke@1
|
304 if (PrintSymbolTableSizeHistogram) {
|
duke@1
|
305 SymbolTable::print_histogram();
|
duke@1
|
306 }
|
duke@1
|
307 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
|
duke@1
|
308 BytecodeCounter::print();
|
duke@1
|
309 }
|
duke@1
|
310 if (PrintBytecodePairHistogram) {
|
duke@1
|
311 BytecodePairHistogram::print();
|
duke@1
|
312 }
|
duke@1
|
313
|
duke@1
|
314 if (PrintCodeCache) {
|
duke@1
|
315 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
|
duke@1
|
316 CodeCache::print();
|
duke@1
|
317 }
|
duke@1
|
318
|
anoll@22210
|
319 if (PrintMethodFlushingStatistics) {
|
anoll@22210
|
320 NMethodSweeper::print();
|
anoll@22210
|
321 }
|
anoll@22210
|
322
|
duke@1
|
323 if (PrintCodeCache2) {
|
duke@1
|
324 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
|
duke@1
|
325 CodeCache::print_internals();
|
duke@1
|
326 }
|
duke@1
|
327
|
duke@1
|
328 if (PrintVtableStats) {
|
duke@1
|
329 klassVtable::print_statistics();
|
duke@1
|
330 klassItable::print_statistics();
|
duke@1
|
331 }
|
duke@1
|
332 if (VerifyOops) {
|
duke@1
|
333 tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count());
|
duke@1
|
334 }
|
duke@1
|
335
|
duke@1
|
336 print_bytecode_count();
|
kvn@8320
|
337 if (PrintMallocStatistics) {
|
duke@1
|
338 tty->print("allocation stats: ");
|
duke@1
|
339 alloc_stats.print();
|
duke@1
|
340 tty->cr();
|
duke@1
|
341 }
|
duke@1
|
342
|
duke@1
|
343 if (PrintSystemDictionaryAtExit) {
|
duke@1
|
344 SystemDictionary::print();
|
duke@1
|
345 }
|
duke@1
|
346
|
minqi@31790
|
347 if (LogTouchedMethods && PrintTouchedMethodsAtExit) {
|
minqi@31790
|
348 Method::print_touched_methods(tty);
|
minqi@31790
|
349 }
|
minqi@31790
|
350
|
duke@1
|
351 if (PrintBiasedLockingStatistics) {
|
duke@1
|
352 BiasedLocking::print_counters();
|
duke@1
|
353 }
|
duke@1
|
354
|
zgu@13861
|
355 // Native memory tracking data
|
zgu@13861
|
356 if (PrintNMTStatistics) {
|
zgu@25946
|
357 MemTracker::final_report(tty);
|
zgu@13861
|
358 }
|
duke@1
|
359 }
|
duke@1
|
360
|
duke@1
|
361 #else // PRODUCT MODE STATISTICS
|
duke@1
|
362
|
duke@1
|
363 void print_statistics() {
|
duke@1
|
364
|
roland@23526
|
365 if (PrintMethodData) {
|
roland@23526
|
366 print_method_profiling_data();
|
roland@23526
|
367 }
|
roland@23526
|
368
|
duke@1
|
369 if (CITime) {
|
duke@1
|
370 CompileBroker::print_times();
|
duke@1
|
371 }
|
vladidan@15201
|
372
|
vladidan@15201
|
373 if (PrintCodeCache) {
|
vladidan@15201
|
374 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
|
vladidan@15201
|
375 CodeCache::print();
|
vladidan@15201
|
376 }
|
vladidan@15201
|
377
|
anoll@22210
|
378 if (PrintMethodFlushingStatistics) {
|
anoll@22210
|
379 NMethodSweeper::print();
|
anoll@22210
|
380 }
|
anoll@22210
|
381
|
duke@1
|
382 #ifdef COMPILER2
|
kvn@23491
|
383 if (PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) {
|
duke@1
|
384 OptoRuntime::print_named_counters();
|
duke@1
|
385 }
|
duke@1
|
386 #endif
|
duke@1
|
387 if (PrintBiasedLockingStatistics) {
|
duke@1
|
388 BiasedLocking::print_counters();
|
duke@1
|
389 }
|
zgu@13861
|
390
|
zgu@13861
|
391 // Native memory tracking data
|
zgu@13861
|
392 if (PrintNMTStatistics) {
|
zgu@25946
|
393 MemTracker::final_report(tty);
|
zgu@13861
|
394 }
|
minqi@31790
|
395
|
minqi@31790
|
396 if (LogTouchedMethods && PrintTouchedMethodsAtExit) {
|
minqi@31790
|
397 Method::print_touched_methods(tty);
|
minqi@31790
|
398 }
|
duke@1
|
399 }
|
duke@1
|
400
|
duke@1
|
401 #endif
|
duke@1
|
402
|
duke@1
|
403 // Note: before_exit() can be executed only once, if more than one threads
|
duke@1
|
404 // are trying to shutdown the VM at the same time, only one thread
|
duke@1
|
405 // can run before_exit() and all other threads must wait.
|
twisti@35143
|
406 void before_exit(JavaThread* thread) {
|
duke@1
|
407 #define BEFORE_EXIT_NOT_RUN 0
|
duke@1
|
408 #define BEFORE_EXIT_RUNNING 1
|
duke@1
|
409 #define BEFORE_EXIT_DONE 2
|
duke@1
|
410 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
|
duke@1
|
411
|
duke@1
|
412 // Note: don't use a Mutex to guard the entire before_exit(), as
|
duke@1
|
413 // JVMTI post_thread_end_event and post_vm_death_event will run native code.
|
duke@1
|
414 // A CAS or OSMutex would work just fine but then we need to manipulate
|
duke@1
|
415 // thread state for Safepoint. Here we use Monitor wait() and notify_all()
|
duke@1
|
416 // for synchronization.
|
duke@1
|
417 { MutexLocker ml(BeforeExit_lock);
|
duke@1
|
418 switch (_before_exit_status) {
|
duke@1
|
419 case BEFORE_EXIT_NOT_RUN:
|
duke@1
|
420 _before_exit_status = BEFORE_EXIT_RUNNING;
|
duke@1
|
421 break;
|
duke@1
|
422 case BEFORE_EXIT_RUNNING:
|
duke@1
|
423 while (_before_exit_status == BEFORE_EXIT_RUNNING) {
|
duke@1
|
424 BeforeExit_lock->wait();
|
duke@1
|
425 }
|
duke@1
|
426 assert(_before_exit_status == BEFORE_EXIT_DONE, "invalid state");
|
duke@1
|
427 return;
|
duke@1
|
428 case BEFORE_EXIT_DONE:
|
dholmes@35914
|
429 // need block to avoid SS compiler bug
|
dholmes@35914
|
430 {
|
dholmes@35914
|
431 return;
|
dholmes@35914
|
432 }
|
duke@1
|
433 }
|
duke@1
|
434 }
|
duke@1
|
435
|
twisti@33160
|
436 #if INCLUDE_JVMCI
|
twisti@35143
|
437 // We are not using CATCH here because we want the exit to continue normally.
|
twisti@35143
|
438 Thread* THREAD = thread;
|
twisti@35143
|
439 JVMCIRuntime::shutdown(THREAD);
|
twisti@35143
|
440 if (HAS_PENDING_EXCEPTION) {
|
kvn@46553
|
441 HandleMark hm(THREAD);
|
twisti@35143
|
442 Handle exception(THREAD, PENDING_EXCEPTION);
|
twisti@35143
|
443 CLEAR_PENDING_EXCEPTION;
|
twisti@35557
|
444 java_lang_Throwable::java_printStackTrace(exception, THREAD);
|
twisti@35143
|
445 }
|
twisti@33160
|
446 #endif
|
twisti@33160
|
447
|
duke@1
|
448 // Hang forever on exit if we're reporting an error.
|
coleenp@46589
|
449 if (ShowMessageBoxOnError && VMError::is_error_reported()) {
|
duke@1
|
450 os::infinite_sleep();
|
duke@1
|
451 }
|
duke@1
|
452
|
mgronlun@39274
|
453 EventThreadEnd event;
|
mgronlun@39274
|
454 if (event.should_commit()) {
|
mgronlun@39274
|
455 event.set_thread(THREAD_TRACE_ID(thread));
|
mgronlun@39274
|
456 event.commit();
|
mgronlun@39274
|
457 }
|
mgronlun@39274
|
458
|
mgronlun@39274
|
459 TRACE_VM_EXIT();
|
mgronlun@39274
|
460
|
dcubed@29321
|
461 // Stop the WatcherThread. We do this before disenrolling various
|
dcubed@29321
|
462 // PeriodicTasks to reduce the likelihood of races.
|
dcubed@29321
|
463 if (PeriodicTask::num_tasks() > 0) {
|
bobv@6176
|
464 WatcherThread::stop();
|
dcubed@29321
|
465 }
|
duke@1
|
466
|
duke@1
|
467 // Print statistics gathered (profiling ...)
|
duke@1
|
468 if (Arguments::has_profile()) {
|
duke@1
|
469 FlatProfiler::disengage();
|
duke@1
|
470 FlatProfiler::print(10);
|
duke@1
|
471 }
|
duke@1
|
472
|
duke@1
|
473 // shut down the StatSampler task
|
duke@1
|
474 StatSampler::disengage();
|
duke@1
|
475 StatSampler::destroy();
|
duke@1
|
476
|
pliden@25070
|
477 // Stop concurrent GC threads
|
pliden@25070
|
478 Universe::heap()->stop();
|
duke@1
|
479
|
duke@1
|
480 // Print GC/heap related information.
|
stefank@37242
|
481 Log(gc, heap, exit) log;
|
brutisso@35061
|
482 if (log.is_info()) {
|
brutisso@35061
|
483 ResourceMark rm;
|
brutisso@35061
|
484 Universe::print_on(log.info_stream());
|
brutisso@35061
|
485 if (log.is_trace()) {
|
brutisso@35061
|
486 ClassLoaderDataGraph::dump_on(log.trace_stream());
|
coleenp@13728
|
487 }
|
duke@1
|
488 }
|
brutisso@35061
|
489 AdaptiveSizePolicyOutput::print();
|
duke@1
|
490
|
duke@1
|
491 if (PrintBytecodeHistogram) {
|
duke@1
|
492 BytecodeHistogram::print();
|
duke@1
|
493 }
|
duke@1
|
494
|
duke@1
|
495 if (JvmtiExport::should_post_thread_life()) {
|
duke@1
|
496 JvmtiExport::post_thread_end(thread);
|
duke@1
|
497 }
|
phh@11480
|
498
|
duke@1
|
499 // Always call even when there are not JVMTI environments yet, since environments
|
duke@1
|
500 // may be attached late and JVMTI must track phases of VM execution
|
duke@1
|
501 JvmtiExport::post_vm_death();
|
duke@1
|
502 Threads::shutdown_vm_agents();
|
duke@1
|
503
|
duke@1
|
504 // Terminate the signal thread
|
duke@1
|
505 // Note: we don't wait until it actually dies.
|
duke@1
|
506 os::terminate_signal_thread();
|
duke@1
|
507
|
duke@1
|
508 print_statistics();
|
duke@1
|
509 Universe::heap()->print_tracing_info();
|
duke@1
|
510
|
duke@1
|
511 { MutexLocker ml(BeforeExit_lock);
|
duke@1
|
512 _before_exit_status = BEFORE_EXIT_DONE;
|
duke@1
|
513 BeforeExit_lock->notify_all();
|
duke@1
|
514 }
|
duke@1
|
515
|
dcubed@20053
|
516 if (VerifyStringTableAtExit) {
|
dcubed@20053
|
517 int fail_cnt = 0;
|
dcubed@20053
|
518 {
|
dcubed@20053
|
519 MutexLocker ml(StringTable_lock);
|
dcubed@20053
|
520 fail_cnt = StringTable::verify_and_compare_entries();
|
dcubed@20053
|
521 }
|
dcubed@20053
|
522
|
dcubed@20053
|
523 if (fail_cnt != 0) {
|
dcubed@20053
|
524 tty->print_cr("ERROR: fail_cnt=%d", fail_cnt);
|
dcubed@20053
|
525 guarantee(fail_cnt == 0, "unexpected StringTable verification failures");
|
dcubed@20053
|
526 }
|
dcubed@20053
|
527 }
|
dcubed@20053
|
528
|
duke@1
|
529 #undef BEFORE_EXIT_NOT_RUN
|
duke@1
|
530 #undef BEFORE_EXIT_RUNNING
|
duke@1
|
531 #undef BEFORE_EXIT_DONE
|
duke@1
|
532 }
|
duke@1
|
533
|
duke@1
|
534 void vm_exit(int code) {
|
dholmes@34633
|
535 Thread* thread =
|
dholmes@34633
|
536 ThreadLocalStorage::is_initialized() ? Thread::current_or_null() : NULL;
|
duke@1
|
537 if (thread == NULL) {
|
dholmes@34633
|
538 // very early initialization failure -- just exit
|
duke@1
|
539 vm_direct_exit(code);
|
duke@1
|
540 }
|
duke@1
|
541
|
duke@1
|
542 if (VMThread::vm_thread() != NULL) {
|
duke@1
|
543 // Fire off a VM_Exit operation to bring VM to a safepoint and exit
|
duke@1
|
544 VM_Exit op(code);
|
duke@1
|
545 if (thread->is_Java_thread())
|
duke@1
|
546 ((JavaThread*)thread)->set_thread_state(_thread_in_vm);
|
duke@1
|
547 VMThread::execute(&op);
|
duke@1
|
548 // should never reach here; but in case something wrong with VM Thread.
|
duke@1
|
549 vm_direct_exit(code);
|
duke@1
|
550 } else {
|
duke@1
|
551 // VM thread is gone, just exit
|
duke@1
|
552 vm_direct_exit(code);
|
duke@1
|
553 }
|
duke@1
|
554 ShouldNotReachHere();
|
duke@1
|
555 }
|
duke@1
|
556
|
duke@1
|
557 void notify_vm_shutdown() {
|
duke@1
|
558 // For now, just a dtrace probe.
|
dcubed@10739
|
559 HOTSPOT_VM_SHUTDOWN();
|
sla@22520
|
560 HS_DTRACE_WORKAROUND_TAIL_CALL_BUG();
|
duke@1
|
561 }
|
duke@1
|
562
|
duke@1
|
563 void vm_direct_exit(int code) {
|
duke@1
|
564 notify_vm_shutdown();
|
sla@8476
|
565 os::wait_for_keypress_at_exit();
|
igerasim@26682
|
566 os::exit(code);
|
duke@1
|
567 }
|
duke@1
|
568
|
duke@1
|
569 void vm_perform_shutdown_actions() {
|
duke@1
|
570 // Warning: do not call 'exit_globals()' here. All threads are still running.
|
duke@1
|
571 // Calling 'exit_globals()' will disable thread-local-storage and cause all
|
duke@1
|
572 // kinds of assertions to trigger in debug mode.
|
duke@1
|
573 if (is_init_completed()) {
|
dholmes@34633
|
574 Thread* thread = Thread::current_or_null();
|
coleenp@7720
|
575 if (thread != NULL && thread->is_Java_thread()) {
|
duke@1
|
576 // We are leaving the VM, set state to native (in case any OS exit
|
duke@1
|
577 // handlers call back to the VM)
|
duke@1
|
578 JavaThread* jt = (JavaThread*)thread;
|
duke@1
|
579 // Must always be walkable or have no last_Java_frame when in
|
duke@1
|
580 // thread_in_native
|
duke@1
|
581 jt->frame_anchor()->make_walkable(jt);
|
duke@1
|
582 jt->set_thread_state(_thread_in_native);
|
duke@1
|
583 }
|
duke@1
|
584 }
|
duke@1
|
585 notify_vm_shutdown();
|
duke@1
|
586 }
|
duke@1
|
587
|
duke@1
|
588 void vm_shutdown()
|
duke@1
|
589 {
|
duke@1
|
590 vm_perform_shutdown_actions();
|
sla@8476
|
591 os::wait_for_keypress_at_exit();
|
duke@1
|
592 os::shutdown();
|
duke@1
|
593 }
|
duke@1
|
594
|
poonam@773
|
595 void vm_abort(bool dump_core) {
|
duke@1
|
596 vm_perform_shutdown_actions();
|
sla@8476
|
597 os::wait_for_keypress_at_exit();
|
sangheki@33600
|
598
|
sangheki@33600
|
599 // Flush stdout and stderr before abort.
|
sangheki@33600
|
600 fflush(stdout);
|
sangheki@33600
|
601 fflush(stderr);
|
sangheki@33600
|
602
|
poonam@773
|
603 os::abort(dump_core);
|
duke@1
|
604 ShouldNotReachHere();
|
duke@1
|
605 }
|
duke@1
|
606
|
duke@1
|
607 void vm_notify_during_shutdown(const char* error, const char* message) {
|
duke@1
|
608 if (error != NULL) {
|
duke@1
|
609 tty->print_cr("Error occurred during initialization of VM");
|
duke@1
|
610 tty->print("%s", error);
|
duke@1
|
611 if (message != NULL) {
|
duke@1
|
612 tty->print_cr(": %s", message);
|
duke@1
|
613 }
|
duke@1
|
614 else {
|
duke@1
|
615 tty->cr();
|
duke@1
|
616 }
|
duke@1
|
617 }
|
duke@1
|
618 if (ShowMessageBoxOnError && WizardMode) {
|
duke@1
|
619 fatal("Error occurred during initialization of VM");
|
duke@1
|
620 }
|
duke@1
|
621 }
|
duke@1
|
622
|
alanb@44326
|
623 void vm_exit_during_initialization() {
|
alanb@44326
|
624 vm_notify_during_shutdown(NULL, NULL);
|
alanb@44326
|
625
|
alanb@44326
|
626 // Failure during initialization, we don't want to dump core
|
alanb@44326
|
627 vm_abort(false);
|
alanb@44326
|
628 }
|
alanb@44326
|
629
|
duke@1
|
630 void vm_exit_during_initialization(Handle exception) {
|
duke@1
|
631 tty->print_cr("Error occurred during initialization of VM");
|
duke@1
|
632 // If there are exceptions on this thread it must be cleared
|
duke@1
|
633 // first and here. Any future calls to EXCEPTION_MARK requires
|
duke@1
|
634 // that no pending exceptions exist.
|
dholmes@34633
|
635 Thread *THREAD = Thread::current(); // can't be NULL
|
duke@1
|
636 if (HAS_PENDING_EXCEPTION) {
|
duke@1
|
637 CLEAR_PENDING_EXCEPTION;
|
duke@1
|
638 }
|
twisti@35143
|
639 java_lang_Throwable::print_stack_trace(exception, tty);
|
duke@1
|
640 tty->cr();
|
duke@1
|
641 vm_notify_during_shutdown(NULL, NULL);
|
poonam@773
|
642
|
poonam@773
|
643 // Failure during initialization, we don't want to dump core
|
poonam@773
|
644 vm_abort(false);
|
duke@1
|
645 }
|
duke@1
|
646
|
coleenp@8076
|
647 void vm_exit_during_initialization(Symbol* ex, const char* message) {
|
duke@1
|
648 ResourceMark rm;
|
duke@1
|
649 vm_notify_during_shutdown(ex->as_C_string(), message);
|
poonam@773
|
650
|
poonam@773
|
651 // Failure during initialization, we don't want to dump core
|
poonam@773
|
652 vm_abort(false);
|
duke@1
|
653 }
|
duke@1
|
654
|
duke@1
|
655 void vm_exit_during_initialization(const char* error, const char* message) {
|
duke@1
|
656 vm_notify_during_shutdown(error, message);
|
poonam@773
|
657
|
poonam@773
|
658 // Failure during initialization, we don't want to dump core
|
poonam@773
|
659 vm_abort(false);
|
duke@1
|
660 }
|
duke@1
|
661
|
duke@1
|
662 void vm_shutdown_during_initialization(const char* error, const char* message) {
|
duke@1
|
663 vm_notify_during_shutdown(error, message);
|
duke@1
|
664 vm_shutdown();
|
duke@1
|
665 }
|
duke@1
|
666
|
kamg@950
|
667 JDK_Version JDK_Version::_current;
|
twisti@13106
|
668 const char* JDK_Version::_runtime_name;
|
sla@14289
|
669 const char* JDK_Version::_runtime_version;
|
duke@1
|
670
|
duke@1
|
671 void JDK_Version::initialize() {
|
kamg@950
|
672 jdk_version_info info;
|
kamg@950
|
673 assert(!_current.is_valid(), "Don't initialize twice");
|
kamg@950
|
674
|
duke@1
|
675 void *lib_handle = os::native_java_library();
|
kamg@950
|
676 jdk_version_info_fn_t func = CAST_TO_FN_PTR(jdk_version_info_fn_t,
|
kamg@950
|
677 os::dll_lookup(lib_handle, "JDK_GetVersionInfo0"));
|
duke@1
|
678
|
amurillo@33959
|
679 assert(func != NULL, "Support for JDK 1.5 or older has been removed after JEP-223");
|
kamg@950
|
680
|
amurillo@33959
|
681 (*func)(&info, sizeof(info));
|
ihse@33957
|
682
|
amurillo@33959
|
683 int major = JDK_VERSION_MAJOR(info.jdk_version);
|
amurillo@33959
|
684 int minor = JDK_VERSION_MINOR(info.jdk_version);
|
amurillo@33959
|
685 int security = JDK_VERSION_SECURITY(info.jdk_version);
|
amurillo@33959
|
686 int build = JDK_VERSION_BUILD(info.jdk_version);
|
amurillo@33959
|
687
|
amurillo@33959
|
688 // Incompatible with pre-4243978 JDK.
|
amurillo@33959
|
689 if (info.pending_list_uses_discovered_field == 0) {
|
amurillo@33959
|
690 vm_exit_during_initialization(
|
amurillo@33959
|
691 "Incompatible JDK is not using Reference.discovered field for pending list");
|
duke@1
|
692 }
|
amurillo@33959
|
693 _current = JDK_Version(major, minor, security, info.patch_version, build,
|
amurillo@33959
|
694 info.thread_park_blocker == 1,
|
amurillo@33959
|
695 info.post_vm_init_hook_enabled == 1);
|
duke@1
|
696 }
|
duke@1
|
697
|
duke@1
|
698 void JDK_Version_init() {
|
duke@1
|
699 JDK_Version::initialize();
|
duke@1
|
700 }
|
kamg@950
|
701
|
kamg@950
|
702 static int64_t encode_jdk_version(const JDK_Version& v) {
|
kamg@950
|
703 return
|
amurillo@33959
|
704 ((int64_t)v.major_version() << (BitsPerByte * 4)) |
|
amurillo@33959
|
705 ((int64_t)v.minor_version() << (BitsPerByte * 3)) |
|
amurillo@33959
|
706 ((int64_t)v.security_version() << (BitsPerByte * 2)) |
|
amurillo@33959
|
707 ((int64_t)v.patch_version() << (BitsPerByte * 1)) |
|
kamg@950
|
708 ((int64_t)v.build_number() << (BitsPerByte * 0));
|
kamg@950
|
709 }
|
kamg@950
|
710
|
kamg@950
|
711 int JDK_Version::compare(const JDK_Version& other) const {
|
kamg@950
|
712 assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)");
|
amurillo@33959
|
713 uint64_t e = encode_jdk_version(*this);
|
amurillo@33959
|
714 uint64_t o = encode_jdk_version(other);
|
amurillo@33959
|
715 return (e > o) ? 1 : ((e == o) ? 0 : -1);
|
kamg@950
|
716 }
|
kamg@950
|
717
|
kamg@950
|
718 void JDK_Version::to_string(char* buffer, size_t buflen) const {
|
goetz@27471
|
719 assert(buffer && buflen > 0, "call with useful buffer");
|
kamg@950
|
720 size_t index = 0;
|
goetz@27471
|
721
|
kamg@950
|
722 if (!is_valid()) {
|
kamg@950
|
723 jio_snprintf(buffer, buflen, "%s", "(uninitialized)");
|
kamg@950
|
724 } else {
|
goetz@27471
|
725 int rc = jio_snprintf(
|
kamg@950
|
726 &buffer[index], buflen - index, "%d.%d", _major, _minor);
|
goetz@27471
|
727 if (rc == -1) return;
|
goetz@27471
|
728 index += rc;
|
ihse@33957
|
729 if (_security > 0) {
|
ihse@33957
|
730 rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _security);
|
shshahma@46293
|
731 if (rc == -1) return;
|
shshahma@46293
|
732 index += rc;
|
kamg@950
|
733 }
|
amurillo@33959
|
734 if (_patch > 0) {
|
amurillo@33959
|
735 rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _patch);
|
goetz@27471
|
736 if (rc == -1) return;
|
goetz@27471
|
737 index += rc;
|
kamg@950
|
738 }
|
kamg@950
|
739 if (_build > 0) {
|
amurillo@33959
|
740 rc = jio_snprintf(&buffer[index], buflen - index, "+%d", _build);
|
goetz@27471
|
741 if (rc == -1) return;
|
goetz@27471
|
742 index += rc;
|
kamg@950
|
743 }
|
kamg@950
|
744 }
|
kamg@950
|
745 }
|