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 "runtime/objectMonitor.hpp"
29#include "utilities/growableArray.hpp"
30
31//
32// class JvmtiRawMonitor
33//
34// Used by JVMTI methods: All RawMonitor methods (CreateRawMonitor, EnterRawMonitor, etc.)
35//
36// Wrapper for ObjectMonitor class that saves the Monitor's name
37//
38
39class JvmtiRawMonitor : public ObjectMonitor {
40private:
41 int _magic;
42 char * _name;
43 // JVMTI_RM_MAGIC is set in contructor and unset in destructor.
44 enum { JVMTI_RM_MAGIC = (int)(('T' << 24) | ('I' << 16) | ('R' << 8) | 'M') };
45
46 int SimpleEnter (Thread * Self) ;
47 int SimpleExit (Thread * Self) ;
48 int SimpleWait (Thread * Self, jlong millis) ;
49 int SimpleNotify (Thread * Self, bool All) ;
50
51public:
52 JvmtiRawMonitor(const char *name);
53 ~JvmtiRawMonitor();
54 int raw_enter(TRAPS);
55 int raw_exit(TRAPS);
56 int raw_wait(jlong millis, bool interruptable, TRAPS);
57 int raw_notify(TRAPS);
58 int raw_notifyAll(TRAPS);
59 int magic() { return _magic; }
60 const char *get_name() { return _name; }
61 bool is_valid();
62};
63
64// Onload pending raw monitors
65// Class is used to cache onload or onstart monitor enter
66// which will transition into real monitor when
67// VM is fully initialized.
68class JvmtiPendingMonitors : public AllStatic {
69
70private:
71 static GrowableArray<JvmtiRawMonitor*> *_monitors; // Cache raw monitor enter
72
73 inline static GrowableArray<JvmtiRawMonitor*>* monitors() { return _monitors; }
74
75 static void dispose() {
76 delete monitors();
77 }
78
79public:
80 static void enter(JvmtiRawMonitor *monitor) {
81 monitors()->append(monitor);
82 }
83
84 static int count() {
85 return monitors()->length();
86 }
87
88 static void destroy(JvmtiRawMonitor *monitor) {
89 while (monitors()->contains(monitor)) {
90 monitors()->remove(monitor);
91 }
92 }
93
94 // Return false if monitor is not found in the list.
95 static bool exit(JvmtiRawMonitor *monitor) {
96 if (monitors()->contains(monitor)) {
97 monitors()->remove(monitor);
98 return true;
99 } else {
100 return false;
101 }
102 }
103
104 static void transition_raw_monitors();
105};
106
107#endif // SHARE_PRIMS_JVMTIRAWMONITOR_HPP
108