Skip to content

Commit 738f070

Browse files
committed
Merge pull request #2 from jon-bell/master
Close some unclosed streams. Disable mutability analysis.
2 parents eac8733 + 7e3dbae commit 738f070

3 files changed

Lines changed: 85 additions & 79 deletions

File tree

Code/ChroniclerJ/src/edu/columbia/cs/psl/chroniclerj/Instrumenter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public static AnnotatedMethod getAnnotatedMethod(String owner, String name, Stri
8282
private static void analyzeClass(InputStream inputStream) {
8383
try {
8484
ClassNode analysisResult = ma.analyzeClass(new ClassReader(inputStream));
85+
inputStream.close();
8586
if (analysisResult == null) {
8687
logger.error("Null analysis result on this analysis");
8788
}
@@ -111,6 +112,7 @@ private static byte[] instrumentClass(InputStream is) {
111112
cr.accept(uidAdder, 0);
112113
byte[] b = cw.toByteArray();
113114
cr = new ClassReader(b);
115+
is.close();
114116
}
115117

116118
ClassWriter cw = new InstrumenterClassWriter(cr, ClassWriter.COMPUTE_MAXS

Code/ChroniclerJ/src/edu/columbia/cs/psl/chroniclerj/analysis/MutabilityAnalyzer.java

Lines changed: 67 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.objectweb.asm.tree.FieldInsnNode;
1515
import org.objectweb.asm.tree.MethodInsnNode;
1616
import org.objectweb.asm.tree.MethodNode;
17+
import org.objectweb.asm.util.Printer;
1718

1819
import edu.columbia.cs.psl.chroniclerj.struct.AnnotatedMethod;
1920
import edu.columbia.cs.psl.chroniclerj.struct.Expression;
@@ -84,6 +85,7 @@ public ClassNode analyzeClass(ClassReader cr) {
8485
ClassNode cn = new ClassNode();
8586
cr.accept(cn, ClassReader.SKIP_DEBUG);
8687

88+
System.out.println("Analyze " + cn.name);
8789
for (Object o : cn.methods) {
8890
MethodNode thisMethodNode = (MethodNode) o;
8991
AnnotatedMethod thisMethod = findOrAddMethod(cn.name, thisMethodNode);
@@ -93,70 +95,71 @@ public ClassNode analyzeClass(ClassReader cr) {
9395
if ((thisMethodNode.access & ACC_NATIVE) != 0) // is native
9496
NonDeterministicLoggingMethodVisitor.registerNDMethod(cn.name, thisMethodNode.name,
9597
thisMethodNode.desc);
96-
97-
ListIterator<?> i = thisMethodNode.instructions.iterator();
98-
boolean isFirstInsn = true;
99-
while (i.hasNext()) {
100-
AbstractInsnNode n = (AbstractInsnNode) i.next();
101-
if (n.getType() == AbstractInsnNode.FIELD_INSN) // Field
102-
// Instruction
103-
{
104-
FieldInsnNode fn = (FieldInsnNode) n;
105-
if (n.getOpcode() == Opcodes.PUTSTATIC) {
106-
// This instruction is changing a static field. Previous
107-
// instruction is the value to set to
108-
FieldExpression pi = new FieldExpression(fn.name, fn.owner, fn.desc,
109-
n.getOpcode());
110-
thisMethod.getPutFieldInsns().add(pi);
111-
thisMethod.setMutatesFieldsDirectly();
112-
} else if (n.getOpcode() == Opcodes.PUTFIELD) {
113-
114-
// This instruction is changing a field.
115-
// Previous instruction will have the value that we are
116-
// setting to
117-
FieldExpression pi = new FieldExpression(fn.name, fn.owner, fn.desc,
118-
n.getOpcode());
119-
pi.setParent(parentInstructionOf(thisMethodNode, pi,
120-
thisMethodNode.instructions.iterator(i.previousIndex())));
121-
thisMethod.getPutFieldInsns().add(pi);
122-
thisMethod.setMutatesFieldsDirectly();
123-
}
124-
} else if (n.getType() == AbstractInsnNode.METHOD_INSN) // Method
125-
// invocation
126-
{
127-
MethodInsnNode whatWeCall = (MethodInsnNode) n;
128-
AnnotatedMethod otherMethod = findOrAddMethod(whatWeCall.owner,
129-
whatWeCall.name, whatWeCall.desc, 0);
130-
otherMethod.functionsThatCallMe.add(thisMethod);
131-
MethodExpression otherMethodExp = new MethodExpression(otherMethod,
132-
whatWeCall.getOpcode());
133-
otherMethodExp.getParams().addAll(
134-
paramsOf(thisMethodNode, otherMethodExp,
135-
thisMethodNode.instructions.iterator(i.previousIndex())));
136-
137-
if (whatWeCall.getOpcode() != Opcodes.INVOKESTATIC)
138-
otherMethodExp.setParent(parentInstructionOf(thisMethodNode,
139-
otherMethodExp,
140-
thisMethodNode.instructions.iterator(i.previousIndex())));
141-
142-
if (NonDeterministicLoggingMethodVisitor.isND(whatWeCall.owner,
143-
whatWeCall.name, whatWeCall.desc)
144-
&& whatWeCall.name.equals("<init>")
145-
&& whatWeCall.owner.equals(cn.superName)
146-
&& thisMethodNode.name.equals("<init>") && isFirstInsn) {
147-
NonDeterministicLoggingMethodVisitor.registerNDMethod(cn.name,
148-
thisMethodNode.name, thisMethodNode.desc);
149-
}
150-
151-
thisMethod.functionsThatICall.add(otherMethodExp);
152-
153-
isFirstInsn = false;
154-
} else if (n.getType() == AbstractInsnNode.INVOKE_DYNAMIC_INSN) // Invoke
155-
// dynamic
156-
{
157-
158-
}
159-
}
98+
//
99+
// ListIterator<?> i = thisMethodNode.instructions.iterator();
100+
// boolean isFirstInsn = true;
101+
// while (i.hasNext()) {
102+
// AbstractInsnNode n = (AbstractInsnNode) i.next();
103+
// System.out.println(n + " " + Printer.OPCODES[n.getOpcode()]);
104+
// if (n.getType() == AbstractInsnNode.FIELD_INSN) // Field
105+
// // Instruction
106+
// {
107+
// FieldInsnNode fn = (FieldInsnNode) n;
108+
// if (n.getOpcode() == Opcodes.PUTSTATIC) {
109+
// // This instruction is changing a static field. Previous
110+
// // instruction is the value to set to
111+
// FieldExpression pi = new FieldExpression(fn.name, fn.owner, fn.desc,
112+
// n.getOpcode());
113+
// thisMethod.getPutFieldInsns().add(pi);
114+
// thisMethod.setMutatesFieldsDirectly();
115+
// } else if (n.getOpcode() == Opcodes.PUTFIELD) {
116+
//
117+
// // This instruction is changing a field.
118+
// // Previous instruction will have the value that we are
119+
// // setting to
120+
// FieldExpression pi = new FieldExpression(fn.name, fn.owner, fn.desc,
121+
// n.getOpcode());
122+
// pi.setParent(parentInstructionOf(thisMethodNode, pi,
123+
// thisMethodNode.instructions.iterator(i.previousIndex())));
124+
// thisMethod.getPutFieldInsns().add(pi);
125+
// thisMethod.setMutatesFieldsDirectly();
126+
// }
127+
// } else if (n.getType() == AbstractInsnNode.METHOD_INSN) // Method
128+
// // invocation
129+
// {
130+
// MethodInsnNode whatWeCall = (MethodInsnNode) n;
131+
// AnnotatedMethod otherMethod = findOrAddMethod(whatWeCall.owner,
132+
// whatWeCall.name, whatWeCall.desc, 0);
133+
// otherMethod.functionsThatCallMe.add(thisMethod);
134+
// MethodExpression otherMethodExp = new MethodExpression(otherMethod,
135+
// whatWeCall.getOpcode());
136+
// otherMethodExp.getParams().addAll(
137+
// paramsOf(thisMethodNode, otherMethodExp,
138+
// thisMethodNode.instructions.iterator(i.previousIndex())));
139+
//
140+
// if (whatWeCall.getOpcode() != Opcodes.INVOKESTATIC)
141+
// otherMethodExp.setParent(parentInstructionOf(thisMethodNode,
142+
// otherMethodExp,
143+
// thisMethodNode.instructions.iterator(i.previousIndex())));
144+
//
145+
// if (NonDeterministicLoggingMethodVisitor.isND(whatWeCall.owner,
146+
// whatWeCall.name, whatWeCall.desc)
147+
// && whatWeCall.name.equals("<init>")
148+
// && whatWeCall.owner.equals(cn.superName)
149+
// && thisMethodNode.name.equals("<init>") && isFirstInsn) {
150+
// NonDeterministicLoggingMethodVisitor.registerNDMethod(cn.name,
151+
// thisMethodNode.name, thisMethodNode.desc);
152+
// }
153+
//
154+
// thisMethod.functionsThatICall.add(otherMethodExp);
155+
//
156+
// isFirstInsn = false;
157+
// } else if (n.getType() == AbstractInsnNode.INVOKE_DYNAMIC_INSN) // Invoke
158+
// // dynamic
159+
// {
160+
//
161+
// }
162+
// }
160163
}
161164
ClassNode ret = new ClassNode();
162165
ret.name = cn.name;

Code/ChroniclerJ/src/edu/columbia/cs/psl/chroniclerj/struct/AnnotatedMethod.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,22 @@ public void setFullyDiscovered(boolean isFullyDiscovered) {
165165
private int callsNDMethods = -1;
166166

167167
public boolean isCallsNDMethods() {
168-
if (callsNDMethods > -1)
169-
return callsNDMethods == 1;
170-
for (MethodExpression ex : functionsThatICall) {
171-
AnnotatedMethod am = ex.getMethod();
172-
if (am != null) {
173-
if (NonDeterministicLoggingMethodVisitor.isND(am.getClazz(), am.getName(),
174-
am.getDescriptor())
175-
|| am.isCallsNDMethods()) {
176-
callsNDMethods = 1;
177-
return true;
178-
}
179-
}
180-
}
181-
callsNDMethods = 0;
182-
return false;
168+
// if (callsNDMethods > -1)
169+
// return callsNDMethods == 1;
170+
// for (MethodExpression ex : functionsThatICall) {
171+
// AnnotatedMethod am = ex.getMethod();
172+
// if (am != null) {
173+
// if (NonDeterministicLoggingMethodVisitor.isND(am.getClazz(), am.getName(),
174+
// am.getDescriptor())
175+
// || am.isCallsNDMethods()) {
176+
// callsNDMethods = 1;
177+
// return true;
178+
// }
179+
// }
180+
// }
181+
// callsNDMethods = 0;
182+
// return false;
183+
return true;
183184
}
184185

185186
}

0 commit comments

Comments
 (0)