src/hotspot/share/gc/shared/concurrentGCThread.cpp
author stefank
Mon, 25 Nov 2019 12:22:13 +0100
changeset 59247 56bf71d64d51
parent 54623 1126f0607c70
child 59290 97d13893ec3c
permissions -rw-r--r--
8234562: Move OrderAccess::release_store*/load_acquire to Atomic Reviewed-by: rehn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     1
/*
54301
2f522c487791 8221392: Reduce ConcurrentGCThreads spinning during start up
pliden
parents: 53103
diff changeset
     2
 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     4
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     8
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    13
 * accompanied this code).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    14
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    21
 * questions.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    22
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    23
 */
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29326
diff changeset
    26
#include "gc/shared/concurrentGCThread.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
    27
#include "runtime/init.hpp"
54329
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    28
#include "runtime/mutexLocker.hpp"
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    29
#include "runtime/orderAccess.hpp"
22758
c6b6abb73544 7182040: volano29 limited by os resource on Linux - need better diagnostic message
iklam
parents: 22551
diff changeset
    30
#include "runtime/os.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    31
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 1374
diff changeset
    32
ConcurrentGCThread::ConcurrentGCThread() :
54329
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    33
    _should_terminate(false),
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    34
    _has_terminated(false) {}
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    35
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    36
void ConcurrentGCThread::create_and_start(ThreadPriority prio) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    37
  if (os::create_thread(this, os::cgc_thread)) {
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    38
    os::set_priority(this, prio);
54329
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    39
    os::start_thread(this);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    40
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    41
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    42
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    43
void ConcurrentGCThread::run() {
54329
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    44
  // Setup handle area
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    45
  set_active_handles(JNIHandleBlock::allocate_block());
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    46
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    47
  // Wait for initialization to complete
54301
2f522c487791 8221392: Reduce ConcurrentGCThreads spinning during start up
pliden
parents: 53103
diff changeset
    48
  wait_init_completed();
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    49
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    50
  run_service();
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    51
54329
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    52
  // Signal thread has terminated
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54329
diff changeset
    53
  MonitorLocker ml(Terminator_lock);
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54623
diff changeset
    54
  Atomic::release_store(&_has_terminated, true);
54329
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    55
  ml.notify_all();
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    56
}
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    57
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    58
void ConcurrentGCThread::stop() {
54329
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    59
  assert(!should_terminate(), "Invalid state");
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    60
  assert(!has_terminated(), "Invalid state");
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    61
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    62
  // Signal thread to terminate
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54623
diff changeset
    63
  Atomic::release_store_fence(&_should_terminate, true);
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    64
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    65
  stop_service();
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    66
54329
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    67
  // Wait for thread to terminate
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54329
diff changeset
    68
  MonitorLocker ml(Terminator_lock);
54329
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    69
  while (!_has_terminated) {
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    70
    ml.wait();
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    71
  }
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    72
}
54329
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    73
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    74
bool ConcurrentGCThread::should_terminate() const {
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54623
diff changeset
    75
  return Atomic::load_acquire(&_should_terminate);
54329
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    76
}
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    77
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    78
bool ConcurrentGCThread::has_terminated() const {
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 54623
diff changeset
    79
  return Atomic::load_acquire(&_has_terminated);
54329
ddd60ad787d4 8221394: Clean up ConcurrentGCThread
pliden
parents: 54301
diff changeset
    80
}