author | dholmes |
Mon, 07 Oct 2019 18:44:53 -0400 | |
changeset 58488 | 165b193b30dd |
parent 53244 | 9807daeb47c4 |
child 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; |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
49 |
ParkEvent * _event; |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
50 |
volatile int _notified; |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
51 |
volatile TStates TState; |
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 |
|
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
56 |
Thread* volatile _owner; // pointer to owning thread |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
57 |
volatile int _recursions; // recursion count, 0 for first entry |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
58 |
QNode* volatile _EntryList; // Threads blocked on entry or reentry. |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
59 |
// The list is actually composed of nodes, |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
60 |
// acting as proxies for Threads. |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
61 |
QNode* volatile _WaitSet; // Threads wait()ing on the monitor |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
62 |
volatile jint _waiters; // number of waiting threads |
6975 | 63 |
int _magic; |
64 |
char * _name; |
|
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 |
||
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
68 |
void SimpleEnter (Thread * Self) ; |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
69 |
void SimpleExit (Thread * Self) ; |
6975 | 70 |
int SimpleWait (Thread * Self, jlong millis) ; |
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
71 |
void SimpleNotify(Thread * Self, bool All) ; |
6975 | 72 |
|
73 |
public: |
|
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
74 |
|
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
75 |
// return codes |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
76 |
enum { |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
77 |
M_OK, // no error |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
78 |
M_ILLEGAL_MONITOR_STATE, // IllegalMonitorStateException |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
79 |
M_INTERRUPTED // Thread.interrupt() |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
80 |
}; |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
81 |
|
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
82 |
// Non-aborting operator new |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
83 |
void* operator new(size_t size) throw() { |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
84 |
return CHeapObj::operator new(size, std::nothrow); |
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 |
|
6975 | 87 |
JvmtiRawMonitor(const char *name); |
88 |
~JvmtiRawMonitor(); |
|
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
89 |
|
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
90 |
Thread * owner() const { return _owner; } |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
91 |
void set_owner(Thread * owner) { _owner = owner; } |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
92 |
int recursions() const { return _recursions; } |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
93 |
void raw_enter(Thread * Self); |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
94 |
int raw_exit(Thread * Self); |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
95 |
int raw_wait(jlong millis, bool interruptable, Thread * Self); |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
96 |
int raw_notify(Thread * Self); |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
97 |
int raw_notifyAll(Thread * Self); |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
98 |
int magic() const { return _magic; } |
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
99 |
const char *get_name() const { return _name; } |
6975 | 100 |
bool is_valid(); |
101 |
}; |
|
102 |
||
103 |
// Onload pending raw monitors |
|
104 |
// Class is used to cache onload or onstart monitor enter |
|
105 |
// which will transition into real monitor when |
|
106 |
// VM is fully initialized. |
|
107 |
class JvmtiPendingMonitors : public AllStatic { |
|
108 |
||
109 |
private: |
|
110 |
static GrowableArray<JvmtiRawMonitor*> *_monitors; // Cache raw monitor enter |
|
111 |
||
112 |
inline static GrowableArray<JvmtiRawMonitor*>* monitors() { return _monitors; } |
|
113 |
||
114 |
static void dispose() { |
|
115 |
delete monitors(); |
|
116 |
} |
|
117 |
||
118 |
public: |
|
119 |
static void enter(JvmtiRawMonitor *monitor) { |
|
120 |
monitors()->append(monitor); |
|
121 |
} |
|
122 |
||
123 |
static int count() { |
|
124 |
return monitors()->length(); |
|
125 |
} |
|
126 |
||
127 |
static void destroy(JvmtiRawMonitor *monitor) { |
|
128 |
while (monitors()->contains(monitor)) { |
|
129 |
monitors()->remove(monitor); |
|
130 |
} |
|
131 |
} |
|
132 |
||
133 |
// Return false if monitor is not found in the list. |
|
134 |
static bool exit(JvmtiRawMonitor *monitor) { |
|
135 |
if (monitors()->contains(monitor)) { |
|
136 |
monitors()->remove(monitor); |
|
137 |
return true; |
|
138 |
} else { |
|
139 |
return false; |
|
140 |
} |
|
141 |
} |
|
142 |
||
143 |
static void transition_raw_monitors(); |
|
144 |
}; |
|
7397 | 145 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
47216
diff
changeset
|
146 |
#endif // SHARE_PRIMS_JVMTIRAWMONITOR_HPP |