jdk.nashorn.internal.codegen.types.ArrayType Java Examples

The following examples show how to use jdk.nashorn.internal.codegen.types.ArrayType. 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: LiteralNode.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayType getArrayType(final Type elementType) {
    if (elementType.isInteger()) {
        return Type.INT_ARRAY;
    } else if (elementType.isNumeric()) {
        return Type.NUMBER_ARRAY;
    } else {
        return Type.OBJECT_ARRAY;
    }
}
 
Example #2
Source File: LiteralNode.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayType getArrayType(final Type elementType) {
    if (elementType.isInteger()) {
        return Type.INT_ARRAY;
    } else if (elementType.isNumeric()) {
        return Type.NUMBER_ARRAY;
    } else {
        return Type.OBJECT_ARRAY;
    }
}
 
Example #3
Source File: LiteralNode.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the array element type as Java format, e.g. [I
 * @return array element type
 */
public ArrayType getArrayType() {
    if (elementType.isInteger()) {
        return Type.INT_ARRAY;
    } else if (elementType.isLong()) {
        return Type.LONG_ARRAY;
    } else if (elementType.isNumeric()) {
        return Type.NUMBER_ARRAY;
    } else {
        return Type.OBJECT_ARRAY;
    }
}
 
Example #4
Source File: LiteralNode.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the array element type as Java format, e.g. [I
 * @return array element type
 */
public ArrayType getArrayType() {
    if (elementType.isInteger()) {
        return Type.INT_ARRAY;
    } else if (elementType.isLong()) {
        return Type.LONG_ARRAY;
    } else if (elementType.isNumeric()) {
        return Type.NUMBER_ARRAY;
    } else {
        return Type.OBJECT_ARRAY;
    }
}
 
Example #5
Source File: LiteralNode.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayType getArrayType(final Type elementType) {
    if (elementType.isInteger()) {
        return Type.INT_ARRAY;
    } else if (elementType.isNumeric()) {
        return Type.NUMBER_ARRAY;
    } else {
        return Type.OBJECT_ARRAY;
    }
}
 
Example #6
Source File: LiteralNode.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayType getArrayType(final Type elementType) {
    if (elementType.isInteger()) {
        return Type.INT_ARRAY;
    } else if (elementType.isNumeric()) {
        return Type.NUMBER_ARRAY;
    } else {
        return Type.OBJECT_ARRAY;
    }
}
 
Example #7
Source File: LiteralNode.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayType getArrayType(final Type elementType) {
    if (elementType.isInteger()) {
        return Type.INT_ARRAY;
    } else if (elementType.isNumeric()) {
        return Type.NUMBER_ARRAY;
    } else {
        return Type.OBJECT_ARRAY;
    }
}
 
Example #8
Source File: LiteralNode.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayType getArrayType(final Type elementType) {
    if (elementType.isInteger()) {
        return Type.INT_ARRAY;
    } else if (elementType.isNumeric()) {
        return Type.NUMBER_ARRAY;
    } else {
        return Type.OBJECT_ARRAY;
    }
}
 
Example #9
Source File: LiteralNode.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayType getArrayType(final Type elementType) {
    if (elementType.isInteger()) {
        return Type.INT_ARRAY;
    } else if (elementType.isLong()) {
        return Type.LONG_ARRAY;
    } else if (elementType.isNumeric()) {
        return Type.NUMBER_ARRAY;
    } else {
        return Type.OBJECT_ARRAY;
    }
}
 
Example #10
Source File: CodeGenerator.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
private MethodEmitter globalAllocateArray(final ArrayType type) {
    //make sure the native array is treated as an array type
    return method.invokestatic(GLOBAL_OBJECT, "allocate", "(" + type.getDescriptor() + ")Ljdk/nashorn/internal/objects/NativeArray;");
}
 
Example #11
Source File: CodeGenerator.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Load a list of nodes as an array of a specific type
 * The array will contain the visited nodes.
 *
 * @param arrayLiteralNode the array of contents
 * @param arrayType        the type of the array, e.g. ARRAY_NUMBER or ARRAY_OBJECT
 *
 * @return the method generator that was used
 */
private MethodEmitter loadArray(final ArrayLiteralNode arrayLiteralNode, final ArrayType arrayType) {
    assert arrayType == Type.INT_ARRAY || arrayType == Type.LONG_ARRAY || arrayType == Type.NUMBER_ARRAY || arrayType == Type.OBJECT_ARRAY;

    final Expression[]    nodes    = arrayLiteralNode.getValue();
    final Object          presets  = arrayLiteralNode.getPresets();
    final int[]           postsets = arrayLiteralNode.getPostsets();
    final Class<?>        type     = arrayType.getTypeClass();
    final List<ArrayUnit> units    = arrayLiteralNode.getUnits();

    loadConstant(presets);

    final Type elementType = arrayType.getElementType();

    if (units != null) {
        final MethodEmitter savedMethod     = method;
        final FunctionNode  currentFunction = lc.getCurrentFunction();

        for (final ArrayUnit arrayUnit : units) {
            unit = lc.pushCompileUnit(arrayUnit.getCompileUnit());

            final String className = unit.getUnitClassName();
            final String name      = currentFunction.uniqueName(SPLIT_PREFIX.symbolName());
            final String signature = methodDescriptor(type, ScriptFunction.class, Object.class, ScriptObject.class, type);

            final MethodEmitter me = unit.getClassEmitter().method(EnumSet.of(Flag.PUBLIC, Flag.STATIC), name, signature);
            method = lc.pushMethodEmitter(me);

            method.setFunctionNode(currentFunction);
            method.begin();

            fixScopeSlot(currentFunction);

            method.load(arrayType, SPLIT_ARRAY_ARG.slot());

            for (int i = arrayUnit.getLo(); i < arrayUnit.getHi(); i++) {
                storeElement(nodes, elementType, postsets[i]);
            }

            method._return();
            method.end();
            method = lc.popMethodEmitter(me);

            assert method == savedMethod;
            method.loadCompilerConstant(CALLEE);
            method.swap();
            method.loadCompilerConstant(THIS);
            method.swap();
            method.loadCompilerConstant(SCOPE);
            method.swap();
            method.invokestatic(className, name, signature);

            unit = lc.popCompileUnit(unit);
        }

        return method;
    }

    for (final int postset : postsets) {
        storeElement(nodes, elementType, postset);
    }

    return method;
}
 
Example #12
Source File: CodeGenerator.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private MethodEmitter globalAllocateArray(final ArrayType type) {
    //make sure the native array is treated as an array type
    return method.invokestatic(GLOBAL_OBJECT, "allocate", "(" + type.getDescriptor() + ")Ljdk/nashorn/internal/objects/NativeArray;");
}
 
Example #13
Source File: CodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Load a list of nodes as an array of a specific type
 * The array will contain the visited nodes.
 *
 * @param arrayLiteralNode the array of contents
 * @param arrayType        the type of the array, e.g. ARRAY_NUMBER or ARRAY_OBJECT
 *
 * @return the method generator that was used
 */
private MethodEmitter loadArray(final ArrayLiteralNode arrayLiteralNode, final ArrayType arrayType) {
    assert arrayType == Type.INT_ARRAY || arrayType == Type.LONG_ARRAY || arrayType == Type.NUMBER_ARRAY || arrayType == Type.OBJECT_ARRAY;

    final Expression[]    nodes    = arrayLiteralNode.getValue();
    final Object          presets  = arrayLiteralNode.getPresets();
    final int[]           postsets = arrayLiteralNode.getPostsets();
    final Class<?>        type     = arrayType.getTypeClass();
    final List<ArrayUnit> units    = arrayLiteralNode.getUnits();

    loadConstant(presets);

    final Type elementType = arrayType.getElementType();

    if (units != null) {
        final MethodEmitter savedMethod     = method;
        final FunctionNode  currentFunction = lc.getCurrentFunction();

        for (final ArrayUnit arrayUnit : units) {
            unit = lc.pushCompileUnit(arrayUnit.getCompileUnit());

            final String className = unit.getUnitClassName();
            final String name      = currentFunction.uniqueName(SPLIT_PREFIX.symbolName());
            final String signature = methodDescriptor(type, ScriptFunction.class, Object.class, ScriptObject.class, type);

            final MethodEmitter me = unit.getClassEmitter().method(EnumSet.of(Flag.PUBLIC, Flag.STATIC), name, signature);
            method = lc.pushMethodEmitter(me);

            method.setFunctionNode(currentFunction);
            method.begin();

            fixScopeSlot(currentFunction);

            method.load(arrayType, SPLIT_ARRAY_ARG.slot());

            for (int i = arrayUnit.getLo(); i < arrayUnit.getHi(); i++) {
                storeElement(nodes, elementType, postsets[i]);
            }

            method._return();
            method.end();
            method = lc.popMethodEmitter(me);

            assert method == savedMethod;
            method.loadCompilerConstant(CALLEE);
            method.swap();
            method.loadCompilerConstant(THIS);
            method.swap();
            method.loadCompilerConstant(SCOPE);
            method.swap();
            method.invokestatic(className, name, signature);

            unit = lc.popCompileUnit(unit);
        }

        return method;
    }

    for (final int postset : postsets) {
        storeElement(nodes, elementType, postset);
    }

    return method;
}
 
Example #14
Source File: CodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private MethodEmitter globalAllocateArray(final ArrayType type) {
    //make sure the native array is treated as an array type
    return method.invokestatic(GLOBAL_OBJECT, "allocate", "(" + type.getDescriptor() + ")Ljdk/nashorn/internal/objects/NativeArray;");
}
 
Example #15
Source File: CodeGenerator.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Load a list of nodes as an array of a specific type
 * The array will contain the visited nodes.
 *
 * @param arrayLiteralNode the array of contents
 * @param arrayType        the type of the array, e.g. ARRAY_NUMBER or ARRAY_OBJECT
 *
 * @return the method generator that was used
 */
private MethodEmitter loadArray(final ArrayLiteralNode arrayLiteralNode, final ArrayType arrayType) {
    assert arrayType == Type.INT_ARRAY || arrayType == Type.LONG_ARRAY || arrayType == Type.NUMBER_ARRAY || arrayType == Type.OBJECT_ARRAY;

    final Expression[]    nodes    = arrayLiteralNode.getValue();
    final Object          presets  = arrayLiteralNode.getPresets();
    final int[]           postsets = arrayLiteralNode.getPostsets();
    final Class<?>        type     = arrayType.getTypeClass();
    final List<ArrayUnit> units    = arrayLiteralNode.getUnits();

    loadConstant(presets);

    final Type elementType = arrayType.getElementType();

    if (units != null) {
        final MethodEmitter savedMethod     = method;
        final FunctionNode  currentFunction = lc.getCurrentFunction();

        for (final ArrayUnit arrayUnit : units) {
            unit = lc.pushCompileUnit(arrayUnit.getCompileUnit());

            final String className = unit.getUnitClassName();
            final String name      = currentFunction.uniqueName(SPLIT_PREFIX.symbolName());
            final String signature = methodDescriptor(type, ScriptFunction.class, Object.class, ScriptObject.class, type);

            final MethodEmitter me = unit.getClassEmitter().method(EnumSet.of(Flag.PUBLIC, Flag.STATIC), name, signature);
            method = lc.pushMethodEmitter(me);

            method.setFunctionNode(currentFunction);
            method.begin();

            fixScopeSlot(currentFunction);

            method.load(arrayType, SPLIT_ARRAY_ARG.slot());

            for (int i = arrayUnit.getLo(); i < arrayUnit.getHi(); i++) {
                storeElement(nodes, elementType, postsets[i]);
            }

            method._return();
            method.end();
            method = lc.popMethodEmitter(me);

            assert method == savedMethod;
            method.loadCompilerConstant(CALLEE);
            method.swap();
            method.loadCompilerConstant(THIS);
            method.swap();
            method.loadCompilerConstant(SCOPE);
            method.swap();
            method.invokestatic(className, name, signature);

            unit = lc.popCompileUnit(unit);
        }

        return method;
    }

    for (final int postset : postsets) {
        storeElement(nodes, elementType, postset);
    }

    return method;
}
 
Example #16
Source File: MethodEmitter.java    From jdk8u_nashorn with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a new array given a length that is popped
 * from the stack and the array type
 *
 * @param arrayType the type of the array
 *
 * @return the method emitter
 */
MethodEmitter newarray(final ArrayType arrayType) {
    debug("newarray ", "arrayType=", arrayType);
    popType(Type.INT); //LENGTH
    pushType(arrayType.newarray(method));
    return this;
}
 
Example #17
Source File: MethodEmitter.java    From jdk8u_nashorn with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a multidimensional array with a given number of dimensions.
 * On the stack are dim lengths of the sub arrays.
 *
 * @param arrayType type of the array
 * @param dims      number of dimensions
 *
 * @return the method emitter
 */
MethodEmitter multinewarray(final ArrayType arrayType, final int dims) {
    debug("multianewarray ", arrayType, dims);
    for (int i = 0; i < dims; i++) {
        popType(Type.INT); //LENGTH
    }
    pushType(arrayType.newarray(method, dims));
    return this;
}
 
Example #18
Source File: MethodEmitter.java    From nashorn with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a new array given a length that is popped
 * from the stack and the array type
 *
 * @param arrayType the type of the array
 *
 * @return the method emitter
 */
MethodEmitter newarray(final ArrayType arrayType) {
    debug("newarray ", "arrayType=", arrayType);
    popType(Type.INT); //LENGTH
    pushType(arrayType.newarray(method));
    return this;
}
 
Example #19
Source File: MethodEmitter.java    From nashorn with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a multidimensional array with a given number of dimensions.
 * On the stack are dim lengths of the sub arrays.
 *
 * @param arrayType type of the array
 * @param dims      number of dimensions
 *
 * @return the method emitter
 */
MethodEmitter multinewarray(final ArrayType arrayType, final int dims) {
    debug("multianewarray ", arrayType, dims);
    for (int i = 0; i < dims; i++) {
        popType(Type.INT); //LENGTH
    }
    pushType(arrayType.newarray(method, dims));
    return this;
}
 
Example #20
Source File: MethodEmitter.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a multidimensional array with a given number of dimensions.
 * On the stack are dim lengths of the sub arrays.
 *
 * @param arrayType type of the array
 * @param dims      number of dimensions
 *
 * @return the method emitter
 */
MethodEmitter multinewarray(final ArrayType arrayType, final int dims) {
    debug("multianewarray ", arrayType, dims);
    for (int i = 0; i < dims; i++) {
        popType(Type.INT); //LENGTH
    }
    pushType(arrayType.newarray(method, dims));
    return this;
}
 
Example #21
Source File: MethodEmitter.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a new array given a length that is popped
 * from the stack and the array type
 *
 * @param arrayType the type of the array
 *
 * @return the method emitter
 */
MethodEmitter newarray(final ArrayType arrayType) {
    debug("newarray ", "arrayType=", arrayType);
    popType(Type.INT); //LENGTH
    pushType(arrayType.newarray(method));
    return this;
}
 
Example #22
Source File: MethodEmitter.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a new array given a length that is popped
 * from the stack and the array type
 *
 * @param arrayType the type of the array
 *
 * @return the method emitter
 */
MethodEmitter newarray(final ArrayType arrayType) {
    debug("newarray ", "arrayType=", arrayType);
    popType(Type.INT); //LENGTH
    pushType(arrayType.newarray(method));
    return this;
}
 
Example #23
Source File: MethodEmitter.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a multidimensional array with a given number of dimensions.
 * On the stack are dim lengths of the sub arrays.
 *
 * @param arrayType type of the array
 * @param dims      number of dimensions
 *
 * @return the method emitter
 */
MethodEmitter multinewarray(final ArrayType arrayType, final int dims) {
    debug("multianewarray ", arrayType, dims);
    for (int i = 0; i < dims; i++) {
        popType(Type.INT); //LENGTH
    }
    pushType(arrayType.newarray(method, dims));
    return this;
}
 
Example #24
Source File: MethodEmitter.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a new array given a length that is popped
 * from the stack and the array type
 *
 * @param arrayType the type of the array
 *
 * @return the method emitter
 */
MethodEmitter newarray(final ArrayType arrayType) {
    debug("newarray ", "arrayType=", arrayType);
    popType(Type.INT); //LENGTH
    pushType(arrayType.newarray(method));
    return this;
}
 
Example #25
Source File: MethodEmitter.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a new array given a length that is popped
 * from the stack and the array type
 *
 * @param arrayType the type of the array
 *
 * @return the method emitter
 */
MethodEmitter newarray(final ArrayType arrayType) {
    debug("newarray ", "arrayType=", arrayType);
    popType(Type.INT); //LENGTH
    pushType(arrayType.newarray(method));
    return this;
}
 
Example #26
Source File: MethodEmitter.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a multidimensional array with a given number of dimensions.
 * On the stack are dim lengths of the sub arrays.
 *
 * @param arrayType type of the array
 * @param dims      number of dimensions
 *
 * @return the method emitter
 */
MethodEmitter multinewarray(final ArrayType arrayType, final int dims) {
    debug("multianewarray ", arrayType, dims);
    for (int i = 0; i < dims; i++) {
        popType(Type.INT); //LENGTH
    }
    pushType(arrayType.newarray(method, dims));
    return this;
}
 
Example #27
Source File: MethodEmitter.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a new array given a length that is popped
 * from the stack and the array type
 *
 * @param arrayType the type of the array
 *
 * @return the method emitter
 */
MethodEmitter newarray(final ArrayType arrayType) {
    debug("newarray ", "arrayType=", arrayType);
    popType(Type.INT); //LENGTH
    pushType(arrayType.newarray(method));
    return this;
}
 
Example #28
Source File: MethodEmitter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a new array given a length that is popped
 * from the stack and the array type
 *
 * @param arrayType the type of the array
 *
 * @return the method emitter
 */
MethodEmitter newarray(final ArrayType arrayType) {
    debug("newarray ", "arrayType=", arrayType);
    popType(Type.INT); //LENGTH
    pushType(arrayType.newarray(method));
    return this;
}
 
Example #29
Source File: MethodEmitter.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a multidimensional array with a given number of dimensions.
 * On the stack are dim lengths of the sub arrays.
 *
 * @param arrayType type of the array
 * @param dims      number of dimensions
 *
 * @return the method emitter
 */
MethodEmitter multinewarray(final ArrayType arrayType, final int dims) {
    debug("multianewarray ", arrayType, dims);
    for (int i = 0; i < dims; i++) {
        popType(Type.INT); //LENGTH
    }
    pushType(arrayType.newarray(method, dims));
    return this;
}
 
Example #30
Source File: MethodEmitter.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a new array given a length that is popped
 * from the stack and the array type
 *
 * @param arrayType the type of the array
 *
 * @return the method emitter
 */
MethodEmitter newarray(final ArrayType arrayType) {
    debug("newarray ", "arrayType=", arrayType);
    popType(Type.INT); //LENGTH
    pushType(arrayType.newarray(method));
    return this;
}