Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-core-dev] Generate invokedynamic

Hi Jesper,

I don’t think so. ObjectTeams extends method calls in a way, that is dependent on the semantics of the language.
As such, I targeted a very specific, narrow use case.

I extended the existing infrastructure. For example, instead of going with an _expression_ (i.e., FunctionalExpression) it is split into the Reference[1] and the MethodBinding.
In MessageSend::generateCode(*,*,*) ObjectTeams already changed how to generate code. There I generate the invokedynamic code when the receiver has the specific Reference type.
For the generation of the invokeDynamic instruction it also needs a class that defines the bootstrap methods. This one is directly specified by me in ClassFile::generateBootstrapMethods(*).

For this to be improved, it would probably need an InvokeDynamicExpression. Then it would still be interesting, how to couple the user-given bootstrap methods, that are required by invokedynamic as well as dynamic constant.
I could think of an extension of public int ClassFile::recordBootstrapMethod(FunctionalExpression) to become public int ClassFile::recordBootstrapMethod(DynamicExpression, ReferenceBinding bootstrapClass, char[] bootstrapSelector, char[] bootstrapSignature). The latter may be coupled into a MethodBinding? This could also improve the code of ClassFile:: generateBootstrapMethods(*) as the decision for the very bootstrapMethod can be moved out (here: MetaFactory vs AltMetaFactory). I did not look to deep into how FunctionalExpression gets assembled.
DynamicExpression will be a super class of FunctionalExpression and InvokeDynamicExpression, DynamicConstantExpression etc.

Everything is currently in the sealed git server of my chair. I’ll open source once finished but code quality will probably be below standards.

Cheers,
Lars



On 9. Nov 2018, at 09:56, Jesper Steen Møller <jesper@xxxxxxxxxxxxx> wrote:

Hi Lars and Stephan

Will this code be suitable for submitting back into the JDT compiler, as an improvement of the code structure around bootstrap methods? (I'm thinking in terms of internal support for generation of e.g. dynamic constants?)

Are there visible Git commits to review or consider?

-Jesper

On 9 Nov 2018, at 09.48, Lars Schuetze <lars.schuetze@xxxxxxxxxxxxx> wrote:

Hi Stephan,

You are right. Taking a step back and looking at the JVM spec yet again confirms your concerns.
It is able to handle int but just as a constant value that is already compiled into the code (constant_pool table) but not as a runtime argument from the stack.

I got it working now!
Thanks for your help Stephan and Jesper.

Cheers,
Lars

On 8. Nov 2018, at 16:22, Stephan Herrmann <stephan.herrmann@xxxxxxxxx> wrote:

Hi Lars,

can bootstrap methods handle primitive types (like int) to begin with?

Stephan

On 08.11.18 15:14, Lars Schuetze wrote:
Hi Jasper,
Thank you very much for pinpointing. I managed to exchange all relevant parts in the JDT compiler to come up with my solution for ObjectTeams.
I have extended the bootstrap generation and also the MessageSend is generated into an invokedynamic. It’s also not that pretty ;-)
However, I have a problem to generate the right class attributes. For u2 num_bootstrap_methods it says that there need to be a type attribute etc. for every argument to the bootstrap method. I was copying the approach taken for MetaFactory.
My bootstrap looks like (MethodType, String, MethodHandle, int, int)CallSite. So I need to add 2 bootstrap arguments. I tried something like
int idx = this.constantPool.literalIndexForType(TypeBinding.INT);
this.contents[localContentsOffset++] = (byte) (idx >> 8);
this.contents[localContentsOffset++] = (byte) idx;
But when running the code it says Exception in thread "main" java.lang.NoClassDefFoundError: I
The whole adaptions to generateBootstrapMethods can be seen https://gist.github.com/lschuetze/c97ff013a1a3b69c1cedecfdee7b688c
Your help is appreciated. I think I am still not understanding the whole picture of JVM spec, the JDT code generation and everything that is expected here.
Cheers,
Lars
Hi Lars

At the moment, both the invokedynamic call and the bootstrap code generation is part of lambda code generation, and has no API as such, since it's specific to LambdaMetafactory. For instance, the bootstrap methods are emitted inside org.eclipse.jdt.internal.compiler.ClassFile.generateBootstrapMethods(List). It's not that pretty.

In general, JDT's top priority is remaining compatible to JLS, so I wouldn't expect us making a language extension to call indy. However, at the (internal) API level, we could probably clean up the code generation a bit, and make the bootstrap and indy calls cleaner (especially now that we have the ConstantDynamic in Java 11, which could lead the way to a number of improvements in the generated code down the road.

Hope that it explains the current situation.

-Jesper

-- 

On 8 Oct 2018, at 12.52, Lars Schuetze <lars.schuetze@xxxxxxxxxxxxx <mailto:lars.schuetze@xxxxxxxxxxxxx>> wrote:

Hello developers,

I was already posting to the Object Teams development mailing list [1], but got no reaction after reasonable time, so because of the similar topic I also post here. Thanks, for your understanding.

I am working with the JDT core version as of Photon branch R4_8_maintenance. I have a runtime which implements a bootstrap method (static CallSite bootstrap(â)) to be used in conjunction with invokedynamic.
ObjectTeams is an extension that is deeply coupled and intermingled with the EJC and also has specific changes to the JDT core plugin. I worked already all my changes into the compiler.
However, it currently just calls the bootstrap method as static method. I want it to be treated as invokedynamic callsite. Looking into the JDT how such a callsite is created (i.e., in CodeStream class etc) I just find references w.r.t. lambdas.

Is there any facility in the JDT already in place to create invokedynamic callsites? Maybe you can point me to the right JDT API to generate an invokedynamic from the MessageSend?

Best regards,
Lars SchÃtze

[1] https://www.eclipse.org/lists/objectteams-dev/msg00021.html

- -
M.Sc. Lars SchÃtze
Research Assistant

Technische UniversitÃt Dresden
Chair for Compiler Construction
Helmholtzstrasse 18, 01069 Dresden, BAR III57
www: https://cfaed.tu-dresden.de/ccc-staff-schuetze
www: https://wwwdb.inf.tu-dresden.de/grk/team/lars-schuetze/
Mail: lars.schuetze@xxxxxxxxxxxxx <mailto:lars.schuetze@xxxxxxxxxxxxx>
Phone: +49 (351) 463-43733
Fax: +49 (351) 463-39995

_______________________________________________
jdt-core-dev mailing list
jdt-core-dev@xxxxxxxxxxx <mailto:jdt-core-dev@xxxxxxxxxxx>
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jdt-core-dev

_______________________________________________
jdt-core-dev mailing list
jdt-core-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jdt-core-dev

_______________________________________________
jdt-core-dev mailing list
jdt-core-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jdt-core-dev

_______________________________________________
jdt-core-dev mailing list
jdt-core-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jdt-core-dev

Attachment: smime.p7s
Description: S/MIME cryptographic signature


Back to the top