< prev index next >

jdk/src/java.base/share/classes/java/lang/Throwable.java

Print this page

        

@@ -22,10 +22,12 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
 package java.lang;
+import sun.misc.VM;
+
 import  java.io.*;
 import  java.util.*;
 
 /**
  * The {@code Throwable} class is the superclass of all errors and

@@ -776,11 +778,15 @@
      * @see     java.lang.Throwable#printStackTrace()
      */
     public synchronized Throwable fillInStackTrace() {
         if (stackTrace != null ||
             backtrace != null /* Out of protocol state */ ) {
+            if (backtrace == null && StackStreamFactory.useStackTrace(this)) {
+                backtrace = StackStreamFactory.makeStackTrace(this);
+            } else {
             fillInStackTrace(0);
+            }
             stackTrace = UNASSIGNED_STACK;
         }
         return this;
     }
 

@@ -817,14 +823,18 @@
     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 */) {
+            if (backtrace instanceof StackStreamFactory.StackTrace) {
+                stackTrace = ((StackStreamFactory.StackTrace)backtrace).getStackTraceElements();
+            } else {
             int depth = getStackTraceDepth();
             stackTrace = new StackTraceElement[depth];
-            for (int i=0; i < depth; i++)
+                for (int i = 0; i < depth; i++)
                 stackTrace[i] = getStackTraceElement(i);
+            }
         } else if (stackTrace == null) {
             return UNASSIGNED_STACK;
         }
         return stackTrace;
     }
< prev index next >