Skip to content

Commit

Permalink
java 7 support, with much pain for stack maps :)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliandolby committed Oct 6, 2014
1 parent c006dbc commit 36709b9
Show file tree
Hide file tree
Showing 45 changed files with 1,178 additions and 95 deletions.
2 changes: 1 addition & 1 deletion com.ibm.wala.cast.java.test.data/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annota
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
Expand Down Expand Up @@ -105,7 +105,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.net.URL;

import org.junit.Ignore;
import org.junit.Test;

import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/com.ibm.wala.cast.js.test.data/examples-src&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#10;"/>
</listAttribute>
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/Java SE 7/"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.ibm.wala.cast.js.rhino.test"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx800M -verbose:gc -ea"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx2048M -verbose:gc -ea"/>
</launchConfiguration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding//harness-src/com/ibm/wala/cast/js/test/TestCorrelatedPairExtraction.java=UTF-8
10 changes: 5 additions & 5 deletions com.ibm.wala.cast.js.test/tests/TestSimpleCallGraphShape.launch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/com.ibm.wala.cast.js.test/harness-src/com/ibm/wala/cast/js/test/TestSimpleCallGraphShape.java"/>
<listEntry value="/com.ibm.wala.cast.js.rhino.test/harness-src/com/ibm/wala/cast/js/test/TestSimpleCallGraphShapeRhino.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
Expand All @@ -10,8 +10,8 @@
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.ibm.wala.cast.js.test.TestSimpleCallGraphShape"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.ibm.wala.cast.js.test"/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.ibm.wala.cast.js.test.TestSimpleCallGraphShapeRhino"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.ibm.wala.cast.js.rhino.test"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx256M -Dcom.ibm.wala.tracefile=/tmp/jssimplecg.out -ea"/>
</launchConfiguration>
2 changes: 1 addition & 1 deletion com.ibm.wala.cast.js/dat/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ function Referrer() {
this.toString = function () { return new String();}
}
document.referrer = new Referrer();
document.evaluate = function evaluate(a, b, c, d, e) {
document.evaluate = function documentEvaluate(a, b, c, d, e) {
}
document.execCommand = function execCommand(a,b,c) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.shrikeBT.IBinaryOpInstruction.IOperator;
import com.ibm.wala.shrikeBT.IComparisonInstruction.Operator;
import com.ibm.wala.shrikeCT.BootstrapMethodsReader.BootstrapMethod;
import com.ibm.wala.shrikeCT.InvalidClassFileException;
import com.ibm.wala.ssa.SSAAddressOfInstruction;
import com.ibm.wala.ssa.SSAArrayLengthInstruction;
Expand Down Expand Up @@ -603,6 +604,11 @@ public SetPrototype SetPrototype(int object, int prototype) {
return new SetPrototype(object, prototype);
}

@Override
public SSAInstruction InvokeInstruction(int i, int[] js, int j, CallSiteReference site, BootstrapMethod bootstrap) {
throw new UnsupportedOperationException();
}

};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/com.ibm.wala.cast.test"/>
Expand All @@ -11,6 +11,7 @@
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/Java SE 7"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.ibm.wala.cast.test"/>
</launchConfiguration>
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annota
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
Expand Down Expand Up @@ -105,7 +105,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
Expand Down
10 changes: 9 additions & 1 deletion com.ibm.wala.core.testdata/src/dynamicCG/ExtraClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

public class ExtraClass {
private final Object x;
private final long l;

public ExtraClass(Object x) {
this.x = x;
this.l = (x==null)? 0: x.hashCode();
}

public ExtraClass() {
Expand All @@ -21,6 +23,12 @@ private static String getName(Object x) {

@Override
public String toString() {
return getName(x);
String s = getName(x);
long t = l;
String s2 = getName(x);
if (t < 0) {
t = 0;
}
return s + ":" + t + ":" + s2;
}
}
2 changes: 1 addition & 1 deletion com.ibm.wala.core.testdata/src/dynamicCG/MainClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class MainClass {
private final Object x;

private MainClass(Object x) {
this.x = x;
}
Expand Down
41 changes: 41 additions & 0 deletions com.ibm.wala.core.testdata/src/shrike/StackMaps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package shrike;

public class StackMaps {
private int field1;
private int field2;
private int min;

public StackMaps(int field1, int field2) {
setMin(field1 > field2? field2: field1);
this.field1 = field1;
this.field2 = field2;
}

private void setMin(int x) {
this.min = x;
}

public static void main(String[] args) {
String result = "success";
try {
if ("max".equals(args[0])) {
System.err.println(new StackMaps(3, 2).max());
} else {
System.err.println(new StackMaps("min" == args[0]? 7: 5, 2).min());
}
} catch (RuntimeException e) {
result = "bad";
throw e;
} finally {
System.err.println(result);
}
}

public int max() {
return field1 > field2? field1: field2;
}

public int min() {
return min;
}
}
2 changes: 2 additions & 0 deletions com.ibm.wala.core.tests/dat/base.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Primordial,Java,stdlib,none
Primordial,Java,jarFile,primordial.jar.model
3 changes: 3 additions & 0 deletions com.ibm.wala.core.tests/dat/ocaml_compr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Primordial,Java,stdlib,none
Primordial,Java,jarFile,primordial.jar.model
Application,Java,jarFile,compr
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.ibm.wala.core.tests.util.WalaTestCase;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.properties.WalaProperties;
import com.ibm.wala.shrike.cg.DynamicCallGraph;
import com.ibm.wala.shrikeBT.analysis.Analyzer.FailureException;
import com.ibm.wala.shrikeCT.InvalidClassFileException;
Expand Down Expand Up @@ -60,7 +61,17 @@ protected void instrument(String testJarLocation) throws IOException, ClassNotFo
assert new File(instrumentedJarLocation).delete();
}

DynamicCallGraph.main(new String[]{testJarLocation, "-o", instrumentedJarLocation});
String rtJar = null;
for(String jar : WalaProperties.getJ2SEJarFiles()) {
if (jar.endsWith("rt.jar") || jar.endsWith("classes.jar")) {
rtJar = jar;
}
}

DynamicCallGraph.main(
rtJar == null?
new String[]{testJarLocation, "-o", instrumentedJarLocation}:
new String[]{testJarLocation, "-o", instrumentedJarLocation, "--rt-jar", rtJar});
Assert.assertTrue("expected to create /tmp/test.jar", new File(instrumentedJarLocation).exists());
instrumentedJarBuilt = true;
}
Expand All @@ -82,11 +93,19 @@ protected void run(String mainClass, String exclusionsFile) throws IOException,
System.setProperty("dynamicCGFilter", tmpFile.getCanonicalPath());
}
try {
testMain.invoke(null, (Object)new String[0]);
testMain.invoke(null, (Object)new String[0]);
} catch (Throwable e) {
// exceptions here are from program being instrumented
// this is fine, since we are collecting its call graph
// and exceptions are possible behavior.

// well, most errors are fine. On the other hand, low-level
// class loading errors likely indicate a bug in instrumentation,
// which is often tested with this test.
while (e.getCause() != null) {
Assert.assertFalse(String.valueOf(e.getCause()), e.getCause() instanceof LinkageError);
e = e.getCause();
}
}

// the VM is not exiting, so stop tracing explicitly
Expand Down
11 changes: 2 additions & 9 deletions com.ibm.wala.core/src/com/ibm/wala/cfg/ShrikeCFG.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,10 @@ private void makeBasicBlocks() {
Assertions.UNREACHABLE();
handlers = null;
}
boolean[] r = new boolean[getInstructions().length];
boolean[] catchers = new boolean[getInstructions().length];
// we initially start with both the entry and exit block.
int blockCount = 2;

// Compute r so r[i] == true iff instruction i begins a basic block.
// While doing so count the number of blocks.
boolean[] r = new boolean[getInstructions().length];
boolean[] catchers = new boolean[getInstructions().length];
r[0] = true;
IInstruction[] instructions = getInstructions();
for (int i = 0; i < instructions.length; i++) {
Expand All @@ -163,22 +160,19 @@ private void makeBasicBlocks() {
if (targets.length > 0 || !instructions[i].isFallThrough()) {
if (i + 1 < instructions.length && !r[i + 1]) {
r[i + 1] = true;
blockCount++;
}
}

for (int j = 0; j < targets.length; j++) {
if (!r[targets[j]]) {
r[targets[j]] = true;
blockCount++;
}
}
if (instructions[i].isPEI()) {
ExceptionHandler[] hs = handlers[i];
// break the basic block here.
if (i + 1 < instructions.length && !r[i + 1]) {
r[i + 1] = true;
blockCount++;
}
if (hs != null && hs.length > 0) {
for (int j = 0; j < hs.length; j++) {
Expand All @@ -187,7 +181,6 @@ private void makeBasicBlocks() {
// we have not discovered the catch block yet.
// form a new basic block
r[hs[j].getHandler()] = true;
blockCount++;
}
catchers[hs[j].getHandler()] = true;
}
Expand Down
15 changes: 15 additions & 0 deletions com.ibm.wala.core/src/com/ibm/wala/classLoader/JavaLanguage.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.ibm.wala.shrikeBT.IInstruction;
import com.ibm.wala.shrikeBT.IUnaryOpInstruction;
import com.ibm.wala.shrikeBT.Instruction;
import com.ibm.wala.shrikeCT.BootstrapMethodsReader.BootstrapMethod;
import com.ibm.wala.shrikeCT.ConstantPoolParser.ReferenceToken;
import com.ibm.wala.shrikeCT.InvalidClassFileException;
import com.ibm.wala.ssa.SSAAddressOfInstruction;
Expand All @@ -47,6 +48,7 @@
import com.ibm.wala.ssa.SSAInstanceofInstruction;
import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.ssa.SSAInstructionFactory;
import com.ibm.wala.ssa.SSAInvokeDynamicInstruction;
import com.ibm.wala.ssa.SSAInvokeInstruction;
import com.ibm.wala.ssa.SSALoadIndirectInstruction;
import com.ibm.wala.ssa.SSALoadMetadataInstruction;
Expand Down Expand Up @@ -238,6 +240,19 @@ public Collection<TypeReference> getExceptionTypes() {
};
}

public SSAInvokeDynamicInstruction InvokeInstruction(int result, int[] params, int exception, CallSiteReference site, BootstrapMethod bootstrap) {
return new SSAInvokeDynamicInstruction(result, params, exception, site, bootstrap) {
@Override
public Collection<TypeReference> getExceptionTypes() {
if (!isStatic()) {
return getNullPointerException();
} else {
return Collections.emptySet();
}
}
};
}

@Override
public SSAInvokeInstruction InvokeInstruction(int[] params, int exception, CallSiteReference site) {
return new SSAInvokeInstruction(params, exception, site) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.ibm.wala.shrikeBT.IComparisonInstruction;
import com.ibm.wala.shrikeBT.IConditionalBranchInstruction;
import com.ibm.wala.shrikeBT.IUnaryOpInstruction;
import com.ibm.wala.shrikeCT.BootstrapMethodsReader.BootstrapMethod;
import com.ibm.wala.types.FieldReference;
import com.ibm.wala.types.TypeReference;

Expand Down Expand Up @@ -99,4 +100,6 @@ SSAConditionalBranchInstruction ConditionalBranchInstruction(IConditionalBranchI

SSAUnaryOpInstruction UnaryOpInstruction(IUnaryOpInstruction.IOperator operator, int result, int val);

SSAInstruction InvokeInstruction(int i, int[] js, int j, CallSiteReference site, BootstrapMethod bootstrap);

}

0 comments on commit 36709b9

Please sign in to comment.