< prev index next >

src/java.base/share/classes/java/lang/invoke/VarHandles.java

Print this page
@@ -57,13 +57,19 @@
      static VarHandle makeFieldHandle(MemberName f, Class<?> refc, boolean isWriteAllowedOnFinalFields) {
          if (!f.isStatic()) {
              long foffset = MethodHandleNatives.objectFieldOffset(f);
              Class<?> type = f.getFieldType();
              if (!type.isPrimitive()) {
-                 return maybeAdapt(f.isFinal() && !isWriteAllowedOnFinalFields
-                        ? new VarHandleReferences.FieldInstanceReadOnly(refc, foffset, type)
-                        : new VarHandleReferences.FieldInstanceReadWrite(refc, foffset, type));
+                 if (f.isFlat()) {
+                     return maybeAdapt(f.isFinal() && !isWriteAllowedOnFinalFields
+                         ? new VarHandleValues.FieldInstanceReadOnly(refc, foffset, type, f.isNullRestricted())
+                         : new VarHandleValues.FieldInstanceReadWrite(refc, foffset, type, f.isNullRestricted()));
+                 } else {
+                     return maybeAdapt(f.isFinal() && !isWriteAllowedOnFinalFields
+                        ? new VarHandleReferences.FieldInstanceReadOnly(refc, foffset, type, f.isNullRestricted())
+                        : new VarHandleReferences.FieldInstanceReadWrite(refc, foffset, type, f.isNullRestricted()));
+                 }
              }
              else if (type == boolean.class) {
                  return maybeAdapt(f.isFinal() && !isWriteAllowedOnFinalFields
                         ? new VarHandleBooleans.FieldInstanceReadOnly(refc, foffset)
                         : new VarHandleBooleans.FieldInstanceReadWrite(refc, foffset));

@@ -119,13 +125,19 @@
      static VarHandle makeStaticFieldVarHandle(Class<?> decl, MemberName f, boolean isWriteAllowedOnFinalFields) {
          Object base = MethodHandleNatives.staticFieldBase(f);
          long foffset = MethodHandleNatives.staticFieldOffset(f);
          Class<?> type = f.getFieldType();
          if (!type.isPrimitive()) {
-             return maybeAdapt(f.isFinal() && !isWriteAllowedOnFinalFields
-                     ? new VarHandleReferences.FieldStaticReadOnly(decl, base, foffset, type)
-                     : new VarHandleReferences.FieldStaticReadWrite(decl, base, foffset, type));
+             if (f.isFlat()) {
+                 return maybeAdapt(f.isFinal() && !isWriteAllowedOnFinalFields
+                         ? new VarHandleValues.FieldStaticReadOnly(decl, base, foffset, type, f.isNullRestricted())
+                         : new VarHandleValues.FieldStaticReadWrite(decl, base, foffset, type, f.isNullRestricted()));
+             } else {
+                 return f.isFinal() && !isWriteAllowedOnFinalFields
+                         ? new VarHandleReferences.FieldStaticReadOnly(decl, base, foffset, type, f.isNullRestricted())
+                         : new VarHandleReferences.FieldStaticReadWrite(decl, base, foffset, type, f.isNullRestricted());
+             }
          }
          else if (type == boolean.class) {
              return maybeAdapt(f.isFinal() && !isWriteAllowedOnFinalFields
                      ? new VarHandleBooleans.FieldStaticReadOnly(decl, base, foffset)
                      : new VarHandleBooleans.FieldStaticReadWrite(decl, base, foffset));

@@ -209,11 +221,13 @@
          int aoffset = UNSAFE.arrayBaseOffset(arrayClass);
          int ascale = UNSAFE.arrayIndexScale(arrayClass);
          int ashift = 31 - Integer.numberOfLeadingZeros(ascale);
  
          if (!componentType.isPrimitive()) {
-             return maybeAdapt(new VarHandleReferences.Array(aoffset, ashift, arrayClass));
+             return maybeAdapt(UNSAFE.isFlattenedArray(arrayClass)
+                 ? new VarHandleValues.Array(aoffset, ashift, arrayClass)
+                 : new VarHandleReferences.Array(aoffset, ashift, arrayClass));
          }
          else if (componentType == boolean.class) {
              return maybeAdapt(new VarHandleBooleans.Array(aoffset, ashift));
          }
          else if (componentType == byte.class) {

@@ -628,11 +642,11 @@
              if (MethodHandleNatives.refKindIsMethod(refKind)) {
                  return info.reflectAs(Method.class, MethodHandles.Lookup.IMPL_LOOKUP)
                          .getExceptionTypes();
              } else if (MethodHandleNatives.refKindIsField(refKind)) {
                  return new Class<?>[0];
-             } else if (MethodHandleNatives.refKindIsConstructor(refKind)) {
+             } else if (MethodHandleNatives.refKindIsObjectConstructor(refKind)) {
                  return info.reflectAs(Constructor.class, MethodHandles.Lookup.IMPL_LOOKUP)
                          .getExceptionTypes();
              } else {
                  throw new AssertionError("Cannot get here");
              }
< prev index next >