Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_verbose_old/VerboseEventStream.cpp
5985 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2014 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
22
*******************************************************************************/
23
24
#include "AtomicOperations.hpp"
25
#include "EnvironmentBase.hpp"
26
#include "VerboseEvent.hpp"
27
#include "VerboseEventStream.hpp"
28
#include "GCExtensions.hpp"
29
#include "VerboseManagerOld.hpp"
30
31
/**
32
* Create a new MM_VerboseEventStream instance.
33
* @return Pointer to the new MM_VerboseEventStream.
34
*/
35
MM_VerboseEventStream *
36
MM_VerboseEventStream::newInstance(MM_EnvironmentBase *env, MM_VerboseManagerOld *manager)
37
{
38
MM_VerboseEventStream *eventStream = NULL;
39
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env->getOmrVM());
40
41
eventStream = (MM_VerboseEventStream *)extensions->getForge()->allocate(sizeof(MM_VerboseEventStream), MM_AllocationCategory::DIAGNOSTIC, J9_GET_CALLSITE());
42
if (eventStream) {
43
new(eventStream) MM_VerboseEventStream(env, manager);
44
}
45
return eventStream;
46
}
47
48
/**
49
* Kill the MM_VerboseEventStream instance.
50
* Tears down the related structures and frees any storage.
51
*/
52
void
53
MM_VerboseEventStream::kill(MM_EnvironmentBase *env)
54
{
55
tearDown(env);
56
57
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env->getOmrVM());
58
extensions->getForge()->free(this);
59
}
60
61
/**
62
* Tear down the structures managed by the MM_VerboseEventStream.
63
*/
64
void
65
MM_VerboseEventStream::tearDown(MM_EnvironmentBase *env)
66
{
67
MM_VerboseEvent *event, *nextEvent;
68
69
event = _eventChain;
70
_eventChain = NULL;
71
_eventChainTail = NULL;
72
73
while(NULL != event){
74
nextEvent = event->getNextEvent();
75
event->kill(env);
76
event = nextEvent;
77
}
78
}
79
80
/**
81
* Calls each events consume routine.
82
*/
83
void
84
MM_VerboseEventStream::callConsumeRoutines(MM_EnvironmentBase *env)
85
{
86
MM_VerboseEvent *event = _eventChain;
87
88
while(NULL != event) {
89
event->consumeEvents();
90
event = event->getNextEvent();
91
}
92
}
93
94
/**
95
* Removes events which don't output form the chain.
96
*/
97
void
98
MM_VerboseEventStream::removeNonOutputEvents(MM_EnvironmentBase *env)
99
{
100
MM_VerboseEvent *event, *nextEvent;
101
102
event = _eventChain;
103
while(NULL != event){
104
nextEvent = event->getNextEvent();
105
if(!event->definesOutputRoutine()){
106
removeEventFromChain(env, event);
107
}
108
event = nextEvent;
109
}
110
}
111
112
/**
113
* Remove a specified event from the event chain.
114
* @param event Pointer to the event to be removed.
115
*/
116
void
117
MM_VerboseEventStream::removeEventFromChain(MM_EnvironmentBase *env, MM_VerboseEvent *event)
118
{
119
MM_VerboseEvent *previousEvent = event->getPreviousEvent();
120
MM_VerboseEvent *nextEvent = event->getNextEvent();
121
122
if(NULL != previousEvent) {
123
previousEvent->setNextEvent(nextEvent);
124
} else {
125
/* We are removing the head of the chain */
126
_eventChain = nextEvent;
127
}
128
129
if(NULL != nextEvent) {
130
nextEvent->setPreviousEvent(previousEvent);
131
} else {
132
/* We are removing the tail of the chain */
133
_eventChainTail = previousEvent;
134
}
135
136
event->kill(env);
137
}
138
139
/**
140
* Add an event to the event chain.
141
* @param event Pointer to the event to be added.
142
*/
143
void
144
MM_VerboseEventStream::chainEvent(MM_EnvironmentBase *env, MM_VerboseEvent *event)
145
{
146
UDATA oldValue, newValue;
147
148
newValue = (UDATA)event;
149
150
do {
151
oldValue = (UDATA)_eventChainTail;
152
((MM_VerboseEvent *)newValue)->setPreviousEvent((MM_VerboseEvent *)oldValue);
153
} while((UDATA)oldValue != MM_AtomicOperations::lockCompareExchange((volatile UDATA *)&_eventChainTail, oldValue, newValue));
154
155
if (oldValue) {
156
((MM_VerboseEvent *)oldValue)->setNextEvent((MM_VerboseEvent*)newValue);
157
} else {
158
_eventChain = event;
159
}
160
}
161
162
/**
163
* Process the event stream.
164
* Prepares the event stream for output and notifies the verbose manager to pass the stream to the output agents.
165
*/
166
void
167
MM_VerboseEventStream::processStream(MM_EnvironmentBase *env)
168
{
169
PORT_ACCESS_FROM_ENVIRONMENT(env);
170
_manager->incrementOutputCount();
171
callConsumeRoutines(env);
172
removeNonOutputEvents(env);
173
_manager->passStreamToOutputAgents(env, this);
174
if(isDisposable()) {
175
kill(env);
176
} else {
177
_manager->setLastOutputTime(j9time_hires_clock());
178
tearDown(env);
179
}
180
}
181
182
/**
183
* Returns an event of a specific type.
184
* Walks the event stream backwards from the event passed in and returns the first event of the type requested.
185
* @param eventID the type of event required.
186
* @param hookInterface interface associated with eventID
187
* @param event pointer to the current event.
188
* @return Pointer an event of that type.
189
*/
190
MM_VerboseEvent *
191
MM_VerboseEventStream::returnEvent(UDATA eventid, J9HookInterface** hookInterface, MM_VerboseEvent *event)
192
{
193
while(NULL != event) {
194
if((eventid == event->getEventType()) && (hookInterface == event->getHookInterface())) {
195
return event;
196
}
197
event = event->getPreviousEvent();
198
}
199
return NULL;
200
}
201
202
/**
203
* Returns an event of a specific type.
204
* Walks the event stream backwards from the event passed in and returns the first event of the type requested.
205
* HOWEVER, if an event of type stopEventID is encountered first, NULL is returned.
206
* @param eventID the type of event required.
207
* @param hookInterface interface associated with eventID
208
* @param event pointer to the current event.
209
* @param stopEventID the type of event to stop at if encountered.
210
* @param stopHookInterface interface associated with stopEventID
211
* @return Pointer an event of that type.
212
*/
213
MM_VerboseEvent *
214
MM_VerboseEventStream::returnEvent(UDATA eventid, J9HookInterface** hookInterface, MM_VerboseEvent *event, UDATA stopEventID, J9HookInterface** stopHookInterface)
215
{
216
while(NULL != event) {
217
if((stopEventID == event->getEventType()) && (stopHookInterface == event->getHookInterface())) {
218
/* we've hit a "stopEventID" first, so return NULL */
219
return NULL;
220
}
221
if((eventid == event->getEventType()) && (hookInterface == event->getHookInterface())) {
222
return event;
223
}
224
event = event->getPreviousEvent();
225
}
226
return NULL;
227
}
228
229