Skip to content

Commit 45b053e

Browse files
committedMay 5, 2015
partitioning based on constructor parameters
1 parent 8db054b commit 45b053e

File tree

9 files changed

+36
-116
lines changed

9 files changed

+36
-116
lines changed
 

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
/README.md~
2+
/svm-classloading/
3+
/svm-jinstruction/
4+
/svm-jvm-conc/

‎svm-partition-trace-spec/src/main/java/com/lexicalscope/svm/partition/spec/Invocation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ public interface Invocation {
44
String callerMethodName();
55
Receiver receiver();
66
Value parameter(String path);
7-
Value callerParameter(int index);
7+
Value local(int index);
88
Value calleeParameter(int index);
99
}

‎svm-partition-trace-spec/src/main/java/com/lexicalscope/svm/partition/spec/MatchersSpec.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static Matcher<CallContext> calledBy(final Matcher<String> matcher) {
6464
public static Matcher<Invocation> callerParameter(final int index, final Matcher<Value> matcher) {
6565
return new FeatureMatcher<Invocation, Value>(matcher, "caller parameter " + index, "parameter") {
6666
@Override protected Value featureValueOf(final Invocation actual) {
67-
return actual.callerParameter(index);
67+
return actual.local(index);
6868
}
6969
};
7070
}

‎svm-partition-trace/src/main/java/com/lexicalscope/svm/partition/trace/ops/JStateCallContext.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,23 @@
1313
import com.lexicalscope.svm.vm.j.JState;
1414
import com.lexicalscope.svm.vm.j.KlassInternalName;
1515
import com.lexicalscope.svm.vm.j.klass.SClass;
16+
import com.lexicalscope.svm.vm.j.klass.SMethodDescriptor;
1617

1718
class JStateCallContext implements CallContext {
1819
private final JState ctx;
1920
private final KlassInternalName klassDesc;
21+
private final SMethodDescriptor targetMethod;
22+
private final Object[] args;
2023

21-
public JStateCallContext(final JState ctx, final KlassInternalName klassDesc) {
24+
public JStateCallContext(
25+
final JState ctx,
26+
final KlassInternalName klassDesc,
27+
final SMethodDescriptor targetMethod,
28+
final Object[] args) {
2229
this.ctx = ctx;
2330
this.klassDesc = klassDesc;
31+
this.targetMethod = targetMethod;
32+
this.args = args;
2433
}
2534

2635
@Override public String callerMethodName() {
@@ -53,7 +62,7 @@ public JStateCallContext(final JState ctx, final KlassInternalName klassDesc) {
5362
throw new UnsupportedOperationException();
5463
}
5564

56-
@Override public Value callerParameter(final int index) {
65+
@Override public Value local(final int index) {
5766
return new Local(){
5867
@Override public Object value() {
5968
return ctx.currentFrame().local(index);
@@ -63,7 +72,7 @@ public JStateCallContext(final JState ctx, final KlassInternalName klassDesc) {
6372
@Override public Value calleeParameter(final int index) {
6473
return new Local(){
6574
@Override public Object value() {
66-
throw new UnsupportedOperationException("we don't know the constructor params because we have to tag the object before its constructor is invoked");
75+
return args[index];
6776
}};
6877
}
6978

‎svm-partition-trace/src/main/java/com/lexicalscope/svm/partition/trace/ops/MatcherPartition.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.lexicalscope.svm.partition.spec.CallContext;
88
import com.lexicalscope.svm.vm.j.JState;
99
import com.lexicalscope.svm.vm.j.KlassInternalName;
10+
import com.lexicalscope.svm.vm.j.klass.SMethodDescriptor;
1011

1112
class MatcherPartition {
1213
private final Matcher<? super CallContext> aMatcher;
@@ -25,8 +26,12 @@ public MatcherPartition(
2526
this.uPartitionTag = uPartitionTag;
2627
}
2728

28-
public Object tagForConstructionOf(final JState ctx, final KlassInternalName klassDesc) {
29-
final CallContext callContext = new JStateCallContext(ctx, klassDesc);
29+
public Object tagForConstructionOf(
30+
final JState ctx,
31+
final KlassInternalName klassDesc,
32+
final SMethodDescriptor targetMethod,
33+
final Object[] args) {
34+
final CallContext callContext = new JStateCallContext(ctx, klassDesc, targetMethod, args);
3035
Object partitionTag;
3136
if (aMatcher.matches(callContext)) {
3237
partitionTag = aPartitionTag;

‎svm-partition-trace/src/main/java/com/lexicalscope/svm/partition/trace/ops/TagConstructorRecieverWithPartition.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public TagConstructorRecieverWithPartition(
2828
ctx.put(
2929
(ObjectRef) args[0],
3030
SClass.OBJECT_TAG_OFFSET,
31-
partition.tagForConstructionOf(ctx, targetMethod.klassName()));
31+
partition.tagForConstructionOf(ctx, targetMethod.klassName(), targetMethod, args));
3232
}
3333

3434
@Override public <T> T query(final InstructionQuery<T> instructionQuery) {

‎svm-partition-trace/src/main/java/com/lexicalscope/svm/partition/trace/ops/TagNewInstanceWithPartitionOp.java

-44
This file was deleted.

‎svm-partition-trace/src/main/java/com/lexicalscope/svm/partition/trace/ops/TrackPartitionAtNew.java

-57
This file was deleted.

‎svm-partition-trace/src/test/java/com/lexicalscope/svm/partition/trace/TestMethodParametersCanBeUsedForPartitioning.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import static org.hamcrest.Matchers.*;
1212
import static org.hamcrest.core.CombinableMatcher.both;
1313

14-
import org.junit.Ignore;
1514
import org.junit.Rule;
1615
import org.junit.Test;
1716

@@ -23,7 +22,8 @@ public class TestMethodParametersCanBeUsedForPartitioning {
2322
{
2423
instrumentPartition(
2524
receiverClass(ClassOutsidePartition.class),
26-
both(receiverClass(ClassSometimesInsidePartition.class)).and(calleeParameter(1, value(equalTo((Object) 2)))),
25+
both(receiverClass(ClassSometimesInsidePartition.class)).
26+
and(calleeParameter(1, value(equalTo((Object) 2)))),
2727
vm);
2828
vm.builder().initialState().meta(TRACE, trace().build());
2929
}
@@ -47,14 +47,18 @@ public int entry(final int x1, final int x2) {
4747
new ClassOutsidePartition().entry(3, 4);
4848
}
4949

50-
@Test @Ignore("need to instrument constructor calls instead of new instructions for this to work") public void collectArgumentsInTrace() throws Exception {
50+
@Test public void collectArgumentsInTrace() throws Exception {
5151
vm.execute();
5252

5353
assertThat(
5454
vm.result().getMeta(TRACE),
55-
has(methodCallOf(ClassSometimesInsidePartition.class, INIT, "(I)V"),
56-
methodReturnOf(ClassSometimesInsidePartition.class, INIT, "(I)V"),
57-
methodCallOf(ClassSometimesInsidePartition.class, "myMethod", "(I)I", any(Object.class), equalTo((Object) 4)),
58-
methodReturnOf(ClassSometimesInsidePartition.class, "myMethod", "(I)I", equalTo((Object) 11))).only().inOrder());
55+
has(methodCallOf(ClassSometimesInsidePartition.class,
56+
INIT, "(I)V", any(Object.class), equalTo((Object) 2)),
57+
methodReturnOf(ClassSometimesInsidePartition.class,
58+
INIT, "(I)V"),
59+
methodCallOf(ClassSometimesInsidePartition.class,
60+
"myMethod", "(I)I", any(Object.class), equalTo((Object) 4)),
61+
methodReturnOf(ClassSometimesInsidePartition.class,
62+
"myMethod", "(I)I", equalTo((Object) 8))).only().inOrder());
5963
}
6064
}

0 commit comments

Comments
 (0)
Please sign in to comment.