mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
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:
parent
5212535a27
commit
9583e3657e
1133 changed files with 95935 additions and 8335 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 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
|
||||
|
@ -27,6 +27,8 @@ package java.lang;
|
|||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.misc.InternalLock;
|
||||
|
||||
/**
|
||||
* The {@code Throwable} class is the superclass of all errors and
|
||||
|
@ -659,27 +661,39 @@ public class Throwable implements Serializable {
|
|||
}
|
||||
|
||||
private void printStackTrace(PrintStreamOrWriter s) {
|
||||
Object lock = s.lock();
|
||||
if (lock instanceof InternalLock locker) {
|
||||
locker.lock();
|
||||
try {
|
||||
lockedPrintStackTrace(s);
|
||||
} finally {
|
||||
locker.unlock();
|
||||
}
|
||||
} else synchronized (lock) {
|
||||
lockedPrintStackTrace(s);
|
||||
}
|
||||
}
|
||||
|
||||
private void lockedPrintStackTrace(PrintStreamOrWriter s) {
|
||||
// Guard against malicious overrides of Throwable.equals by
|
||||
// using a Set with identity equality semantics.
|
||||
Set<Throwable> dejaVu = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
dejaVu.add(this);
|
||||
|
||||
synchronized (s.lock()) {
|
||||
// Print our stack trace
|
||||
s.println(this);
|
||||
StackTraceElement[] trace = getOurStackTrace();
|
||||
for (StackTraceElement traceElement : trace)
|
||||
s.println("\tat " + traceElement);
|
||||
// Print our stack trace
|
||||
s.println(this);
|
||||
StackTraceElement[] trace = getOurStackTrace();
|
||||
for (StackTraceElement traceElement : trace)
|
||||
s.println("\tat " + traceElement);
|
||||
|
||||
// Print suppressed exceptions, if any
|
||||
for (Throwable se : getSuppressed())
|
||||
se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu);
|
||||
// Print suppressed exceptions, if any
|
||||
for (Throwable se : getSuppressed())
|
||||
se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu);
|
||||
|
||||
// Print cause, if any
|
||||
Throwable ourCause = getCause();
|
||||
if (ourCause != null)
|
||||
ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu);
|
||||
}
|
||||
// Print cause, if any
|
||||
Throwable ourCause = getCause();
|
||||
if (ourCause != null)
|
||||
ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -691,7 +705,7 @@ public class Throwable implements Serializable {
|
|||
String caption,
|
||||
String prefix,
|
||||
Set<Throwable> dejaVu) {
|
||||
assert Thread.holdsLock(s.lock());
|
||||
assert s.isLockedByCurrentThread();
|
||||
if (dejaVu.contains(this)) {
|
||||
s.println(prefix + caption + "[CIRCULAR REFERENCE: " + this + "]");
|
||||
} else {
|
||||
|
@ -743,6 +757,15 @@ public class Throwable implements Serializable {
|
|||
/** Returns the object to be locked when using this StreamOrWriter */
|
||||
abstract Object lock();
|
||||
|
||||
boolean isLockedByCurrentThread() {
|
||||
Object lock = lock();
|
||||
if (lock instanceof InternalLock locker) {
|
||||
return locker.isHeldByCurrentThread();
|
||||
} else {
|
||||
return Thread.holdsLock(lock);
|
||||
}
|
||||
}
|
||||
|
||||
/** Prints the specified string as a line on this StreamOrWriter */
|
||||
abstract void println(Object o);
|
||||
}
|
||||
|
@ -755,7 +778,7 @@ public class Throwable implements Serializable {
|
|||
}
|
||||
|
||||
Object lock() {
|
||||
return printStream;
|
||||
return SharedSecrets.getJavaIOPrintStreamAccess().lock(printStream);
|
||||
}
|
||||
|
||||
void println(Object o) {
|
||||
|
@ -771,7 +794,7 @@ public class Throwable implements Serializable {
|
|||
}
|
||||
|
||||
Object lock() {
|
||||
return printWriter;
|
||||
return SharedSecrets.getJavaIOPrintWriterAccess().lock(printWriter);
|
||||
}
|
||||
|
||||
void println(Object o) {
|
||||
|
@ -833,11 +856,13 @@ public class Throwable implements Serializable {
|
|||
private synchronized StackTraceElement[] getOurStackTrace() {
|
||||
// Initialize stack trace field with information from
|
||||
// backtrace if this is the first call to this method
|
||||
if (stackTrace == UNASSIGNED_STACK ||
|
||||
(stackTrace == null && backtrace != null) /* Out of protocol state */) {
|
||||
stackTrace = StackTraceElement.of(this, depth);
|
||||
} else if (stackTrace == null) {
|
||||
return UNASSIGNED_STACK;
|
||||
if (stackTrace == UNASSIGNED_STACK || stackTrace == null) {
|
||||
if (backtrace != null) { /* Out of protocol state */
|
||||
stackTrace = StackTraceElement.of(backtrace, depth);
|
||||
} else {
|
||||
// no backtrace, fillInStackTrace overridden or not called
|
||||
return UNASSIGNED_STACK;
|
||||
}
|
||||
}
|
||||
return stackTrace;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue