< prev index next >

src/java.base/share/classes/jdk/internal/misc/ThreadFlock.java

Print this page
@@ -29,10 +29,11 @@
  import java.time.Duration;
  import java.util.Objects;
  import java.util.Set;
  import java.util.concurrent.ConcurrentHashMap;
  import java.util.concurrent.TimeoutException;
+ import java.util.concurrent.StructureViolationException;
  import java.util.concurrent.locks.LockSupport;
  import java.util.stream.Stream;
  import jdk.internal.access.JavaLangAccess;
  import jdk.internal.access.SharedSecrets;
  import jdk.internal.vm.ScopedValueContainer;

@@ -85,11 +86,10 @@
      static {
          try {
              MethodHandles.Lookup l = MethodHandles.lookup();
              THREAD_COUNT = l.findVarHandle(ThreadFlock.class, "threadCount", int.class);
              PERMIT = l.findVarHandle(ThreadFlock.class, "permit", boolean.class);
-             Unsafe.getUnsafe().ensureClassInitialized(StructureViolationExceptions.class);
          } catch (Exception e) {
              throw new InternalError(e);
          }
      }
  

@@ -260,12 +260,12 @@
       * @return the thread, started
       * @throws IllegalStateException if this flock is shutdown or closed
       * @throws IllegalThreadStateException if the given thread was already started
       * @throws WrongThreadException if the current thread is not the owner or a thread
       * contained in the flock
-      * @throws jdk.incubator.concurrent.StructureViolationException if the current
-      * scoped value bindings are not the same as when the flock was created
+      * @throws StructureViolationException if the current scoped value bindings are
+      * not the same as when the flock was created
       */
      public Thread start(Thread thread) {
          ensureOwnerOrContainsThread();
          JLA.start(thread, container);
          return thread;

@@ -403,12 +403,11 @@
       * scoped value bindings, and the thread flock was created before the scoped values
       * were bound, then {@code StructureViolationException} is thrown after closing the
       * thread flock.
       *
       * @throws WrongThreadException if invoked by a thread that is not the owner
-      * @throws jdk.incubator.concurrent.StructureViolationException if a structure
-      * violation was detected
+      * @throws StructureViolationException if a structure violation was detected
       */
      public void close() {
          ensureOwner();
          if (closed)
              return;

@@ -511,18 +510,19 @@
              this.flock = flock;
          }
  
          @Override
          public ThreadContainerImpl push() {
-             // Virtual threads in the root containers are not tracked so need
+             // Virtual threads in the root containers may not be tracked so need
              // to register container to ensure that it is found
-             Thread thread = Thread.currentThread();
-             if (thread.isVirtual()
-                     && JLA.threadContainer(thread) == ThreadContainers.root()) {
-                 this.key = ThreadContainers.registerContainer(this);
+             if (!ThreadContainers.trackAllThreads()) {
+                 Thread thread = Thread.currentThread();
+                 if (thread.isVirtual()
+                         && JLA.threadContainer(thread) == ThreadContainers.root()) {
+                     this.key = ThreadContainers.registerContainer(this);
+                 }
              }
- 
              super.push();
              return this;
          }
  
          /**

@@ -536,11 +536,11 @@
                  boolean atTop = popForcefully(); // may block
                  Object key = this.key;
                  if (key != null)
                      ThreadContainers.deregisterContainer(key);
                  if (!atTop)
-                     StructureViolationExceptions.throwException();
+                     throw new StructureViolationException();
              }
          }
  
          /**
           * Invoked when an enclosing scope is closing. Invokes ThreadFlock.close to

@@ -561,10 +561,14 @@
                  assert false : "Should not get there";
                  return false;
              }
          }
  
+         @Override
+         public String name() {
+             return flock.name();
+         }
          @Override
          public long threadCount() {
              return flock.threadCount();
          }
          @Override

@@ -578,14 +582,10 @@
          @Override
          public void onExit(Thread thread) {
              flock.onExit(thread);
          }
          @Override
-         public String toString() {
-             return flock.toString();
-         }
-         @Override
          public ScopedValueContainer.BindingsSnapshot scopedValueBindings() {
              return flock.scopedValueBindings();
          }
      }
  }
< prev index next >