[Soot-list] Help needed with ThreadLocalObjectsAnalysis
Arie Zilberstein
arie.zilberstein at gmail.com
Fri Sep 4 14:13:48 EDT 2009
OK,
----------------> Tested class code: <-----------
public class Publish {
public static void main(String[] args) {
Publish publish = new Publish();
invokeThreadAccessSharedDummy();
publish.test();
}
private static void invokeThreadAccessSharedDummy() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
sharedDummy.integer = 20;
System.out.println("in thread!");
}
});
t.start();
}
Dummy d;
static Dummy sharedDummy;
private void test() {
// d is local
d = new Dummy();
d.integer = 5;
// publish d
sharedDummy = d;
// d is now shared
d.integer = 10;
}
}
----------------> Class invoking TLOA <-------------
public class ThreadLocalSceneTransformer extends SceneTransformer {
private static Transformer instance = new
ThreadLocalSceneTransformer();
private ThreadLocalObjectsAnalysis tloa;
public static Transformer v() {
return instance;
}
private ThreadLocalObjectsAnalysis getTLOA() {
MhpTester mhp = new SynchObliviousMhpAnalysis();
ThreadLocalObjectsAnalysis tloa = new
ThreadLocalObjectsAnalysis(mhp);
return tloa;
}
@Override
protected void internalTransform(String phaseName, Map options) {
tloa = getTLOA();
iterateAllMethods();
}
private void iterateAllMethods() {
// Find methods
Iterator<SootClass> getClassesIt =
Scene.v().getApplicationClasses()
.iterator();
while (getClassesIt.hasNext()) {
SootClass appClass = getClassesIt.next();
Iterator<SootMethod> getMethodsIt =
appClass.getMethods()
.iterator();
while (getMethodsIt.hasNext()) {
SootMethod method = getMethodsIt.next();
analyzeMethod(method);
}
}
}
private void analyzeMethod(SootMethod method) {
if (!method.hasActiveBody()) {
return;
}
Body activeBody = method.getActiveBody();
List<ValueBox> useAndDefBoxes =
activeBody.getUseAndDefBoxes();
for (ValueBox valueBox : useAndDefBoxes) {
Value value = valueBox.getValue();
if (value instanceof FieldRef) {
analyzeField(method, value);
}
}
}
private void analyzeField(SootMethod method, Value value) {
FieldRef fr = (FieldRef) value;
boolean fieldIsThreadLocal = tloa.isObjectThreadLocal(fr,
method);
if (fieldIsThreadLocal) {
// DISCOVERED A THREAD LOCAL FIELD, KEEP IT IN
DATABASE HERE...
}
}
}
----------------------------------------------
I inject the new transformer in the recommended way.
I use the following parameters on the main() method:
-cp <folder> -process-dir <folder> -d <output-folder> -pp -w -p cg.spark
enabled:true -p jb use-original-names:true -app -keep-bytecode-offset
-main-class Publish
Best,
Arie
-----Original Message-----
From: eric.bodden at googlemail.com [mailto:eric.bodden at googlemail.com] On
Behalf Of Eric Bodden
Sent: Friday, September 04, 2009 6:51 PM
To: Arie Zilberstein
Cc: soot-list at sable.mcgill.ca
Subject: Re: [Soot-list] Help needed with ThreadLocalObjectsAnalysis
Arie can you send us the complete examples? It's hard to tell form the
code fragment you send. In those cases details usually count.
Eric
2009/9/4 Arie Zilberstein <arie.zilberstein at gmail.com>:
> Hi,
>
>
>
> I'm experimenting with soot's ThreadLocalObjectsAnalysis class.
>
>
>
> I want to find out if a field of an object is thread-local or
thread-shared
> within a method. I realize that this may change over the lifetime of a
> single method. Look at this example:
>
>
>
> Dummy d;
>
> static Dummy sharedDummy;
>
>
>
> private void test() {
>
> d = new Dummy(); // d is thread-local
>
> d.integer = 5;
>
>
>
> sharedDummy = d; // publish d; it is not thread-shared
>
> d.integer = 10;
>
> }
>
>
>
> I used the ThreadLocalObjectsAnalysis object, hoping that it would
determine
> that the second write to d (d.integer=10) is to a field which is
> thread-shared, but for some reason, it deduced that the field is
> thread-local.
>
>
>
> I'm using the object like this:
>
> MhpTester mhp = new SynchObliviousMhpAnalysis();
>
> ThreadLocalObjectsAnalysis tloa = new
> ThreadLocalObjectsAnalysis(mhp);
>
> // later, given a value from a method
>
> boolean fieldIsThreadLocal = tloa.isObjectThreadLocal(value, method);
>
>
>
>
>
> I should note that, just before calling test(), I'm starting a thread
which
> deliberately sets sharedDummy.integer to 20. That's why I expect the
object
> stored in sharedDummy to be thread-shared.
>
>
>
> I would appreciate any help! Is this my misunderstanding? or a problem?
>
>
>
> Best,
>
> Arie
>
>
>
>
>
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
>
--
Eric Bodden
Software Technology Group, Technische Universität Darmstadt, Germany
Tel: +49 6151 16-5478 Fax: +49 6151 16-5410
Mailing Address: S2|02 A209, Hochschulstraße 10, 64289 Darmstadt
More information about the Soot-list
mailing list