Skip to content

Instantly share code, notes, and snippets.

@cheald

cheald/01_before Secret

Created June 18, 2015 00:35
Show Gist options
  • Save cheald/0e25a182d41620302ceb to your computer and use it in GitHub Desktop.
Save cheald/0e25a182d41620302ceb to your computer and use it in GitHub Desktop.
bin/jruby --dev -e "require 'active_support/all'" 9.30s user 0.35s system 186% cpu 5.177 total
bin/jruby --dev -e "require 'active_support/all'" 8.66s user 0.30s system 186% cpu 4.795 total
bin/jruby --dev -e "require 'active_support/all'" 8.76s user 0.32s system 186% cpu 4.860 total
bin/jruby --dev -e "require 'active_support/all'" 8.76s user 0.26s system 184% cpu 4.887 total
bin/jruby --dev -e "require 'active_support/all'" 8.78s user 0.28s system 186% cpu 4.864 total
bin/jruby --dev -e "require 'active_support/all'" 9.01s user 0.28s system 184% cpu 5.046 total
bin/jruby --dev -e "require 'active_support/all'" 9.02s user 0.31s system 185% cpu 5.025 total
bin/jruby --dev -e "require 'active_support/all'" 8.97s user 0.26s system 182% cpu 5.054 total
bin/jruby --dev -e "require 'active_support/all'" 8.75s user 0.34s system 184% cpu 4.919 total
bin/jruby --dev -e "require 'active_support/all'" 8.62s user 0.26s system 182% cpu 4.870 total
bin/jruby --dev -e "require 'active_support/all'" 8.01s user 0.31s system 175% cpu 4.738 total
bin/jruby --dev -e "require 'active_support/all'" 8.60s user 0.34s system 185% cpu 4.824 total
bin/jruby --dev -e "require 'active_support/all'" 8.32s user 0.36s system 185% cpu 4.688 total
bin/jruby --dev -e "require 'active_support/all'" 8.30s user 0.30s system 184% cpu 4.656 total
bin/jruby --dev -e "require 'active_support/all'" 8.33s user 0.31s system 185% cpu 4.646 total
bin/jruby --dev -e "require 'active_support/all'" 7.82s user 0.27s system 185% cpu 4.370 total
bin/jruby --dev -e "require 'active_support/all'" 8.19s user 0.28s system 185% cpu 4.553 total
bin/jruby --dev -e "require 'active_support/all'" 8.25s user 0.26s system 183% cpu 4.648 total
bin/jruby --dev -e "require 'active_support/all'" 8.17s user 0.31s system 185% cpu 4.572 total
bin/jruby --dev -e "require 'active_support/all'" 8.07s user 0.27s system 184% cpu 4.516 total
diff --git a/core/src/main/java/org/jruby/RubyClass.java b/core/src/main/java/org/jruby/RubyClass.java
index 9c8d88e..338ab0d 100644
--- a/core/src/main/java/org/jruby/RubyClass.java
+++ b/core/src/main/java/org/jruby/RubyClass.java
@@ -696,12 +696,19 @@ public class RubyClass extends RubyModule {
}
else {
IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $!
+ boolean lastHooksEnabled = context.isEventHooksEnabled();
+ boolean lastExceptionsEnabled = context.exceptionBacktracesEnabled();
+ context.setEventHooksEnabled(false);
+ context.setExceptionBacktracesEnabled(false);
try {
return checkFuncallExec(context, self, method, args);
} catch (RaiseException e) {
IRubyObject ret = checkFuncallFailed(context, self, method, runtime.getNoMethodError(), args);
runtime.getGlobalVariables().set("$!", oldExc); // restore $!
return ret;
+ } finally {
+ context.setEventHooksEnabled(lastHooksEnabled);
+ context.setExceptionBacktracesEnabled(lastExceptionsEnabled);
}
}
}
diff --git a/core/src/main/java/org/jruby/exceptions/RaiseException.java b/core/src/main/java/org/jruby/exceptions/RaiseException.java
index cf4098f..91ac5ed 100644
--- a/core/src/main/java/org/jruby/exceptions/RaiseException.java
+++ b/core/src/main/java/org/jruby/exceptions/RaiseException.java
@@ -191,7 +191,7 @@ public class RaiseException extends JumpException {
}
private void preRaise(ThreadContext context) {
- preRaise(context, (IRubyObject)null);
+ preRaise(context, (IRubyObject) null);
}
private void preRaise(ThreadContext context, StackTraceElement[] javaTrace) {
@@ -211,20 +211,23 @@ public class RaiseException extends JumpException {
if (RubyInstanceConfig.LOG_EXCEPTIONS) TraceType.dumpException(exception);
- if (backtrace == null) {
- exception.prepareBacktrace(context, nativeException);
- } else {
- exception.forceBacktrace(backtrace);
- }
+ if (context.exceptionBacktracesEnabled()) {
+ // System.out.println(String.format("Exception: %s", exception));
+ if (backtrace == null) {
+ exception.prepareBacktrace(context, nativeException);
+ } else {
+ exception.forceBacktrace(backtrace);
+ }
- // call Throwable.setStackTrace so that when RaiseException appears nested inside another exception,
- // Ruby stack trace gets displayed
+ // call Throwable.setStackTrace so that when RaiseException appears nested inside another exception,
+ // Ruby stack trace gets displayed
- // JRUBY-2673: if wrapping a NativeException, use the actual Java exception's trace as our Java trace
- if (exception instanceof NativeException) {
- setStackTrace(((NativeException)exception).getCause().getStackTrace());
- } else {
- setStackTrace(RaiseException.javaTraceFromRubyTrace(exception.getBacktraceElements()));
+ // JRUBY-2673: if wrapping a NativeException, use the actual Java exception's trace as our Java trace
+ if (exception instanceof NativeException) {
+ setStackTrace(((NativeException)exception).getCause().getStackTrace());
+ } else {
+ setStackTrace(RaiseException.javaTraceFromRubyTrace(exception.getBacktraceElements()));
+ }
}
}
diff --git a/core/src/main/java/org/jruby/runtime/ThreadContext.java b/core/src/main/java/org/jruby/runtime/ThreadContext.java
index 9a6d4d8..eed62bf 100644
--- a/core/src/main/java/org/jruby/runtime/ThreadContext.java
+++ b/core/src/main/java/org/jruby/runtime/ThreadContext.java
@@ -121,6 +121,7 @@ public final class ThreadContext {
private ProfileCollection profileCollection;
private boolean eventHooksEnabled = true;
+ private boolean exceptionBacktracesEnabled = true;
CallType lastCallType;
@@ -739,7 +740,16 @@ public final class ThreadContext {
public void setEventHooksEnabled(boolean flag) {
eventHooksEnabled = flag;
}
-
+
+ public boolean exceptionBacktracesEnabled() {
+ return exceptionBacktracesEnabled;
+ }
+
+ public void setExceptionBacktracesEnabled(boolean flag) {
+ exceptionBacktracesEnabled = flag;
+ }
+
+
/**
* Create an Array with backtrace information.
* @param level
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment