Re: LocalVariablesSorter performance
Eirik Bjørsnøs (via asm Mailing List) <[email protected]> Wed, 17 Feb 2021 15:38:58 +0100
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <CA+pBWhsLbOHvZar5Fq4uRPtk2SmFJHWTOcVbpN+K4KBF8DP2dg@mail.gmail.com> |
This is a multi-part message in MIME format... ------------=_1613572755-2833-16 Content-Type: multipart/alternative; boundary="0000000000008da0ee05bb892e0d" --0000000000008da0ee05bb892e0d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Eugene, I have done some experiments using that approach in the past, however I never got it working. I don't have the exact code around, but from memory I don't think I could ever make the Java class file stack frame verifier happy when introducing variables out-of-order. My instrumentation specifically adds counting local variables (one int per line) at the beginning of the method. Before returns (and in a catch clause), it reports the counts by calling out of the method. When I used higher-than-max slots in the beginning of the method, the verifier would see variables used later in the method body as "top" types, which my stack frames were not prepared for. Eirik. On Wed, Feb 17, 2021 at 3:28 PM Eugene Kuleshov <[email protected]> wrote: > Eirik, > > I'm wondering why you need to prepend variables at all? > Unless converting static to non-static method or adding parameters, > knowing the max number of variables for the method you can use > variable slots after that. > > regards, > Eugene > > > On Wed, Feb 17, 2021 at 5:37 AM Eirik Bj=C3=B8rsn=C3=B8s <[email protected]> wr= ote: > > > > Hi, > > > > I've been looking into the performance of LocalVariablesSorter. This > class currently only supports expanded frames, which means we need to use > the ClassReader.EXPAND_FRAMES option when reading the class. > > > > As my use case only requires prepending variables at the very start of > methods, I don't need to support adding variables at arbitrary code > locations. Taking this into consideration, I made a LocalVariablesPrepend= er > class which simply shifts local variables forward by the amount needed for > injecting the new variables. It also remaps all FULL frames and converts > first-frame SAME/APPEND frames into remapped FULL frames. > > > > This allows LocalVariablesPrepender to be used without > ClassReader.EXPAND_FRAMES. > > > > I then did a JMH benchmark comparing the throughput of injecting a > single local variable (injects ICONST_M1, ISTORE x) using > LocalVariablesSorter to that of my LocalVariablesPrepender. The class used > for testing was Jetty's Server class. > > > > Here are the results: > > > > Benchmark Mode Cnt Score > Error Units > > LocalVariableInjectors.localVariablesPrepender thrpt 25 3940.191 = =C2=B1 > 42.010 ops/s > > LocalVariableInjectors.localVariablesSorter thrpt 25 2681.776 = =C2=B1 > 175.943 ops/s > > > > That's a significant performance improvement for not expanding frames! > > > > What would it take to rewrite LocalVariablesSorter to not require > expanded frames? If that task is too complex, then perhaps ASM should have > something similar to a LocalVariablesPrepender? > > > > Cheers, > > Eirik. > > > > > > > > -- > > 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=3Dhelp > > OW2 mailing lists service home page: http://www.ow2.org/wws > --0000000000008da0ee05bb892e0d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><br><div>Eugene,</div><div><br></div><div>I have done some= experiments using that approach in the=C2=A0past, however I never got it w= orking.=C2=A0</div><div><br></div><div>I don't have the exact code arou= nd, but from memory I don't think I could ever make the Java class file= stack frame verifier happy when introducing variables out-of-order.</div><= div><br></div><div>My instrumentation specifically adds counting local vari= ables (one int per line) at the beginning of the method. Before returns (an= d in a catch clause), it reports the counts by calling out of the method.</= div><div><br></div><div>When I used higher-than-max slots in the beginning = of the method, the verifier would see variables used later in the method bo= dy as "top" types, which my stack frames were not prepared for.= =C2=A0</div><div><br></div><div>Eirik.</div><div><br></div><div>=C2=A0</div= ><div>=C2=A0</div><div></div></div><br><div class=3D"gmail_quote"><div dir= =3D"ltr" class=3D"gmail_attr">On Wed, Feb 17, 2021 at 3:28 PM Eugene Kulesh= ov <<a href=3D"mailto:[email protected]">[email protected]</a>> w= rote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0p= x 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Eirik,<br> <br> =C2=A0 I'm wondering why you need to prepend variables at all?<br> =C2=A0 Unless converting static to non-static method or adding parameters,<= br> knowing the max number of variables for the method you can use<br> variable slots after that.<br> <br> =C2=A0 regards,<br> =C2=A0 Eugene<br> <br> <br> On Wed, Feb 17, 2021 at 5:37 AM Eirik Bj=C3=B8rsn=C3=B8s <<a href=3D"mai= lto:[email protected]" target=3D"_blank">[email protected]</a>> wrote:<br> ><br> > Hi,<br> ><br> > I've been looking into the performance of LocalVariablesSorter. Th= is class currently only supports expanded frames, which means we need to us= e the ClassReader.EXPAND_FRAMES option when reading the class.<br> ><br> > As my use case only requires prepending variables at the very start of= methods, I don't need to support adding variables at arbitrary code lo= cations. Taking this into consideration, I made a LocalVariablesPrepender c= lass which simply shifts local variables forward by the amount needed for i= njecting the new variables. It also remaps all FULL frames and converts fir= st-frame SAME/APPEND frames into remapped FULL frames.<br> ><br> > This allows LocalVariablesPrepender to be used without ClassReader.EXP= AND_FRAMES.<br> ><br> > I then did a JMH benchmark comparing the throughput of injecting a sin= gle local variable (injects ICONST_M1, ISTORE x)=C2=A0 using LocalVariables= Sorter to that of my LocalVariablesPrepender. The class used for testing wa= s Jetty's Server class.<br> ><br> > Here are the results:<br> ><br> > Benchmark=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 Mode=C2=A0 Cnt=C2=A0 =C2=A0 =C2=A0Score=C2=A0 =C2=A0 =C2=A0Error=C2= =A0 Units<br> > LocalVariableInjectors.localVariablesPrepender=C2=A0 thrpt=C2=A0 =C2= =A025=C2=A0 3940.191 =C2=B1=C2=A0 42.010=C2=A0 ops/s<br> > LocalVariableInjectors.localVariablesSorter=C2=A0 =C2=A0 =C2=A0thrpt= =C2=A0 =C2=A025=C2=A0 2681.776 =C2=B1 175.943=C2=A0 ops/s<br> ><br> > That's a significant performance improvement for not expanding fra= mes!<br> ><br> > What would it take to rewrite LocalVariablesSorter to not require expa= nded frames? If that task is too complex, then perhaps ASM should have some= thing similar to a LocalVariablesPrepender?<br> ><br> > Cheers,<br> > Eirik.<br> ><br> ><br> ><br> > --<br> > You receive this message as a subscriber of the <a href=3D"mailto:asm@= ow2.org" target=3D"_blank">[email protected]</a> mailing list.<br> > To unsubscribe: mailto:<a href=3D"mailto:[email protected]" targ= et=3D"_blank">[email protected]</a><br> > For general help: mailto:<a href=3D"mailto:[email protected]" target=3D"_b= lank">[email protected]</a>?subject=3Dhelp<br> > OW2 mailing lists service home page: <a href=3D"http://www.ow2.org/wws= " rel=3D"noreferrer" target=3D"_blank">http://www.ow2.org/wws</a><br> </blockquote></div> --0000000000008da0ee05bb892e0d-- ------------=_1613572755-2833-16 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit -- 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 ------------=_1613572755-2833-16--