src/hotspot/share/gc/shared/parallelCleaning.hpp
author coleenp
Fri, 28 Sep 2018 16:07:39 -0400
changeset 51959 db0c3952de52
parent 51537 a5d47d1b2a74
child 52385 5c679ec60888
permissions -rw-r--r--
8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files Reviewed-by: iklam, stuefe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51524
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
     1
/*
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
     4
 *
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
     8
 *
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    13
 * accompanied this code).
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    14
 *
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    18
 *
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    21
 * questions.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    22
 *
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    23
 */
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    24
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    25
#ifndef SHARE_VM_GC_SHARED_PARALLELCLEANING_HPP
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    26
#define SHARE_VM_GC_SHARED_PARALLELCLEANING_HPP
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    27
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents: 51537
diff changeset
    28
#include "classfile/classLoaderDataGraph.inline.hpp"
51524
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    29
#include "gc/shared/oopStorageParState.hpp"
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    30
#include "gc/shared/stringdedup/stringDedup.hpp"
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    31
#include "gc/shared/workgroup.hpp"
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    32
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    33
class ParallelCleaningTask;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    34
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    35
class StringCleaningTask : public AbstractGangTask {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    36
private:
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    37
  BoolObjectClosure* _is_alive;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    38
  StringDedupUnlinkOrOopsDoClosure * const _dedup_closure;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    39
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    40
  OopStorage::ParState<false /* concurrent */, false /* const */> _par_state_string;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    41
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    42
  int _initial_string_table_size;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    43
51537
a5d47d1b2a74 8209852: Counters in StringCleaningTask should be type of size_t
zgu
parents: 51524
diff changeset
    44
  bool            _process_strings;
a5d47d1b2a74 8209852: Counters in StringCleaningTask should be type of size_t
zgu
parents: 51524
diff changeset
    45
  volatile size_t _strings_processed;
a5d47d1b2a74 8209852: Counters in StringCleaningTask should be type of size_t
zgu
parents: 51524
diff changeset
    46
  volatile size_t _strings_removed;
51524
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    47
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    48
public:
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    49
  StringCleaningTask(BoolObjectClosure* is_alive, StringDedupUnlinkOrOopsDoClosure* dedup_closure, bool process_strings);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    50
  ~StringCleaningTask();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    51
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    52
  void work(uint worker_id);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    53
51537
a5d47d1b2a74 8209852: Counters in StringCleaningTask should be type of size_t
zgu
parents: 51524
diff changeset
    54
  size_t strings_processed() const { return _strings_processed; }
a5d47d1b2a74 8209852: Counters in StringCleaningTask should be type of size_t
zgu
parents: 51524
diff changeset
    55
  size_t strings_removed()   const { return _strings_removed; }
51524
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    56
};
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    57
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    58
class CodeCacheUnloadingTask {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    59
private:
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    60
  static Monitor* _lock;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    61
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    62
  BoolObjectClosure* const _is_alive;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    63
  const bool               _unloading_occurred;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    64
  const uint               _num_workers;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    65
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    66
  // Variables used to claim nmethods.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    67
  CompiledMethod* _first_nmethod;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    68
  CompiledMethod* volatile _claimed_nmethod;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    69
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    70
  // The list of nmethods that need to be processed by the second pass.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    71
  CompiledMethod* volatile _postponed_list;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    72
  volatile uint            _num_entered_barrier;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    73
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    74
public:
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    75
  CodeCacheUnloadingTask(uint num_workers, BoolObjectClosure* is_alive, bool unloading_occurred);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    76
  ~CodeCacheUnloadingTask();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    77
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    78
private:
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    79
  void add_to_postponed_list(CompiledMethod* nm);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    80
  void clean_nmethod(CompiledMethod* nm);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    81
  void clean_nmethod_postponed(CompiledMethod* nm);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    82
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    83
  static const int MaxClaimNmethods = 16;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    84
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    85
  void claim_nmethods(CompiledMethod** claimed_nmethods, int *num_claimed_nmethods);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    86
  CompiledMethod* claim_postponed_nmethod();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    87
public:
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    88
  // Mark that we're done with the first pass of nmethod cleaning.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    89
  void barrier_mark(uint worker_id);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    90
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    91
  // See if we have to wait for the other workers to
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    92
  // finish their first-pass nmethod cleaning work.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    93
  void barrier_wait(uint worker_id);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    94
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    95
  // Cleaning and unloading of nmethods. Some work has to be postponed
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    96
  // to the second pass, when we know which nmethods survive.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    97
  void work_first_pass(uint worker_id);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    98
  void work_second_pass(uint worker_id);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    99
};
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   100
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   101
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   102
class KlassCleaningTask : public StackObj {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   103
  volatile int                            _clean_klass_tree_claimed;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   104
  ClassLoaderDataGraphKlassIteratorAtomic _klass_iterator;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   105
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   106
public:
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   107
  KlassCleaningTask();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   108
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   109
private:
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   110
  bool claim_clean_klass_tree_task();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   111
  InstanceKlass* claim_next_klass();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   112
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   113
public:
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   114
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   115
  void clean_klass(InstanceKlass* ik) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   116
    ik->clean_weak_instanceklass_links();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   117
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   118
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   119
  void work();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   120
};
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   121
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   122
// To minimize the remark pause times, the tasks below are done in parallel.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   123
class ParallelCleaningTask : public AbstractGangTask {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   124
private:
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   125
  bool                        _unloading_occurred;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   126
  StringCleaningTask          _string_task;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   127
  CodeCacheUnloadingTask      _code_cache_task;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   128
  KlassCleaningTask           _klass_cleaning_task;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   129
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   130
public:
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   131
  // The constructor is run in the VMThread.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   132
  ParallelCleaningTask(BoolObjectClosure* is_alive, StringDedupUnlinkOrOopsDoClosure* dedup_closure,
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   133
    uint num_workers, bool unloading_occurred);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   134
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   135
  void work(uint worker_id);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   136
};
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   137
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   138
#endif // SHARE_VM_GC_SHARED_PARALLELCLEANING_HPP