< prev index next > src/java.base/share/classes/java/lang/System.java
Print this page
import java.util.function.Supplier;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;
import jdk.internal.logger.LoggerFinderLoader.TemporaryLoggerFinder;
+ import jdk.internal.misc.Blocker;
import jdk.internal.misc.CarrierThreadLocal;
import jdk.internal.misc.Unsafe;
import jdk.internal.util.StaticProperty;
import jdk.internal.module.ModuleBootstrap;
import jdk.internal.module.ServicesCatalog;
StaticProperty.javaHome(); // Load StaticProperty to cache the property values
lineSeparator = props.getProperty("line.separator");
- FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
- FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
- FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
+ FileInputStream fdIn = new In(FileDescriptor.in);
+ FileOutputStream fdOut = new Out(FileDescriptor.out);
+ FileOutputStream fdErr = new Out(FileDescriptor.err);
initialIn = new BufferedInputStream(fdIn);
setIn0(initialIn);
// stdout/err.encoding are set when the VM is associated with the terminal,
// thus they are equivalent to Console.charset(), otherwise the encodings
// of those properties default to native.encoding
// system properties, java.lang and other core classes are now initialized
VM.initLevel(1);
}
+ /**
+ * System.in.
+ */
+ private static class In extends FileInputStream {
+ In(FileDescriptor fd) {
+ super(fd);
+ }
+
+ @Override
+ public int read() throws IOException {
+ boolean attempted = Blocker.begin();
+ try {
+ return super.read();
+ } finally {
+ Blocker.end(attempted);
+ }
+ }
+
+ @Override
+ public int read(byte[] b) throws IOException {
+ boolean attempted = Blocker.begin();
+ try {
+ return super.read(b);
+ } finally {
+ Blocker.end(attempted);
+ }
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ boolean attempted = Blocker.begin();
+ try {
+ return super.read(b, off, len);
+ } finally {
+ Blocker.end(attempted);
+ }
+ }
+ }
+
+ /**
+ * System.out/System.err wrap this output stream.
+ */
+ private static class Out extends FileOutputStream {
+ Out(FileDescriptor fd) {
+ super(fd);
+ }
+
+ @Override
+ public void write(int b) throws IOException {
+ boolean attempted = Blocker.begin();
+ try {
+ super.write(b);
+ } finally {
+ Blocker.end(attempted);
+ }
+ }
+
+ @Override
+ public void write(byte[] b) throws IOException {
+ boolean attempted = Blocker.begin();
+ try {
+ super.write(b);
+ } finally {
+ Blocker.end(attempted);
+ }
+ }
+
+ @Override
+ public void write(byte[] b, int off, int len) throws IOException {
+ boolean attempted = Blocker.begin();
+ try {
+ super.write(b, off, len);
+ } finally {
+ Blocker.end(attempted);
+ }
+ }
+ }
+
// @see #initPhase2()
static ModuleLayer bootLayer;
/*
* Invoked by VM. Phase 2 module system initialization.
public Thread currentCarrierThread() {
return Thread.currentCarrierThread();
}
- public <V> V executeOnCarrierThread(Callable<V> task) throws Exception {
- if (Thread.currentThread() instanceof VirtualThread vthread) {
- return vthread.executeOnCarrierThread(task);
- } else {
- return task.call();
- }
- }
-
public <T> T getCarrierThreadLocal(CarrierThreadLocal<T> local) {
return ((ThreadLocal<T>)local).getCarrierThreadLocal();
}
public <T> void setCarrierThreadLocal(CarrierThreadLocal<T> local, T value) {
< prev index next >