Re: Re: How to insert instrcutions at the beginning and/or at the end of each basic block?
John Bergin <[email protected]>
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <[email protected]> |
Hi Leo, "LabelNode" defines the start of a new basic block.
So you could cycle through the opcodes, on finding a LabelNode
then instrument what you like, and I've listed the branching
instructions so you can instrument at that point too...
Good luck..
while (j.hasNext()) {
AbstractInsnNode node = (AbstractInsnNode) j.next();
int opcode = node.getOpcode();
if (in instanceof LabelNode) {
if (j.hasNext()) {
// instrument.
}
}
switch(opcode) {
case IFEQ:
case IFNE:
case IFLT:
case IFGE:
case IFGT:
case IFLE:
case IFNULL:
case IFNONNULL:
case IF_ICMPEQ:
case IF_ICMPNE:
case IF_ICMPLT:
case IF_ICMPGE:
case IF_ICMPGT:
case IF_ICMPLE:
case IF_ACMPEQ:
case IF_ACMPNE:
case JSR:
case GOTO:
//instrument after branching instructions.
break;
}
}
Buu Vinh wrote:
> You can insert your logic at method's entry and exit using
> onMethodEntry and onMethodExit.
>
> Hope this helps.
>
> Buu Vinh
>
> --- On *Wed, 7/6/11, Leo Romanoff /<[email protected]>/* wrote:
>
>
> From: Leo Romanoff <[email protected]>
> Subject: [asm] How to insert instrcutions at the beginning and/or
> at the end of each basic block?
> To: [email protected]
> Date: Wednesday, July 6, 2011, 10:32 AM
>
>
> Hi,
>
> I'd like to instrument my java classes and insert certain sequences of
> instructions at the beginning and/or at the end of each basic block
> (specifically, these instructions are supposed to call a static
> method of
> predefined class).
>
> How this can be done?
>
> Do I need to use classes from the org.objectweb.asm.tree.analysis
> for it? I
> undrestand how I can obtain frames using something like:
> Analyzer a = new Analyzer(new BasicInterpreter());
> ...
> a.analyze(owner, mn);
> Frame[] frames = a.getFrames();
>
> But how do I get from frames to instructuions contained in this
> basic block,
> so that I can insert new ones?
>
> May be there are some existing examples for this kind of
> instrumentation
> already?
>
> Thanks for any help,
> Leo
> --
> View this message in context:
> http://old.nabble.com/How-to-insert-instrcutions-at-the-beginning-and-or-at-the-end-of-each-basic-block--tp32005881p32005881.html
> Sent from the ASM mailing list archive at Nabble.com.
>
>
> -----Inline Attachment Follows-----
>
>
> --
> You receive this message as a subscriber of the [email protected]
> </mc/[email protected]> mailing list.
> To unsubscribe: mailto:[email protected]
> </mc/[email protected]>
> For general help: mailto:[email protected]
> </mc/[email protected]>?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
>
message-footer.txt
(text/plain, 238 B)
-- You receive this message as a subscriber of the [email protected] mailing list. To unsubscribe: mailto:[email protected] For general help: mailto:[email protected]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws