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

Commit

Permalink
Stash #49.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongl committed Dec 21, 2012
1 parent ac32351 commit d4be75d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
3 changes: 3 additions & 0 deletions acceptance-test/TraceTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.lang.ArrayStoreException;
import java.util.Arrays;

public class TraceTarget {

public static void main(String[] args) throws Exception {
Object o = loadClass();
Arrays.asList(1,2).size();

while (true) {
addOne(0);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/github/zhongl/housemd/duck/Duck.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.lang.reflect.Array;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.jar.JarFile;

/**
* @author <a href="mailto:zhong.lunfu@gmail.com">zhongl</a>
Expand All @@ -32,6 +33,8 @@ public static void agentmain(String arguments, Instrumentation instrumentation)
String telephoneClassName = parts[1];
int port = Integer.parseInt(parts[2]);

instrumentation.appendToBootstrapClassLoaderSearch(new JarFile(new File(agentJar.toURI())));

ClassLoader classLoader = new URLClassLoader(new URL[]{agentJar}) {
@Override
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class Transform extends ((Instrumentation, Filter, Seconds, Int, Loggable, Hook)
def isNotInterface = skipClass("") { _.isInterface }

@inline
def isNotFromBootClassLoader = skipClass("loaded from bootclassloader") { isFromBootClassLoader(_) }
def isNotThreadLocalOrInternal = skipClass("because tracing it could cause stack overflow") { _.getName.startsWith("java.lang.ThreadLocal") }

filter(c) && isNotBelongsHouseMD && isNotInterface //&& isNotFromBootClassLoader
filter(c) && isNotBelongsHouseMD && isNotInterface && isNotThreadLocalOrInternal
}

if (candidates.isEmpty) {
Expand Down Expand Up @@ -138,7 +138,6 @@ class Transform extends ((Instrumentation, Filter, Seconds, Int, Loggable, Hook)
}
}


private def loadOrDefineAdviceClassFrom(loader: ClassLoader): Class[_] = loadOrDefine(classOf[Advice], loader)

private def advice(limit: Int) = new Advice() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ object ReflectionUtils {
def loadOrDefine(clazz: Class[_], inClassLoader: ClassLoader) = {
val name = clazz.getName
try {
inClassLoader.loadClass(name)
val loader = Option(inClassLoader) getOrElse Thread.currentThread().getContextClassLoader
loader.loadClass(name)
} catch {
case e: ClassNotFoundException =>
import Utils._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ class TransformCommandSpec extends FunSpec with ShouldMatchers with AdviceReflec
}
}

ignore("should not probe class loaded by boot classloader") {
it("should probe class loaded by boot classloader") {
parseAndRun("String") { out =>
out.split("\n").head should be("WARN : Skip " + classOf[String] + " loaded from bootclassloader")
out.split("\n").head should be("INFO : Probe " + classOf[String])
}
}

Expand All @@ -126,6 +126,15 @@ class TransformCommandSpec extends FunSpec with ShouldMatchers with AdviceReflec
}
}

it("should not probe classes ThreadLocal") {
parseAndRun("ThreadLocal") { out =>
out.split("\n") should {
contain("WARN : Skip " + classOf[ThreadLocal] + " because tracing it could cause stack overflow.")
contain("No matched class")
}
}
}

it("should probe F by I+") {
parseAndRun("-l 1 I+") { out =>
val withoutInfo = out.split("\n").filter(!_.startsWith("INFO"))
Expand Down

0 comments on commit d4be75d

Please sign in to comment.