author | egahlin |
Fri, 13 Sep 2019 18:46:07 +0200 | |
branch | JEP-349-branch |
changeset 58129 | 7b751fe181a5 |
parent 58020 | f082177c5023 |
permissions | -rw-r--r-- |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
1 |
/* |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
4 |
* |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
10 |
* |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
15 |
* accompanied this code). |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
16 |
* |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
20 |
* |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
23 |
* questions. |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
24 |
*/ |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
25 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
26 |
package jdk.jfr.consumer; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
27 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
28 |
import java.io.IOException; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
29 |
import java.security.AccessControlContext; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
30 |
import java.security.AccessController; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
31 |
import java.security.PrivilegedAction; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
32 |
import java.time.Duration; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
33 |
import java.time.Instant; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
34 |
import java.util.Comparator; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
35 |
import java.util.Objects; |
58020
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
36 |
import java.util.concurrent.atomic.AtomicLong; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
37 |
import java.util.function.Consumer; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
38 |
|
57614 | 39 |
import jdk.jfr.internal.JVM; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
40 |
import jdk.jfr.internal.LogLevel; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
41 |
import jdk.jfr.internal.LogTag; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
42 |
import jdk.jfr.internal.Logger; |
57985 | 43 |
import jdk.jfr.internal.SecuritySupport; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
44 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
45 |
/* |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
46 |
* Purpose of this class is to simplify the implementation of |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
47 |
* an event stream. In particular, it handles: |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
48 |
* |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
49 |
* - configuration storage |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
50 |
* - atomic updates to a configuration |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
51 |
* - dispatch mechanism |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
52 |
* - error handling |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
53 |
* - security |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
54 |
* |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
55 |
*/ |
57985 | 56 |
abstract class AbstractEventStream implements EventStream { |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
57 |
|
58129 | 58 |
static final Comparator<? super RecordedEvent> END_TIME = (e1, e2) -> Long.compare(e1.endTimeTicks, e2.endTimeTicks); |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
59 |
|
58020
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
60 |
private final static AtomicLong counter = new AtomicLong(1); |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
61 |
private final Object terminated = new Object(); |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
62 |
private final boolean active; |
58129 | 63 |
private final Runnable flushOperation = () -> dispatcher().runFlushActions(); |
57985 | 64 |
private final AccessControlContext accessControllerContext; |
58129 | 65 |
private final StreamConfiguration configuration = new StreamConfiguration(); |
57861 | 66 |
|
58129 | 67 |
private volatile Thread thread; |
68 |
private Dispatcher dispatcher; |
|
69 |
||
70 |
private volatile boolean closed; |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
71 |
|
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
72 |
public AbstractEventStream(AccessControlContext acc, boolean active) throws IOException { |
57985 | 73 |
this.accessControllerContext = Objects.requireNonNull(acc); |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
74 |
this.active = active; |
57985 | 75 |
} |
76 |
||
77 |
@Override |
|
78 |
abstract public void start(); |
|
79 |
||
80 |
@Override |
|
81 |
abstract public void startAsync(); |
|
82 |
||
83 |
@Override |
|
84 |
abstract public void close(); |
|
85 |
||
58129 | 86 |
protected final Dispatcher dispatcher() { |
87 |
if (configuration.hasChanged()) { |
|
88 |
synchronized (configuration) { |
|
89 |
dispatcher = new Dispatcher(configuration); |
|
90 |
} |
|
91 |
} |
|
92 |
return dispatcher; |
|
93 |
} |
|
94 |
||
57985 | 95 |
@Override |
96 |
public final void setOrdered(boolean ordered) { |
|
58129 | 97 |
configuration.setOrdered(ordered); |
57985 | 98 |
} |
99 |
||
100 |
@Override |
|
101 |
public final void setReuse(boolean reuse) { |
|
58129 | 102 |
configuration.setReuse(reuse); |
57985 | 103 |
} |
104 |
||
105 |
@Override |
|
106 |
public final void setStartTime(Instant startTime) { |
|
107 |
Objects.nonNull(startTime); |
|
58129 | 108 |
synchronized (configuration) { |
109 |
if (configuration.started) { |
|
57985 | 110 |
throw new IllegalStateException("Stream is already started"); |
111 |
} |
|
112 |
if (startTime.isBefore(Instant.EPOCH)) { |
|
113 |
startTime = Instant.EPOCH; |
|
114 |
} |
|
58129 | 115 |
configuration.setStartTime(startTime); |
57985 | 116 |
} |
117 |
} |
|
118 |
||
119 |
@Override |
|
120 |
public final void setEndTime(Instant endTime) { |
|
121 |
Objects.requireNonNull(endTime); |
|
58129 | 122 |
synchronized (configuration) { |
123 |
if (configuration.started) { |
|
57985 | 124 |
throw new IllegalStateException("Stream is already started"); |
125 |
} |
|
58129 | 126 |
configuration.setEndTime(endTime); |
57985 | 127 |
} |
128 |
} |
|
129 |
||
130 |
@Override |
|
131 |
public final void onEvent(Consumer<RecordedEvent> action) { |
|
132 |
Objects.requireNonNull(action); |
|
58129 | 133 |
configuration.addEventAction(action); |
57985 | 134 |
} |
135 |
||
136 |
@Override |
|
137 |
public final void onEvent(String eventName, Consumer<RecordedEvent> action) { |
|
138 |
Objects.requireNonNull(eventName); |
|
139 |
Objects.requireNonNull(action); |
|
58129 | 140 |
configuration.addEventAction(eventName, action); |
57985 | 141 |
} |
142 |
||
143 |
@Override |
|
144 |
public final void onFlush(Runnable action) { |
|
145 |
Objects.requireNonNull(action); |
|
58129 | 146 |
configuration.addFlushAction(action); |
57985 | 147 |
} |
148 |
||
149 |
@Override |
|
150 |
public final void onClose(Runnable action) { |
|
151 |
Objects.requireNonNull(action); |
|
58129 | 152 |
configuration.addCloseAction(action); |
57985 | 153 |
} |
154 |
||
155 |
@Override |
|
156 |
public final void onError(Consumer<Throwable> action) { |
|
157 |
Objects.requireNonNull(action); |
|
58129 | 158 |
configuration.addErrorAction(action); |
57985 | 159 |
} |
160 |
||
161 |
@Override |
|
162 |
public final boolean remove(Object action) { |
|
163 |
Objects.requireNonNull(action); |
|
58129 | 164 |
return configuration.remove(action); |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
165 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
166 |
|
57985 | 167 |
@Override |
58020
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
168 |
public final void awaitTermination() throws InterruptedException { |
57985 | 169 |
awaitTermination(Duration.ofMillis(0)); |
170 |
} |
|
171 |
||
172 |
@Override |
|
58020
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
173 |
public final void awaitTermination(Duration timeout) throws InterruptedException { |
57985 | 174 |
Objects.requireNonNull(timeout); |
58020
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
175 |
if (timeout.isNegative()) { |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
176 |
throw new IllegalArgumentException("timeout value is negative"); |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
177 |
} |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
178 |
|
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
179 |
long base = System.currentTimeMillis(); |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
180 |
long now = 0; |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
181 |
|
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
182 |
long millis; |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
183 |
try { |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
184 |
millis = Math.multiplyExact(timeout.getSeconds(), 1000); |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
185 |
} catch (ArithmeticException a) { |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
186 |
millis = Long.MAX_VALUE; |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
187 |
} |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
188 |
int nanos = timeout.toNanosPart(); |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
189 |
if (nanos == 0 && millis == 0) { |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
190 |
synchronized (terminated) { |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
191 |
while (!isClosed()) { |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
192 |
terminated.wait(0); |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
193 |
} |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
194 |
} |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
195 |
} else { |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
196 |
while (!isClosed()) { |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
197 |
long delay = millis - now; |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
198 |
if (delay <= 0) { |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
199 |
break; |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
200 |
} |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
201 |
synchronized (terminated) { |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
202 |
terminated.wait(delay, nanos); |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
203 |
} |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
204 |
now = System.currentTimeMillis() - base; |
57985 | 205 |
} |
206 |
} |
|
207 |
} |
|
208 |
||
209 |
protected abstract void process() throws Exception; |
|
210 |
||
211 |
protected final void setClosed(boolean closed) { |
|
58129 | 212 |
this.closed = closed; |
57985 | 213 |
} |
214 |
||
215 |
protected final boolean isClosed() { |
|
58129 | 216 |
return closed; |
57985 | 217 |
} |
218 |
||
219 |
protected final void startAsync(long startNanos) { |
|
220 |
startInternal(startNanos); |
|
58020
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
221 |
Runnable r = () -> run(accessControllerContext); |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
222 |
thread = SecuritySupport.createThreadWitNoPermissions(nextThreadName(), r); |
57985 | 223 |
thread.start(); |
224 |
} |
|
225 |
||
226 |
protected final void start(long startNanos) { |
|
227 |
startInternal(startNanos); |
|
58020
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
228 |
thread = Thread.currentThread(); |
57985 | 229 |
run(accessControllerContext); |
230 |
} |
|
231 |
||
232 |
protected final Runnable getFlushOperation() { |
|
233 |
return flushOperation; |
|
234 |
} |
|
235 |
||
236 |
private void startInternal(long startNanos) { |
|
58129 | 237 |
synchronized (configuration) { |
238 |
if (configuration.started) { |
|
57985 | 239 |
throw new IllegalStateException("Event stream can only be started once"); |
240 |
} |
|
241 |
if (active) { |
|
58129 | 242 |
configuration.setStartNanos(startNanos); |
57985 | 243 |
} |
58129 | 244 |
configuration.setStarted(true); |
57985 | 245 |
} |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
246 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
247 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
248 |
private void execute() { |
57614 | 249 |
JVM.getJVM().exclude(Thread.currentThread()); |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
250 |
try { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
251 |
process(); |
58129 | 252 |
} catch (IOException ioe) { |
253 |
// This can happen if a chunk file is removed, or |
|
254 |
// a file is access that has been closed |
|
255 |
// This is "normal" behavior for streaming and the |
|
256 |
// stream will be closed when this happens |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
257 |
} catch (Exception e) { |
58129 | 258 |
// TODO: Remove before integrating |
259 |
e.printStackTrace(); |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
260 |
} finally { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
261 |
Logger.log(LogTag.JFR_SYSTEM_STREAMING, LogLevel.DEBUG, "Execution of stream ended."); |
58020
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
262 |
try { |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
263 |
close(); |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
264 |
} finally { |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
265 |
synchronized (terminated) { |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
266 |
terminated.notifyAll(); |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
267 |
} |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
268 |
} |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
269 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
270 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
271 |
|
58020
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
272 |
private void run(AccessControlContext accessControlContext) { |
57985 | 273 |
AccessController.doPrivileged(new PrivilegedAction<Void>() { |
274 |
@Override |
|
275 |
public Void run() { |
|
276 |
execute(); |
|
277 |
return null; |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
278 |
} |
58020
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
279 |
}, accessControlContext); |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
280 |
} |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
281 |
|
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
282 |
private String nextThreadName() { |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
283 |
counter.incrementAndGet(); |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
284 |
return "JFR Event Stream " + counter; |
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
285 |
} |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
286 |
} |