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:
emit
dupinstruction 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 ofdupinstruction choose from, each different behavior; see jvm specification §6.5 details.call static method once, store result in temporary variable (use 1 of
astoreinstruction variants). push onto stack when it's needed using correspondingaloadvariant.
depending on structure of method, may combine these techniques (load temporary local, dup necessary, unrelated, repeat, etc.).
Comments
Post a Comment