src/hotspot/share/gc/shared/parallelCleaning.cpp
author zgu
Mon, 27 Aug 2018 17:20:29 -0400
changeset 51537 a5d47d1b2a74
parent 51524 9d01ad46daef
child 52385 5c679ec60888
permissions -rw-r--r--
8209852: Counters in StringCleaningTask should be type of size_t Summary: Converted counters to size_t type to avoid casting Reviewed-by: coleenp
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"
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    30
#include "memory/resourceArea.hpp"
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    31
#include "logging/log.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
StringCleaningTask::StringCleaningTask(BoolObjectClosure* is_alive, StringDedupUnlinkOrOopsDoClosure* dedup_closure, bool process_strings) :
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    34
  AbstractGangTask("String Unlinking"),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    35
  _is_alive(is_alive),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    36
  _dedup_closure(dedup_closure),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    37
  _par_state_string(StringTable::weak_storage()),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    38
  _initial_string_table_size((int) StringTable::the_table()->table_size()),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    39
  _process_strings(process_strings), _strings_processed(0), _strings_removed(0) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    40
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    41
  if (process_strings) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    42
    StringTable::reset_dead_counter();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    43
  }
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
StringCleaningTask::~StringCleaningTask() {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    47
  log_info(gc, stringtable)(
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    48
      "Cleaned string table, "
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    49
      "strings: " SIZE_FORMAT " processed, " SIZE_FORMAT " removed",
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    50
      strings_processed(), strings_removed());
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    51
  if (_process_strings) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    52
    StringTable::finish_dead_counter();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    53
  }
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
void StringCleaningTask::work(uint worker_id) {
51537
a5d47d1b2a74 8209852: Counters in StringCleaningTask should be type of size_t
zgu
parents: 51524
diff changeset
    57
  size_t strings_processed = 0;
a5d47d1b2a74 8209852: Counters in StringCleaningTask should be type of size_t
zgu
parents: 51524
diff changeset
    58
  size_t strings_removed = 0;
51524
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    59
  if (_process_strings) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    60
    StringTable::possibly_parallel_unlink(&_par_state_string, _is_alive, &strings_processed, &strings_removed);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    61
    Atomic::add(strings_processed, &_strings_processed);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    62
    Atomic::add(strings_removed, &_strings_removed);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    63
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    64
  if (_dedup_closure != NULL) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    65
    StringDedup::parallel_unlink(_dedup_closure, worker_id);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    66
  }
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
CodeCacheUnloadingTask::CodeCacheUnloadingTask(uint num_workers, BoolObjectClosure* is_alive, bool unloading_occurred) :
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    70
      _is_alive(is_alive),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    71
      _unloading_occurred(unloading_occurred),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    72
      _num_workers(num_workers),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    73
      _first_nmethod(NULL),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    74
      _claimed_nmethod(NULL),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    75
      _postponed_list(NULL),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    76
      _num_entered_barrier(0) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    77
  CompiledMethod::increase_unloading_clock();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    78
  // Get first alive nmethod
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    79
  CompiledMethodIterator iter = CompiledMethodIterator();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    80
  if(iter.next_alive()) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    81
    _first_nmethod = iter.method();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    82
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    83
  _claimed_nmethod = _first_nmethod;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    84
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    85
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    86
CodeCacheUnloadingTask::~CodeCacheUnloadingTask() {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    87
  CodeCache::verify_clean_inline_caches();
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::set_needs_cache_clean(false);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    90
  guarantee(CodeCache::scavenge_root_nmethods() == NULL, "Must be");
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    91
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    92
  CodeCache::verify_icholder_relocations();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    93
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    94
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    95
Monitor* CodeCacheUnloadingTask::_lock = new Monitor(Mutex::leaf, "Code Cache Unload lock", false, Monitor::_safepoint_check_never);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    96
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    97
void CodeCacheUnloadingTask::add_to_postponed_list(CompiledMethod* nm) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    98
  CompiledMethod* old;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
    99
  do {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   100
    old = _postponed_list;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   101
    nm->set_unloading_next(old);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   102
  } while (Atomic::cmpxchg(nm, &_postponed_list, old) != old);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   103
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   104
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   105
void CodeCacheUnloadingTask::clean_nmethod(CompiledMethod* nm) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   106
  bool postponed = nm->do_unloading_parallel(_is_alive, _unloading_occurred);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   107
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   108
  if (postponed) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   109
    // This nmethod referred to an nmethod that has not been cleaned/unloaded yet.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   110
    add_to_postponed_list(nm);
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
  // Mark that this nmethod has been cleaned/unloaded.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   114
  // After this call, it will be safe to ask if this nmethod was unloaded or not.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   115
  nm->set_unloading_clock(CompiledMethod::global_unloading_clock());
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   116
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   117
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   118
void CodeCacheUnloadingTask::clean_nmethod_postponed(CompiledMethod* nm) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   119
  nm->do_unloading_parallel_postponed();
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
void CodeCacheUnloadingTask::claim_nmethods(CompiledMethod** claimed_nmethods, int *num_claimed_nmethods) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   123
  CompiledMethod* first;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   124
  CompiledMethodIterator last;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   125
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   126
  do {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   127
    *num_claimed_nmethods = 0;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   128
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   129
    first = _claimed_nmethod;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   130
    last = CompiledMethodIterator(first);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   131
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   132
    if (first != NULL) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   133
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   134
      for (int i = 0; i < MaxClaimNmethods; i++) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   135
        if (!last.next_alive()) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   136
          break;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   137
        }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   138
        claimed_nmethods[i] = last.method();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   139
        (*num_claimed_nmethods)++;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   140
      }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   141
    }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   142
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   143
  } while (Atomic::cmpxchg(last.method(), &_claimed_nmethod, first) != first);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   144
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   145
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   146
CompiledMethod* CodeCacheUnloadingTask::claim_postponed_nmethod() {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   147
  CompiledMethod* claim;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   148
  CompiledMethod* next;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   149
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   150
  do {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   151
    claim = _postponed_list;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   152
    if (claim == NULL) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   153
      return NULL;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   154
    }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   155
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   156
    next = claim->unloading_next();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   157
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   158
  } while (Atomic::cmpxchg(next, &_postponed_list, claim) != claim);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   159
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   160
  return claim;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   161
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   162
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   163
void CodeCacheUnloadingTask::barrier_mark(uint worker_id) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   164
  MonitorLockerEx ml(_lock, Mutex::_no_safepoint_check_flag);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   165
  _num_entered_barrier++;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   166
  if (_num_entered_barrier == _num_workers) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   167
    ml.notify_all();
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
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   171
void CodeCacheUnloadingTask::barrier_wait(uint worker_id) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   172
  if (_num_entered_barrier < _num_workers) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   173
    MonitorLockerEx ml(_lock, Mutex::_no_safepoint_check_flag);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   174
    while (_num_entered_barrier < _num_workers) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   175
        ml.wait(Mutex::_no_safepoint_check_flag, 0, false);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   176
    }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   177
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   178
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   179
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   180
void CodeCacheUnloadingTask::work_first_pass(uint worker_id) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   181
  // The first nmethods is claimed by the first worker.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   182
  if (worker_id == 0 && _first_nmethod != NULL) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   183
    clean_nmethod(_first_nmethod);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   184
    _first_nmethod = NULL;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   185
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   186
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   187
  int num_claimed_nmethods;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   188
  CompiledMethod* claimed_nmethods[MaxClaimNmethods];
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   189
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   190
  while (true) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   191
    claim_nmethods(claimed_nmethods, &num_claimed_nmethods);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   192
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   193
    if (num_claimed_nmethods == 0) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   194
      break;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   195
    }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   196
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   197
    for (int i = 0; i < num_claimed_nmethods; i++) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   198
      clean_nmethod(claimed_nmethods[i]);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   199
    }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   200
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   201
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   202
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   203
void CodeCacheUnloadingTask::work_second_pass(uint worker_id) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   204
  CompiledMethod* nm;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   205
  // Take care of postponed nmethods.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   206
  while ((nm = claim_postponed_nmethod()) != NULL) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   207
    clean_nmethod_postponed(nm);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   208
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   209
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   210
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   211
KlassCleaningTask::KlassCleaningTask() :
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   212
  _clean_klass_tree_claimed(0),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   213
  _klass_iterator() {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   214
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   215
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   216
bool KlassCleaningTask::claim_clean_klass_tree_task() {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   217
  if (_clean_klass_tree_claimed) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   218
    return false;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   219
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   220
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   221
  return Atomic::cmpxchg(1, &_clean_klass_tree_claimed, 0) == 0;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   222
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   223
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   224
InstanceKlass* KlassCleaningTask::claim_next_klass() {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   225
  Klass* klass;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   226
  do {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   227
    klass =_klass_iterator.next_klass();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   228
  } while (klass != NULL && !klass->is_instance_klass());
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   229
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   230
  // this can be null so don't call InstanceKlass::cast
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   231
  return static_cast<InstanceKlass*>(klass);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   232
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   233
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   234
void KlassCleaningTask::work() {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   235
  ResourceMark rm;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   236
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   237
  // One worker will clean the subklass/sibling klass tree.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   238
  if (claim_clean_klass_tree_task()) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   239
    Klass::clean_subklass_tree();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   240
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   241
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   242
  // All workers will help cleaning the classes,
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   243
  InstanceKlass* klass;
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   244
  while ((klass = claim_next_klass()) != NULL) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   245
    clean_klass(klass);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   246
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   247
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   248
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   249
ParallelCleaningTask::ParallelCleaningTask(BoolObjectClosure* is_alive,
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   250
  StringDedupUnlinkOrOopsDoClosure* dedup_closure, uint num_workers, bool unloading_occurred) :
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   251
  AbstractGangTask("Parallel Cleaning"),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   252
  _unloading_occurred(unloading_occurred),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   253
  _string_task(is_alive, StringDedup::is_enabled() ? dedup_closure : NULL, true),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   254
  _code_cache_task(num_workers, is_alive, unloading_occurred),
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   255
  _klass_cleaning_task() {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   256
}
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   257
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   258
// The parallel work done by all worker threads.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   259
void ParallelCleaningTask::work(uint worker_id) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   260
    // Do first pass of code cache cleaning.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   261
    _code_cache_task.work_first_pass(worker_id);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   262
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   263
    // Let the threads mark that the first pass is done.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   264
    _code_cache_task.barrier_mark(worker_id);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   265
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   266
    // Clean the Strings and Symbols.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   267
    _string_task.work(worker_id);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   268
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   269
    // Wait for all workers to finish the first code cache cleaning pass.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   270
    _code_cache_task.barrier_wait(worker_id);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   271
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   272
    // Do the second code cache cleaning work, which realize on
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   273
    // the liveness information gathered during the first pass.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   274
    _code_cache_task.work_second_pass(worker_id);
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   275
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   276
  // Clean all klasses that were not unloaded.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   277
  // The weak metadata in klass doesn't need to be
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   278
  // processed if there was no unloading.
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   279
  if (_unloading_occurred) {
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   280
    _klass_cleaning_task.work();
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   281
  }
9d01ad46daef 8209841: [REDO] Refactor G1ParallelCleaningTask into shared
zgu
parents:
diff changeset
   282
}