Java Code Examples for jdk.nashorn.internal.codegen.types.Type#getMethodDescriptor()

The following examples show how to use jdk.nashorn.internal.codegen.types.Type#getMethodDescriptor() . 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: SharedScopeCall.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
private String getStaticSignature() {
    if (staticSignature == null) {
        if (paramTypes == null) {
            staticSignature = Type.getMethodDescriptor(returnType, Type.typeFor(ScriptObject.class), Type.INT);
        } else {
            final Type[] params = new Type[paramTypes.length + 2];
            params[0] = Type.typeFor(ScriptObject.class);
            params[1] = Type.INT;
            int i = 2;
            for (Type type : paramTypes)  {
                if (type.isObject()) {
                    type = Type.OBJECT;
                }
                params[i++] = type;
            }
            staticSignature = Type.getMethodDescriptor(returnType, params);
        }
    }
    return staticSignature;
}
 
Example 2
Source File: MethodEmitter.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        Type pt = stack.peek(pos++);
        // "erase" specific ScriptObject subtype info - except for NativeArray.
        // NativeArray is used for array/List/Deque conversion for Java calls.
        if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
            !NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
            pt = Type.SCRIPT_OBJECT;
        }
        paramTypes[i] = pt;
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example 3
Source File: SharedScopeCall.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private String getStaticSignature() {
    if (staticSignature == null) {
        if (paramTypes == null) {
            staticSignature = Type.getMethodDescriptor(returnType, Type.typeFor(ScriptObject.class), Type.INT);
        } else {
            final Type[] params = new Type[paramTypes.length + 2];
            params[0] = Type.typeFor(ScriptObject.class);
            params[1] = Type.INT;
            int i = 2;
            for (Type type : paramTypes)  {
                if (type.isObject()) {
                    type = Type.OBJECT;
                }
                params[i++] = type;
            }
            staticSignature = Type.getMethodDescriptor(returnType, params);
        }
    }
    return staticSignature;
}
 
Example 4
Source File: SharedScopeCall.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private String getStaticSignature() {
    if (staticSignature == null) {
        if (paramTypes == null) {
            staticSignature = Type.getMethodDescriptor(returnType, Type.typeFor(ScriptObject.class), Type.INT);
        } else {
            final Type[] params = new Type[paramTypes.length + 2];
            params[0] = Type.typeFor(ScriptObject.class);
            params[1] = Type.INT;
            int i = 2;
            for (Type type : paramTypes)  {
                if (type.isObject()) {
                    type = Type.OBJECT;
                }
                params[i++] = type;
            }
            staticSignature = Type.getMethodDescriptor(returnType, params);
        }
    }
    return staticSignature;
}
 
Example 5
Source File: MethodEmitter.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        Type pt = stack.peek(pos++);
        // "erase" specific ScriptObject subtype info - except for NativeArray.
        // NativeArray is used for array/List/Deque conversion for Java calls.
        if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
            !NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
            pt = Type.SCRIPT_OBJECT;
        }
        paramTypes[i] = pt;
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example 6
Source File: MethodEmitter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        Type pt = stack.peek(pos++);
        // "erase" specific ScriptObject subtype info - except for NativeArray.
        // NativeArray is used for array/List/Deque conversion for Java calls.
        if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
            !NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
            pt = Type.SCRIPT_OBJECT;
        }
        paramTypes[i] = pt;
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example 7
Source File: MethodEmitter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        Type pt = stack.peek(pos++);
        // "erase" specific ScriptObject subtype info - except for NativeArray.
        // NativeArray is used for array/List/Deque conversion for Java calls.
        if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
            !NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
            pt = Type.SCRIPT_OBJECT;
        }
        paramTypes[i] = pt;
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example 8
Source File: MethodEmitter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        Type pt = stack.peek(pos++);
        // "erase" specific ScriptObject subtype info - except for NativeArray.
        // NativeArray is used for array/List/Deque conversion for Java calls.
        if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
            !NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
            pt = Type.SCRIPT_OBJECT;
        }
        paramTypes[i] = pt;
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example 9
Source File: MethodEmitter.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        Type pt = stack.peek(pos++);
        // "erase" specific ScriptObject subtype info - except for NativeArray.
        // NativeArray is used for array/List/Deque conversion for Java calls.
        if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
            !NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
            pt = Type.SCRIPT_OBJECT;
        }
        paramTypes[i] = pt;
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example 10
Source File: MethodEmitter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        Type pt = stack.peek(pos++);
        // "erase" specific ScriptObject subtype info - except for NativeArray.
        // NativeArray is used for array/List/Deque conversion for Java calls.
        if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
            !NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
            pt = Type.SCRIPT_OBJECT;
        }
        paramTypes[i] = pt;
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example 11
Source File: SharedScopeCall.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private String getStaticSignature() {
    if (staticSignature == null) {
        if (paramTypes == null) {
            staticSignature = Type.getMethodDescriptor(returnType, Type.typeFor(ScriptObject.class), Type.INT);
        } else {
            final Type[] params = new Type[paramTypes.length + 2];
            params[0] = Type.typeFor(ScriptObject.class);
            params[1] = Type.INT;
            System.arraycopy(paramTypes, 0, params, 2, paramTypes.length);
            staticSignature = Type.getMethodDescriptor(returnType, params);
        }
    }
    return staticSignature;
}
 
Example 12
Source File: SharedScopeCall.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private String getStaticSignature() {
    if (staticSignature == null) {
        if (paramTypes == null) {
            staticSignature = Type.getMethodDescriptor(returnType, Type.typeFor(ScriptObject.class), Type.INT);
        } else {
            final Type[] params = new Type[paramTypes.length + 2];
            params[0] = Type.typeFor(ScriptObject.class);
            params[1] = Type.INT;
            System.arraycopy(paramTypes, 0, params, 2, paramTypes.length);
            staticSignature = Type.getMethodDescriptor(returnType, params);
        }
    }
    return staticSignature;
}
 
Example 13
Source File: MethodEmitter.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        paramTypes[i] = stack.peek(pos++);
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example 14
Source File: SharedScopeCall.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private String getStaticSignature() {
    if (staticSignature == null) {
        if (paramTypes == null) {
            staticSignature = Type.getMethodDescriptor(returnType, Type.typeFor(ScriptObject.class), Type.INT);
        } else {
            final Type[] params = new Type[paramTypes.length + 2];
            params[0] = Type.typeFor(ScriptObject.class);
            params[1] = Type.INT;
            System.arraycopy(paramTypes, 0, params, 2, paramTypes.length);
            staticSignature = Type.getMethodDescriptor(returnType, params);
        }
    }
    return staticSignature;
}
 
Example 15
Source File: MethodEmitter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        paramTypes[i] = stack.peek(pos++);
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example 16
Source File: MethodEmitter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Dynamic getter for indexed structures. Pop index and receiver from stack,
 * generate appropriate signatures based on types
 *
 * @param result result type for getter
 * @param flags call site flags for getter
 * @param isMethod should it prefer retrieving methods
 *
 * @return the method emitter
 */
MethodEmitter dynamicGetIndex(final Type result, final int flags, final boolean isMethod) {
    debug("dynamic_get_index", peekType(1), "[", peekType(), "]");

    Type resultType = result;
    if (result.isBoolean()) {
        resultType = Type.OBJECT; // INT->OBJECT to avoid another dimension of cross products in the getters. TODO
    }

    Type index = peekType();
    if (index.isObject() || index.isBoolean()) {
        index = Type.OBJECT; //e.g. string->object
        convert(Type.OBJECT);
    }
    popType();

    popType(Type.OBJECT);

    final String signature = Type.getMethodDescriptor(resultType, Type.OBJECT /*e.g STRING->OBJECT*/, index);

    method.visitInvokeDynamicInsn(isMethod ? "dyn:getMethod|getElem|getProp" : "dyn:getElem|getProp|getMethod",
            signature, LINKERBOOTSTRAP, flags);
    pushType(resultType);

    if (result.isBoolean()) {
        convert(Type.BOOLEAN);
    }

    return this;
}
 
Example 17
Source File: SharedScopeCall.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private String getStaticSignature() {
    if (staticSignature == null) {
        if (paramTypes == null) {
            staticSignature = Type.getMethodDescriptor(returnType, Type.typeFor(ScriptObject.class), Type.INT);
        } else {
            final Type[] params = new Type[paramTypes.length + 2];
            params[0] = Type.typeFor(ScriptObject.class);
            params[1] = Type.INT;
            System.arraycopy(paramTypes, 0, params, 2, paramTypes.length);
            staticSignature = Type.getMethodDescriptor(returnType, params);
        }
    }
    return staticSignature;
}
 
Example 18
Source File: MethodEmitter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        paramTypes[i] = stack.peek(pos++);
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example 19
Source File: MethodEmitter.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Dynamic getter for indexed structures. Pop index and receiver from stack,
 * generate appropriate signatures based on types
 *
 * @param result result type for getter
 * @param flags call site flags for getter
 * @param isMethod should it prefer retrieving methods
 *
 * @return the method emitter
 */
MethodEmitter dynamicGetIndex(final Type result, final int flags, final boolean isMethod) {
    debug("dynamic_get_index", peekType(1), "[", peekType(), "]");

    Type resultType = result;
    if (result.isBoolean()) {
        resultType = Type.OBJECT; // INT->OBJECT to avoid another dimension of cross products in the getters. TODO
    }

    Type index = peekType();
    if (index.isObject() || index.isBoolean()) {
        index = Type.OBJECT; //e.g. string->object
        convert(Type.OBJECT);
    }
    popType();

    popType(Type.OBJECT);

    final String signature = Type.getMethodDescriptor(resultType, Type.OBJECT /*e.g STRING->OBJECT*/, index);

    method.visitInvokeDynamicInsn(isMethod ? "dyn:getMethod|getElem|getProp" : "dyn:getElem|getProp|getMethod",
            signature, LINKERBOOTSTRAP, flags);
    pushType(resultType);

    if (result.isBoolean()) {
        convert(Type.BOOLEAN);
    }

    return this;
}
 
Example 20
Source File: SharedScopeCall.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private String getStaticSignature() {
    if (staticSignature == null) {
        if (paramTypes == null) {
            staticSignature = Type.getMethodDescriptor(returnType, Type.typeFor(ScriptObject.class), Type.INT);
        } else {
            final Type[] params = new Type[paramTypes.length + 2];
            params[0] = Type.typeFor(ScriptObject.class);
            params[1] = Type.INT;
            System.arraycopy(paramTypes, 0, params, 2, paramTypes.length);
            staticSignature = Type.getMethodDescriptor(returnType, params);
        }
    }
    return staticSignature;
}