< prev index next >

src/hotspot/share/runtime/safepoint.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2019, 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  *


 477     assert(_state == _synchronized, "must be synchronized before ending safepoint synchronization");
 478 
 479     // Change state first to _not_synchronized.
 480     // No threads should see _synchronized when running.
 481     _state = _not_synchronized;
 482 
 483     // Set the next dormant (even) safepoint id.
 484     assert((_safepoint_counter & 0x1) == 1, "must be odd");
 485     Atomic::release_store(&_safepoint_counter, _safepoint_counter + 1);
 486 
 487     OrderAccess::fence(); // Keep the local state from floating up.
 488 
 489     jtiwh.rewind();
 490     for (; JavaThread *current = jtiwh.next(); ) {
 491       // Clear the visited flag to ensure that the critical counts are collected properly.
 492       DEBUG_ONLY(current->reset_visited_for_critical_count(active_safepoint_counter);)
 493       ThreadSafepointState* cur_state = current->safepoint_state();
 494       assert(!cur_state->is_running(), "Thread not suspended at safepoint");
 495       cur_state->restart(); // TSS _running
 496       assert(cur_state->is_running(), "safepoint state has not been reset");
 497 
 498       SafepointMechanism::disarm_if_needed(current, false /* NO release */);
 499     }
 500   } // ~JavaThreadIteratorWithHandle
 501 
 502   // Release threads lock, so threads can be created/destroyed again.
 503   Threads_lock->unlock();
 504 
 505   // Wake threads after local state is correctly set.
 506   _wait_barrier->disarm();
 507 }
 508 
 509 // Wake up all threads, so they are ready to resume execution after the safepoint
 510 // operation has been carried out
 511 void SafepointSynchronize::end() {
 512   assert(Threads_lock->owned_by_self(), "must hold Threads_lock");
 513   EventSafepointEnd event;
 514   assert(Thread::current()->is_VM_thread(), "Only VM thread can execute a safepoint");
 515 
 516   disarm_safepoint();
 517 
 518   Universe::heap()->safepoint_synchronize_end();


 719 }
 720 
 721 static bool safepoint_safe_with(JavaThread *thread, JavaThreadState state) {
 722   switch(state) {
 723   case _thread_in_native:
 724     // native threads are safe if they have no java stack or have walkable stack
 725     return !thread->has_last_Java_frame() || thread->frame_anchor()->walkable();
 726 
 727   case _thread_blocked:
 728     // On wait_barrier or blocked.
 729     // Blocked threads should already have walkable stack.
 730     assert(!thread->has_last_Java_frame() || thread->frame_anchor()->walkable(), "blocked and not walkable");
 731     return true;
 732 
 733   default:
 734     return false;
 735   }
 736 }
 737 
 738 bool SafepointSynchronize::handshake_safe(JavaThread *thread) {
 739   assert(Thread::current()->is_VM_thread(), "Must be VMThread");
 740   if (thread->is_ext_suspended() || thread->is_terminated()) {
 741     return true;
 742   }
 743   JavaThreadState stable_state;
 744   if (try_stable_load_state(&stable_state, thread, InactiveSafepointCounter)) {
 745     return safepoint_safe_with(thread, stable_state);
 746   }
 747   return false;
 748 }
 749 
 750 // See if the thread is running inside a lazy critical native and
 751 // update the thread critical count if so.  Also set a suspend flag to
 752 // cause the native wrapper to return into the JVM to do the unlock
 753 // once the native finishes.
 754 static void check_for_lazy_critical_native(JavaThread *thread, JavaThreadState state) {
 755   if (state == _thread_in_native &&
 756       thread->has_last_Java_frame() &&
 757       thread->frame_anchor()->walkable()) {
 758     // This thread might be in a critical native nmethod so look at
 759     // the top of the stack and increment the critical count if it


   1 /*
   2  * Copyright (c) 1997, 2020, 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  *


 477     assert(_state == _synchronized, "must be synchronized before ending safepoint synchronization");
 478 
 479     // Change state first to _not_synchronized.
 480     // No threads should see _synchronized when running.
 481     _state = _not_synchronized;
 482 
 483     // Set the next dormant (even) safepoint id.
 484     assert((_safepoint_counter & 0x1) == 1, "must be odd");
 485     Atomic::release_store(&_safepoint_counter, _safepoint_counter + 1);
 486 
 487     OrderAccess::fence(); // Keep the local state from floating up.
 488 
 489     jtiwh.rewind();
 490     for (; JavaThread *current = jtiwh.next(); ) {
 491       // Clear the visited flag to ensure that the critical counts are collected properly.
 492       DEBUG_ONLY(current->reset_visited_for_critical_count(active_safepoint_counter);)
 493       ThreadSafepointState* cur_state = current->safepoint_state();
 494       assert(!cur_state->is_running(), "Thread not suspended at safepoint");
 495       cur_state->restart(); // TSS _running
 496       assert(cur_state->is_running(), "safepoint state has not been reset");


 497     }
 498   } // ~JavaThreadIteratorWithHandle
 499 
 500   // Release threads lock, so threads can be created/destroyed again.
 501   Threads_lock->unlock();
 502 
 503   // Wake threads after local state is correctly set.
 504   _wait_barrier->disarm();
 505 }
 506 
 507 // Wake up all threads, so they are ready to resume execution after the safepoint
 508 // operation has been carried out
 509 void SafepointSynchronize::end() {
 510   assert(Threads_lock->owned_by_self(), "must hold Threads_lock");
 511   EventSafepointEnd event;
 512   assert(Thread::current()->is_VM_thread(), "Only VM thread can execute a safepoint");
 513 
 514   disarm_safepoint();
 515 
 516   Universe::heap()->safepoint_synchronize_end();


 717 }
 718 
 719 static bool safepoint_safe_with(JavaThread *thread, JavaThreadState state) {
 720   switch(state) {
 721   case _thread_in_native:
 722     // native threads are safe if they have no java stack or have walkable stack
 723     return !thread->has_last_Java_frame() || thread->frame_anchor()->walkable();
 724 
 725   case _thread_blocked:
 726     // On wait_barrier or blocked.
 727     // Blocked threads should already have walkable stack.
 728     assert(!thread->has_last_Java_frame() || thread->frame_anchor()->walkable(), "blocked and not walkable");
 729     return true;
 730 
 731   default:
 732     return false;
 733   }
 734 }
 735 
 736 bool SafepointSynchronize::handshake_safe(JavaThread *thread) {

 737   if (thread->is_ext_suspended() || thread->is_terminated()) {
 738     return true;
 739   }
 740   JavaThreadState stable_state;
 741   if (try_stable_load_state(&stable_state, thread, InactiveSafepointCounter)) {
 742     return safepoint_safe_with(thread, stable_state);
 743   }
 744   return false;
 745 }
 746 
 747 // See if the thread is running inside a lazy critical native and
 748 // update the thread critical count if so.  Also set a suspend flag to
 749 // cause the native wrapper to return into the JVM to do the unlock
 750 // once the native finishes.
 751 static void check_for_lazy_critical_native(JavaThread *thread, JavaThreadState state) {
 752   if (state == _thread_in_native &&
 753       thread->has_last_Java_frame() &&
 754       thread->frame_anchor()->walkable()) {
 755     // This thread might be in a critical native nmethod so look at
 756     // the top of the stack and increment the critical count if it


< prev index next >