Re: Example for ConstantDynamic

Gunnar Morling <[email protected]> Thu, 31 Oct 2019 09:46:04 +0100
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <CADGJaX_c56C8PP2JPmFyMmdM_W+Lhx07gK+n7gLZUzRGd9hFow@mail.gmail.com>
This is a multi-part message in MIME format...

------------=_1572511579-31803-1
Content-Type: multipart/alternative; boundary="000000000000e7c76a059630e17a"

--000000000000e7c76a059630e17a
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

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 <[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 t=
he
> 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,
> 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,
> Object two) { ... }
> }
>
> R=C3=A9mi
>
> ------------------------------
>
> *De: *"Gunnar Morling" <[email protected]>
> *=C3=80: *"asm" <[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 ConstantDynamic
> (JEP 309) reference (visitLdcInsn) using ASM? In particular I'm unsure
> about linking it to the bootstrap method.
>
> Thanks for any pointers,
>
> --Gunnar
>
>
>
> --
> 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
>
>

--000000000000e7c76a059630e17a
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Remi,<div><br></div><div>Thanks for the super-fast reply. =
I&#39;ll play with that.</div><div><br></div><div>--Gunnar</div><div><br></=
div><div><br></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" cl=
ass=3D"gmail_attr">Am Mi., 30. Okt. 2019 um 23:41=C2=A0Uhr schrieb Remi For=
ax &lt;<a href=3D"mailto:[email protected]">[email protected]</a>&gt;:<br><=
/div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bo=
rder-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style=3D"f=
ont-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)"><div=
>Hi Gunnar,</div><div>with a LDC on a constant dynamic<br></div><div>=C2=A0=
 mv.visitLdc(<span>new</span> <span>ConstantDynamic</span>(&quot;name&quot;=
, &quot;Ljava/lang/Object;&quot;, BSM, 2));<br></div><div><br></div><div>BS=
M is a Handle to a static method starting with a Lookup (a MethodHandles.Lo=
okup), a String (here &quot;name&quot;), 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>=C2=A0 so <span>Ha=
ndle</span> BSM =3D <span>new Handle(Opcodes.H_INVOKESTATIC, &quot;RT&quot;=
, &quot;bsm&quot;, MethodType.methodType(Object.class, Lookup.class, String=
.class, int.class).toMethodDescriptorString(), false);</span><br></div><div=
><br></div><div>so the method bsm inside the class RT can be<br></div><div>=
class RT {<br></div><div>=C2=A0 public static Object bsm(Lookup lookup, Str=
ing name, Class&lt;?&gt; type, int two) { ... }<br></div><div>}<br></div><d=
iv><br></div><div>note that the VM calls any boostrap method using MethodHa=
ndle.invoke so any supertypes for the parameter types, any subtype for the =
return type, or any boxing/varargs will also work, by example<br></div><div=
><div>class RT {</div><div>=C2=A0 public static String bsm(Lookup lookup, O=
bject name, Class&lt;?&gt; type, Object two) { ... }</div><div>}</div><div>=
<br></div></div><div>R=C3=A9mi<span></span></div><div>=C2=A0 <br></div><hr =
id=3D"gmail-m_1809410738653198026zwchr"><div><blockquote style=3D"border-le=
ft:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,=
0);font-weight:normal;font-style:normal;text-decoration:none;font-family:He=
lvetica,Arial,sans-serif;font-size:12pt"><b>De: </b>&quot;Gunnar Morling&qu=
ot; &lt;<a href=3D"mailto:[email protected]" target=3D"_blank">gunnar@hi=
bernate.org</a>&gt;<br><b>=C3=80: </b>&quot;asm&quot; &lt;<a href=3D"mailto=
:[email protected]" target=3D"_blank">[email protected]</a>&gt;<br><b>Envoy=C3=A9: </b>=
Mercredi 30 Octobre 2019 23:11:52<br><b>Objet: </b>[asm] Example for Consta=
ntDynamic<br></blockquote></div><div><blockquote style=3D"border-left:2px s=
olid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-=
weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,=
Arial,sans-serif;font-size:12pt"><div dir=3D"ltr">Hi,<br><div>Is there any =
simple yet complete example of producing a ConstantDynamic (JEP 309) refere=
nce (visitLdcInsn) using ASM? In particular I&#39;m unsure about linking it=
 to the bootstrap method.</div><br><div>Thanks=C2=A0for 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>

--000000000000e7c76a059630e17a--

------------=_1572511579-31803-1
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

------------=_1572511579-31803-1--