Skip to content

Instantly share code, notes, and snippets.

@enebo
Created January 20, 2011 18:30
Show Gist options
  • Save enebo/788335 to your computer and use it in GitHub Desktop.
Save enebo/788335 to your computer and use it in GitHub Desktop.
thread.patch
diff --git a/src/org/jruby/RubyThread.java b/src/org/jruby/RubyThread.java
index f1f85b2..c45afe2 100644
--- a/src/org/jruby/RubyThread.java
+++ b/src/org/jruby/RubyThread.java
@@ -172,7 +172,11 @@ public class RubyThread extends RubyObject implements ExecutionContext {
public ThreadContext getContext() {
return contextRef.get();
}
-
+
+
+ public Thread getNativeThread() {
+ return threadImpl instanceof NativeThread ? ((NativeThread) threadImpl).getThread() : null;
+ }
/**
* Dispose of the current thread by removing it from its parent ThreadGroup.
*/
@@ -863,7 +867,7 @@ public class RubyThread extends RubyObject implements ExecutionContext {
@JRubyMethod(compat = CompatVersion.RUBY1_9)
public IRubyObject backtrace(ThreadContext context) {
- return context.createCallerBacktrace(context.getRuntime(), 0);
+ return getContext().createCallerBacktrace(context.getRuntime(), 0);
}
public StackTraceElement[] javaBacktrace() {
diff --git a/src/org/jruby/runtime/ThreadContext.java b/src/org/jruby/runtime/ThreadContext.java
index e3e9c3e..c257117 100644
--- a/src/org/jruby/runtime/ThreadContext.java
+++ b/src/org/jruby/runtime/ThreadContext.java
@@ -795,12 +795,18 @@ public final class ThreadContext {
}
public RubyStackTraceElement[] gatherCallerBacktrace(int level) {
+ Thread nativeThread = thread.getNativeThread();
+
+ // Future thread or otherwise unforthgiving thread impl.
+ if (nativeThread == null) return new RubyStackTraceElement[] {};
+
Backtrace[] copy = new Backtrace[backtraceIndex + 1];
+
System.arraycopy(backtrace, 0, copy, 0, backtraceIndex + 1);
RubyStackTraceElement[] trace = gatherHybridBacktrace(
runtime,
copy,
- Thread.currentThread().getStackTrace(),
+ nativeThread.getStackTrace(),
false);
return trace;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment