mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-10 02:18:46 +00:00
8292351: tty should always live
Reviewed-by: clanger, coleenp, dholmes
This commit is contained in:
parent
4da1745836
commit
a85a72341b
@ -421,8 +421,19 @@ stringStream::~stringStream() {
|
||||
}
|
||||
}
|
||||
|
||||
// tty needs to be always accessible since there are code paths that may write to it
|
||||
// outside of the VM lifespan.
|
||||
// Examples for pre-VM-init accesses: Early NMT init, Early UL init
|
||||
// Examples for post-VM-exit accesses: many, e.g. NMT C-heap bounds checker, signal handling, AGCT, ...
|
||||
// During lifetime tty is served by an instance of defaultStream. That instance's deletion cannot
|
||||
// be (easily) postponed or omitted since it has ties to the JVM infrastructure.
|
||||
// The policy followed here is a compromise reached during review of JDK-8292351:
|
||||
// - pre-init: we silently swallow all output. We won't see anything, but at least won't crash
|
||||
// - post-exit: we write to a simple fdStream, but somewhat mimic the behavior of the real defaultStream
|
||||
static nullStream tty_preinit_stream;
|
||||
outputStream* tty = &tty_preinit_stream;
|
||||
|
||||
xmlStream* xtty;
|
||||
outputStream* tty;
|
||||
extern Mutex* tty_lock;
|
||||
|
||||
#define EXTRACHARLEN 32
|
||||
@ -615,6 +626,9 @@ void fileStream::flush() {
|
||||
}
|
||||
}
|
||||
|
||||
fdStream fdStream::_stdout_stream(1);
|
||||
fdStream fdStream::_stderr_stream(2);
|
||||
|
||||
void fdStream::write(const char* s, size_t len) {
|
||||
if (_fd != -1) {
|
||||
// Make an unused local variable to avoid warning from gcc compiler.
|
||||
@ -961,13 +975,13 @@ void ostream_exit() {
|
||||
if (ostream_exit_called) return;
|
||||
ostream_exit_called = true;
|
||||
ClassListWriter::delete_classlist();
|
||||
if (tty != defaultStream::instance) {
|
||||
delete tty;
|
||||
// Make sure tty works after VM exit by assigning an always-on functioning fdStream.
|
||||
outputStream* tmp = tty;
|
||||
tty = DisplayVMOutputToStderr ? fdStream::stdout_stream() : fdStream::stderr_stream();
|
||||
if (tmp != &tty_preinit_stream && tmp != defaultStream::instance) {
|
||||
delete tmp;
|
||||
}
|
||||
if (defaultStream::instance != NULL) {
|
||||
delete defaultStream::instance;
|
||||
}
|
||||
tty = NULL;
|
||||
delete defaultStream::instance;
|
||||
xtty = NULL;
|
||||
defaultStream::instance = NULL;
|
||||
}
|
||||
|
||||
@ -248,6 +248,8 @@ class fileStream : public outputStream {
|
||||
class fdStream : public outputStream {
|
||||
protected:
|
||||
int _fd;
|
||||
static fdStream _stdout_stream;
|
||||
static fdStream _stderr_stream;
|
||||
public:
|
||||
fdStream(int fd = -1) : _fd(fd) { }
|
||||
bool is_open() const { return _fd != -1; }
|
||||
@ -255,6 +257,17 @@ class fdStream : public outputStream {
|
||||
int fd() const { return _fd; }
|
||||
virtual void write(const char* c, size_t len);
|
||||
void flush() {};
|
||||
|
||||
// predefined streams for unbuffered IO to stdout, stderr
|
||||
static fdStream* stdout_stream() { return &_stdout_stream; }
|
||||
static fdStream* stderr_stream() { return &_stderr_stream; }
|
||||
};
|
||||
|
||||
// A /dev/null equivalent stream
|
||||
class nullStream : public outputStream {
|
||||
public:
|
||||
void write(const char* c, size_t len) {}
|
||||
void flush() {};
|
||||
};
|
||||
|
||||
void ostream_init();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user