Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 3fdccd5

Browse files
committed
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
1 parent 6d5c758 commit 3fdccd5

File tree

5 files changed

+137
-4
lines changed

5 files changed

+137
-4
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.spideruci.analysis.statik.instrumentation;
2+
3+
import java.util.HashMap;
4+
5+
public class ClassSourceMap {
6+
7+
8+
private static HashMap<String, String> classSourceMap = new HashMap<String, String>();
9+
10+
public static HashMap<String, String> getclassSourceMap(){
11+
return classSourceMap;
12+
}
13+
14+
public static void putsourceClassMap(String className, String sourceName){
15+
classSourceMap.put(className, sourceName);
16+
}
17+
18+
public static String getSource(String className){
19+
return classSourceMap.get(className);
20+
}
21+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.spideruci.analysis.statik.instrumentation;
2+
3+
public class MethodInfo {
4+
5+
private int startLine = -1;
6+
private int endLine = -1;
7+
private String className = null;
8+
9+
public int getStartLine(){
10+
return startLine;
11+
}
12+
13+
public int getEndLine(){
14+
return endLine;
15+
}
16+
17+
public String getClassName(){
18+
return className;
19+
}
20+
21+
public void putStartLine(int line){
22+
this.startLine = line;
23+
}
24+
25+
public void putEndLine(int line){
26+
this.endLine = line;
27+
}
28+
29+
public void putClassName(String name){
30+
this.className = name;
31+
}
32+
33+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.spideruci.analysis.statik.instrumentation;
2+
3+
import java.util.HashMap;
4+
5+
public class MethodMap {
6+
7+
private static HashMap<String, MethodInfo> methodMap = new HashMap<String, MethodInfo>();
8+
9+
public static HashMap<String, MethodInfo> getMethodMap(){
10+
return methodMap;
11+
}
12+
13+
public static void clearMethodMap(){
14+
methodMap = new HashMap<String, MethodInfo>();
15+
}
16+
17+
/*
18+
* Put method information into @methodMap
19+
* @name : method name
20+
* @line : source line number
21+
* @className: class name that the method belongs to
22+
*/
23+
public static void putMethod(String name, int line, String className){
24+
25+
//if method doesn't exist in @methodMap,
26+
//put the method into the hash and its class information
27+
if(methodMap.get(name) == null){
28+
methodMap.put(name, new MethodInfo());
29+
methodMap.get(name).putClassName(className);
30+
}
31+
32+
//if method start line is set to -1
33+
//put the current source line number as the method start line and end line
34+
if(methodMap.get(name).getStartLine() == -1){
35+
methodMap.get(name).putStartLine(line);
36+
methodMap.get(name).putEndLine(line);
37+
}
38+
39+
//if method start line is not -1 and smaller than current source line number,
40+
//put the current source line number as the method start line
41+
else if(methodMap.get(name).getStartLine() > line)
42+
methodMap.get(name).putStartLine(line);
43+
44+
//if method start line is not -1 and the end line is smaller than current source line number,
45+
//put the current source line number as the method end line
46+
else if(methodMap.get(name).getEndLine() < line)
47+
methodMap.get(name).putEndLine(line);
48+
49+
}
50+
51+
public static void putMethodClass(String methodName, String className){
52+
methodMap.get(methodName).putClassName(className);
53+
}
54+
55+
56+
public static void putMethodMap(String name, MethodInfo info){
57+
methodMap.put(name, info);
58+
}
59+
60+
61+
}

src/org/spideruci/analysis/statik/instrumentation/SourceLineAdapter.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static org.spideruci.analysis.dynamic.Profiler.REAL_OUT;
44
import static org.spideruci.analysis.dynamic.Profiler.log;
5-
65
import org.objectweb.asm.ClassVisitor;
76
import org.objectweb.asm.MethodVisitor;
87
import org.objectweb.asm.Opcodes;
@@ -11,28 +10,39 @@
1110

1211
public class SourceLineAdapter extends ClassVisitor {
1312
private String className;
14-
13+
private String sourceName;
14+
1515
public SourceLineAdapter(ClassVisitor cv, String className) {
1616
super(Opcodes.ASM5, cv);
1717
this.className = className;
1818
}
19+
20+
@Override
21+
public void visitSource(String source, String debug) {
22+
super.visitSource(source, debug);
23+
sourceName = className.substring(1, className.lastIndexOf("/")+1).replaceAll("/", ".") + source;
24+
ClassSourceMap.putsourceClassMap(className.substring(1).replaceAll("/", "."), sourceName);
25+
26+
}
1927

2028
@Override
2129
public MethodVisitor visitMethod(int access, String name, String desc,
2230
String signature, String[] exceptions) {
2331
MethodVisitor mv;
24-
32+
2533
mv = cv.visitMethod(access, name, desc, signature, exceptions);
2634

2735
if (mv != null
2836
&& ((access & Opcodes.ACC_NATIVE) == 0)) {
2937

3038
TraceEvent methodDecl = EventBuilder.buildMethodDecl(className, access, name+desc);
3139
mv = new SourcelineMethodAdapter(methodDecl, access, name, desc, mv);
40+
3241
if (log) {
33-
REAL_OUT.println(methodDecl.getLog());
42+
REAL_OUT.println(methodDecl.getLog());
3443
}
3544
}
45+
3646
return mv;
3747
}
3848
}

src/org/spideruci/analysis/statik/instrumentation/SourcelineMethodAdapter.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package org.spideruci.analysis.statik.instrumentation;
22

33
import static org.spideruci.analysis.trace.EventBuilder.*;
4+
<<<<<<< Updated upstream
45
import static org.spideruci.analysis.dynamic.RuntimeTypeProfiler.BUFFER_TYPE_NAME;
56
import static org.spideruci.analysis.dynamic.RuntimeTypeProfiler.BUFFER_TYPE_NAME_SYSID;
67
import static org.spideruci.analysis.dynamic.RuntimeTypeProfiler.CLEAR_BUFFER;
78
import static org.spideruci.analysis.statik.instrumentation.Deputy.RUNTIME_TYPE_PROFILER_NAME;
89

10+
=======
11+
>>>>>>> Stashed changes
912
import org.objectweb.asm.Label;
1013
import org.objectweb.asm.MethodVisitor;
1114
import org.objectweb.asm.Opcodes;
@@ -22,6 +25,7 @@ public class SourcelineMethodAdapter extends AdviceAdapter {
2225

2326
private TraceEvent methodDecl;
2427
private boolean shouldInstrument;
28+
2529

2630
public SourcelineMethodAdapter(TraceEvent methodDecl, int access, String name,
2731
String desc, MethodVisitor mv) {
@@ -78,6 +82,7 @@ protected void onMethodEnter() {
7882
.build(Profiler.METHODENTER);
7983

8084
Profiler.latestLineNumber = lineNum;
85+
8186
shouldInstrument = true;
8287
}
8388

@@ -97,6 +102,7 @@ protected void onMethodExit(int opcode) {
97102
.build(Profiler.METHODEXIT);
98103

99104
Profiler.latestLineNumber = lineNum;
105+
100106
}
101107

102108
@Override
@@ -130,6 +136,8 @@ public void visitLineNumber(int line, Label start) {
130136
String instructionLog = buildInstructionLog(line, EventType.$line$,
131137
opcode, methodDecl.getId());
132138

139+
MethodMap.putMethod(methodDecl.getDeclName(), line, methodDecl.getDeclOwner().substring(1).replaceAll("/", "."));
140+
133141
ProfilerCallBack.start(mv)
134142
.passArg(instructionLog)
135143
.passThis(methodDecl.getDeclAccess())

0 commit comments

Comments
 (0)