Add support for stream in stream with exclusion JEP-349-branch
authoregahlin
Fri, 11 Oct 2019 20:20:12 +0200
branchJEP-349-branch
changeset 58571 3d823192d9ca
parent 58570 12bf92ce7991
child 58572 0d3ae8536b83
Add support for stream in stream with exclusion
src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/EventDirectoryStream.java
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/EventDirectoryStream.java	Fri Oct 11 20:19:08 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/EventDirectoryStream.java	Fri Oct 11 20:20:12 2019 +0200
@@ -54,6 +54,7 @@
     private ChunkParser currentParser;
     private long currentChunkStartNanos;
     private RecordedEvent[] sortedCache;
+    private int threadExclusionLevel = 0;
 
     public EventDirectoryStream(AccessControlContext acc, Path p, FileAccess fileAccess, boolean active) throws IOException {
         super(acc, active);
@@ -81,11 +82,21 @@
 
     @Override
     protected void process() throws IOException {
+        JVM jvm = JVM.getJVM();
+        Thread t = Thread.currentThread();
         try {
-            JVM.getJVM().exclude(Thread.currentThread());
+            if (jvm.isExcluded(t)) {
+                threadExclusionLevel++;
+            } else {
+                jvm.exclude(t);
+            }
             processRecursionSafe();
         } finally {
-            JVM.getJVM().include(Thread.currentThread());
+            if (threadExclusionLevel > 0) {
+                threadExclusionLevel--;
+            } else {
+                jvm.include(t);
+            }
         }
     }