author | dholmes |
Thu, 14 Nov 2019 22:36:40 -0500 | |
changeset 59105 | 76ae9aa0e794 |
parent 58509 | 7b41c88f8432 |
permissions | -rw-r--r-- |
6975 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. |
6975 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
47216
diff
changeset
|
25 |
#ifndef SHARE_PRIMS_JVMTIRAWMONITOR_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
47216
diff
changeset
|
26 |
#define SHARE_PRIMS_JVMTIRAWMONITOR_HPP |
7397 | 27 |
|
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
28 |
#include "memory/allocation.hpp" |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
29 |
#include "runtime/park.hpp" |
7397 | 30 |
#include "utilities/growableArray.hpp" |
31 |
||
6975 | 32 |
// |
33 |
// class JvmtiRawMonitor |
|
34 |
// |
|
35 |
// Used by JVMTI methods: All RawMonitor methods (CreateRawMonitor, EnterRawMonitor, etc.) |
|
36 |
// |
|
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
37 |
// A simplified version of the ObjectMonitor code. |
6975 | 38 |
// |
39 |
||
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
40 |
class JvmtiRawMonitor : public CHeapObj<mtSynchronizer> { |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
41 |
|
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
42 |
// Helper class to allow Threads to be linked into queues. |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
43 |
// This is a stripped down version of ObjectWaiter. |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
44 |
class QNode : public StackObj { |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
45 |
friend class JvmtiRawMonitor; |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
46 |
enum TStates { TS_READY, TS_RUN, TS_WAIT, TS_ENTER }; |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
47 |
QNode* volatile _next; |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
48 |
QNode* volatile _prev; |
58509 | 49 |
ParkEvent* _event; |
50 |
volatile int _notified; |
|
51 |
volatile TStates _t_state; |
|
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
52 |
|
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
53 |
QNode(Thread* thread); |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
54 |
}; |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
55 |
|
58509 | 56 |
Thread* volatile _owner; // pointer to owning thread |
57 |
volatile int _recursions; // recursion count, 0 for first entry |
|
58 |
QNode* volatile _entry_list; // Threads blocked on entry or reentry. |
|
59 |
// The list is actually composed of nodes, |
|
60 |
// acting as proxies for Threads. |
|
61 |
QNode* volatile _wait_set; // Threads wait()ing on the monitor |
|
62 |
volatile jint _waiters; // number of waiting threads |
|
63 |
int _magic; |
|
64 |
char* _name; |
|
6975 | 65 |
// JVMTI_RM_MAGIC is set in contructor and unset in destructor. |
66 |
enum { JVMTI_RM_MAGIC = (int)(('T' << 24) | ('I' << 16) | ('R' << 8) | 'M') }; |
|
67 |
||
59105
76ae9aa0e794
8233549: Thread interrupted state must only be accessed when not in a safepoint-safe state
dholmes
parents:
58509
diff
changeset
|
68 |
// Helpers for queue management isolation |
76ae9aa0e794
8233549: Thread interrupted state must only be accessed when not in a safepoint-safe state
dholmes
parents:
58509
diff
changeset
|
69 |
void enqueue_waiter(QNode& node); |
76ae9aa0e794
8233549: Thread interrupted state must only be accessed when not in a safepoint-safe state
dholmes
parents:
58509
diff
changeset
|
70 |
void dequeue_waiter(QNode& node); |
76ae9aa0e794
8233549: Thread interrupted state must only be accessed when not in a safepoint-safe state
dholmes
parents:
58509
diff
changeset
|
71 |
|
76ae9aa0e794
8233549: Thread interrupted state must only be accessed when not in a safepoint-safe state
dholmes
parents:
58509
diff
changeset
|
72 |
// Mostly low-level implementation routines |
58509 | 73 |
void simple_enter(Thread* self); |
74 |
void simple_exit(Thread* self); |
|
75 |
int simple_wait(Thread* self, jlong millis); |
|
76 |
void simple_notify(Thread* self, bool all); |
|
6975 | 77 |
|
58509 | 78 |
public: |
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
79 |
|
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
80 |
// return codes |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
81 |
enum { |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
82 |
M_OK, // no error |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
83 |
M_ILLEGAL_MONITOR_STATE, // IllegalMonitorStateException |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
84 |
M_INTERRUPTED // Thread.interrupt() |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
85 |
}; |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
86 |
|
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
87 |
// Non-aborting operator new |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
88 |
void* operator new(size_t size) throw() { |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
89 |
return CHeapObj::operator new(size, std::nothrow); |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
90 |
} |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
91 |
|
58509 | 92 |
JvmtiRawMonitor(const char* name); |
6975 | 93 |
~JvmtiRawMonitor(); |
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
94 |
|
58509 | 95 |
Thread* owner() const { return _owner; } |
96 |
void set_owner(Thread* owner) { _owner = owner; } |
|
97 |
int recursions() const { return _recursions; } |
|
98 |
void raw_enter(Thread* self); |
|
99 |
int raw_exit(Thread* self); |
|
59105
76ae9aa0e794
8233549: Thread interrupted state must only be accessed when not in a safepoint-safe state
dholmes
parents:
58509
diff
changeset
|
100 |
int raw_wait(jlong millis, Thread* self); |
58509 | 101 |
int raw_notify(Thread* self); |
102 |
int raw_notifyAll(Thread* self); |
|
103 |
int magic() const { return _magic; } |
|
104 |
const char* get_name() const { return _name; } |
|
105 |
bool is_valid(); |
|
6975 | 106 |
}; |
107 |
||
108 |
// Onload pending raw monitors |
|
109 |
// Class is used to cache onload or onstart monitor enter |
|
110 |
// which will transition into real monitor when |
|
111 |
// VM is fully initialized. |
|
112 |
class JvmtiPendingMonitors : public AllStatic { |
|
113 |
||
58509 | 114 |
private: |
115 |
static GrowableArray<JvmtiRawMonitor*>* _monitors; // Cache raw monitor enter |
|
6975 | 116 |
|
117 |
inline static GrowableArray<JvmtiRawMonitor*>* monitors() { return _monitors; } |
|
118 |
||
119 |
static void dispose() { |
|
120 |
delete monitors(); |
|
121 |
} |
|
122 |
||
58509 | 123 |
public: |
124 |
static void enter(JvmtiRawMonitor* monitor) { |
|
6975 | 125 |
monitors()->append(monitor); |
126 |
} |
|
127 |
||
128 |
static int count() { |
|
129 |
return monitors()->length(); |
|
130 |
} |
|
131 |
||
58509 | 132 |
static void destroy(JvmtiRawMonitor* monitor) { |
6975 | 133 |
while (monitors()->contains(monitor)) { |
134 |
monitors()->remove(monitor); |
|
135 |
} |
|
136 |
} |
|
137 |
||
138 |
// Return false if monitor is not found in the list. |
|
58509 | 139 |
static bool exit(JvmtiRawMonitor* monitor) { |
6975 | 140 |
if (monitors()->contains(monitor)) { |
141 |
monitors()->remove(monitor); |
|
142 |
return true; |
|
143 |
} else { |
|
144 |
return false; |
|
145 |
} |
|
146 |
} |
|
147 |
||
148 |
static void transition_raw_monitors(); |
|
149 |
}; |
|
7397 | 150 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
47216
diff
changeset
|
151 |
#endif // SHARE_PRIMS_JVMTIRAWMONITOR_HPP |