From 5f7c86eebb44d823e3583a49c3fbcd6c3dc29ede Mon Sep 17 00:00:00 2001 From: sjfink Date: Tue, 19 Jul 2011 21:14:29 +0000 Subject: [PATCH 01/12] attempt to fix build breakage on Linux git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4219 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../ibm/wala/fixedpoint/impl/DefaultFixedPointSystem.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/com.ibm.wala.util/src/com/ibm/wala/fixedpoint/impl/DefaultFixedPointSystem.java b/com.ibm.wala.util/src/com/ibm/wala/fixedpoint/impl/DefaultFixedPointSystem.java index ebb9ccce0..9926ea0a2 100644 --- a/com.ibm.wala.util/src/com/ibm/wala/fixedpoint/impl/DefaultFixedPointSystem.java +++ b/com.ibm.wala.util/src/com/ibm/wala/fixedpoint/impl/DefaultFixedPointSystem.java @@ -33,8 +33,7 @@ import com.ibm.wala.util.graph.traverse.Topological; /** * Default implementation of a dataflow graph */ -@SuppressWarnings("rawtypes") -public class DefaultFixedPointSystem implements IFixedPointSystem { +public class DefaultFixedPointSystem> implements IFixedPointSystem { static final boolean DEBUG = false; /** @@ -47,14 +46,14 @@ public class DefaultFixedPointSystem implements IFixedPoint * equals() ... the NumberedGraph does not support this. TODO: use a custom * NumberedNodeManager to save space */ - final private Set equations = HashSetFactory.make(); + final private Set> equations = HashSetFactory.make(); /** * We maintain a hash set of variables in order to check for equality with * equals() ... the NumberedGraph does not support this. TODO: use a custom * NumberedNodeManager to save space */ - final private Set variables = HashSetFactory.make(); + final private Set> variables = HashSetFactory.make(); /** * @param expectedOut number of expected out edges in the "usual" case From c5a5507103889b33a014b54b6818e5c0810b8396 Mon Sep 17 00:00:00 2001 From: sjfink Date: Tue, 19 Jul 2011 21:27:43 +0000 Subject: [PATCH 02/12] attempt to fix build breakage on Linux git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4220 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../com/ibm/wala/fixedpoint/impl/DefaultFixedPointSolver.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/com.ibm.wala.util/src/com/ibm/wala/fixedpoint/impl/DefaultFixedPointSolver.java b/com.ibm.wala.util/src/com/ibm/wala/fixedpoint/impl/DefaultFixedPointSolver.java index 95e1eef24..9507ea446 100644 --- a/com.ibm.wala.util/src/com/ibm/wala/fixedpoint/impl/DefaultFixedPointSolver.java +++ b/com.ibm.wala.util/src/com/ibm/wala/fixedpoint/impl/DefaultFixedPointSolver.java @@ -17,8 +17,7 @@ import com.ibm.wala.fixpoint.IVariable; /** * Default implementation of a fixed point solver. */ -@SuppressWarnings("rawtypes") -public abstract class DefaultFixedPointSolver extends AbstractFixedPointSolver { +public abstract class DefaultFixedPointSolver> extends AbstractFixedPointSolver { private final DefaultFixedPointSystem graph; From af16c5d55169c02ddc8734938ce9fc89856c8404 Mon Sep 17 00:00:00 2001 From: sjfink Date: Tue, 19 Jul 2011 21:32:50 +0000 Subject: [PATCH 03/12] attempt to fix build breakage on Linux git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4221 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../src/com/ibm/wala/dataflow/graph/DataflowSolver.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/com.ibm.wala.util/src/com/ibm/wala/dataflow/graph/DataflowSolver.java b/com.ibm.wala.util/src/com/ibm/wala/dataflow/graph/DataflowSolver.java index ed043db97..58d71caf1 100644 --- a/com.ibm.wala.util/src/com/ibm/wala/dataflow/graph/DataflowSolver.java +++ b/com.ibm.wala.util/src/com/ibm/wala/dataflow/graph/DataflowSolver.java @@ -25,8 +25,7 @@ import com.ibm.wala.util.intset.IntegerUnionFind; /** * Iterative solver for a Killdall dataflow framework */ -@SuppressWarnings("rawtypes") -public abstract class DataflowSolver extends DefaultFixedPointSolver { +public abstract class DataflowSolver> extends DefaultFixedPointSolver { /** * the dataflow problem to solve From a6a818824489ae5dba703ac358a9b99dbe5f64de Mon Sep 17 00:00:00 2001 From: msridhar1 Date: Fri, 22 Jul 2011 15:53:33 +0000 Subject: [PATCH 04/12] change getPointerKeys() to return an Iterable, so we're not forced to construct a Collection (can cause a space blowup for a very large points-to relation) git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4224 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../ibm/wala/ipa/callgraph/propagation/PointerAnalysis.java | 3 ++- .../wala/ipa/callgraph/propagation/PointerAnalysisImpl.java | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PointerAnalysis.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PointerAnalysis.java index 1902734d2..870fb471b 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PointerAnalysis.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PointerAnalysis.java @@ -48,7 +48,8 @@ public interface PointerAnalysis { /** * @return all pointer keys known */ - Collection getPointerKeys(); + Iterable getPointerKeys(); + /** * @return all instance keys known diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PointerAnalysisImpl.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PointerAnalysisImpl.java index fcf9e1945..667a6b98b 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PointerAnalysisImpl.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PointerAnalysisImpl.java @@ -38,7 +38,7 @@ import com.ibm.wala.ssa.SSAThrowInstruction; import com.ibm.wala.types.FieldReference; import com.ibm.wala.types.TypeReference; import com.ibm.wala.util.collections.HashSetFactory; -import com.ibm.wala.util.collections.Iterator2Collection; +import com.ibm.wala.util.collections.Iterator2Iterable; import com.ibm.wala.util.debug.Assertions; import com.ibm.wala.util.intset.IntSet; import com.ibm.wala.util.intset.MutableMapping; @@ -538,8 +538,8 @@ public class PointerAnalysisImpl extends AbstractPointerAnalysis { /* * @see com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis#iteratePointerKeys() */ - public Collection getPointerKeys() { - return Iterator2Collection.toSet(pointsToMap.iterateKeys()); + public Iterable getPointerKeys() { + return Iterator2Iterable.make(pointsToMap.iterateKeys()); } public IClassHierarchy getClassHierarchy() { From 3e4e4836e2f87d2533a528b11fba587fc98971e1 Mon Sep 17 00:00:00 2001 From: msridhar1 Date: Fri, 22 Jul 2011 15:58:41 +0000 Subject: [PATCH 05/12] allow for clearing error messages to free memory git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4225 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../harness-src/com/ibm/wala/cast/test/Util.java | 3 +++ .../java/com/ibm/wala/cast/loader/CAstAbstractLoader.java | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/com.ibm.wala.cast.test/harness-src/com/ibm/wala/cast/test/Util.java b/com.ibm.wala.cast.test/harness-src/com/ibm/wala/cast/test/Util.java index 7b3647e85..c8128749b 100644 --- a/com.ibm.wala.cast.test/harness-src/com/ibm/wala/cast/test/Util.java +++ b/com.ibm.wala.cast.test/harness-src/com/ibm/wala/cast/test/Util.java @@ -29,6 +29,8 @@ public class Util { } } } + // clear out the errors to free some memory + ((CAstAbstractLoader)loader).clearMessages(); } } if (message != null) { @@ -36,5 +38,6 @@ public class Util { } Assert.assertTrue(String.valueOf(message), message == null); } + } diff --git a/com.ibm.wala.cast/source/java/com/ibm/wala/cast/loader/CAstAbstractLoader.java b/com.ibm.wala.cast/source/java/com/ibm/wala/cast/loader/CAstAbstractLoader.java index a4acf4cd0..a684b2018 100644 --- a/com.ibm.wala.cast/source/java/com/ibm/wala/cast/loader/CAstAbstractLoader.java +++ b/com.ibm.wala.cast/source/java/com/ibm/wala/cast/loader/CAstAbstractLoader.java @@ -92,6 +92,11 @@ public abstract class CAstAbstractLoader implements IClassLoader { return errors.get(m); } + + public void clearMessages() { + errors.clear(); + } + public IClass lookupClass(String className, IClassHierarchy cha) { assert this.cha == cha; return (IClass) types.get(TypeName.string2TypeName(className)); From 82d751a814672caade5d236e84d3e5b5db25af26 Mon Sep 17 00:00:00 2001 From: msridhar1 Date: Fri, 22 Jul 2011 17:06:09 +0000 Subject: [PATCH 06/12] try to fix javac compile errors git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4226 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../stackMachine/AbstractIntStackMachine.java | 11 +++++------ .../src/com/ibm/wala/dataflow/ssa/SSAInference.java | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/com.ibm.wala.core/src/com/ibm/wala/analysis/stackMachine/AbstractIntStackMachine.java b/com.ibm.wala.core/src/com/ibm/wala/analysis/stackMachine/AbstractIntStackMachine.java index 0f655e381..74b8d47bb 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/analysis/stackMachine/AbstractIntStackMachine.java +++ b/com.ibm.wala.core/src/com/ibm/wala/analysis/stackMachine/AbstractIntStackMachine.java @@ -78,7 +78,7 @@ public abstract class AbstractIntStackMachine implements FixedPointConstants { /** * The solver */ - private DataflowSolver solver; + private DataflowSolver solver; /** * The control flow graph to analyze @@ -257,14 +257,14 @@ public abstract class AbstractIntStackMachine implements FixedPointConstants { } public MachineState getEntryState() { - return (MachineState) solver.getIn(cfg.entry()); + return solver.getIn(cfg.entry()); } /** * @return the state at the entry to a given block */ public MachineState getIn(ShrikeCFG.BasicBlock bb) { - return (MachineState) solver.getIn(bb); + return solver.getIn(bb); } private class MeetOperator extends AbstractMeetOperator { @@ -547,7 +547,7 @@ public abstract class AbstractIntStackMachine implements FixedPointConstants { /** * Representation of the state of the JVM stack machine at some program point. */ - public class MachineState extends AbstractVariable { + public class MachineState extends AbstractVariable { private int[] stack; private int[] locals; @@ -711,8 +711,7 @@ public abstract class AbstractIntStackMachine implements FixedPointConstants { return result; } - public void copyState(IVariable v) { - MachineState other = (MachineState) v; + public void copyState(MachineState other) { if (other.stack == null) { stack = null; } else { diff --git a/com.ibm.wala.core/src/com/ibm/wala/dataflow/ssa/SSAInference.java b/com.ibm.wala.core/src/com/ibm/wala/dataflow/ssa/SSAInference.java index cff41b1b8..0d111c6ac 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/dataflow/ssa/SSAInference.java +++ b/com.ibm.wala.core/src/com/ibm/wala/dataflow/ssa/SSAInference.java @@ -31,7 +31,7 @@ import com.ibm.wala.ssa.SymbolTable; * * @see TypeInference for the canonical client of this machinery. */ -public abstract class SSAInference extends DefaultFixedPointSolver { +public abstract class SSAInference> extends DefaultFixedPointSolver { static final boolean DEBUG = false; /** From 214e541ed049c63a7acff85f0b487d08e63985c5 Mon Sep 17 00:00:00 2001 From: msridhar1 Date: Fri, 22 Jul 2011 19:45:41 +0000 Subject: [PATCH 07/12] added more exclusions to get tests to run in a reasonable amount of time git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4227 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- com.ibm.wala.core.tests/dat/Java60RegressionExclusions.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/com.ibm.wala.core.tests/dat/Java60RegressionExclusions.txt b/com.ibm.wala.core.tests/dat/Java60RegressionExclusions.txt index 454830adf..a621d345d 100644 --- a/com.ibm.wala.core.tests/dat/Java60RegressionExclusions.txt +++ b/com.ibm.wala.core.tests/dat/Java60RegressionExclusions.txt @@ -6,3 +6,6 @@ com\/sun\/.* sun\/.* org\/netbeans\/.* org\/openide\/.* +com\/ibm\/crypto\/.* +com\/ibm\/security\/.* +org\/apache\/xerces\/.* From 25b0e330155caee2ae5d0fce760380e841f0921d Mon Sep 17 00:00:00 2001 From: msridhar1 Date: Fri, 22 Jul 2011 20:24:35 +0000 Subject: [PATCH 08/12] fix test to be less dependent on library code git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4228 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../analysis/dataflow/DataflowTest.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/com.ibm.wala.core.tests/src/com/ibm/wala/examples/analysis/dataflow/DataflowTest.java b/com.ibm.wala.core.tests/src/com/ibm/wala/examples/analysis/dataflow/DataflowTest.java index 6732a4c2c..1aafca3bd 100644 --- a/com.ibm.wala.core.tests/src/com/ibm/wala/examples/analysis/dataflow/DataflowTest.java +++ b/com.ibm.wala.core.tests/src/com/ibm/wala/examples/analysis/dataflow/DataflowTest.java @@ -10,6 +10,9 @@ *******************************************************************************/ package com.ibm.wala.examples.analysis.dataflow; +import java.util.ArrayList; +import java.util.List; + import junit.framework.Assert; import org.junit.AfterClass; @@ -140,11 +143,16 @@ public class DataflowTest extends WalaTestCase { if (delegate.getNumber() == 4) { IntSet solution = solver.getOut(bb).getValue(); IntIterator intIterator = solution.intIterator(); + List> applicationDefs = new ArrayList>(); while (intIterator.hasNext()) { int next = intIterator.next(); - System.out.println(reachingDefs.getNodeAndInstrForNumber(next)); + final Pair def = reachingDefs.getNodeAndInstrForNumber(next); + if (def.fst.getMethod().getDeclaringClass().getClassLoader().getReference().equals(ClassLoaderReference.Application)) { + System.out.println(def); + applicationDefs.add(def); + } } - Assert.assertEquals(4, solution.size()); + Assert.assertEquals(2, applicationDefs.size()); } } } @@ -168,11 +176,16 @@ public class DataflowTest extends WalaTestCase { if (delegate.getNumber() == 4) { IntSet solution = result.getResult(bb); IntIterator intIterator = solution.intIterator(); + List> applicationDefs = new ArrayList>(); while (intIterator.hasNext()) { int next = intIterator.next(); - System.out.println(reachingDefs.getDomain().getMappedObject(next)); + final Pair def = reachingDefs.getDomain().getMappedObject(next); + if (def.fst.getMethod().getDeclaringClass().getClassLoader().getReference().equals(ClassLoaderReference.Application)) { + System.out.println(def); + applicationDefs.add(def); + } } - Assert.assertEquals(3, solution.size()); + Assert.assertEquals(1, applicationDefs.size()); } } } From 981e04f243961f27712a98cda5e408718ee2a12f Mon Sep 17 00:00:00 2001 From: msridhar1 Date: Fri, 22 Jul 2011 20:26:04 +0000 Subject: [PATCH 09/12] update to work on Windows git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4229 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../src/com/ibm/wala/util/io/FileProviderTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/com.ibm.wala.core.tests/src/com/ibm/wala/util/io/FileProviderTest.java b/com.ibm.wala.core.tests/src/com/ibm/wala/util/io/FileProviderTest.java index f0fe43bf5..6fda01327 100644 --- a/com.ibm.wala.core.tests/src/com/ibm/wala/util/io/FileProviderTest.java +++ b/com.ibm.wala.core.tests/src/com/ibm/wala/util/io/FileProviderTest.java @@ -7,6 +7,8 @@ import java.net.URL; import org.junit.Test; +import com.ibm.wala.util.PlatformUtil; + public class FileProviderTest { @Test @@ -25,7 +27,7 @@ public class FileProviderTest { public void testURLWithInvalidURIChars() throws MalformedURLException { // setup: URL url = new URL("file:///[Eclipse]/File.jar"); - String expected = "/[Eclipse]/File.jar"; + String expected = PlatformUtil.onWindows() ? "/C:/[Eclipse]/File.jar" : "/[Eclipse]/File.jar"; // exercise: String actual = FileProvider.filePathFromURL(url); // verify: From deddf6ecbe8d0fe93cedd4e75b48b4a71bb113ca Mon Sep 17 00:00:00 2001 From: msridhar1 Date: Fri, 22 Jul 2011 21:29:57 +0000 Subject: [PATCH 10/12] make the condition checked by a couple of tests more specific, to avoid issues with different Java library versions git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4230 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../core/tests/callGraph/ReflectionTest.java | 214 +++++++++++------- 1 file changed, 130 insertions(+), 84 deletions(-) diff --git a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/callGraph/ReflectionTest.java b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/callGraph/ReflectionTest.java index f34453ba9..545f41189 100644 --- a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/callGraph/ReflectionTest.java +++ b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/callGraph/ReflectionTest.java @@ -30,6 +30,7 @@ import com.ibm.wala.ipa.callgraph.CGNode; import com.ibm.wala.ipa.callgraph.CallGraph; import com.ibm.wala.ipa.callgraph.Context; import com.ibm.wala.ipa.callgraph.Entrypoint; +import com.ibm.wala.ipa.callgraph.impl.Everywhere; import com.ibm.wala.ipa.callgraph.propagation.ConstantKey; import com.ibm.wala.ipa.callgraph.propagation.ReceiverInstanceContext; import com.ibm.wala.ipa.cha.ClassHierarchy; @@ -55,33 +56,35 @@ public class ReflectionTest extends WalaTestCase { } private static AnalysisScope cachedScope; - + private static AnalysisScope findOrCreateAnalysisScope() throws IOException { if (cachedScope == null) { cachedScope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA, "Java60RegressionExclusions.txt"); } return cachedScope; } - + private static IClassHierarchy cachedCHA; - + private static IClassHierarchy findOrCreateCHA(AnalysisScope scope) throws ClassHierarchyException { if (cachedCHA == null) { cachedCHA = ClassHierarchy.make(scope); } return cachedCHA; } - + @AfterClass public static void afterClass() { cachedCHA = null; cachedScope = null; } - + /** - * test that when analyzing Reflect1.main(), there is no warning about "Integer". + * test that when analyzing Reflect1.main(), there is no warning about + * "Integer". */ - @Test public void testReflect1() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect1() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -102,10 +105,12 @@ public class ReflectionTest extends WalaTestCase { } /** - * Test that when analyzing reflect2, the call graph includes a node for java.lang.Integer.. This should be - * forced by the call for Class.forName("java.lang.Integer"). + * Test that when analyzing reflect2, the call graph includes a node for + * java.lang.Integer.. This should be forced by the call for + * Class.forName("java.lang.Integer"). */ - @Test public void testReflect2() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect2() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -120,9 +125,11 @@ public class ReflectionTest extends WalaTestCase { } /** - * Check that when analyzing Reflect3, the successors of newInstance do not include reflection/Reflect3$Hash + * Check that when analyzing Reflect3, the successors of newInstance do not + * include reflection/Reflect3$Hash */ - @Test public void testReflect3() throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException { + @Test + public void testReflect3() throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -150,9 +157,11 @@ public class ReflectionTest extends WalaTestCase { } /** - * Check that when analyzing Reflect4, successors of newInstance() do not include FilePermission ctor. + * Check that when analyzing Reflect4, successors of newInstance() do not + * include FilePermission ctor. */ - @Test public void testReflect4() throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException { + @Test + public void testReflect4() throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -178,9 +187,11 @@ public class ReflectionTest extends WalaTestCase { } /** - * Check that when analyzing Reflect5, successors of newInstance do not include a Reflect5$A ctor + * Check that when analyzing Reflect5, successors of newInstance do not + * include a Reflect5$A ctor */ - @Test public void testReflect5() throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException { + @Test + public void testReflect5() throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -206,9 +217,11 @@ public class ReflectionTest extends WalaTestCase { } /** - * Check that when analyzing Reflect6, successors of newInstance do not include a Reflect6$A ctor + * Check that when analyzing Reflect6, successors of newInstance do not + * include a Reflect6$A ctor */ - @Test public void testReflect6() throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException { + @Test + public void testReflect6() throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -234,7 +247,8 @@ public class ReflectionTest extends WalaTestCase { } @SuppressWarnings("unchecked") - @Test public void testReflect7() throws Exception { + @Test + public void testReflect7() throws Exception { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -258,7 +272,8 @@ public class ReflectionTest extends WalaTestCase { // Get all the children of the main node(s) Collection mainChildren = getSuccNodes(cg, mainNodes); - // Verify that one of those children is Constructor.newInstance, where Constructor is a FilePermission constructor + // Verify that one of those children is Constructor.newInstance, where + // Constructor is a FilePermission constructor CGNode filePermConstrNewInstanceNode = null; for (CGNode node : mainChildren) { @@ -310,11 +325,13 @@ public class ReflectionTest extends WalaTestCase { } return succNodes; } - + /** - * Test that when analyzing reflect8, the call graph includes a node for java.lang.Integer.toString() + * Test that when analyzing reflect8, the call graph includes a node for + * java.lang.Integer.toString() */ - @Test public void testReflect8() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect8() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -326,11 +343,13 @@ public class ReflectionTest extends WalaTestCase { Set nodes = cg.getNodes(mr); Assert.assertFalse(nodes.isEmpty()); } - + /** - * Test that when analyzing reflect9, the call graph includes a node for java.lang.Integer.toString() + * Test that when analyzing reflect9, the call graph includes a node for + * java.lang.Integer.toString() */ - @Test public void testReflect9() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect9() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -342,11 +361,13 @@ public class ReflectionTest extends WalaTestCase { Set nodes = cg.getNodes(mr); Assert.assertFalse(nodes.isEmpty()); } - + /** - * Test that when analyzing Reflect10, the call graph includes a node for java.lang.Integer.toString() + * Test that when analyzing Reflect10, the call graph includes a node for + * java.lang.Integer.toString() */ - @Test public void testReflect10() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect10() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -358,11 +379,13 @@ public class ReflectionTest extends WalaTestCase { Set nodes = cg.getNodes(mr); Assert.assertFalse(nodes.isEmpty()); } - + /** - * Test that when analyzing Reflect11, the call graph includes a node for java.lang.Object.wait() + * Test that when analyzing Reflect11, the call graph includes a node for + * java.lang.Object.wait() */ - @Test public void testReflect11() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect11() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -374,12 +397,13 @@ public class ReflectionTest extends WalaTestCase { Set nodes = cg.getNodes(mr); Assert.assertFalse(nodes.isEmpty()); } - + /** - * Test that when analyzing Reflect12, the call graph does not include a node for reflection.Helper.n - * but does include a node for reflection.Helper.m + * Test that when analyzing Reflect12, the call graph does not include a node + * for reflection.Helper.n but does include a node for reflection.Helper.m */ - @Test public void testReflect12() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect12() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -394,12 +418,13 @@ public class ReflectionTest extends WalaTestCase { nodes = cg.getNodes(mr); Assert.assertTrue(nodes.isEmpty()); } - + /** - * Test that when analyzing Reflect13, the call graph includes both a node for reflection.Helper.n - * and a node for reflection.Helper.m + * Test that when analyzing Reflect13, the call graph includes both a node for + * reflection.Helper.n and a node for reflection.Helper.m */ - @Test public void testReflect13() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect13() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -414,12 +439,13 @@ public class ReflectionTest extends WalaTestCase { nodes = cg.getNodes(mr); Assert.assertFalse(nodes.isEmpty()); } - + /** - * Test that when analyzing Reflect14, the call graph does not include a node for reflection.Helper.n - * but does include a node for reflection.Helper.s + * Test that when analyzing Reflect14, the call graph does not include a node + * for reflection.Helper.n but does include a node for reflection.Helper.s */ - @Test public void testReflect14() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect14() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -434,13 +460,14 @@ public class ReflectionTest extends WalaTestCase { nodes = cg.getNodes(mr); Assert.assertTrue(nodes.isEmpty()); } - + /** - * Test that when analyzing Reflect15, the call graph includes a node for the constructor - * of Helper that takes 2 parameters and for Helper.n, but no node for the constructors of - * Helper that takes 0 or 1 parameters. + * Test that when analyzing Reflect15, the call graph includes a node for the + * constructor of Helper that takes 2 parameters and for Helper.n, but no node + * for the constructors of Helper that takes 0 or 1 parameters. */ - @Test public void testReflect15() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect15() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -461,11 +488,13 @@ public class ReflectionTest extends WalaTestCase { nodes = cg.getNodes(mr); Assert.assertFalse(nodes.isEmpty()); } - + /** - * Test that when analyzing Reflect16, the call graph includes a node for java.lang.Integer.toString() + * Test that when analyzing Reflect16, the call graph includes a node for + * java.lang.Integer.toString() */ - @Test public void testReflect16() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect16() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -477,43 +506,52 @@ public class ReflectionTest extends WalaTestCase { Set nodes = cg.getNodes(mr); Assert.assertFalse(nodes.isEmpty()); } - + /** - * Test that when analyzing Reflect17, the call graph does not include a node for java.lang.Integer.toString() + * Test that when analyzing Reflect17, the call graph does not include any + * edges from reflection.Helper.t() */ - @Test public void testReflect17() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect17() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, TestConstants.REFLECT17_MAIN); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); CallGraph cg = CallGraphTestUtil.buildZeroOneCFA(options, new AnalysisCache(), cha, scope, false); - TypeReference tr = TypeReference.findOrCreate(ClassLoaderReference.Primordial, "Ljava/lang/Integer"); - MethodReference mr = MethodReference.findOrCreate(tr, "toString", "()Ljava/lang/String;"); - Set nodes = cg.getNodes(mr); - Assert.assertTrue(nodes.isEmpty()); + TypeReference tr = TypeReference.findOrCreate(ClassLoaderReference.Application, "Lreflection/Helper"); + MethodReference mr = MethodReference.findOrCreate(tr, "t", "(Ljava/lang/Integer;)V"); + CGNode node = cg.getNode(cg.getClassHierarchy().resolveMethod(mr), Everywhere.EVERYWHERE); + Assert.assertEquals(0, cg.getSuccNodeCount(node)); } - + /** - * Test that when analyzing Reflect18, the call graph includes a node for java.lang.Integer.toString() + * Test that when analyzing Reflect18, the call graph includes a node for + * java.lang.Integer.toString() */ - @Test public void testReflect18() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect18() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, TestConstants.REFLECT18_MAIN); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); CallGraph cg = CallGraphTestUtil.buildZeroOneCFA(options, new AnalysisCache(), cha, scope, false); - TypeReference tr = TypeReference.findOrCreate(ClassLoaderReference.Primordial, "Ljava/lang/Integer"); - MethodReference mr = MethodReference.findOrCreate(tr, "toString", "()Ljava/lang/String;"); - Set nodes = cg.getNodes(mr); - Assert.assertFalse(nodes.isEmpty()); + TypeReference tr = TypeReference.findOrCreate(ClassLoaderReference.Application, "Lreflection/Helper"); + MethodReference mr = MethodReference.findOrCreate(tr, "t", "(Ljava/lang/Integer;)V"); + CGNode node = cg.getNode(cg.getClassHierarchy().resolveMethod(mr), Everywhere.EVERYWHERE); + Assert.assertEquals(1, cg.getSuccNodeCount(node)); + CGNode succ = cg.getSuccNodes(node).next(); + Assert.assertEquals("Node: < Primordial, Ljava/lang/Integer, toString()Ljava/lang/String; > Context: Everywhere", + succ.toString()); } - + /** - * Test that when analyzing Reflect19, the call graph includes a node for java.lang.Integer.toString() + * Test that when analyzing Reflect19, the call graph includes a node for + * java.lang.Integer.toString() */ - @Test public void testReflect19() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect19() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -525,11 +563,13 @@ public class ReflectionTest extends WalaTestCase { Set nodes = cg.getNodes(mr); Assert.assertFalse(nodes.isEmpty()); } - + /** - * Test that when analyzing Reflect20, the call graph includes a node for Helper.o. + * Test that when analyzing Reflect20, the call graph includes a node for + * Helper.o. */ - @Test public void testReflect20() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect20() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -541,12 +581,14 @@ public class ReflectionTest extends WalaTestCase { Set nodes = cg.getNodes(mr); Assert.assertFalse(nodes.isEmpty()); } - + /** - * Test that when analyzing Reflect21, the call graph includes a node for the constructor of {@link Helper} that takes - * two {@link Object} parameters. This is to test the support for Class.getDeclaredConstructor. + * Test that when analyzing Reflect21, the call graph includes a node for the + * constructor of {@link Helper} that takes two {@link Object} parameters. + * This is to test the support for Class.getDeclaredConstructor. */ - @Test public void testReflect21() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect21() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -558,12 +600,14 @@ public class ReflectionTest extends WalaTestCase { Set nodes = cg.getNodes(mr); Assert.assertFalse(nodes.isEmpty()); } - + /** - * Test that when analyzing Reflect22, the call graph includes a node for the constructor of {@link Helper} that takes - * one {@link Integer} parameters. This is to test the support for Class.getDeclaredConstructors. + * Test that when analyzing Reflect22, the call graph includes a node for the + * constructor of {@link Helper} that takes one {@link Integer} parameters. + * This is to test the support for Class.getDeclaredConstructors. */ - @Test public void testReflect22() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect22() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, @@ -575,12 +619,14 @@ public class ReflectionTest extends WalaTestCase { Set nodes = cg.getNodes(mr); Assert.assertFalse(nodes.isEmpty()); } - + /** - * Test that when analyzing Reflect22, the call graph includes a node for the constructor of {@link Helper} that takes - * one {@link Integer} parameters. This is to test the support for Class.getDeclaredConstructors. + * Test that when analyzing Reflect22, the call graph includes a node for the + * constructor of {@link Helper} that takes one {@link Integer} parameters. + * This is to test the support for Class.getDeclaredConstructors. */ - @Test public void testReflect23() throws WalaException, IllegalArgumentException, CancelException, IOException { + @Test + public void testReflect23() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, From e9199401c98532a747a1b476ace4651a6ffde12a Mon Sep 17 00:00:00 2001 From: msridhar1 Date: Fri, 22 Jul 2011 21:48:15 +0000 Subject: [PATCH 11/12] change to remove time blowup in test on recent Java versions git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4231 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../src/com/ibm/wala/core/tests/slicer/SlicerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/slicer/SlicerTest.java b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/slicer/SlicerTest.java index 9fff2452b..e8804377e 100644 --- a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/slicer/SlicerTest.java +++ b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/slicer/SlicerTest.java @@ -229,7 +229,7 @@ public class SlicerTest { TestConstants.SLICE7_MAIN); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); - CallGraphBuilder builder = Util.makeVanillaZeroOneContainerCFABuilder(options, new AnalysisCache(), cha, scope); + CallGraphBuilder builder = Util.makeZeroOneContainerCFABuilder(options, new AnalysisCache(), cha, scope); CallGraph cg = builder.makeCallGraph(options, null); CGNode main = findMainMethod(cg); From 253444a6ad57c2309d6489f1dd76b64932c35565 Mon Sep 17 00:00:00 2001 From: msridhar1 Date: Mon, 25 Jul 2011 18:10:31 +0000 Subject: [PATCH 12/12] make demand pointer analysis tests less dependent on standard library implementation git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4234 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../src/demandpa/DummyHashMap.java | 57 +++++++++++++++ .../src/demandpa/DummyHashSet.java | 25 +++++++ .../src/demandpa/DummyLinkedList.java | 58 +++++++++++++++ .../src/demandpa/FlowsToTestHashSet.java | 6 +- .../src/demandpa/TestHashMapGet.java | 6 +- .../src/demandpa/TestHashSet.java | 6 +- .../src/demandpa/TestHashtableEnum.java | 10 +-- .../src/demandpa/TestHashtableGet.java | 61 ---------------- .../src/demandpa/TestLinkedList.java | 6 +- .../src/demandpa/TestLinkedListIter.java | 6 +- .../core/tests/demandpa/AbstractPtrTest.java | 73 ++++--------------- .../tests/demandpa/ContextSensitiveTest.java | 8 +- .../core/tests/demandpa/NoRefinePtrTest.java | 2 +- .../wala/core/tests/demandpa/TestInfo.java | 2 - .../tests/demandpa/TunedRefinementTest.java | 8 +- 15 files changed, 179 insertions(+), 155 deletions(-) create mode 100644 com.ibm.wala.core.testdata/src/demandpa/DummyHashMap.java create mode 100644 com.ibm.wala.core.testdata/src/demandpa/DummyHashSet.java create mode 100644 com.ibm.wala.core.testdata/src/demandpa/DummyLinkedList.java delete mode 100644 com.ibm.wala.core.testdata/src/demandpa/TestHashtableGet.java diff --git a/com.ibm.wala.core.testdata/src/demandpa/DummyHashMap.java b/com.ibm.wala.core.testdata/src/demandpa/DummyHashMap.java new file mode 100644 index 000000000..8420393e6 --- /dev/null +++ b/com.ibm.wala.core.testdata/src/demandpa/DummyHashMap.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package demandpa; + +/** + * doesn't actually work; just for testing pointer analysis + */ +public class DummyHashMap { + + Object[] keys = new Object[10]; + + Object[] values = new Object[10]; + + public void put(Object object, Object object2) { + int ind = object.hashCode() % keys.length; + keys[ind] = object; + values[ind] = object2; + } + + public Iter keyIter() { + return new Iter() { + + public Object next() { + return keys[0]; + } + }; + } + + public Iter valuesIter() { + return new Iter() { + + public Object next() { + return values[0]; + } + }; + } + + public Object get(Object key1) { + return values[0]; + } + + private Iter keyOrValueIter(int type) { + return type == 0 ? keyIter() : valuesIter(); + } + + public Iter elements() { + return keyOrValueIter(-1); + } +} diff --git a/com.ibm.wala.core.testdata/src/demandpa/DummyHashSet.java b/com.ibm.wala.core.testdata/src/demandpa/DummyHashSet.java new file mode 100644 index 000000000..f3189c035 --- /dev/null +++ b/com.ibm.wala.core.testdata/src/demandpa/DummyHashSet.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package demandpa; + +public class DummyHashSet { + + private final DummyHashMap hashMap = new DummyHashMap(); + + public void add(Object object) { + hashMap.put(object, object); + } + + public Iter iterator() { + return hashMap.keyIter(); + } + +} diff --git a/com.ibm.wala.core.testdata/src/demandpa/DummyLinkedList.java b/com.ibm.wala.core.testdata/src/demandpa/DummyLinkedList.java new file mode 100644 index 000000000..bf1e6ad66 --- /dev/null +++ b/com.ibm.wala.core.testdata/src/demandpa/DummyLinkedList.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package demandpa; + +public class DummyLinkedList { + + static class Element { + Element next; + Object data; + } + + Element head = null; + + public void add(Object o) { + if (head == null) { + head = new Element(); + head.data = o; + } else { + Element tmp = head; + while (tmp.next != null) { + tmp = tmp.next; + } + Element newElement = new Element(); + newElement.data = o; + tmp.next = newElement; + } + } + + public Object get(int ind) { + Element tmp = head; + for (int i = 0; i < ind; i++) { + tmp = tmp.next; + } + return tmp.data; + } + + public Iter iterator() { + return new Iter() { + + public Object next() { + // just return some arbitrary element, from the point of view of flow-insensitive points-to analysis + Element tmp = head; + while (tmp.data == tmp.next) { // shouldn't be able to interpret this condition + tmp = tmp.next; + } + return tmp.data; + } + }; + } +} diff --git a/com.ibm.wala.core.testdata/src/demandpa/FlowsToTestHashSet.java b/com.ibm.wala.core.testdata/src/demandpa/FlowsToTestHashSet.java index e73a1265f..76049fd8e 100644 --- a/com.ibm.wala.core.testdata/src/demandpa/FlowsToTestHashSet.java +++ b/com.ibm.wala.core.testdata/src/demandpa/FlowsToTestHashSet.java @@ -10,7 +10,6 @@ *******************************************************************************/ package demandpa; -import java.util.HashSet; /** * @author manu @@ -18,10 +17,9 @@ import java.util.HashSet; */ public class FlowsToTestHashSet { - @SuppressWarnings("unchecked") public static void main(String[] args) { - HashSet s1 = new HashSet(); - HashSet s2 = new HashSet(); + DummyHashSet s1 = new DummyHashSet(); + DummyHashSet s2 = new DummyHashSet(); s1.add(new FlowsToType()); s2.add(new Object()); Object o1 = s1.iterator().next(); diff --git a/com.ibm.wala.core.testdata/src/demandpa/TestHashMapGet.java b/com.ibm.wala.core.testdata/src/demandpa/TestHashMapGet.java index 78dd294ac..04f09d254 100644 --- a/com.ibm.wala.core.testdata/src/demandpa/TestHashMapGet.java +++ b/com.ibm.wala.core.testdata/src/demandpa/TestHashMapGet.java @@ -37,14 +37,12 @@ */ package demandpa; -import java.util.HashMap; public class TestHashMapGet { - @SuppressWarnings("unchecked") public static void main(String[] args) { - HashMap s1 = new HashMap(); - HashMap s2 = new HashMap(); + DummyHashMap s1 = new DummyHashMap(); + DummyHashMap s2 = new DummyHashMap(); Object key1 = new Object(); Object key2 = new Object(); s1.put(key1, new Object()); diff --git a/com.ibm.wala.core.testdata/src/demandpa/TestHashSet.java b/com.ibm.wala.core.testdata/src/demandpa/TestHashSet.java index 546a05299..c8eab2bbf 100644 --- a/com.ibm.wala.core.testdata/src/demandpa/TestHashSet.java +++ b/com.ibm.wala.core.testdata/src/demandpa/TestHashSet.java @@ -37,14 +37,12 @@ */ package demandpa; -import java.util.HashSet; public class TestHashSet { - @SuppressWarnings("unchecked") public static void main(String[] args) { - HashSet s1 = new HashSet(); - HashSet s2 = new HashSet(); + DummyHashSet s1 = new DummyHashSet(); + DummyHashSet s2 = new DummyHashSet(); s1.add(new Object()); s2.add(new Object()); Object o1 = s1.iterator().next(); diff --git a/com.ibm.wala.core.testdata/src/demandpa/TestHashtableEnum.java b/com.ibm.wala.core.testdata/src/demandpa/TestHashtableEnum.java index 3d5e3e823..205d4cfee 100644 --- a/com.ibm.wala.core.testdata/src/demandpa/TestHashtableEnum.java +++ b/com.ibm.wala.core.testdata/src/demandpa/TestHashtableEnum.java @@ -37,23 +37,21 @@ */ package demandpa; -import java.util.Hashtable; public class TestHashtableEnum { /** * @param args */ - @SuppressWarnings("unchecked") public static void main(String[] args) { - Hashtable h1 = new Hashtable(); - Hashtable h2 = new Hashtable(); + DummyHashMap h1 = new DummyHashMap(); + DummyHashMap h2 = new DummyHashMap(); Object key1 = new Object(); Object key2 = new Object(); h1.put(key1, new Object()); h2.put(key2, new Object()); - Object o1 = h1.elements().nextElement(); - Object o2 = h2.elements().nextElement(); + Object o1 = h1.elements().next(); + Object o2 = h2.elements().next(); TestUtil.makeVarUsed(o1); TestUtil.testThisVar(o2); diff --git a/com.ibm.wala.core.testdata/src/demandpa/TestHashtableGet.java b/com.ibm.wala.core.testdata/src/demandpa/TestHashtableGet.java deleted file mode 100644 index d18560aec..000000000 --- a/com.ibm.wala.core.testdata/src/demandpa/TestHashtableGet.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * This file is a derivative of code released by the University of - * California under the terms listed below. - * - * Refinement Analysis Tools is Copyright (c) 2007 The Regents of the - * University of California (Regents). Provided that this notice and - * the following two paragraphs are included in any distribution of - * Refinement Analysis Tools or its derivative work, Regents agrees - * not to assert any of Regents' copyright rights in Refinement - * Analysis Tools against recipient for recipient's reproduction, - * preparation of derivative works, public display, public - * performance, distribution or sublicensing of Refinement Analysis - * Tools and derivative works, in source code and object code form. - * This agreement not to assert does not confer, by implication, - * estoppel, or otherwise any license or rights in any intellectual - * property of Regents, including, but not limited to, any patents - * of Regents or Regents' employees. - * - * IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, - * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, - * INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE - * AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY - * WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING - * DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS - * IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, - * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - */ -package demandpa; - -import java.util.Hashtable; - -public class TestHashtableGet { - - /** - * @param args - */ - @SuppressWarnings("unchecked") - public static void main(String[] args) { - Hashtable h1 = new Hashtable(); - Hashtable h2 = new Hashtable(); - Object key1 = new Object(); - Object key2 = new Object(); - h1.put(key1, new Object()); - h2.put(key2, new Object()); - Object o1 = h1.get(key1); - Object o2 = h2.get(key2); - TestUtil.makeVarUsed(o1); - TestUtil.testThisVar(o2); - } - -} diff --git a/com.ibm.wala.core.testdata/src/demandpa/TestLinkedList.java b/com.ibm.wala.core.testdata/src/demandpa/TestLinkedList.java index 1185b77f3..a8a861120 100644 --- a/com.ibm.wala.core.testdata/src/demandpa/TestLinkedList.java +++ b/com.ibm.wala.core.testdata/src/demandpa/TestLinkedList.java @@ -37,17 +37,15 @@ */ package demandpa; -import java.util.LinkedList; public class TestLinkedList { /** * @param args */ - @SuppressWarnings("unchecked") public static void main(String[] args) { - LinkedList l1 = new LinkedList(); - LinkedList l2 = new LinkedList(); + DummyLinkedList l1 = new DummyLinkedList(); + DummyLinkedList l2 = new DummyLinkedList(); l1.add(new Object()); l2.add(new Object()); Object o1 = l1.get(0); diff --git a/com.ibm.wala.core.testdata/src/demandpa/TestLinkedListIter.java b/com.ibm.wala.core.testdata/src/demandpa/TestLinkedListIter.java index 1a3807e6e..724fbed58 100644 --- a/com.ibm.wala.core.testdata/src/demandpa/TestLinkedListIter.java +++ b/com.ibm.wala.core.testdata/src/demandpa/TestLinkedListIter.java @@ -37,17 +37,15 @@ */ package demandpa; -import java.util.LinkedList; public class TestLinkedListIter { /** * @param args */ - @SuppressWarnings("unchecked") public static void main(String[] args) { - LinkedList l1 = new LinkedList(); - LinkedList l2 = new LinkedList(); + DummyLinkedList l1 = new DummyLinkedList(); + DummyLinkedList l2 = new DummyLinkedList(); l1.add(new Object()); l2.add(new Object()); Object o1 = l1.iterator().next(); diff --git a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/AbstractPtrTest.java b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/AbstractPtrTest.java index 96e284970..d0c90f8d7 100644 --- a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/AbstractPtrTest.java +++ b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/AbstractPtrTest.java @@ -90,11 +90,6 @@ public abstract class AbstractPtrTest { */ protected final String scopeFile; - /** - * analysis scope from latest test - */ - private AnalysisScope scope = null; - protected AbstractPtrTest(String scopeFile) { this.scopeFile = scopeFile; } @@ -162,64 +157,22 @@ public abstract class AbstractPtrTest { return null; } - /** - * Test if the computed size of some points-to test matches what is expected. - * - * @param mainClass the main class of the test; we choose a variable from its main() method that is passed to the method - * TestUtil.testThisVar() - * @param expected14Size expected p2set size when using 1.4 libraries - * @param expected15Size expected p2set size when using 1.4 libraries - * @param expected16Size expected p2set size when using 1.4 libraries - * @throws ClassHierarchyException - * @throws IllegalArgumentException - * @throws CancelException - * @throws IOException - */ - protected void doPointsToSizeTest(String mainClass, int expected14Size, int expected15Size, int expected16Size) - throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { - assert scope == null; - Collection pointsTo = getPointsToSetToTest(mainClass); - if (debug) { - System.err.println("points-to for " + mainClass + ": " + pointsTo); - } - assert scope != null; - try { - if (scope.isJava16Libraries()) { - Assert.assertEquals(expected16Size, pointsTo.size()); - } else if (scope.isJava15Libraries()) { - Assert.assertEquals(expected15Size, pointsTo.size()); - } else if (scope.isJava14Libraries()) { - Assert.assertEquals(expected14Size, pointsTo.size()); - } else { - Assertions.UNREACHABLE("unexpected library version"); - } - } finally { - // don't hold on to a scope pointer - scope = null; - } - } protected void doFlowsToSizeTest(String mainClass, int size) throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { - assert scope == null; Collection flowsTo = getFlowsToSetToTest(mainClass); if (debug) { System.err.println("flows-to for " + mainClass + ": " + flowsTo); } - assert scope != null; - try { - Assert.assertEquals(size, flowsTo.size()); - } finally { - // don't hold on to a scope pointer - scope = null; - } + Assert.assertEquals(size, flowsTo.size()); } private Collection getFlowsToSetToTest(String mainClass) throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { final DemandRefinementPointsTo dmp = makeDemandPointerAnalysis(mainClass); - // find the single allocation site of FlowsToType, make an InstanceKey, and query it + // find the single allocation site of FlowsToType, make an InstanceKey, and + // query it CGNode mainMethod = AbstractPtrTest.findMainMethod(dmp.getBaseCallGraph()); InstanceKey keyToQuery = getFlowsToInstanceKey(mainMethod, dmp.getHeapModel()); Collection flowsTo = dmp.getFlowsTo(keyToQuery).snd; @@ -227,12 +180,13 @@ public abstract class AbstractPtrTest { } /** - * returns the instance key corresponding to the single allocation site of type FlowsToType + * returns the instance key corresponding to the single allocation site of + * type FlowsToType */ private InstanceKey getFlowsToInstanceKey(CGNode mainMethod, HeapModel heapModel) { // TODO Auto-generated method stub - TypeReference flowsToTypeRef = TypeReference.findOrCreate(ClassLoaderReference.Application, StringStuff - .deployment2CanonicalTypeString("demandpa.FlowsToType")); + TypeReference flowsToTypeRef = TypeReference.findOrCreate(ClassLoaderReference.Application, + StringStuff.deployment2CanonicalTypeString("demandpa.FlowsToType")); final IR mainIR = mainMethod.getIR(); if (debug) { System.err.println(mainIR); @@ -248,7 +202,11 @@ public abstract class AbstractPtrTest { protected void doPointsToSizeTest(String mainClass, int expectedSize) throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { - doPointsToSizeTest(mainClass, expectedSize, expectedSize, expectedSize); + Collection pointsTo = getPointsToSetToTest(mainClass); + if (debug) { + System.err.println("points-to for " + mainClass + ": " + pointsTo); + } + Assert.assertEquals(expectedSize, pointsTo.size()); } private Collection getPointsToSetToTest(String mainClass) throws ClassHierarchyException, IllegalArgumentException, @@ -265,7 +223,6 @@ public abstract class AbstractPtrTest { protected DemandRefinementPointsTo makeDemandPointerAnalysis(String mainClass) throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); - this.scope = scope; // build a type hierarchy IClassHierarchy cha = findOrCreateCHA(scope); @@ -279,10 +236,12 @@ public abstract class AbstractPtrTest { final CallGraph cg = cgBuilder.makeCallGraph(options, null); // System.err.println(cg.toString()); - // MemoryAccessMap mam = new SimpleMemoryAccessMap(cg, cgBuilder.getPointerAnalysis().getHeapModel(), false); + // MemoryAccessMap mam = new SimpleMemoryAccessMap(cg, + // cgBuilder.getPointerAnalysis().getHeapModel(), false); MemoryAccessMap mam = new PABasedMemoryAccessMap(cg, cgBuilder.getPointerAnalysis()); SSAPropagationCallGraphBuilder builder = Util.makeVanillaZeroOneCFABuilder(options, analysisCache, cha, scope); - DemandRefinementPointsTo fullDemandPointsTo = DemandRefinementPointsTo.makeWithDefaultFlowGraph(cg, builder, mam, cha, options, getStateMachineFactory()); + DemandRefinementPointsTo fullDemandPointsTo = DemandRefinementPointsTo.makeWithDefaultFlowGraph(cg, builder, mam, cha, options, + getStateMachineFactory()); return fullDemandPointsTo; } diff --git a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/ContextSensitiveTest.java b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/ContextSensitiveTest.java index 8622fecc3..a2c60ddaf 100644 --- a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/ContextSensitiveTest.java +++ b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/ContextSensitiveTest.java @@ -86,8 +86,8 @@ public class ContextSensitiveTest extends AbstractPtrTest { @Test public void testHashtableEnum() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { // 3 because - // can't tell between key, value, and entry enumerators in Hashtable - doPointsToSizeTest(TestInfo.TEST_HASHTABLE_ENUM, 3); + // can't tell between key and value enumerators in Hashtable + doPointsToSizeTest(TestInfo.TEST_HASHTABLE_ENUM, 2); } @Ignore("support for this combination of context sensitivity and on-the-fly call graph refinement is not yet implemented") @@ -135,12 +135,12 @@ public class ContextSensitiveTest extends AbstractPtrTest { @Test public void testHashSet() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { - doPointsToSizeTest(TestInfo.TEST_HASH_SET, 2, 2, 1); + doPointsToSizeTest(TestInfo.TEST_HASH_SET, 1); } @Test public void testHashMapGet() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { - doPointsToSizeTest(TestInfo.TEST_HASHMAP_GET, 2, 1, 1); + doPointsToSizeTest(TestInfo.TEST_HASHMAP_GET, 1); } @Test diff --git a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/NoRefinePtrTest.java b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/NoRefinePtrTest.java index f8171cda2..a542069b6 100644 --- a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/NoRefinePtrTest.java +++ b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/NoRefinePtrTest.java @@ -67,7 +67,7 @@ public class NoRefinePtrTest extends AbstractPtrTest { @Test public void testHashSet() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { - doPointsToSizeTest(TestInfo.TEST_HASH_SET, 3, 3, 2); + doPointsToSizeTest(TestInfo.TEST_HASH_SET, 2); } @Test diff --git a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/TestInfo.java b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/TestInfo.java index d7c8649fa..69efdce35 100644 --- a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/TestInfo.java +++ b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/TestInfo.java @@ -85,8 +85,6 @@ public class TestInfo { public static final String TEST_ARRAY_LIST = "Ldemandpa/TestArrayList"; - public static final String TEST_HASHTABLE_GET = "Ldemandpa/TestHashtableGet"; - public static final String TEST_HASHTABLE_ENUM = "Ldemandpa/TestHashtableEnum"; public static final String TEST_NASTY_PTRS = "Ldemandpa/TestNastyPtrs"; diff --git a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/TunedRefinementTest.java b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/TunedRefinementTest.java index 3ce78bd23..a67a32a7b 100644 --- a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/TunedRefinementTest.java +++ b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/TunedRefinementTest.java @@ -55,8 +55,8 @@ public class TunedRefinementTest extends AbstractPtrTest { @Test public void testHashtableEnum() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { // 3 because - // can't tell between key, value, and entry enumerators in Hashtable - doPointsToSizeTest(TestInfo.TEST_HASHTABLE_ENUM, 3); + // can't tell between key and value enumerators in Hashtable + doPointsToSizeTest(TestInfo.TEST_HASHTABLE_ENUM, 2); } // we know this one fails... @@ -107,12 +107,12 @@ public class TunedRefinementTest extends AbstractPtrTest { @Test public void testHashSet() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { - doPointsToSizeTest(TestInfo.TEST_HASH_SET, 2, 2, 1); + doPointsToSizeTest(TestInfo.TEST_HASH_SET, 1); } @Test public void testHashMapGet() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { - doPointsToSizeTest(TestInfo.TEST_HASHMAP_GET, 2, 1, 1); + doPointsToSizeTest(TestInfo.TEST_HASHMAP_GET, 1); } @Test