src/hotspot/share/utilities/globalCounter.inline.hpp
author stefank
Tue, 26 Nov 2019 10:47:46 +0100
changeset 59290 97d13893ec3c
parent 59247 56bf71d64d51
permissions -rw-r--r--
8234748: Clean up atomic and orderAccess includes Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49800
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52332
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
49800
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
     4
 *
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
     8
 *
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    13
 * accompanied this code).
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    14
 *
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    18
 *
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    21
 * questions.
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    22
 *
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    23
 */
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52332
diff changeset
    25
#ifndef SHARE_UTILITIES_GLOBALCOUNTER_INLINE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52332
diff changeset
    26
#define SHARE_UTILITIES_GLOBALCOUNTER_INLINE_HPP
49800
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    27
52332
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    28
#include "runtime/atomic.hpp"
49812
0c2ceb50783e 8201799: Build failures after JDK-8195099 (Concurrent safe-memory-reclamation mechanism)
shade
parents: 49800
diff changeset
    29
#include "runtime/thread.inline.hpp"
49800
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    30
#include "utilities/globalCounter.hpp"
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    31
52332
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    32
inline GlobalCounter::CSContext
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    33
GlobalCounter::critical_section_begin(Thread *thread) {
49800
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    34
  assert(thread == Thread::current(), "must be current thread");
52332
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    35
  uintx old_cnt = Atomic::load(thread->get_rcu_counter());
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    36
  // Retain the old counter value if already active, e.g. nested.
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    37
  // Otherwise, set the counter to the current version + active bit.
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    38
  uintx new_cnt = old_cnt;
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    39
  if ((new_cnt & COUNTER_ACTIVE) == 0) {
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    40
    new_cnt = Atomic::load(&_global_counter._counter) | COUNTER_ACTIVE;
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    41
  }
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
    42
  Atomic::release_store_fence(thread->get_rcu_counter(), new_cnt);
52332
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    43
  return static_cast<CSContext>(old_cnt);
49800
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    44
}
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    45
52332
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    46
inline void
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    47
GlobalCounter::critical_section_end(Thread *thread, CSContext context) {
49800
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    48
  assert(thread == Thread::current(), "must be current thread");
51511
eb8d5aeabab3 8209850: Allow NamedThreads to use GlobalCounter critical sections
kbarrett
parents: 50429
diff changeset
    49
  assert((*thread->get_rcu_counter() & COUNTER_ACTIVE) == COUNTER_ACTIVE, "must be in critical section");
52332
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    50
  // Restore the counter value from before the associated begin.
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
    51
  Atomic::release_store(thread->get_rcu_counter(),
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
    52
                        static_cast<uintx>(context));
49800
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    53
}
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    54
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    55
class GlobalCounter::CriticalSection {
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    56
 private:
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    57
  Thread* _thread;
52332
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    58
  CSContext _context;
49800
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    59
 public:
52332
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    60
  inline CriticalSection(Thread* thread) :
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    61
    _thread(thread),
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    62
    _context(GlobalCounter::critical_section_begin(_thread))
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    63
  {}
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    64
49800
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    65
  inline  ~CriticalSection() {
52332
d2a3503c72f7 8212827: GlobalCounter should support nested critical sections
kbarrett
parents: 51548
diff changeset
    66
    GlobalCounter::critical_section_end(_thread, _context);
49800
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    67
  }
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    68
};
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    69
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52332
diff changeset
    70
#endif // SHARE_UTILITIES_GLOBALCOUNTER_INLINE_HPP