Created
January 20, 2011 18:30
-
-
Save enebo/788335 to your computer and use it in GitHub Desktop.
thread.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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