Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.spideruci.analysis.statik.instrumentation;

import java.util.HashMap;

public class ClassSourceMap {


private static HashMap<String, String> classSourceMap = new HashMap<String, String>();

public static HashMap<String, String> 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);
}
}
33 changes: 33 additions & 0 deletions src/org/spideruci/analysis/statik/instrumentation/MethodInfo.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
61 changes: 61 additions & 0 deletions src/org/spideruci/analysis/statik/instrumentation/MethodMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.spideruci.analysis.statik.instrumentation;

import java.util.HashMap;

public class MethodMap {

private static HashMap<String, MethodInfo> methodMap = new HashMap<String, MethodInfo>();

public static HashMap<String, MethodInfo> getMethodMap(){
return methodMap;
}

public static void clearMethodMap(){
methodMap = new HashMap<String, MethodInfo>();
}

/*
* 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);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -11,28 +10,39 @@

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
&& ((access & Opcodes.ACC_NATIVE) == 0)) {

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class SourcelineMethodAdapter extends AdviceAdapter {

private TraceEvent methodDecl;
private boolean shouldInstrument;


public SourcelineMethodAdapter(TraceEvent methodDecl, int access, String name,
String desc, MethodVisitor mv) {
Expand Down Expand Up @@ -78,6 +79,7 @@ protected void onMethodEnter() {
.build(Profiler.METHODENTER);

Profiler.latestLineNumber = lineNum;

shouldInstrument = true;
}

Expand All @@ -97,6 +99,7 @@ protected void onMethodExit(int opcode) {
.build(Profiler.METHODEXIT);

Profiler.latestLineNumber = lineNum;

}

@Override
Expand Down Expand Up @@ -130,6 +133,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())
Expand Down