Skip to content
This repository was archived by the owner on Mar 14, 2019. It is now read-only.

Commit

Permalink
Fixed #54: Interrupted in tracing.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongl committed Jun 20, 2012
1 parent 5d2a4eb commit 4872157
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion acceptance-test/TraceTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void main(String[] args) throws Exception {

while (true) {
addOne(0);
o.getClass().getMethod("m", String.class).invoke(o, "123");
o.getClass().getMethod("m", String.class).invoke(o, (String)null);
try {
Thread.sleep(500L);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ public void heartbeat(long now) {
println("Can't inspect " + accessor + " because there's no invocation on " + accessor.classSimpleName);
else
for (Object target : targets) printStat(target);
println();
}

private void printStat(Object target) {
try {
println(accessor + " " + accessor.getField(target) + " " + target + " " + target.getClass().getClassLoader());
println();
} catch (Exception e) {
error(e);
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/com/github/zhongl/housemd/command/Trace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.github.zhongl.housemd.misc.Reflections._
import java.util.Date
import collection.immutable.SortedSet
import com.github.zhongl.housemd.instrument.{Hook, Context}
import org.objectweb.asm.Type

/**
* @author <a href="mailto:[email protected]">zhongl<a>
Expand Down Expand Up @@ -105,7 +106,7 @@ class Trace(val inst: Instrumentation, out: PrintOut)
lazy val methodSign = "%1$s.%2$s(%3$s)".format(
simpleNameOf(context.className),
context.methodName,
context.arguments.map(o => simpleNameOf(o.getClass)).mkString(", ")
Type.getArgumentTypes(context.descriptor).map(t => simpleNameOf(t.getClassName)).mkString(", ")
)

lazy val loader = if (context.loader == null) "BootClassLoader" else context.loader.toString
Expand All @@ -124,7 +125,7 @@ class Trace(val inst: Instrumentation, out: PrintOut)
this.context.className == context.className &&
this.context.methodName == context.methodName &&
this.context.arguments.size == context.arguments.size &&
this.context.arguments.map(_.getClass) == context.arguments.map(_.getClass) &&
this.context.descriptor == context.descriptor &&
this.context.thisObject == context.thisObject

def reps(maxMethodSignLength: Int, maxClassLoaderLength: Int) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public abstract class Advice {
public static final String VOID_RETURN = "voidReturn";
public static final String THIS = "this";
public static final String ARGUMENTS = "arguments";
public static final String DESCRIPTOR = "descriptor";
public static final String STACK = "stack";
public static final String STARTED = "started";
public static final String STOPPED = "stopped";
Expand Down Expand Up @@ -84,6 +85,7 @@ public static void onMethodBegin(String className, String methodName, String des
context.put(VOID_RETURN, isVoidReturn(descriptor));
context.put(THIS, thisObject);
context.put(ARGUMENTS, arguments);
context.put(DESCRIPTOR, descriptor);
context.put(STACK, currentStackTrace());
context.put(STARTED, System.currentTimeMillis());
context.put(THREAD, Thread.currentThread());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ case class Context(
methodName: String,
loader: ClassLoader,
arguments: Array[AnyRef],
descriptor: String,
isVoidReturn: Boolean,
thisObject: AnyRef,
started: Long,
Expand All @@ -44,6 +45,7 @@ object Context {
map.get(Advice.METHOD).asInstanceOf[String],
map.get(Advice.CLASS_LOADER).asInstanceOf[ClassLoader],
map.get(Advice.ARGUMENTS).asInstanceOf[Array[AnyRef]],
map.get(Advice.DESCRIPTOR).asInstanceOf[String],
map.get(Advice.VOID_RETURN).asInstanceOf[Boolean],
map.get(Advice.THIS),
map.get(Advice.STARTED).asInstanceOf[Long],
Expand Down

0 comments on commit 4872157

Please sign in to comment.