Re: Method size in bytes
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <CAKJVBvA6tpcDsvR5MvZcGoy+-N_Y7dDXJisfszUi-vH0stkt5Q@mail.gmail.com> |
This is a multi-part message in MIME format... ------------=_1717323690-3809417-7 Content-Type: multipart/alternative; boundary="0000000000007344890619e592ce" --0000000000007344890619e592ce Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Peter, You should sum the bytes for all instructions. So you should implement all `visitXxxInsn` methods. Note also that different instructions have a different number of bytes. For instance `visitIntInsn` may be related to either BIPUSH or SIPUSH. The former occupies 2-bytes and the later 3-bytes. ASM commons library already have this implemented on the `CodeSizeEvaluator` visitor. Maybe better idea to use this implementation. Best regards Roberto Araujo Em s=C3=A1b., 1 de jun. de 2024 11:35, Peter Rader <[email protected]> escreveu: > > Hello, > > I try to find the biggest size of all methods in a class. What I can find > is the amount of instructions. But how to measure the bytes? This is my > Visitor: > > > public static class MethodMeter extends MethodVisitor { > > private final AtomicInteger maxInstructionSize; > private final AtomicInteger currentInstructionSize =3D new > AtomicInteger(0); > public MethodMeter(final AtomicInteger maxBytecodeSize) { > super(Opcodes.ASM4); > this.maxInstructionSize =3D maxBytecodeSize; > } > @Override > public void visitAttribute(final Attribute attribute) { > super.visitAttribute(attribute); > } > @Override > public void visitEnd() { > if (currentInstructionSize.get() > > maxInstructionSize.get()) { > > maxInstructionSize.set(currentInstructionSize.get()); > } > currentInstructionSize.set(0); > } > @Override > public void visitInsn(final int opcode) { > currentInstructionSize.addAndGet(1); > } > @Override > public void visitIntInsn(final int opcode, final int operand) { > currentInstructionSize.addAndGet(1); > } > } > > > Kind regards > > Peter Rader > -- > Fachinformatiker AE / IT Software Developer > Peter Rader > Wilsnacker Strasse 17 > 10559 Berlin - GERMANY > Tel: 0049 (0)30 / 6 29 33 29 6 > Fax: 0049 (0)30 / 6 29 33 29 6 > Handy: 0049 (0)176 / 87 521 576 > > -- > 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 > --0000000000007344890619e592ce Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"auto"><div><div dir=3D"auto">Hi Peter,</div><div dir=3D"auto"><= br></div><div dir=3D"auto">You should sum the bytes for all instructions. S= o you should implement=C2=A0 all `visitXxxInsn` methods. Note also that dif= ferent instructions have a different number of bytes. For instance `visitIn= tInsn` may be related to either BIPUSH or SIPUSH. The former occupies 2-byt= es and the later 3-bytes.</div><div dir=3D"auto"><br></div>ASM commons libr= ary already have this implemented on the `CodeSizeEvaluator` visitor. Maybe= better idea to use this implementation.</div><div dir=3D"auto"><br></div><= div dir=3D"auto">Best regards</div><div dir=3D"auto"><br></div><div dir=3D"= auto">Roberto Araujo<br><br><div class=3D"gmail_quote" dir=3D"auto"><div di= r=3D"ltr" class=3D"gmail_attr">Em s=C3=A1b., 1 de jun. de 2024 11:35, Peter= Rader <<a href=3D"mailto:[email protected]" rel=3D"noreferrer noreferrer nore= ferrer" target=3D"_blank">[email protected]</a>> escreveu:<br></div><blockquot= e class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc sol= id;padding-left:1ex"><br> Hello,<br> =C2=A0<br> I try to find the biggest size of all methods in a class. What I can find i= s the amount of instructions. But how to measure the bytes? This is my Visi= tor:<br> <br> <br> public static class MethodMeter extends MethodVisitor {<br> <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 private final AtomicInteger maxInstructionSize;= <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 private final AtomicInteger currentInstructionS= ize =3D new AtomicInteger(0);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 public MethodMeter(final AtomicInteger maxBytec= odeSize) {<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 super(Opcodes.ASM4)= ;<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 this.maxInstruction= Size =3D maxBytecodeSize;<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 @Override<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 public void visitAttribute(final Attribute attr= ibute) {<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 super.visitAttribut= e(attribute);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 @Override<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 public void visitEnd() {<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (currentInstruct= ionSize.get() > maxInstructionSize.get()) {<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 maxInstructionSize.set(currentInstructionSize.get());<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 currentInstructionS= ize.set(0);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 @Override<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 public void visitInsn(final int opcode) {<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 currentInstructionS= ize.addAndGet(1);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 @Override<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 public void visitIntInsn(final int opcode, fina= l int operand) {<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 currentInstructionS= ize.addAndGet(1);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br> }<br> <br> =C2=A0<br> Kind regards<br> <br> Peter Rader<br> --<br> Fachinformatiker AE / IT Software Developer<br> Peter Rader<br> Wilsnacker Strasse 17<br> 10559 Berlin - GERMANY<br> Tel: 0049 (0)30 / 6 29 33 29 6<br> Fax: 0049 (0)30 / 6 29 33 29 6<br> Handy: 0049 (0)176 / 87 521 576<br> <br> -- <br> You receive this message as a subscriber of the <a href=3D"mailto:[email protected]= rg" rel=3D"noreferrer noreferrer noreferrer noreferrer" target=3D"_blank">a= [email protected]</a> mailing list.<br> To unsubscribe: mailto:<a href=3D"mailto:[email protected]" rel=3D"no= referrer noreferrer noreferrer noreferrer" target=3D"_blank">asm-unsubscrib= [email protected]</a><br> For general help: mailto:<a href=3D"mailto:[email protected]" rel=3D"noreferrer= noreferrer noreferrer noreferrer" target=3D"_blank">[email protected]</a>?subj= ect=3Dhelp<br> OW2 mailing lists service home page: <a href=3D"http://www.ow2.org/wws" rel= =3D"noreferrer noreferrer noreferrer noreferrer noreferrer" target=3D"_blan= k">http://www.ow2.org/wws</a><br> </blockquote></div> </div></div> --0000000000007344890619e592ce-- ------------=_1717323690-3809417-7 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- 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 ------------=_1717323690-3809417-7--