Skip to content

Commit 73c12f4

Browse files
authored
Merge pull request #356 from MarcMil/dev-experimental
Introducing ThreadUtils
2 parents b119180 + 322e3d5 commit 73c12f4

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

soot-infoflow/src/soot/jimple/infoflow/memory/FlowDroidTimeoutWatcher.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import soot.jimple.infoflow.memory.IMemoryBoundedSolver.IMemoryBoundedSolverStatusNotification;
1111
import soot.jimple.infoflow.memory.reasons.TimeoutReason;
1212
import soot.jimple.infoflow.results.InfoflowResults;
13+
import soot.jimple.infoflow.util.ThreadUtils;
1314

1415
/**
1516
* Class for enforcing timeouts on IFDS solvers
@@ -98,7 +99,7 @@ public void start() {
9899
logger.info("FlowDroid timeout watcher started");
99100
this.stopped = false;
100101

101-
new Thread(new Runnable() {
102+
ThreadUtils.createGenericThread(new Runnable() {
102103

103104
@Override
104105
public void run() {
@@ -155,7 +156,7 @@ private boolean isTerminated() {
155156
return allTerminated;
156157
}
157158

158-
}, "FlowDroid Timeout Watcher").start();
159+
}, "FlowDroid Timeout Watcher", true).start();
159160
}
160161

161162
/**

soot-infoflow/src/soot/jimple/infoflow/memory/MemoryWarningSystem.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.slf4j.Logger;
2525
import org.slf4j.LoggerFactory;
2626

27+
import soot.jimple.infoflow.util.ThreadUtils;
28+
2729
/**
2830
* Notification system that triggers a callback when the JVM is about to run out
2931
* of memory. Inspired by code from
@@ -204,7 +206,7 @@ public void setWarningThreshold(double percentage) {
204206
if (useOwnImplementation) {
205207
// No JVM support is available, use our own implementation
206208
if (thrLowMemoryWarningThread == null) {
207-
thrLowMemoryWarningThread = new Thread(new Runnable() {
209+
thrLowMemoryWarningThread = ThreadUtils.createGenericThread(new Runnable() {
208210

209211
@Override
210212
public void run() {
@@ -251,9 +253,7 @@ public void run() {
251253
}
252254
}
253255

254-
});
255-
thrLowMemoryWarningThread.setName("Low memory monitor");
256-
thrLowMemoryWarningThread.setDaemon(true);
256+
}, "Low memory monitor", true);
257257
thrLowMemoryWarningThread.setPriority(Thread.MIN_PRIORITY);
258258
thrLowMemoryWarningThread.start();
259259
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package soot.jimple.infoflow.util;
2+
3+
/**
4+
* This class can be used to create threads.
5+
* Own implementations may provide their own factory if they wish.
6+
*/
7+
public class ThreadUtils {
8+
/**
9+
* Can be used to create threads
10+
*/
11+
public static interface IThreadFactory {
12+
/**
13+
* Adds a thread which is generic, i.e. not necessary tied to a specific soot instance.
14+
* @param r the runnable
15+
* @param name the name of the thread
16+
* @param daemon whether the thread is a daemon
17+
* @return the thread
18+
*/
19+
public Thread createGenericThread(Runnable r, String name, boolean daemon);
20+
}
21+
22+
public static IThreadFactory threadFactory = new IThreadFactory() {
23+
24+
@Override
25+
public Thread createGenericThread(Runnable r, String name, boolean daemon) {
26+
Thread thr = new Thread(r, name);
27+
thr.setDaemon(daemon);
28+
return thr;
29+
}
30+
31+
};
32+
33+
/**
34+
* Adds a thread which is generic, i.e. not necessary tied to a specific soot instance.
35+
* @param r the runnable
36+
* @param name the name of the thread
37+
* @param daemon whether the thread is a daemon
38+
* @return the thread
39+
*/
40+
public static Thread createGenericThread(Runnable r, String name, boolean daemon) {
41+
return threadFactory.createGenericThread(r, name, daemon);
42+
}
43+
}

0 commit comments

Comments
 (0)