Fwd: Annotation extension with CONDYN

Brian Goetz brian.goetz at oracle.com
Mon Sep 30 20:17:59 UTC 2019


Received on the -comments list (quite a long time ago; caught in the 
grease traps.)  More appropriate for amber-dev, so answering there.

The short answer is that yes, expanding the set of classfile constants 
also potentially expands the set of annotation properties, but the 
former expansion is a necessary-but-not-sufficient condition -- not 
everything that can be expressed in the constant pool makes sense to 
express as an annotation property.  (In the limiting case, condy allows 
us to put mutable objects in the CP (though this would be foolish to 
actually do); we don't want to open this door at the language level.  
Condy is a low-level tool for compiler writers, but it may expose 
opportunities for langauge improvements.)

One obvious candidate for exposing more interesting constants in 
annotations is _method references_ (of the static/unbound variety.)  
THis is a much more sensible match than method handles, which are a 
low-level mechanism (again, intended more for compiler and framework 
writers than for user code.)

As we expand the set of things you can put in the constant pool, this 
becomes an opportunity to expand what can be considered a compile-time 
constant in the language.

I mostly disagree with the "but this doesn't raise a problem because..." 
argumentation; I think this is the sort of deal-with-the-devil people 
are willing to make when they're in pain, that they regret later.  
(Method refs don't have this problem.)


-------- Forwarded Message --------
Subject: 	Annotation extension with CONDYN
Date: 	Sat, 24 Nov 2018 20:13:20 +0100
From: 	Jeremy Barrow <jeremy.a.barrow at gmail.com>
To: 	amber-spec-comments at openjdk.java.net



Hey everyone,
As I was working on something relating to annotations,
I realised we still use the typical pattern of using a class or some other
constant to refer to specific functionality.
With things like MethodHandles and a lot more recently CON DYN surely it's
possible to embed a lot more into an annotation?
Is there any specific technical restriction, because I would love being
able to do something like:
https://gist.github.com/Jezza/7d5bedaadbe3adcb65bb6e4981de9901

Right now we have to do something like:
@Annotation("onBefore"), and then do the necessary things behind the scenes.
This does raise questions such as being able to enforce signatures, etc,
but I don't think that's a problem as it's no different to what it was
before, and it's effectively the same as, say, accepting a MethodHandle as
a parameter.

Cheers,
Jeremy.


More information about the amber-dev mailing list