add an example of constructing IRs and use of ReferenceCleanser
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3805 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
4cda34d1e4
commit
cab2bcfd07
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/com.ibm.wala.core.tests/src/com/ibm/wala/examples/analysis/ConstructAllIRs.java"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="1"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5" javaProject="com.ibm.wala.core.tests" path="1" type="4"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento exportedEntriesOnly="false" project="com.ibm.wala.core.tests"/> </runtimeClasspathEntry> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry path="3" projectName="com.ibm.wala.core.testdata" type="1"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/com.ibm.wala.core.testdata/bin" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/com.ibm.wala.core.testdata/src" path="3" type="2"/> "/>
|
||||
</listAttribute>
|
||||
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.ibm.wala.examples.analysis.ConstructAllIRs"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="/Users/manu/Documents/workspaces/34workspace/com.ibm.wala.core.tests/dat/bcel.txt"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.ibm.wala.core.tests"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea -Xmx400M"/>
|
||||
</launchConfiguration>
|
|
@ -0,0 +1,97 @@
|
|||
/*******************************************************************************
|
||||
* 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 com.ibm.wala.examples.analysis;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.ibm.wala.classLoader.IClass;
|
||||
import com.ibm.wala.classLoader.IMethod;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||
import com.ibm.wala.ipa.callgraph.impl.Everywhere;
|
||||
import com.ibm.wala.ipa.cha.ClassHierarchy;
|
||||
import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
||||
import com.ibm.wala.util.config.AnalysisScopeReader;
|
||||
import com.ibm.wala.util.perf.Stopwatch;
|
||||
import com.ibm.wala.util.ref.ReferenceCleanser;
|
||||
|
||||
/**
|
||||
* An analysis skeleton that simply constructs IRs for all methods in a class hierarchy. Illustrates the use of
|
||||
* {@link ReferenceCleanser} to improve running time / reduce memory usage.
|
||||
*/
|
||||
public class ConstructAllIRs {
|
||||
|
||||
/**
|
||||
* Should we periodically clear out soft reference caches in an attempt to help the GC?
|
||||
*/
|
||||
private final static boolean PERIODIC_WIPE_SOFT_CACHES = true;
|
||||
|
||||
/**
|
||||
* Interval which defines the period to clear soft reference caches
|
||||
*/
|
||||
private final static int WIPE_SOFT_CACHE_INTERVAL = 2500;
|
||||
|
||||
/**
|
||||
* Counter for wiping soft caches
|
||||
*/
|
||||
private static int wipeCount = 0;
|
||||
|
||||
/**
|
||||
* First command-line argument should be location of scope file for application to analyze
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ClassHierarchyException
|
||||
*/
|
||||
public static void main(String[] args) throws IOException, ClassHierarchyException {
|
||||
String scopeFile = args[0];
|
||||
|
||||
// measure running time
|
||||
Stopwatch s = new Stopwatch();
|
||||
s.start();
|
||||
AnalysisScope scope = AnalysisScopeReader.readJavaScope(scopeFile, null, ConstructAllIRs.class.getClassLoader());
|
||||
|
||||
// build a type hierarchy
|
||||
System.out.print("building class hierarchy...");
|
||||
ClassHierarchy cha = ClassHierarchy.make(scope);
|
||||
System.out.println("done");
|
||||
|
||||
// register class hierarchy and AnalysisCache with the reference cleanser, so that their soft references are appropriately wiped
|
||||
ReferenceCleanser.registerClassHierarchy(cha);
|
||||
AnalysisCache cache = new AnalysisCache();
|
||||
ReferenceCleanser.registerCache(cache);
|
||||
AnalysisOptions options = new AnalysisOptions();
|
||||
|
||||
System.out.print("building IRs...");
|
||||
for (IClass klass : cha) {
|
||||
for (IMethod method : klass.getDeclaredMethods()) {
|
||||
wipeSoftCaches();
|
||||
// construct an IR; it will be cached
|
||||
cache.getSSACache().findOrCreateIR(method, Everywhere.EVERYWHERE, options.getSSAOptions());
|
||||
}
|
||||
}
|
||||
System.out.println("done");
|
||||
s.stop();
|
||||
System.out.println("RUNNING TIME: " + s.getElapsedMillis());
|
||||
|
||||
}
|
||||
|
||||
private static void wipeSoftCaches() {
|
||||
if (PERIODIC_WIPE_SOFT_CACHES) {
|
||||
wipeCount++;
|
||||
if (wipeCount >= WIPE_SOFT_CACHE_INTERVAL) {
|
||||
wipeCount = 0;
|
||||
ReferenceCleanser.clearSoftCaches();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue