bytecode - Loading an existing java object onto stack using ASM -


i trying use asm project , hit performance issue trying required object using static method , called 1000 times

visitor.visitmethodinsn(opcodes.invokestatic, trackingconstants.to_helper_class, "getrttdobject",trackingconstants.to_helper_get_client_method_desc);  visitor.visitmethodinsn(opcodes.invokeinterface, trackingconstants.client_interface_class, "getpattern",trackingconstants.client_interface_class_getpattern_method_desc);      

this first call causing me overhead(where required object , pass next line performing "getpattern" on object.during investigation realized object trying retrieve via static method available me starting if able push java object onto stack , avoid static calls wouldn't not face performance issues.

i tried couple of ways no luck , tried create new field of object illegalargumentexception similar post creating new field asm 4 after going through link realized need write code create object , can't directly use existing object.

so there no way can load existing java object onto stack (i guess on stack, there way can use it) , perform required operations instead of using static call it? there way can achieve it?

once object on stack (presumably after call static method first time), can:

  1. emit dup instruction duplicate value on stack each time needed. performant option, requires craft bytecode in such way value at/near top of stack when need it. there few variants of dup instruction choose from, each different behavior; see jvm specification §6.5 details.

  2. call static method once, store result in temporary variable (use 1 of astore instruction variants). push onto stack when it's needed using corresponding aload variant.

depending on structure of method, may combine these techniques (load temporary local, dup necessary, unrelated, repeat, etc.).


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -