content: package org.apache.doris.fe.dump.util;
  
  import org.graalvm.visualvm.lib.jfluid.heap.GCRoot;
  import org.graalvm.visualvm.lib.jfluid.heap.Heap;
  import org.graalvm.visualvm.lib.jfluid.heap.ThreadObjectGCRoot;
  
  import java.util.Collection;
  
  public class DumpUtils {
      public static ThreadObjectGCRoot getOOMEThread(Heap heap) {
          Collection<GCRoot> roots = heap.getGCRoots();
  
          for (GCRoot root : roots) {
              if(root.getKind().equals(GCRoot.THREAD_OBJECT)) {
                  ThreadObjectGCRoot threadRoot = (ThreadObjectGCRoot)root;
                  StackTraceElement[] stackTrace = threadRoot.getStackTrace();
  
                  if (stackTrace!=null && stackTrace.length>=1) {
                      StackTraceElement ste = stackTrace[0];
  
                      if (OutOfMemoryError.class.getName().equals(ste.getClassName()) && "<init>".equals(ste.getMethodName())) {  // NOI18N
                          return threadRoot;
                      }
                  }
              }
          }
          return null;
      }
  }
  