From 3fdccd50a635c1888454a5fe08ddb5de6fd7d87e Mon Sep 17 00:00:00 2001 From: jycamus90 Date: Thu, 11 Feb 2016 20:25:55 -0800 Subject: [PATCH 1/2] Adding method start/end line info and more - Added MethodMap class which stores method name, method start line, method end line, and class information - Added ClassSourceMap class to capture which class belongs to which source file --- .../instrumentation/ClassSourceMap.java | 21 +++++++ .../statik/instrumentation/MethodInfo.java | 33 ++++++++++ .../statik/instrumentation/MethodMap.java | 61 +++++++++++++++++++ .../instrumentation/SourceLineAdapter.java | 18 ++++-- .../SourcelineMethodAdapter.java | 8 +++ 5 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 src/org/spideruci/analysis/statik/instrumentation/ClassSourceMap.java create mode 100644 src/org/spideruci/analysis/statik/instrumentation/MethodInfo.java create mode 100644 src/org/spideruci/analysis/statik/instrumentation/MethodMap.java diff --git a/src/org/spideruci/analysis/statik/instrumentation/ClassSourceMap.java b/src/org/spideruci/analysis/statik/instrumentation/ClassSourceMap.java new file mode 100644 index 0000000..f20baec --- /dev/null +++ b/src/org/spideruci/analysis/statik/instrumentation/ClassSourceMap.java @@ -0,0 +1,21 @@ +package org.spideruci.analysis.statik.instrumentation; + +import java.util.HashMap; + +public class ClassSourceMap { + + + private static HashMap classSourceMap = new HashMap(); + + public static HashMap getclassSourceMap(){ + return classSourceMap; + } + + public static void putsourceClassMap(String className, String sourceName){ + classSourceMap.put(className, sourceName); + } + + public static String getSource(String className){ + return classSourceMap.get(className); + } +} diff --git a/src/org/spideruci/analysis/statik/instrumentation/MethodInfo.java b/src/org/spideruci/analysis/statik/instrumentation/MethodInfo.java new file mode 100644 index 0000000..35cd8f1 --- /dev/null +++ b/src/org/spideruci/analysis/statik/instrumentation/MethodInfo.java @@ -0,0 +1,33 @@ +package org.spideruci.analysis.statik.instrumentation; + +public class MethodInfo { + + private int startLine = -1; + private int endLine = -1; + private String className = null; + + public int getStartLine(){ + return startLine; + } + + public int getEndLine(){ + return endLine; + } + + public String getClassName(){ + return className; + } + + public void putStartLine(int line){ + this.startLine = line; + } + + public void putEndLine(int line){ + this.endLine = line; + } + + public void putClassName(String name){ + this.className = name; + } + +} diff --git a/src/org/spideruci/analysis/statik/instrumentation/MethodMap.java b/src/org/spideruci/analysis/statik/instrumentation/MethodMap.java new file mode 100644 index 0000000..a56d494 --- /dev/null +++ b/src/org/spideruci/analysis/statik/instrumentation/MethodMap.java @@ -0,0 +1,61 @@ +package org.spideruci.analysis.statik.instrumentation; + +import java.util.HashMap; + +public class MethodMap { + + private static HashMap methodMap = new HashMap(); + + public static HashMap getMethodMap(){ + return methodMap; + } + + public static void clearMethodMap(){ + methodMap = new HashMap(); + } + + /* + * Put method information into @methodMap + * @name : method name + * @line : source line number + * @className: class name that the method belongs to + */ + public static void putMethod(String name, int line, String className){ + + //if method doesn't exist in @methodMap, + //put the method into the hash and its class information + if(methodMap.get(name) == null){ + methodMap.put(name, new MethodInfo()); + methodMap.get(name).putClassName(className); + } + + //if method start line is set to -1 + //put the current source line number as the method start line and end line + if(methodMap.get(name).getStartLine() == -1){ + methodMap.get(name).putStartLine(line); + methodMap.get(name).putEndLine(line); + } + + //if method start line is not -1 and smaller than current source line number, + //put the current source line number as the method start line + else if(methodMap.get(name).getStartLine() > line) + methodMap.get(name).putStartLine(line); + + //if method start line is not -1 and the end line is smaller than current source line number, + //put the current source line number as the method end line + else if(methodMap.get(name).getEndLine() < line) + methodMap.get(name).putEndLine(line); + + } + + public static void putMethodClass(String methodName, String className){ + methodMap.get(methodName).putClassName(className); + } + + + public static void putMethodMap(String name, MethodInfo info){ + methodMap.put(name, info); + } + + +} diff --git a/src/org/spideruci/analysis/statik/instrumentation/SourceLineAdapter.java b/src/org/spideruci/analysis/statik/instrumentation/SourceLineAdapter.java index 31ce6ac..d540092 100755 --- a/src/org/spideruci/analysis/statik/instrumentation/SourceLineAdapter.java +++ b/src/org/spideruci/analysis/statik/instrumentation/SourceLineAdapter.java @@ -2,7 +2,6 @@ import static org.spideruci.analysis.dynamic.Profiler.REAL_OUT; import static org.spideruci.analysis.dynamic.Profiler.log; - import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; @@ -11,17 +10,26 @@ public class SourceLineAdapter extends ClassVisitor { private String className; - + private String sourceName; + public SourceLineAdapter(ClassVisitor cv, String className) { super(Opcodes.ASM5, cv); this.className = className; } + + @Override + public void visitSource(String source, String debug) { + super.visitSource(source, debug); + sourceName = className.substring(1, className.lastIndexOf("/")+1).replaceAll("/", ".") + source; + ClassSourceMap.putsourceClassMap(className.substring(1).replaceAll("/", "."), sourceName); + + } @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv; - + mv = cv.visitMethod(access, name, desc, signature, exceptions); if (mv != null @@ -29,10 +37,12 @@ public MethodVisitor visitMethod(int access, String name, String desc, TraceEvent methodDecl = EventBuilder.buildMethodDecl(className, access, name+desc); mv = new SourcelineMethodAdapter(methodDecl, access, name, desc, mv); + if (log) { - REAL_OUT.println(methodDecl.getLog()); + REAL_OUT.println(methodDecl.getLog()); } } + return mv; } } diff --git a/src/org/spideruci/analysis/statik/instrumentation/SourcelineMethodAdapter.java b/src/org/spideruci/analysis/statik/instrumentation/SourcelineMethodAdapter.java index 428705f..7a02dc7 100755 --- a/src/org/spideruci/analysis/statik/instrumentation/SourcelineMethodAdapter.java +++ b/src/org/spideruci/analysis/statik/instrumentation/SourcelineMethodAdapter.java @@ -1,11 +1,14 @@ package org.spideruci.analysis.statik.instrumentation; import static org.spideruci.analysis.trace.EventBuilder.*; +<<<<<<< Updated upstream import static org.spideruci.analysis.dynamic.RuntimeTypeProfiler.BUFFER_TYPE_NAME; import static org.spideruci.analysis.dynamic.RuntimeTypeProfiler.BUFFER_TYPE_NAME_SYSID; import static org.spideruci.analysis.dynamic.RuntimeTypeProfiler.CLEAR_BUFFER; import static org.spideruci.analysis.statik.instrumentation.Deputy.RUNTIME_TYPE_PROFILER_NAME; +======= +>>>>>>> Stashed changes import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; @@ -22,6 +25,7 @@ public class SourcelineMethodAdapter extends AdviceAdapter { private TraceEvent methodDecl; private boolean shouldInstrument; + public SourcelineMethodAdapter(TraceEvent methodDecl, int access, String name, String desc, MethodVisitor mv) { @@ -78,6 +82,7 @@ protected void onMethodEnter() { .build(Profiler.METHODENTER); Profiler.latestLineNumber = lineNum; + shouldInstrument = true; } @@ -97,6 +102,7 @@ protected void onMethodExit(int opcode) { .build(Profiler.METHODEXIT); Profiler.latestLineNumber = lineNum; + } @Override @@ -130,6 +136,8 @@ public void visitLineNumber(int line, Label start) { String instructionLog = buildInstructionLog(line, EventType.$line$, opcode, methodDecl.getId()); + MethodMap.putMethod(methodDecl.getDeclName(), line, methodDecl.getDeclOwner().substring(1).replaceAll("/", ".")); + ProfilerCallBack.start(mv) .passArg(instructionLog) .passThis(methodDecl.getDeclAccess()) From 326d0c50a1fa4016956fd7c817395eb07a620017 Mon Sep 17 00:00:00 2001 From: jycamus90 Date: Fri, 12 Feb 2016 11:35:15 -0800 Subject: [PATCH 2/2] random conflict resolved. --- .../statik/instrumentation/SourcelineMethodAdapter.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/org/spideruci/analysis/statik/instrumentation/SourcelineMethodAdapter.java b/src/org/spideruci/analysis/statik/instrumentation/SourcelineMethodAdapter.java index 7a02dc7..e3897fa 100755 --- a/src/org/spideruci/analysis/statik/instrumentation/SourcelineMethodAdapter.java +++ b/src/org/spideruci/analysis/statik/instrumentation/SourcelineMethodAdapter.java @@ -1,14 +1,11 @@ package org.spideruci.analysis.statik.instrumentation; import static org.spideruci.analysis.trace.EventBuilder.*; -<<<<<<< Updated upstream import static org.spideruci.analysis.dynamic.RuntimeTypeProfiler.BUFFER_TYPE_NAME; import static org.spideruci.analysis.dynamic.RuntimeTypeProfiler.BUFFER_TYPE_NAME_SYSID; import static org.spideruci.analysis.dynamic.RuntimeTypeProfiler.CLEAR_BUFFER; import static org.spideruci.analysis.statik.instrumentation.Deputy.RUNTIME_TYPE_PROFILER_NAME; -======= ->>>>>>> Stashed changes import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes;