src/hotspot/share/prims/jvmtiRawMonitor.cpp
author dholmes
Tue, 17 Sep 2019 19:09:37 -0400
changeset 58196 cea6839598e8
parent 54469 8592226f5cd3
child 58488 165b193b30dd
permissions -rw-r--r--
8230424: Use platform independent code for Thread.interrupt support 8231094: os::sleep in assert message should be changed to JavaThread::sleep Reviewed-by: rehn, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6975
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     1
/*
54469
8592226f5cd3 8221584: SIGSEGV in os::PlatformEvent::unpark() in JvmtiRawMonitor::raw_exit while posting method exit event
dholmes
parents: 51702
diff changeset
     2
 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
6975
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     4
 *
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     8
 *
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    13
 * accompanied this code).
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    14
 *
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    18
 *
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    21
 * questions.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    22
 *
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    23
 */
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
    25
#include "precompiled.hpp"
49360
886acec3b4c6 8199275: Fix inclusions of allocation.inline.hpp
stefank
parents: 48488
diff changeset
    26
#include "memory/allocation.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6975
diff changeset
    27
#include "prims/jvmtiRawMonitor.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 25351
diff changeset
    28
#include "runtime/atomic.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49360
diff changeset
    29
#include "runtime/interfaceSupport.inline.hpp"
50429
83aec1d357d4 8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents: 49449
diff changeset
    30
#include "runtime/orderAccess.hpp"
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 13963
diff changeset
    31
#include "runtime/thread.inline.hpp"
6975
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    32
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    33
GrowableArray<JvmtiRawMonitor*> *JvmtiPendingMonitors::_monitors = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<JvmtiRawMonitor*>(1,true);
6975
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    34
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    35
void JvmtiPendingMonitors::transition_raw_monitors() {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    36
  assert((Threads::number_of_threads()==1),
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    37
         "Java thread has not created yet or more than one java thread \
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    38
is running. Raw monitor transition will not work");
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    39
  JavaThread *current_java_thread = JavaThread::current();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    40
  assert(current_java_thread->thread_state() == _thread_in_vm, "Must be in vm");
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    41
  {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    42
    ThreadBlockInVM __tbivm(current_java_thread);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    43
    for(int i=0; i< count(); i++) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    44
      JvmtiRawMonitor *rmonitor = monitors()->at(i);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    45
      int r = rmonitor->raw_enter(current_java_thread);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    46
      assert(r == ObjectMonitor::OM_OK, "raw_enter should have worked");
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    47
    }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    48
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    49
  // pending monitors are converted to real monitor so delete them all.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    50
  dispose();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    51
}
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    52
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    53
//
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    54
// class JvmtiRawMonitor
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    55
//
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    56
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    57
JvmtiRawMonitor::JvmtiRawMonitor(const char *name) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    58
#ifdef ASSERT
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    59
  _name = strcpy(NEW_C_HEAP_ARRAY(char, strlen(name) + 1, mtInternal), name);
6975
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    60
#else
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    61
  _name = NULL;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    62
#endif
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    63
  _magic = JVMTI_RM_MAGIC;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    64
}
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    65
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    66
JvmtiRawMonitor::~JvmtiRawMonitor() {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    67
#ifdef ASSERT
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    68
  FreeHeap(_name);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    69
#endif
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    70
  _magic = 0;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    71
}
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    72
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    73
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    74
bool
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    75
JvmtiRawMonitor::is_valid() {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    76
  int value = 0;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    77
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    78
  // This object might not be a JvmtiRawMonitor so we can't assume
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    79
  // the _magic field is properly aligned. Get the value in a safe
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    80
  // way and then check against JVMTI_RM_MAGIC.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    81
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    82
  switch (sizeof(_magic)) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    83
  case 2:
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    84
    value = Bytes::get_native_u2((address)&_magic);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    85
    break;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    86
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    87
  case 4:
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    88
    value = Bytes::get_native_u4((address)&_magic);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    89
    break;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    90
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    91
  case 8:
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    92
    value = Bytes::get_native_u8((address)&_magic);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    93
    break;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    94
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    95
  default:
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    96
    guarantee(false, "_magic field is an unexpected size");
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    97
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    98
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
    99
  return value == JVMTI_RM_MAGIC;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   100
}
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   101
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   102
// -------------------------------------------------------------------------
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   103
// The raw monitor subsystem is entirely distinct from normal
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   104
// java-synchronization or jni-synchronization.  raw monitors are not
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   105
// associated with objects.  They can be implemented in any manner
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   106
// that makes sense.  The original implementors decided to piggy-back
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   107
// the raw-monitor implementation on the existing Java objectMonitor mechanism.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   108
// This flaw needs to fixed.  We should reimplement raw monitors as sui-generis.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   109
// Specifically, we should not implement raw monitors via java monitors.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   110
// Time permitting, we should disentangle and deconvolve the two implementations
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   111
// and move the resulting raw monitor implementation over to the JVMTI directories.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   112
// Ideally, the raw monitor implementation would be built on top of
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   113
// park-unpark and nothing else.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   114
//
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   115
// raw monitors are used mainly by JVMTI
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   116
// The raw monitor implementation borrows the ObjectMonitor structure,
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   117
// but the operators are degenerate and extremely simple.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   118
//
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   119
// Mixed use of a single objectMonitor instance -- as both a raw monitor
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   120
// and a normal java monitor -- is not permissible.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   121
//
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   122
// Note that we use the single RawMonitor_lock to protect queue operations for
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   123
// _all_ raw monitors.  This is a scalability impediment, but since raw monitor usage
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   124
// is deprecated and rare, this is not of concern.  The RawMonitor_lock can not
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   125
// be held indefinitely.  The critical sections must be short and bounded.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   126
//
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   127
// -------------------------------------------------------------------------
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   128
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   129
int JvmtiRawMonitor::SimpleEnter (Thread * Self) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   130
  for (;;) {
48488
51825789dd89 8194406: Use Atomic::replace_if_null
kbarrett
parents: 47634
diff changeset
   131
    if (Atomic::replace_if_null(Self, &_owner)) {
6975
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   132
       return OS_OK ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   133
    }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   134
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   135
    ObjectWaiter Node (Self) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   136
    Self->_ParkEvent->reset() ;     // strictly optional
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   137
    Node.TState = ObjectWaiter::TS_ENTER ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   138
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   139
    RawMonitor_lock->lock_without_safepoint_check() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   140
    Node._next  = _EntryList ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   141
    _EntryList  = &Node ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   142
    OrderAccess::fence() ;
48488
51825789dd89 8194406: Use Atomic::replace_if_null
kbarrett
parents: 47634
diff changeset
   143
    if (_owner == NULL && Atomic::replace_if_null(Self, &_owner)) {
6975
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   144
        _EntryList = Node._next ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   145
        RawMonitor_lock->unlock() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   146
        return OS_OK ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   147
    }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   148
    RawMonitor_lock->unlock() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   149
    while (Node.TState == ObjectWaiter::TS_ENTER) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   150
       Self->_ParkEvent->park() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   151
    }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   152
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   153
}
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   154
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   155
int JvmtiRawMonitor::SimpleExit (Thread * Self) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   156
  guarantee (_owner == Self, "invariant") ;
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47216
diff changeset
   157
  OrderAccess::release_store(&_owner, (void*)NULL) ;
6975
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   158
  OrderAccess::fence() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   159
  if (_EntryList == NULL) return OS_OK ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   160
  ObjectWaiter * w ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   161
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   162
  RawMonitor_lock->lock_without_safepoint_check() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   163
  w = _EntryList ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   164
  if (w != NULL) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   165
      _EntryList = w->_next ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   166
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   167
  RawMonitor_lock->unlock() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   168
  if (w != NULL) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   169
      guarantee (w ->TState == ObjectWaiter::TS_ENTER, "invariant") ;
54469
8592226f5cd3 8221584: SIGSEGV in os::PlatformEvent::unpark() in JvmtiRawMonitor::raw_exit while posting method exit event
dholmes
parents: 51702
diff changeset
   170
      // Once we set TState to TS_RUN the waiting thread can complete
8592226f5cd3 8221584: SIGSEGV in os::PlatformEvent::unpark() in JvmtiRawMonitor::raw_exit while posting method exit event
dholmes
parents: 51702
diff changeset
   171
      // SimpleEnter and 'w' is pointing into random stack space. So we have
8592226f5cd3 8221584: SIGSEGV in os::PlatformEvent::unpark() in JvmtiRawMonitor::raw_exit while posting method exit event
dholmes
parents: 51702
diff changeset
   172
      // to ensure we extract the ParkEvent (which is in type-stable memory)
8592226f5cd3 8221584: SIGSEGV in os::PlatformEvent::unpark() in JvmtiRawMonitor::raw_exit while posting method exit event
dholmes
parents: 51702
diff changeset
   173
      // before we set the state, and then don't access 'w'.
6975
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   174
      ParkEvent * ev = w->_event ;
54469
8592226f5cd3 8221584: SIGSEGV in os::PlatformEvent::unpark() in JvmtiRawMonitor::raw_exit while posting method exit event
dholmes
parents: 51702
diff changeset
   175
      OrderAccess::loadstore();
6975
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   176
      w->TState = ObjectWaiter::TS_RUN ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   177
      OrderAccess::fence() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   178
      ev->unpark() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   179
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   180
  return OS_OK ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   181
}
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   182
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   183
int JvmtiRawMonitor::SimpleWait (Thread * Self, jlong millis) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   184
  guarantee (_owner == Self  , "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   185
  guarantee (_recursions == 0, "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   186
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   187
  ObjectWaiter Node (Self) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   188
  Node._notified = 0 ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   189
  Node.TState    = ObjectWaiter::TS_WAIT ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   190
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   191
  RawMonitor_lock->lock_without_safepoint_check() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   192
  Node._next     = _WaitSet ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   193
  _WaitSet       = &Node ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   194
  RawMonitor_lock->unlock() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   195
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   196
  SimpleExit (Self) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   197
  guarantee (_owner != Self, "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   198
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   199
  int ret = OS_OK ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   200
  if (millis <= 0) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   201
    Self->_ParkEvent->park();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   202
  } else {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   203
    ret = Self->_ParkEvent->park(millis);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   204
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   205
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   206
  // If thread still resides on the waitset then unlink it.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   207
  // Double-checked locking -- the usage is safe in this context
54469
8592226f5cd3 8221584: SIGSEGV in os::PlatformEvent::unpark() in JvmtiRawMonitor::raw_exit while posting method exit event
dholmes
parents: 51702
diff changeset
   208
  // as TState is volatile and the lock-unlock operators are
6975
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   209
  // serializing (barrier-equivalent).
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   210
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   211
  if (Node.TState == ObjectWaiter::TS_WAIT) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   212
    RawMonitor_lock->lock_without_safepoint_check() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   213
    if (Node.TState == ObjectWaiter::TS_WAIT) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   214
      // Simple O(n) unlink, but performance isn't critical here.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   215
      ObjectWaiter * p ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   216
      ObjectWaiter * q = NULL ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   217
      for (p = _WaitSet ; p != &Node; p = p->_next) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   218
         q = p ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   219
      }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   220
      guarantee (p == &Node, "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   221
      if (q == NULL) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   222
        guarantee (p == _WaitSet, "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   223
        _WaitSet = p->_next ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   224
      } else {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   225
        guarantee (p == q->_next, "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   226
        q->_next = p->_next ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   227
      }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   228
      Node.TState = ObjectWaiter::TS_RUN ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   229
    }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   230
    RawMonitor_lock->unlock() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   231
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   232
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   233
  guarantee (Node.TState == ObjectWaiter::TS_RUN, "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   234
  SimpleEnter (Self) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   235
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   236
  guarantee (_owner == Self, "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   237
  guarantee (_recursions == 0, "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   238
  return ret ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   239
}
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   240
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   241
int JvmtiRawMonitor::SimpleNotify (Thread * Self, bool All) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   242
  guarantee (_owner == Self, "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   243
  if (_WaitSet == NULL) return OS_OK ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   244
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   245
  // We have two options:
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   246
  // A. Transfer the threads from the WaitSet to the EntryList
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   247
  // B. Remove the thread from the WaitSet and unpark() it.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   248
  //
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   249
  // We use (B), which is crude and results in lots of futile
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   250
  // context switching.  In particular (B) induces lots of contention.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   251
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   252
  ParkEvent * ev = NULL ;       // consider using a small auto array ...
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   253
  RawMonitor_lock->lock_without_safepoint_check() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   254
  for (;;) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   255
      ObjectWaiter * w = _WaitSet ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   256
      if (w == NULL) break ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   257
      _WaitSet = w->_next ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   258
      if (ev != NULL) { ev->unpark(); ev = NULL; }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   259
      ev = w->_event ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   260
      OrderAccess::loadstore() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   261
      w->TState = ObjectWaiter::TS_RUN ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   262
      OrderAccess::storeload();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   263
      if (!All) break ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   264
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   265
  RawMonitor_lock->unlock() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   266
  if (ev != NULL) ev->unpark();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   267
  return OS_OK ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   268
}
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   269
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   270
// Any JavaThread will enter here with state _thread_blocked
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   271
int JvmtiRawMonitor::raw_enter(TRAPS) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   272
  void * Contended ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   273
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   274
  // don't enter raw monitor if thread is being externally suspended, it will
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   275
  // surprise the suspender if a "suspended" thread can still enter monitor
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   276
  JavaThread * jt = (JavaThread *)THREAD;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   277
  if (THREAD->is_Java_thread()) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   278
    jt->SR_lock()->lock_without_safepoint_check();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   279
    while (jt->is_external_suspend()) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   280
      jt->SR_lock()->unlock();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   281
      jt->java_suspend_self();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   282
      jt->SR_lock()->lock_without_safepoint_check();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   283
    }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   284
    // guarded by SR_lock to avoid racing with new external suspend requests.
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47216
diff changeset
   285
    Contended = Atomic::cmpxchg(THREAD, &_owner, (void*)NULL);
6975
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   286
    jt->SR_lock()->unlock();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   287
  } else {
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47216
diff changeset
   288
    Contended = Atomic::cmpxchg(THREAD, &_owner, (void*)NULL);
6975
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   289
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   290
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   291
  if (Contended == THREAD) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   292
     _recursions ++ ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   293
     return OM_OK ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   294
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   295
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   296
  if (Contended == NULL) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   297
     guarantee (_owner == THREAD, "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   298
     guarantee (_recursions == 0, "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   299
     return OM_OK ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   300
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   301
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   302
  THREAD->set_current_pending_monitor(this);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   303
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   304
  if (!THREAD->is_Java_thread()) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   305
     // No other non-Java threads besides VM thread would acquire
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   306
     // a raw monitor.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   307
     assert(THREAD->is_VM_thread(), "must be VM thread");
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   308
     SimpleEnter (THREAD) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   309
   } else {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   310
     guarantee (jt->thread_state() == _thread_blocked, "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   311
     for (;;) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   312
       jt->set_suspend_equivalent();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   313
       // cleared by handle_special_suspend_equivalent_condition() or
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   314
       // java_suspend_self()
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   315
       SimpleEnter (THREAD) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   316
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   317
       // were we externally suspended while we were waiting?
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   318
       if (!jt->handle_special_suspend_equivalent_condition()) break ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   319
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   320
       // This thread was externally suspended
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   321
       //
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   322
       // This logic isn't needed for JVMTI raw monitors,
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   323
       // but doesn't hurt just in case the suspend rules change. This
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   324
           // logic is needed for the JvmtiRawMonitor.wait() reentry phase.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   325
           // We have reentered the contended monitor, but while we were
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   326
           // waiting another thread suspended us. We don't want to reenter
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   327
           // the monitor while suspended because that would surprise the
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   328
           // thread that suspended us.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   329
           //
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   330
           // Drop the lock -
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   331
       SimpleExit (THREAD) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   332
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   333
           jt->java_suspend_self();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   334
         }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   335
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   336
     assert(_owner == THREAD, "Fatal error with monitor owner!");
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   337
     assert(_recursions == 0, "Fatal error with monitor recursions!");
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   338
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   339
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   340
  THREAD->set_current_pending_monitor(NULL);
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   341
  guarantee (_recursions == 0, "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   342
  return OM_OK;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   343
}
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   344
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   345
// Used mainly for JVMTI raw monitor implementation
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   346
// Also used for JvmtiRawMonitor::wait().
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   347
int JvmtiRawMonitor::raw_exit(TRAPS) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   348
  if (THREAD != _owner) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   349
    return OM_ILLEGAL_MONITOR_STATE;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   350
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   351
  if (_recursions > 0) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   352
    --_recursions ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   353
    return OM_OK ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   354
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   355
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   356
  void * List = _EntryList ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   357
  SimpleExit (THREAD) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   358
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   359
  return OM_OK;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   360
}
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   361
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   362
// Used for JVMTI raw monitor implementation.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   363
// All JavaThreads will enter here with state _thread_blocked
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   364
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   365
int JvmtiRawMonitor::raw_wait(jlong millis, bool interruptible, TRAPS) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   366
  if (THREAD != _owner) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   367
    return OM_ILLEGAL_MONITOR_STATE;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   368
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   369
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   370
  // To avoid spurious wakeups we reset the parkevent -- This is strictly optional.
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   371
  // The caller must be able to tolerate spurious returns from raw_wait().
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   372
  THREAD->_ParkEvent->reset() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   373
  OrderAccess::fence() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   374
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   375
  // check interrupt event
58196
cea6839598e8 8230424: Use platform independent code for Thread.interrupt support
dholmes
parents: 54469
diff changeset
   376
  if (interruptible) {
cea6839598e8 8230424: Use platform independent code for Thread.interrupt support
dholmes
parents: 54469
diff changeset
   377
    assert(THREAD->is_Java_thread(), "Only JavaThreads can be interruptible");
cea6839598e8 8230424: Use platform independent code for Thread.interrupt support
dholmes
parents: 54469
diff changeset
   378
    JavaThread* jt = (JavaThread*) THREAD;
cea6839598e8 8230424: Use platform independent code for Thread.interrupt support
dholmes
parents: 54469
diff changeset
   379
    if (jt->is_interrupted(true)) {
cea6839598e8 8230424: Use platform independent code for Thread.interrupt support
dholmes
parents: 54469
diff changeset
   380
      return OM_INTERRUPTED;
cea6839598e8 8230424: Use platform independent code for Thread.interrupt support
dholmes
parents: 54469
diff changeset
   381
    }
6975
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   382
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   383
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   384
  intptr_t save = _recursions ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   385
  _recursions = 0 ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   386
  _waiters ++ ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   387
  if (THREAD->is_Java_thread()) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   388
    guarantee (((JavaThread *) THREAD)->thread_state() == _thread_blocked, "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   389
    ((JavaThread *)THREAD)->set_suspend_equivalent();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   390
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   391
  int rv = SimpleWait (THREAD, millis) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   392
  _recursions = save ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   393
  _waiters -- ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   394
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   395
  guarantee (THREAD == _owner, "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   396
  if (THREAD->is_Java_thread()) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   397
     JavaThread * jSelf = (JavaThread *) THREAD ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   398
     for (;;) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   399
        if (!jSelf->handle_special_suspend_equivalent_condition()) break ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   400
        SimpleExit (THREAD) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   401
        jSelf->java_suspend_self();
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   402
        SimpleEnter (THREAD) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   403
        jSelf->set_suspend_equivalent() ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   404
     }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   405
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   406
  guarantee (THREAD == _owner, "invariant") ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   407
58196
cea6839598e8 8230424: Use platform independent code for Thread.interrupt support
dholmes
parents: 54469
diff changeset
   408
  if (interruptible) {
cea6839598e8 8230424: Use platform independent code for Thread.interrupt support
dholmes
parents: 54469
diff changeset
   409
    JavaThread* jt = (JavaThread*) THREAD;
cea6839598e8 8230424: Use platform independent code for Thread.interrupt support
dholmes
parents: 54469
diff changeset
   410
    if (jt->is_interrupted(true)) {
cea6839598e8 8230424: Use platform independent code for Thread.interrupt support
dholmes
parents: 54469
diff changeset
   411
      return OM_INTERRUPTED;
cea6839598e8 8230424: Use platform independent code for Thread.interrupt support
dholmes
parents: 54469
diff changeset
   412
    }
6975
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   413
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   414
  return OM_OK ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   415
}
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   416
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   417
int JvmtiRawMonitor::raw_notify(TRAPS) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   418
  if (THREAD != _owner) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   419
    return OM_ILLEGAL_MONITOR_STATE;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   420
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   421
  SimpleNotify (THREAD, false) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   422
  return OM_OK;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   423
}
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   424
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   425
int JvmtiRawMonitor::raw_notifyAll(TRAPS) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   426
  if (THREAD != _owner) {
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   427
    return OM_ILLEGAL_MONITOR_STATE;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   428
  }
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   429
  SimpleNotify (THREAD, true) ;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   430
  return OM_OK;
dc9b63952682 6988353: refactor contended sync subsystem
acorn
parents:
diff changeset
   431
}