+ TRACEJVMCALLS(("JVM_DumpThreads((env=%p, threadClass=%p, threads=%p)", env, threadClass, threads));
+
+ if (threads == NULL) {
+ exceptions_throw_nullpointerexception();
+ return NULL;
+ }
+
+ ObjectArray oa(threads);
+
+ // Get length of the threads array.
+ int32_t length = oa.get_length();
+
+ if (length <= 0) {
+ exceptions_throw_illegalargumentexception();
+ return NULL;
+ }
+
+ // Allocate array to hold stacktraces.
+ classinfo* arrayclass = class_array_of(class_java_lang_StackTraceElement, true);
+ ObjectArray oaresult(length, arrayclass);
+
+ if (oaresult.is_null()) {
+ return NULL;
+ }
+
+ // Iterate over all passed thread objects.
+ for (i = 0; i < length; i++) {
+ java_handle_t* thread = oa.get_element(i);
+
+ // Get thread for the given thread object.
+ threadobject* t = thread_get_thread(thread);
+
+ // The threadobject is null when a thread is created in Java.
+ if (t == NULL)
+ continue;
+
+ // Get stacktrace for given thread.
+ stacktrace_t* st = stacktrace_get_of_thread(t);
+
+ // Convert stacktrace into array of StackTraceElements.
+ java_handle_objectarray_t* oaste = stacktrace_get_StackTraceElements(st);
+
+ if (oaste == NULL)
+ return NULL;
+
+ oaresult.set_element(i, oaste);
+ }
+
+ return oaresult.get_handle();