com.sun.org.apache.bcel.internal.generic.ASTORE Java Examples

The following examples show how to use com.sun.org.apache.bcel.internal.generic.ASTORE. 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 Project: jdk1.8-source-analysis   Author: raysonfang   File: MethodGenerator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to generate an instance of a subclass of
 * {@link StoreInstruction} based on the specified {@link Type} that will
 * store a value in the specified local variable
 * @param index the JVM stack frame index of the variable that is to be
 * stored
 * @param type the {@link Type} of the variable
 * @return the generated {@link StoredInstruction}
 */
private static Instruction storeLocal(int index, Type type) {
    if (type == Type.BOOLEAN) {
       return new ISTORE(index);
    } else if (type == Type.INT) {
       return new ISTORE(index);
    } else if (type == Type.SHORT) {
       return new ISTORE(index);
    } else if (type == Type.LONG) {
       return new LSTORE(index);
    } else if (type == Type.BYTE) {
       return new ISTORE(index);
    } else if (type == Type.CHAR) {
       return new ISTORE(index);
    } else if (type == Type.FLOAT) {
       return new FSTORE(index);
    } else if (type == Type.DOUBLE) {
       return new DSTORE(index);
    } else {
       return new ASTORE(index);
    }
}
 
Example #2
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: CompareGenerator.java    License: Apache License 2.0 6 votes vote down vote up
public CompareGenerator(int access_flags, Type return_type,
                        Type[] arg_types, String[] arg_names,
                        String method_name, String class_name,
                        InstructionList il, ConstantPoolGen cp) {
    super(access_flags, return_type, arg_types, arg_names, method_name,
          class_name, il, cp);

    _iloadCurrent = new ILOAD(CURRENT_INDEX);
    _istoreCurrent = new ISTORE(CURRENT_INDEX);
    _aloadDom = new ALOAD(DOM_INDEX);
    _iloadLast = new ILOAD(LAST_INDEX);

    LocalVariableGen iterator =
        addLocalVariable("iterator",
                         Util.getJCRefType(Constants.NODE_ITERATOR_SIG),
                         null, null);
    ITERATOR_INDEX = iterator.getIndex();
    _aloadIterator = new ALOAD(ITERATOR_INDEX);
    _astoreIterator = new ASTORE(ITERATOR_INDEX);
    il.append(new ACONST_NULL());
    il.append(storeIterator());
}
 
Example #3
Source Project: TencentKona-8   Author: Tencent   File: MethodGenerator.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper method to generate an instance of a subclass of
 * {@link StoreInstruction} based on the specified {@link Type} that will
 * store a value in the specified local variable
 * @param index the JVM stack frame index of the variable that is to be
 * stored
 * @param type the {@link Type} of the variable
 * @return the generated {@link StoredInstruction}
 */
private static Instruction storeLocal(int index, Type type) {
    if (type == Type.BOOLEAN) {
       return new ISTORE(index);
    } else if (type == Type.INT) {
       return new ISTORE(index);
    } else if (type == Type.SHORT) {
       return new ISTORE(index);
    } else if (type == Type.LONG) {
       return new LSTORE(index);
    } else if (type == Type.BYTE) {
       return new ISTORE(index);
    } else if (type == Type.CHAR) {
       return new ISTORE(index);
    } else if (type == Type.FLOAT) {
       return new FSTORE(index);
    } else if (type == Type.DOUBLE) {
       return new DSTORE(index);
    } else {
       return new ASTORE(index);
    }
}
 
Example #4
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: CompareGenerator.java    License: GNU General Public License v2.0 6 votes vote down vote up
public CompareGenerator(int access_flags, Type return_type,
                        Type[] arg_types, String[] arg_names,
                        String method_name, String class_name,
                        InstructionList il, ConstantPoolGen cp) {
    super(access_flags, return_type, arg_types, arg_names, method_name,
          class_name, il, cp);

    _iloadCurrent = new ILOAD(CURRENT_INDEX);
    _istoreCurrent = new ISTORE(CURRENT_INDEX);
    _aloadDom = new ALOAD(DOM_INDEX);
    _iloadLast = new ILOAD(LAST_INDEX);

    LocalVariableGen iterator =
        addLocalVariable("iterator",
                         Util.getJCRefType(Constants.NODE_ITERATOR_SIG),
                         null, null);
    ITERATOR_INDEX = iterator.getIndex();
    _aloadIterator = new ALOAD(ITERATOR_INDEX);
    _astoreIterator = new ASTORE(ITERATOR_INDEX);
    il.append(new ACONST_NULL());
    il.append(storeIterator());
}
 
Example #5
Source Project: jdk8u60   Author: chenghanpeng   File: CompareGenerator.java    License: GNU General Public License v2.0 6 votes vote down vote up
public CompareGenerator(int access_flags, Type return_type,
                        Type[] arg_types, String[] arg_names,
                        String method_name, String class_name,
                        InstructionList il, ConstantPoolGen cp) {
    super(access_flags, return_type, arg_types, arg_names, method_name,
          class_name, il, cp);

    _iloadCurrent = new ILOAD(CURRENT_INDEX);
    _istoreCurrent = new ISTORE(CURRENT_INDEX);
    _aloadDom = new ALOAD(DOM_INDEX);
    _iloadLast = new ILOAD(LAST_INDEX);

    LocalVariableGen iterator =
        addLocalVariable("iterator",
                         Util.getJCRefType(Constants.NODE_ITERATOR_SIG),
                         null, null);
    ITERATOR_INDEX = iterator.getIndex();
    _aloadIterator = new ALOAD(ITERATOR_INDEX);
    _astoreIterator = new ASTORE(ITERATOR_INDEX);
    il.append(new ACONST_NULL());
    il.append(storeIterator());
}
 
Example #6
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: TestGenerator.java    License: MIT License 5 votes vote down vote up
public TestGenerator(int access_flags, Type return_type,
                     Type[] arg_types, String[] arg_names,
                     String method_name, String class_name,
                     InstructionList il, ConstantPoolGen cp) {
    super(access_flags, return_type, arg_types, arg_names, method_name,
          class_name, il, cp);

    _iloadCurrent  = new ILOAD(CURRENT_NODE_INDEX);
    _istoreCurrent = new ISTORE(CURRENT_NODE_INDEX);
    _iloadContext  = new ILOAD(CONTEXT_NODE_INDEX);
    _istoreContext  = new ILOAD(CONTEXT_NODE_INDEX);
    _astoreIterator = new ASTORE(ITERATOR_INDEX);
    _aloadIterator  = new ALOAD(ITERATOR_INDEX);
}
 
Example #7
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: TestGenerator.java    License: Apache License 2.0 5 votes vote down vote up
public TestGenerator(int access_flags, Type return_type,
                     Type[] arg_types, String[] arg_names,
                     String method_name, String class_name,
                     InstructionList il, ConstantPoolGen cp) {
    super(access_flags, return_type, arg_types, arg_names, method_name,
          class_name, il, cp);

    _iloadCurrent  = new ILOAD(CURRENT_NODE_INDEX);
    _istoreCurrent = new ISTORE(CURRENT_NODE_INDEX);
    _iloadContext  = new ILOAD(CONTEXT_NODE_INDEX);
    _istoreContext  = new ILOAD(CONTEXT_NODE_INDEX);
    _astoreIterator = new ASTORE(ITERATOR_INDEX);
    _aloadIterator  = new ALOAD(ITERATOR_INDEX);
}
 
Example #8
Source Project: TencentKona-8   Author: Tencent   File: TestGenerator.java    License: GNU General Public License v2.0 5 votes vote down vote up
public TestGenerator(int access_flags, Type return_type,
                     Type[] arg_types, String[] arg_names,
                     String method_name, String class_name,
                     InstructionList il, ConstantPoolGen cp) {
    super(access_flags, return_type, arg_types, arg_names, method_name,
          class_name, il, cp);

    _iloadCurrent  = new ILOAD(CURRENT_NODE_INDEX);
    _istoreCurrent = new ISTORE(CURRENT_NODE_INDEX);
    _iloadContext  = new ILOAD(CONTEXT_NODE_INDEX);
    _istoreContext  = new ILOAD(CONTEXT_NODE_INDEX);
    _astoreIterator = new ASTORE(ITERATOR_INDEX);
    _aloadIterator  = new ALOAD(ITERATOR_INDEX);
}
 
Example #9
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: RtMethodGenerator.java    License: MIT License 5 votes vote down vote up
public RtMethodGenerator(int access_flags, Type return_type,
                         Type[] arg_types, String[] arg_names,
                         String method_name, String class_name,
                         InstructionList il, ConstantPoolGen cp) {
    super(access_flags, return_type, arg_types, arg_names, method_name,
          class_name, il, cp);

    _astoreHandler = new ASTORE(HANDLER_INDEX);
    _aloadHandler  = new ALOAD(HANDLER_INDEX);
}
 
Example #10
Source Project: jdk8u60   Author: chenghanpeng   File: RtMethodGenerator.java    License: GNU General Public License v2.0 5 votes vote down vote up
public RtMethodGenerator(int access_flags, Type return_type,
                         Type[] arg_types, String[] arg_names,
                         String method_name, String class_name,
                         InstructionList il, ConstantPoolGen cp) {
    super(access_flags, return_type, arg_types, arg_names, method_name,
          class_name, il, cp);

    _astoreHandler = new ASTORE(HANDLER_INDEX);
    _aloadHandler  = new ALOAD(HANDLER_INDEX);
}
 
Example #11
Source Project: jdk8u60   Author: chenghanpeng   File: TestGenerator.java    License: GNU General Public License v2.0 5 votes vote down vote up
public TestGenerator(int access_flags, Type return_type,
                     Type[] arg_types, String[] arg_names,
                     String method_name, String class_name,
                     InstructionList il, ConstantPoolGen cp) {
    super(access_flags, return_type, arg_types, arg_names, method_name,
          class_name, il, cp);

    _iloadCurrent  = new ILOAD(CURRENT_NODE_INDEX);
    _istoreCurrent = new ISTORE(CURRENT_NODE_INDEX);
    _iloadContext  = new ILOAD(CONTEXT_NODE_INDEX);
    _istoreContext  = new ILOAD(CONTEXT_NODE_INDEX);
    _astoreIterator = new ASTORE(ITERATOR_INDEX);
    _aloadIterator  = new ALOAD(ITERATOR_INDEX);
}
 
Example #12
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: Copy.java    License: Apache License 2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    final LocalVariableGen name =
        methodGen.addLocalVariable2("name",
                                    Util.getJCRefType(STRING_SIG),
                                    null);
    final LocalVariableGen length =
        methodGen.addLocalVariable2("length",
                                    Util.getJCRefType("I"),
                                    null);

    // Get the name of the node to copy and save for later
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadCurrentNode());
    il.append(methodGen.loadHandler());
    final int cpy = cpg.addInterfaceMethodref(DOM_INTF,
                                              "shallowCopy",
                                              "("
                                              + NODE_SIG
                                              + TRANSLET_OUTPUT_SIG
                                              + ")" + STRING_SIG);
    il.append(new INVOKEINTERFACE(cpy, 3));
    il.append(DUP);
    name.setStart(il.append(new ASTORE(name.getIndex())));
    final BranchHandle ifBlock1 = il.append(new IFNULL(null));

    // Get the length of the node name and save for later
    il.append(new ALOAD(name.getIndex()));
    final int lengthMethod = cpg.addMethodref(STRING_CLASS,"length","()I");
    il.append(new INVOKEVIRTUAL(lengthMethod));
    il.append(DUP);
    length.setStart(il.append(new ISTORE(length.getIndex())));

    // Ignore attribute sets if current node is ROOT. DOM.shallowCopy()
    // returns "" for ROOT, so skip attribute sets if length == 0
    final BranchHandle ifBlock4 = il.append(new IFEQ(null));

    // Copy in attribute sets if specified
    if (_useSets != null) {
        // If the parent of this element will result in an element being
        // output then we know that it is safe to copy out the attributes
        final SyntaxTreeNode parent = getParent();
        if ((parent instanceof LiteralElement) ||
            (parent instanceof LiteralElement)) {
            _useSets.translate(classGen, methodGen);
        }
        // If not we have to check to see if the copy will result in an
        // element being output.
        else {
            // check if element; if not skip to translate body
            il.append(new ILOAD(length.getIndex()));
            final BranchHandle ifBlock2 = il.append(new IFEQ(null));
            // length != 0 -> element -> do attribute sets
            _useSets.translate(classGen, methodGen);
            // not an element; root
            ifBlock2.setTarget(il.append(NOP));
        }
    }

    // Instantiate body of xsl:copy
    ifBlock4.setTarget(il.append(NOP));
    translateContents(classGen, methodGen);

    // Call the output handler's endElement() if we copied an element
    // (The DOM.shallowCopy() method calls startElement().)
    length.setEnd(il.append(new ILOAD(length.getIndex())));
    final BranchHandle ifBlock3 = il.append(new IFEQ(null));
    il.append(methodGen.loadHandler());
    name.setEnd(il.append(new ALOAD(name.getIndex())));
    il.append(methodGen.endElement());

    final InstructionHandle end = il.append(NOP);
    ifBlock1.setTarget(end);
    ifBlock3.setTarget(end);
    methodGen.removeLocalVariable(name);
    methodGen.removeLocalVariable(length);
}
 
Example #13
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: FilteredAbsoluteLocationPath.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    if (_path != null) {
        final int initDFI = cpg.addMethodref(DUP_FILTERED_ITERATOR,
                                            "<init>",
                                            "("
                                            + NODE_ITERATOR_SIG
                                            + ")V");

        // Backwards branches are prohibited if an uninitialized object is
        // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
        // We don't know whether this code might contain backwards branches,
        // so we mustn't create the new object until after we've created
        // the suspect arguments to its constructor.  Instead we calculate
        // the values of the arguments to the constructor first, store them
        // in temporary variables, create the object and reload the
        // arguments from the temporaries to avoid the problem.

        // Compile relative path iterator(s)
        LocalVariableGen pathTemp =
           methodGen.addLocalVariable("filtered_absolute_location_path_tmp",
                                      Util.getJCRefType(NODE_ITERATOR_SIG),
                                      null, null);
        _path.translate(classGen, methodGen);
        pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));

        // Create new Dup Filter Iterator
        il.append(new NEW(cpg.addClass(DUP_FILTERED_ITERATOR)));
        il.append(DUP);
        pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));

        // Initialize Dup Filter Iterator with iterator from the stack
        il.append(new INVOKESPECIAL(initDFI));
    }
    else {
        final int git = cpg.addInterfaceMethodref(DOM_INTF,
                                                  "getIterator",
                                                  "()"+NODE_ITERATOR_SIG);
        il.append(methodGen.loadDOM());
        il.append(new INVOKEINTERFACE(git, 1));
    }
}
 
Example #14
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: ResultTreeType.java    License: MIT License 4 votes vote down vote up
public Instruction STORE(int slot) {
    return new ASTORE(slot);
}
 
Example #15
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: Number.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * This method compiles code that is common to matchesFrom() and
 * matchesCount() in the auxillary class.
 */
private void compileLocals(NodeCounterGenerator nodeCounterGen,
                           MatchGenerator matchGen,
                           InstructionList il)
{
    int field;
    LocalVariableGen local;
    ConstantPoolGen cpg = nodeCounterGen.getConstantPool();

    // Get NodeCounter._iterator and store locally
    local = matchGen.addLocalVariable("iterator",
                                      Util.getJCRefType(NODE_ITERATOR_SIG),
                                      null, null);
    field = cpg.addFieldref(NODE_COUNTER, "_iterator",
                            ITERATOR_FIELD_SIG);
    il.append(ALOAD_0); // 'this' pointer on stack
    il.append(new GETFIELD(field));
    local.setStart(il.append(new ASTORE(local.getIndex())));
    matchGen.setIteratorIndex(local.getIndex());

    // Get NodeCounter._translet and store locally
    local = matchGen.addLocalVariable("translet",
                              Util.getJCRefType(TRANSLET_SIG),
                              null, null);
    field = cpg.addFieldref(NODE_COUNTER, "_translet",
                            "Lcom/sun/org/apache/xalan/internal/xsltc/Translet;");
    il.append(ALOAD_0); // 'this' pointer on stack
    il.append(new GETFIELD(field));
    il.append(new CHECKCAST(cpg.addClass(TRANSLET_CLASS)));
    local.setStart(il.append(new ASTORE(local.getIndex())));
    nodeCounterGen.setTransletIndex(local.getIndex());

    // Get NodeCounter._document and store locally
    local = matchGen.addLocalVariable("document",
                                      Util.getJCRefType(DOM_INTF_SIG),
                                      null, null);
    field = cpg.addFieldref(_className, "_document", DOM_INTF_SIG);
    il.append(ALOAD_0); // 'this' pointer on stack
    il.append(new GETFIELD(field));
    // Make sure we have the correct DOM type on the stack!!!
    local.setStart(il.append(new ASTORE(local.getIndex())));
    matchGen.setDomIndex(local.getIndex());
}
 
Example #16
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ObjectType.java    License: GNU General Public License v2.0 4 votes vote down vote up
public Instruction STORE(int slot) {
    return new ASTORE(slot);
}
 
Example #17
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: ParentLocationPath.java    License: Apache License 2.0 4 votes vote down vote up
public void translateStep(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Backwards branches are prohibited if an uninitialized object is
    // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
    // We don't know whether this code might contain backwards branches
    // so we mustn't create the new object until after we've created
    // the suspect arguments to its constructor.  Instead we calculate
    // the values of the arguments to the constructor first, store them
    // in temporary variables, create the object and reload the
    // arguments from the temporaries to avoid the problem.

    LocalVariableGen pathTemp
            = methodGen.addLocalVariable("parent_location_path_tmp1",
                                     Util.getJCRefType(NODE_ITERATOR_SIG),
                                     null, null);
    pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));

    _step.translate(classGen, methodGen);
    LocalVariableGen stepTemp
            = methodGen.addLocalVariable("parent_location_path_tmp2",
                                     Util.getJCRefType(NODE_ITERATOR_SIG),
                                     null, null);
    stepTemp.setStart(il.append(new ASTORE(stepTemp.getIndex())));

    // Create new StepIterator
    final int initSI = cpg.addMethodref(STEP_ITERATOR_CLASS,
                                        "<init>",
                                        "("
                                        +NODE_ITERATOR_SIG
                                        +NODE_ITERATOR_SIG
                                        +")V");
    il.append(new NEW(cpg.addClass(STEP_ITERATOR_CLASS)));
    il.append(DUP);

    pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));
    stepTemp.setEnd(il.append(new ALOAD(stepTemp.getIndex())));

    // Initialize StepIterator with iterators from the stack
    il.append(new INVOKESPECIAL(initSI));

    // This is a special case for the //* path with or without predicates
    Expression stp = _step;
    if (stp instanceof ParentLocationPath)
        stp = ((ParentLocationPath)stp).getStep();

    if ((_path instanceof Step) && (stp instanceof Step)) {
        final int path = ((Step)_path).getAxis();
        final int step = ((Step)stp).getAxis();
        if ((path == Axis.DESCENDANTORSELF && step == Axis.CHILD) ||
            (path == Axis.PRECEDING        && step == Axis.PARENT)) {
            final int incl = cpg.addMethodref(NODE_ITERATOR_BASE,
                                              "includeSelf",
                                              "()" + NODE_ITERATOR_SIG);
            il.append(new INVOKEVIRTUAL(incl));
        }
    }

    /*
     * If this pattern contains a sequence of descendant iterators we
     * run the risk of returning the same node several times. We put
     * a new iterator on top of the existing one to assure node order
     * and prevent returning a single node multiple times.
     */
    if (_orderNodes) {
        final int order = cpg.addInterfaceMethodref(DOM_INTF,
                                                    ORDER_ITERATOR,
                                                    ORDER_ITERATOR_SIG);
        il.append(methodGen.loadDOM());
        il.append(SWAP);
        il.append(methodGen.loadContextNode());
        il.append(new INVOKEINTERFACE(order, 3));
    }
}
 
Example #18
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: ProcessingInstruction.java    License: Apache License 2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (!_isLiteral) {
        // if the ncname is an AVT, then the ncname has to be checked at runtime if it is a valid ncname
        LocalVariableGen nameValue =
                methodGen.addLocalVariable2("nameValue",
        Util.getJCRefType(STRING_SIG),
                                            null);

        // store the name into a variable first so _name.translate only needs to be called once
        _name.translate(classGen, methodGen);
        nameValue.setStart(il.append(new ASTORE(nameValue.getIndex())));
        il.append(new ALOAD(nameValue.getIndex()));

        // call checkNCName if the name is an AVT
        final int check = cpg.addMethodref(BASIS_LIBRARY_CLASS, "checkNCName",
                            "("
                            +STRING_SIG
                            +")V");
                            il.append(new INVOKESTATIC(check));

        // Save the current handler base on the stack
        il.append(methodGen.loadHandler());
        il.append(DUP);     // first arg to "attributes" call

        // load name value again
        nameValue.setEnd(il.append(new ALOAD(nameValue.getIndex())));
    } else {
        // Save the current handler base on the stack
        il.append(methodGen.loadHandler());
        il.append(DUP);     // first arg to "attributes" call

        // Push attribute name
        _name.translate(classGen, methodGen);// 2nd arg

    }

    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS,
                                           "stringValueHandler",
                                           STRING_VALUE_HANDLER_SIG)));
    il.append(DUP);
    il.append(methodGen.storeHandler());

    // translate contents with substituted handler
    translateContents(classGen, methodGen);

    // get String out of the handler
    il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_VALUE_HANDLER,
                                                 "getValueOfPI",
                                                 "()" + STRING_SIG)));
    // call "processingInstruction"
    final int processingInstruction =
        cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
                                  "processingInstruction",
                                  "(" + STRING_SIG + STRING_SIG + ")V");
    il.append(new INVOKEINTERFACE(processingInstruction, 3));
    // Restore old handler base from stack
    il.append(methodGen.storeHandler());
}
 
Example #19
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: FilterParentPath.java    License: Apache License 2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Create new StepIterator
    final int initSI = cpg.addMethodref(STEP_ITERATOR_CLASS,
                                        "<init>",
                                        "("
                                        +NODE_ITERATOR_SIG
                                        +NODE_ITERATOR_SIG
                                        +")V");

    // Backwards branches are prohibited if an uninitialized object is
    // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
    // We don't know whether this code might contain backwards branches,
    // so we mustn't create the new object until after we've created
    // the suspect arguments to its constructor.  Instead we calculate
    // the values of the arguments to the constructor first, store them
    // in temporary variables, create the object and reload the
    // arguments from the temporaries to avoid the problem.

    // Recursively compile 2 iterators
    _filterExpr.translate(classGen, methodGen);
    LocalVariableGen filterTemp =
            methodGen.addLocalVariable("filter_parent_path_tmp1",
                                       Util.getJCRefType(NODE_ITERATOR_SIG),
                                       null, null);
    filterTemp.setStart(il.append(new ASTORE(filterTemp.getIndex())));

    _path.translate(classGen, methodGen);
    LocalVariableGen pathTemp =
            methodGen.addLocalVariable("filter_parent_path_tmp2",
                                       Util.getJCRefType(NODE_ITERATOR_SIG),
                                       null, null);
    pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));

    il.append(new NEW(cpg.addClass(STEP_ITERATOR_CLASS)));
    il.append(DUP);
    filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
    pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));

    // Initialize StepIterator with iterators from the stack
    il.append(new INVOKESPECIAL(initSI));

    // This is a special case for the //* path with or without predicates
    if (_hasDescendantAxis) {
        final int incl = cpg.addMethodref(NODE_ITERATOR_BASE,
                                          "includeSelf",
                                          "()" + NODE_ITERATOR_SIG);
        il.append(new INVOKEVIRTUAL(incl));
    }

    SyntaxTreeNode parent = getParent();

    boolean parentAlreadyOrdered =
        (parent instanceof RelativeLocationPath)
            || (parent instanceof FilterParentPath)
            || (parent instanceof KeyCall)
            || (parent instanceof CurrentCall)
            || (parent instanceof DocumentCall);

    if (!parentAlreadyOrdered) {
        final int order = cpg.addInterfaceMethodref(DOM_INTF,
                                                    ORDER_ITERATOR,
                                                    ORDER_ITERATOR_SIG);
        il.append(methodGen.loadDOM());
        il.append(SWAP);
        il.append(methodGen.loadContextNode());
        il.append(new INVOKEINTERFACE(order, 3));
    }
}
 
Example #20
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: ResultTreeType.java    License: MIT License 4 votes vote down vote up
/**
 * Expects a result tree on the stack and pushes a boxed result tree.
 * Result trees are already boxed so the translation is just a NOP.
 *
 * @param classGen A BCEL class generator
 * @param methodGen A BCEL method generator
 * @param type An instance of ReferenceType (any)
 * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
 */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
                        ReferenceType type) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_methodName == null) {
        il.append(NOP);
    }
    else {
        LocalVariableGen domBuilder, newDom;
        final String className = classGen.getClassName();
        final int current = methodGen.getLocalIndex("current");

        // Push required parameters
        il.append(classGen.loadTranslet());
        if (classGen.isExternal()) {
            il.append(new CHECKCAST(cpg.addClass(className)));
        }
        il.append(methodGen.loadDOM());

        // Create new instance of DOM class (with RTF_INITIAL_SIZE nodes)
        il.append(methodGen.loadDOM());
        int index = cpg.addInterfaceMethodref(DOM_INTF,
                             "getResultTreeFrag",
                             "(IZ)" + DOM_INTF_SIG);
        il.append(new PUSH(cpg, RTF_INITIAL_SIZE));
        il.append(new PUSH(cpg, false));
        il.append(new INVOKEINTERFACE(index,3));
        il.append(DUP);

        // Store new DOM into a local variable
        newDom = methodGen.addLocalVariable("rt_to_reference_dom",
                                            Util.getJCRefType(DOM_INTF_SIG),
                                            null, null);
        il.append(new CHECKCAST(cpg.addClass(DOM_INTF_SIG)));
        newDom.setStart(il.append(new ASTORE(newDom.getIndex())));

        // Overwrite old handler with DOM handler
        index = cpg.addInterfaceMethodref(DOM_INTF,
                             "getOutputDomBuilder",
                             "()" + TRANSLET_OUTPUT_SIG);

        il.append(new INVOKEINTERFACE(index,1));
        //index = cpg.addMethodref(DOM_IMPL,
            //                   "getOutputDomBuilder",
            //                   "()" + TRANSLET_OUTPUT_SIG);
        //il.append(new INVOKEVIRTUAL(index));
        il.append(DUP);
        il.append(DUP);

        // Store DOM handler in a local in order to call endDocument()
        domBuilder =
            methodGen.addLocalVariable("rt_to_reference_handler",
                                       Util.getJCRefType(TRANSLET_OUTPUT_SIG),
                                       null, null);
        domBuilder.setStart(il.append(new ASTORE(domBuilder.getIndex())));

        // Call startDocument on the new handler
        index = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
                                          "startDocument", "()V");
        il.append(new INVOKEINTERFACE(index, 1));

        // Call the method that implements this result tree
        index = cpg.addMethodref(className,
                                 _methodName,
                                 "("
                                 + DOM_INTF_SIG
                                 + TRANSLET_OUTPUT_SIG
                                 +")V");
        il.append(new INVOKEVIRTUAL(index));

        // Call endDocument on the DOM handler
        domBuilder.setEnd(il.append(new ALOAD(domBuilder.getIndex())));
        index = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
                                          "endDocument", "()V");
        il.append(new INVOKEINTERFACE(index, 1));

        // Push the new DOM on the stack
        newDom.setEnd(il.append(new ALOAD(newDom.getIndex())));
    }
}
 
Example #21
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: AttributeSetMethodGenerator.java    License: Apache License 2.0 4 votes vote down vote up
public Instruction storeParameter(int index) {
    return new ASTORE(index + PARAM_START_INDEX);
}
 
Example #22
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: ObjectType.java    License: Apache License 2.0 4 votes vote down vote up
public Instruction STORE(int slot) {
    return new ASTORE(slot);
}
 
Example #23
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ResultTreeType.java    License: GNU General Public License v2.0 4 votes vote down vote up
public Instruction STORE(int slot) {
    return new ASTORE(slot);
}
 
Example #24
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: NamedMethodGenerator.java    License: Apache License 2.0 4 votes vote down vote up
public Instruction storeParameter(int index) {
    return new ASTORE(index + PARAM_START_INDEX);
}
 
Example #25
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: MethodGenerator.java    License: Apache License 2.0 4 votes vote down vote up
public MethodGenerator(int access_flags, Type return_type,
                       Type[] arg_types, String[] arg_names,
                       String method_name, String class_name,
                       InstructionList il, ConstantPoolGen cpg) {
    super(access_flags, return_type, arg_types, arg_names, method_name,
          class_name, il, cpg);

    _astoreHandler  = new ASTORE(HANDLER_INDEX);
    _aloadHandler   = new ALOAD(HANDLER_INDEX);
    _astoreIterator = new ASTORE(ITERATOR_INDEX);
    _aloadIterator  = new ALOAD(ITERATOR_INDEX);
    _aloadDom       = new ALOAD(DOM_INDEX);
    _astoreDom      = new ASTORE(DOM_INDEX);

    final int startElement =
        cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
                                  "startElement",
                                  START_ELEMENT_SIG);
    _startElement = new INVOKEINTERFACE(startElement, 2);

    final int endElement =
        cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
                                  "endElement",
                                  END_ELEMENT_SIG);
    _endElement = new INVOKEINTERFACE(endElement, 2);

    final int attribute =
        cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
                                  "addAttribute",
                                  "("
                                  + STRING_SIG
                                  + STRING_SIG
                                  + ")V");
    _attribute = new INVOKEINTERFACE(attribute, 3);

    final int uniqueAttribute =
        cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
                                  "addUniqueAttribute",
                                  "("
                                  + STRING_SIG
                                  + STRING_SIG
                                  + "I)V");
    _uniqueAttribute = new INVOKEINTERFACE(uniqueAttribute, 4);

    final int namespace =
        cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
                                  "namespaceAfterStartElement",
                                  "("
                                  + STRING_SIG
                                  + STRING_SIG
                                  + ")V");
    _namespace = new INVOKEINTERFACE(namespace, 3);

    int index = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
                                          "startDocument",
                                          "()V");
    _startDocument = new INVOKEINTERFACE(index, 1);

    index = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
                                      "endDocument",
                                      "()V");
    _endDocument = new INVOKEINTERFACE(index, 1);


    index = cpg.addInterfaceMethodref(NODE_ITERATOR,
                                      SET_START_NODE,
                                      SET_START_NODE_SIG);
    _setStartNode = new INVOKEINTERFACE(index, 2);

    index = cpg.addInterfaceMethodref(NODE_ITERATOR,
                                      "reset", "()"+NODE_ITERATOR_SIG);
    _reset = new INVOKEINTERFACE(index, 1);

    index = cpg.addInterfaceMethodref(NODE_ITERATOR, NEXT, NEXT_SIG);
    _nextNode = new INVOKEINTERFACE(index, 1);

    _slotAllocator = new SlotAllocator();
    _slotAllocator.initialize(getLocalVariableRegistry().getLocals(false));
    _allocatorInit = true;
}
 
Example #26
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: ResultTreeType.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Expects a result tree on the stack and pushes a boxed result tree.
 * Result trees are already boxed so the translation is just a NOP.
 *
 * @param classGen A BCEL class generator
 * @param methodGen A BCEL method generator
 * @param type An instance of ReferenceType (any)
 * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
 */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
                        ReferenceType type) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_methodName == null) {
        il.append(NOP);
    }
    else {
        LocalVariableGen domBuilder, newDom;
        final String className = classGen.getClassName();
        final int current = methodGen.getLocalIndex("current");

        // Push required parameters
        il.append(classGen.loadTranslet());
        if (classGen.isExternal()) {
            il.append(new CHECKCAST(cpg.addClass(className)));
        }
        il.append(methodGen.loadDOM());

        // Create new instance of DOM class (with RTF_INITIAL_SIZE nodes)
        il.append(methodGen.loadDOM());
        int index = cpg.addInterfaceMethodref(DOM_INTF,
                             "getResultTreeFrag",
                             "(IZ)" + DOM_INTF_SIG);
        il.append(new PUSH(cpg, RTF_INITIAL_SIZE));
        il.append(new PUSH(cpg, false));
        il.append(new INVOKEINTERFACE(index,3));
        il.append(DUP);

        // Store new DOM into a local variable
        newDom = methodGen.addLocalVariable("rt_to_reference_dom",
                                            Util.getJCRefType(DOM_INTF_SIG),
                                            null, null);
        il.append(new CHECKCAST(cpg.addClass(DOM_INTF_SIG)));
        newDom.setStart(il.append(new ASTORE(newDom.getIndex())));

        // Overwrite old handler with DOM handler
        index = cpg.addInterfaceMethodref(DOM_INTF,
                             "getOutputDomBuilder",
                             "()" + TRANSLET_OUTPUT_SIG);

        il.append(new INVOKEINTERFACE(index,1));
        //index = cpg.addMethodref(DOM_IMPL,
            //                   "getOutputDomBuilder",
            //                   "()" + TRANSLET_OUTPUT_SIG);
        //il.append(new INVOKEVIRTUAL(index));
        il.append(DUP);
        il.append(DUP);

        // Store DOM handler in a local in order to call endDocument()
        domBuilder =
            methodGen.addLocalVariable("rt_to_reference_handler",
                                       Util.getJCRefType(TRANSLET_OUTPUT_SIG),
                                       null, null);
        domBuilder.setStart(il.append(new ASTORE(domBuilder.getIndex())));

        // Call startDocument on the new handler
        index = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
                                          "startDocument", "()V");
        il.append(new INVOKEINTERFACE(index, 1));

        // Call the method that implements this result tree
        index = cpg.addMethodref(className,
                                 _methodName,
                                 "("
                                 + DOM_INTF_SIG
                                 + TRANSLET_OUTPUT_SIG
                                 +")V");
        il.append(new INVOKEVIRTUAL(index));

        // Call endDocument on the DOM handler
        domBuilder.setEnd(il.append(new ALOAD(domBuilder.getIndex())));
        index = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
                                          "endDocument", "()V");
        il.append(new INVOKEINTERFACE(index, 1));

        // Push the new DOM on the stack
        newDom.setEnd(il.append(new ALOAD(newDom.getIndex())));
    }
}
 
Example #27
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Copy.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    final LocalVariableGen name =
        methodGen.addLocalVariable2("name",
                                    Util.getJCRefType(STRING_SIG),
                                    null);
    final LocalVariableGen length =
        methodGen.addLocalVariable2("length",
                                    Util.getJCRefType("I"),
                                    null);

    // Get the name of the node to copy and save for later
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadCurrentNode());
    il.append(methodGen.loadHandler());
    final int cpy = cpg.addInterfaceMethodref(DOM_INTF,
                                              "shallowCopy",
                                              "("
                                              + NODE_SIG
                                              + TRANSLET_OUTPUT_SIG
                                              + ")" + STRING_SIG);
    il.append(new INVOKEINTERFACE(cpy, 3));
    il.append(DUP);
    name.setStart(il.append(new ASTORE(name.getIndex())));
    final BranchHandle ifBlock1 = il.append(new IFNULL(null));

    // Get the length of the node name and save for later
    il.append(new ALOAD(name.getIndex()));
    final int lengthMethod = cpg.addMethodref(STRING_CLASS,"length","()I");
    il.append(new INVOKEVIRTUAL(lengthMethod));
    il.append(DUP);
    length.setStart(il.append(new ISTORE(length.getIndex())));

    // Ignore attribute sets if current node is ROOT. DOM.shallowCopy()
    // returns "" for ROOT, so skip attribute sets if length == 0
    final BranchHandle ifBlock4 = il.append(new IFEQ(null));

    // Copy in attribute sets if specified
    if (_useSets != null) {
        // If the parent of this element will result in an element being
        // output then we know that it is safe to copy out the attributes
        final SyntaxTreeNode parent = getParent();
        if ((parent instanceof LiteralElement) ||
            (parent instanceof LiteralElement)) {
            _useSets.translate(classGen, methodGen);
        }
        // If not we have to check to see if the copy will result in an
        // element being output.
        else {
            // check if element; if not skip to translate body
            il.append(new ILOAD(length.getIndex()));
            final BranchHandle ifBlock2 = il.append(new IFEQ(null));
            // length != 0 -> element -> do attribute sets
            _useSets.translate(classGen, methodGen);
            // not an element; root
            ifBlock2.setTarget(il.append(NOP));
        }
    }

    // Instantiate body of xsl:copy
    ifBlock4.setTarget(il.append(NOP));
    translateContents(classGen, methodGen);

    // Call the output handler's endElement() if we copied an element
    // (The DOM.shallowCopy() method calls startElement().)
    length.setEnd(il.append(new ILOAD(length.getIndex())));
    final BranchHandle ifBlock3 = il.append(new IFEQ(null));
    il.append(methodGen.loadHandler());
    name.setEnd(il.append(new ALOAD(name.getIndex())));
    il.append(methodGen.endElement());

    final InstructionHandle end = il.append(NOP);
    ifBlock1.setTarget(end);
    ifBlock3.setTarget(end);
    methodGen.removeLocalVariable(name);
    methodGen.removeLocalVariable(length);
}
 
Example #28
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: ReferenceType.java    License: MIT License 4 votes vote down vote up
public Instruction STORE(int slot) {
    return new ASTORE(slot);
}
 
Example #29
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: NodeSetType.java    License: Apache License 2.0 4 votes vote down vote up
public Instruction STORE(int slot) {
    return new ASTORE(slot);
}
 
Example #30
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: StepPattern.java    License: Apache License 2.0 4 votes vote down vote up
private void translateSimpleContext(ClassGenerator classGen,
                                    MethodGenerator methodGen) {
    int index;
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Store matching node into a local variable
    LocalVariableGen match;
    match = methodGen.addLocalVariable("step_pattern_tmp1",
                                       Util.getJCRefType(NODE_SIG),
                                       null, null);
    match.setStart(il.append(new ISTORE(match.getIndex())));

    // If pattern not reduced then check kernel
    if (!_isEpsilon) {
        il.append(new ILOAD(match.getIndex()));
        translateKernel(classGen, methodGen);
    }

    // Push current iterator and current node on the stack
    il.append(methodGen.loadCurrentNode());
    il.append(methodGen.loadIterator());

    // Create a new matching iterator using the matching node
    index = cpg.addMethodref(MATCHING_ITERATOR, "<init>",
                             "(I" + NODE_ITERATOR_SIG + ")V");

    // Backwards branches are prohibited if an uninitialized object is
    // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
    // We don't know whether this code might contain backwards branches,
    // so we mustn't create the new object until after we've created
    // the suspect arguments to its constructor.  Instead we calculate
    // the values of the arguments to the constructor first, store them
    // in temporary variables, create the object and reload the
    // arguments from the temporaries to avoid the problem.

    _step.translate(classGen, methodGen);
    LocalVariableGen stepIteratorTemp =
            methodGen.addLocalVariable("step_pattern_tmp2",
                                       Util.getJCRefType(NODE_ITERATOR_SIG),
                                       null, null);
    stepIteratorTemp.setStart(
            il.append(new ASTORE(stepIteratorTemp.getIndex())));

    il.append(new NEW(cpg.addClass(MATCHING_ITERATOR)));
    il.append(DUP);
    il.append(new ILOAD(match.getIndex()));
    stepIteratorTemp.setEnd(
            il.append(new ALOAD(stepIteratorTemp.getIndex())));
    il.append(new INVOKESPECIAL(index));

    // Get the parent of the matching node
    il.append(methodGen.loadDOM());
    il.append(new ILOAD(match.getIndex()));
    index = cpg.addInterfaceMethodref(DOM_INTF, GET_PARENT, GET_PARENT_SIG);
    il.append(new INVOKEINTERFACE(index, 2));

    // Start the iterator with the parent
    il.append(methodGen.setStartNode());

    // Overwrite current iterator and current node
    il.append(methodGen.storeIterator());
    match.setEnd(il.append(new ILOAD(match.getIndex())));
    il.append(methodGen.storeCurrentNode());

    // Translate the expression of the predicate
    Predicate pred = (Predicate) _predicates.elementAt(0);
    Expression exp = pred.getExpr();
    exp.translateDesynthesized(classGen, methodGen);

    // Backpatch true list and restore current iterator/node
    InstructionHandle restore = il.append(methodGen.storeIterator());
    il.append(methodGen.storeCurrentNode());
    exp.backPatchTrueList(restore);
    BranchHandle skipFalse = il.append(new GOTO(null));

    // Backpatch false list and restore current iterator/node
    restore = il.append(methodGen.storeIterator());
    il.append(methodGen.storeCurrentNode());
    exp.backPatchFalseList(restore);
    _falseList.add(il.append(new GOTO(null)));

    // True list falls through
    skipFalse.setTarget(il.append(NOP));
}