Java Code Examples for jdk.nashorn.internal.codegen.ObjectClassGenerator#getFieldName()

The following examples show how to use jdk.nashorn.internal.codegen.ObjectClassGenerator#getFieldName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessorProperty.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public GettersSetters(Class<?> structure) {
    final int fieldCount = ObjectClassGenerator.getFieldCount(structure);
    getters = new MethodHandle[fieldCount];
    setters = new MethodHandle[fieldCount];
    for(int i = 0; i < fieldCount; ++i) {
        final String fieldName = ObjectClassGenerator.getFieldName(i, Type.OBJECT);
        getters[i] = MH.asType(MH.getter(lookup, structure, fieldName, Type.OBJECT.getTypeClass()), Lookup.GET_OBJECT_TYPE);
        setters[i] = MH.asType(MH.setter(lookup, structure, fieldName, Type.OBJECT.getTypeClass()), Lookup.SET_OBJECT_TYPE);
    }
}
 
Example 2
Source File: AccessorProperty.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public GettersSetters(Class<?> structure) {
    final int fieldCount = ObjectClassGenerator.getFieldCount(structure);
    getters = new MethodHandle[fieldCount];
    setters = new MethodHandle[fieldCount];
    for(int i = 0; i < fieldCount; ++i) {
        final String fieldName = ObjectClassGenerator.getFieldName(i, Type.OBJECT);
        getters[i] = MH.asType(MH.getter(lookup, structure, fieldName, Type.OBJECT.getTypeClass()), Lookup.GET_OBJECT_TYPE);
        setters[i] = MH.asType(MH.setter(lookup, structure, fieldName, Type.OBJECT.getTypeClass()), Lookup.SET_OBJECT_TYPE);
    }
}
 
Example 3
Source File: AccessorProperty.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
public GettersSetters(Class<?> structure) {
    final int fieldCount = ObjectClassGenerator.getFieldCount(structure);
    getters = new MethodHandle[fieldCount];
    setters = new MethodHandle[fieldCount];
    for(int i = 0; i < fieldCount; ++i) {
        final String fieldName = ObjectClassGenerator.getFieldName(i, Type.OBJECT);
        getters[i] = MH.asType(MH.getter(lookup, structure, fieldName, Type.OBJECT.getTypeClass()), Lookup.GET_OBJECT_TYPE);
        setters[i] = MH.asType(MH.setter(lookup, structure, fieldName, Type.OBJECT.getTypeClass()), Lookup.SET_OBJECT_TYPE);
    }
}
 
Example 4
Source File: AccessorProperty.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor for dual field AccessorPropertys.
 *
 * @param key              property key
 * @param flags            property flags
 * @param structure        structure for objects associated with this property
 * @param slot             property field number or spill slot
 */
public AccessorProperty(final String key, final int flags, final Class<?> structure, final int slot) {
    super(key, flags, slot);

    /*
     * primitiveGetter and primitiveSetter are only used in dual fields mode. Setting them to null also
     * works in dual field mode, it only means that the property never has a primitive
     * representation.
     */
    primitiveGetter = null;
    primitiveSetter = null;

    if (isParameter() && hasArguments()) {
        final MethodHandle arguments   = MH.getter(lookup, structure, "arguments", ScriptObject.class);

        objectGetter = MH.asType(MH.insertArguments(MH.filterArguments(ScriptObject.GET_ARGUMENT.methodHandle(), 0, arguments), 1, slot), Lookup.GET_OBJECT_TYPE);
        objectSetter = MH.asType(MH.insertArguments(MH.filterArguments(ScriptObject.SET_ARGUMENT.methodHandle(), 0, arguments), 1, slot), Lookup.SET_OBJECT_TYPE);
    } else {
        final GettersSetters gs = GETTERS_SETTERS.get(structure);
        objectGetter = gs.getters[slot];
        objectSetter = gs.setters[slot];

        if (!OBJECT_FIELDS_ONLY) {
            final String fieldNamePrimitive = ObjectClassGenerator.getFieldName(slot, PRIMITIVE_TYPE);
            final Class<?> typeClass = PRIMITIVE_TYPE.getTypeClass();
            primitiveGetter = MH.asType(MH.getter(lookup, structure, fieldNamePrimitive, typeClass), ACCESSOR_GETTER_PRIMITIVE_TYPE);
            primitiveSetter = MH.asType(MH.setter(lookup, structure, fieldNamePrimitive, typeClass), ACCESSOR_SETTER_PRIMITIVE_TYPE);
        }
    }

    Class<?> initialType = null;

    if (OBJECT_FIELDS_ONLY || isAlwaysObject()) {
        initialType = Object.class;
    } else if (!canBePrimitive()) {
        info(key + " cannot be primitive");
        initialType = Object.class;
    } else {
        info(key + " CAN be primitive");
        if (!canBeUndefined()) {
            info(key + " is always defined");
            initialType = int.class; //double works too for less type invalidation, but this requires experimentation, e.g. var x = 17; x += 2 will turn it into double now because of lack of range analysis
        }
    }

    // is always object means "is never initialized to undefined, and always of object type
    setCurrentType(initialType);
}
 
Example 5
Source File: AccessorProperty.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor for dual field AccessorPropertys.
 *
 * @param key              property key
 * @param flags            property flags
 * @param structure        structure for objects associated with this property
 * @param slot             property field number or spill slot
 */
public AccessorProperty(final String key, final int flags, final Class<?> structure, final int slot) {
    super(key, flags, slot);

    /*
     * primitiveGetter and primitiveSetter are only used in dual fields mode. Setting them to null also
     * works in dual field mode, it only means that the property never has a primitive
     * representation.
     */
    primitiveGetter = null;
    primitiveSetter = null;

    if (isParameter() && hasArguments()) {
        final MethodHandle arguments   = MH.getter(lookup, structure, "arguments", ScriptObject.class);

        objectGetter = MH.asType(MH.insertArguments(MH.filterArguments(ScriptObject.GET_ARGUMENT.methodHandle(), 0, arguments), 1, slot), Lookup.GET_OBJECT_TYPE);
        objectSetter = MH.asType(MH.insertArguments(MH.filterArguments(ScriptObject.SET_ARGUMENT.methodHandle(), 0, arguments), 1, slot), Lookup.SET_OBJECT_TYPE);
    } else {
        final GettersSetters gs = GETTERS_SETTERS.get(structure);
        objectGetter = gs.getters[slot];
        objectSetter = gs.setters[slot];

        if (!OBJECT_FIELDS_ONLY) {
            final String fieldNamePrimitive = ObjectClassGenerator.getFieldName(slot, PRIMITIVE_TYPE);
            final Class<?> typeClass = PRIMITIVE_TYPE.getTypeClass();
            primitiveGetter = MH.asType(MH.getter(lookup, structure, fieldNamePrimitive, typeClass), ACCESSOR_GETTER_PRIMITIVE_TYPE);
            primitiveSetter = MH.asType(MH.setter(lookup, structure, fieldNamePrimitive, typeClass), ACCESSOR_SETTER_PRIMITIVE_TYPE);
        }
    }

    Class<?> initialType = null;

    if (OBJECT_FIELDS_ONLY || isAlwaysObject()) {
        initialType = Object.class;
    } else if (!canBePrimitive()) {
        info(key + " cannot be primitive");
        initialType = Object.class;
    } else {
        info(key + " CAN be primitive");
        if (!canBeUndefined()) {
            info(key + " is always defined");
            initialType = int.class; //double works too for less type invalidation, but this requires experimentation, e.g. var x = 17; x += 2 will turn it into double now because of lack of range analysis
        }
    }

    // is always object means "is never initialized to undefined, and always of object type
    setCurrentType(initialType);
}
 
Example 6
Source File: AccessorProperty.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor for dual field AccessorPropertys.
 *
 * @param key              property key
 * @param flags            property flags
 * @param structure        structure for objects associated with this property
 * @param slot             property field number or spill slot
 */
public AccessorProperty(final String key, final int flags, final Class<?> structure, final int slot) {
    super(key, flags, slot);

    /*
     * primitiveGetter and primitiveSetter are only used in dual fields mode. Setting them to null also
     * works in dual field mode, it only means that the property never has a primitive
     * representation.
     */
    primitiveGetter = null;
    primitiveSetter = null;

    if (isParameter() && hasArguments()) {
        final MethodHandle arguments   = MH.getter(lookup, structure, "arguments", ScriptObject.class);

        objectGetter = MH.asType(MH.insertArguments(MH.filterArguments(ScriptObject.GET_ARGUMENT.methodHandle(), 0, arguments), 1, slot), Lookup.GET_OBJECT_TYPE);
        objectSetter = MH.asType(MH.insertArguments(MH.filterArguments(ScriptObject.SET_ARGUMENT.methodHandle(), 0, arguments), 1, slot), Lookup.SET_OBJECT_TYPE);
    } else {
        final GettersSetters gs = GETTERS_SETTERS.get(structure);
        objectGetter = gs.getters[slot];
        objectSetter = gs.setters[slot];

        if (!OBJECT_FIELDS_ONLY) {
            final String fieldNamePrimitive = ObjectClassGenerator.getFieldName(slot, PRIMITIVE_TYPE);
            final Class<?> typeClass = PRIMITIVE_TYPE.getTypeClass();
            primitiveGetter = MH.asType(MH.getter(lookup, structure, fieldNamePrimitive, typeClass), ACCESSOR_GETTER_PRIMITIVE_TYPE);
            primitiveSetter = MH.asType(MH.setter(lookup, structure, fieldNamePrimitive, typeClass), ACCESSOR_SETTER_PRIMITIVE_TYPE);
        }
    }

    Class<?> initialType = null;

    if (OBJECT_FIELDS_ONLY || isAlwaysObject()) {
        initialType = Object.class;
    } else if (!canBePrimitive()) {
        info(key + " cannot be primitive");
        initialType = Object.class;
    } else {
        info(key + " CAN be primitive");
        if (!canBeUndefined()) {
            info(key + " is always defined");
            initialType = int.class; //double works too for less type invalidation, but this requires experimentation, e.g. var x = 17; x += 2 will turn it into double now because of lack of range analysis
        }
    }

    // is always object means "is never initialized to undefined, and always of object type
    setCurrentType(initialType);
}