src/hotspot/share/gc/shared/barrierSet.cpp
author eosterlund
Tue, 16 Oct 2018 13:18:22 +0200
changeset 52142 ca0c25e01c5b
parent 51600 56309b1b9d9b
child 52955 f0f3dc30e3bb
permissions -rw-r--r--
8210498: nmethod entry barriers Reviewed-by: kvn, pliden
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
/*
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 47998
diff changeset
     2
 * Copyright (c) 1997, 2018, 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: 4461
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4461
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: 4461
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: 5547
diff changeset
    25
#include "precompiled.hpp"
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 47998
diff changeset
    26
#include "gc/shared/barrierSet.hpp"
49748
6a880e576856 8199417: Modularize interpreter GC barriers
eosterlund
parents: 49484
diff changeset
    27
#include "gc/shared/barrierSetAssembler.hpp"
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49748
diff changeset
    28
#include "runtime/thread.hpp"
49748
6a880e576856 8199417: Modularize interpreter GC barriers
eosterlund
parents: 49484
diff changeset
    29
#include "utilities/macros.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    30
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49748
diff changeset
    31
BarrierSet* BarrierSet::_barrier_set = NULL;
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49748
diff changeset
    32
51600
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    33
class SetBarrierSetNonJavaThread : public ThreadClosure {
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    34
  BarrierSet* _barrier_set;
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    35
  size_t _count;
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    36
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    37
public:
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    38
  SetBarrierSetNonJavaThread(BarrierSet* barrier_set) :
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    39
    _barrier_set(barrier_set), _count(0) {}
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    40
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    41
  virtual void do_thread(Thread* thread) {
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    42
    _barrier_set->on_thread_create(thread);
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    43
    ++_count;
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    44
  }
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    45
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    46
  size_t count() const { return _count; }
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    47
};
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    48
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49748
diff changeset
    49
void BarrierSet::set_barrier_set(BarrierSet* barrier_set) {
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49748
diff changeset
    50
  assert(_barrier_set == NULL, "Already initialized");
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49748
diff changeset
    51
  _barrier_set = barrier_set;
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49748
diff changeset
    52
51600
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    53
  // Some threads are created before the barrier set, so the call to
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    54
  // BarrierSet::on_thread_create had to be deferred for them.  Now that
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    55
  // we have the barrier set, do those deferred calls.
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    56
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    57
  // First do any non-JavaThreads.
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    58
  SetBarrierSetNonJavaThread njt_closure(_barrier_set);
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    59
  Threads::non_java_threads_do(&njt_closure);
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    60
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    61
  // Do the current (main) thread.  Ensure it's the one and only
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    62
  // JavaThread so far.  Also verify that it isn't yet on the thread
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    63
  // list, else we'd also need to call BarrierSet::on_thread_attach.
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    64
  assert(Thread::current()->is_Java_thread(),
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    65
         "Expected main thread to be a JavaThread");
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    66
  assert((njt_closure.count() + 1) == Threads::threads_before_barrier_set(),
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    67
         "Unexpected JavaThreads before barrier set initialization: "
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    68
         "Non-JavaThreads: " SIZE_FORMAT ", all: " SIZE_FORMAT,
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    69
         njt_closure.count(), Threads::threads_before_barrier_set());
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    70
  assert(!JavaThread::current()->on_thread_list(),
56309b1b9d9b 8209975: Some GCThreadLocalData not initialized
kbarrett
parents: 49752
diff changeset
    71
         "Main thread already on thread list.");
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49748
diff changeset
    72
  _barrier_set->on_thread_create(Thread::current());
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49748
diff changeset
    73
}
49748
6a880e576856 8199417: Modularize interpreter GC barriers
eosterlund
parents: 49484
diff changeset
    74
6a880e576856 8199417: Modularize interpreter GC barriers
eosterlund
parents: 49484
diff changeset
    75
// Called from init.cpp
6a880e576856 8199417: Modularize interpreter GC barriers
eosterlund
parents: 49484
diff changeset
    76
void gc_barrier_stubs_init() {
6a880e576856 8199417: Modularize interpreter GC barriers
eosterlund
parents: 49484
diff changeset
    77
  BarrierSet* bs = BarrierSet::barrier_set();
6a880e576856 8199417: Modularize interpreter GC barriers
eosterlund
parents: 49484
diff changeset
    78
#ifndef ZERO
6a880e576856 8199417: Modularize interpreter GC barriers
eosterlund
parents: 49484
diff changeset
    79
  BarrierSetAssembler* bs_assembler = bs->barrier_set_assembler();
6a880e576856 8199417: Modularize interpreter GC barriers
eosterlund
parents: 49484
diff changeset
    80
  bs_assembler->barrier_stubs_init();
6a880e576856 8199417: Modularize interpreter GC barriers
eosterlund
parents: 49484
diff changeset
    81
#endif
6a880e576856 8199417: Modularize interpreter GC barriers
eosterlund
parents: 49484
diff changeset
    82
}