Temporary commit; things are broken, but I need to switch back to master for a bit.

This commit is contained in:
Max Schaefer 2013-06-06 14:30:52 +08:00
parent 68db1cc279
commit 0c67118fe2
10 changed files with 95 additions and 37 deletions

View File

@ -75,12 +75,10 @@ public class HTMLCGBuilder {
* the HTML page to analyse, can either be a path to a local file or a URL * the HTML page to analyse, can either be a path to a local file or a URL
* @param timeout * @param timeout
* analysis timeout in seconds, -1 means no timeout * analysis timeout in seconds, -1 means no timeout
* @param automated_extraction
* whether to automatically extract correlated pairs
* @throws IOException * @throws IOException
* @throws ClassHierarchyException * @throws ClassHierarchyException
*/ */
public static CGBuilderResult buildHTMLCG(String src, int timeout, boolean automated_extraction, CGBuilderType builderType) public static CGBuilderResult buildHTMLCG(String src, int timeout, CGBuilderType builderType)
throws ClassHierarchyException, IOException { throws ClassHierarchyException, IOException {
CGBuilderResult res = new CGBuilderResult(); CGBuilderResult res = new CGBuilderResult();
URL url = null; URL url = null;
@ -90,13 +88,9 @@ public class HTMLCGBuilder {
Assert.fail("Could not find page to analyse: " + src); Assert.fail("Could not find page to analyse: " + src);
} }
com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil.setTranslatorFactory(new CAstRhinoTranslatorFactory()); com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil.setTranslatorFactory(new CAstRhinoTranslatorFactory());
if(automated_extraction)
com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil.setPreprocessor(new CorrelatedPairExtractorFactory(new CAstRhinoTranslatorFactory(), url));
JSCFABuilder builder = null; JSCFABuilder builder = null;
try { try {
builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url, builderType); builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url, builderType);
builder.setContextSelector(new PropertyNameContextSelector(builder.getAnalysisCache(), 2, builder.getContextSelector()));
builder.setContextSelector(new PropertyNameContextSelector(builder.getAnalysisCache(), 3, builder.getContextSelector()));
// TODO we need to find a better way to do this ContextSelector delegation; // TODO we need to find a better way to do this ContextSelector delegation;
// the code below belongs somewhere else!!! // the code below belongs somewhere else!!!
// the bound of 4 is what is needed to pass our current framework tests // the bound of 4 is what is needed to pass our current framework tests
@ -191,7 +185,7 @@ public class HTMLCGBuilder {
JavaScriptFunctionDotCallTargetSelector.WARN_ABOUT_IMPRECISE_CALLGRAPH = false; JavaScriptFunctionDotCallTargetSelector.WARN_ABOUT_IMPRECISE_CALLGRAPH = false;
// build call graph // build call graph
CGBuilderResult res = buildHTMLCG(src, timeout, true, AstTranslator.NEW_LEXICAL ? CGBuilderType.ONE_CFA_PRECISE_LEXICAL : CGBuilderType.ZERO_ONE_CFA); CGBuilderResult res = buildHTMLCG(src, timeout, AstTranslator.NEW_LEXICAL ? CGBuilderType.ONE_CFA_PRECISE_LEXICAL : CGBuilderType.ZERO_ONE_CFA);
if(res.construction_time == -1) if(res.construction_time == -1)
System.out.println("TIMED OUT"); System.out.println("TIMED OUT");

View File

@ -16,6 +16,7 @@ import static com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil.setTranslatorFa
import static com.ibm.wala.cast.js.test.JSCallGraphBuilderUtil.makeScriptScope; import static com.ibm.wala.cast.js.test.JSCallGraphBuilderUtil.makeScriptScope;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.util.Map; import java.util.Map;
import junit.framework.Assert; import junit.framework.Assert;
@ -160,8 +161,9 @@ public class TestRhinoSourceMap {
sources.put(assertion[0], assertion[1]); sources.put(assertion[0], assertion[1]);
} }
JavaScriptLoaderFactory loaders = makeLoaders(); URL script = TestRhinoSourceMap.class.getClassLoader().getResource(fileName);
AnalysisScope scope = makeScriptScope("tests", fileName, loaders); JavaScriptLoaderFactory loaders = makeLoaders(null);
AnalysisScope scope = makeScriptScope(script, "tests", fileName, loaders);
IClassHierarchy cha = makeHierarchy(scope, loaders); IClassHierarchy cha = makeHierarchy(scope, loaders);
for(IClass cls : cha) { for(IClass cls : cha) {
if (cls.getName().toString().contains(fileName)) { if (cls.getName().toString().contains(fileName)) {

View File

@ -27,9 +27,12 @@ import com.ibm.wala.cast.js.ipa.callgraph.JSAnalysisOptions;
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder; import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil; import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
import com.ibm.wala.cast.js.ipa.callgraph.JSZeroOrOneXCFABuilder; import com.ibm.wala.cast.js.ipa.callgraph.JSZeroOrOneXCFABuilder;
import com.ibm.wala.cast.js.ipa.callgraph.PropertyNameContextSelector;
import com.ibm.wala.cast.js.ipa.callgraph.correlations.extraction.CorrelatedPairExtractorFactory;
import com.ibm.wala.cast.js.loader.JavaScriptLoader; import com.ibm.wala.cast.js.loader.JavaScriptLoader;
import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory; import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory;
import com.ibm.wala.cast.loader.CAstAbstractLoader; import com.ibm.wala.cast.loader.CAstAbstractLoader;
import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory;
import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.SourceFileModule; import com.ibm.wala.classLoader.SourceFileModule;
import com.ibm.wala.classLoader.SourceModule; import com.ibm.wala.classLoader.SourceModule;
@ -52,19 +55,25 @@ import com.ibm.wala.util.WalaException;
public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil { public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil {
public static enum CGBuilderType { public static enum CGBuilderType {
ZERO_ONE_CFA(false, false, true), ZERO_ONE_CFA_NO_CALL_APPLY(false, false, false), ZERO_ONE_CFA_PRECISE_LEXICAL(false, true, ZERO_ONE_CFA(false, false, true, true),
true), ONE_CFA(true, false, true), ONE_CFA_PRECISE_LEXICAL(true, true, true); ZERO_ONE_CFA_NO_CALL_APPLY(false, false, false, true),
ZERO_ONE_CFA_PRECISE_LEXICAL(false, true, true, true),
ONE_CFA(true, false, true, true),
ONE_CFA_PRECISE_LEXICAL(true, true, true, true);
private final boolean useOneCFA; private final boolean useOneCFA;
private final boolean usePreciseLexical; private final boolean usePreciseLexical;
private final boolean handleCallApply; private final boolean handleCallApply;
private final boolean extractCorrelatedPairs;
private CGBuilderType(boolean useOneCFA, boolean usePreciseLexical, boolean handleCallApply) { private CGBuilderType(boolean useOneCFA, boolean usePreciseLexical, boolean handleCallApply, boolean extractCorrelatedPairs) {
this.useOneCFA = useOneCFA; this.useOneCFA = useOneCFA;
this.usePreciseLexical = usePreciseLexical; this.usePreciseLexical = usePreciseLexical;
this.handleCallApply = handleCallApply; this.handleCallApply = handleCallApply;
this.extractCorrelatedPairs = extractCorrelatedPairs;
} }
public boolean useOneCFA() { public boolean useOneCFA() {
@ -74,26 +83,40 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
public boolean usePreciseLexical() { public boolean usePreciseLexical() {
return usePreciseLexical; return usePreciseLexical;
} }
public boolean handleCallApply() { public boolean handleCallApply() {
return handleCallApply; return handleCallApply;
} }
public boolean extractCorrelatedPairs() {
return extractCorrelatedPairs;
}
} }
public static JSCFABuilder makeScriptCGBuilder(String dir, String name, CGBuilderType builderType) throws IOException, WalaException { public static JSCFABuilder makeScriptCGBuilder(String dir, String name, CGBuilderType builderType) throws IOException, WalaException {
JavaScriptLoaderFactory loaders = JSCallGraphUtil.makeLoaders(); URL script = getURLforFile(dir, name);
CAstRewriterFactory preprocessor = builderType.extractCorrelatedPairs ? new CorrelatedPairExtractorFactory(translatorFactory, script) : null;
JavaScriptLoaderFactory loaders = JSCallGraphUtil.makeLoaders(preprocessor);
AnalysisScope scope = makeScriptScope(dir, name, loaders); AnalysisScope scope = makeScriptScope(script, dir, name, loaders);
return makeCG(loaders, scope, builderType, AstIRFactory.makeDefaultFactory()); return makeCG(loaders, scope, builderType, AstIRFactory.makeDefaultFactory());
} }
static AnalysisScope makeScriptScope(String dir, String name, JavaScriptLoaderFactory loaders) throws IOException { private static URL getURLforFile(String dir, String name) {
URL script = JSCallGraphBuilderUtil.class.getClassLoader().getResource(dir + File.separator + name); URL script = JSCallGraphBuilderUtil.class.getClassLoader().getResource(dir + File.separator + name);
if (script == null) { if (script == null) {
script = JSCallGraphBuilderUtil.class.getClassLoader().getResource(dir + "/" + name); script = JSCallGraphBuilderUtil.class.getClassLoader().getResource(dir + "/" + name);
} }
assert script != null : "cannot find " + dir + " and " + name; assert script != null : "cannot find " + dir + " and " + name;
return script;
}
static AnalysisScope makeScriptScope(String dir, String name, JavaScriptLoaderFactory loaders) throws IOException {
return makeScriptScope(getURLforFile(dir, name), dir, name, loaders);
}
static AnalysisScope makeScriptScope(URL script, String dir, String name, JavaScriptLoaderFactory loaders) throws IOException {
AnalysisScope scope; AnalysisScope scope;
if (script.openConnection() instanceof JarURLConnection) { if (script.openConnection() instanceof JarURLConnection) {
scope = makeScope(new URL[] { script }, loaders, JavaScriptLoader.JS); scope = makeScope(new URL[] { script }, loaders, JavaScriptLoader.JS);
@ -122,7 +145,8 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
public static CallGraph makeScriptCG(SourceModule[] scripts, CGBuilderType builderType, IRFactory<IMethod> irFactory) throws IOException, IllegalArgumentException, public static CallGraph makeScriptCG(SourceModule[] scripts, CGBuilderType builderType, IRFactory<IMethod> irFactory) throws IOException, IllegalArgumentException,
CancelException, WalaException { CancelException, WalaException {
PropagationCallGraphBuilder b = makeCGBuilder(makeLoaders(), scripts, builderType, irFactory); CAstRewriterFactory preprocessor = builderType.extractCorrelatedPairs ? new CorrelatedPairExtractorFactory(translatorFactory, scripts) : null;
PropagationCallGraphBuilder b = makeCGBuilder(makeLoaders(preprocessor), scripts, builderType, irFactory);
CallGraph CG = b.makeCallGraph(b.getOptions()); CallGraph CG = b.makeCallGraph(b.getOptions());
// dumpCG(b.getPointerAnalysis(), CG); // dumpCG(b.getPointerAnalysis(), CG);
return CG; return CG;
@ -136,6 +160,7 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
JavaScriptLoader.addBootstrapFile(WebUtil.preamble); JavaScriptLoader.addBootstrapFile(WebUtil.preamble);
SourceModule[] scripts; SourceModule[] scripts;
IRFactory<IMethod> irFactory = AstIRFactory.makeDefaultFactory(); IRFactory<IMethod> irFactory = AstIRFactory.makeDefaultFactory();
CAstRewriterFactory preprocessor = builderType.extractCorrelatedPairs ? new CorrelatedPairExtractorFactory(translatorFactory, url) : null;
JavaScriptLoaderFactory loaders = new WebPageLoaderFactory(translatorFactory, preprocessor); JavaScriptLoaderFactory loaders = new WebPageLoaderFactory(translatorFactory, preprocessor);
try { try {
Set<MappedSourceModule> script = WebUtil.extractScriptFromHTML(url).fst; Set<MappedSourceModule> script = WebUtil.extractScriptFromHTML(url).fst;
@ -146,6 +171,8 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
((CAstAbstractLoader)loaders.getTheLoader()).addMessage(dummy, e.warning); ((CAstAbstractLoader)loaders.getTheLoader()).addMessage(dummy, e.warning);
} }
JSCFABuilder builder = makeCGBuilder(loaders, scripts, builderType, irFactory); JSCFABuilder builder = makeCGBuilder(loaders, scripts, builderType, irFactory);
if(builderType.extractCorrelatedPairs)
builder.setContextSelector(new PropertyNameContextSelector(builder.getAnalysisCache(), 2, builder.getContextSelector()));
builder.setBaseURL(url); builder.setBaseURL(url);
return builder; return builder;
} }
@ -180,6 +207,8 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
AnalysisCache cache = makeCache(irFactory); AnalysisCache cache = makeCache(irFactory);
JSCFABuilder builder = new JSZeroOrOneXCFABuilder(cha, options, cache, null, null, ZeroXInstanceKeys.ALLOCATIONS, JSCFABuilder builder = new JSZeroOrOneXCFABuilder(cha, options, cache, null, null, ZeroXInstanceKeys.ALLOCATIONS,
builderType.useOneCFA()); builderType.useOneCFA());
if(builderType.extractCorrelatedPairs())
builder.setContextSelector(new PropertyNameContextSelector(builder.getAnalysisCache(), 2, builder.getContextSelector()));
return builder; return builder;
} catch (ClassHierarchyException e) { } catch (ClassHierarchyException e) {

View File

@ -41,7 +41,7 @@ public abstract class TestArgumentSensitivity extends TestJSCallGraphShape {
new Object[] { "tests/args.js/a", new String[] { "tests/args.js/y", "tests/args.js/z", "!tests/args.js/wrong" } } }; new Object[] { "tests/args.js/a", new String[] { "tests/args.js/y", "tests/args.js/z", "!tests/args.js/wrong" } } };
@Test public void testArgs() throws IOException, IllegalArgumentException, CancelException, ClassHierarchyException, WalaException { @Test public void testArgs() throws IOException, IllegalArgumentException, CancelException, ClassHierarchyException, WalaException {
JavaScriptLoaderFactory loaders = JSCallGraphBuilderUtil.makeLoaders(); JavaScriptLoaderFactory loaders = JSCallGraphBuilderUtil.makeLoaders(null);
AnalysisScope scope = JSCallGraphBuilderUtil.makeScriptScope("tests", "args.js", loaders); AnalysisScope scope = JSCallGraphBuilderUtil.makeScriptScope("tests", "args.js", loaders);
IClassHierarchy cha = JSCallGraphBuilderUtil.makeHierarchy(scope, loaders); IClassHierarchy cha = JSCallGraphBuilderUtil.makeHierarchy(scope, loaders);

View File

@ -652,6 +652,18 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
//JSCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); //JSCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForDeadCode); verifyGraphAssertions(CG, assertionsForDeadCode);
} }
private static final Object[][] assertionsForExtend = new Object[][] {
new Object[] { ROOT, new String[] { "tests/extend.js" } },
new Object[] { "tests/extend.js", new String[] { "suffix:foo", "!suffix:bar" } }
};
@Test
public void testExtend() throws IOException, WalaException, IllegalArgumentException, CancelException {
JSCFABuilder builder = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "extend.js");
CallGraph cg = builder.makeCallGraph(builder.getOptions());
verifyGraphAssertions(cg, assertionsForExtend);
}
@Test @Test
public void testDeadCatch() throws IllegalArgumentException, IOException, CancelException, WalaException { public void testDeadCatch() throws IllegalArgumentException, IOException, CancelException, WalaException {

View File

@ -63,11 +63,6 @@ public class JSCallGraphUtil extends com.ibm.wala.cast.ipa.callgraph.CAstCallGra
*/ */
public static JavaScriptTranslatorFactory translatorFactory; public static JavaScriptTranslatorFactory translatorFactory;
/**
* preprocessor to run generated CAst trees through, null if none
*/
public static CAstRewriterFactory preprocessor;
/** /**
* Set up the translator factory. This method should be called before invoking * Set up the translator factory. This method should be called before invoking
* {@link #makeLoaders()}. * {@link #makeLoaders()}.
@ -80,10 +75,6 @@ public class JSCallGraphUtil extends com.ibm.wala.cast.ipa.callgraph.CAstCallGra
return translatorFactory; return translatorFactory;
} }
public static void setPreprocessor(CAstRewriterFactory preprocessor) {
JSCallGraphUtil.preprocessor = preprocessor;
}
public static JSAnalysisOptions makeOptions(AnalysisScope scope, IClassHierarchy cha, Iterable<Entrypoint> roots) { public static JSAnalysisOptions makeOptions(AnalysisScope scope, IClassHierarchy cha, Iterable<Entrypoint> roots) {
final JSAnalysisOptions options = new JSAnalysisOptions(scope, /* final JSAnalysisOptions options = new JSAnalysisOptions(scope, /*
* AstIRFactory. * AstIRFactory.
@ -101,7 +92,11 @@ public class JSCallGraphUtil extends com.ibm.wala.cast.ipa.callgraph.CAstCallGra
return options; return options;
} }
public static JavaScriptLoaderFactory makeLoaders() { /**
* @param preprocessor CAst rewriter to use for preprocessing JavaScript source files; may be null
* @return
*/
public static JavaScriptLoaderFactory makeLoaders(CAstRewriterFactory preprocessor) {
if (translatorFactory == null) { if (translatorFactory == null) {
throw new IllegalStateException("com.ibm.wala.cast.js.ipa.callgraph.Util.setTranslatorFactory() must be invoked before makeLoaders()"); throw new IllegalStateException("com.ibm.wala.cast.js.ipa.callgraph.Util.setTranslatorFactory() must be invoked before makeLoaders()");
} }

View File

@ -14,6 +14,7 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import com.ibm.wala.cast.ir.ssa.AbstractReflectiveGet; import com.ibm.wala.cast.ir.ssa.AbstractReflectiveGet;
import com.ibm.wala.cast.ir.ssa.AstIRFactory;
import com.ibm.wala.cast.ir.ssa.AstIsDefinedInstruction; import com.ibm.wala.cast.ir.ssa.AstIsDefinedInstruction;
import com.ibm.wala.cast.js.ipa.callgraph.correlations.CorrelationFinder; import com.ibm.wala.cast.js.ipa.callgraph.correlations.CorrelationFinder;
import com.ibm.wala.cast.js.ipa.callgraph.correlations.extraction.ClosureExtractor; import com.ibm.wala.cast.js.ipa.callgraph.correlations.extraction.ClosureExtractor;
@ -27,14 +28,17 @@ import com.ibm.wala.ipa.callgraph.Context;
import com.ibm.wala.ipa.callgraph.ContextItem; import com.ibm.wala.ipa.callgraph.ContextItem;
import com.ibm.wala.ipa.callgraph.ContextKey; import com.ibm.wala.ipa.callgraph.ContextKey;
import com.ibm.wala.ipa.callgraph.ContextSelector; import com.ibm.wala.ipa.callgraph.ContextSelector;
import com.ibm.wala.ipa.callgraph.impl.Everywhere;
import com.ibm.wala.ipa.callgraph.propagation.ConcreteTypeKey; import com.ibm.wala.ipa.callgraph.propagation.ConcreteTypeKey;
import com.ibm.wala.ipa.callgraph.propagation.FilteredPointerKey.SingleInstanceFilter; import com.ibm.wala.ipa.callgraph.propagation.FilteredPointerKey.SingleInstanceFilter;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey; import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ssa.DefUse; import com.ibm.wala.ssa.DefUse;
import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.ReflectiveMemberAccess; import com.ibm.wala.ssa.ReflectiveMemberAccess;
import com.ibm.wala.ssa.SSAAbstractInvokeInstruction; import com.ibm.wala.ssa.SSAAbstractInvokeInstruction;
import com.ibm.wala.ssa.SSAGetInstruction; import com.ibm.wala.ssa.SSAGetInstruction;
import com.ibm.wala.ssa.SSAInstruction; import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.ssa.SSAOptions;
import com.ibm.wala.types.MethodReference; import com.ibm.wala.types.MethodReference;
import com.ibm.wala.util.collections.HashMapFactory; import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.collections.Iterator2Iterable; import com.ibm.wala.util.collections.Iterator2Iterable;

View File

@ -16,6 +16,7 @@ import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
@ -78,7 +79,6 @@ public class CorrelationFinder {
private final JavaScriptTranslatorFactory translatorFactory; private final JavaScriptTranslatorFactory translatorFactory;
@SuppressWarnings("unused")
public static CorrelationSummary findCorrelatedAccesses(IMethod method, IR ir) { public static CorrelationSummary findCorrelatedAccesses(IMethod method, IR ir) {
AstMethod astMethod = (AstMethod)method; AstMethod astMethod = (AstMethod)method;
DefUse du = new DefUse(ir); DefUse du = new DefUse(ir);
@ -229,7 +229,10 @@ public class CorrelationFinder {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private void printCorrelatedAccesses(URL url) throws IOException, ClassHierarchyException { private void printCorrelatedAccesses(URL url) throws IOException, ClassHierarchyException {
Map<IMethod, CorrelationSummary> summaries = findCorrelatedAccesses(url); printCorrelatedAccesses(findCorrelatedAccesses(url));
}
private void printCorrelatedAccesses(Map<IMethod, CorrelationSummary> summaries) {
List<Pair<Position, String>> correlations = new ArrayList<Pair<Position,String>>(); List<Pair<Position, String>> correlations = new ArrayList<Pair<Position,String>>();
for(CorrelationSummary summary : summaries.values()) for(CorrelationSummary summary : summaries.values())
correlations.addAll(summary.pp()); correlations.addAll(summary.pp());
@ -247,21 +250,25 @@ public class CorrelationFinder {
public Map<IMethod, CorrelationSummary> findCorrelatedAccesses(URL url) throws IOException, ClassHierarchyException { public Map<IMethod, CorrelationSummary> findCorrelatedAccesses(URL url) throws IOException, ClassHierarchyException {
JavaScriptLoader.addBootstrapFile(WebUtil.preamble); JavaScriptLoader.addBootstrapFile(WebUtil.preamble);
Set<? extends SourceModule> script = null; Set<? extends SourceModule> scripts = null;
try { try {
script = WebUtil.extractScriptFromHTML(url).fst; scripts = WebUtil.extractScriptFromHTML(url).fst;
} catch (Error e) { } catch (Error e) {
assert false : e.warning; assert false : e.warning;
} }
Map<IMethod, CorrelationSummary> summaries = findCorrelatedAccesses(script); Map<IMethod, CorrelationSummary> summaries = findCorrelatedAccesses(scripts);
return summaries; return summaries;
} }
public Map<IMethod, CorrelationSummary> findCorrelatedAccesses(Set<? extends SourceModule> script) throws IOException, public Map<IMethod, CorrelationSummary> findCorrelatedAccesses(Collection<? extends SourceModule> scripts) throws IOException,
ClassHierarchyException {
return findCorrelatedAccesses(scripts.toArray(new SourceModule[scripts.size()]));
}
public Map<IMethod, CorrelationSummary> findCorrelatedAccesses(SourceModule[] scripts_array) throws IOException,
ClassHierarchyException { ClassHierarchyException {
SourceModule[] scripts = script.toArray(new SourceModule[script.size()]);
WebPageLoaderFactory loaders = new WebPageLoaderFactory(translatorFactory); WebPageLoaderFactory loaders = new WebPageLoaderFactory(translatorFactory);
CAstAnalysisScope scope = new CAstAnalysisScope(scripts, loaders, Collections.singleton(JavaScriptLoader.JS)); CAstAnalysisScope scope = new CAstAnalysisScope(scripts_array, loaders, Collections.singleton(JavaScriptLoader.JS));
IClassHierarchy cha = ClassHierarchy.make(scope, loaders, JavaScriptLoader.JS); IClassHierarchy cha = ClassHierarchy.make(scope, loaders, JavaScriptLoader.JS);
try { try {
Util.checkForFrontEndErrors(cha); Util.checkForFrontEndErrors(cha);
@ -274,11 +281,15 @@ public class CorrelationFinder {
for(IClass klass : cha) { for(IClass klass : cha) {
for(IMethod method : klass.getAllMethods()) { for(IMethod method : klass.getAllMethods()) {
IR ir = factory.makeIR(method, Everywhere.EVERYWHERE, SSAOptions.defaultOptions()); IR ir = factory.makeIR(method, Everywhere.EVERYWHERE, SSAOptions.defaultOptions());
if(method.toString().endsWith("__WINDOW_MAIN__>"))
System.out.println(ir);
CorrelationSummary summary = findCorrelatedAccesses(method, ir); CorrelationSummary summary = findCorrelatedAccesses(method, ir);
if(!summary.getCorrelations().isEmpty()) if(!summary.getCorrelations().isEmpty())
correlations.put(method, summary); correlations.put(method, summary);
} }
} }
printCorrelatedAccesses(correlations);
return correlations; return correlations;
} }

View File

@ -50,6 +50,7 @@ import com.ibm.wala.cast.tree.impl.CAstControlFlowRecorder;
import com.ibm.wala.cast.tree.impl.CAstOperator; import com.ibm.wala.cast.tree.impl.CAstOperator;
import com.ibm.wala.cast.tree.impl.CAstSymbolImpl; import com.ibm.wala.cast.tree.impl.CAstSymbolImpl;
import com.ibm.wala.cast.tree.rewrite.CAstBasicRewriter.NoKey; import com.ibm.wala.cast.tree.rewrite.CAstBasicRewriter.NoKey;
import com.ibm.wala.cast.util.CAstPrinter;
import com.ibm.wala.util.collections.HashMapFactory; import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.collections.HashSetFactory; import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.collections.Pair; import com.ibm.wala.util.collections.Pair;
@ -419,7 +420,7 @@ public class ClosureExtractor extends CAstRewriterExt {
boolean extractingEmpty = false; boolean extractingEmpty = false;
String name = EXTRACTED_FUN_BASENAME + (anonymous_counter++); String name = EXTRACTED_FUN_BASENAME + (anonymous_counter++);
// Create a new entity for the extracted function. // Create a new entity for the extracted function.
ExtractedFunction new_entity = new ExtractedFunction(name, context); ExtractedFunction new_entity = new ExtractedFunction(name, context);
context.setExtractedEntity(new_entity); context.setExtractedEntity(new_entity);

View File

@ -13,6 +13,7 @@ package com.ibm.wala.cast.js.ipa.callgraph.correlations.extraction;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.Collection;
import java.util.Map; import java.util.Map;
import com.ibm.wala.cast.js.ipa.callgraph.correlations.CorrelationFinder; import com.ibm.wala.cast.js.ipa.callgraph.correlations.CorrelationFinder;
@ -23,6 +24,7 @@ import com.ibm.wala.cast.tree.CAstEntity;
import com.ibm.wala.cast.tree.rewrite.CAstBasicRewriter.NoKey; import com.ibm.wala.cast.tree.rewrite.CAstBasicRewriter.NoKey;
import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory; import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory;
import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.ipa.cha.ClassHierarchyException;
public class CorrelatedPairExtractorFactory implements CAstRewriterFactory<NodePos, NoKey> { public class CorrelatedPairExtractorFactory implements CAstRewriterFactory<NodePos, NoKey> {
@ -32,6 +34,14 @@ public class CorrelatedPairExtractorFactory implements CAstRewriterFactory<NodeP
this(new CorrelationFinder(translatorFactory).findCorrelatedAccesses(entryPoint)); this(new CorrelationFinder(translatorFactory).findCorrelatedAccesses(entryPoint));
} }
public CorrelatedPairExtractorFactory(JavaScriptTranslatorFactory translatorFactory, Collection<? extends SourceModule> scripts) throws ClassHierarchyException, IOException {
this(new CorrelationFinder(translatorFactory).findCorrelatedAccesses(scripts));
}
public CorrelatedPairExtractorFactory(JavaScriptTranslatorFactory translatorFactory, SourceModule[] scripts) throws ClassHierarchyException, IOException {
this(new CorrelationFinder(translatorFactory).findCorrelatedAccesses(scripts));
}
public CorrelatedPairExtractorFactory(Map<IMethod, CorrelationSummary> summaries) { public CorrelatedPairExtractorFactory(Map<IMethod, CorrelationSummary> summaries) {
this.summaries = summaries; this.summaries = summaries;
} }