--- old/src/java.base/share/classes/java/lang/Class.java 2019-05-15 13:57:33.791686212 -0400 +++ new/src/java.base/share/classes/java/lang/Class.java 2019-05-15 13:57:33.423684387 -0400 @@ -62,8 +62,6 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.StringJoiner; -import java.util.stream.Stream; import java.util.stream.Collectors; import jdk.internal.HotSpotIntrinsicCandidate; @@ -197,9 +195,9 @@ * @return a string representation of this class object. */ public String toString() { - return (isValue() ? "inline " : "") + return (isInlineClass() ? "inline " : "") + (isInterface() ? "interface " : (isPrimitive() ? "" : "class ")) - + getName() + (isValue() && isBoxType() ? "?" : ""); + + getName() + (isInlineClass() && isNullableType() ? "?" : ""); } /** @@ -260,7 +258,7 @@ if (isAnnotation()) { sb.append('@'); } - if (isValue()) { + if (isInlineClass()) { sb.append("value"); sb.append(' '); } @@ -362,10 +360,6 @@ *

If {@code name} denotes an array class, the component type of * the array class is loaded but not initialized. * - *

If {@code name} denotes a value class, this method returns - * the {@code Class} object representing the - * {@linkplain #asBoxType() box value type}. - * *

For example, in an instance method the expression: * *

@@ -446,10 +440,6 @@ * the given name is a class defined in a different module, this method * returns {@code null} after the class is loaded.

* - *

If {@code name} denotes a value class, this method returns - * the {@code Class} object representing the - * {@linkplain #asBoxType() box value type}.

- * *

This method does not check whether the requested class is * accessible to its caller.

* @@ -512,11 +502,11 @@ /** - * Returns {@code true} if this class is a value class. + * Returns {@code true} if this class is an inline class. * - * @return {@code true} if this class is a value class. + * @return {@code true} if this class is an inline class. */ - public boolean isValue() { + public boolean isInlineClass() { int mods = this.getModifiers(); if ((mods & VALUE_TYPE) != 0) { if ((mods & (Modifier.INTERFACE | Modifier.ABSTRACT)) != 0) { @@ -531,51 +521,56 @@ } /** - * Returns a {@code Class} object representing the box type - * of this class if this class is a {@linkplain #isValue() value class}; + * Returns a {@code Class} object representing the nullable-projection + * type if this class is an {@linkplain #isInlineClass() inline class}; * otherwise, returns this class. * - *

A value class has two {@code Class} representations, - * a null-free type or a nullable box type, that can be obtained - * by calling {@link #asValueType()} or {@link #asBoxType()} method - * for conversion. + *

An inline class has two {@code Class} representations, + * the zero-default inline class and the nullable-projection type + * that can be obtained by calling {@link #asPrimaryType()} or + * {@link #asNullableType()} method respectively. * - * @return the box type of this class if this class is a value class; - * otherwise, this class. + * @return the {@code Class} object representing the nullable-projection of + * this class if this class is an inline class; otherwise, this class. */ @HotSpotIntrinsicCandidate - public Class asBoxType() { - return isValue() ? boxType : this; + public Class asNullableType() { + return isInlineClass() ? nullableType : this; } /** - * Returns a {@code Class} object representing the null-free value type - * of this class if this class is a {@linkplain #isValue() value class}; - * otherwise, returns {@code null}. + * Returns a {@code Class} object representing this zero-default + * inline class if this class is an {@linkplain #isInlineClass() inline class}; + * otherwise, returns this class. * - *

A value class has two {@code Class} representations, - * a null-free type or a nullable box type, that can be obtained - * by calling {@link #asValueType()} or {@link #asBoxType()} method - * for conversion. + *

An inline class has two {@code Class} representations, + * the zero-default inline class and the nullable-projection type + * that can be obtained by calling {@link #asPrimaryType()} or + * {@link #asNullableType()} method respectively. * - * @return the unbox value type of this class if this class is a value class; - * otherwise, {@code null}. + * @return the {@code Class} object representing the zero-default inline class + * if this class is an inline class; otherwise, this class. */ @HotSpotIntrinsicCandidate - public Class asValueType() { - return isValue() ? valueType : null; + public Class asPrimaryType() { + return isInlineClass() ? inlineType : this; } - /* - * Returns true if this class is a non-value class or a box value class. + /** + * Returns {@code true} if this class is a nullable type. A nullable type + * can be a reference class or interface and + * a {@linkplain #asNullableType nullable-projection type}. + * + * @return {@code true} if this class is a nullable type. */ - boolean isBoxType() { - return boxType == null || this == boxType; + public boolean isNullableType() { + return nullableType == null || this == nullableType; } - // set by VM if this class is a value type - private transient Class boxType; - private transient Class valueType; + // set by VM if this class is an inline type + // otherwise, these two fields are null + private transient Class inlineType; + private transient Class nullableType; /** * Creates a new instance of the class represented by this {@code Class} @@ -635,7 +630,7 @@ public T newInstance() throws InstantiationException, IllegalAccessException { - if (this.isValue()) { + if (this.isInlineClass()) { throw new IllegalAccessException( "cannot create new instance of an inline class " + this.getName()); } @@ -855,7 +850,7 @@ * char C * class or interface * Lclassname; - * {@linkplain #asValueType() regular value class} + * {@linkplain #asPrimaryType() inline class} * Qclassname; * double D * float F @@ -875,11 +870,13 @@ * byte.class.getName() * returns "byte" * Point.class.getName() - * returns "p.Point" + * returns "Point" * (new Object[3]).getClass().getName() * returns "[Ljava.lang.Object;" * (new Point[3]).getClass().getName() * returns "[QPoint;" + * (new Point?[3][4]).getClass().getName() + * returns "[[LPoint;" * (new int[3][4][5][6][7][8][9]).getClass().getName() * returns "[[[[[[[I" *

@@ -1298,7 +1295,7 @@ * @since 1.1 */ public Object[] getSigners() { - Class c = (isValue() && !isBoxType()) ? asBoxType() : this; + Class c = isInlineClass() && isNullableType() ? asPrimaryType() : this; return c.getSigners0(); } @@ -1308,7 +1305,7 @@ * Set the signers of this class. */ void setSigners(Object[] signers) { - Class c = (isValue() && !isBoxType()) ? asBoxType() : this; + Class c = isInlineClass() && isNullableType() ? asPrimaryType() : this; c.setSigners0(signers); } @@ -1650,9 +1647,6 @@ * component type with "[]" appended. In particular the simple * name of an array whose component type is anonymous is "[]". * - *

The simple name of a value type is the simple name of - * this class with {@code ".box"} appended. - * * @return the simple name of the underlying class * @since 1.5 */ @@ -1674,7 +1668,7 @@ simpleName = getName(); simpleName = simpleName.substring(simpleName.lastIndexOf('.') + 1); // strip the package name } - return isValue() && isBoxType() ? simpleName + ".box" : simpleName; + return simpleName; } /** @@ -1700,8 +1694,7 @@ return sb.toString(); } catch (Throwable e) { /*FALLTHRU*/ } } - // ## append "/box" to box value type instead? - return isBoxType() ? getName() : getName() + "/val"; + return toTypeName(); } /** @@ -3526,13 +3519,21 @@ sb.append(getName() + "." + name + "("); if (argTypes != null) { sb.append(Arrays.stream(argTypes) - .map(c -> (c == null) ? "null" : c.getName()) + .map(c -> (c == null) ? "null" : c.toTypeName()) .collect(Collectors.joining(","))); } sb.append(")"); return sb.toString(); } + /* + * Returns the class name appended with "?" if it is the nullable projection + * of an inline class. + */ + private String toTypeName() { + return isInlineClass() && isNullableType() ? getName() + "?" : getName(); + } + /** use serialVersionUID from JDK 1.1 for interoperability */ private static final long serialVersionUID = 3206093459760846163L; @@ -3707,16 +3708,16 @@ * * @throws ClassCastException if the object is not * {@code null} and is not assignable to the type T. - * @throws NullPointerException if this class is a {@linkplain #asValueType() - * null-free value class} and the object is {@code null} + * @throws NullPointerException if this class is an {@linkplain #asPrimaryType() + * inline class} and the object is {@code null} * * @since 1.5 */ @SuppressWarnings("unchecked") @HotSpotIntrinsicCandidate public T cast(Object obj) { - if (isValue() && !isBoxType() && obj == null) - throw new NullPointerException(getName() + " is non-nullable value class"); + if (isInlineClass() && !isNullableType() && obj == null) + throw new NullPointerException(getName() + " is an inline class"); if (obj != null && !isInstance(obj)) throw new ClassCastException(cannotCastMsg(obj));