src/hotspot/share/gc/shared/weakProcessor.cpp
author kbarrett
Tue, 28 Aug 2018 12:57:40 -0400
changeset 51546 b9f6a4427da9
parent 50297 580744d900c8
child 53536 482109fae02b
permissions -rw-r--r--
8072498: Multi-thread JNI weak reference processing Summary: Add parallel processing support to WeakProcessor. Reviewed-by: tschatzl, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47648
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
     1
/*
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47779
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
47648
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
     4
 *
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
     7
 * published by the Free Software Foundation.
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
     8
 *
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    13
 * accompanied this code).
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    14
 *
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    18
 *
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    21
 * questions.
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    22
 *
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    23
 */
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    24
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    25
#include "precompiled.hpp"
50297
580744d900c8 8202813: Move vm_weak processing from SystemDictionary to WeakProcessor
coleenp
parents: 50113
diff changeset
    26
#include "gc/shared/oopStorage.inline.hpp"
51546
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    27
#include "gc/shared/oopStorageParState.inline.hpp"
47648
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    28
#include "gc/shared/weakProcessor.hpp"
51546
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    29
#include "gc/shared/weakProcessor.inline.hpp"
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    30
#include "gc/shared/weakProcessorPhases.hpp"
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    31
#include "gc/shared/weakProcessorPhaseTimes.hpp"
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    32
#include "memory/allocation.inline.hpp"
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    33
#include "memory/iterator.hpp"
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    34
#include "runtime/globals.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 47779
diff changeset
    35
#include "utilities/macros.hpp"
47648
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    36
47676
b1c020fc35a3 8189748: More precise closures for WeakProcessor::weak_oops_do calls
stefank
parents: 47649
diff changeset
    37
void WeakProcessor::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive) {
51546
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    38
  FOR_EACH_WEAK_PROCESSOR_PHASE(phase) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    39
    if (WeakProcessorPhases::is_serial(phase)) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    40
      WeakProcessorPhases::processor(phase)(is_alive, keep_alive);
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    41
    } else {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    42
      WeakProcessorPhases::oop_storage(phase)->weak_oops_do(is_alive, keep_alive);
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    43
    }
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    44
  }
47648
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    45
}
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    46
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    47
void WeakProcessor::oops_do(OopClosure* closure) {
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    48
  AlwaysTrueClosure always_true;
47676
b1c020fc35a3 8189748: More precise closures for WeakProcessor::weak_oops_do calls
stefank
parents: 47649
diff changeset
    49
  weak_oops_do(&always_true, closure);
47648
226b1fc611b9 8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff changeset
    50
}
51546
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    51
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    52
uint WeakProcessor::ergo_workers(uint max_workers) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    53
  // Ignore ParallelRefProcEnabled; that's for j.l.r.Reference processing.
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    54
  if (ReferencesPerThread == 0) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    55
    // Configuration says always use all the threads.
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    56
    return max_workers;
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    57
  }
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    58
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    59
  // One thread per ReferencesPerThread references (or fraction thereof)
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    60
  // in the various OopStorage objects, bounded by max_threads.
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    61
  //
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    62
  // Serial phases are ignored in this calculation, because of the
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    63
  // cost of running unnecessary threads.  These phases are normally
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    64
  // small or empty (assuming they are configured to exist at all),
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    65
  // and development oriented, so not allocating any threads
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    66
  // specifically for them is okay.
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    67
  size_t ref_count = 0;
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    68
  FOR_EACH_WEAK_PROCESSOR_OOP_STORAGE_PHASE(phase) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    69
    ref_count += WeakProcessorPhases::oop_storage(phase)->allocation_count();
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    70
  }
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    71
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    72
  // +1 to (approx) round up the ref per thread division.
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    73
  size_t nworkers = 1 + (ref_count / ReferencesPerThread);
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    74
  nworkers = MIN2(nworkers, static_cast<size_t>(max_workers));
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    75
  return static_cast<uint>(nworkers);
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    76
}
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    77
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    78
void WeakProcessor::Task::initialize() {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    79
  assert(_nworkers != 0, "must be");
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    80
  assert(_phase_times == NULL || _nworkers <= _phase_times->max_threads(),
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    81
         "nworkers (%u) exceeds max threads (%u)",
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    82
         _nworkers, _phase_times->max_threads());
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    83
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    84
  if (_phase_times) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    85
    _phase_times->set_active_workers(_nworkers);
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    86
  }
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    87
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    88
  uint storage_count = WeakProcessorPhases::oop_storage_phase_count;
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    89
  _storage_states = NEW_C_HEAP_ARRAY(StorageState, storage_count, mtGC);
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    90
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    91
  StorageState* states = _storage_states;
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    92
  FOR_EACH_WEAK_PROCESSOR_OOP_STORAGE_PHASE(phase) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    93
    OopStorage* storage = WeakProcessorPhases::oop_storage(phase);
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    94
    new (states++) StorageState(storage, _nworkers);
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    95
  }
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    96
}
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    97
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    98
WeakProcessor::Task::Task(uint nworkers) :
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
    99
  _phase_times(NULL),
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   100
  _nworkers(nworkers),
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   101
  _serial_phases_done(WeakProcessorPhases::serial_phase_count),
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   102
  _storage_states(NULL)
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   103
{
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   104
  initialize();
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   105
}
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   106
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   107
WeakProcessor::Task::Task(WeakProcessorPhaseTimes* phase_times, uint nworkers) :
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   108
  _phase_times(phase_times),
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   109
  _nworkers(nworkers),
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   110
  _serial_phases_done(WeakProcessorPhases::serial_phase_count),
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   111
  _storage_states(NULL)
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   112
{
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   113
  initialize();
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   114
}
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   115
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   116
WeakProcessor::Task::~Task() {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   117
  if (_storage_states != NULL) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   118
    StorageState* states = _storage_states;
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   119
    FOR_EACH_WEAK_PROCESSOR_OOP_STORAGE_PHASE(phase) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   120
      states->StorageState::~StorageState();
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   121
      ++states;
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   122
    }
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   123
    FREE_C_HEAP_ARRAY(StorageState, _storage_states);
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   124
  }
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   125
}
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   126
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   127
void WeakProcessor::GangTask::work(uint worker_id) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   128
  _erased_do_work(this, worker_id);
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents: 50297
diff changeset
   129
}