72 import jdk.internal.misc.Unsafe;
73 import jdk.internal.util.StaticProperty;
74 import jdk.internal.module.ModuleBootstrap;
75 import jdk.internal.module.ServicesCatalog;
76 import jdk.internal.reflect.CallerSensitive;
77 import jdk.internal.reflect.Reflection;
78 import jdk.internal.access.JavaLangAccess;
79 import jdk.internal.access.SharedSecrets;
80 import jdk.internal.misc.VM;
81 import jdk.internal.logger.LoggerFinderLoader;
82 import jdk.internal.logger.LazyLoggers;
83 import jdk.internal.logger.LocalizedLoggerWrapper;
84 import jdk.internal.util.SystemProps;
85 import jdk.internal.vm.Continuation;
86 import jdk.internal.vm.ContinuationScope;
87 import jdk.internal.vm.StackableScope;
88 import jdk.internal.vm.ThreadContainer;
89 import jdk.internal.vm.annotation.ForceInline;
90 import jdk.internal.vm.annotation.IntrinsicCandidate;
91 import jdk.internal.vm.annotation.Stable;
92 import jdk.internal.vm.annotation.ChangesCurrentThread;
93 import sun.nio.fs.DefaultFileSystemProvider;
94 import sun.reflect.annotation.AnnotationType;
95 import sun.nio.ch.Interruptible;
96 import sun.nio.cs.UTF_8;
97 import sun.security.util.SecurityConstants;
98
99 /**
100 * The {@code System} class contains several useful class fields
101 * and methods. It cannot be instantiated.
102 *
103 * Among the facilities provided by the {@code System} class
104 * are standard input, standard output, and error output streams;
105 * access to externally defined properties and environment
106 * variables; a means of loading files and libraries; and a utility
107 * method for quickly copying a portion of an array.
108 *
109 * @since 1.0
110 */
111 public final class System {
112 /* Register the natives via the static initializer.
2546 public ThreadContainer threadContainer(Thread thread) {
2547 return thread.threadContainer();
2548 }
2549
2550 public void start(Thread thread, ThreadContainer container) {
2551 thread.start(container);
2552 }
2553
2554 public StackableScope headStackableScope(Thread thread) {
2555 return thread.headStackableScopes();
2556 }
2557
2558 public void setHeadStackableScope(StackableScope scope) {
2559 Thread.setHeadStackableScope(scope);
2560 }
2561
2562 public Thread currentCarrierThread() {
2563 return Thread.currentCarrierThread();
2564 }
2565
2566 @ChangesCurrentThread
2567 public <V> V executeOnCarrierThread(Callable<V> task) throws Exception {
2568 Thread thread = Thread.currentThread();
2569 if (thread.isVirtual()) {
2570 Thread carrier = Thread.currentCarrierThread();
2571 carrier.setCurrentThread(carrier);
2572 try {
2573 return task.call();
2574 } finally {
2575 carrier.setCurrentThread(thread);
2576 }
2577 } else {
2578 return task.call();
2579 }
2580 }
2581
2582 public <T> T getCarrierThreadLocal(CarrierThreadLocal<T> local) {
2583 return ((ThreadLocal<T>)local).getCarrierThreadLocal();
2584 }
2585
2586 public <T> void setCarrierThreadLocal(CarrierThreadLocal<T> local, T value) {
2587 ((ThreadLocal<T>)local).setCarrierThreadLocal(value);
2588 }
2589
2590 public void removeCarrierThreadLocal(CarrierThreadLocal<?> local) {
2591 ((ThreadLocal<?>)local).removeCarrierThreadLocal();
2592 }
2593
2594 public boolean isCarrierThreadLocalPresent(CarrierThreadLocal<?> local) {
2595 return ((ThreadLocal<?>)local).isCarrierThreadLocalPresent();
2596 }
2597
2598 public Object[] scopedValueCache() {
2599 return Thread.scopedValueCache();
2600 }
2601
2602 public void setScopedValueCache(Object[] cache) {
2603 Thread.setScopedValueCache(cache);
2604 }
2605
2606 public Object scopedValueBindings() {
2607 return Thread.scopedValueBindings();
2608 }
2609
2610 public Object findScopedValueBindings() {
2611 return Thread.findScopedValueBindings();
2612 }
2613
2614 public void setScopedValueBindings(Object bindings) {
2615 Thread.setScopedValueBindings(bindings);
2616 }
2617
2618 @ForceInline
2619 public void ensureMaterializedForStackWalk(Object value) {
2620 Thread.ensureMaterializedForStackWalk(value);
2621 }
2622
2623 public Continuation getContinuation(Thread thread) {
2624 return thread.getContinuation();
2625 }
2626
2627 public void setContinuation(Thread thread, Continuation continuation) {
2628 thread.setContinuation(continuation);
2629 }
2630
2631 public ContinuationScope virtualThreadContinuationScope() {
2632 return VirtualThread.continuationScope();
2633 }
2634
2635 public void parkVirtualThread() {
2636 Thread thread = Thread.currentThread();
2637 if (thread instanceof BaseVirtualThread vthread) {
2638 vthread.park();
2639 } else {
2640 throw new WrongThreadException();
2641 }
2642 }
|
72 import jdk.internal.misc.Unsafe;
73 import jdk.internal.util.StaticProperty;
74 import jdk.internal.module.ModuleBootstrap;
75 import jdk.internal.module.ServicesCatalog;
76 import jdk.internal.reflect.CallerSensitive;
77 import jdk.internal.reflect.Reflection;
78 import jdk.internal.access.JavaLangAccess;
79 import jdk.internal.access.SharedSecrets;
80 import jdk.internal.misc.VM;
81 import jdk.internal.logger.LoggerFinderLoader;
82 import jdk.internal.logger.LazyLoggers;
83 import jdk.internal.logger.LocalizedLoggerWrapper;
84 import jdk.internal.util.SystemProps;
85 import jdk.internal.vm.Continuation;
86 import jdk.internal.vm.ContinuationScope;
87 import jdk.internal.vm.StackableScope;
88 import jdk.internal.vm.ThreadContainer;
89 import jdk.internal.vm.annotation.ForceInline;
90 import jdk.internal.vm.annotation.IntrinsicCandidate;
91 import jdk.internal.vm.annotation.Stable;
92 import sun.nio.fs.DefaultFileSystemProvider;
93 import sun.reflect.annotation.AnnotationType;
94 import sun.nio.ch.Interruptible;
95 import sun.nio.cs.UTF_8;
96 import sun.security.util.SecurityConstants;
97
98 /**
99 * The {@code System} class contains several useful class fields
100 * and methods. It cannot be instantiated.
101 *
102 * Among the facilities provided by the {@code System} class
103 * are standard input, standard output, and error output streams;
104 * access to externally defined properties and environment
105 * variables; a means of loading files and libraries; and a utility
106 * method for quickly copying a portion of an array.
107 *
108 * @since 1.0
109 */
110 public final class System {
111 /* Register the natives via the static initializer.
2545 public ThreadContainer threadContainer(Thread thread) {
2546 return thread.threadContainer();
2547 }
2548
2549 public void start(Thread thread, ThreadContainer container) {
2550 thread.start(container);
2551 }
2552
2553 public StackableScope headStackableScope(Thread thread) {
2554 return thread.headStackableScopes();
2555 }
2556
2557 public void setHeadStackableScope(StackableScope scope) {
2558 Thread.setHeadStackableScope(scope);
2559 }
2560
2561 public Thread currentCarrierThread() {
2562 return Thread.currentCarrierThread();
2563 }
2564
2565 public <V> V executeOnCarrierThread(Callable<V> task) throws Exception {
2566 if (Thread.currentThread() instanceof VirtualThread vthread) {
2567 return vthread.executeOnCarrierThread(task);
2568 } else {
2569 return task.call();
2570 }
2571 }
2572
2573 public <T> T getCarrierThreadLocal(CarrierThreadLocal<T> local) {
2574 return ((ThreadLocal<T>)local).getCarrierThreadLocal();
2575 }
2576
2577 public <T> void setCarrierThreadLocal(CarrierThreadLocal<T> local, T value) {
2578 ((ThreadLocal<T>)local).setCarrierThreadLocal(value);
2579 }
2580
2581 public void removeCarrierThreadLocal(CarrierThreadLocal<?> local) {
2582 ((ThreadLocal<?>)local).removeCarrierThreadLocal();
2583 }
2584
2585 public boolean isCarrierThreadLocalPresent(CarrierThreadLocal<?> local) {
2586 return ((ThreadLocal<?>)local).isCarrierThreadLocalPresent();
2587 }
2588
2589 public Object[] scopedValueCache() {
2590 return Thread.scopedValueCache();
2591 }
2592
2593 public void setScopedValueCache(Object[] cache) {
2594 Thread.setScopedValueCache(cache);
2595 }
2596
2597 public Object scopedValueBindings() {
2598 return Thread.scopedValueBindings();
2599 }
2600
2601 public Continuation getContinuation(Thread thread) {
2602 return thread.getContinuation();
2603 }
2604
2605 public void setContinuation(Thread thread, Continuation continuation) {
2606 thread.setContinuation(continuation);
2607 }
2608
2609 public ContinuationScope virtualThreadContinuationScope() {
2610 return VirtualThread.continuationScope();
2611 }
2612
2613 public void parkVirtualThread() {
2614 Thread thread = Thread.currentThread();
2615 if (thread instanceof BaseVirtualThread vthread) {
2616 vthread.park();
2617 } else {
2618 throw new WrongThreadException();
2619 }
2620 }
|