Commit c5c39352 authored by Lukáš Marek's avatar Lukáš Marek

Reverted back to 566

parent 829b2d92
package ch.usi.dag.disl.test.staticfield;
import ch.usi.dag.disl.annotation.AfterReturning;
import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.annotation.SyntheticStaticField;
import ch.usi.dag.disl.annotation.SyntheticStaticField.Scope;
import ch.usi.dag.disl.marker.BodyMarker;
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
public class DiSLClass {
@SyntheticStaticField(scope = Scope.PERCLASS)
public static String s;
@SyntheticStaticField(scope = Scope.PERMETHOD)
public static String mid;
@Before(marker = BodyMarker.class, scope = "TargetClass.*", order = 2)
public static void precondition(MethodStaticContext msc) {
mid = msc.thisMethodFullName();
System.out.println("Entering " + mid + " while s is " + s);
}
@AfterReturning(marker = BodyMarker.class, scope = "TargetClass.*", order = 2)
public static void postcondition() {
System.out.println("Exiting " + mid + " while s is " + s);
}
@Before(marker = BodyMarker.class, scope = "TargetClass.print", order = 1)
public static void precondition2() {
s = "Set in TargetClass.print";
}
}
Manifest-Version: 1.0
DiSL-Classes: ch.usi.dag.disl.test.staticfield.DiSLClass
\ No newline at end of file
package ch.usi.dag.disl.test.staticfield;
public class TargetClass {
public void print() {
System.out.println("This is the body of TargetClass.print");
}
public static void main(String[] args) {
TargetClass t = new TargetClass();
t.print();
}
}
......@@ -24,7 +24,6 @@ import ch.usi.dag.disl.cbloader.ManifestHelper.ManifestInfo;
import ch.usi.dag.disl.classparser.ClassParser;
import ch.usi.dag.disl.exception.DiSLException;
import ch.usi.dag.disl.exception.DiSLIOException;
import ch.usi.dag.disl.exception.DiSLInMethodException;
import ch.usi.dag.disl.exception.DynamicInfoException;
import ch.usi.dag.disl.exception.InitException;
import ch.usi.dag.disl.exception.ManifestInfoException;
......@@ -36,7 +35,6 @@ import ch.usi.dag.disl.exception.TransformerException;
import ch.usi.dag.disl.exclusion.ExclusionSet;
import ch.usi.dag.disl.guard.GuardHelper;
import ch.usi.dag.disl.localvar.SyntheticLocalVar;
import ch.usi.dag.disl.localvar.SyntheticStaticFieldVar;
import ch.usi.dag.disl.localvar.ThreadLocalVar;
import ch.usi.dag.disl.processor.Proc;
import ch.usi.dag.disl.processor.generator.PIResolver;
......@@ -82,8 +80,6 @@ public class DiSL {
private final Set<Scope> exclusionSet;
private final List<Snippet> snippets;
private final List<SyntheticStaticFieldVar> syntheticStaticFields;
/**
* DiSL initialization
......@@ -146,10 +142,6 @@ public class DiSL {
// - this is set when everything is ok
// - it serves as initialization flag
snippets = parsedSnippets;
// get parsed synthetic static fields
syntheticStaticFields = new LinkedList<SyntheticStaticFieldVar>(parser
.getAllLocalVars().getSyntheticStaticFields().values());
// TODO put checker here
// like After should catch normal and abnormal execution
......@@ -317,8 +309,8 @@ public class DiSL {
// *** viewing ***
Weaver.instrument(classNode, methodNode, snippetMarkings,
new LinkedList<SyntheticLocalVar>(usedSLVs),
syntheticStaticFields, staticInfo, piResolver);
new LinkedList<SyntheticLocalVar>(usedSLVs), staticInfo,
piResolver);
if(debug) {
System.out.println("Instumenting method: " + className
......@@ -403,17 +395,7 @@ public class DiSL {
// instrument all methods in a class
for (MethodNode methodNode : classNode.methods) {
boolean methodChanged = false;
// intercept all exceptions and add a method name
try {
methodChanged = instrumentMethod(classNode, methodNode);
}
catch(DiSLException e) {
throw new DiSLInMethodException(
classNode.name + "." + methodNode.name, e);
}
boolean methodChanged = instrumentMethod(classNode, methodNode);
// add method to the set of changed methods
if (methodChanged) {
......
package ch.usi.dag.disl.annotation;
public @interface SyntheticStaticField {
public enum Scope {
PERCLASS, PERMETHOD
}
Scope scope() default (Scope.PERMETHOD);
}
......@@ -18,11 +18,9 @@ import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.analysis.Frame;
import org.objectweb.asm.tree.analysis.SourceValue;
import ch.usi.dag.disl.annotation.SyntheticStaticField;
import ch.usi.dag.disl.annotation.SyntheticLocal;
import ch.usi.dag.disl.exception.ParserException;
import ch.usi.dag.disl.localvar.LocalVars;
import ch.usi.dag.disl.localvar.SyntheticStaticFieldVar;
import ch.usi.dag.disl.localvar.SyntheticLocalVar;
import ch.usi.dag.disl.localvar.ThreadLocalVar;
import ch.usi.dag.disl.util.AsmHelper;
......@@ -120,15 +118,6 @@ abstract class AbstractParser {
continue;
}
// static local
if (annotationType.equals(Type.getType(SyntheticStaticField.class))) {
SyntheticStaticFieldVar slv = parseSyntheticStaticField(
className, field, annotation);
result.getSyntheticStaticFields().put(slv.getID(), slv);
continue;
}
throw new ParserException("Field " + className + "."
+ field.name + " has unsupported DiSL annotation");
}
......@@ -382,40 +371,4 @@ abstract class AbstractParser {
}
}
}
private SyntheticStaticFieldVar parseSyntheticStaticField(String className,
FieldNode field, AnnotationNode annotation) throws ParserException {
// check if field is static
if ((field.access & Opcodes.ACC_STATIC) == 0) {
throw new ParserException("Field " + field.name + className + "."
+ " declared as SyntheticLocalField but is not static");
}
// parse annotation data
STLAnnotaionData slad = new STLAnnotaionData();
ParserHelper.parseAnnotation(slad, annotation);
SyntheticStaticField.Scope ssfScope = SyntheticStaticField.Scope.PERMETHOD;
if (slad.scope != null) {
// enum is converted to array
// - first value is class name
// - second value is value name
ssfScope = SyntheticStaticField.Scope.valueOf(slad.scope[1]);
}
// field type
Type fieldType = Type.getType(field.desc);
return new SyntheticStaticFieldVar(className, field.name, fieldType,
ssfScope, field.access);
}
private static class STLAnnotaionData {
public String[] scope = null;
}
}
package ch.usi.dag.disl.exception;
public class DiSLInMethodException extends DiSLException {
private static final long serialVersionUID = 4819683200958042417L;
public DiSLInMethodException() {
super();
}
public DiSLInMethodException(String message, Throwable cause) {
super(message, cause);
}
public DiSLInMethodException(String message) {
super(message);
}
public DiSLInMethodException(Throwable cause) {
super(cause);
}
}
......@@ -9,8 +9,6 @@ public class LocalVars {
new HashMap<String, SyntheticLocalVar>();
private Map<String, ThreadLocalVar> threadLocals =
new HashMap<String, ThreadLocalVar>();
private Map<String, SyntheticStaticFieldVar> syntheticStaticFields =
new HashMap<String, SyntheticStaticFieldVar>();
public Map<String, SyntheticLocalVar> getSyntheticLocals() {
return syntheticLocals;
......@@ -19,15 +17,10 @@ public class LocalVars {
public Map<String, ThreadLocalVar> getThreadLocals() {
return threadLocals;
}
public Map<String, SyntheticStaticFieldVar> getSyntheticStaticFields() {
return syntheticStaticFields;
}
public void putAll(LocalVars localVars) {
syntheticLocals.putAll(localVars.getSyntheticLocals());
threadLocals.putAll(localVars.getThreadLocals());
syntheticStaticFields.putAll(localVars.getSyntheticStaticFields());
}
}
package ch.usi.dag.disl.localvar;
import org.objectweb.asm.Type;
import ch.usi.dag.disl.annotation.SyntheticStaticField.Scope;
public class SyntheticStaticFieldVar extends AbstractLocalVar {
private int access;
private Scope scope;
public SyntheticStaticFieldVar(String className, String fieldName, Type type,
Scope scope, int access) {
super(className, fieldName, type);
this.scope = scope;
this.access = access;
}
public String getTypeAsDesc() {
return getType().getDescriptor();
}
public int getAccess() {
return access;
}
public Scope getScope() {
return scope;
}
}
......@@ -8,7 +8,6 @@ import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.JumpInsnNode;
......@@ -23,9 +22,7 @@ import ch.usi.dag.disl.annotation.AfterReturning;
import ch.usi.dag.disl.annotation.AfterThrowing;
import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.annotation.SyntheticLocal.Initialize;
import ch.usi.dag.disl.annotation.SyntheticStaticField;
import ch.usi.dag.disl.exception.DynamicInfoException;
import ch.usi.dag.disl.localvar.SyntheticStaticFieldVar;
import ch.usi.dag.disl.localvar.SyntheticLocalVar;
import ch.usi.dag.disl.processor.generator.PIResolver;
import ch.usi.dag.disl.snippet.Shadow;
......@@ -153,57 +150,6 @@ public class Weaver {
methodNode.maxLocals += syntheticLocalVars.size();
}
private static void fixSyntheticStaticField(ClassNode clazz, MethodNode method,
List<SyntheticStaticFieldVar> syntheticStaticFieldVars) {
for (AbstractInsnNode instr : method.instructions.toArray()) {
int opcode = instr.getOpcode();
if (!(opcode == Opcodes.GETSTATIC)
&& !(opcode == Opcodes.PUTSTATIC)) {
continue;
}
FieldInsnNode field_instr = (FieldInsnNode) instr;
for (SyntheticStaticFieldVar var : syntheticStaticFieldVars) {
if (!field_instr.owner.equals(var.getOwner())
|| !field_instr.name.equals(var.getName())) {
continue;
}
field_instr.owner = clazz.name;
field_instr.name = "$DISL_" + field_instr.name;
if (var.getScope() == SyntheticStaticField.Scope.PERMETHOD) {
field_instr.name += clazz.methods.indexOf(method);
}
int count = 0;
for (FieldNode field : clazz.fields) {
if (field.name.equals(field_instr.name)) {
break;
}
count++;
}
if (count == clazz.fields.size()) {
clazz.fields.add(new FieldNode(var.getAccess(), field_instr.name,
field_instr.desc, null, null));
}
break;
}
}
}
// Return a successor label of weaving location corresponding to
// the input 'end'.
private static LabelNode getEndLabel(MethodNode methodNode,
......@@ -297,7 +243,6 @@ public class Weaver {
public static void instrument(ClassNode classNode, MethodNode methodNode,
Map<Snippet, List<Shadow>> snippetMarkings,
List<SyntheticLocalVar> syntheticLocalVars,
List<SyntheticStaticFieldVar> syntheticStaticFieldVars,
SCGenerator staticInfoHolder, PIResolver piResolver)
throws DynamicInfoException {
......@@ -370,7 +315,6 @@ public class Weaver {
}
static2Local(methodNode, syntheticLocalVars);
fixSyntheticStaticField(classNode, methodNode, syntheticStaticFieldVars);
AdvancedSorter.sort(methodNode);
}
......
......@@ -300,11 +300,9 @@ public class WeavingCode {
// index should be less than the stack height
if (operand >= basicframe.getStackSize() || operand < 0) {
throw new DynamicInfoException(
"Dynamic context wrong access." +
" Access out of bounds. Accessed " + operand +
", but the size of stack is "
+ basicframe.getLocals());
throw new DiSLFatalException("Illegal access of index "
+ operand + " on a stack with "
+ basicframe.getStackSize() + " operands");
}
// Type checking
......@@ -312,10 +310,9 @@ public class WeavingCode {
operand).getType();
if (t.getSort() != targetType.getSort()) {
throw new DynamicInfoException(
"Dynamic context wrong access. Requested \"" +
t + "\" but found \"" + targetType
+ "\" on the stack.");
throw new DiSLFatalException("Unwanted type \""
+ targetType + "\", while user needs \"" + t
+ "\"");
}
// store the stack value without changing the semantic
......@@ -346,10 +343,8 @@ public class WeavingCode {
// index should be less than the size of local variables
if (slot >= basicframe.getLocals() || slot < 0) {
throw new DynamicInfoException(
"Dynamic context wrong access." +
" Access out of bounds. Accessed " + slot +
", but the size of stack is "
throw new DiSLFatalException("Illegal access of index "
+ slot + " while the size of local variable is "
+ basicframe.getLocals());
}
......@@ -357,10 +352,8 @@ public class WeavingCode {
Type targetType = basicframe.getLocal(slot).getType();
if (t.getSort() != targetType.getSort()) {
throw new DynamicInfoException(
"Dynamic context wrong access. Requested \"" +
t + "\" but found \"" + targetType
+ "\" on the stack.");
throw new DiSLFatalException("Unwanted type \""
+ targetType + "\", while user needs \"" + t + "\"");
}
// box value if applicable
......@@ -379,10 +372,8 @@ public class WeavingCode {
// index should be less than the size of local variables
if (operand >= basicframe.getLocals() || operand < 0) {
throw new DynamicInfoException(
"Dynamic context wrong access." +
" Access out of bounds. Accessed " + operand +
", but the size of stack is "
throw new DiSLFatalException("Illegal access of index "
+ operand + " while the size of local variable is "
+ basicframe.getLocals());
}
......@@ -390,10 +381,8 @@ public class WeavingCode {
Type targetType = basicframe.getLocal(operand).getType();
if (t.getSort() != targetType.getSort()) {
throw new DynamicInfoException(
"Dynamic context wrong access. Requested \"" +
t + "\" but found \"" + targetType
+ "\" on the stack.");
throw new DiSLFatalException("Unwanted type \""
+ targetType + "\", while user needs \"" + t + "\"");
}
// box value if applicable
......
......@@ -8,7 +8,6 @@ import java.util.concurrent.atomic.AtomicLong;
import ch.usi.dag.disl.DiSL;
import ch.usi.dag.disl.exception.DiSLException;
import ch.usi.dag.disl.exception.DiSLInMethodException;
public abstract class DiSLServer {
......@@ -84,19 +83,7 @@ public abstract class DiSLServer {
if (e instanceof DiSLException) {
System.err.print("DiSL error");
// report during which method it happened
if (e instanceof DiSLInMethodException) {
System.err.print(" (while instrumenting method \""
+ e.getMessage() + "\")");
// set inner error
e = e.getCause();
}
System.err.println(": " + e.getMessage());
System.err.println("DiSL error: " + e.getMessage());
reportInnerError(e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment