|
1 /* |
|
2 * Copyright (c) 2013, 2018, 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_VM_JFR_RECORDER_SERVICE_JFRPOSTBOX_HPP |
|
26 #define SHARE_VM_JFR_RECORDER_SERVICE_JFRPOSTBOX_HPP |
|
27 |
|
28 #include "jfr/utilities/jfrAllocation.hpp" |
|
29 |
|
30 #define MSGBIT(e) (1<<(e)) |
|
31 |
|
32 enum JFR_Msg { |
|
33 MSG_ALL_MSGS = -1, |
|
34 MSG_CLONE_IN_MEMORY = 0, |
|
35 MSG_START, |
|
36 MSG_STOP, |
|
37 MSG_ROTATE, |
|
38 MSG_FULLBUFFER, |
|
39 MSG_CHECKPOINT, |
|
40 MSG_WAKEUP, |
|
41 MSG_SHUTDOWN, |
|
42 MSG_VM_ERROR, |
|
43 MSG_DEADBUFFER, |
|
44 MSG_NO_OF_MSGS |
|
45 }; |
|
46 |
|
47 /** |
|
48 * Jfr messaging. |
|
49 * |
|
50 * Synchronous messages (posting thread waits for message completion): |
|
51 * |
|
52 * MSG_CLONE_IN_MEMORY (0) ; MSGBIT(MSG_CLONE_IN_MEMORY) == (1 << 0) == 0x1 |
|
53 * MSG_START(1) ; MSGBIT(MSG_START) == (1 << 0x1) == 0x2 |
|
54 * MSG_STOP (2) ; MSGBIT(MSG_STOP) == (1 << 0x2) == 0x4 |
|
55 * MSG_ROTATE (3) ; MSGBIT(MSG_ROTATE) == (1 << 0x3) == 0x8 |
|
56 * MSG_VM_ERROR (8) ; MSGBIT(MSG_VM_ERROR) == (1 << 8) == 0x100 |
|
57 * |
|
58 * Asynchronous messages (posting thread returns immediately upon deposit): |
|
59 * |
|
60 * MSG_FULLBUFFER (4) ; MSGBIT(MSG_FULLBUFFER) == (1 << 0x4) == 0x10 |
|
61 * MSG_CHECKPOINT (5) ; MSGBIT(CHECKPOINT) == (1 << 5) == 0x20 |
|
62 * MSG_WAKEUP (6) ; MSGBIT(WAKEUP) == (1 << 6) == 0x40 |
|
63 * MSG_SHUTDOWN (7) ; MSGBIT(MSG_SHUTDOWN) == (1 << 7) == 0x80 |
|
64 * MSG_DEADBUFFER (9) ; MSGBIT(MSG_DEADBUFFER) == (1 << 9) == 0x200 |
|
65 */ |
|
66 |
|
67 class JfrPostBox : public JfrCHeapObj { |
|
68 friend class JfrRecorder; |
|
69 public: |
|
70 void post(JFR_Msg msg); |
|
71 |
|
72 private: |
|
73 uintptr_t _msg_read_serial; |
|
74 uintptr_t _msg_handled_serial; |
|
75 volatile int _messages; |
|
76 bool _has_waiters; |
|
77 |
|
78 JfrPostBox(); |
|
79 static JfrPostBox& instance(); |
|
80 static JfrPostBox* create(); |
|
81 static void destroy(); |
|
82 |
|
83 void asynchronous_post(int msg); |
|
84 void synchronous_post(int msg); |
|
85 void deposit(int new_messages); |
|
86 bool is_message_processed(uintptr_t serial_id) const; |
|
87 |
|
88 friend void recorderthread_entry(JavaThread*, Thread*); |
|
89 // for the friend declaration above |
|
90 bool is_empty() const; |
|
91 int collect(); |
|
92 bool check_waiters(int messages) const; |
|
93 void notify_waiters(); |
|
94 void notify_collection_stop(); |
|
95 }; |
|
96 |
|
97 #endif // SHARE_VM_JFR_RECORDER_SERVICE_JFRPOSTBOX_HPP |