1 /* 2 * Copyright (c) 2018, 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 * 23 */ 24 25 #ifndef SHARE_GC_SHARED_PARALLELCLEANING_HPP 26 #define SHARE_GC_SHARED_PARALLELCLEANING_HPP 27 28 #include "classfile/classLoaderDataGraph.hpp" 29 #include "code/codeCache.hpp" 30 #include "gc/shared/oopStorageParState.hpp" 31 #include "gc/shared/stringdedup/stringDedup.hpp" 32 #include "gc/shared/workgroup.hpp" 33 34 class ParallelCleaningTask; 35 36 class StringDedupCleaningTask : public AbstractGangTask { 37 StringDedupUnlinkOrOopsDoClosure _dedup_closure; 38 39 public: 40 StringDedupCleaningTask(BoolObjectClosure* is_alive, OopClosure* keep_alive, bool resize_table); 41 ~StringDedupCleaningTask(); 42 43 void work(uint worker_id); 44 }; 45 46 class CodeCacheUnloadingTask { 47 48 CodeCache::UnloadingScope _unloading_scope; 49 const bool _unloading_occurred; 50 const uint _num_workers; 51 52 // Variables used to claim nmethods. 53 CompiledMethod* _first_nmethod; 54 CompiledMethod* volatile _claimed_nmethod; 55 56 public: 57 CodeCacheUnloadingTask(uint num_workers, BoolObjectClosure* is_alive, bool unloading_occurred); 58 ~CodeCacheUnloadingTask(); 59 60 private: 61 static const int MaxClaimNmethods = 16; 62 void claim_nmethods(CompiledMethod** claimed_nmethods, int *num_claimed_nmethods); 63 64 public: 65 // Cleaning and unloading of nmethods. 66 void work(uint worker_id); 67 }; 68 69 70 class KlassCleaningTask : public StackObj { 71 volatile int _clean_klass_tree_claimed; 72 ClassLoaderDataGraphKlassIteratorAtomic _klass_iterator; 73 74 public: 75 KlassCleaningTask(); 76 77 private: 78 bool claim_clean_klass_tree_task(); 79 InstanceKlass* claim_next_klass(); 80 81 public: 82 clean_klass(InstanceKlass * ik)83 void clean_klass(InstanceKlass* ik) { 84 ik->clean_weak_instanceklass_links(); 85 } 86 87 void work(); 88 }; 89 90 #if INCLUDE_JVMCI 91 class JVMCICleaningTask : public StackObj { 92 volatile int _cleaning_claimed; 93 94 public: 95 JVMCICleaningTask(); 96 // Clean JVMCI metadata handles. 97 void work(bool unloading_occurred); 98 99 private: 100 bool claim_cleaning_task(); 101 }; 102 #endif 103 104 // Do cleanup of some weakly held data in the same parallel task. 105 // Assumes a non-moving context. 106 class ParallelCleaningTask : public AbstractGangTask { 107 private: 108 bool _unloading_occurred; 109 StringDedupCleaningTask _string_dedup_task; 110 CodeCacheUnloadingTask _code_cache_task; 111 #if INCLUDE_JVMCI 112 JVMCICleaningTask _jvmci_cleaning_task; 113 #endif 114 KlassCleaningTask _klass_cleaning_task; 115 116 public: 117 // The constructor is run in the VMThread. 118 ParallelCleaningTask(BoolObjectClosure* is_alive, 119 uint num_workers, 120 bool unloading_occurred, 121 bool resize_dedup_table); 122 123 void work(uint worker_id); 124 }; 125 126 #endif // SHARE_GC_SHARED_PARALLELCLEANING_HPP 127