src/hotspot/share/gc/shared/concurrentGCThread.cpp
author coleenp
Fri, 16 Mar 2018 09:12:13 -0400
changeset 49449 ef5d5d343e2a
parent 47216 71c04702a3d5
child 52302 912b79d983d9
permissions -rw-r--r--
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files Summary: interfaceSupport.hpp is an inline file so moved to interfaceSupport.inline.hpp and stopped including it in .hpp files Reviewed-by: stefank, rehn, kvn
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
/*
36082
e734f3a55bdf 8136854: G1 ConcurrentG1RefineThread::stop delays JVM shutdown for >150ms
tschatzl
parents: 34633
diff changeset
     2
 * Copyright (c) 2001, 2016, 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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
    26
#include "classfile/systemDictionary.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29326
diff changeset
    27
#include "gc/shared/concurrentGCThread.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
    28
#include "oops/instanceRefKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
    29
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
    30
#include "runtime/init.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
    31
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6768
diff changeset
    32
#include "runtime/javaCalls.hpp"
22758
c6b6abb73544 7182040: volano29 limited by os resource on Linux - need better diagnostic message
iklam
parents: 22551
diff changeset
    33
#include "runtime/os.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    34
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 1374
diff changeset
    35
ConcurrentGCThread::ConcurrentGCThread() :
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 1374
diff changeset
    36
  _should_terminate(false), _has_terminated(false) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    37
};
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    38
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    39
void ConcurrentGCThread::create_and_start(ThreadPriority prio) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    40
  if (os::create_thread(this, os::cgc_thread)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    41
    // XXX: need to set this to low priority
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 13738
diff changeset
    42
    // unless "aggressive mode" set; priority
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    43
    // should be just less than that of VMThread.
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    44
    os::set_priority(this, prio);
39984
8ecc78131588 8155263: DisableStartThread should not be applied to GC worker threads
jmasa
parents: 37129
diff changeset
    45
    if (!_should_terminate) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    46
      os::start_thread(this);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    47
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    48
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    49
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    50
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    51
void ConcurrentGCThread::initialize_in_thread() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    52
  this->record_stack_base_and_size();
29326
ebaa169c6dc3 8073464: GC workers do not have thread names
david
parents: 28163
diff changeset
    53
  this->initialize_named_thread();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    54
  this->set_active_handles(JNIHandleBlock::allocate_block());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    55
  // From this time Thread::current() should be working.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    56
  assert(this == Thread::current(), "just checking");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    57
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    58
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    59
void ConcurrentGCThread::wait_for_universe_init() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    60
  MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    61
  while (!is_init_completed() && !_should_terminate) {
36082
e734f3a55bdf 8136854: G1 ConcurrentG1RefineThread::stop delays JVM shutdown for >150ms
tschatzl
parents: 34633
diff changeset
    62
    CGC_lock->wait(Mutex::_no_safepoint_check_flag, 1);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    63
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    64
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    65
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    66
void ConcurrentGCThread::terminate() {
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 33123
diff changeset
    67
  assert(_should_terminate, "Should only be called on terminate request.");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    68
  // Signal that it is terminated
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    69
  {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    70
    MutexLockerEx mu(Terminator_lock,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    71
                     Mutex::_no_safepoint_check_flag);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    72
    _has_terminated = true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    73
    Terminator_lock->notify();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    74
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    75
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    76
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    77
void ConcurrentGCThread::run() {
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    78
  initialize_in_thread();
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    79
  wait_for_universe_init();
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    80
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    81
  run_service();
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    82
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    83
  terminate();
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    84
}
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    85
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    86
void ConcurrentGCThread::stop() {
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    87
  // it is ok to take late safepoints here, if needed
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    88
  {
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    89
    MutexLockerEx mu(Terminator_lock);
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    90
    assert(!_has_terminated,   "stop should only be called once");
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    91
    assert(!_should_terminate, "stop should only be called once");
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    92
    _should_terminate = true;
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    93
  }
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    94
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    95
  stop_service();
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    96
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    97
  {
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    98
    MutexLockerEx mu(Terminator_lock);
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
    99
    while (!_has_terminated) {
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
   100
      Terminator_lock->wait();
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
   101
    }
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
   102
  }
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36082
diff changeset
   103
}