author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
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 |
||
58509 | 68 |
void simple_enter(Thread* self); |
69 |
void simple_exit(Thread* self); |
|
70 |
int simple_wait(Thread* self, jlong millis); |
|
71 |
void simple_notify(Thread* self, bool all); |
|
6975 | 72 |
|
58509 | 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 |
|
58509 | 87 |
JvmtiRawMonitor(const char* name); |
6975 | 88 |
~JvmtiRawMonitor(); |
58488
165b193b30dd
8231289: Disentangle JvmtiRawMonitor from ObjectMonitor and clean it up
dholmes
parents:
53244
diff
changeset
|
89 |
|
58509 | 90 |
Thread* owner() const { return _owner; } |
91 |
void set_owner(Thread* owner) { _owner = owner; } |
|
92 |
int recursions() const { return _recursions; } |
|
93 |
void raw_enter(Thread* self); |
|
94 |
int raw_exit(Thread* self); |
|
95 |
int raw_wait(jlong millis, bool interruptible, Thread* self); |
|
96 |
int raw_notify(Thread* self); |
|
97 |
int raw_notifyAll(Thread* self); |
|
98 |
int magic() const { return _magic; } |
|
99 |
const char* get_name() const { return _name; } |
|
100 |
bool is_valid(); |
|
6975 | 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 |
||
58509 | 109 |
private: |
110 |
static GrowableArray<JvmtiRawMonitor*>* _monitors; // Cache raw monitor enter |
|
6975 | 111 |
|
112 |
inline static GrowableArray<JvmtiRawMonitor*>* monitors() { return _monitors; } |
|
113 |
||
114 |
static void dispose() { |
|
115 |
delete monitors(); |
|
116 |
} |
|
117 |
||
58509 | 118 |
public: |
119 |
static void enter(JvmtiRawMonitor* monitor) { |
|
6975 | 120 |
monitors()->append(monitor); |
121 |
} |
|
122 |
||
123 |
static int count() { |
|
124 |
return monitors()->length(); |
|
125 |
} |
|
126 |
||
58509 | 127 |
static void destroy(JvmtiRawMonitor* monitor) { |
6975 | 128 |
while (monitors()->contains(monitor)) { |
129 |
monitors()->remove(monitor); |
|
130 |
} |
|
131 |
} |
|
132 |
||
133 |
// Return false if monitor is not found in the list. |
|
58509 | 134 |
static bool exit(JvmtiRawMonitor* monitor) { |
6975 | 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 |