From 551c3702425cfcc368e7c40ec8545d6090c4ca8a Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Mon, 13 May 2013 19:37:24 +0400 Subject: [PATCH] dumpByteCode flag --- .../jet/preloading/ProfilingInstrumenterExample.java | 5 +++-- .../instrumentation/InterceptionInstrumenter.java | 11 ++++++----- .../instrumentation/MethodInstrumenter.java | 10 +++++++++- .../annotations/MethodInterceptor.java | 3 +++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/ProfilingInstrumenterExample.java b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/ProfilingInstrumenterExample.java index 84cd06441a2..4ba01b3316f 100644 --- a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/ProfilingInstrumenterExample.java +++ b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/ProfilingInstrumenterExample.java @@ -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", methodName = "capitalize", - methodDesc = "\\(Ljava/lang/String;\\).*") + methodDesc = "\\(Ljava/lang/String;\\).*", + dumpByteCode = true) public static Object c = new CollectFirstArguments(); public static class CollectFirstArguments { diff --git a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/InterceptionInstrumenter.java b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/InterceptionInstrumenter.java index 06a14340055..48b3b0b466c 100644 --- a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/InterceptionInstrumenter.java +++ b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/InterceptionInstrumenter.java @@ -37,9 +37,6 @@ public class InterceptionInstrumenter { private static final Pattern ANYTHING = Pattern.compile(".*"); private static final Type OBJECT_TYPE = Type.getType(Object.class); - //private final boolean dumpInstrumentedMethods = true; - private final boolean dumpInstrumentedMethods = false; - private final Map classPatterns = new LinkedHashMap(); private final Set neverMatchedClassPatterns = new LinkedHashSet(); @@ -129,7 +126,8 @@ public class InterceptionInstrumenter { enterData, normalReturnData, exceptionData, - annotation.logInterceptions()); + annotation.logInterceptions(), + annotation.dumpByteCode()); for (Method dumpMethod : dumpMethods) { addDumpTask(interceptor, dumpMethod, instrumenter); @@ -305,6 +303,7 @@ public class InterceptionInstrumenter { if (applicableInstrumenters.isEmpty()) return mv; + boolean dumpByteCode = false; final List normalReturnData = new ArrayList(); final List enterData = new ArrayList(); final List exceptionData = new ArrayList(); @@ -314,11 +313,13 @@ public class InterceptionInstrumenter { normalReturnData.addAll(instrumenter.getNormalReturnData()); exceptionData.addAll(instrumenter.getExceptionData()); + + dumpByteCode |= instrumenter.shouldDumpByteCode(); } if (enterData.isEmpty() && normalReturnData.isEmpty() && exceptionData.isEmpty()) return mv; - if (dumpInstrumentedMethods) { + if (dumpByteCode) { mv = getDumpingVisitorWrapper(mv, name, desc); } diff --git a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodInstrumenter.java b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodInstrumenter.java index d1e4be18737..504c1663262 100644 --- a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodInstrumenter.java +++ b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodInstrumenter.java @@ -29,6 +29,7 @@ class MethodInstrumenter { private final List normalReturnData; private final List exceptionData; private final boolean logApplications; + private final boolean dumpByteCode; public MethodInstrumenter( String debugName, @@ -37,7 +38,9 @@ class MethodInstrumenter { boolean allowMultipleMatches, List enterData, List normalReturnData, - List exceptionData, boolean logApplications + List exceptionData, + boolean logApplications, + boolean dumpByteCode ) { this.debugName = debugName; this.classPattern = classPattern; @@ -48,6 +51,7 @@ class MethodInstrumenter { this.normalReturnData = normalReturnData; this.exceptionData = exceptionData; this.logApplications = logApplications; + this.dumpByteCode = dumpByteCode; } public boolean allowsMultipleMatches() { @@ -76,6 +80,10 @@ class MethodInstrumenter { return exceptionData; } + boolean shouldDumpByteCode() { + return dumpByteCode; + } + @Override public String toString() { return debugName + "[" + classPattern + ":" + namePattern + " " + descPattern + (allowMultipleMatches ? " multiple" : "") + "]"; diff --git a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/annotations/MethodInterceptor.java b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/annotations/MethodInterceptor.java index 20370f16514..1c3c2dbdb7f 100644 --- a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/annotations/MethodInterceptor.java +++ b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/annotations/MethodInterceptor.java @@ -38,4 +38,7 @@ public @interface MethodInterceptor { // if true, every method instrumented with this interceptor will be logged to stdout boolean logInterceptions() default false; + + // if true, byte codes of every method instrumented with this interceptor will be logged to stdout + boolean dumpByteCode() default false; }