src/hotspot/share/utilities/globalCounter.inline.hpp
author coleenp
Wed, 06 Jun 2018 10:45:40 -0400
changeset 50429 83aec1d357d4
parent 49812 0c2ceb50783e
child 51511 eb8d5aeabab3
permissions -rw-r--r--
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files Summary: move orderAccess.inline.hpp into orderAccess.hpp and remove os.hpp inclusion and conditional os::is_MP() for fence on x86 platforms Reviewed-by: dholmes, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49800
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
     1
/*
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
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
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    25
#ifndef SHARE_UTILITIES_GLOBAL_COUNTER_INLINE_HPP
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    26
#define SHARE_UTILITIES_GLOBAL_COUNTER_INLINE_HPP
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    27
50429
83aec1d357d4 8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents: 49812
diff changeset
    28
#include "runtime/orderAccess.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
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    32
inline void GlobalCounter::critical_section_begin(Thread *thread) {
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    33
  assert(thread == Thread::current(), "must be current thread");
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    34
  assert(thread->is_VM_thread() || thread->is_Java_thread(), "must be VMThread or JavaThread");
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    35
  assert((*thread->get_rcu_counter() & COUNTER_ACTIVE) == 0x0, "nestled critical sections, not supported yet");
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    36
  uintx gbl_cnt = OrderAccess::load_acquire(&_global_counter._counter);
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    37
  OrderAccess::release_store_fence(thread->get_rcu_counter(), gbl_cnt | COUNTER_ACTIVE);
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    38
}
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    39
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    40
inline void GlobalCounter::critical_section_end(Thread *thread) {
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    41
  assert(thread == Thread::current(), "must be current thread");
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    42
  assert(thread->is_VM_thread() || thread->is_Java_thread(), "must be VMThread or JavaThread");
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    43
  assert((*thread->get_rcu_counter() & COUNTER_ACTIVE) == COUNTER_ACTIVE, "must be in ctitical section");
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    44
  // Mainly for debugging we set it to 'now'.
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    45
  uintx gbl_cnt = OrderAccess::load_acquire(&_global_counter._counter);
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    46
  OrderAccess::release_store(thread->get_rcu_counter(), gbl_cnt);
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    47
}
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    48
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    49
class GlobalCounter::CriticalSection {
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    50
 private:
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    51
  Thread* _thread;
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    52
 public:
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    53
  inline CriticalSection(Thread* thread) : _thread(thread) {
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    54
    GlobalCounter::critical_section_begin(_thread);
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    55
  }
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    56
  inline  ~CriticalSection() {
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    57
    GlobalCounter::critical_section_end(_thread);
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    58
  }
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    59
};
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    60
69d7398038c5 8195099: Concurrent safe-memory-reclamation mechanism
rehn
parents:
diff changeset
    61
#endif // include guard