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 
  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   BoolObjectClosure* _is_alive;
  93   volatile int       _cleaning_claimed;
  94 
  95 public:
  96   JVMCICleaningTask(BoolObjectClosure* is_alive);
  97   // Clean JVMCI metadata handles.
  98   void work(bool unloading_occurred);
  99 
 100 private:
 101   bool claim_cleaning_task();
 102 };
 103 #endif
 104 
 105 // Do cleanup of some weakly held data in the same parallel task.
 106 // Assumes a non-moving context.
 107 class ParallelCleaningTask : public AbstractGangTask {
 108 private:
 109   bool                    _unloading_occurred;
 110   StringDedupCleaningTask _string_dedup_task;
 111   CodeCacheUnloadingTask  _code_cache_task;
 112 #if INCLUDE_JVMCI
 113   JVMCICleaningTask       _jvmci_cleaning_task;
 114 #endif
 115   KlassCleaningTask       _klass_cleaning_task;
 116 
 117 public:
 118   // The constructor is run in the VMThread.
 119   ParallelCleaningTask(BoolObjectClosure* is_alive,
 120                        uint num_workers,
 121                        bool unloading_occurred,
 122                        bool resize_dedup_table);
 123 
 124   void work(uint worker_id);
 125 };
 126 
 127 #endif // SHARE_GC_SHARED_PARALLELCLEANING_HPP
--- EOF ---