Re: Example for ConstantDynamic

[email protected] Fri, 1 Nov 2019 01:19:27 +0100 (CET)
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <[email protected]>
This is a multi-part message in MIME format...

------------=_1572567578-31803-12
Content-Type: multipart/alternative; 
	boundary="=_6346791e-bc23-493b-b9b4-4eee6b465261"

--=_6346791e-bc23-493b-b9b4-4eee6b465261
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

> De: "Gunnar Morling" <[email protected]>
> =C3=80: "Gunnar Morling" <[email protected]>
> Cc: "Remi Forax" <[email protected]>, "asm" <[email protected]>
> Envoy=C3=A9: Jeudi 31 Octobre 2019 22:47:13
> Objet: Re: [asm] Example for ConstantDynamic

> Remi,
> So I could generate a class with an ldc instruction that loads a dynamic
> constant. Nice!
> Now when is the bootstrap method invoked? I was assuming/hoping it would =
happen
> lazily when executing the first ldc referencing it, but it seems to happe=
n as
> soon as the class is loaded. Is there any way to control or defer this?
> Thanks again,

If condy is only referenced by one ldc, it should only loaded the first tim=
e you need it. If you have several ldcs or if you are using the same condy*=
 as a bootstrap arguments, it will be initialized once for all occurences.=
=20
* beware ASM shares them if they have the exact same parameters=20

> --Gunnar

> PS: for future readers of this thread, the call to methodType() is missin=
g the
> class parameter before the int.class.

yes, my bad, it should be MethodType.methodType(Object.class, Lookup.class,=
 String.class, Class.class, int.class).toMethodDescriptorString()=20

R=C3=A9mi=20

> Am Do., 31. Okt. 2019 um 09:46 Uhr schrieb Gunnar Morling < [
> mailto:[email protected] | [email protected] ] >:

>> Remi,
>> Thanks for the super-fast reply. I'll play with that.

>> --Gunnar

>> Am Mi., 30. Okt. 2019 um 23:41 Uhr schrieb Remi Forax < [
>> mailto:[email protected] | [email protected] ] >:

>>> Hi Gunnar,
>>> with a LDC on a constant dynamic
>>> mv.visitLdc( new ConstantDynamic ("name", "Ljava/lang/Object;", BSM, 2)=
);

>>> BSM is a Handle to a static method starting with a Lookup (a
>>> MethodHandles.Lookup), a String (here "name"), a Class corresponding to=
 the
>>> field descriptor (here Object.class) and some bootstrap constants (here=
 2), the
>>> return value is the value of the constant.
>>> so Handle BSM =3D new Handle(Opcodes.H_INVOKESTATIC, "RT", "bsm",
>>> MethodType.methodType(Object.class, Lookup.class, String.class, Class.c=
lass,
>>> int.class).toMethodDescriptorString(), false);

>>> so the method bsm inside the class RT can be
>>> class RT {
>>> public static Object bsm(Lookup lookup, String name, Class<?> type, int=
 two) {
>>> ... }
>>> }

>>> note that the VM calls any boostrap method using MethodHandle.invoke so=
 any
>>> supertypes for the parameter types, any subtype for the return type, or=
 any
>>> boxing/varargs will also work, by example
>>> class RT {
>>> public static String bsm(Lookup lookup, Object name, Class<?> type, Obj=
ect two)
>>> { ... }
>>> }

>>> R=C3=A9mi

>>>> De: "Gunnar Morling" < [ mailto:[email protected] | gunnar@hibernat=
e.org ] >
>>>> =C3=80: "asm" < [ mailto:[email protected] | [email protected] ] >
>>>> Envoy=C3=A9: Mercredi 30 Octobre 2019 23:11:52
>>>> Objet: [asm] Example for ConstantDynamic

>>>> Hi,
>>>> Is there any simple yet complete example of producing a ConstantDynami=
c (JEP
>>>> 309) reference (visitLdcInsn) using ASM? In particular I'm unsure abou=
t linking
>>>> it to the bootstrap method.

>>>> Thanks for any pointers,

>>>> --Gunnar

>>>> --
>>>> You receive this message as a subscriber of the [ mailto:[email protected] |
>>>> [email protected] ] mailing list.
>>>> To unsubscribe: mailto: [ mailto:[email protected] |
>>>> [email protected] ]
>>>> For general help: mailto: [ mailto:[email protected] | [email protected] ] ?su=
bject=3Dhelp
>>>> OW2 mailing lists service home page: [ http://www.ow2.org/wws |
>>>> http://www.ow2.org/wws ]

--=_6346791e-bc23-493b-b9b4-4eee6b465261
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<html><body><div style=3D"font-family: arial, helvetica, sans-serif; font-s=
ize: 12pt; color: #000000"><div><br></div><div><br></div><hr id=3D"zwchr" d=
ata-marker=3D"__DIVIDER__"><div data-marker=3D"__HEADERS__"><blockquote sty=
le=3D"border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:=
#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:=
Helvetica,Arial,sans-serif;font-size:12pt;"><b>De: </b>"Gunnar Morling" &lt=
;[email protected]&gt;<br><b>=C3=80: </b>"Gunnar Morling" &lt;gunnar@hib=
ernate.org&gt;<br><b>Cc: </b>"Remi Forax" &lt;[email protected]&gt;, "asm" =
&lt;[email protected]&gt;<br><b>Envoy=C3=A9: </b>Jeudi 31 Octobre 2019 22:47:13<b=
r><b>Objet: </b>Re: [asm] Example for ConstantDynamic<br></blockquote></div=
><div data-marker=3D"__QUOTED_TEXT__"><blockquote style=3D"border-left:2px =
solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:norma=
l;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-s=
erif;font-size:12pt;"><div dir=3D"ltr">Remi,<br>So I could generate a class=
 with an ldc instruction that loads a dynamic constant. Nice!<br><div>Now w=
hen is the bootstrap method invoked? I was assuming/hoping it would happen =
lazily when executing the first ldc referencing it, but it seems to happen =
as soon as the class is loaded. Is there any way to control or defer this?<=
br><div>Thanks again,</div></div></div></blockquote><div><br></div>If condy=
 is only referenced by one ldc, it should only loaded the first time you ne=
ed it. If you have several ldcs or if you are using the same condy* as a bo=
otstrap arguments, it will be initialized once for all occurences.<br></div=
><div data-marker=3D"__QUOTED_TEXT__"><div>* beware ASM shares them if they=
 have the exact same parameters</div><div><br data-mce-bogus=3D"1"></div><b=
lockquote style=3D"border-left:2px solid #1010FF;margin-left:5px;padding-le=
ft:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none=
;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir=3D"ltr"><=
div><div>--Gunnar</div></div></div></blockquote><blockquote style=3D"border=
-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-we=
ight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Ar=
ial,sans-serif;font-size:12pt;"><div dir=3D"ltr"><div><div><br><br><div>PS:=
 for future readers of this thread, the call to methodType() is missing the=
 class parameter before the int.class.</div></div></div></div></blockquote>=
<div><br></div><div>yes, my bad, it should be <span>MethodType.methodType(O=
bject.class, Lookup.class, String.class, Class.class, int.class).toMethodDe=
scriptorString()</span></div><div><br data-mce-bogus=3D"1"></div><div>R=C3=
=A9mi<br data-mce-bogus=3D"1"></div><div><br data-mce-bogus=3D"1"></div><bl=
ockquote style=3D"border-left:2px solid #1010FF;margin-left:5px;padding-lef=
t:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;=
font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir=3D"ltr"><d=
iv><br></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D=
"gmail_attr">Am Do., 31. Okt. 2019 um 09:46&nbsp;Uhr schrieb Gunnar Morling=
 &lt;<a href=3D"mailto:[email protected]" target=3D"_blank">gunnar@hiber=
nate.org</a>&gt;:<br></div><blockquote class=3D"gmail_quote" style=3D"margi=
n:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex=
"><div dir=3D"ltr">Remi,<br><div>Thanks for the super-fast reply. I'll play=
 with that.</div><br><div>--Gunnar</div><br><br></div><br><div class=3D"gma=
il_quote"><div dir=3D"ltr" class=3D"gmail_attr">Am Mi., 30. Okt. 2019 um 23=
:41&nbsp;Uhr schrieb Remi Forax &lt;<a href=3D"mailto:[email protected]" ta=
rget=3D"_blank">[email protected]</a>&gt;:<br></div><blockquote class=3D"gm=
ail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,=
204,204);padding-left:1ex"><div><div style=3D"font-family:arial,helvetica,s=
ans-serif;font-size:12pt;color:rgb(0,0,0)"><div>Hi Gunnar,</div><div>with a=
 LDC on a constant dynamic<br></div><div>&nbsp; mv.visitLdc(<span>new</span=
> <span>ConstantDynamic</span>("name", "Ljava/lang/Object;", BSM, 2));<br><=
/div><br><div>BSM is a Handle to a static method starting with a Lookup (a =
MethodHandles.Lookup), a String (here "name"), a Class corresponding to the=
 field descriptor (here Object.class) and some bootstrap constants (here 2)=
, the return value is the value of the constant.<br></div><div>&nbsp; so <s=
pan>Handle</span> BSM =3D <span>new Handle(Opcodes.H_INVOKESTATIC, "RT", "b=
sm", MethodType.methodType(Object.class, Lookup.class, String.class, Class.=
class, int.class).toMethodDescriptorString(), false);</span><br></div><br><=
div>so the method bsm inside the class RT can be<br></div><div>class RT {<b=
r></div><div>&nbsp; public static Object bsm(Lookup lookup, String name, Cl=
ass&lt;?&gt; type, int two) { ... }<br></div><div>}<br></div><br><div>note =
that the VM calls any boostrap method using MethodHandle.invoke so any supe=
rtypes for the parameter types, any subtype for the return type, or any box=
ing/varargs will also work, by example<br></div><div><div>class RT {</div><=
div>&nbsp; public static String bsm(Lookup lookup, Object name, Class&lt;?&=
gt; type, Object two) { ... }</div><div>}</div><br></div><div>R=C3=A9mi</di=
v><div>&nbsp; <br></div><hr id=3D"gmail-m_-4498365127723273330gmail-m_18094=
10738653198026zwchr"><div><blockquote style=3D"border-left:2px solid rgb(16=
,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:norm=
al;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-=
serif;font-size:12pt"><b>De: </b>"Gunnar Morling" &lt;<a href=3D"mailto:gun=
[email protected]" target=3D"_blank">[email protected]</a>&gt;<br><b>=C3=
=80: </b>"asm" &lt;<a href=3D"mailto:[email protected]" target=3D"_blank">asm@ow2=
.org</a>&gt;<br><b>Envoy=C3=A9: </b>Mercredi 30 Octobre 2019 23:11:52<br><b=
>Objet: </b>[asm] Example for ConstantDynamic<br></blockquote></div><div><b=
lockquote style=3D"border-left:2px solid rgb(16,16,255);margin-left:5px;pad=
ding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-de=
coration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div d=
ir=3D"ltr">Hi,<br><div>Is there any simple yet complete example of producin=
g a ConstantDynamic (JEP 309) reference (visitLdcInsn) using ASM? In partic=
ular I'm unsure about linking it to the bootstrap method.</div><br><div>Tha=
nks&nbsp;for any pointers,</div><br><div>--Gunnar</div><br></div>
<br><br>-- <br>You receive this message as a subscriber of the <a href=3D"m=
ailto:[email protected]" target=3D"_blank">[email protected]</a> mailing list.<br>To un=
subscribe: mailto:<a href=3D"mailto:[email protected]" target=3D"_bla=
nk">[email protected]</a><br>For general help: mailto:<a href=3D"mail=
to:[email protected]" target=3D"_blank">[email protected]</a>?subject=3Dhelp<br>OW2=
 mailing lists service home page: <a href=3D"http://www.ow2.org/wws" target=
=3D"_blank">http://www.ow2.org/wws</a><br></blockquote></div></div></div></=
blockquote></div>
</blockquote></div><br></blockquote></div></div></body></html>=

--=_6346791e-bc23-493b-b9b4-4eee6b465261--

------------=_1572567578-31803-12
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

------------=_1572567578-31803-12--