< prev index next >

src/java.base/share/classes/java/lang/System.java

Print this page
@@ -30,10 +30,11 @@
  import java.io.FileDescriptor;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
+ import java.io.OutputStream;
  import java.io.PrintStream;
  import java.io.UnsupportedEncodingException;
  import java.lang.annotation.Annotation;
  import java.lang.invoke.MethodHandle;
  import java.lang.invoke.MethodType;

@@ -61,10 +62,11 @@
  import java.util.Properties;
  import java.util.PropertyPermission;
  import java.util.ResourceBundle;
  import java.util.Set;
  import java.util.WeakHashMap;
+ import java.util.concurrent.Callable;
  import java.util.function.Supplier;
  import java.util.concurrent.ConcurrentHashMap;
  import java.util.stream.Stream;
  import jdk.internal.misc.Unsafe;
  import jdk.internal.util.StaticProperty;

@@ -77,12 +79,17 @@
  import jdk.internal.misc.VM;
  import jdk.internal.logger.LoggerFinderLoader;
  import jdk.internal.logger.LazyLoggers;
  import jdk.internal.logger.LocalizedLoggerWrapper;
  import jdk.internal.util.SystemProps;
+ import jdk.internal.vm.Continuation;
+ import jdk.internal.vm.ContinuationScope;
+ import jdk.internal.vm.ThreadContainer;
  import jdk.internal.vm.annotation.IntrinsicCandidate;
  import jdk.internal.vm.annotation.Stable;
+ import jdk.internal.vm.annotation.ChangesCurrentThread;
+ import sun.nio.ch.ConsoleStreams;
  import sun.nio.fs.DefaultFileSystemProvider;
  import sun.reflect.annotation.AnnotationType;
  import sun.nio.ch.Interruptible;
  import sun.security.util.SecurityConstants;
  

@@ -2012,17 +2019,17 @@
      public static native String mapLibraryName(String libname);
  
      /**
       * Create PrintStream for stdout/err based on encoding.
       */
-     private static PrintStream newPrintStream(FileOutputStream fos, String enc) {
+     private static PrintStream newPrintStream(OutputStream out, String enc) {
         if (enc != null) {
              try {
-                 return new PrintStream(new BufferedOutputStream(fos, 128), true, enc);
+                 return new PrintStream(new BufferedOutputStream(out, 128), true, enc);
              } catch (UnsupportedEncodingException uee) {}
          }
-         return new PrintStream(new BufferedOutputStream(fos, 128), true);
+         return new PrintStream(new BufferedOutputStream(out, 128), true);
      }
  
      /**
       * Logs an exception/error at initialization time to stdout or stderr.
       *

@@ -2123,25 +2130,23 @@
          // thus they are equivalent to Console.charset(), otherwise the encoding
          // defaults to native.encoding
          setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding", StaticProperty.nativeEncoding())));
          setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding", StaticProperty.nativeEncoding())));
  
+ //        setIn0(new BufferedInputStream(ConsoleStreams.in));
+ //        setOut0(newPrintStream(ConsoleStreams.out, props.getProperty("sun.stdout.encoding")));
+ //        setErr0(newPrintStream(ConsoleStreams.err, props.getProperty("sun.stderr.encoding")));
+ 
          // Setup Java signal handlers for HUP, TERM, and INT (where available).
          Terminator.setup();
  
          // Initialize any miscellaneous operating system settings that need to be
          // set for the class libraries. Currently this is no-op everywhere except
          // for Windows where the process-wide error mode is set before the java.io
          // classes are used.
          VM.initializeOSEnvironment();
  
-         // The main thread is not added to its thread group in the same
-         // way as other threads; we must do it ourselves here.
-         Thread current = Thread.currentThread();
-         current.getThreadGroup().add(current);
- 
- 
          // Subsystems that are invoked during initialization can invoke
          // VM.isBooted() in order to avoid doing things that should
          // wait until the VM is fully initialized. The initialization level
          // is incremented from 0 to 1 here to indicate the first phase of
          // initialization has completed.

@@ -2424,15 +2429,15 @@
              }
  
              public void setCause(Throwable t, Throwable cause) {
                  t.setCause(cause);
              }
- 
+             
              public ProtectionDomain protectionDomain(Class<?> c) {
                  return c.protectionDomain();
              }
- 
+             
              public MethodHandle stringConcatHelper(String name, MethodType methodType) {
                  return StringConcatHelper.lookupStatic(name, methodType);
              }
  
              public long stringConcatInitialCoder() {

@@ -2458,8 +2463,94 @@
  
              @Override
              public void exit(int statusCode) {
                  Shutdown.exit(statusCode);
              }
+             
+             public Thread[] getAllThreads() {
+                 return Thread.getAllThreads();
+             }
+ 
+             public ThreadContainer threadContainer(Thread thread) {
+                 return thread.threadContainer();
+             }
+ 
+             public void start(Thread thread, ThreadContainer container) {
+                 thread.start(container);
+             }
+ 
+             public ThreadContainer headThreadContainer(Thread thread) {
+                 return thread.headThreadContainer();
+             }
+ 
+             public Object pushThreadContainer(ThreadContainer container) {
+                 return Thread.currentThread().pushThreadContainer(container);
+             }
+ 
+             public void popThreadContainer(ThreadContainer container) {
+                 Thread.currentThread().popThreadContainer(container);
+             }
+ 
+             public Thread currentCarrierThread() {
+                 return Thread.currentCarrierThread();
+             }
+ 
+             @ChangesCurrentThread
+             public <V> V executeOnCarrierThread(Callable<V> task) throws Exception {
+                 Thread thread = Thread.currentThread();
+                 if (thread.isVirtual()) {
+                     Thread carrier = Thread.currentCarrierThread();
+                     carrier.setCurrentThread(carrier);
+                     try {
+                         return task.call();
+                     } finally {
+                         carrier.setCurrentThread(thread);
+                     }
+                 } else {
+                     return task.call();
+                 }
+             }
+ 
+             public <T> T getCarrierThreadLocal(ThreadLocal<T> local) {
+                 return local.getCarrierThreadLocal();
+             }
+ 
+             public <T> void setCarrierThreadLocal(ThreadLocal<T> local, T value) {
+                 local.setCarrierThreadLocal(value);
+             }
+ 
+             public Object[] scopeLocalCache() {
+                 return Thread.scopeLocalCache();
+             }
+ 
+             public void setScopeLocalCache(Object[] cache) {
+                 Thread.setScopeLocalCache(cache);
+             }
+ 
+             public Continuation getContinuation(Thread thread) {
+                 return thread.getContinuation();
+             }
+ 
+             public void setContinuation(Thread thread, Continuation continuation) {
+                 thread.setContinuation(continuation);
+             }
+ 
+             public void parkVirtualThread() {
+                 ((VirtualThread) Thread.currentThread()).park();
+             }
+ 
+             public void parkVirtualThread(long nanos) {
+                 ((VirtualThread) Thread.currentThread()).parkNanos(nanos);
+             }
+ 
+             public void unparkVirtualThread(Thread thread) {
+                 ((VirtualThread) thread).unpark();
+             }
+ 
+             public StackWalker newStackWalkerInstance(Set<StackWalker.Option> options,
+                                                       ContinuationScope contScope,
+                                                       Continuation continuation) {
+                 return StackWalker.newInstance(options, null, contScope, continuation);
+             }
          });
      }
  }
< prev index next >