< prev index next >

src/java.base/share/classes/java/lang/StackTraceElement.java

Print this page
@@ -27,10 +27,11 @@
  
  import jdk.internal.loader.BuiltinClassLoader;
  import jdk.internal.misc.VM;
  import jdk.internal.module.ModuleHashes;
  import jdk.internal.module.ModuleReferenceImpl;
+ import jdk.internal.vm.Continuation;
  
  import java.lang.module.ModuleDescriptor.Version;
  import java.lang.module.ModuleReference;
  import java.lang.module.ResolvedModule;
  import java.util.HashSet;

@@ -82,10 +83,14 @@
      private String methodName;
      /**
       * The source file name.
       */
      private String fileName;
+     /**
+      * The contintation name.
+      */
+     private String contScopeName;
      /**
       * The source line number.
       */
      private int    lineNumber;
      /**

@@ -369,15 +374,27 @@
                  s += "@" + moduleVersion;
              }
          }
          s = s.isEmpty() ? declaringClass : s + "/" + declaringClass;
  
-         return s + "." + methodName + "(" +
+         s = s + "." + methodName + "(" +
               (isNativeMethod() ? "Native Method)" :
                (fileName != null && lineNumber >= 0 ?
                 fileName + ":" + lineNumber + ")" :
                  (fileName != null ?  ""+fileName+")" : "Unknown Source)")));
+ 
+         if (contScopeName != null
+                 && !contScopeName.equals(VirtualThread.continuationScope().getName())
+                 && isContinuationEntry()) {
+             s = s + " " + contScopeName;
+         }
+ 
+         return s;
+     }
+ 
+     private boolean isContinuationEntry() {
+         return declaringClass.equals(Continuation.class.getName()) && methodName.equals("enter");
      }
  
      /**
       * Returns true if the specified object is another
       * {@code StackTraceElement} instance representing the same execution

@@ -411,11 +428,12 @@
                  && e.declaringClass.equals(declaringClass)
                  && Objects.equals(classLoaderName, e.classLoaderName)
                  && Objects.equals(moduleName, e.moduleName)
                  && Objects.equals(moduleVersion, e.moduleVersion)
                  && Objects.equals(methodName, e.methodName)
-                 && Objects.equals(fileName, e.fileName);
+                 && Objects.equals(fileName, e.fileName)
+                 && Objects.equals(contScopeName, e.contScopeName);
      }
  
      /**
       * Returns a hash code value for this stack trace element.
       */

@@ -423,10 +441,11 @@
          int result = 31*declaringClass.hashCode() + methodName.hashCode();
          result = 31*result + Objects.hashCode(classLoaderName);
          result = 31*result + Objects.hashCode(moduleName);
          result = 31*result + Objects.hashCode(moduleVersion);
          result = 31*result + Objects.hashCode(fileName);
+         result = 31*result + Objects.hashCode(contScopeName);
          result = 31*result + lineNumber;
          return result;
      }
  
  

@@ -527,26 +546,21 @@
      }
  
  
      /*
       * Returns an array of StackTraceElements of the given depth
-      * filled from the backtrace of a given Throwable.
+      * filled from the given backtrace.
       */
-     static StackTraceElement[] of(Throwable x, int depth) {
+     static StackTraceElement[] of(Object x, int depth) {
          StackTraceElement[] stackTrace = new StackTraceElement[depth];
          for (int i = 0; i < depth; i++) {
              stackTrace[i] = new StackTraceElement();
          }
  
          // VM to fill in StackTraceElement
-         initStackTraceElements(stackTrace, x);
- 
-         // ensure the proper StackTraceElement initialization
-         for (StackTraceElement ste : stackTrace) {
-             ste.computeFormat();
-         }
-         return stackTrace;
+         initStackTraceElements(stackTrace, x, depth);
+         return of(stackTrace);
      }
  
      /*
       * Returns a StackTraceElement from a given StackFrameInfo.
       */

@@ -556,16 +570,24 @@
  
          ste.computeFormat();
          return ste;
      }
  
+     static StackTraceElement[] of(StackTraceElement[] stackTrace) {
+         // ensure the proper StackTraceElement initialization
+         for (StackTraceElement ste : stackTrace) {
+             ste.computeFormat();
+         }
+         return stackTrace;
+     }
+ 
      /*
       * Sets the given stack trace elements with the backtrace
       * of the given Throwable.
       */
      private static native void initStackTraceElements(StackTraceElement[] elements,
-                                                       Throwable x);
+                                                       Object x, int depth);
      /*
       * Sets the given stack trace element with the given StackFrameInfo
       */
      private static native void initStackTraceElement(StackTraceElement element,
                                                       StackFrameInfo sfi);
< prev index next >