< 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 ***
                  s += "@" + moduleVersion;
              }
          }
          s = s.isEmpty() ? declaringClass : s + "/" + declaringClass;
  
!         return s + "." + methodName + "(" +
               (isNativeMethod() ? "Native Method)" :
                (fileName != null && lineNumber >= 0 ?
                 fileName + ":" + lineNumber + ")" :
                  (fileName != null ?  ""+fileName+")" : "Unknown Source)")));
      }
  
      /**
       * Returns true if the specified object is another
       * {@code StackTraceElement} instance representing the same execution
--- 374,27 ---
                  s += "@" + moduleVersion;
              }
          }
          s = s.isEmpty() ? declaringClass : s + "/" + declaringClass;
  
!         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 ***
                  && 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);
      }
  
      /**
       * Returns a hash code value for this stack trace element.
       */
--- 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(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 ***
      }
  
  
      /*
       * Returns an array of StackTraceElements of the given depth
!      * filled from the backtrace of a given Throwable.
       */
!     static StackTraceElement[] of(Throwable 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;
      }
  
      /*
       * Returns a StackTraceElement from a given StackFrameInfo.
       */
--- 546,21 ---
      }
  
  
      /*
       * Returns an array of StackTraceElements of the given depth
!      * filled from the given backtrace.
       */
!     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, depth);
!         return of(stackTrace);
      }
  
      /*
       * Returns a StackTraceElement from a given StackFrameInfo.
       */

*** 556,16 ***
  
          ste.computeFormat();
          return ste;
      }
  
      /*
       * Sets the given stack trace elements with the backtrace
       * of the given Throwable.
       */
      private static native void initStackTraceElements(StackTraceElement[] elements,
!                                                       Throwable x);
      /*
       * Sets the given stack trace element with the given StackFrameInfo
       */
      private static native void initStackTraceElement(StackTraceElement element,
                                                       StackFrameInfo sfi);
--- 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,
!                                                       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 >