On Sun, Mar 02, 2003 at 02:45:31AM -0500, Chris Pickett wrote:
Hi.
I'm trying to compute the number of silent stores in a Java program. A
silent store occurs when the value stored is identical to the value
already there. I have three questions:
Q1) Why does the single variable "y" in the following code get split
into "b1" and "b2" in the Jimple representation:
public class HelloWorld {
public static void main(String[] args) {
int y;
y = 2;
y = 2;
}
}
-->
public class HelloWorld extends java.lang.Object
{
public void <init>()
{
HelloWorld r0;
r0 := @this: HelloWorld;
specialinvoke r0.<java.lang.Object: void <init>()>();
return;
}
public static void main(java.lang.String[] )
{
java.lang.String[] r0;
byte b0, b1;
r0 := @parameter0: java.lang.String[];
b0 = 2;
b1 = 2;
return;
}
}
By default, Soot splits variables according to def-use chains. This is
mostly because of the variables representing stack slots; they are
typically reused many times, and not splitting them would be very
unfortunate for any analysis trying to use Jimple. You can use the
phase option -p jb unsplit-original-locals to get the original locals
back.
Q2) How can I test whether a variable (register?) has been initialized
at runtime. Currently, for the Jimple code:
The Java VM spec says that every variable must be provable to be
initialized before it is first used. The code you are producing
reads the variable before it has been initialized, so the VM cannot
prove that it will always be initialized before being read, so it
refuses to run it. Given that any code that may read uninitialized
variables will be rejected by the VM, it seems kind of pointless to
count reads of uninitialized variables, since there will never be any.
I actually don't want to do anything if the variable has not been
initialized, except to increment the store counter for that variable.
I can't add code to initialize the variable before I test, because if
I did it might give a false silent store when really it's just the
initialization of a variable.