src/hotspot/share/gc/shared/parallelCleaning.cpp
author dholmes
Thu, 08 Nov 2018 07:42:08 -0500
changeset 52448 bc5c7f63dbae
parent 52385 5c679ec60888
child 52661 4f45c682eab0
permissions -rw-r--r--
8213137: Remove static initialization of monitor/mutex instances Summary: moved to the global mutex list in mutexLocker Reviewed-by: tschatzl, dcubed, rehn, eosterlund
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
#include "precompiled.hpp"
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    26
#include "classfile/symbolTable.hpp"
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    27
#include "classfile/stringTable.hpp"
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    28
#include "code/codeCache.hpp"
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    29
#include "gc/shared/parallelCleaning.hpp"
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 51537
diff changeset
    30
#include "logging/log.hpp"
51524
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    31
#include "memory/resourceArea.hpp"
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    32
#include "logging/log.hpp"
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    33
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    34
StringCleaningTask::StringCleaningTask(BoolObjectClosure* is_alive, StringDedupUnlinkOrOopsDoClosure* dedup_closure, bool process_strings) :
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    35
  AbstractGangTask("String Unlinking"),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    36
  _is_alive(is_alive),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    37
  _dedup_closure(dedup_closure),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    38
  _par_state_string(StringTable::weak_storage()),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    39
  _initial_string_table_size((int) StringTable::the_table()->table_size()),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    40
  _process_strings(process_strings), _strings_processed(0), _strings_removed(0) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    41
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    42
  if (process_strings) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    43
    StringTable::reset_dead_counter();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    44
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    45
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    46
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    47
StringCleaningTask::~StringCleaningTask() {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    48
  log_info(gc, stringtable)(
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    49
      "Cleaned string table, "
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    50
      "strings: " SIZE_FORMAT " processed, " SIZE_FORMAT " removed",
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    51
      strings_processed(), strings_removed());
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    52
  if (_process_strings) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    53
    StringTable::finish_dead_counter();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    54
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    55
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    56
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    57
void StringCleaningTask::work(uint worker_id) {
51537
a5d47d1b2a74 8209852: Counters in StringCleaningTask should be type of size_t
zgu
parents: 51524
diff changeset
    58
  size_t strings_processed = 0;
a5d47d1b2a74 8209852: Counters in StringCleaningTask should be type of size_t
zgu
parents: 51524
diff changeset
    59
  size_t strings_removed = 0;
51524
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    60
  if (_process_strings) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    61
    StringTable::possibly_parallel_unlink(&_par_state_string, _is_alive, &strings_processed, &strings_removed);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    62
    Atomic::add(strings_processed, &_strings_processed);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    63
    Atomic::add(strings_removed, &_strings_removed);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    64
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    65
  if (_dedup_closure != NULL) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    66
    StringDedup::parallel_unlink(_dedup_closure, worker_id);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    67
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    68
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    69
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    70
CodeCacheUnloadingTask::CodeCacheUnloadingTask(uint num_workers, BoolObjectClosure* is_alive, bool unloading_occurred) :
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 51537
diff changeset
    71
      _unloading_scope(is_alive),
51524
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    72
      _unloading_occurred(unloading_occurred),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    73
      _num_workers(num_workers),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    74
      _first_nmethod(NULL),
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 51537
diff changeset
    75
      _claimed_nmethod(NULL) {
51524
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    76
  // Get first alive nmethod
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    77
  CompiledMethodIterator iter = CompiledMethodIterator();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    78
  if(iter.next_alive()) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    79
    _first_nmethod = iter.method();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    80
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    81
  _claimed_nmethod = _first_nmethod;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    82
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    83
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    84
CodeCacheUnloadingTask::~CodeCacheUnloadingTask() {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    85
  CodeCache::verify_clean_inline_caches();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    86
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    87
  guarantee(CodeCache::scavenge_root_nmethods() == NULL, "Must be");
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    88
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    89
  CodeCache::verify_icholder_relocations();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    90
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    91
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    92
void CodeCacheUnloadingTask::claim_nmethods(CompiledMethod** claimed_nmethods, int *num_claimed_nmethods) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    93
  CompiledMethod* first;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    94
  CompiledMethodIterator last;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    95
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    96
  do {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    97
    *num_claimed_nmethods = 0;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    98
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    99
    first = _claimed_nmethod;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   100
    last = CompiledMethodIterator(first);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   101
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   102
    if (first != NULL) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   103
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   104
      for (int i = 0; i < MaxClaimNmethods; i++) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   105
        if (!last.next_alive()) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   106
          break;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   107
        }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   108
        claimed_nmethods[i] = last.method();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   109
        (*num_claimed_nmethods)++;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   110
      }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   111
    }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   112
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   113
  } while (Atomic::cmpxchg(last.method(), &_claimed_nmethod, first) != first);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   114
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   115
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 51537
diff changeset
   116
void CodeCacheUnloadingTask::work(uint worker_id) {
51524
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   117
  // The first nmethods is claimed by the first worker.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   118
  if (worker_id == 0 && _first_nmethod != NULL) {
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 51537
diff changeset
   119
    _first_nmethod->do_unloading(_unloading_occurred);
51524
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   120
    _first_nmethod = NULL;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   121
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   122
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   123
  int num_claimed_nmethods;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   124
  CompiledMethod* claimed_nmethods[MaxClaimNmethods];
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   125
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   126
  while (true) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   127
    claim_nmethods(claimed_nmethods, &num_claimed_nmethods);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   128
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   129
    if (num_claimed_nmethods == 0) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   130
      break;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   131
    }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   132
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   133
    for (int i = 0; i < num_claimed_nmethods; i++) {
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 51537
diff changeset
   134
      claimed_nmethods[i]->do_unloading(_unloading_occurred);
51524
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   135
    }
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
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   139
KlassCleaningTask::KlassCleaningTask() :
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   140
  _clean_klass_tree_claimed(0),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   141
  _klass_iterator() {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   142
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   143
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   144
bool KlassCleaningTask::claim_clean_klass_tree_task() {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   145
  if (_clean_klass_tree_claimed) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   146
    return false;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   147
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   148
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   149
  return Atomic::cmpxchg(1, &_clean_klass_tree_claimed, 0) == 0;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   150
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   151
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   152
InstanceKlass* KlassCleaningTask::claim_next_klass() {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   153
  Klass* klass;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   154
  do {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   155
    klass =_klass_iterator.next_klass();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   156
  } while (klass != NULL && !klass->is_instance_klass());
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   157
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   158
  // this can be null so don't call InstanceKlass::cast
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   159
  return static_cast<InstanceKlass*>(klass);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   160
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   161
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   162
void KlassCleaningTask::work() {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   163
  ResourceMark rm;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   164
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   165
  // One worker will clean the subklass/sibling klass tree.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   166
  if (claim_clean_klass_tree_task()) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   167
    Klass::clean_subklass_tree();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   168
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   169
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   170
  // All workers will help cleaning the classes,
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   171
  InstanceKlass* klass;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   172
  while ((klass = claim_next_klass()) != NULL) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   173
    clean_klass(klass);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   174
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   175
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   176
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   177
ParallelCleaningTask::ParallelCleaningTask(BoolObjectClosure* is_alive,
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   178
  StringDedupUnlinkOrOopsDoClosure* dedup_closure, uint num_workers, bool unloading_occurred) :
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   179
  AbstractGangTask("Parallel Cleaning"),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   180
  _unloading_occurred(unloading_occurred),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   181
  _string_task(is_alive, StringDedup::is_enabled() ? dedup_closure : NULL, true),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   182
  _code_cache_task(num_workers, is_alive, unloading_occurred),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   183
  _klass_cleaning_task() {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   184
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   185
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   186
// The parallel work done by all worker threads.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   187
void ParallelCleaningTask::work(uint worker_id) {
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 51537
diff changeset
   188
  // Do first pass of code cache cleaning.
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 51537
diff changeset
   189
  _code_cache_task.work(worker_id);
51524
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   190
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 51537
diff changeset
   191
  // Clean the Strings and Symbols.
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 51537
diff changeset
   192
  _string_task.work(worker_id);
51524
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   193
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   194
  // Clean all klasses that were not unloaded.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   195
  // The weak metadata in klass doesn't need to be
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   196
  // processed if there was no unloading.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   197
  if (_unloading_occurred) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   198
    _klass_cleaning_task.work();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   199
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   200
}