|
26 | 26 | import static com.oracle.truffle.espresso.threads.EspressoThreadRegistry.getThreadId; |
27 | 27 | import static com.oracle.truffle.espresso.threads.ThreadState.TIMED_SLEEPING; |
28 | 28 |
|
29 | | -import java.util.Arrays; |
30 | 29 | import java.util.concurrent.TimeUnit; |
31 | 30 | import java.util.concurrent.atomic.AtomicLong; |
32 | 31 |
|
@@ -116,21 +115,6 @@ public static void setCurrentThread(@JavaType(Thread.class) StaticObject self, @ |
116 | 115 | return context.getVM().JVM_GetAllThreads(null); |
117 | 116 | } |
118 | 117 |
|
119 | | - @Substitution |
120 | | - public static @JavaType(StackTraceElement[][].class) StaticObject dumpThreads(@JavaType(Thread[].class) StaticObject threads, @Inject EspressoLanguage language, @Inject Meta meta) { |
121 | | - if (StaticObject.isNull(threads)) { |
122 | | - throw meta.throwNullPointerException(); |
123 | | - } |
124 | | - if (threads.length(language) == 0) { |
125 | | - throw meta.throwException(meta.java_lang_IllegalArgumentException); |
126 | | - } |
127 | | - EspressoContext context = meta.getContext(); |
128 | | - StaticObject trace = StaticObject.createArray(meta.java_lang_StackTraceElement.array(), StaticObject.EMPTY_ARRAY, context); |
129 | | - StaticObject[] toWrap = new StaticObject[threads.length(language)]; |
130 | | - Arrays.fill(toWrap, trace); |
131 | | - return StaticObject.createArray(meta.java_lang_StackTraceElement.array().array(), toWrap, context); |
132 | | - } |
133 | | - |
134 | 118 | @Substitution(hasReceiver = true) |
135 | 119 | abstract static class Start0 extends SubstitutionNode { |
136 | 120 | abstract void execute(@JavaType(Thread.class) StaticObject self); |
@@ -332,6 +316,22 @@ public static void setNativeName(@JavaType(Thread.class) StaticObject self, @Jav |
332 | 316 | hostThread.setName(meta.toHostString(name)); |
333 | 317 | } |
334 | 318 |
|
| 319 | + // Return an array of stack traces (arrays of stack trace elements), one for each thread in the |
| 320 | + // threads array, or NULL for threads that were unresponsive. |
| 321 | + @Substitution |
| 322 | + public static @JavaType(StackTraceElement[][].class) StaticObject dumpThreads(@JavaType(Thread[].class) StaticObject threadsArray, |
| 323 | + @Inject EspressoLanguage language, @Inject Meta meta, @Inject EspressoContext context, @Inject SubstitutionProfiler location) { |
| 324 | + if (StaticObject.isNull(threadsArray)) { |
| 325 | + throw meta.throwNullPointerException(); |
| 326 | + } |
| 327 | + if (threadsArray.length(language) == 0) { |
| 328 | + throw meta.throwException(meta.java_lang_IllegalArgumentException); |
| 329 | + } |
| 330 | + VM.StackTrace[] traces = ThreadRequests.getStackTraces(context, InterpreterToVM.MAX_STACK_DEPTH, location, threadsArray.unwrap(language)); |
| 331 | + return meta.java_lang_StackTraceElement.array().allocateReferenceArray(traces.length, |
| 332 | + i -> traces[i] == null ? StaticObject.NULL : traces[i].toGuest(context)); |
| 333 | + } |
| 334 | + |
335 | 335 | @Substitution(languageFilter = VersionFilter.Java19OrLater.class, hasReceiver = true) |
336 | 336 | abstract static class GetStackTrace0 extends SubstitutionNode { |
337 | 337 | abstract @JavaType(Object.class) StaticObject execute(@JavaType(Thread.class) StaticObject self); |
|
0 commit comments