Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add flag in new runtime class to reduce tracing excludes while class … #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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,22 @@
package de.unisb.cs.st.javaslicer.tracer.instrumentation;

public class Runtime {

private static boolean isRunning = false;

public static boolean isRunning(){
return isRunning;
}

public static void startTracing(){
isRunning = true;
}

public static void stopTracing(){
isRunning = false;
}

public static void finishTracing(){
stopTracing();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,24 @@
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.JumpInsnNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.LocalVariableNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TryCatchBlockNode;

import de.unisb.cs.st.javaslicer.common.classRepresentation.ReadClass;
import de.unisb.cs.st.javaslicer.common.classRepresentation.ReadMethod;
import de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.AbstractInstruction;
import de.unisb.cs.st.javaslicer.tracer.ThreadTracer;
import de.unisb.cs.st.javaslicer.tracer.Tracer;
import de.unisb.cs.st.javaslicer.tracer.instrumentation.TracingMethodInstrumenter.FixedInstructionIterator;


public class TracingClassInstrumenter implements Opcodes {

Expand All @@ -64,11 +70,77 @@ protected TracingClassInstrumenter(final ReadClass readClass, final Tracer trace

@SuppressWarnings("unchecked")
public void transform(final ClassNode classNode) {

final ListIterator<MethodNode> methodIt = classNode.methods.listIterator();
while (methodIt.hasNext()) {
transformMethod(classNode, methodIt.next(), methodIt);

MethodNode current = methodIt.next();

MethodNode unInstrumented = new MethodNode();
copyMethod(current, unInstrumented);

if(unInstrumented.name.equals("<init>")){
unInstrumented.name = "init_uninstr";
}else if(unInstrumented.name.equals("<clinit>")){
unInstrumented.name = "clinit_uninstr";
}
else{
unInstrumented.name = unInstrumented.name + "_uninstr";
}

//add label for uninstrumented code
LabelNode beginCode = new LabelNode();

transformMethod(classNode, current, methodIt);

//do not modify <cinit> and do not modify abstract or native methods
if(/*!current.name.equals("<clinit>") &&*/ (current.access & ACC_ABSTRACT) == 0 && (current.access & ACC_NATIVE) == 0){

FixedInstructionIterator instructionIterator = new FixedInstructionIterator(current.instructions);

if(current.name.equals("main") && current.desc.equals("([Ljava/lang/String;)V")){
// instructionIterator.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(Runtime.class), "init", "()V"));
instructionIterator.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(Runtime.class), "startTracing", "()V", false));
}

instructionIterator.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(Runtime.class), "isRunning", "()Z", false));
instructionIterator.add(new JumpInsnNode(IFEQ, beginCode));

if(current.name.equals("main") && current.desc.equals("([Ljava/lang/String;)V")){
while (instructionIterator.hasNext()) {
AbstractInsnNode n = instructionIterator.next();

if(n.getOpcode() == INVOKEINTERFACE /*|| n.getOpcode()==RET*/){
MethodInsnNode call = (MethodInsnNode) n;
if(call.name.equals("leaveMethod") && call.owner.equals(Type.getInternalName(ThreadTracer.class))){
//instructionIterator.previous();
//instructionIterator.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(Runtime.class), "stopTracing", "()V"));
instructionIterator.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(Runtime.class), "finishTracing", "()V", false));
instructionIterator.next();
}
}
}
}

instructionIterator = new FixedInstructionIterator(unInstrumented.instructions);
current.instructions.add(beginCode);
while(instructionIterator.hasNext()){
current.instructions.add(instructionIterator.next());
}

// reset the labels
final Iterator<?> insnIt = current.instructions.iterator();
while (insnIt.hasNext()) {
final Object insn = insnIt.next();
if (insn instanceof LabelNode)
((LabelNode)insn).resetLabel();
}

}

}
this.readClass.ready();

}

protected void transformMethod(final ClassNode classNode, final MethodNode method, final ListIterator<MethodNode> methodIt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ public void transform(final ListIterator<MethodNode> methodIt) {
case AbstractInsnNode.MULTIANEWARRAY_INSN:
transformMultiANewArrayInsn((MultiANewArrayInsnNode)insnNode);
break;
case AbstractInsnNode.INVOKE_DYNAMIC_INSN:
//TODO
// ignore
break;
case AbstractInsnNode.FRAME:
// ignore
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,27 @@ private boolean isExcluded(final String javaClassName) {
if (javaClassName.startsWith("de.unisb.cs.st.sequitur"))
return true;

// Object
if (javaClassName.equals("java.lang.Object"))
return true;
// references
if (javaClassName.startsWith("java.lang.ref."))
return true;

//////////////////////////////////////////////////////////////////
// NOTE: these will be cleaned up when the system runs stable
//////////////////////////////////////////////////////////////////

/*
if (javaClassName.equals("java.lang.System"))
return true;
/*

if (javaClassName.equals("java.lang.VerifyError")
|| javaClassName.equals("java.lang.ClassCircularityError")
|| javaClassName.equals("java.lang.LinkageError")
|| javaClassName.equals("java.lang.Error")
|| javaClassName.equals("java.lang.Throwable"))
return null;
*/


if (javaClassName.startsWith("java.util.Collections"))
return true;
Expand All @@ -193,14 +200,7 @@ private boolean isExcluded(final String javaClassName) {
return true;
if (javaClassName.equals("java.lang.Math"))
return true;

// Object
if (javaClassName.equals("java.lang.Object"))
return true;
// references
if (javaClassName.startsWith("java.lang.ref."))
return true;

*/
return false;
}

Expand Down