hg: valhalla/valhalla/langtools: Add experimental support for generic class literals

Remi Forax forax at univ-mlv.fr
Mon Aug 18 14:48:02 UTC 2014


On 08/18/2014 04:22 PM, Paul Benedict wrote:
> I do find it interesting the specialization is activated by the
> parametrized type, not the class itself. I suppose you could do something
> like MyClass<any X, Y> where only some parameters are specialized, but not
> quite sure why you would.

specialization, at least at current state, is just a glorified 
query/replace on the bytecode,
the specializer replace all occurence of X with the primitive type 
argument so
it make sense to have it on a type variable basis.

>   Bikeshedding: could this hint at the keyword
> should really belong at the class level than the type level?

each keyword 'any' cost you space (if every specialization is 
instantiated at runtime),
by example if you have Pair<any A, any B>, you can generate a lot of 
combination (A x B),
while Pair<A, any B>  can only generate the combination (B).

Note that it's not clear now that we need different specialization for 
byte/char/short,
if we have a way to separate at the JDK/VM level the declaration of 
fields and the declaration of methods.
Futhermore, if a method doesn't use ==/!=, int and float (resp. long and 
double) can share the same
implementation (basically one for 32 bits and one for 64 bits).

So the real number of variation is not clear yet (at least for me) but
each time you use 'any', you request for more specializations.

>
>
> Cheers,
> Paul

cheers,
Rémi

>
>
> On Mon, Aug 18, 2014 at 9:07 AM, Maurizio Cimadamore <
> maurizio.cimadamore at oracle.com> wrote:
>
>> On 18/08/14 14:51, Paul Benedict wrote:
>>
>> Just asking so I can understand.... are specialized classes fully
>> reifiable?
>>
>> Yeah - stuff like Box<int> is considered to be fully reified, as the
>> specializer will turn it into a specialized Box${T=int} version where all
>> references to the type-variables have been replaced with their 'I'
>> counterparts. This means you can lift all restrictions that apply to
>> reified types, such as no array creation, no instance of, unchecked cast
>> only, no class literals.
>>
>> Maurizio
>>
>>
>>
>> Cheers,
>> Paul
>>
>>
>> On Mon, Aug 18, 2014 at 8:29 AM, <maurizio.cimadamore at oracle.com> wrote:
>>
>>> Changeset: 459f251550d5
>>> Author:    mcimadamore
>>> Date:      2014-08-18 14:25 +0100
>>> URL:
>>> http://hg.openjdk.java.net/valhalla/valhalla/langtools/rev/459f251550d5
>>>
>>> Add experimental support for generic class literals
>>> *) Now fully specialized classes literals are allowed with no warnings.
>>> *) Specializable but not reifiable class literals are allowed with
>>> warnings.
>>> *) Non-specializable class literals rejected.
>>> *) Add new tests
>>>
>>> ! src/share/classes/com/sun/tools/javac/comp/Attr.java
>>> ! src/share/classes/com/sun/tools/javac/comp/Lower.java
>>> ! src/share/classes/com/sun/tools/javac/comp/SpecializeTypes.java
>>> ! src/share/classes/com/sun/tools/javac/jvm/Gen.java
>>> ! src/share/classes/com/sun/tools/javac/parser/JavacParser.java
>>> ! src/share/classes/com/sun/tools/javac/resources/compiler.properties
>>> ! src/share/classes/com/sun/tools/javac/tree/JCTree.java
>>> + test/tools/javac/diags/examples/IllegalGenericTypeForClassLit.java
>>> + test/tools/javac/diags/examples/UncheckedGenericClassLit.java
>>> ! test/tools/javac/failover/CheckAttributedTree.java
>>> + test/tools/javac/valhalla/typespec/ClassLiterals01.java
>>> + test/tools/javac/valhalla/typespec/ClassLiterals01.out
>>> ! test/tools/javac/valhalla/typespec/items/Opcodes.java
>>> + test/tools/javac/valhalla/typespec/items/tests/TestClassLit.java
>>>
>>>
>>



More information about the valhalla-dev mailing list