1 /*
2 * Copyright (c) 1997, 2015, 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 *
404 #define BEFORE_EXIT_DONE 2
405 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
406
407 // Note: don't use a Mutex to guard the entire before_exit(), as
408 // JVMTI post_thread_end_event and post_vm_death_event will run native code.
409 // A CAS or OSMutex would work just fine but then we need to manipulate
410 // thread state for Safepoint. Here we use Monitor wait() and notify_all()
411 // for synchronization.
412 { MutexLocker ml(BeforeExit_lock);
413 switch (_before_exit_status) {
414 case BEFORE_EXIT_NOT_RUN:
415 _before_exit_status = BEFORE_EXIT_RUNNING;
416 break;
417 case BEFORE_EXIT_RUNNING:
418 while (_before_exit_status == BEFORE_EXIT_RUNNING) {
419 BeforeExit_lock->wait();
420 }
421 assert(_before_exit_status == BEFORE_EXIT_DONE, "invalid state");
422 return;
423 case BEFORE_EXIT_DONE:
424 return;
425 }
426 }
427
428 #if INCLUDE_JVMCI
429 // We are not using CATCH here because we want the exit to continue normally.
430 Thread* THREAD = thread;
431 JVMCIRuntime::shutdown(THREAD);
432 if (HAS_PENDING_EXCEPTION) {
433 Handle exception(THREAD, PENDING_EXCEPTION);
434 CLEAR_PENDING_EXCEPTION;
435 ttyLocker ttyl;
436 java_lang_Throwable::print_stack_trace(exception, tty);
437 }
438 #endif
439
440 // Hang forever on exit if we're reporting an error.
441 if (ShowMessageBoxOnError && is_error_reported()) {
442 os::infinite_sleep();
443 }
444
445 // Stop the WatcherThread. We do this before disenrolling various
446 // PeriodicTasks to reduce the likelihood of races.
|
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 *
404 #define BEFORE_EXIT_DONE 2
405 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN;
406
407 // Note: don't use a Mutex to guard the entire before_exit(), as
408 // JVMTI post_thread_end_event and post_vm_death_event will run native code.
409 // A CAS or OSMutex would work just fine but then we need to manipulate
410 // thread state for Safepoint. Here we use Monitor wait() and notify_all()
411 // for synchronization.
412 { MutexLocker ml(BeforeExit_lock);
413 switch (_before_exit_status) {
414 case BEFORE_EXIT_NOT_RUN:
415 _before_exit_status = BEFORE_EXIT_RUNNING;
416 break;
417 case BEFORE_EXIT_RUNNING:
418 while (_before_exit_status == BEFORE_EXIT_RUNNING) {
419 BeforeExit_lock->wait();
420 }
421 assert(_before_exit_status == BEFORE_EXIT_DONE, "invalid state");
422 return;
423 case BEFORE_EXIT_DONE:
424 // need block to avoid SS compiler bug
425 {
426 return;
427 }
428 }
429 }
430
431 #if INCLUDE_JVMCI
432 // We are not using CATCH here because we want the exit to continue normally.
433 Thread* THREAD = thread;
434 JVMCIRuntime::shutdown(THREAD);
435 if (HAS_PENDING_EXCEPTION) {
436 Handle exception(THREAD, PENDING_EXCEPTION);
437 CLEAR_PENDING_EXCEPTION;
438 ttyLocker ttyl;
439 java_lang_Throwable::print_stack_trace(exception, tty);
440 }
441 #endif
442
443 // Hang forever on exit if we're reporting an error.
444 if (ShowMessageBoxOnError && is_error_reported()) {
445 os::infinite_sleep();
446 }
447
448 // Stop the WatcherThread. We do this before disenrolling various
449 // PeriodicTasks to reduce the likelihood of races.
|