< prev index next >

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

Print this page

  48 import java.net.URL;
  49 import java.nio.channels.Channel;
  50 import java.nio.channels.spi.SelectorProvider;
  51 import java.nio.charset.CharacterCodingException;
  52 import java.nio.charset.Charset;
  53 import java.security.AccessControlContext;
  54 import java.security.AccessController;
  55 import java.security.CodeSource;
  56 import java.security.PrivilegedAction;
  57 import java.security.ProtectionDomain;
  58 import java.util.Collections;
  59 import java.util.List;
  60 import java.util.Locale;
  61 import java.util.Map;
  62 import java.util.Objects;
  63 import java.util.Properties;
  64 import java.util.PropertyPermission;
  65 import java.util.ResourceBundle;
  66 import java.util.Set;
  67 import java.util.WeakHashMap;
  68 import java.util.concurrent.Callable;

  69 import java.util.function.Supplier;
  70 import java.util.concurrent.ConcurrentHashMap;
  71 import java.util.stream.Stream;
  72 
  73 import jdk.internal.logger.LoggerFinderLoader.TemporaryLoggerFinder;
  74 import jdk.internal.misc.Blocker;
  75 import jdk.internal.misc.CarrierThreadLocal;
  76 import jdk.internal.misc.Unsafe;
  77 import jdk.internal.util.StaticProperty;
  78 import jdk.internal.module.ModuleBootstrap;
  79 import jdk.internal.module.ServicesCatalog;
  80 import jdk.internal.reflect.CallerSensitive;
  81 import jdk.internal.reflect.Reflection;
  82 import jdk.internal.access.JavaLangAccess;
  83 import jdk.internal.access.SharedSecrets;
  84 import jdk.internal.logger.LoggerFinderLoader;
  85 import jdk.internal.logger.LazyLoggers;
  86 import jdk.internal.logger.LocalizedLoggerWrapper;
  87 import jdk.internal.misc.VM;
  88 import jdk.internal.util.SystemProps;

2247 
2248         @Override
2249         public int read(byte[] b, int off, int len) throws IOException {
2250             boolean attempted = Blocker.begin();
2251             try {
2252                 return super.read(b, off, len);
2253             } finally {
2254                 Blocker.end(attempted);
2255             }
2256         }
2257     }
2258 
2259     /**
2260      * System.out/System.err wrap this output stream.
2261      */
2262     private static class Out extends FileOutputStream {
2263         Out(FileDescriptor fd) {
2264             super(fd);
2265         }
2266 

2267         public void write(int b) throws IOException {
2268             boolean attempted = Blocker.begin();
2269             try {
2270                 super.write(b);
2271             } finally {
2272                 Blocker.end(attempted);
2273             }
2274         }
2275 
2276         @Override
2277         public void write(byte[] b) throws IOException {
2278             boolean attempted = Blocker.begin();
2279             try {
2280                 super.write(b);
2281             } finally {
2282                 Blocker.end(attempted);
2283             }
2284         }
2285 
2286         @Override

2664             public ThreadContainer threadContainer(Thread thread) {
2665                 return thread.threadContainer();
2666             }
2667 
2668             public void start(Thread thread, ThreadContainer container) {
2669                 thread.start(container);
2670             }
2671 
2672             public StackableScope headStackableScope(Thread thread) {
2673                 return thread.headStackableScopes();
2674             }
2675 
2676             public void setHeadStackableScope(StackableScope scope) {
2677                 Thread.setHeadStackableScope(scope);
2678             }
2679 
2680             public Thread currentCarrierThread() {
2681                 return Thread.currentCarrierThread();
2682             }
2683 
2684             public <V> V executeOnCarrierThread(Callable<V> task) throws Exception {
2685                 if (Thread.currentThread() instanceof VirtualThread vthread) {
2686                     return vthread.executeOnCarrierThread(task);
2687                 } else {
2688                     return task.call();
2689                 }
2690             }
2691 
2692             public <T> T getCarrierThreadLocal(CarrierThreadLocal<T> local) {
2693                 return ((ThreadLocal<T>)local).getCarrierThreadLocal();
2694             }
2695 
2696             public <T> void setCarrierThreadLocal(CarrierThreadLocal<T> local, T value) {
2697                 ((ThreadLocal<T>)local).setCarrierThreadLocal(value);
2698             }
2699 
2700             public void removeCarrierThreadLocal(CarrierThreadLocal<?> local) {
2701                 ((ThreadLocal<?>)local).removeCarrierThreadLocal();
2702             }
2703 
2704             public boolean isCarrierThreadLocalPresent(CarrierThreadLocal<?> local) {
2705                 return ((ThreadLocal<?>)local).isCarrierThreadLocalPresent();
2706             }
2707 
2708             public Object[] scopedValueCache() {
2709                 return Thread.scopedValueCache();
2710             }
2711 

2738                 }
2739             }
2740 
2741             public void parkVirtualThread(long nanos) {
2742                 Thread thread = Thread.currentThread();
2743                 if (thread instanceof BaseVirtualThread vthread) {
2744                     vthread.parkNanos(nanos);
2745                 } else {
2746                     throw new WrongThreadException();
2747                 }
2748             }
2749 
2750             public void unparkVirtualThread(Thread thread) {
2751                 if (thread instanceof BaseVirtualThread vthread) {
2752                     vthread.unpark();
2753                 } else {
2754                     throw new WrongThreadException();
2755                 }
2756             }
2757 








2758             public StackWalker newStackWalkerInstance(Set<StackWalker.Option> options,
2759                                                       ContinuationScope contScope,
2760                                                       Continuation continuation) {
2761                 return StackWalker.newInstance(options, null, contScope, continuation);
2762             }
2763 
2764             public String getLoaderNameID(ClassLoader loader) {
2765                 return loader != null ? loader.nameAndId() : "null";
2766             }
2767 
2768             @Override
2769             public void copyToSegmentRaw(String string, MemorySegment segment, long offset) {
2770                 string.copyToSegmentRaw(segment, offset);
2771             }
2772 
2773             @Override
2774             public boolean bytesCompatible(String string, Charset charset) {
2775                 return string.bytesCompatible(charset);
2776             }
2777 

  48 import java.net.URL;
  49 import java.nio.channels.Channel;
  50 import java.nio.channels.spi.SelectorProvider;
  51 import java.nio.charset.CharacterCodingException;
  52 import java.nio.charset.Charset;
  53 import java.security.AccessControlContext;
  54 import java.security.AccessController;
  55 import java.security.CodeSource;
  56 import java.security.PrivilegedAction;
  57 import java.security.ProtectionDomain;
  58 import java.util.Collections;
  59 import java.util.List;
  60 import java.util.Locale;
  61 import java.util.Map;
  62 import java.util.Objects;
  63 import java.util.Properties;
  64 import java.util.PropertyPermission;
  65 import java.util.ResourceBundle;
  66 import java.util.Set;
  67 import java.util.WeakHashMap;
  68 import java.util.concurrent.Executor;
  69 import java.util.concurrent.ScheduledExecutorService;
  70 import java.util.function.Supplier;
  71 import java.util.concurrent.ConcurrentHashMap;
  72 import java.util.stream.Stream;
  73 
  74 import jdk.internal.logger.LoggerFinderLoader.TemporaryLoggerFinder;
  75 import jdk.internal.misc.Blocker;
  76 import jdk.internal.misc.CarrierThreadLocal;
  77 import jdk.internal.misc.Unsafe;
  78 import jdk.internal.util.StaticProperty;
  79 import jdk.internal.module.ModuleBootstrap;
  80 import jdk.internal.module.ServicesCatalog;
  81 import jdk.internal.reflect.CallerSensitive;
  82 import jdk.internal.reflect.Reflection;
  83 import jdk.internal.access.JavaLangAccess;
  84 import jdk.internal.access.SharedSecrets;
  85 import jdk.internal.logger.LoggerFinderLoader;
  86 import jdk.internal.logger.LazyLoggers;
  87 import jdk.internal.logger.LocalizedLoggerWrapper;
  88 import jdk.internal.misc.VM;
  89 import jdk.internal.util.SystemProps;

2248 
2249         @Override
2250         public int read(byte[] b, int off, int len) throws IOException {
2251             boolean attempted = Blocker.begin();
2252             try {
2253                 return super.read(b, off, len);
2254             } finally {
2255                 Blocker.end(attempted);
2256             }
2257         }
2258     }
2259 
2260     /**
2261      * System.out/System.err wrap this output stream.
2262      */
2263     private static class Out extends FileOutputStream {
2264         Out(FileDescriptor fd) {
2265             super(fd);
2266         }
2267 
2268         @Override
2269         public void write(int b) throws IOException {
2270             boolean attempted = Blocker.begin();
2271             try {
2272                 super.write(b);
2273             } finally {
2274                 Blocker.end(attempted);
2275             }
2276         }
2277 
2278         @Override
2279         public void write(byte[] b) throws IOException {
2280             boolean attempted = Blocker.begin();
2281             try {
2282                 super.write(b);
2283             } finally {
2284                 Blocker.end(attempted);
2285             }
2286         }
2287 
2288         @Override

2666             public ThreadContainer threadContainer(Thread thread) {
2667                 return thread.threadContainer();
2668             }
2669 
2670             public void start(Thread thread, ThreadContainer container) {
2671                 thread.start(container);
2672             }
2673 
2674             public StackableScope headStackableScope(Thread thread) {
2675                 return thread.headStackableScopes();
2676             }
2677 
2678             public void setHeadStackableScope(StackableScope scope) {
2679                 Thread.setHeadStackableScope(scope);
2680             }
2681 
2682             public Thread currentCarrierThread() {
2683                 return Thread.currentCarrierThread();
2684             }
2685 








2686             public <T> T getCarrierThreadLocal(CarrierThreadLocal<T> local) {
2687                 return ((ThreadLocal<T>)local).getCarrierThreadLocal();
2688             }
2689 
2690             public <T> void setCarrierThreadLocal(CarrierThreadLocal<T> local, T value) {
2691                 ((ThreadLocal<T>)local).setCarrierThreadLocal(value);
2692             }
2693 
2694             public void removeCarrierThreadLocal(CarrierThreadLocal<?> local) {
2695                 ((ThreadLocal<?>)local).removeCarrierThreadLocal();
2696             }
2697 
2698             public boolean isCarrierThreadLocalPresent(CarrierThreadLocal<?> local) {
2699                 return ((ThreadLocal<?>)local).isCarrierThreadLocalPresent();
2700             }
2701 
2702             public Object[] scopedValueCache() {
2703                 return Thread.scopedValueCache();
2704             }
2705 

2732                 }
2733             }
2734 
2735             public void parkVirtualThread(long nanos) {
2736                 Thread thread = Thread.currentThread();
2737                 if (thread instanceof BaseVirtualThread vthread) {
2738                     vthread.parkNanos(nanos);
2739                 } else {
2740                     throw new WrongThreadException();
2741                 }
2742             }
2743 
2744             public void unparkVirtualThread(Thread thread) {
2745                 if (thread instanceof BaseVirtualThread vthread) {
2746                     vthread.unpark();
2747                 } else {
2748                     throw new WrongThreadException();
2749                 }
2750             }
2751 
2752             public Executor virtualThreadDefaultScheduler() {
2753                 return VirtualThread.defaultScheduler();
2754             }
2755 
2756             public Stream<ScheduledExecutorService> virtualThreadDelayedTaskSchedulers() {
2757                 return VirtualThread.delayedTaskSchedulers();
2758             }
2759 
2760             public StackWalker newStackWalkerInstance(Set<StackWalker.Option> options,
2761                                                       ContinuationScope contScope,
2762                                                       Continuation continuation) {
2763                 return StackWalker.newInstance(options, null, contScope, continuation);
2764             }
2765 
2766             public String getLoaderNameID(ClassLoader loader) {
2767                 return loader != null ? loader.nameAndId() : "null";
2768             }
2769 
2770             @Override
2771             public void copyToSegmentRaw(String string, MemorySegment segment, long offset) {
2772                 string.copyToSegmentRaw(segment, offset);
2773             }
2774 
2775             @Override
2776             public boolean bytesCompatible(String string, Charset charset) {
2777                 return string.bytesCompatible(charset);
2778             }
2779 
< prev index next >