Lifting operations from inline classes to reference projections
Remi Forax
forax at univ-mlv.fr
Mon Dec 16 15:00:08 UTC 2019
----- Mail original -----
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Maurizio Cimadamore" <maurizio.cimadamore at oracle.com>, "valhalla-spec-experts"
> <valhalla-spec-experts at openjdk.java.net>
> Envoyé: Lundi 16 Décembre 2019 15:27:59
> Objet: Re: Lifting operations from inline classes to reference projections
>>
>> I'm not too worried about having a V.ref with its own members - after
>> all, V.ref should be a language fiction (for the VM, the only real
>> thing is V). So, in my mental model, it will be javac, not the VM, to
>> do most of the lifting here. Am I wrong in my assumption?
>
> The VM team has expressed a preference that these members not be
> duplicated, so we're exploring alternatives. One alternative that has
> been suggested is: if X is a reference projection of V, then
> `invokeinterface X.m()`, be adjusted to look for members on V. (Some
> adjustments would be made to the resolution for the case of private
> implementations, where the access check would be relaxed on the
> implementation _class_ but not the _member_. This sidesteps the problem
> with the obvious solution (interface methods on V.ref) having to do with
> non-public methods.)
I don't think that private implementation is a real issue.
Let say when have an inline type HashEntry,
public class HashMap<K,V> {
private static inline class HashEntry<K,V> implements Map.Entry<K, V> {
private K key;
private V value;
public K getKey() { return key; }
...
}
...
}
now if we introduce a public HashEntry.ref, we have
public class HashMap<K,V> {
private static inline class HashEntry<K,V> implements Map.Entry<K, V>, HashEntry.ref<K,V> {
private K key;
private V value;
public K getKey() { return key; }
...
}
public interface HashEntry.ref<K,V> extends Map.Entry<K, V> {
// empty
}
...
}
>From outside HashMap, HashEntry.ref<String,String>.key is not valid, but that's expected,
HashEntry.ref<String,String>.getKey() is accessible because a ref has the same set of interfaces as the corresponding inline type and this is how public methods are getting exposed.
Rémi
More information about the valhalla-spec-experts
mailing list