Skip to content

Commit 752f936

Browse files
author
duke
committed
Backport 65b32394187988abab99a8017eda39b1bd4a1782
1 parent 89c5659 commit 752f936

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/EventDirectoryStream.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ private void processOrdered(Dispatcher c) throws IOException {
257257
}
258258
for (int i = 0; i < index; i++) {
259259
c.dispatch(sortedCache[i]);
260+
sortedCache[i] = null;
261+
}
262+
// Shrink array
263+
if (index > 100_000 && 4 * index < sortedCache.length) {
264+
sortedCache = new RecordedEvent[2 * index];
260265
}
261266
onFlush();
262267
return;

src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/EventFileStream.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ private void processOrdered(Dispatcher c) throws IOException {
127127
cacheSorted[index++] = event;
128128
}
129129
dispatchOrdered(c, index);
130+
if (index > 100_000 && 4 * index < cacheSorted.length) {
131+
cacheSorted = new RecordedEvent[2 * index];
132+
}
133+
onFlush();
130134
index = 0;
131135
}
132136
}
@@ -136,8 +140,8 @@ private void dispatchOrdered(Dispatcher c, int index) {
136140
Arrays.sort(cacheSorted, 0, index, EVENT_COMPARATOR);
137141
for (int i = 0; i < index; i++) {
138142
c.dispatch(cacheSorted[i]);
143+
cacheSorted[i] = null;
139144
}
140-
onFlush();
141145
}
142146

143147
private void processUnordered(Dispatcher c) throws IOException {

0 commit comments

Comments
 (0)