Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/runtime/java.cpp
32285 views
1
/*
2
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#include "precompiled.hpp"
26
#include "classfile/classLoader.hpp"
27
#include "classfile/symbolTable.hpp"
28
#include "classfile/systemDictionary.hpp"
29
#include "code/codeCache.hpp"
30
#include "compiler/compileBroker.hpp"
31
#include "compiler/compilerOracle.hpp"
32
#include "interpreter/bytecodeHistogram.hpp"
33
#include "jfr/jfrEvents.hpp"
34
#include "jfr/support/jfrThreadId.hpp"
35
#include "memory/genCollectedHeap.hpp"
36
#include "memory/oopFactory.hpp"
37
#include "memory/universe.hpp"
38
#include "oops/constantPool.hpp"
39
#include "oops/generateOopMap.hpp"
40
#include "oops/instanceKlass.hpp"
41
#include "oops/instanceOop.hpp"
42
#include "oops/method.hpp"
43
#include "oops/objArrayOop.hpp"
44
#include "oops/oop.inline.hpp"
45
#include "oops/symbol.hpp"
46
#include "prims/jvmtiExport.hpp"
47
#include "runtime/arguments.hpp"
48
#include "runtime/biasedLocking.hpp"
49
#include "runtime/compilationPolicy.hpp"
50
#include "runtime/deoptimization.hpp"
51
#include "runtime/fprofiler.hpp"
52
#include "runtime/init.hpp"
53
#include "runtime/interfaceSupport.hpp"
54
#include "runtime/java.hpp"
55
#include "runtime/memprofiler.hpp"
56
#include "runtime/sharedRuntime.hpp"
57
#include "runtime/statSampler.hpp"
58
#include "runtime/sweeper.hpp"
59
#include "runtime/task.hpp"
60
#include "runtime/thread.inline.hpp"
61
#include "runtime/timer.hpp"
62
#include "runtime/vm_operations.hpp"
63
#include "services/memTracker.hpp"
64
#include "utilities/dtrace.hpp"
65
#include "utilities/globalDefinitions.hpp"
66
#include "utilities/histogram.hpp"
67
#include "utilities/macros.hpp"
68
#include "utilities/vmError.hpp"
69
#ifdef TARGET_ARCH_x86
70
# include "vm_version_x86.hpp"
71
#endif
72
#ifdef TARGET_ARCH_aarch32
73
# include "vm_version_aarch32.hpp"
74
#endif
75
#ifdef TARGET_ARCH_aarch64
76
# include "vm_version_aarch64.hpp"
77
#endif
78
#ifdef TARGET_ARCH_sparc
79
# include "vm_version_sparc.hpp"
80
#endif
81
#ifdef TARGET_ARCH_zero
82
# include "vm_version_zero.hpp"
83
#endif
84
#ifdef TARGET_ARCH_arm
85
# include "vm_version_arm.hpp"
86
#endif
87
#ifdef TARGET_ARCH_ppc
88
# include "vm_version_ppc.hpp"
89
#endif
90
#if INCLUDE_ALL_GCS
91
#include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"
92
#include "gc_implementation/parallelScavenge/psScavenge.hpp"
93
#include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"
94
#endif // INCLUDE_ALL_GCS
95
#ifdef COMPILER1
96
#include "c1/c1_Compiler.hpp"
97
#include "c1/c1_Runtime1.hpp"
98
#endif
99
#ifdef COMPILER2
100
#include "code/compiledIC.hpp"
101
#include "compiler/methodLiveness.hpp"
102
#include "opto/compile.hpp"
103
#include "opto/indexSet.hpp"
104
#include "opto/runtime.hpp"
105
#endif
106
#if INCLUDE_JFR
107
#include "jfr/jfr.hpp"
108
#endif
109
110
#ifndef USDT2
111
HS_DTRACE_PROBE_DECL(hotspot, vm__shutdown);
112
#endif /* !USDT2 */
113
114
#ifndef PRODUCT
115
116
// Statistics printing (method invocation histogram)
117
118
GrowableArray<Method*>* collected_invoked_methods;
119
120
void collect_invoked_methods(Method* m) {
121
if (m->invocation_count() + m->compiled_invocation_count() >= 1 ) {
122
collected_invoked_methods->push(m);
123
}
124
}
125
126
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
127
128
GrowableArray<Method*>* collected_profiled_methods;
129
130
void collect_profiled_methods(Method* m) {
131
Thread* thread = Thread::current();
132
// This HandleMark prevents a huge amount of handles from being added
133
// to the metadata_handles() array on the thread.
134
HandleMark hm(thread);
135
methodHandle mh(thread, m);
136
if ((m->method_data() != NULL) &&
137
(PrintMethodData || CompilerOracle::should_print(mh))) {
138
collected_profiled_methods->push(m);
139
}
140
}
141
142
143
int compare_methods(Method** a, Method** b) {
144
// %%% there can be 32-bit overflow here
145
return ((*b)->invocation_count() + (*b)->compiled_invocation_count())
146
- ((*a)->invocation_count() + (*a)->compiled_invocation_count());
147
}
148
149
150
void print_method_invocation_histogram() {
151
ResourceMark rm;
152
HandleMark hm;
153
collected_invoked_methods = new GrowableArray<Method*>(1024);
154
SystemDictionary::methods_do(collect_invoked_methods);
155
collected_invoked_methods->sort(&compare_methods);
156
//
157
tty->cr();
158
tty->print_cr("Histogram Over MethodOop Invocation Counters (cutoff = %d):", MethodHistogramCutoff);
159
tty->cr();
160
tty->print_cr("____Count_(I+C)____Method________________________Module_________________");
161
unsigned total = 0, int_total = 0, comp_total = 0, static_total = 0, final_total = 0,
162
synch_total = 0, nativ_total = 0, acces_total = 0;
163
for (int index = 0; index < collected_invoked_methods->length(); index++) {
164
Method* m = collected_invoked_methods->at(index);
165
int c = m->invocation_count() + m->compiled_invocation_count();
166
if (c >= MethodHistogramCutoff) m->print_invocation_count();
167
int_total += m->invocation_count();
168
comp_total += m->compiled_invocation_count();
169
if (m->is_final()) final_total += c;
170
if (m->is_static()) static_total += c;
171
if (m->is_synchronized()) synch_total += c;
172
if (m->is_native()) nativ_total += c;
173
if (m->is_accessor()) acces_total += c;
174
}
175
tty->cr();
176
total = int_total + comp_total;
177
tty->print_cr("Invocations summary:");
178
tty->print_cr("\t%9d (%4.1f%%) interpreted", int_total, 100.0 * int_total / total);
179
tty->print_cr("\t%9d (%4.1f%%) compiled", comp_total, 100.0 * comp_total / total);
180
tty->print_cr("\t%9d (100%%) total", total);
181
tty->print_cr("\t%9d (%4.1f%%) synchronized", synch_total, 100.0 * synch_total / total);
182
tty->print_cr("\t%9d (%4.1f%%) final", final_total, 100.0 * final_total / total);
183
tty->print_cr("\t%9d (%4.1f%%) static", static_total, 100.0 * static_total / total);
184
tty->print_cr("\t%9d (%4.1f%%) native", nativ_total, 100.0 * nativ_total / total);
185
tty->print_cr("\t%9d (%4.1f%%) accessor", acces_total, 100.0 * acces_total / total);
186
tty->cr();
187
SharedRuntime::print_call_statistics(comp_total);
188
}
189
190
void print_method_profiling_data() {
191
ResourceMark rm;
192
HandleMark hm;
193
collected_profiled_methods = new GrowableArray<Method*>(1024);
194
SystemDictionary::methods_do(collect_profiled_methods);
195
collected_profiled_methods->sort(&compare_methods);
196
197
int count = collected_profiled_methods->length();
198
int total_size = 0;
199
if (count > 0) {
200
for (int index = 0; index < count; index++) {
201
Method* m = collected_profiled_methods->at(index);
202
ttyLocker ttyl;
203
tty->print_cr("------------------------------------------------------------------------");
204
//m->print_name(tty);
205
m->print_invocation_count();
206
tty->print_cr(" mdo size: %d bytes", m->method_data()->size_in_bytes());
207
tty->cr();
208
// Dump data on parameters if any
209
if (m->method_data() != NULL && m->method_data()->parameters_type_data() != NULL) {
210
tty->fill_to(2);
211
m->method_data()->parameters_type_data()->print_data_on(tty);
212
}
213
m->print_codes();
214
total_size += m->method_data()->size_in_bytes();
215
}
216
tty->print_cr("------------------------------------------------------------------------");
217
tty->print_cr("Total MDO size: %d bytes", total_size);
218
}
219
}
220
221
void print_bytecode_count() {
222
if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
223
tty->print_cr("[BytecodeCounter::counter_value = %d]", BytecodeCounter::counter_value());
224
}
225
}
226
227
AllocStats alloc_stats;
228
229
230
231
// General statistics printing (profiling ...)
232
void print_statistics() {
233
#ifdef ASSERT
234
235
if (CountRuntimeCalls) {
236
extern Histogram *RuntimeHistogram;
237
RuntimeHistogram->print();
238
}
239
240
if (CountJNICalls) {
241
extern Histogram *JNIHistogram;
242
JNIHistogram->print();
243
}
244
245
if (CountJVMCalls) {
246
extern Histogram *JVMHistogram;
247
JVMHistogram->print();
248
}
249
250
#endif
251
252
if (MemProfiling) {
253
MemProfiler::disengage();
254
}
255
256
if (CITime) {
257
CompileBroker::print_times();
258
}
259
260
#ifdef COMPILER1
261
if ((PrintC1Statistics || LogVMOutput || LogCompilation) && UseCompiler) {
262
FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintC1Statistics);
263
Runtime1::print_statistics();
264
Deoptimization::print_statistics();
265
SharedRuntime::print_statistics();
266
nmethod::print_statistics();
267
}
268
#endif /* COMPILER1 */
269
270
#ifdef COMPILER2
271
if ((PrintOptoStatistics || LogVMOutput || LogCompilation) && UseCompiler) {
272
FlagSetting fs(DisplayVMOutput, DisplayVMOutput && PrintOptoStatistics);
273
Compile::print_statistics();
274
#ifndef COMPILER1
275
Deoptimization::print_statistics();
276
nmethod::print_statistics();
277
SharedRuntime::print_statistics();
278
#endif //COMPILER1
279
os::print_statistics();
280
}
281
282
if (PrintLockStatistics || PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) {
283
OptoRuntime::print_named_counters();
284
}
285
286
if (TimeLivenessAnalysis) {
287
MethodLiveness::print_times();
288
}
289
#ifdef ASSERT
290
if (CollectIndexSetStatistics) {
291
IndexSet::print_statistics();
292
}
293
#endif // ASSERT
294
#endif // COMPILER2
295
if (CountCompiledCalls) {
296
print_method_invocation_histogram();
297
}
298
if (ProfileInterpreter COMPILER1_PRESENT(|| C1UpdateMethodData)) {
299
print_method_profiling_data();
300
}
301
if (TimeCompiler) {
302
COMPILER2_PRESENT(Compile::print_timers();)
303
}
304
if (TimeCompilationPolicy) {
305
CompilationPolicy::policy()->print_time();
306
}
307
if (TimeOopMap) {
308
GenerateOopMap::print_time();
309
}
310
if (ProfilerCheckIntervals) {
311
PeriodicTask::print_intervals();
312
}
313
if (PrintSymbolTableSizeHistogram) {
314
SymbolTable::print_histogram();
315
}
316
if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
317
BytecodeCounter::print();
318
}
319
if (PrintBytecodePairHistogram) {
320
BytecodePairHistogram::print();
321
}
322
323
if (PrintCodeCache) {
324
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
325
CodeCache::print();
326
}
327
328
if (PrintMethodFlushingStatistics) {
329
NMethodSweeper::print();
330
}
331
332
if (PrintCodeCache2) {
333
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
334
CodeCache::print_internals();
335
}
336
337
if (PrintClassStatistics) {
338
SystemDictionary::print_class_statistics();
339
}
340
if (PrintMethodStatistics) {
341
SystemDictionary::print_method_statistics();
342
}
343
344
if (PrintVtableStats) {
345
klassVtable::print_statistics();
346
klassItable::print_statistics();
347
}
348
if (VerifyOops && Verbose) {
349
tty->print_cr("+VerifyOops count: %d", StubRoutines::verify_oop_count());
350
}
351
352
print_bytecode_count();
353
if (PrintMallocStatistics) {
354
tty->print("allocation stats: ");
355
alloc_stats.print();
356
tty->cr();
357
}
358
359
if (PrintSystemDictionaryAtExit) {
360
SystemDictionary::print();
361
}
362
363
if (PrintBiasedLockingStatistics) {
364
BiasedLocking::print_counters();
365
}
366
367
#ifdef ENABLE_ZAP_DEAD_LOCALS
368
#ifdef COMPILER2
369
if (ZapDeadCompiledLocals) {
370
tty->print_cr("Compile::CompiledZap_count = %d", Compile::CompiledZap_count);
371
tty->print_cr("OptoRuntime::ZapDeadCompiledLocals_count = %d", OptoRuntime::ZapDeadCompiledLocals_count);
372
}
373
#endif // COMPILER2
374
#endif // ENABLE_ZAP_DEAD_LOCALS
375
// Native memory tracking data
376
if (PrintNMTStatistics) {
377
MemTracker::final_report(tty);
378
}
379
}
380
381
#else // PRODUCT MODE STATISTICS
382
383
void print_statistics() {
384
385
if (CITime) {
386
CompileBroker::print_times();
387
}
388
389
if (PrintCodeCache) {
390
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
391
CodeCache::print();
392
}
393
394
if (PrintMethodFlushingStatistics) {
395
NMethodSweeper::print();
396
}
397
398
#ifdef COMPILER2
399
if (PrintPreciseBiasedLockingStatistics || PrintPreciseRTMLockingStatistics) {
400
OptoRuntime::print_named_counters();
401
}
402
#endif
403
if (PrintBiasedLockingStatistics) {
404
BiasedLocking::print_counters();
405
}
406
407
// Native memory tracking data
408
if (PrintNMTStatistics) {
409
MemTracker::final_report(tty);
410
}
411
}
412
413
#endif
414
415
416
// Helper class for registering on_exit calls through JVM_OnExit
417
418
extern "C" {
419
typedef void (*__exit_proc)(void);
420
}
421
422
class ExitProc : public CHeapObj<mtInternal> {
423
private:
424
__exit_proc _proc;
425
// void (*_proc)(void);
426
ExitProc* _next;
427
public:
428
// ExitProc(void (*proc)(void)) {
429
ExitProc(__exit_proc proc) {
430
_proc = proc;
431
_next = NULL;
432
}
433
void evaluate() { _proc(); }
434
ExitProc* next() const { return _next; }
435
void set_next(ExitProc* next) { _next = next; }
436
};
437
438
439
// Linked list of registered on_exit procedures
440
441
static ExitProc* exit_procs = NULL;
442
443
444
extern "C" {
445
void register_on_exit_function(void (*func)(void)) {
446
ExitProc *entry = new ExitProc(func);
447
// Classic vm does not throw an exception in case the allocation failed,
448
if (entry != NULL) {
449
entry->set_next(exit_procs);
450
exit_procs = entry;
451
}
452
}
453
}
454
455
// Note: before_exit() can be executed only once, if more than one threads
456
// are trying to shutdown the VM at the same time, only one thread
457
// can run before_exit() and all other threads must wait.
458
void before_exit(JavaThread * thread) {
459
#define BEFORE_EXIT_NOT_RUN 0
460
#define BEFORE_EXIT_RUNNING 1
461
#define BEFORE_EXIT_DONE 2
462
static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
463
464
// Note: don't use a Mutex to guard the entire before_exit(), as
465
// JVMTI post_thread_end_event and post_vm_death_event will run native code.
466
// A CAS or OSMutex would work just fine but then we need to manipulate
467
// thread state for Safepoint. Here we use Monitor wait() and notify_all()
468
// for synchronization.
469
{ MutexLocker ml(BeforeExit_lock);
470
switch (_before_exit_status) {
471
case BEFORE_EXIT_NOT_RUN:
472
_before_exit_status = BEFORE_EXIT_RUNNING;
473
break;
474
case BEFORE_EXIT_RUNNING:
475
while (_before_exit_status == BEFORE_EXIT_RUNNING) {
476
BeforeExit_lock->wait();
477
}
478
assert(_before_exit_status == BEFORE_EXIT_DONE, "invalid state");
479
return;
480
case BEFORE_EXIT_DONE:
481
return;
482
}
483
}
484
485
// The only difference between this and Win32's _onexit procs is that
486
// this version is invoked before any threads get killed.
487
ExitProc* current = exit_procs;
488
while (current != NULL) {
489
ExitProc* next = current->next();
490
current->evaluate();
491
delete current;
492
current = next;
493
}
494
495
// Hang forever on exit if we're reporting an error.
496
if (ShowMessageBoxOnError && is_error_reported()) {
497
os::infinite_sleep();
498
}
499
500
// Terminate watcher thread - must before disenrolling any periodic task
501
if (PeriodicTask::num_tasks() > 0)
502
WatcherThread::stop();
503
504
// Print statistics gathered (profiling ...)
505
if (Arguments::has_profile()) {
506
FlatProfiler::disengage();
507
FlatProfiler::print(10);
508
}
509
510
// shut down the StatSampler task
511
StatSampler::disengage();
512
StatSampler::destroy();
513
514
// Stop concurrent GC threads
515
Universe::heap()->stop();
516
517
// Print GC/heap related information.
518
if (PrintGCDetails) {
519
Universe::print();
520
AdaptiveSizePolicyOutput(0);
521
if (Verbose) {
522
ClassLoaderDataGraph::dump_on(gclog_or_tty);
523
}
524
}
525
526
if (PrintBytecodeHistogram) {
527
BytecodeHistogram::print();
528
}
529
530
if (JvmtiExport::should_post_thread_life()) {
531
JvmtiExport::post_thread_end(thread);
532
}
533
534
535
EventThreadEnd event;
536
if (event.should_commit()) {
537
event.set_thread(JFR_THREAD_ID(thread));
538
event.commit();
539
}
540
541
JFR_ONLY(Jfr::on_vm_shutdown();)
542
543
// Always call even when there are not JVMTI environments yet, since environments
544
// may be attached late and JVMTI must track phases of VM execution
545
JvmtiExport::post_vm_death();
546
Threads::shutdown_vm_agents();
547
548
// Terminate the signal thread
549
// Note: we don't wait until it actually dies.
550
os::terminate_signal_thread();
551
552
print_statistics();
553
Universe::heap()->print_tracing_info();
554
555
{ MutexLocker ml(BeforeExit_lock);
556
_before_exit_status = BEFORE_EXIT_DONE;
557
BeforeExit_lock->notify_all();
558
}
559
560
if (VerifyStringTableAtExit) {
561
int fail_cnt = 0;
562
{
563
MutexLocker ml(StringTable_lock);
564
fail_cnt = StringTable::verify_and_compare_entries();
565
}
566
567
if (fail_cnt != 0) {
568
tty->print_cr("ERROR: fail_cnt=%d", fail_cnt);
569
guarantee(fail_cnt == 0, "unexpected StringTable verification failures");
570
}
571
}
572
573
#undef BEFORE_EXIT_NOT_RUN
574
#undef BEFORE_EXIT_RUNNING
575
#undef BEFORE_EXIT_DONE
576
}
577
578
void vm_exit(int code) {
579
Thread* thread = ThreadLocalStorage::is_initialized() ?
580
ThreadLocalStorage::get_thread_slow() : NULL;
581
if (thread == NULL) {
582
// we have serious problems -- just exit
583
vm_direct_exit(code);
584
}
585
586
if (VMThread::vm_thread() != NULL) {
587
// Fire off a VM_Exit operation to bring VM to a safepoint and exit
588
VM_Exit op(code);
589
if (thread->is_Java_thread())
590
((JavaThread*)thread)->set_thread_state(_thread_in_vm);
591
VMThread::execute(&op);
592
// should never reach here; but in case something wrong with VM Thread.
593
vm_direct_exit(code);
594
} else {
595
// VM thread is gone, just exit
596
vm_direct_exit(code);
597
}
598
ShouldNotReachHere();
599
}
600
601
void notify_vm_shutdown() {
602
// For now, just a dtrace probe.
603
#ifndef USDT2
604
HS_DTRACE_PROBE(hotspot, vm__shutdown);
605
HS_DTRACE_WORKAROUND_TAIL_CALL_BUG();
606
#else /* USDT2 */
607
HOTSPOT_VM_SHUTDOWN();
608
#endif /* USDT2 */
609
}
610
611
void vm_direct_exit(int code) {
612
notify_vm_shutdown();
613
os::wait_for_keypress_at_exit();
614
::exit(code);
615
}
616
617
void vm_perform_shutdown_actions() {
618
// Warning: do not call 'exit_globals()' here. All threads are still running.
619
// Calling 'exit_globals()' will disable thread-local-storage and cause all
620
// kinds of assertions to trigger in debug mode.
621
if (is_init_completed()) {
622
Thread* thread = ThreadLocalStorage::is_initialized() ?
623
ThreadLocalStorage::get_thread_slow() : NULL;
624
if (thread != NULL && thread->is_Java_thread()) {
625
// We are leaving the VM, set state to native (in case any OS exit
626
// handlers call back to the VM)
627
JavaThread* jt = (JavaThread*)thread;
628
// Must always be walkable or have no last_Java_frame when in
629
// thread_in_native
630
jt->frame_anchor()->make_walkable(jt);
631
jt->set_thread_state(_thread_in_native);
632
}
633
}
634
notify_vm_shutdown();
635
}
636
637
void vm_shutdown()
638
{
639
vm_perform_shutdown_actions();
640
os::wait_for_keypress_at_exit();
641
os::shutdown();
642
}
643
644
void vm_abort(bool dump_core) {
645
vm_perform_shutdown_actions();
646
os::wait_for_keypress_at_exit();
647
os::abort(dump_core);
648
ShouldNotReachHere();
649
}
650
651
void vm_notify_during_shutdown(const char* error, const char* message) {
652
if (error != NULL) {
653
tty->print_cr("Error occurred during initialization of VM");
654
tty->print("%s", error);
655
if (message != NULL) {
656
tty->print_cr(": %s", message);
657
}
658
else {
659
tty->cr();
660
}
661
}
662
if (ShowMessageBoxOnError && WizardMode) {
663
fatal("Error occurred during initialization of VM");
664
}
665
}
666
667
void vm_exit_during_initialization(Handle exception) {
668
tty->print_cr("Error occurred during initialization of VM");
669
// If there are exceptions on this thread it must be cleared
670
// first and here. Any future calls to EXCEPTION_MARK requires
671
// that no pending exceptions exist.
672
Thread *THREAD = Thread::current();
673
if (HAS_PENDING_EXCEPTION) {
674
CLEAR_PENDING_EXCEPTION;
675
}
676
java_lang_Throwable::print(exception, tty);
677
tty->cr();
678
java_lang_Throwable::print_stack_trace(exception(), tty);
679
tty->cr();
680
vm_notify_during_shutdown(NULL, NULL);
681
682
// Failure during initialization, we don't want to dump core
683
vm_abort(false);
684
}
685
686
void vm_exit_during_initialization(Symbol* ex, const char* message) {
687
ResourceMark rm;
688
vm_notify_during_shutdown(ex->as_C_string(), message);
689
690
// Failure during initialization, we don't want to dump core
691
vm_abort(false);
692
}
693
694
void vm_exit_during_initialization(const char* error, const char* message) {
695
vm_notify_during_shutdown(error, message);
696
697
// Failure during initialization, we don't want to dump core
698
vm_abort(false);
699
}
700
701
void vm_shutdown_during_initialization(const char* error, const char* message) {
702
vm_notify_during_shutdown(error, message);
703
vm_shutdown();
704
}
705
706
JDK_Version JDK_Version::_current;
707
const char* JDK_Version::_runtime_name;
708
const char* JDK_Version::_runtime_version;
709
710
void JDK_Version::initialize() {
711
jdk_version_info info;
712
assert(!_current.is_valid(), "Don't initialize twice");
713
714
void *lib_handle = os::native_java_library();
715
jdk_version_info_fn_t func = CAST_TO_FN_PTR(jdk_version_info_fn_t,
716
os::dll_lookup(lib_handle, "JDK_GetVersionInfo0"));
717
718
if (func == NULL) {
719
// JDK older than 1.6
720
_current._partially_initialized = true;
721
} else {
722
(*func)(&info, sizeof(info));
723
724
int major = JDK_VERSION_MAJOR(info.jdk_version);
725
int minor = JDK_VERSION_MINOR(info.jdk_version);
726
int micro = JDK_VERSION_MICRO(info.jdk_version);
727
int build = JDK_VERSION_BUILD(info.jdk_version);
728
if (major == 1 && minor > 4) {
729
// We represent "1.5.0" as "5.0", but 1.4.2 as itself.
730
major = minor;
731
minor = micro;
732
micro = 0;
733
}
734
_current = JDK_Version(major, minor, micro, info.update_version,
735
info.special_update_version, build,
736
info.thread_park_blocker == 1,
737
info.post_vm_init_hook_enabled == 1,
738
info.pending_list_uses_discovered_field == 1);
739
}
740
}
741
742
void JDK_Version::fully_initialize(
743
uint8_t major, uint8_t minor, uint8_t micro, uint8_t update) {
744
// This is only called when current is less than 1.6 and we've gotten
745
// far enough in the initialization to determine the exact version.
746
assert(major < 6, "not needed for JDK version >= 6");
747
assert(is_partially_initialized(), "must not initialize");
748
if (major < 5) {
749
// JDK verison sequence: 1.2.x, 1.3.x, 1.4.x, 5.0.x, 6.0.x, etc.
750
micro = minor;
751
minor = major;
752
major = 1;
753
}
754
_current = JDK_Version(major, minor, micro, update);
755
}
756
757
void JDK_Version_init() {
758
JDK_Version::initialize();
759
}
760
761
static int64_t encode_jdk_version(const JDK_Version& v) {
762
return
763
((int64_t)v.major_version() << (BitsPerByte * 5)) |
764
((int64_t)v.minor_version() << (BitsPerByte * 4)) |
765
((int64_t)v.micro_version() << (BitsPerByte * 3)) |
766
((int64_t)v.update_version() << (BitsPerByte * 2)) |
767
((int64_t)v.special_update_version() << (BitsPerByte * 1)) |
768
((int64_t)v.build_number() << (BitsPerByte * 0));
769
}
770
771
int JDK_Version::compare(const JDK_Version& other) const {
772
assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)");
773
if (!is_partially_initialized() && other.is_partially_initialized()) {
774
return -(other.compare(*this)); // flip the comparators
775
}
776
assert(!other.is_partially_initialized(), "Not initialized yet");
777
if (is_partially_initialized()) {
778
assert(other.major_version() >= 6,
779
"Invalid JDK version comparison during initialization");
780
return -1;
781
} else {
782
uint64_t e = encode_jdk_version(*this);
783
uint64_t o = encode_jdk_version(other);
784
return (e > o) ? 1 : ((e == o) ? 0 : -1);
785
}
786
}
787
788
void JDK_Version::to_string(char* buffer, size_t buflen) const {
789
assert(buffer && buflen > 0, "call with useful buffer");
790
size_t index = 0;
791
if (!is_valid()) {
792
jio_snprintf(buffer, buflen, "%s", "(uninitialized)");
793
} else if (is_partially_initialized()) {
794
jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0");
795
} else {
796
int rc = jio_snprintf(
797
&buffer[index], buflen - index, "%d.%d", _major, _minor);
798
if (rc == -1) return;
799
index += rc;
800
if (_micro > 0) {
801
rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _micro);
802
if (rc == -1) return;
803
index += rc;
804
}
805
if (_update > 0) {
806
rc = jio_snprintf(&buffer[index], buflen - index, "_%02d", _update);
807
if (rc == -1) return;
808
index += rc;
809
}
810
if (_special > 0) {
811
rc = jio_snprintf(&buffer[index], buflen - index, "%c", _special);
812
if (rc == -1) return;
813
index += rc;
814
}
815
if (_build > 0) {
816
rc = jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build);
817
if (rc == -1) return;
818
index += rc;
819
}
820
}
821
}
822
823