changeset 53727:56be324d844d lworld

[lworld] replace MemberName::canBeNull with MemberName::isValue to represent null-free value field
author mchung
date Mon, 14 Jan 2019 11:53:52 -0800
parents c0b051ccd97d
children 2e0d2eda25c1
files src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java src/java.base/share/classes/java/lang/invoke/GenerateJLIClassesHelper.java src/java.base/share/classes/java/lang/invoke/MemberName.java src/java.base/share/classes/java/lang/invoke/VarHandles.java src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template
diffstat 5 files changed, 38 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java	Mon Jan 14 17:45:15 2019 +0530
+++ b/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java	Mon Jan 14 11:53:52 2019 -0800
@@ -111,13 +111,13 @@
             if (member.isStatic()) {
                 long offset = MethodHandleNatives.staticFieldOffset(member);
                 Object base = MethodHandleNatives.staticFieldBase(member);
-                return member.canBeNull() ? new StaticAccessor(mtype, lform, member, base, offset)
-                                          : new StaticValueAccessor(mtype, lform, member, base, offset);
+                return member.isValue() ? new StaticValueAccessor(mtype, lform, member, base, offset)
+                                        : new StaticAccessor(mtype, lform, member, base, offset);
             } else {
                 long offset = MethodHandleNatives.objectFieldOffset(member);
                 assert(offset == (int)offset);
-                return  member.canBeNull() ? new Accessor(mtype, lform, member, (int)offset)
-                                           : new ValueAccessor(mtype, lform, member, (int)offset);
+                return  member.isValue() ? new ValueAccessor(mtype, lform, member, (int)offset)
+                                         : new Accessor(mtype, lform, member, (int)offset);
 
             }
         }
@@ -640,14 +640,14 @@
     @Stable
     private static final LambdaForm[] ACCESSOR_FORMS
             = new LambdaForm[afIndex(AF_LIMIT, false, false, 0)];
-    static int ftypeKind(Class<?> ftype, boolean canBeNull) {
+    static int ftypeKind(Class<?> ftype, boolean isValue) {
         if (ftype.isPrimitive())
             return Wrapper.forPrimitiveType(ftype).ordinal();
         else if (VerifyType.isNullReferenceConversion(Object.class, ftype)) {
             return FT_UNCHECKED_REF;
         } else
             // null check for value type in addition to check cast
-            return canBeNull ? FT_CHECKED_REF : FT_CHECKED_VALUE;
+            return isValue ? FT_CHECKED_VALUE : FT_CHECKED_REF;
     }
 
     /**
@@ -657,9 +657,6 @@
      */
     private static LambdaForm preparedFieldLambdaForm(MemberName m) {
         Class<?> ftype = m.getFieldType();
-        boolean isVolatile = m.isVolatile();
-        boolean isFlatValue = m.isFlattened();
-        boolean canBeNull = m.canBeNull();
         byte formOp;
         switch (m.getReferenceKind()) {
         case REF_getField:      formOp = AF_GETFIELD;    break;
@@ -670,12 +667,12 @@
         }
         if (shouldBeInitialized(m)) {
             // precompute the barrier-free version:
-            preparedFieldLambdaForm(formOp, isVolatile, isFlatValue , canBeNull, ftype);
+            preparedFieldLambdaForm(formOp, m.isVolatile(), m.isValue(), m.isFlattened(), ftype);
             assert((AF_GETSTATIC_INIT - AF_GETSTATIC) ==
                    (AF_PUTSTATIC_INIT - AF_PUTSTATIC));
             formOp += (AF_GETSTATIC_INIT - AF_GETSTATIC);
         }
-        LambdaForm lform = preparedFieldLambdaForm(formOp, isVolatile, isFlatValue , canBeNull, ftype);
+        LambdaForm lform = preparedFieldLambdaForm(formOp, m.isVolatile(), m.isValue(), m.isFlattened(), ftype);
         maybeCompile(lform, m);
         assert(lform.methodType().dropParameterTypes(0, 1)
                 .equals(m.getInvocationType().basicType()))
@@ -683,12 +680,12 @@
         return lform;
     }
 
-    private static LambdaForm preparedFieldLambdaForm(byte formOp, boolean isVolatile, boolean isFlatValue, boolean canBeNull, Class<?> ftype) {
-        int ftypeKind = ftypeKind(ftype, canBeNull);
+    private static LambdaForm preparedFieldLambdaForm(byte formOp, boolean isVolatile, boolean isValue, boolean isFlatValue, Class<?> ftype) {
+        int ftypeKind = ftypeKind(ftype, isValue);
         int afIndex = afIndex(formOp, isVolatile, isFlatValue, ftypeKind);
         LambdaForm lform = ACCESSOR_FORMS[afIndex];
         if (lform != null)  return lform;
-        lform = makePreparedFieldLambdaForm(formOp, isVolatile, isFlatValue, ftypeKind);
+        lform = makePreparedFieldLambdaForm(formOp, isVolatile, isValue, isFlatValue, ftypeKind);
         ACCESSOR_FORMS[afIndex] = lform;  // don't bother with a CAS
         return lform;
     }
@@ -752,25 +749,31 @@
         throw new AssertionError("Invalid arguments");
     }
 
-    static LambdaForm makePreparedFieldLambdaForm(byte formOp, boolean isVolatile, boolean isFlatValue, int ftypeKind) {
+    /** invoked by GenerateJLIClassesHelper */
+    static LambdaForm makePreparedFieldLambdaForm(byte formOp, boolean isVolatile, int ftype) {
+        return makePreparedFieldLambdaForm(formOp, isVolatile, false, false, ftype);
+    }
+
+    private static LambdaForm makePreparedFieldLambdaForm(byte formOp, boolean isVolatile, boolean isValue, boolean isFlatValue, int ftypeKind) {
         boolean isGetter  = (formOp & 1) == (AF_GETFIELD & 1);
         boolean isStatic  = (formOp >= AF_GETSTATIC);
         boolean needsInit = (formOp >= AF_GETSTATIC_INIT);
         boolean needsCast = (ftypeKind == FT_CHECKED_REF || ftypeKind == FT_CHECKED_VALUE);
         Wrapper fw = (needsCast ? Wrapper.OBJECT : ALL_WRAPPERS[ftypeKind]);
         Class<?> ft = fw.primitiveType();
-        assert(needsCast ? true : ftypeKind(ft, ftypeKind != FT_CHECKED_VALUE) == ftypeKind);
+        assert(needsCast ? true : ftypeKind(ft, isValue) == ftypeKind);
 
         // getObject, putIntVolatile, etc.
         Kind kind = getFieldKind(isGetter, isVolatile, isFlatValue, fw);
 
         MethodType linkerType;
-        if (isFlatValue) {
-            linkerType = isGetter ? MethodType.methodType(ft, Object.class, long.class, Class.class)
-                                  : MethodType.methodType(void.class, Object.class, long.class, Class.class, ft);
+        boolean hasValueTypeArg = isGetter ? isValue : isFlatValue;
+        if (isGetter) {
+            linkerType = isValue ? MethodType.methodType(ft, Object.class, long.class, Class.class)
+                                 : MethodType.methodType(ft, Object.class, long.class);
         } else {
-            linkerType = isGetter ? MethodType.methodType(ft, Object.class, long.class)
-                                  : MethodType.methodType(void.class, Object.class, long.class, ft);
+            linkerType = isFlatValue ? MethodType.methodType(void.class, Object.class, long.class, Class.class, ft)
+                                     : MethodType.methodType(void.class, Object.class, long.class, ft);
         }
         MemberName linker = new MemberName(Unsafe.class, kind.methodName, linkerType, REF_invokeVirtual);
         try {
@@ -801,7 +804,7 @@
         final int OBJ_CHECK = (OBJ_BASE >= 0 ? nameCursor++ : -1);
         final int U_HOLDER  = nameCursor++;  // UNSAFE holder
         final int INIT_BAR  = (needsInit ? nameCursor++ : -1);
-        final int VALUE_TYPE = (isFlatValue ? nameCursor++ : -1);
+        final int VALUE_TYPE = (hasValueTypeArg ? nameCursor++ : -1);
         final int PRE_CAST  = (needsCast && !isGetter ? nameCursor++ : -1);
         final int LINKER_CALL = nameCursor++;
         final int POST_CAST = (needsCast && isGetter ? nameCursor++ : -1);
@@ -812,7 +815,7 @@
         if (needsCast && !isGetter)
             names[PRE_CAST] = new Name(getFunction(NF_checkCast), names[DMH_THIS], names[SET_VALUE]);
         Object[] outArgs = new Object[1 + linkerType.parameterCount()];
-        assert (outArgs.length == (isFlatValue ? (isGetter ? 4 : 5) : (isGetter ? 3 : 4)));
+        assert (outArgs.length == (isGetter ? 3 : 4) + (hasValueTypeArg ? 1 : 0));
         outArgs[0] = names[U_HOLDER] = new Name(getFunction(NF_UNSAFE));
         if (isStatic) {
             outArgs[1] = names[F_HOLDER]  = new Name(getFunction(NF_staticBase), names[DMH_THIS]);
@@ -822,7 +825,7 @@
             outArgs[2] = names[F_OFFSET]  = new Name(getFunction(NF_fieldOffset), names[DMH_THIS]);
         }
         int x = 3;
-        if (isFlatValue) {
+        if (hasValueTypeArg) {
             outArgs[x++] = names[VALUE_TYPE] = isStatic ? new Name(getFunction(NF_staticFieldValueType), names[DMH_THIS])
                                                         : new Name(getFunction(NF_fieldValueType), names[DMH_THIS]);
         }
--- a/src/java.base/share/classes/java/lang/invoke/GenerateJLIClassesHelper.java	Mon Jan 14 17:45:15 2019 +0530
+++ b/src/java.base/share/classes/java/lang/invoke/GenerateJLIClassesHelper.java	Mon Jan 14 11:53:52 2019 -0800
@@ -82,14 +82,14 @@
             for (byte b = DirectMethodHandle.AF_GETFIELD; b < DirectMethodHandle.AF_LIMIT; b++) {
                 int ftype = DirectMethodHandle.ftypeKind(wrapper.primitiveType(), true);
                 LambdaForm form = DirectMethodHandle
-                        .makePreparedFieldLambdaForm(b, false /*isVolatile*/, false, ftype);
+                        .makePreparedFieldLambdaForm(b, false /*isVolatile*/, ftype);
                 if (form.kind != LambdaForm.Kind.GENERIC) {
                     forms.add(form);
                     names.add(form.kind.defaultLambdaName);
                 }
                 // volatile
                 form = DirectMethodHandle
-                        .makePreparedFieldLambdaForm(b, true /*isVolatile*/, false, ftype);
+                        .makePreparedFieldLambdaForm(b, true /*isVolatile*/, ftype);
                 if (form.kind != LambdaForm.Kind.GENERIC) {
                     forms.add(form);
                     names.add(form.kind.defaultLambdaName);
--- a/src/java.base/share/classes/java/lang/invoke/MemberName.java	Mon Jan 14 17:45:15 2019 +0530
+++ b/src/java.base/share/classes/java/lang/invoke/MemberName.java	Mon Jan 14 11:53:52 2019 -0800
@@ -473,11 +473,11 @@
     /** Query whether this member is a flattened field */
     public boolean isFlattened() { return (flags & FLATTENED) == FLATTENED; }
 
-    /** Query whether this member can be assigned to null. */
-    public boolean canBeNull()  {
+    /** Query whether this member is a field of normal value type. */
+    public boolean isValue()  {
         if (isField()) {
             Class<?> type = getFieldType();
-            return type == type.asBoxType();
+            return type == type.asValueType();
         }
         return false;
     }
--- a/src/java.base/share/classes/java/lang/invoke/VarHandles.java	Mon Jan 14 17:45:15 2019 +0530
+++ b/src/java.base/share/classes/java/lang/invoke/VarHandles.java	Mon Jan 14 11:53:52 2019 -0800
@@ -43,7 +43,7 @@
                 } else {
                     return f.isFinal() && !isWriteAllowedOnFinalFields
                        ? new VarHandleReferences.FieldInstanceReadOnly(refc, foffset, type)
-                       : new VarHandleReferences.FieldInstanceReadWrite(refc, foffset, type, f.canBeNull());
+                       : new VarHandleReferences.FieldInstanceReadWrite(refc, foffset, type, f.isValue());
                 }
             }
             else if (type == boolean.class) {
@@ -106,7 +106,7 @@
                 assert(!f.isFlattened());   // static field is not flattened
                 return f.isFinal() && !isWriteAllowedOnFinalFields
                        ? new VarHandleReferences.FieldStaticReadOnly(base, foffset, type)
-                       : new VarHandleReferences.FieldStaticReadWrite(base, foffset, type, f.canBeNull());
+                       : new VarHandleReferences.FieldStaticReadWrite(base, foffset, type, f.isValue());
             }
             else if (type == boolean.class) {
                 return f.isFinal() && !isWriteAllowedOnFinalFields
--- a/src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template	Mon Jan 14 17:45:15 2019 +0530
+++ b/src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template	Mon Jan 14 11:53:52 2019 -0800
@@ -118,10 +118,10 @@
 #if[Object]
         final boolean needsNullCheck;
 #end[Object]
-        FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType, boolean canBeNull}) {
+        FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType, boolean notNullable}) {
             super(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadWrite.FORM);
 #if[Object]
-            this.needsNullCheck = !canBeNull;
+            this.needsNullCheck = notNullable;
 #end[Object]
         }
 
@@ -425,10 +425,10 @@
 #if[Object]
         final boolean needsNullCheck;
 #end[Object]
-        FieldStaticReadWrite(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType, boolean canBeNull}) {
+        FieldStaticReadWrite(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType, boolean notNullable}) {
             super(base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadWrite.FORM);
 #if[Object]
-            this.needsNullCheck = !canBeNull;
+            this.needsNullCheck = notNullable;
 #end[Object]
         }