< prev index next >

src/hotspot/share/runtime/safepoint.cpp

Print this page




   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/classLoaderData.hpp"
  27 #include "classfile/stringTable.hpp"
  28 #include "classfile/symbolTable.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "code/codeCache.hpp"
  31 #include "code/icBuffer.hpp"
  32 #include "code/nmethod.hpp"
  33 #include "code/pcDesc.hpp"
  34 #include "code/scopeDesc.hpp"
  35 #include "gc/shared/collectedHeap.hpp"
  36 #include "gc/shared/gcLocker.hpp"
  37 #include "gc/shared/strongRootsScope.hpp"
  38 #include "gc/shared/workgroup.hpp"
  39 #include "interpreter/interpreter.hpp"
  40 #include "jfr/jfrEvents.hpp"
  41 #include "logging/log.hpp"
  42 #include "logging/logStream.hpp"
  43 #include "memory/resourceArea.hpp"
  44 #include "memory/universe.hpp"
  45 #include "oops/oop.inline.hpp"
  46 #include "oops/symbol.hpp"


 703       // CMS delays purging the CLDG until the beginning of the next safepoint and to
 704       // make sure concurrent sweep is done
 705       const char* name = "purging class loader data graph";
 706       EventSafepointCleanupTask event;
 707       TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
 708       ClassLoaderDataGraph::purge_if_needed();
 709       if (event.should_commit()) {
 710         post_safepoint_cleanup_task_event(&event, name);
 711       }
 712     }
 713 
 714     if (!_subtasks.is_task_claimed(SafepointSynchronize::SAFEPOINT_CLEANUP_SYSTEM_DICTIONARY_RESIZE)) {
 715       const char* name = "resizing system dictionaries";
 716       EventSafepointCleanupTask event;
 717       TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
 718       ClassLoaderDataGraph::resize_if_needed();
 719       if (event.should_commit()) {
 720         post_safepoint_cleanup_task_event(&event, name);
 721       }
 722     }

 723     _subtasks.all_tasks_completed(_num_workers);
 724   }
 725 };
 726 
 727 // Various cleaning tasks that should be done periodically at safepoints.
 728 void SafepointSynchronize::do_cleanup_tasks() {
 729 
 730   TraceTime timer("safepoint cleanup tasks", TRACETIME_LOG(Info, safepoint, cleanup));
 731 
 732   // Prepare for monitor deflation.
 733   DeflateMonitorCounters deflate_counters;
 734   ObjectSynchronizer::prepare_deflate_idle_monitors(&deflate_counters);
 735 
 736   CollectedHeap* heap = Universe::heap();
 737   assert(heap != NULL, "heap not initialized yet?");
 738   WorkGang* cleanup_workers = heap->get_safepoint_workers();
 739   if (cleanup_workers != NULL) {
 740     // Parallel cleanup using GC provided thread pool.
 741     uint num_cleanup_workers = cleanup_workers->active_workers();
 742     ParallelSPCleanupTask cleanup(num_cleanup_workers, &deflate_counters);
 743     StrongRootsScope srs(num_cleanup_workers);
 744     cleanup_workers->run_task(&cleanup);
 745   } else {
 746     // Serial cleanup using VMThread.
 747     ParallelSPCleanupTask cleanup(1, &deflate_counters);
 748     StrongRootsScope srs(1);
 749     cleanup.work(0);
 750   }
 751 









 752   // Finish monitor deflation.
 753   ObjectSynchronizer::finish_deflate_idle_monitors(&deflate_counters);

 754 }
 755 
 756 
 757 bool SafepointSynchronize::safepoint_safe(JavaThread *thread, JavaThreadState state) {
 758   switch(state) {
 759   case _thread_in_native:
 760     // native threads are safe if they have no java stack or have walkable stack
 761     return !thread->has_last_Java_frame() || thread->frame_anchor()->walkable();
 762 
 763    // blocked threads should have already have walkable stack
 764   case _thread_blocked:
 765     assert(!thread->has_last_Java_frame() || thread->frame_anchor()->walkable(), "blocked and not walkable");
 766     return true;
 767 
 768   default:
 769     return false;
 770   }
 771 }
 772 
 773 




   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/classLoaderData.inline.hpp"
  27 #include "classfile/stringTable.hpp"
  28 #include "classfile/symbolTable.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "code/codeCache.hpp"
  31 #include "code/icBuffer.hpp"
  32 #include "code/nmethod.hpp"
  33 #include "code/pcDesc.hpp"
  34 #include "code/scopeDesc.hpp"
  35 #include "gc/shared/collectedHeap.hpp"
  36 #include "gc/shared/gcLocker.hpp"
  37 #include "gc/shared/strongRootsScope.hpp"
  38 #include "gc/shared/workgroup.hpp"
  39 #include "interpreter/interpreter.hpp"
  40 #include "jfr/jfrEvents.hpp"
  41 #include "logging/log.hpp"
  42 #include "logging/logStream.hpp"
  43 #include "memory/resourceArea.hpp"
  44 #include "memory/universe.hpp"
  45 #include "oops/oop.inline.hpp"
  46 #include "oops/symbol.hpp"


 703       // CMS delays purging the CLDG until the beginning of the next safepoint and to
 704       // make sure concurrent sweep is done
 705       const char* name = "purging class loader data graph";
 706       EventSafepointCleanupTask event;
 707       TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
 708       ClassLoaderDataGraph::purge_if_needed();
 709       if (event.should_commit()) {
 710         post_safepoint_cleanup_task_event(&event, name);
 711       }
 712     }
 713 
 714     if (!_subtasks.is_task_claimed(SafepointSynchronize::SAFEPOINT_CLEANUP_SYSTEM_DICTIONARY_RESIZE)) {
 715       const char* name = "resizing system dictionaries";
 716       EventSafepointCleanupTask event;
 717       TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
 718       ClassLoaderDataGraph::resize_if_needed();
 719       if (event.should_commit()) {
 720         post_safepoint_cleanup_task_event(&event, name);
 721       }
 722     }
 723 
 724     _subtasks.all_tasks_completed(_num_workers);
 725   }
 726 };
 727 
 728 // Various cleaning tasks that should be done periodically at safepoints.
 729 void SafepointSynchronize::do_cleanup_tasks() {
 730 
 731   TraceTime timer("safepoint cleanup tasks", TRACETIME_LOG(Info, safepoint, cleanup));
 732 
 733   // Prepare for monitor deflation.
 734   DeflateMonitorCounters deflate_counters;
 735   ObjectSynchronizer::prepare_deflate_idle_monitors(&deflate_counters);
 736 
 737   CollectedHeap* heap = Universe::heap();
 738   assert(heap != NULL, "heap not initialized yet?");
 739   WorkGang* cleanup_workers = heap->get_safepoint_workers();
 740   if (cleanup_workers != NULL) {
 741     // Parallel cleanup using GC provided thread pool.
 742     uint num_cleanup_workers = cleanup_workers->active_workers();
 743     ParallelSPCleanupTask cleanup(num_cleanup_workers, &deflate_counters);
 744     StrongRootsScope srs(num_cleanup_workers);
 745     cleanup_workers->run_task(&cleanup);
 746   } else {
 747     // Serial cleanup using VMThread.
 748     ParallelSPCleanupTask cleanup(1, &deflate_counters);
 749     StrongRootsScope srs(1);
 750     cleanup.work(0);
 751   }
 752 
 753   // Needs to be done single threaded by the VMThread.  This walks
 754   // the thread stacks looking for references to metadata before
 755   // deciding to remove it from the metaspaces.
 756   if (ClassLoaderDataGraph::should_clean_metaspaces()) {
 757     const char* name = "cleanup live ClassLoaderData metaspaces";
 758     TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
 759     ClassLoaderDataGraph::walk_metadata_and_clean_metaspaces();
 760   }
 761 
 762   // Finish monitor deflation.
 763   ObjectSynchronizer::finish_deflate_idle_monitors(&deflate_counters);
 764 
 765 }
 766 
 767 
 768 bool SafepointSynchronize::safepoint_safe(JavaThread *thread, JavaThreadState state) {
 769   switch(state) {
 770   case _thread_in_native:
 771     // native threads are safe if they have no java stack or have walkable stack
 772     return !thread->has_last_Java_frame() || thread->frame_anchor()->walkable();
 773 
 774    // blocked threads should have already have walkable stack
 775   case _thread_blocked:
 776     assert(!thread->has_last_Java_frame() || thread->frame_anchor()->walkable(), "blocked and not walkable");
 777     return true;
 778 
 779   default:
 780     return false;
 781   }
 782 }
 783 
 784 


< prev index next >