java.lang.reflect.Modifier#isVolatile ( )源码实例Demo

下面列出了java.lang.reflect.Modifier#isVolatile ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: joyrpc   文件: JavassistProxyFactory.java
/**
 * 添加修饰符
 *
 * @param mod     修饰符变量
 * @param builder 字符串构建器
 * @return 字符串构建器
 */
protected StringBuilder modifier(final int mod, final StringBuilder builder) {
    if (Modifier.isPublic(mod)) {
        builder.append("public");
    } else if (Modifier.isProtected(mod)) {
        builder.append("protected");
    } else if (Modifier.isPrivate(mod)) {
        builder.append("private");
    }
    if (Modifier.isStatic(mod)) {
        builder.append(" static");
    }
    if (Modifier.isVolatile(mod)) {
        builder.append(" volatile");
    }

    return builder;
}
 
源代码2 项目: j2objc   文件: AtomicLongFieldUpdater.java
CASUpdater(final Class<T> tclass, final String fieldName,
           final Class<?> caller) {
    final Field field;
    final int modifiers;
    try {
        field = tclass.getDeclaredField(fieldName); // android-changed
        modifiers = field.getModifiers();
        // BEGIN Android-removed
        // sun.reflect.misc.ReflectUtil.ensureMemberAccess(
        //     caller, tclass, null, modifiers);
        // ClassLoader cl = tclass.getClassLoader();
        // ClassLoader ccl = caller.getClassLoader();
        // if ((ccl != null) && (ccl != cl) &&
        //     ((cl == null) || !isAncestor(cl, ccl))) {
        //     sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        // }
        // END Android-removed
    // BEGIN Android-removed
    // } catch (PrivilegedActionException pae) {
    //     throw new RuntimeException(pae.getException());
    // END Android-removed
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (field.getType() != long.class)
        throw new IllegalArgumentException("Must be long type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    this.cclass = (Modifier.isProtected(modifiers)) ? caller : tclass;
    this.tclass = tclass;
    this.offset = U.objectFieldOffset(field);
}
 
源代码3 项目: openjdk-8   文件: AtomicIntegerFieldUpdater.java
AtomicIntegerFieldUpdaterImpl(final Class<T> tclass,
                              final String fieldName,
                              final Class<?> caller) {
    final Field field;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
          sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    Class<?> fieldt = field.getType();
    if (fieldt != int.class)
        throw new IllegalArgumentException("Must be integer type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    this.cclass = (Modifier.isProtected(modifiers) &&
                   caller != tclass) ? caller : null;
    this.tclass = tclass;
    offset = unsafe.objectFieldOffset(field);
}
 
源代码4 项目: jdk8u60   文件: AtomicLongFieldUpdater.java
CASUpdater(final Class<T> tclass, final String fieldName,
           final Class<?> caller) {
    final Field field;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
          sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    Class<?> fieldt = field.getType();
    if (fieldt != long.class)
        throw new IllegalArgumentException("Must be long type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    this.cclass = (Modifier.isProtected(modifiers) &&
                   caller != tclass) ? caller : null;
    this.tclass = tclass;
    offset = unsafe.objectFieldOffset(field);
}
 
UnsafeAtomicIntegerFieldUpdater(Unsafe unsafe, Class<?> tClass, String fieldName) throws NoSuchFieldException {
    Field field = tClass.getDeclaredField(fieldName);
    if (!Modifier.isVolatile(field.getModifiers())) {
        throw new IllegalArgumentException("Must be volatile");
    }
    this.unsafe = unsafe;
    offset = unsafe.objectFieldOffset(field);
}
 
UnsafeAtomicLongFieldUpdater(Unsafe unsafe, Class<?> tClass, String fieldName) throws NoSuchFieldException {
    Field field = tClass.getDeclaredField(fieldName);
    if (!Modifier.isVolatile(field.getModifiers())) {
        throw new IllegalArgumentException("Must be volatile");
    }
    this.unsafe = unsafe;
    offset = unsafe.objectFieldOffset(field);
}
 
源代码7 项目: jdk8u-jdk   文件: AtomicLongFieldUpdater.java
LockedUpdater(final Class<T> tclass, final String fieldName,
              final Class<?> caller) {
    Field field = null;
    int modifiers = 0;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
          sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    Class<?> fieldt = field.getType();
    if (fieldt != long.class)
        throw new IllegalArgumentException("Must be long type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    this.cclass = (Modifier.isProtected(modifiers) &&
                   caller != tclass) ? caller : null;
    this.tclass = tclass;
    offset = unsafe.objectFieldOffset(field);
}
 
AtomicIntegerFieldUpdaterImpl(final Class<T> tclass,
                              final String fieldName,
                              final Class<?> caller) {
    final Field field;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
            sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (field.getType() != int.class)
        throw new IllegalArgumentException("Must be integer type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    // Access to protected field members is restricted to receivers only
    // of the accessing class, or one of its subclasses, and the
    // accessing class must in turn be a subclass (or package sibling)
    // of the protected member's defining class.
    // If the updater refers to a protected field of a declaring class
    // outside the current package, the receiver argument will be
    // narrowed to the type of the accessing class.
    this.cclass = (Modifier.isProtected(modifiers) &&
                   tclass.isAssignableFrom(caller) &&
                   !isSamePackage(tclass, caller))
                  ? caller : tclass;
    this.tclass = tclass;
    this.offset = U.objectFieldOffset(field);
}
 
源代码9 项目: javaide   文件: UnsafeFieldAccessorFactory.java
static FieldAccessor newFieldAccessor(Field field, boolean override) {
    Class type = field.getType();
    boolean isStatic = Modifier.isStatic(field.getModifiers());
    boolean isFinal = Modifier.isFinal(field.getModifiers());
    boolean isVolatile = Modifier.isVolatile(field.getModifiers());
    boolean isQualified = isFinal || isVolatile;
    boolean isReadOnly = isFinal && (isStatic || !override);
    if (isStatic) {
        // This code path does not guarantee that the field's
        // declaring class has been initialized, but it must be
        // before performing reflective operations.
        UnsafeFieldAccessorImpl.unsafe.ensureClassInitialized(field.getDeclaringClass());

        if (!isQualified) {
            if (type == Boolean.TYPE) {
                return new UnsafeStaticBooleanFieldAccessorImpl(field);
            } else if (type == Byte.TYPE) {
                return new UnsafeStaticByteFieldAccessorImpl(field);
            } else if (type == Short.TYPE) {
                return new UnsafeStaticShortFieldAccessorImpl(field);
            } else if (type == Character.TYPE) {
                return new UnsafeStaticCharacterFieldAccessorImpl(field);
            } else if (type == Integer.TYPE) {
                return new UnsafeStaticIntegerFieldAccessorImpl(field);
            } else if (type == Long.TYPE) {
                return new UnsafeStaticLongFieldAccessorImpl(field);
            } else if (type == Float.TYPE) {
                return new UnsafeStaticFloatFieldAccessorImpl(field);
            } else if (type == Double.TYPE) {
                return new UnsafeStaticDoubleFieldAccessorImpl(field);
            } else {
                return new UnsafeStaticObjectFieldAccessorImpl(field);
            }
        } else {
            if (type == Boolean.TYPE) {
                return new UnsafeQualifiedStaticBooleanFieldAccessorImpl(field, isReadOnly);
            } else if (type == Byte.TYPE) {
                return new UnsafeQualifiedStaticByteFieldAccessorImpl(field, isReadOnly);
            } else if (type == Short.TYPE) {
                return new UnsafeQualifiedStaticShortFieldAccessorImpl(field, isReadOnly);
            } else if (type == Character.TYPE) {
                return new UnsafeQualifiedStaticCharacterFieldAccessorImpl(field, isReadOnly);
            } else if (type == Integer.TYPE) {
                return new UnsafeQualifiedStaticIntegerFieldAccessorImpl(field, isReadOnly);
            } else if (type == Long.TYPE) {
                return new UnsafeQualifiedStaticLongFieldAccessorImpl(field, isReadOnly);
            } else if (type == Float.TYPE) {
                return new UnsafeQualifiedStaticFloatFieldAccessorImpl(field, isReadOnly);
            } else if (type == Double.TYPE) {
                return new UnsafeQualifiedStaticDoubleFieldAccessorImpl(field, isReadOnly);
            } else {
                return new UnsafeQualifiedStaticObjectFieldAccessorImpl(field, isReadOnly);
            }
        }
    } else {
        if (!isQualified) {
            if (type == Boolean.TYPE) {
                return new UnsafeBooleanFieldAccessorImpl(field);
            } else if (type == Byte.TYPE) {
                return new UnsafeByteFieldAccessorImpl(field);
            } else if (type == Short.TYPE) {
                return new UnsafeShortFieldAccessorImpl(field);
            } else if (type == Character.TYPE) {
                return new UnsafeCharacterFieldAccessorImpl(field);
            } else if (type == Integer.TYPE) {
                return new UnsafeIntegerFieldAccessorImpl(field);
            } else if (type == Long.TYPE) {
                return new UnsafeLongFieldAccessorImpl(field);
            } else if (type == Float.TYPE) {
                return new UnsafeFloatFieldAccessorImpl(field);
            } else if (type == Double.TYPE) {
                return new UnsafeDoubleFieldAccessorImpl(field);
            } else {
                return new UnsafeObjectFieldAccessorImpl(field);
            }
        } else {
            if (type == Boolean.TYPE) {
                return new UnsafeQualifiedBooleanFieldAccessorImpl(field, isReadOnly);
            } else if (type == Byte.TYPE) {
                return new UnsafeQualifiedByteFieldAccessorImpl(field, isReadOnly);
            } else if (type == Short.TYPE) {
                return new UnsafeQualifiedShortFieldAccessorImpl(field, isReadOnly);
            } else if (type == Character.TYPE) {
                return new UnsafeQualifiedCharacterFieldAccessorImpl(field, isReadOnly);
            } else if (type == Integer.TYPE) {
                return new UnsafeQualifiedIntegerFieldAccessorImpl(field, isReadOnly);
            } else if (type == Long.TYPE) {
                return new UnsafeQualifiedLongFieldAccessorImpl(field, isReadOnly);
            } else if (type == Float.TYPE) {
                return new UnsafeQualifiedFloatFieldAccessorImpl(field, isReadOnly);
            } else if (type == Double.TYPE) {
                return new UnsafeQualifiedDoubleFieldAccessorImpl(field, isReadOnly);
            } else {
                return new UnsafeQualifiedObjectFieldAccessorImpl(field, isReadOnly);
            }
        }
    }
}
 
源代码10 项目: openjdk-jdk8u   文件: UnsafeFieldAccessorFactory.java
static FieldAccessor newFieldAccessor(Field field, boolean override) {
    Class<?> type = field.getType();
    boolean isStatic = Modifier.isStatic(field.getModifiers());
    boolean isFinal = Modifier.isFinal(field.getModifiers());
    boolean isVolatile = Modifier.isVolatile(field.getModifiers());
    boolean isQualified = isFinal || isVolatile;
    boolean isReadOnly = isFinal && (isStatic || !override);
    if (isStatic) {
        // This code path does not guarantee that the field's
        // declaring class has been initialized, but it must be
        // before performing reflective operations.
        UnsafeFieldAccessorImpl.unsafe.ensureClassInitialized(field.getDeclaringClass());

        if (!isQualified) {
            if (type == Boolean.TYPE) {
                return new UnsafeStaticBooleanFieldAccessorImpl(field);
            } else if (type == Byte.TYPE) {
                return new UnsafeStaticByteFieldAccessorImpl(field);
            } else if (type == Short.TYPE) {
                return new UnsafeStaticShortFieldAccessorImpl(field);
            } else if (type == Character.TYPE) {
                return new UnsafeStaticCharacterFieldAccessorImpl(field);
            } else if (type == Integer.TYPE) {
                return new UnsafeStaticIntegerFieldAccessorImpl(field);
            } else if (type == Long.TYPE) {
                return new UnsafeStaticLongFieldAccessorImpl(field);
            } else if (type == Float.TYPE) {
                return new UnsafeStaticFloatFieldAccessorImpl(field);
            } else if (type == Double.TYPE) {
                return new UnsafeStaticDoubleFieldAccessorImpl(field);
            } else {
                return new UnsafeStaticObjectFieldAccessorImpl(field);
            }
        } else {
            if (type == Boolean.TYPE) {
                return new UnsafeQualifiedStaticBooleanFieldAccessorImpl(field, isReadOnly);
            } else if (type == Byte.TYPE) {
                return new UnsafeQualifiedStaticByteFieldAccessorImpl(field, isReadOnly);
            } else if (type == Short.TYPE) {
                return new UnsafeQualifiedStaticShortFieldAccessorImpl(field, isReadOnly);
            } else if (type == Character.TYPE) {
                return new UnsafeQualifiedStaticCharacterFieldAccessorImpl(field, isReadOnly);
            } else if (type == Integer.TYPE) {
                return new UnsafeQualifiedStaticIntegerFieldAccessorImpl(field, isReadOnly);
            } else if (type == Long.TYPE) {
                return new UnsafeQualifiedStaticLongFieldAccessorImpl(field, isReadOnly);
            } else if (type == Float.TYPE) {
                return new UnsafeQualifiedStaticFloatFieldAccessorImpl(field, isReadOnly);
            } else if (type == Double.TYPE) {
                return new UnsafeQualifiedStaticDoubleFieldAccessorImpl(field, isReadOnly);
            } else {
                return new UnsafeQualifiedStaticObjectFieldAccessorImpl(field, isReadOnly);
            }
        }
    } else {
        if (!isQualified) {
            if (type == Boolean.TYPE) {
                return new UnsafeBooleanFieldAccessorImpl(field);
            } else if (type == Byte.TYPE) {
                return new UnsafeByteFieldAccessorImpl(field);
            } else if (type == Short.TYPE) {
                return new UnsafeShortFieldAccessorImpl(field);
            } else if (type == Character.TYPE) {
                return new UnsafeCharacterFieldAccessorImpl(field);
            } else if (type == Integer.TYPE) {
                return new UnsafeIntegerFieldAccessorImpl(field);
            } else if (type == Long.TYPE) {
                return new UnsafeLongFieldAccessorImpl(field);
            } else if (type == Float.TYPE) {
                return new UnsafeFloatFieldAccessorImpl(field);
            } else if (type == Double.TYPE) {
                return new UnsafeDoubleFieldAccessorImpl(field);
            } else {
                return new UnsafeObjectFieldAccessorImpl(field);
            }
        } else {
            if (type == Boolean.TYPE) {
                return new UnsafeQualifiedBooleanFieldAccessorImpl(field, isReadOnly);
            } else if (type == Byte.TYPE) {
                return new UnsafeQualifiedByteFieldAccessorImpl(field, isReadOnly);
            } else if (type == Short.TYPE) {
                return new UnsafeQualifiedShortFieldAccessorImpl(field, isReadOnly);
            } else if (type == Character.TYPE) {
                return new UnsafeQualifiedCharacterFieldAccessorImpl(field, isReadOnly);
            } else if (type == Integer.TYPE) {
                return new UnsafeQualifiedIntegerFieldAccessorImpl(field, isReadOnly);
            } else if (type == Long.TYPE) {
                return new UnsafeQualifiedLongFieldAccessorImpl(field, isReadOnly);
            } else if (type == Float.TYPE) {
                return new UnsafeQualifiedFloatFieldAccessorImpl(field, isReadOnly);
            } else if (type == Double.TYPE) {
                return new UnsafeQualifiedDoubleFieldAccessorImpl(field, isReadOnly);
            } else {
                return new UnsafeQualifiedObjectFieldAccessorImpl(field, isReadOnly);
            }
        }
    }
}
 
源代码11 项目: FHIR   文件: FHIRSwaggerGenerator.java
private static void generateDefinition(Class<?> modelClass, JsonObjectBuilder definitions) throws Exception {
        if (!ModelSupport.isPrimitiveType(modelClass)) {
            JsonObjectBuilder definition = factory.createObjectBuilder();
            JsonObjectBuilder properties = factory.createObjectBuilder();
            JsonArrayBuilder required = factory.createArrayBuilder();

            StructureDefinition structureDefinition = getStructureDefinition(modelClass);

            if (structureDefinition == null) {
                System.err.println("Failed generateDefinition for: " + modelClass.getName());
                return;
            }

            if (Resource.class.isAssignableFrom(modelClass)) {
                // add the 'resourceType' property
                JsonObjectBuilder property = factory.createObjectBuilder();

                // Convert all the primitive types to json types.
                property.add("type", "string");
                if (Resource.class == modelClass) {
                    // TODO: when a filter was passed, limit this to just the resource types included in the filter
                    List<String> typeNames = Arrays.stream(ResourceType.ValueSet.values()).map(ResourceType.ValueSet::value).collect(Collectors.toList());
                    JsonArrayBuilder enumValues = factory.createArrayBuilder(typeNames);
                    property.add("enum", enumValues);
                    properties.add("resourceType", property.build());
                    required.add("resourceType");
                } else {
                    // TODO how to "overwrite" the Resource definition and say that the value is fixed?
                    // https://github.com/OAI/OpenAPI-Specification/issues/1313
//                    property.add("enum", modelClass.getSimpleName());
                }
            }

            for (Field field : modelClass.getDeclaredFields()) {
                if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isVolatile(field.getModifiers())) {
                    if (!ModelSupport.isChoiceElement(modelClass, ModelSupport.getElementName(field)) && field.isAnnotationPresent(Required.class)) {
                        required.add(ModelSupport.getElementName(field));
                    }
                    generateProperties(structureDefinition, modelClass, field, properties);
                }
            }

            JsonArray requiredArray = required.build();

            Class<?> superClass = modelClass.getSuperclass();
            if (superClass != null
                    && superClass.getPackage().getName().startsWith("com.ibm.fhir.model")
                    && !superClass.equals(AbstractVisitable.class)) {
                JsonArrayBuilder allOf = factory.createArrayBuilder();

                JsonObjectBuilder ref = factory.createObjectBuilder();
                ref.add("$ref", "#/definitions/" + superClass.getSimpleName());
                allOf.add(ref);

                JsonObjectBuilder wrapper = factory.createObjectBuilder();
                wrapper.add("type", "object");
                wrapper.add("properties", properties);
                if (!requiredArray.isEmpty()) {
                    wrapper.add("required", requiredArray);
                }
                allOf.add(wrapper);

                definition.add("allOf", allOf);
            } else {
                definition.add("type", "object");
                if (Resource.class.equals(modelClass)) {
                    definition.add("discriminator", "resourceType");
                }
                definition.add("properties", properties);
                if (!requiredArray.isEmpty()) {
                    definition.add("required", requiredArray);
                }
            }

            if (Resource.class.isAssignableFrom(modelClass)) {
                FHIROpenApiGenerator.addExamples(modelClass, definition);
            }

            definitions.add(getSimpleNameWithEnclosingNames(modelClass), definition);
        }
    }
 
AtomicReferenceFieldUpdaterImpl(final Class<T> tclass,
                                final Class<V> vclass,
                                final String fieldName,
                                final Class<?> caller) {
    final Field field;
    final Class<?> fieldClass;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
            sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
        fieldClass = field.getType();
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (vclass != fieldClass)
        throw new ClassCastException();
    if (vclass.isPrimitive())
        throw new IllegalArgumentException("Must be reference type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    // Access to protected field members is restricted to receivers only
    // of the accessing class, or one of its subclasses, and the
    // accessing class must in turn be a subclass (or package sibling)
    // of the protected member's defining class.
    // If the updater refers to a protected field of a declaring class
    // outside the current package, the receiver argument will be
    // narrowed to the type of the accessing class.
    this.cclass = (Modifier.isProtected(modifiers) &&
                   tclass.isAssignableFrom(caller) &&
                   !isSamePackage(tclass, caller))
                  ? caller : tclass;
    this.tclass = tclass;
    this.vclass = vclass;
    this.offset = U.objectFieldOffset(field);
}
 
源代码13 项目: openjdk-jdk8u   文件: MemberName.java
/** Utility method to query the modifier flags of this member. */
public boolean isVolatile() {
    return Modifier.isVolatile(flags);
}
 
static FieldAccessor newFieldAccessor(Field field, boolean override) {
    Class<?> type = field.getType();
    boolean isStatic = Modifier.isStatic(field.getModifiers());
    boolean isFinal = Modifier.isFinal(field.getModifiers());
    boolean isVolatile = Modifier.isVolatile(field.getModifiers());
    boolean isQualified = isFinal || isVolatile;
    boolean isReadOnly = isFinal && (isStatic || !override);
    if (isStatic) {
        // This code path does not guarantee that the field's
        // declaring class has been initialized, but it must be
        // before performing reflective operations.
        UnsafeFieldAccessorImpl.unsafe.ensureClassInitialized(field.getDeclaringClass());

        if (!isQualified) {
            if (type == Boolean.TYPE) {
                return new UnsafeStaticBooleanFieldAccessorImpl(field);
            } else if (type == Byte.TYPE) {
                return new UnsafeStaticByteFieldAccessorImpl(field);
            } else if (type == Short.TYPE) {
                return new UnsafeStaticShortFieldAccessorImpl(field);
            } else if (type == Character.TYPE) {
                return new UnsafeStaticCharacterFieldAccessorImpl(field);
            } else if (type == Integer.TYPE) {
                return new UnsafeStaticIntegerFieldAccessorImpl(field);
            } else if (type == Long.TYPE) {
                return new UnsafeStaticLongFieldAccessorImpl(field);
            } else if (type == Float.TYPE) {
                return new UnsafeStaticFloatFieldAccessorImpl(field);
            } else if (type == Double.TYPE) {
                return new UnsafeStaticDoubleFieldAccessorImpl(field);
            } else {
                return new UnsafeStaticObjectFieldAccessorImpl(field);
            }
        } else {
            if (type == Boolean.TYPE) {
                return new UnsafeQualifiedStaticBooleanFieldAccessorImpl(field, isReadOnly);
            } else if (type == Byte.TYPE) {
                return new UnsafeQualifiedStaticByteFieldAccessorImpl(field, isReadOnly);
            } else if (type == Short.TYPE) {
                return new UnsafeQualifiedStaticShortFieldAccessorImpl(field, isReadOnly);
            } else if (type == Character.TYPE) {
                return new UnsafeQualifiedStaticCharacterFieldAccessorImpl(field, isReadOnly);
            } else if (type == Integer.TYPE) {
                return new UnsafeQualifiedStaticIntegerFieldAccessorImpl(field, isReadOnly);
            } else if (type == Long.TYPE) {
                return new UnsafeQualifiedStaticLongFieldAccessorImpl(field, isReadOnly);
            } else if (type == Float.TYPE) {
                return new UnsafeQualifiedStaticFloatFieldAccessorImpl(field, isReadOnly);
            } else if (type == Double.TYPE) {
                return new UnsafeQualifiedStaticDoubleFieldAccessorImpl(field, isReadOnly);
            } else {
                return new UnsafeQualifiedStaticObjectFieldAccessorImpl(field, isReadOnly);
            }
        }
    } else {
        if (!isQualified) {
            if (type == Boolean.TYPE) {
                return new UnsafeBooleanFieldAccessorImpl(field);
            } else if (type == Byte.TYPE) {
                return new UnsafeByteFieldAccessorImpl(field);
            } else if (type == Short.TYPE) {
                return new UnsafeShortFieldAccessorImpl(field);
            } else if (type == Character.TYPE) {
                return new UnsafeCharacterFieldAccessorImpl(field);
            } else if (type == Integer.TYPE) {
                return new UnsafeIntegerFieldAccessorImpl(field);
            } else if (type == Long.TYPE) {
                return new UnsafeLongFieldAccessorImpl(field);
            } else if (type == Float.TYPE) {
                return new UnsafeFloatFieldAccessorImpl(field);
            } else if (type == Double.TYPE) {
                return new UnsafeDoubleFieldAccessorImpl(field);
            } else {
                return new UnsafeObjectFieldAccessorImpl(field);
            }
        } else {
            if (type == Boolean.TYPE) {
                return new UnsafeQualifiedBooleanFieldAccessorImpl(field, isReadOnly);
            } else if (type == Byte.TYPE) {
                return new UnsafeQualifiedByteFieldAccessorImpl(field, isReadOnly);
            } else if (type == Short.TYPE) {
                return new UnsafeQualifiedShortFieldAccessorImpl(field, isReadOnly);
            } else if (type == Character.TYPE) {
                return new UnsafeQualifiedCharacterFieldAccessorImpl(field, isReadOnly);
            } else if (type == Integer.TYPE) {
                return new UnsafeQualifiedIntegerFieldAccessorImpl(field, isReadOnly);
            } else if (type == Long.TYPE) {
                return new UnsafeQualifiedLongFieldAccessorImpl(field, isReadOnly);
            } else if (type == Float.TYPE) {
                return new UnsafeQualifiedFloatFieldAccessorImpl(field, isReadOnly);
            } else if (type == Double.TYPE) {
                return new UnsafeQualifiedDoubleFieldAccessorImpl(field, isReadOnly);
            } else {
                return new UnsafeQualifiedObjectFieldAccessorImpl(field, isReadOnly);
            }
        }
    }
}
 
源代码15 项目: hottub   文件: FieldDocImpl.java
/**
 * Return true if this field is volatile
 */
public boolean isVolatile() {
    return Modifier.isVolatile(getModifiers());
}
 
源代码16 项目: dragonwell8_jdk   文件: AtomicLongFieldUpdater.java
CASUpdater(final Class<T> tclass, final String fieldName,
           final Class<?> caller) {
    final Field field;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
            sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (field.getType() != long.class)
        throw new IllegalArgumentException("Must be long type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    // Access to protected field members is restricted to receivers only
    // of the accessing class, or one of its subclasses, and the
    // accessing class must in turn be a subclass (or package sibling)
    // of the protected member's defining class.
    // If the updater refers to a protected field of a declaring class
    // outside the current package, the receiver argument will be
    // narrowed to the type of the accessing class.
    this.cclass = (Modifier.isProtected(modifiers) &&
                   tclass.isAssignableFrom(caller) &&
                   !isSamePackage(tclass, caller))
                  ? caller : tclass;
    this.tclass = tclass;
    this.offset = U.objectFieldOffset(field);
}
 
源代码17 项目: jdk8u_jdk   文件: UnsafeFieldAccessorFactory.java
static FieldAccessor newFieldAccessor(Field field, boolean override) {
    Class<?> type = field.getType();
    boolean isStatic = Modifier.isStatic(field.getModifiers());
    boolean isFinal = Modifier.isFinal(field.getModifiers());
    boolean isVolatile = Modifier.isVolatile(field.getModifiers());
    boolean isQualified = isFinal || isVolatile;
    boolean isReadOnly = isFinal && (isStatic || !override);
    if (isStatic) {
        // This code path does not guarantee that the field's
        // declaring class has been initialized, but it must be
        // before performing reflective operations.
        UnsafeFieldAccessorImpl.unsafe.ensureClassInitialized(field.getDeclaringClass());

        if (!isQualified) {
            if (type == Boolean.TYPE) {
                return new UnsafeStaticBooleanFieldAccessorImpl(field);
            } else if (type == Byte.TYPE) {
                return new UnsafeStaticByteFieldAccessorImpl(field);
            } else if (type == Short.TYPE) {
                return new UnsafeStaticShortFieldAccessorImpl(field);
            } else if (type == Character.TYPE) {
                return new UnsafeStaticCharacterFieldAccessorImpl(field);
            } else if (type == Integer.TYPE) {
                return new UnsafeStaticIntegerFieldAccessorImpl(field);
            } else if (type == Long.TYPE) {
                return new UnsafeStaticLongFieldAccessorImpl(field);
            } else if (type == Float.TYPE) {
                return new UnsafeStaticFloatFieldAccessorImpl(field);
            } else if (type == Double.TYPE) {
                return new UnsafeStaticDoubleFieldAccessorImpl(field);
            } else {
                return new UnsafeStaticObjectFieldAccessorImpl(field);
            }
        } else {
            if (type == Boolean.TYPE) {
                return new UnsafeQualifiedStaticBooleanFieldAccessorImpl(field, isReadOnly);
            } else if (type == Byte.TYPE) {
                return new UnsafeQualifiedStaticByteFieldAccessorImpl(field, isReadOnly);
            } else if (type == Short.TYPE) {
                return new UnsafeQualifiedStaticShortFieldAccessorImpl(field, isReadOnly);
            } else if (type == Character.TYPE) {
                return new UnsafeQualifiedStaticCharacterFieldAccessorImpl(field, isReadOnly);
            } else if (type == Integer.TYPE) {
                return new UnsafeQualifiedStaticIntegerFieldAccessorImpl(field, isReadOnly);
            } else if (type == Long.TYPE) {
                return new UnsafeQualifiedStaticLongFieldAccessorImpl(field, isReadOnly);
            } else if (type == Float.TYPE) {
                return new UnsafeQualifiedStaticFloatFieldAccessorImpl(field, isReadOnly);
            } else if (type == Double.TYPE) {
                return new UnsafeQualifiedStaticDoubleFieldAccessorImpl(field, isReadOnly);
            } else {
                return new UnsafeQualifiedStaticObjectFieldAccessorImpl(field, isReadOnly);
            }
        }
    } else {
        if (!isQualified) {
            if (type == Boolean.TYPE) {
                return new UnsafeBooleanFieldAccessorImpl(field);
            } else if (type == Byte.TYPE) {
                return new UnsafeByteFieldAccessorImpl(field);
            } else if (type == Short.TYPE) {
                return new UnsafeShortFieldAccessorImpl(field);
            } else if (type == Character.TYPE) {
                return new UnsafeCharacterFieldAccessorImpl(field);
            } else if (type == Integer.TYPE) {
                return new UnsafeIntegerFieldAccessorImpl(field);
            } else if (type == Long.TYPE) {
                return new UnsafeLongFieldAccessorImpl(field);
            } else if (type == Float.TYPE) {
                return new UnsafeFloatFieldAccessorImpl(field);
            } else if (type == Double.TYPE) {
                return new UnsafeDoubleFieldAccessorImpl(field);
            } else {
                return new UnsafeObjectFieldAccessorImpl(field);
            }
        } else {
            if (type == Boolean.TYPE) {
                return new UnsafeQualifiedBooleanFieldAccessorImpl(field, isReadOnly);
            } else if (type == Byte.TYPE) {
                return new UnsafeQualifiedByteFieldAccessorImpl(field, isReadOnly);
            } else if (type == Short.TYPE) {
                return new UnsafeQualifiedShortFieldAccessorImpl(field, isReadOnly);
            } else if (type == Character.TYPE) {
                return new UnsafeQualifiedCharacterFieldAccessorImpl(field, isReadOnly);
            } else if (type == Integer.TYPE) {
                return new UnsafeQualifiedIntegerFieldAccessorImpl(field, isReadOnly);
            } else if (type == Long.TYPE) {
                return new UnsafeQualifiedLongFieldAccessorImpl(field, isReadOnly);
            } else if (type == Float.TYPE) {
                return new UnsafeQualifiedFloatFieldAccessorImpl(field, isReadOnly);
            } else if (type == Double.TYPE) {
                return new UnsafeQualifiedDoubleFieldAccessorImpl(field, isReadOnly);
            } else {
                return new UnsafeQualifiedObjectFieldAccessorImpl(field, isReadOnly);
            }
        }
    }
}
 
源代码18 项目: Java8CN   文件: AtomicReferenceFieldUpdater.java
AtomicReferenceFieldUpdaterImpl(final Class<T> tclass,
                                final Class<V> vclass,
                                final String fieldName,
                                final Class<?> caller) {
    final Field field;
    final Class<?> fieldClass;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
          sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
        fieldClass = field.getType();
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (vclass != fieldClass)
        throw new ClassCastException();
    if (vclass.isPrimitive())
        throw new IllegalArgumentException("Must be reference type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    this.cclass = (Modifier.isProtected(modifiers) &&
                   caller != tclass) ? caller : null;
    this.tclass = tclass;
    if (vclass == Object.class)
        this.vclass = null;
    else
        this.vclass = vclass;
    offset = unsafe.objectFieldOffset(field);
}
 
源代码19 项目: openjdk-jdk9   文件: ModifiersProvider.java
/**
 * @see Modifier#isVolatile(int)
 */
default boolean isVolatile() {
    return Modifier.isVolatile(getModifiers());
}
 
AtomicReferenceFieldUpdaterImpl(final Class<T> tclass,
                                final Class<V> vclass,
                                final String fieldName,
                                final Class<?> caller) {
    final Field field;
    final Class<?> fieldClass;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
            sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
        fieldClass = field.getType();
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (vclass != fieldClass)
        throw new ClassCastException();
    if (vclass.isPrimitive())
        throw new IllegalArgumentException("Must be reference type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    // Access to protected field members is restricted to receivers only
    // of the accessing class, or one of its subclasses, and the
    // accessing class must in turn be a subclass (or package sibling)
    // of the protected member's defining class.
    // If the updater refers to a protected field of a declaring class
    // outside the current package, the receiver argument will be
    // narrowed to the type of the accessing class.
    this.cclass = (Modifier.isProtected(modifiers) &&
                   tclass.isAssignableFrom(caller) &&
                   !isSamePackage(tclass, caller))
                  ? caller : tclass;
    this.tclass = tclass;
    this.vclass = vclass;
    this.offset = U.objectFieldOffset(field);
}