OpenJDK / valhalla / valhalla
changeset 52836:60b15b8cbfd9 lworld
8213173 : [lworld] Add light weight box support for to model nullable value types.
author | sadayapalam |
---|---|
date | Tue, 20 Nov 2018 10:47:35 +0530 |
parents | 221983ae9e6b |
children | 4aba8143588e |
files | src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java |
diffstat | 4 files changed, 50 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java Tue Oct 30 15:43:00 2018 +0530 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java Tue Nov 20 10:47:35 2018 +0530 @@ -317,6 +317,12 @@ throw new AssertionError(); } + /** Define a light weight nullable box type. Make sense only for for a value type. + */ + public Type loxType() { + throw new AssertionError(); + } + /** * If this is a constant type, return its underlying type. * Otherwise, return the type itself. @@ -331,7 +337,13 @@ * it should not be used outside this class. */ protected Type typeNoMetadata() { - return metadata == TypeMetadata.EMPTY ? this : baseType(); + Type t = metadata == TypeMetadata.EMPTY ? this : baseType(); + if (t.hasTag(CLASS)) { + ClassType ct = (ClassType) t; + if (ct.loxType != null && ct.loxType.tsym.isValue()) + return ct.loxType; + } + return t; } /** @@ -961,6 +973,12 @@ */ public List<Type> all_interfaces_field; + /** The light weight box type for this type - make sense only for value types + * Perhaps this field should be elided by having this maintained in a side + * data structure + * */ + private ClassType loxType; + public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) { this(outer, typarams, tsym, TypeMetadata.EMPTY); } @@ -1007,6 +1025,22 @@ }; } + public Type loxType() { + Assert.check(tsym.isValue()); + if (loxType == null) { + loxType = new ClassType(outer_field, typarams_field, null); + loxType.allparams_field = this.allparams_field; + loxType.supertype_field = this.supertype_field; + loxType.interfaces_field = this.interfaces_field; + loxType.all_interfaces_field = this.all_interfaces_field; + ClassSymbol ts = new ClassSymbol((tsym.flags() & ~VALUE), tsym.name, loxType, tsym.owner); + ts.members_field = tsym.members(); + loxType.tsym = ts; + loxType.loxType = this; + } + return loxType; + } + /** The Java source which this type represents. */ @DefinedBy(Api.LANGUAGE_MODEL)
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Oct 30 15:43:00 2018 +0530 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Nov 20 10:47:35 2018 +0530 @@ -2171,6 +2171,16 @@ : new AccessError(env, site, sym); } } + + if (c.isValue() && site.tsym == c) { + if (name == names.val) { + return c; + } + if (name == names.box) { + return site.loxType().tsym; + } + } + return typeNotFound; }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java Tue Oct 30 15:43:00 2018 +0530 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java Tue Nov 20 10:47:35 2018 +0530 @@ -2141,7 +2141,7 @@ if (!tree.clazz.type.isPrimitive() && !types.isSameType(tree.expr.type, tree.clazz.type) && types.asSuper(tree.expr.type, tree.clazz.type.tsym) == null) { - code.emitop2(checkcast, makeRef(tree.pos(), tree.clazz.type)); + code.emitop2(checkcast, makeRef(tree.pos(), tree.clazz.type, types.emitQtypes && types.isValue(tree.clazz.type))); } }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java Tue Oct 30 15:43:00 2018 +0530 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java Tue Nov 20 10:47:35 2018 +0530 @@ -197,6 +197,8 @@ public final Name module_info; public final Name package_info; public final Name requireNonNull; + public final Name box; + public final Name val; // lambda-related public final Name lambda; @@ -369,6 +371,8 @@ module_info = fromString("module-info"); package_info = fromString("package-info"); requireNonNull = fromString("requireNonNull"); + box = fromString("box"); + val = fromString("val"); //lambda-related lambda = fromString("lambda$");