Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -55,6 +56,30 @@ private enum State {
summary, hierarchy, intf, methods, method, flow, clear, gaps, gap, constraints, key, index
}

/**
* It takes quite a while to create a new XML Input Factory
*/
private static class CachedFactory {
WeakReference<Thread> thread;
XMLInputFactory factory;

public CachedFactory() {

XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
this.factory = factory;
this.thread = new WeakReference<Thread>(Thread.currentThread());
}

public boolean isValidForThisThread() {
Thread thr = thread.get();
return Thread.currentThread() == thr;
}
}

private CachedFactory cachedFactory;

/**
* Reads a summary xml and places the new summaries into the given data object.
* This method closes the reader.
Expand All @@ -68,10 +93,13 @@ public void read(Reader reader, ClassMethodSummaries summaries)
throws XMLStreamException, SummaryXMLException, IOException {
XMLStreamReader xmlreader = null;
try {
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
xmlreader = factory.createXMLStreamReader(reader);
//Sadly, the XML Input Factory is not thread safe :/
CachedFactory cachedFact = cachedFactory;
if (cachedFact == null || !cachedFact.isValidForThisThread()) {
cachedFact = new CachedFactory();
this.cachedFactory = cachedFact;
}
xmlreader = cachedFact.factory.createXMLStreamReader(reader);
final MethodSummaries summary = summaries.getMethodSummaries();

Map<String, String> sourceAttributes = new HashMap<String, String>();
Expand Down
4 changes: 4 additions & 0 deletions soot-infoflow/src/soot/jimple/infoflow/AbstractInfoflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,7 @@ else if (reason instanceof TimeoutReason)
performanceData.updateMaxMemoryConsumption(getUsedMemory());
logger.info(String.format("Memory consumption after cleanup: %d MB", getUsedMemory()));

beforePathReconstruction = System.nanoTime();
// Reconstruct the paths from source to sink
reconstructPaths(builder, resultExecutor, res);
} finally {
Expand Down Expand Up @@ -1339,6 +1340,9 @@ else if (logger.isInfoEnabled()) {
*/
protected void reconstructPaths(IAbstractionPathBuilder builder, InterruptableExecutor executor,
Set<AbstractionAtSink> ifdsResults) {
if (ifdsResults.isEmpty())
return;

FlowDroidTimeoutWatcher pathTimeoutWatcher = null;

try {
Expand Down