reducing the number of methods annotated with @TrackableConstant

Vicente Romero vicente.romero at
Fri Aug 25 13:33:58 UTC 2017

On 08/25/2017 09:04 AM, Brian Goetz wrote:
> What is the underlying concern that is motivating this proposal?

code like:

final? int zero = (int) Intrinsics.ldc(defaultCondy);

will widen the interaction surface between constables (condy in this 
case) and primitive. The compiler would need to track the use of 
variable 'zero' in all possible places where an integer can appear. By 
default the compiler will try to fold it's internal value, if present, 
with other literals or variables. As long as the real value of 'zero' is 
not known till execution time, this means that we will have to disallow 
any intent to fold 'zero' with any other 'constant'. Adding to the 
picture that @TrackableConstant already forces the compiler to track 
other primitives and Strings, this implies adding special code to detect 
when is save and when it is not safe to access the value of the 
constant. I think that this extra effort to just track, for example, a 
descriptor (String) just in case the user decides to write code like:

         ClassRef c2 = ClassRef.of("Ljava/lang/String;");
         Class<?> c3 = ldc(ClassRef.of("" + c2.descriptorString()));  // 
method descriptorString() is annotated with @TrackableConstant

is unnecessary. I'm just trying to simplify the model. My feeling is 
that we will need a better story to track constants or another option: 
we will have to drop the decision of allowing effectively final 
constables to behave as a constant. This is the reason why we have in 
constant folding an infrastructure to track the subexpressions appearing 
in the initialization of a constant. This means that there are first 
class and second class constants as this tracking is done only for 
constables. So I think we should have only a class of constants we 
should do the same for all. But implementing the tracking for all 
constants will imply some overhead to the compiler plus it will need an 
update of the JLS. This is probably the most important underlying 
concern I have about the treatment of constants in the constant folding 
/ condy project.

> On 8/24/2017 11:13 PM, Vicente Romero wrote:
>> Hi,
>> I propose reducing the number of methods annotated with the 
>> @TrackableConstant annotation in the current Constables API. Actually 
>> reducing the number of them should be a consequence of reducing the 
>> applicability of the annotation. Annotating methods that return 
>> primitive types or Strings adds more overhead to the compiler but, 
>> IMO, it adds little value to the API and developers. My suggestion is 
>> that if a method returns a Constable type, or at most an array of a 
>> Constable type, then it could be annotated with @TrackableConstant 
>> and remove it from all other cases.
>> Comments?
>> Vicente

More information about the amber-dev mailing list