8284161: Implementation of Virtual Threads (Preview)

Co-authored-by: Ron Pressler <rpressler@openjdk.org>
Co-authored-by: Alan Bateman <alanb@openjdk.org>
Co-authored-by: Erik Österlund <eosterlund@openjdk.org>
Co-authored-by: Andrew Haley <aph@openjdk.org>
Co-authored-by: Rickard Bäckman <rbackman@openjdk.org>
Co-authored-by: Markus Grönlund <mgronlun@openjdk.org>
Co-authored-by: Leonid Mesnik <lmesnik@openjdk.org>
Co-authored-by: Serguei Spitsyn <sspitsyn@openjdk.org>
Co-authored-by: Chris Plummer <cjplummer@openjdk.org>
Co-authored-by: Coleen Phillimore <coleenp@openjdk.org>
Co-authored-by: Robbin Ehn <rehn@openjdk.org>
Co-authored-by: Stefan Karlsson <stefank@openjdk.org>
Co-authored-by: Thomas Schatzl <tschatzl@openjdk.org>
Co-authored-by: Sergey Kuksenko <skuksenko@openjdk.org>
Reviewed-by: lancea, eosterlund, rehn, sspitsyn, stefank, tschatzl, dfuchs, lmesnik, dcubed, kevinw, amenkov, dlong, mchung, psandoz, bpb, coleenp, smarks, egahlin, mseledtsov, coffeys, darcy
This commit is contained in:
Alan Bateman 2022-05-07 08:06:16 +00:00
parent 5212535a27
commit 9583e3657e
1133 changed files with 95935 additions and 8335 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, 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
@ -28,9 +28,9 @@ package java.io;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import jdk.internal.misc.InternalLock;
import sun.nio.cs.StreamEncoder;
/**
* An OutputStreamWriter is a bridge from character streams to byte streams:
* Characters written to it are encoded into bytes using a specified {@link
@ -74,9 +74,22 @@ import sun.nio.cs.StreamEncoder;
*/
public class OutputStreamWriter extends Writer {
private final StreamEncoder se;
/**
* Return the lock object for the given writer's stream encoder.
* If the writer type is trusted then an internal lock can be used. If the
* writer type is not trusted then the writer object is the lock.
*/
private static Object lockFor(OutputStreamWriter writer) {
Class<?> clazz = writer.getClass();
if (clazz == OutputStreamWriter.class || clazz == FileWriter.class) {
return InternalLock.newLockOr(writer);
} else {
return writer;
}
}
/**
* Creates an OutputStreamWriter that uses the named charset.
*
@ -95,7 +108,7 @@ public class OutputStreamWriter extends Writer {
super(out);
if (charsetName == null)
throw new NullPointerException("charsetName");
se = StreamEncoder.forOutputStreamWriter(out, this, charsetName);
se = StreamEncoder.forOutputStreamWriter(out, lockFor(this), charsetName);
}
/**
@ -108,7 +121,7 @@ public class OutputStreamWriter extends Writer {
*/
public OutputStreamWriter(OutputStream out) {
super(out);
se = StreamEncoder.forOutputStreamWriter(out, this,
se = StreamEncoder.forOutputStreamWriter(out, lockFor(this),
out instanceof PrintStream ps ? ps.charset() : Charset.defaultCharset());
}
@ -127,7 +140,7 @@ public class OutputStreamWriter extends Writer {
super(out);
if (cs == null)
throw new NullPointerException("charset");
se = StreamEncoder.forOutputStreamWriter(out, this, cs);
se = StreamEncoder.forOutputStreamWriter(out, lockFor(this), cs);
}
/**
@ -145,7 +158,7 @@ public class OutputStreamWriter extends Writer {
super(out);
if (enc == null)
throw new NullPointerException("charset encoder");
se = StreamEncoder.forOutputStreamWriter(out, this, enc);
se = StreamEncoder.forOutputStreamWriter(out, lockFor(this), enc);
}
/**