< prev index next >

src/java.base/share/classes/jdk/internal/vm/SharedThreadContainer.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this

@@ -24,14 +24,12 @@
   */
  package jdk.internal.vm;
  
  import java.lang.invoke.MethodHandles;
  import java.lang.invoke.VarHandle;
- import java.util.Objects;
  import java.util.Set;
  import java.util.concurrent.ConcurrentHashMap;
- import java.util.concurrent.atomic.LongAdder;
  import java.util.stream.Stream;
  import jdk.internal.access.JavaLangAccess;
  import jdk.internal.access.SharedSecrets;
  
  /**

@@ -48,20 +46,17 @@
              CLOSED = l.findVarHandle(SharedThreadContainer.class,
                      "closed", boolean.class);
              VIRTUAL_THREADS = l.findVarHandle(SharedThreadContainer.class,
                      "virtualThreads", Set.class);
          } catch (Exception e) {
-             throw new InternalError(e);
+             throw new ExceptionInInitializerError(e);
          }
      }
  
      // name of container, used by toString
      private final String name;
  
-     // the number of threads in the container
-     private final LongAdder threadCount;
- 
      // the virtual threads in the container, created lazily
      private volatile Set<Thread> virtualThreads;
  
      // the key for this container in the registry
      private volatile Object key;

@@ -74,11 +69,10 @@
       * @param name the container name, can be null
       */
      private SharedThreadContainer(String name) {
          super(/*shared*/ true);
          this.name = name;
-         this.threadCount = new LongAdder();
      }
  
      /**
       * Creates a shared thread container with the given parent and name.
       * @throws IllegalArgumentException if the parent has an owner.

@@ -98,10 +92,15 @@
       */
      public static SharedThreadContainer create(String name) {
          return create(ThreadContainers.root(), name);
      }
  
+     @Override
+     public String name() {
+         return name;
+     }
+ 
      @Override
      public Thread owner() {
          return null;
      }
  

@@ -117,25 +116,18 @@
                      vthreads = this.virtualThreads;
                  }
              }
              vthreads.add(thread);
          }
-         threadCount.add(1L);
      }
  
      @Override
      public void onExit(Thread thread) {
-         threadCount.add(-1L);
          if (thread.isVirtual())
              virtualThreads.remove(thread);
      }
  
-     @Override
-     public long threadCount() {
-         return threadCount.sum();
-     }
- 
      @Override
      public Stream<Thread> threads() {
          // live platform threads in this container
          Stream<Thread> platformThreads = Stream.of(JLA.getAllThreads())
                  .filter(t -> JLA.threadContainer(t) == this);

@@ -169,16 +161,6 @@
      public void close() {
          if (!closed && CLOSED.compareAndSet(this, false, true)) {
              ThreadContainers.deregisterContainer(key);
          }
      }
- 
-     @Override
-     public String toString() {
-         String id = Objects.toIdentityString(this);
-         if (name != null) {
-             return name + "/" + id;
-         } else {
-             return id;
-         }
-     }
  }
< prev index next >