Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/prims/jvmtiRawMonitor.hpp
41144 views
1
/*
2
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
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
25
#ifndef SHARE_PRIMS_JVMTIRAWMONITOR_HPP
26
#define SHARE_PRIMS_JVMTIRAWMONITOR_HPP
27
28
#include "memory/allocation.hpp"
29
#include "runtime/park.hpp"
30
#include "utilities/growableArray.hpp"
31
32
//
33
// class JvmtiRawMonitor
34
//
35
// Used by JVMTI methods: All RawMonitor methods (CreateRawMonitor, EnterRawMonitor, etc.)
36
//
37
// A simplified version of the ObjectMonitor code.
38
//
39
40
// Important note:
41
// Raw monitors can be used in callbacks which happen during safepoint by the VM
42
// thread (e.g., heapRootCallback). This means we may not transition/safepoint
43
// poll in many cases, else the agent JavaThread can deadlock with the VM thread,
44
// as this old comment says:
45
// "We can't safepoint block in here because we could deadlock the vmthread. Blech."
46
// The rules are:
47
// - We must never safepoint poll if raw monitor is owned.
48
// - We may safepoint poll before it is owned and after it has been released.
49
// If this were the only thing we needed to think about we could just stay in
50
// native for all operations. However we need to honor a suspend request, not
51
// entering a monitor if suspended, and check for interrupts. Honoring a suspend
52
// request and reading the interrupt flag must be done from VM state
53
// (a safepoint unsafe state).
54
55
class JvmtiRawMonitor : public CHeapObj<mtSynchronizer> {
56
57
// Helper class to allow Threads to be linked into queues.
58
// This is a stripped down version of ObjectWaiter.
59
class QNode : public StackObj {
60
friend class JvmtiRawMonitor;
61
enum TStates { TS_READY, TS_RUN, TS_WAIT, TS_ENTER };
62
QNode* volatile _next;
63
QNode* volatile _prev;
64
ParkEvent* _event;
65
volatile int _notified;
66
volatile TStates _t_state;
67
68
QNode(Thread* thread);
69
};
70
71
Thread* volatile _owner; // pointer to owning thread
72
volatile int _recursions; // recursion count, 0 for first entry
73
QNode* volatile _entry_list; // Threads blocked on entry or reentry.
74
// The list is actually composed of nodes,
75
// acting as proxies for Threads.
76
QNode* volatile _wait_set; // Threads wait()ing on the monitor
77
int _magic;
78
char* _name;
79
// JVMTI_RM_MAGIC is set in contructor and unset in destructor.
80
enum { JVMTI_RM_MAGIC = (int)(('T' << 24) | ('I' << 16) | ('R' << 8) | 'M') };
81
82
// Helpers for queue management isolation
83
void enqueue_waiter(QNode& node);
84
void dequeue_waiter(QNode& node);
85
86
// Mostly low-level implementation routines
87
void simple_enter(Thread* self);
88
void simple_exit(Thread* self);
89
int simple_wait(Thread* self, jlong millis);
90
void simple_notify(Thread* self, bool all);
91
92
class ExitOnSuspend {
93
protected:
94
JvmtiRawMonitor* _rm;
95
bool _rm_exited;
96
public:
97
ExitOnSuspend(JvmtiRawMonitor* rm) : _rm(rm), _rm_exited(false) {}
98
void operator()(JavaThread* current);
99
bool monitor_exited() { return _rm_exited; }
100
};
101
102
public:
103
104
// return codes
105
enum {
106
M_OK, // no error
107
M_ILLEGAL_MONITOR_STATE, // IllegalMonitorStateException
108
M_INTERRUPTED // Thread.interrupt()
109
};
110
111
// Non-aborting operator new
112
void* operator new(size_t size) throw() {
113
return CHeapObj::operator new(size, std::nothrow);
114
}
115
116
JvmtiRawMonitor(const char* name);
117
~JvmtiRawMonitor();
118
119
Thread* owner() const { return _owner; }
120
void set_owner(Thread* owner) { _owner = owner; }
121
int recursions() const { return _recursions; }
122
void raw_enter(Thread* self);
123
int raw_exit(Thread* self);
124
int raw_wait(jlong millis, Thread* self);
125
int raw_notify(Thread* self);
126
int raw_notifyAll(Thread* self);
127
int magic() const { return _magic; }
128
const char* get_name() const { return _name; }
129
bool is_valid();
130
};
131
132
// Onload pending raw monitors
133
// Class is used to cache onload or onstart monitor enter
134
// which will transition into real monitor when
135
// VM is fully initialized.
136
class JvmtiPendingMonitors : public AllStatic {
137
138
private:
139
static GrowableArray<JvmtiRawMonitor*>* _monitors; // Cache raw monitor enter
140
141
inline static GrowableArray<JvmtiRawMonitor*>* monitors() { return _monitors; }
142
143
static void dispose() {
144
delete monitors();
145
}
146
147
public:
148
static void enter(JvmtiRawMonitor* monitor) {
149
monitors()->append(monitor);
150
}
151
152
static int count() {
153
return monitors()->length();
154
}
155
156
static void destroy(JvmtiRawMonitor* monitor) {
157
while (monitors()->contains(monitor)) {
158
monitors()->remove(monitor);
159
}
160
}
161
162
// Return false if monitor is not found in the list.
163
static bool exit(JvmtiRawMonitor* monitor) {
164
return monitors()->remove_if_existing(monitor);
165
}
166
167
static void transition_raw_monitors();
168
};
169
170
#endif // SHARE_PRIMS_JVMTIRAWMONITOR_HPP
171
172