|
From: Yao Q. <qiy...@gm...> - 2008-10-28 08:44:35
|
We want to know what objects these static fields may point to, by this
code snip,
final class Visitor extends SSAInstruction.Visitor
{
@Override
public void visitGet(SSAGetInstruction instruction)
{
if (instruction.isStatic())
{
IField f = ai.getClassHierarchy().resolveField(instruction.getDeclaredField());
PointerKey refPointer = pt.getHeapModel().getPointerKeyForStaticField(f);
OrdinalSet<InstanceKey> instances = pt.getPointsToSet(refPointer);
for (Iterator<InstanceKey> it = instances.iterator(); it.hasNext();)
{
InstanceKey ik = it.next();
ConcreteTypeKey ctk = (ConcreteTypeKey) ik;
System.out.println (ctk.getConcreteType()); //
}
}
}
Visitor v = new Visitor();
int first = bb.getFirstInstructionIndex();
int last = bb.getLastInstructionIndex();
for (int i = first; i <= last; i++)
{
SSAInstruction s = statements[i];
if (s != null)
{
s.visit(v);
}
}
What we got is shown below,
<Primordial,Ljava/lang/Integer>
<Primordial,Ljava/lang/Integer>
What we expecte is that different static field may point to different
objects. However, these static fields are represend by
ConcreteTypekey, and all of them is the same. we could not know
wether two static fields point to the same object or not. I guess
that InstanceKeyWithNode should be got, because these static field is
initialized in <clinit>.
Please let me know if I made some mistakes or misunderstand APIs in
WALA. Thanks.
Test Case.
-----------------------
public class PointTo
{
static Integer lock = new Integer(0);
static Integer lock1 = new Integer(1);
Object o;
public PointTo()
{
o = null;
}
public void m()
{}
/**
* @param args
*/
public static void main(String[] args)
{
PointTo pt = new PointTo();
synchronized (lock)
{
pt.o = new Object();
}
synchronized (lock1)
{
Object o = pt.o;
}
}
}
--
Yao
|