author | egahlin |
Fri, 30 Aug 2019 20:39:38 +0200 | |
branch | JEP-349-branch |
changeset 57971 | aa7b1ea52413 |
parent 57948 | 59ad17a19e24 |
child 57985 | be121cbf3284 |
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.lang.invoke.VarHandle; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
30 |
import java.security.AccessControlContext; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
31 |
import java.security.AccessController; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
32 |
import java.security.PrivilegedAction; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
33 |
import java.time.Duration; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
34 |
import java.time.Instant; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
35 |
import java.util.ArrayList; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
36 |
import java.util.Arrays; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
37 |
import java.util.Comparator; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
38 |
import java.util.List; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
39 |
import java.util.Objects; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
40 |
import java.util.function.Consumer; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
41 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
42 |
import jdk.jfr.EventType; |
57614 | 43 |
import jdk.jfr.internal.JVM; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
44 |
import jdk.jfr.internal.LogLevel; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
45 |
import jdk.jfr.internal.LogTag; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
46 |
import jdk.jfr.internal.Logger; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
47 |
import jdk.jfr.internal.LongMap; |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
48 |
import jdk.jfr.internal.Utils; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
49 |
import jdk.jfr.internal.consumer.InternalEventFilter; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
50 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
51 |
/* |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
52 |
* Purpose of this class is to simplify the implementation of |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
53 |
* an event stream. In particular, it handles: |
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 |
* - configuration storage |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
56 |
* - atomic updates to a configuration |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
57 |
* - dispatch mechanism |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
58 |
* - error handling |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
59 |
* - security |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
60 |
* |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
61 |
*/ |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
62 |
abstract class AbstractEventStream implements Runnable { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
63 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
64 |
public static final class StreamConfiguration { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
65 |
private static final Runnable[] NO_ACTIONS = new Runnable[0]; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
66 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
67 |
private Runnable[] flushActions = NO_ACTIONS; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
68 |
private Runnable[] closeActions = NO_ACTIONS; |
57971 | 69 |
private Runnable[] errorActions = NO_ACTIONS; |
70 |
||
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
71 |
private EventDispatcher[] dispatchers = NO_DISPATCHERS; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
72 |
private InternalEventFilter eventFilter = InternalEventFilter.ACCEPT_ALL; |
57971 | 73 |
private LongMap<EventDispatcher[]> dispatcherLookup = new LongMap<>(); |
74 |
private boolean changedConfiguration = false; |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
75 |
private boolean closed = false; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
76 |
private boolean reuse = true; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
77 |
private boolean ordered = true; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
78 |
private Instant startTime = null; |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
79 |
private Instant endTime = null; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
80 |
private boolean started = false; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
81 |
private long startNanos = 0; |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
82 |
private long endNanos = Long.MAX_VALUE; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
83 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
84 |
public StreamConfiguration(StreamConfiguration configuration) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
85 |
this.flushActions = configuration.flushActions; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
86 |
this.closeActions = configuration.closeActions; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
87 |
this.dispatchers = configuration.dispatchers; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
88 |
this.eventFilter = configuration.eventFilter; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
89 |
this.closed = configuration.closed; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
90 |
this.reuse = configuration.reuse; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
91 |
this.ordered = configuration.ordered; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
92 |
this.startTime = configuration.startTime; |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
93 |
this.endTime = configuration.endTime; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
94 |
this.started = configuration.started; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
95 |
this.startNanos = configuration.startNanos; |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
96 |
this.endNanos = configuration.endNanos; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
97 |
this.dispatcherLookup = configuration.dispatcherLookup; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
98 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
99 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
100 |
public StreamConfiguration() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
101 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
102 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
103 |
final public StreamConfiguration remove(Object action) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
104 |
flushActions = remove(flushActions, action); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
105 |
closeActions = remove(closeActions, action); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
106 |
dispatchers = removeDispatch(dispatchers, action); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
107 |
return this; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
108 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
109 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
110 |
final public StreamConfiguration addDispatcher(EventDispatcher e) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
111 |
dispatchers = add(dispatchers, e); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
112 |
eventFilter = buildFilter(dispatchers); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
113 |
dispatcherLookup = new LongMap<>(); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
114 |
return this; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
115 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
116 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
117 |
final public StreamConfiguration addFlushAction(Runnable action) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
118 |
flushActions = add(flushActions, action); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
119 |
return this; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
120 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
121 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
122 |
final public StreamConfiguration addCloseAction(Runnable action) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
123 |
closeActions = add(closeActions, action); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
124 |
return this; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
125 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
126 |
|
57971 | 127 |
public StreamConfiguration addErrorAction(Runnable action) { |
128 |
errorActions = add(errorActions, action); |
|
129 |
return this; |
|
130 |
} |
|
131 |
||
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
132 |
final public StreamConfiguration setClosed(boolean closed) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
133 |
this.closed = closed; |
57971 | 134 |
changedConfiguration = true; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
135 |
return this; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
136 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
137 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
138 |
final public boolean isClosed() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
139 |
return closed; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
140 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
141 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
142 |
final public Runnable[] getCloseActions() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
143 |
return closeActions; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
144 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
145 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
146 |
final public Runnable[] getFlushActions() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
147 |
return flushActions; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
148 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
149 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
150 |
private EventDispatcher[] removeDispatch(EventDispatcher[] array, Object action) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
151 |
List<EventDispatcher> list = new ArrayList<>(array.length); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
152 |
boolean modified = false; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
153 |
for (int i = 0; i < array.length; i++) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
154 |
if (array[i].action != action) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
155 |
list.add(array[i]); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
156 |
} else { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
157 |
modified = true; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
158 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
159 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
160 |
EventDispatcher[] result = list.toArray(new EventDispatcher[0]); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
161 |
if (modified) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
162 |
eventFilter = buildFilter(result); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
163 |
dispatcherLookup = new LongMap<>(); |
57971 | 164 |
changedConfiguration = true; |
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 |
return result; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
167 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
168 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
169 |
private <T> T[] remove(T[] array, Object action) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
170 |
List<T> list = new ArrayList<>(array.length); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
171 |
for (int i = 0; i < array.length; i++) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
172 |
if (array[i] != action) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
173 |
list.add(array[i]); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
174 |
} else { |
57971 | 175 |
changedConfiguration = true; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
176 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
177 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
178 |
return list.toArray(array); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
179 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
180 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
181 |
private <T> T[] add(T[] array, T object) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
182 |
List<T> list = new ArrayList<>(Arrays.asList(array)); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
183 |
list.add(object); |
57971 | 184 |
changedConfiguration = true; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
185 |
return list.toArray(array); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
186 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
187 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
188 |
private static InternalEventFilter buildFilter(EventDispatcher[] dispatchers) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
189 |
InternalEventFilter ef = new InternalEventFilter(); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
190 |
for (EventDispatcher ed : dispatchers) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
191 |
String name = ed.eventName; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
192 |
if (name == null) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
193 |
return InternalEventFilter.ACCEPT_ALL; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
194 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
195 |
ef.setThreshold(name, 0); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
196 |
} |
57921
08327ab323c5
Make stream thread non-daemon and remove unnecessary copying of filter
egahlin
parents:
57861
diff
changeset
|
197 |
return ef; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
198 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
199 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
200 |
final public StreamConfiguration setReuse(boolean reuse) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
201 |
this.reuse = reuse; |
57971 | 202 |
changedConfiguration = true; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
203 |
return this; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
204 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
205 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
206 |
final public StreamConfiguration setOrdered(boolean ordered) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
207 |
this.ordered = ordered; |
57971 | 208 |
changedConfiguration = true; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
209 |
return this; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
210 |
} |
57971 | 211 |
|
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
212 |
public StreamConfiguration setEndTime(Instant endTime) { |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
213 |
this.endTime = endTime; |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
214 |
this.endNanos = Utils.timeToNanos(endTime); |
57971 | 215 |
changedConfiguration = true; |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
216 |
return this; |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
217 |
} |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
218 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
219 |
final public StreamConfiguration setStartTime(Instant startTime) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
220 |
this.startTime = startTime; |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
221 |
this.startNanos = Utils.timeToNanos(startTime); |
57971 | 222 |
changedConfiguration = true; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
223 |
return this; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
224 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
225 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
226 |
final public Instant getStartTime() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
227 |
return startTime; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
228 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
229 |
|
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
230 |
public Object getEndTime() { |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
231 |
return endTime; |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
232 |
} |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
233 |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
234 |
final public boolean isStarted() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
235 |
return started; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
236 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
237 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
238 |
final public StreamConfiguration setStartNanos(long startNanos) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
239 |
this.startNanos = startNanos; |
57971 | 240 |
changedConfiguration = true; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
241 |
return this; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
242 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
243 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
244 |
final public void setStarted(boolean started) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
245 |
this.started = started; |
57971 | 246 |
changedConfiguration = true; |
57604
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 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
249 |
final public boolean hasChanged() { |
57971 | 250 |
return changedConfiguration; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
251 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
252 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
253 |
final public boolean getReuse() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
254 |
return reuse; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
255 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
256 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
257 |
final public boolean getOrdered() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
258 |
return ordered; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
259 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
260 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
261 |
final public InternalEventFilter getFiler() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
262 |
return eventFilter; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
263 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
264 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
265 |
final public long getStartNanos() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
266 |
return startNanos; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
267 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
268 |
|
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
269 |
final public long getEndNanos() { |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
270 |
return endNanos; |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
271 |
} |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
272 |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
273 |
final public InternalEventFilter getFilter() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
274 |
return eventFilter; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
275 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
276 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
277 |
final public String toString() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
278 |
StringBuilder sb = new StringBuilder(); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
279 |
for (Runnable flush : flushActions) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
280 |
sb.append("Flush Action: ").append(flush).append("\n"); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
281 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
282 |
for (Runnable close : closeActions) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
283 |
sb.append("Close Action: " + close + "\n"); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
284 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
285 |
for (EventDispatcher dispatcher : dispatchers) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
286 |
sb.append("Dispatch Action: " + dispatcher.eventName + "(" + dispatcher + ") \n"); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
287 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
288 |
sb.append("Closed: ").append(closed).append("\n"); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
289 |
sb.append("Reuse: ").append(reuse).append("\n"); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
290 |
sb.append("Ordered: ").append(ordered).append("\n"); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
291 |
sb.append("Started: ").append(started).append("\n"); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
292 |
sb.append("Start Time: ").append(startTime).append("\n"); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
293 |
sb.append("Start Nanos: ").append(startNanos).append("\n"); |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
294 |
sb.append("End Time: ").append(endTime).append("\n"); |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
295 |
sb.append("End Nanos: ").append(endNanos).append("\n"); |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
296 |
return sb.toString(); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
297 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
298 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
299 |
private EventDispatcher[] getDispatchers() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
300 |
return dispatchers; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
301 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
302 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
303 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
304 |
final static class EventDispatcher { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
305 |
final static EventDispatcher[] NO_DISPATCHERS = new EventDispatcher[0]; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
306 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
307 |
final private String eventName; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
308 |
final private Consumer<RecordedEvent> action; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
309 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
310 |
public EventDispatcher(Consumer<RecordedEvent> action) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
311 |
this(null, action); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
312 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
313 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
314 |
public EventDispatcher(String eventName, Consumer<RecordedEvent> action) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
315 |
this.eventName = eventName; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
316 |
this.action = action; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
317 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
318 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
319 |
public void offer(RecordedEvent event) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
320 |
action.accept(event); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
321 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
322 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
323 |
public boolean accepts(EventType eventType) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
324 |
return (eventName == null || eventType.getName().equals(eventName)); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
325 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
326 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
327 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
328 |
public final static Comparator<? super RecordedEvent> END_TIME = (e1, e2) -> Long.compare(e1.endTimeTicks, e2.endTimeTicks); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
329 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
330 |
private final static EventDispatcher[] NO_DISPATCHERS = new EventDispatcher[0]; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
331 |
private final AccessControlContext accessControlContext; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
332 |
private final Thread thread; |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
333 |
private final boolean active; |
57861 | 334 |
protected final Runnable flushOperation = () -> runFlushActions(); |
335 |
||
57971 | 336 |
// Modified by updateConfiguration() |
57948
59ad17a19e24
Publish configuration using volatile instread fence
egahlin
parents:
57921
diff
changeset
|
337 |
protected volatile StreamConfiguration configuration = new StreamConfiguration(); |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
338 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
339 |
// Cache the last event type and dispatch. |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
340 |
private EventType lastEventType; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
341 |
private EventDispatcher[] lastEventDispatch; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
342 |
|
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
343 |
public AbstractEventStream(AccessControlContext acc, boolean active) throws IOException { |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
344 |
this.accessControlContext = acc; |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
345 |
this.active = active; |
57614 | 346 |
// Create thread object in constructor to ensure caller has |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
347 |
// permission before constructing object |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
348 |
thread = new Thread(this); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
349 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
350 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
351 |
public final void run() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
352 |
AccessController.doPrivileged(new PrivilegedAction<Void>() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
353 |
@Override |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
354 |
public Void run() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
355 |
execute(); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
356 |
return null; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
357 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
358 |
}, accessControlContext); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
359 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
360 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
361 |
private void execute() { |
57614 | 362 |
JVM.getJVM().exclude(Thread.currentThread()); |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
363 |
try { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
364 |
process(); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
365 |
} catch (Exception e) { |
57971 | 366 |
defaultErrorHandler(e); |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
367 |
} finally { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
368 |
Logger.log(LogTag.JFR_SYSTEM_STREAMING, LogLevel.DEBUG, "Execution of stream ended."); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
369 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
370 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
371 |
|
57971 | 372 |
public abstract void process() throws Exception; |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
373 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
374 |
protected final void clearLastDispatch() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
375 |
lastEventDispatch = null; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
376 |
lastEventType = null; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
377 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
378 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
379 |
protected final void dispatch(RecordedEvent event) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
380 |
EventType type = event.getEventType(); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
381 |
EventDispatcher[] ret = null; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
382 |
if (type == lastEventType) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
383 |
ret = lastEventDispatch; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
384 |
} else { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
385 |
ret = configuration.dispatcherLookup.get(type.getId()); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
386 |
if (ret == null) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
387 |
List<EventDispatcher> list = new ArrayList<>(); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
388 |
for (EventDispatcher e : configuration.getDispatchers()) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
389 |
if (e.accepts(type)) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
390 |
list.add(e); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
391 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
392 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
393 |
ret = list.isEmpty() ? NO_DISPATCHERS : list.toArray(new EventDispatcher[0]); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
394 |
configuration.dispatcherLookup.put(type.getId(), ret); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
395 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
396 |
lastEventDispatch = ret; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
397 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
398 |
for (int i = 0; i < ret.length; i++) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
399 |
try { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
400 |
ret[i].offer(event); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
401 |
} catch (Exception e) { |
57971 | 402 |
handleError(e); |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
403 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
404 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
405 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
406 |
|
57971 | 407 |
protected final void handleError(Throwable e) { |
408 |
StreamConfiguration c = configuration; |
|
409 |
if (c.errorActions.length == 0) { |
|
410 |
defaultErrorHandler(e); |
|
411 |
return; |
|
412 |
} |
|
413 |
for (Runnable r : c.errorActions) { |
|
414 |
r.run(); |
|
415 |
} |
|
416 |
} |
|
417 |
||
418 |
protected final void defaultErrorHandler(Throwable e) { |
|
419 |
e.printStackTrace(); |
|
420 |
} |
|
421 |
||
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
422 |
public final void runCloseActions() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
423 |
Runnable[] cas = configuration.getCloseActions(); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
424 |
for (int i = 0; i < cas.length; i++) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
425 |
try { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
426 |
cas[i].run(); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
427 |
} catch (Exception e) { |
57971 | 428 |
handleError(e); |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
429 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
430 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
431 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
432 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
433 |
public final void runFlushActions() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
434 |
Runnable[] fas = configuration.getFlushActions(); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
435 |
for (int i = 0; i < fas.length; i++) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
436 |
try { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
437 |
fas[i].run(); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
438 |
} catch (Exception e) { |
57971 | 439 |
handleError(e); |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
440 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
441 |
} |
57971 | 442 |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
443 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
444 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
445 |
// Purpose of synchronizing the following methods is |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
446 |
// to serialize changes to the configuration, so only one |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
447 |
// thread at a time can change the configuration. |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
448 |
// |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
449 |
// The purpose is not to guard the configuration field. A new |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
450 |
// configuration is published using updateConfiguration |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
451 |
// |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
452 |
public final synchronized boolean remove(Object action) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
453 |
return updateConfiguration(new StreamConfiguration(configuration).remove(action)); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
454 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
455 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
456 |
public final synchronized void onEvent(Consumer<RecordedEvent> action) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
457 |
add(new EventDispatcher(action)); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
458 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
459 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
460 |
public final synchronized void onEvent(String eventName, Consumer<RecordedEvent> action) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
461 |
add(new EventDispatcher(eventName, action)); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
462 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
463 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
464 |
private final synchronized void add(EventDispatcher e) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
465 |
updateConfiguration(new StreamConfiguration(configuration).addDispatcher(e)); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
466 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
467 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
468 |
public final synchronized void onFlush(Runnable action) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
469 |
updateConfiguration(new StreamConfiguration(configuration).addFlushAction(action)); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
470 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
471 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
472 |
public final synchronized void addCloseAction(Runnable action) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
473 |
updateConfiguration(new StreamConfiguration(configuration).addCloseAction(action)); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
474 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
475 |
|
57971 | 476 |
public final synchronized void addErrorAction(Runnable action) { |
477 |
updateConfiguration(new StreamConfiguration(configuration).addErrorAction(action)); |
|
478 |
} |
|
479 |
||
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
480 |
public final synchronized void setClosed(boolean closed) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
481 |
updateConfiguration(new StreamConfiguration(configuration).setClosed(closed)); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
482 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
483 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
484 |
public final synchronized void setReuse(boolean reuse) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
485 |
updateConfiguration(new StreamConfiguration(configuration).setReuse(reuse)); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
486 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
487 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
488 |
public final synchronized void setOrdered(boolean ordered) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
489 |
updateConfiguration(new StreamConfiguration(configuration).setOrdered(ordered)); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
490 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
491 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
492 |
public final synchronized void setStartNanos(long startNanos) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
493 |
updateConfiguration(new StreamConfiguration(configuration).setStartNanos(startNanos)); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
494 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
495 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
496 |
public final synchronized void setStartTime(Instant startTime) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
497 |
Objects.nonNull(startTime); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
498 |
if (configuration.isStarted()) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
499 |
throw new IllegalStateException("Stream is already started"); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
500 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
501 |
if (startTime.isBefore(Instant.EPOCH)) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
502 |
startTime = Instant.EPOCH; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
503 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
504 |
updateConfiguration(new StreamConfiguration(configuration).setStartTime(startTime)); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
505 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
506 |
|
57971 | 507 |
public final synchronized void setEndTime(Instant endTime) { |
508 |
if (configuration.isStarted()) { |
|
509 |
throw new IllegalStateException("Stream is already started"); |
|
510 |
} |
|
511 |
updateConfiguration(new StreamConfiguration(configuration).setEndTime(endTime)); |
|
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
512 |
} |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
513 |
|
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
514 |
protected boolean updateConfiguration(StreamConfiguration newConfiguration) { |
57971 | 515 |
if (!Thread.holdsLock(this)) { |
516 |
throw new InternalError("Modification of configuration without proper lock"); |
|
517 |
} |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
518 |
if (newConfiguration.hasChanged()) { |
57948
59ad17a19e24
Publish configuration using volatile instread fence
egahlin
parents:
57921
diff
changeset
|
519 |
// Publish objects held by configuration object |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
520 |
VarHandle.releaseFence(); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
521 |
configuration = newConfiguration; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
522 |
return true; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
523 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
524 |
return false; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
525 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
526 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
527 |
public final boolean isClosed() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
528 |
return configuration.isClosed(); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
529 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
530 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
531 |
public final void startAsync(long startNanos) { |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
532 |
startInternal(startNanos); |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
533 |
thread.start(); |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
534 |
} |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
535 |
|
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
536 |
public final void start(long startNanos) { |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
537 |
startInternal(startNanos); |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
538 |
run(); |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
539 |
} |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
540 |
|
57971 | 541 |
private synchronized void startInternal(long startNanos) { |
542 |
if (configuration.isStarted()) { |
|
543 |
throw new IllegalStateException("Event stream can only be started once"); |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
544 |
} |
57971 | 545 |
StreamConfiguration c = new StreamConfiguration(configuration); |
546 |
if (active) { |
|
547 |
c.setStartNanos(startNanos); |
|
548 |
} |
|
549 |
c.setStarted(true); |
|
550 |
updateConfiguration(c); |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
551 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
552 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
553 |
public final void awaitTermination(Duration timeout) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
554 |
Objects.requireNonNull(timeout); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
555 |
if (thread != Thread.currentThread()) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
556 |
try { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
557 |
thread.join(timeout.toMillis()); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
558 |
} catch (InterruptedException e) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
559 |
// ignore |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
560 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
561 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
562 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
563 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
564 |
public final void awaitTermination() { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
565 |
awaitTermination(Duration.ofMillis(0)); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
566 |
} |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
567 |
|
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
568 |
abstract public void close(); |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
569 |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
diff
changeset
|
570 |
} |