dumpByteCode flag

This commit is contained in:
Andrey Breslav
2013-05-13 19:37:24 +04:00
parent bb12685004
commit 551c370242
4 changed files with 21 additions and 8 deletions
@@ -76,10 +76,11 @@ public class ProfilingInstrumenterExample extends InterceptionInstrumenterAdapto
} }
} }
// Collect all strings that were capitalized using StringUtil // Collect all strings that were capitalized using StringUtil, and dump its instrumented byte code
@MethodInterceptor(className = "com/intellij/openapi/util/text/StringUtil", @MethodInterceptor(className = "com/intellij/openapi/util/text/StringUtil",
methodName = "capitalize", methodName = "capitalize",
methodDesc = "\\(Ljava/lang/String;\\).*") methodDesc = "\\(Ljava/lang/String;\\).*",
dumpByteCode = true)
public static Object c = new CollectFirstArguments(); public static Object c = new CollectFirstArguments();
public static class CollectFirstArguments { public static class CollectFirstArguments {
@@ -37,9 +37,6 @@ public class InterceptionInstrumenter {
private static final Pattern ANYTHING = Pattern.compile(".*"); private static final Pattern ANYTHING = Pattern.compile(".*");
private static final Type OBJECT_TYPE = Type.getType(Object.class); private static final Type OBJECT_TYPE = Type.getType(Object.class);
//private final boolean dumpInstrumentedMethods = true;
private final boolean dumpInstrumentedMethods = false;
private final Map<String, ClassMatcher> classPatterns = new LinkedHashMap<String, ClassMatcher>(); private final Map<String, ClassMatcher> classPatterns = new LinkedHashMap<String, ClassMatcher>();
private final Set<String> neverMatchedClassPatterns = new LinkedHashSet<String>(); private final Set<String> neverMatchedClassPatterns = new LinkedHashSet<String>();
@@ -129,7 +126,8 @@ public class InterceptionInstrumenter {
enterData, enterData,
normalReturnData, normalReturnData,
exceptionData, exceptionData,
annotation.logInterceptions()); annotation.logInterceptions(),
annotation.dumpByteCode());
for (Method dumpMethod : dumpMethods) { for (Method dumpMethod : dumpMethods) {
addDumpTask(interceptor, dumpMethod, instrumenter); addDumpTask(interceptor, dumpMethod, instrumenter);
@@ -305,6 +303,7 @@ public class InterceptionInstrumenter {
if (applicableInstrumenters.isEmpty()) return mv; if (applicableInstrumenters.isEmpty()) return mv;
boolean dumpByteCode = false;
final List<MethodData> normalReturnData = new ArrayList<MethodData>(); final List<MethodData> normalReturnData = new ArrayList<MethodData>();
final List<MethodData> enterData = new ArrayList<MethodData>(); final List<MethodData> enterData = new ArrayList<MethodData>();
final List<MethodData> exceptionData = new ArrayList<MethodData>(); final List<MethodData> exceptionData = new ArrayList<MethodData>();
@@ -314,11 +313,13 @@ public class InterceptionInstrumenter {
normalReturnData.addAll(instrumenter.getNormalReturnData()); normalReturnData.addAll(instrumenter.getNormalReturnData());
exceptionData.addAll(instrumenter.getExceptionData()); exceptionData.addAll(instrumenter.getExceptionData());
dumpByteCode |= instrumenter.shouldDumpByteCode();
} }
if (enterData.isEmpty() && normalReturnData.isEmpty() && exceptionData.isEmpty()) return mv; if (enterData.isEmpty() && normalReturnData.isEmpty() && exceptionData.isEmpty()) return mv;
if (dumpInstrumentedMethods) { if (dumpByteCode) {
mv = getDumpingVisitorWrapper(mv, name, desc); mv = getDumpingVisitorWrapper(mv, name, desc);
} }
@@ -29,6 +29,7 @@ class MethodInstrumenter {
private final List<MethodData> normalReturnData; private final List<MethodData> normalReturnData;
private final List<MethodData> exceptionData; private final List<MethodData> exceptionData;
private final boolean logApplications; private final boolean logApplications;
private final boolean dumpByteCode;
public MethodInstrumenter( public MethodInstrumenter(
String debugName, String debugName,
@@ -37,7 +38,9 @@ class MethodInstrumenter {
boolean allowMultipleMatches, boolean allowMultipleMatches,
List<MethodData> enterData, List<MethodData> enterData,
List<MethodData> normalReturnData, List<MethodData> normalReturnData,
List<MethodData> exceptionData, boolean logApplications List<MethodData> exceptionData,
boolean logApplications,
boolean dumpByteCode
) { ) {
this.debugName = debugName; this.debugName = debugName;
this.classPattern = classPattern; this.classPattern = classPattern;
@@ -48,6 +51,7 @@ class MethodInstrumenter {
this.normalReturnData = normalReturnData; this.normalReturnData = normalReturnData;
this.exceptionData = exceptionData; this.exceptionData = exceptionData;
this.logApplications = logApplications; this.logApplications = logApplications;
this.dumpByteCode = dumpByteCode;
} }
public boolean allowsMultipleMatches() { public boolean allowsMultipleMatches() {
@@ -76,6 +80,10 @@ class MethodInstrumenter {
return exceptionData; return exceptionData;
} }
boolean shouldDumpByteCode() {
return dumpByteCode;
}
@Override @Override
public String toString() { public String toString() {
return debugName + "[" + classPattern + ":" + namePattern + " " + descPattern + (allowMultipleMatches ? " multiple" : "") + "]"; return debugName + "[" + classPattern + ":" + namePattern + " " + descPattern + (allowMultipleMatches ? " multiple" : "") + "]";
@@ -38,4 +38,7 @@ public @interface MethodInterceptor {
// if true, every method instrumented with this interceptor will be logged to stdout // if true, every method instrumented with this interceptor will be logged to stdout
boolean logInterceptions() default false; boolean logInterceptions() default false;
// if true, byte codes of every method instrumented with this interceptor will be logged to stdout
boolean dumpByteCode() default false;
} }