Permalink
Browse files

cleanup

  • Loading branch information...
1 parent c52b94a commit 1b6d008120eb0b0526f5dd73fb01fd1b5a1f5a42 @clojure-site clojure-site committed Sep 12, 2009
@@ -10,129 +10,128 @@
import org.jruby.runtime.builtin.IRubyObject;
public class CallsiteHook extends RcovHook {
+
+ private static CallsiteHook callsiteHook;
- private static CallsiteHook callsiteHook;
-
- public static CallsiteHook getCallsiteHook() {
- if (callsiteHook == null) {
- callsiteHook = new CallsiteHook();
- }
- return callsiteHook;
- }
-
- private boolean active;
- private RubyHash defsites;
- private RubyHash callsites;
-
- private CallsiteHook() {
- super();
- }
-
- public boolean isActive() {
- return active;
- }
-
- public boolean isInterestedInEvent(RubyEvent event) {
- return event == RubyEvent.CALL || event == RubyEvent.C_CALL;
- }
-
- public RubyArray getCallsiteInfo(Ruby runtime) {
- RubyArray info = runtime.newArray();
- info.add(getCallsites(runtime));
- info.add(getDefsites(runtime));
- return info;
- }
-
- public void setActive(boolean active) {
- this.active = active;
- }
-
- public RubyHash resetDefsites() {
- defsites.clear();
- return defsites;
+ public static CallsiteHook getCallsiteHook() {
+ if (callsiteHook == null) {
+ callsiteHook = new CallsiteHook();
}
-
- public void eventHandler(ThreadContext context, String event, String file, int line,
- String name, IRubyObject type) {
- RubyArray currentMethod = context.getRuntime().newArray();
- currentMethod.add(context.getFrameKlazz());
- currentMethod.add(context.getRuntime().newSymbol(name));
-
- RubyArray fileLoc = context.getRuntime().newArray();
- fileLoc.add(file);
- fileLoc.add(Long.valueOf(line));
- defsites = getDefsites(context.getRuntime());
- if (!context.isWithinTrace()) {
- context.setWithinTrace(true);
-
- defsites.put(currentMethod, fileLoc);
-
- callsites = getCallsites(context.getRuntime());
- if (!callsites.containsKey(currentMethod)) {
- callsites.put(currentMethod, RubyHash.newHash(context.getRuntime()));
- }
- RubyHash hash = (RubyHash) callsites.get(currentMethod);
-
- RubyArray callerArray = customBacktrace(context);
- if (!hash.containsKey(callerArray)) {
- hash.put(callerArray, Long.valueOf(0));
- }
- Long count = (Long) hash.get(callerArray);
- long itCount = count.longValue() + 1L;
- hash.put(callerArray, Long.valueOf(itCount));
- context.setWithinTrace(false);
- }
-
+ return callsiteHook;
+ }
+
+ private boolean active;
+ private RubyHash defsites;
+ private RubyHash callsites;
+
+ private CallsiteHook() {
+ super();
+ }
+
+ public boolean isActive() {
+ return active;
+ }
+
+ public boolean isInterestedInEvent(RubyEvent event) {
+ return event == RubyEvent.CALL || event == RubyEvent.C_CALL;
+ }
+
+ public RubyArray getCallsiteInfo(Ruby runtime) {
+ RubyArray info = runtime.newArray();
+ info.add(getCallsites(runtime));
+ info.add(getDefsites(runtime));
+ return info;
+ }
+
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+
+ public RubyHash resetDefsites() {
+ defsites.clear();
+ return defsites;
+ }
+
+ public void eventHandler(ThreadContext context, String event, String file, int line, String name, IRubyObject type) {
+ RubyArray currentMethod = context.getRuntime().newArray();
+ currentMethod.add(context.getFrameKlazz());
+ currentMethod.add(context.getRuntime().newSymbol(name));
+
+ RubyArray fileLoc = context.getRuntime().newArray();
+ fileLoc.add(file);
+ fileLoc.add(Long.valueOf(line));
+ defsites = getDefsites(context.getRuntime());
+
+ if (!context.isWithinTrace()) {
+ context.setWithinTrace(true);
+ defsites.put(currentMethod, fileLoc);
+ callsites = getCallsites(context.getRuntime());
+
+ if (!callsites.containsKey(currentMethod)) {
+ callsites.put(currentMethod, RubyHash.newHash(context.getRuntime()));
+ }
+
+ RubyHash hash = (RubyHash) callsites.get(currentMethod);
+ RubyArray callerArray = customBacktrace(context);
+
+ if (!hash.containsKey(callerArray)) {
+ hash.put(callerArray, Long.valueOf(0));
+ }
+
+ Long count = (Long) hash.get(callerArray);
+ long itCount = count.longValue() + 1L;
+ hash.put(callerArray, Long.valueOf(itCount));
+ context.setWithinTrace(false);
}
-
- private RubyArray customBacktrace(ThreadContext context) {
- Frame[] frames = context.createBacktrace(1, false);
- RubyArray ary = context.getRuntime().newArray();
- ary.addAll(formatBacktrace(context.getRuntime(), frames[frames.length - 1]));
-
- return context.getRuntime().newArray((IRubyObject) ary);
+ }
+
+ private RubyArray customBacktrace(ThreadContext context) {
+ Frame[] frames = context.createBacktrace(1, false);
+ RubyArray ary = context.getRuntime().newArray();
+ ary.addAll(formatBacktrace(context.getRuntime(), frames[frames.length - 1]));
+ return context.getRuntime().newArray((IRubyObject) ary);
+ }
+
+ /*
+ * TODO: The logic in this method really needs to be wrapped in a backtrace
+ * object or something. Then I could fix the file path issues that cause
+ * test failures.
+ * @param runtime
+ * @param backtrace
+ * @return
+ */
+ private RubyArray formatBacktrace(Ruby runtime, Frame backtrace) {
+ RubyArray ary = runtime.newArray();
+
+ if (backtrace == null) {
+ ary.add(runtime.getNil());
+ ary.add(runtime.getNil());
+ ary.add("");
+ ary.add(Long.valueOf(0));
+ } else {
+ ary.add(backtrace.getKlazz());
+ ary.add((backtrace.getName() == null ? runtime.getNil() : runtime.newSymbol( backtrace.getName())));
+ ary.add(backtrace.getFile());
+ //Add 1 to compensate for the zero offset in the Frame elements.
+ ary.add(backtrace.getLine() + 1);
}
-
- /**
- * TODO: The logic in this method really needs to be wrapped in a backtrace
- * object or something. Then I could fix the file path issues that cause
- * test failures.
- * @param runtime
- * @param backtrace
- * @return
- */
- private RubyArray formatBacktrace(Ruby runtime, Frame backtrace) {
- RubyArray ary = runtime.newArray();
- if ( backtrace == null ) {
- ary.add(runtime.getNil());
- ary.add(runtime.getNil());
- ary.add("");
- ary.add(Long.valueOf(0));
- } else {
- ary.add( backtrace.getKlazz());
- ary.add( ( backtrace.getName() == null ?
- runtime.getNil() :
- runtime.newSymbol( backtrace.getName() ) ) );
- ary.add(backtrace.getFile());
- //Add 1 to compensate for the zero offset in the Frame elements.
- ary.add(backtrace.getLine() + 1);
- }
-
- return ary;
- }
-
- private RubyHash getCallsites(Ruby runtime) {
- if (this.callsites == null) {
- this.callsites = RubyHash.newHash(runtime);
- }
- return this.callsites;
+
+ return ary;
+ }
+
+ private RubyHash getCallsites(Ruby runtime) {
+ if (this.callsites == null) {
+ this.callsites = RubyHash.newHash(runtime);
}
-
- private RubyHash getDefsites(Ruby runtime) {
- if (this.defsites == null) {
- this.defsites = RubyHash.newHash(runtime);
- }
- return this.defsites;
+
+ return this.callsites;
+ }
+
+ private RubyHash getDefsites(Ruby runtime) {
+ if (this.defsites == null) {
+ this.defsites = RubyHash.newHash(runtime);
}
-
+
+ return this.defsites;
+ }
}
Oops, something went wrong.

0 comments on commit 1b6d008

Please sign in to comment.