[Soot-list] Newbie's question

Sunny sunfire001 at gmail.com
Thu Apr 20 14:22:00 EDT 2006


Hi Michael,

Thank you very much for this information. Certainly it helps! I think it is
best if you have experience using AspectJ which helps give me some
comparisions between Soot and AspectJ (relevant to our needs).


These days I browsed a few similar tools as recommend by Chris and a couple
of others. I am still struggling to figure out which is the one that best
suits my needs. Initially I used JDI to implement my project but
unfortunately, JDI is not able to retrieve the underlying object in the
target VM, given an object reference which delegates that object. In
addition, JDI does not support read/write events for local variables. Then I
turned to AspectJ which is a powerful and easy-to-use tool and solves the
first problem mentioned above. However, it did not solve the second one.

Now given these many choices (JPDA, AspectJ, Soot, ASM...), I think Soot
might be a better one. I have read a few Soot tutorials and skimmed its
APIs, and found it can do various types of program analysis. It seems that I
have to abandon AspectJ and turn to Soot. But before delving into deeper, I
need to know more about what it can do (eg, I need to make sure while I gain
certain benefits from Soot, I won't lose other functionality that AspectJ
provides). Here I prepared a few questions:

1. What do you mean by "ahead-of-time" instrumentation? Does this mean
compile-time?And are there any other types of instrumentations in Soot (e.g.,
runtime ...)?

2. When a method is called, can I easily obtain the context information of
this invocation?That is, can I know who is the caller, who is callee, and
what are the arguments/return values of this method call?

3. When a field or local variable is read/written, can I know what is the
read/write statement's context (i.e., what is the statement's enclosing
object and what is the field's declaring object)?

4. Whan a field or local variable is written, can I know the old value of
this field/local?

Soot can do a lot of program analysis and it provides a large set of APIs. I
would like to focus on only a small subset of it. Could you please recommend
some specific documents/examples that I should read directly (I have tried
the example "Using Soot to instrument a class file" by Feng Qian)?

Your advice is greatly appreciated!

Sunny



On 4/18/06, mbatch at cs.mcgill.ca <mbatch at cs.mcgill.ca> wrote:
>
>
> >> Basically my monitoring program needs to be notified when an object
> >> field, a local variable, or a parameter is write or read. Also I would
> >> like to know something like the entry/exit points of a method call ...
> >>
> >> I used to use AspectJ to implement my project.
>
> By the sounds of it, you compiled the program with aspects which reported
> read/writes. If so, this sounds like ahead-of-time stuff, so you could
> certainly use soot in the same way (ahead-of-time instrumentation).
>
> Soot would work great as it's fairly trivial to find those places in the
> code where a field (or local) is read/written as well as all method calls,
> and simply add method calls to your analyzer before or after (depending on
> what you need) the access.
>
> Nevertheless, JVMTI could work as well for you as since you can monitor a
> running java program on a single-step basis (generally every single
> bytecode) though this might make the program run much slower than
> instrumenting on those places you want to consider (then again, maybe not
> if you want to consider every local read/write)... If you are
> uncomfortable with c and want to stick with java, Soot might be the best
> option.. Otherwise, I found this JVMTI information quickly on a java/sun
> forum:
>
> Given the bytecodes "iload 5", we can get all the information from
> getbytecode() in the JVMTI. The bytecode buffer returned contains both the
> opcodes and the associated operands (cp index, immediate value, local
> variable index etc.). You need to parse the byte buffer returned from the
> JVM TI API. In a for or while loop fetch each byte, switch on opcode and
> in each case read the operands by advancing array index.
>
> Example code which prints out each bytecode of a method:
>
> static void JNICALL callbackSingleStep(jvmtiEnv *jvmti_env,
> JNIEnv* jni_env, jthread thread, jmethodID method, jlocation location)
> {
> enter_critical_section(jvmti); {
>
>    jvmtiError error;
>    jint bytecodeCountPtr;
>    unsigned char *bytecodesPtr;
>
>    error = jvmti->GetBytecodes(method, &bytecodeCountPtr, &bytecodesPtr);
>
>    bytecode = (unsigned char) bytecodesPtr[location];
>    bytecode_stat[bytecode]++;
>
>    if (bytecode==187) {
>      operand1 = (unsigned char) bytecodesPtr[location+1];
>      operand2 =(unsigned char) bytecodesPtr[location+2];
>      fprintf(stdout,"bytecode = \t%d\n", bytecode);
>      fprintf(stdout,"operand1 = \t%d\n", operand1);
>      fprintf(stdout,"operand2 = \t%d\n", operand2);
>    }
>
>    error = jvmti->Deallocate(bytecodesPtr);
>    check_jvmti_error(jvmti_env, error,
>           "Cannot deallocate bytecode pointer");
>
> } exit_critical_section(jvmti);
> }
>
>
> Hope this helps,
>
> Michael
>
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20060420/a0d0e795/attachment.htm


More information about the Soot-list mailing list