Re: Example for ConstantDynamic

Gunnar Morling <[email protected]> Thu, 31 Oct 2019 22:47:13 +0100
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <CADGJaX93LcJin=B9skoVq5Kk=c5ZseCRt2ZyNa26f7Qixocorw@mail.gmail.com>
This is a multi-part message in MIME format...

------------=_1572558449-31803-11
Content-Type: multipart/alternative; boundary="000000000000754db305963bcb0e"

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

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
happen as soon as the class is loaded. Is there any way to control or defer
this?

Thanks again,

--Gunnar

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


Am Do., 31. Okt. 2019 um 09:46 Uhr schrieb Gunnar Morling <
[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 <[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,
>> 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
>>
>>

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

<div dir=3D"ltr">Remi,<div><br></div>So I could generate a class with an ld=
c instruction that loads a dynamic constant. Nice!<div><br></div><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?<=
div><br></div><div>Thanks again,</div><div><br></div><div>--Gunnar<br><div>=
<br></div><div>PS: for future readers of this thread, the call to methodTyp=
e() is missing the class parameter before the int.class.</div></div><div><b=
r></div></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=
=3D"gmail_attr">Am Do., 31. Okt. 2019 um 09:46=C2=A0Uhr schrieb Gunnar Morl=
ing &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;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"l=
tr">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" class=3D"gmail_=
attr">Am Mi., 30. Okt. 2019 um 23:41=C2=A0Uhr schrieb Remi Forax &lt;<a hre=
f=3D"mailto:[email protected]" target=3D"_blank">[email protected]</a>&gt;:=
<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8=
ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style=
=3D"font-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>BSM is a Handle to a static method starting with a Lookup (a MethodHand=
les.Lookup), 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 <s=
pan>Handle</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></di=
v><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 looku=
p, String name, Class&lt;?&gt; type, int two) { ... }<br></div><div>}<br></=
div><div><br></div><div>note that the VM calls any boostrap method using Me=
thodHandle.invoke so any supertypes for the parameter types, any subtype fo=
r the return type, or any boxing/varargs will also work, by example<br></di=
v><div><div>class RT {</div><div>=C2=A0 public static String bsm(Lookup loo=
kup, Object 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></di=
v><hr id=3D"gmail-m_-4498365127723273330gmail-m_1809410738653198026zwchr"><=
div><blockquote style=3D"border-left:2px solid rgb(16,16,255);margin-left:5=
px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;t=
ext-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt">=
<b>De: </b>&quot;Gunnar Morling&quot; &lt;<a href=3D"mailto:gunnar@hibernat=
e.org" target=3D"_blank">[email protected]</a>&gt;<br><b>=C3=80: </b>&qu=
ot;asm&quot; &lt;<a href=3D"mailto:[email protected]" target=3D"_blank">[email protected]=
rg</a>&gt;<br><b>Envoy=C3=A9: </b>Mercredi 30 Octobre 2019 23:11:52<br><b>O=
bjet: </b>[asm] Example for ConstantDynamic<br></blockquote></div><div><blo=
ckquote style=3D"border-left:2px solid rgb(16,16,255);margin-left:5px;paddi=
ng-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-deco=
ration: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) reference (visitLdcInsn) using ASM? In particul=
ar I&#39;m unsure about linking it to the bootstrap method.</div><br><div>T=
hanks=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>
</blockquote></div>

--000000000000754db305963bcb0e--

------------=_1572558449-31803-11
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

------------=_1572558449-31803-11--