Java Code Examples for com.sun.org.apache.bcel.internal.generic.ConstantPoolGen#getConstantPool()

The following examples show how to use com.sun.org.apache.bcel.internal.generic.ConstantPoolGen#getConstantPool() . 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: Number.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private void compileDefault(ClassGenerator classGen,
                            MethodGenerator methodGen) {
    int index;
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();

    int[] fieldIndexes = getXSLTC().getNumberFieldIndexes();

    if (fieldIndexes[_level] == -1) {
        Field defaultNode = new Field(ACC_PRIVATE,
                                      cpg.addUtf8(FieldNames[_level]),
                                      cpg.addUtf8(NODE_COUNTER_SIG),
                                      null,
                                      cpg.getConstantPool());

        // Add a new private field to this class
        classGen.addField(defaultNode);

        // Get a reference to the newly added field
        fieldIndexes[_level] = cpg.addFieldref(classGen.getClassName(),
                                               FieldNames[_level],
                                               NODE_COUNTER_SIG);
    }

    // Check if field is initialized (runtime)
    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock1 = il.append(new IFNONNULL(null));

    // Create an instance of DefaultNodeCounter
    index = cpg.addMethodref(ClassNames[_level],
                             "getDefaultNodeCounter",
                             "(" + TRANSLET_INTF_SIG
                             + DOM_INTF_SIG
                             + NODE_ITERATOR_SIG
                             + ")" + NODE_COUNTER_SIG);
    il.append(classGen.loadTranslet());
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadIterator());
    il.append(new INVOKESTATIC(index));
    il.append(DUP);

    // Store the node counter in the field
    il.append(classGen.loadTranslet());
    il.append(SWAP);
    il.append(new PUTFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock2 = il.append(new GOTO(null));

    // Backpatch conditionals
    ifBlock1.setTarget(il.append(classGen.loadTranslet()));
    il.append(new GETFIELD(fieldIndexes[_level]));

    ifBlock2.setTarget(il.append(NOP));
}
 
Example 2
Source File: StepPattern.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private void translateGeneralContext(ClassGenerator classGen,
                                     MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    int iteratorIndex = 0;
    BranchHandle ifBlock = null;
    LocalVariableGen iter, node, node2;
    final String iteratorName = getNextFieldName();

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

    // Create a new local to store the iterator
    iter = methodGen.addLocalVariable("step_pattern_tmp2",
                                      Util.getJCRefType(NODE_ITERATOR_SIG),
                                      null, null);

    // Add a new private field if this is the main class
    if (!classGen.isExternal()) {
        final Field iterator =
            new Field(ACC_PRIVATE,
                      cpg.addUtf8(iteratorName),
                      cpg.addUtf8(NODE_ITERATOR_SIG),
                      null, cpg.getConstantPool());
        classGen.addField(iterator);
        iteratorIndex = cpg.addFieldref(classGen.getClassName(),
                                        iteratorName,
                                        NODE_ITERATOR_SIG);

        il.append(classGen.loadTranslet());
        il.append(new GETFIELD(iteratorIndex));
        il.append(DUP);
        iter.setStart(il.append(new ASTORE(iter.getIndex())));
        ifBlock = il.append(new IFNONNULL(null));
        il.append(classGen.loadTranslet());
    }

    // Compile the step created at type checking time
    _step.translate(classGen, methodGen);
    InstructionHandle iterStore = il.append(new ASTORE(iter.getIndex()));

    // If in the main class update the field too
    if (!classGen.isExternal()) {
        il.append(new ALOAD(iter.getIndex()));
        il.append(new PUTFIELD(iteratorIndex));
        ifBlock.setTarget(il.append(NOP));
    } else {
        // If class is not external, start of range for iter variable was
        // set above
        iter.setStart(iterStore);
    }

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

    // Initialize the iterator with the parent
    il.append(new ALOAD(iter.getIndex()));
    il.append(SWAP);
    il.append(methodGen.setStartNode());

    /*
     * Inline loop:
     *
     * int node2;
     * while ((node2 = iter.next()) != NodeIterator.END
     *                && node2 < node);
     * return node2 == node;
     */
    BranchHandle skipNext;
    InstructionHandle begin, next;
    node2 = methodGen.addLocalVariable("step_pattern_tmp3",
                                       Util.getJCRefType(NODE_SIG),
                                       null, null);

    skipNext = il.append(new GOTO(null));
    next = il.append(new ALOAD(iter.getIndex()));
    node2.setStart(next);
    begin = il.append(methodGen.nextNode());
    il.append(DUP);
    il.append(new ISTORE(node2.getIndex()));
    _falseList.add(il.append(new IFLT(null)));      // NodeIterator.END

    il.append(new ILOAD(node2.getIndex()));
    il.append(new ILOAD(node.getIndex()));
    iter.setEnd(il.append(new IF_ICMPLT(next)));

    node2.setEnd(il.append(new ILOAD(node2.getIndex())));
    node.setEnd(il.append(new ILOAD(node.getIndex())));
    _falseList.add(il.append(new IF_ICMPNE(null)));

    skipNext.setTarget(begin);
}
 
Example 3
Source File: Number.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private void compileDefault(ClassGenerator classGen,
                            MethodGenerator methodGen) {
    int index;
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();

    int[] fieldIndexes = getXSLTC().getNumberFieldIndexes();

    if (fieldIndexes[_level] == -1) {
        Field defaultNode = new Field(ACC_PRIVATE,
                                      cpg.addUtf8(FieldNames[_level]),
                                      cpg.addUtf8(NODE_COUNTER_SIG),
                                      null,
                                      cpg.getConstantPool());

        // Add a new private field to this class
        classGen.addField(defaultNode);

        // Get a reference to the newly added field
        fieldIndexes[_level] = cpg.addFieldref(classGen.getClassName(),
                                               FieldNames[_level],
                                               NODE_COUNTER_SIG);
    }

    // Check if field is initialized (runtime)
    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock1 = il.append(new IFNONNULL(null));

    // Create an instance of DefaultNodeCounter
    index = cpg.addMethodref(ClassNames[_level],
                             "getDefaultNodeCounter",
                             "(" + TRANSLET_INTF_SIG
                             + DOM_INTF_SIG
                             + NODE_ITERATOR_SIG
                             + ")" + NODE_COUNTER_SIG);
    il.append(classGen.loadTranslet());
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadIterator());
    il.append(new INVOKESTATIC(index));
    il.append(DUP);

    // Store the node counter in the field
    il.append(classGen.loadTranslet());
    il.append(SWAP);
    il.append(new PUTFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock2 = il.append(new GOTO(null));

    // Backpatch conditionals
    ifBlock1.setTarget(il.append(classGen.loadTranslet()));
    il.append(new GETFIELD(fieldIndexes[_level]));

    ifBlock2.setTarget(il.append(NOP));
}
 
Example 4
Source File: StepPattern.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private void translateGeneralContext(ClassGenerator classGen,
                                     MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    int iteratorIndex = 0;
    BranchHandle ifBlock = null;
    LocalVariableGen iter, node, node2;
    final String iteratorName = getNextFieldName();

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

    // Create a new local to store the iterator
    iter = methodGen.addLocalVariable("step_pattern_tmp2",
                                      Util.getJCRefType(NODE_ITERATOR_SIG),
                                      null, null);

    // Add a new private field if this is the main class
    if (!classGen.isExternal()) {
        final Field iterator =
            new Field(ACC_PRIVATE,
                      cpg.addUtf8(iteratorName),
                      cpg.addUtf8(NODE_ITERATOR_SIG),
                      null, cpg.getConstantPool());
        classGen.addField(iterator);
        iteratorIndex = cpg.addFieldref(classGen.getClassName(),
                                        iteratorName,
                                        NODE_ITERATOR_SIG);

        il.append(classGen.loadTranslet());
        il.append(new GETFIELD(iteratorIndex));
        il.append(DUP);
        iter.setStart(il.append(new ASTORE(iter.getIndex())));
        ifBlock = il.append(new IFNONNULL(null));
        il.append(classGen.loadTranslet());
    }

    // Compile the step created at type checking time
    _step.translate(classGen, methodGen);
    InstructionHandle iterStore = il.append(new ASTORE(iter.getIndex()));

    // If in the main class update the field too
    if (!classGen.isExternal()) {
        il.append(new ALOAD(iter.getIndex()));
        il.append(new PUTFIELD(iteratorIndex));
        ifBlock.setTarget(il.append(NOP));
    } else {
        // If class is not external, start of range for iter variable was
        // set above
        iter.setStart(iterStore);
    }

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

    // Initialize the iterator with the parent
    il.append(new ALOAD(iter.getIndex()));
    il.append(SWAP);
    il.append(methodGen.setStartNode());

    /*
     * Inline loop:
     *
     * int node2;
     * while ((node2 = iter.next()) != NodeIterator.END
     *                && node2 < node);
     * return node2 == node;
     */
    BranchHandle skipNext;
    InstructionHandle begin, next;
    node2 = methodGen.addLocalVariable("step_pattern_tmp3",
                                       Util.getJCRefType(NODE_SIG),
                                       null, null);

    skipNext = il.append(new GOTO(null));
    next = il.append(new ALOAD(iter.getIndex()));
    node2.setStart(next);
    begin = il.append(methodGen.nextNode());
    il.append(DUP);
    il.append(new ISTORE(node2.getIndex()));
    _falseList.add(il.append(new IFLT(null)));      // NodeIterator.END

    il.append(new ILOAD(node2.getIndex()));
    il.append(new ILOAD(node.getIndex()));
    iter.setEnd(il.append(new IF_ICMPLT(next)));

    node2.setEnd(il.append(new ILOAD(node2.getIndex())));
    node.setEnd(il.append(new ILOAD(node.getIndex())));
    _falseList.add(il.append(new IF_ICMPNE(null)));

    skipNext.setTarget(begin);
}
 
Example 5
Source File: Number.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private void compileDefault(ClassGenerator classGen,
                            MethodGenerator methodGen) {
    int index;
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();

    int[] fieldIndexes = getXSLTC().getNumberFieldIndexes();

    if (fieldIndexes[_level] == -1) {
        Field defaultNode = new Field(ACC_PRIVATE,
                                      cpg.addUtf8(FieldNames[_level]),
                                      cpg.addUtf8(NODE_COUNTER_SIG),
                                      null,
                                      cpg.getConstantPool());

        // Add a new private field to this class
        classGen.addField(defaultNode);

        // Get a reference to the newly added field
        fieldIndexes[_level] = cpg.addFieldref(classGen.getClassName(),
                                               FieldNames[_level],
                                               NODE_COUNTER_SIG);
    }

    // Check if field is initialized (runtime)
    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock1 = il.append(new IFNONNULL(null));

    // Create an instance of DefaultNodeCounter
    index = cpg.addMethodref(ClassNames[_level],
                             "getDefaultNodeCounter",
                             "(" + TRANSLET_INTF_SIG
                             + DOM_INTF_SIG
                             + NODE_ITERATOR_SIG
                             + ")" + NODE_COUNTER_SIG);
    il.append(classGen.loadTranslet());
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadIterator());
    il.append(new INVOKESTATIC(index));
    il.append(DUP);

    // Store the node counter in the field
    il.append(classGen.loadTranslet());
    il.append(SWAP);
    il.append(new PUTFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock2 = il.append(new GOTO(null));

    // Backpatch conditionals
    ifBlock1.setTarget(il.append(classGen.loadTranslet()));
    il.append(new GETFIELD(fieldIndexes[_level]));

    ifBlock2.setTarget(il.append(NOP));
}
 
Example 6
Source File: StepPattern.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void translateGeneralContext(ClassGenerator classGen,
                                     MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    int iteratorIndex = 0;
    BranchHandle ifBlock = null;
    LocalVariableGen iter, node, node2;
    final String iteratorName = getNextFieldName();

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

    // Create a new local to store the iterator
    iter = methodGen.addLocalVariable("step_pattern_tmp2",
                                      Util.getJCRefType(NODE_ITERATOR_SIG),
                                      null, null);

    // Add a new private field if this is the main class
    if (!classGen.isExternal()) {
        final Field iterator =
            new Field(ACC_PRIVATE,
                      cpg.addUtf8(iteratorName),
                      cpg.addUtf8(NODE_ITERATOR_SIG),
                      null, cpg.getConstantPool());
        classGen.addField(iterator);
        iteratorIndex = cpg.addFieldref(classGen.getClassName(),
                                        iteratorName,
                                        NODE_ITERATOR_SIG);

        il.append(classGen.loadTranslet());
        il.append(new GETFIELD(iteratorIndex));
        il.append(DUP);
        iter.setStart(il.append(new ASTORE(iter.getIndex())));
        ifBlock = il.append(new IFNONNULL(null));
        il.append(classGen.loadTranslet());
    }

    // Compile the step created at type checking time
    _step.translate(classGen, methodGen);
    InstructionHandle iterStore = il.append(new ASTORE(iter.getIndex()));

    // If in the main class update the field too
    if (!classGen.isExternal()) {
        il.append(new ALOAD(iter.getIndex()));
        il.append(new PUTFIELD(iteratorIndex));
        ifBlock.setTarget(il.append(NOP));
    } else {
        // If class is not external, start of range for iter variable was
        // set above
        iter.setStart(iterStore);
    }

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

    // Initialize the iterator with the parent
    il.append(new ALOAD(iter.getIndex()));
    il.append(SWAP);
    il.append(methodGen.setStartNode());

    /*
     * Inline loop:
     *
     * int node2;
     * while ((node2 = iter.next()) != NodeIterator.END
     *                && node2 < node);
     * return node2 == node;
     */
    BranchHandle skipNext;
    InstructionHandle begin, next;
    node2 = methodGen.addLocalVariable("step_pattern_tmp3",
                                       Util.getJCRefType(NODE_SIG),
                                       null, null);

    skipNext = il.append(new GOTO(null));
    next = il.append(new ALOAD(iter.getIndex()));
    node2.setStart(next);
    begin = il.append(methodGen.nextNode());
    il.append(DUP);
    il.append(new ISTORE(node2.getIndex()));
    _falseList.add(il.append(new IFLT(null)));      // NodeIterator.END

    il.append(new ILOAD(node2.getIndex()));
    il.append(new ILOAD(node.getIndex()));
    iter.setEnd(il.append(new IF_ICMPLT(next)));

    node2.setEnd(il.append(new ILOAD(node2.getIndex())));
    node.setEnd(il.append(new ILOAD(node.getIndex())));
    _falseList.add(il.append(new IF_ICMPNE(null)));

    skipNext.setTarget(begin);
}
 
Example 7
Source File: Number.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void compileDefault(ClassGenerator classGen,
                            MethodGenerator methodGen) {
    int index;
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();

    int[] fieldIndexes = getXSLTC().getNumberFieldIndexes();

    if (fieldIndexes[_level] == -1) {
        Field defaultNode = new Field(ACC_PRIVATE,
                                      cpg.addUtf8(FieldNames[_level]),
                                      cpg.addUtf8(NODE_COUNTER_SIG),
                                      null,
                                      cpg.getConstantPool());

        // Add a new private field to this class
        classGen.addField(defaultNode);

        // Get a reference to the newly added field
        fieldIndexes[_level] = cpg.addFieldref(classGen.getClassName(),
                                               FieldNames[_level],
                                               NODE_COUNTER_SIG);
    }

    // Check if field is initialized (runtime)
    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock1 = il.append(new IFNONNULL(null));

    // Create an instance of DefaultNodeCounter
    index = cpg.addMethodref(ClassNames[_level],
                             "getDefaultNodeCounter",
                             "(" + TRANSLET_INTF_SIG
                             + DOM_INTF_SIG
                             + NODE_ITERATOR_SIG
                             + ")" + NODE_COUNTER_SIG);
    il.append(classGen.loadTranslet());
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadIterator());
    il.append(new INVOKESTATIC(index));
    il.append(DUP);

    // Store the node counter in the field
    il.append(classGen.loadTranslet());
    il.append(SWAP);
    il.append(new PUTFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock2 = il.append(new GOTO(null));

    // Backpatch conditionals
    ifBlock1.setTarget(il.append(classGen.loadTranslet()));
    il.append(new GETFIELD(fieldIndexes[_level]));

    ifBlock2.setTarget(il.append(NOP));
}
 
Example 8
Source File: StepPattern.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
private void translateGeneralContext(ClassGenerator classGen,
                                     MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    int iteratorIndex = 0;
    BranchHandle ifBlock = null;
    LocalVariableGen iter, node, node2;
    final String iteratorName = getNextFieldName();

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

    // Create a new local to store the iterator
    iter = methodGen.addLocalVariable("step_pattern_tmp2",
                                      Util.getJCRefType(NODE_ITERATOR_SIG),
                                      null, null);

    // Add a new private field if this is the main class
    if (!classGen.isExternal()) {
        final Field iterator =
            new Field(ACC_PRIVATE,
                      cpg.addUtf8(iteratorName),
                      cpg.addUtf8(NODE_ITERATOR_SIG),
                      null, cpg.getConstantPool());
        classGen.addField(iterator);
        iteratorIndex = cpg.addFieldref(classGen.getClassName(),
                                        iteratorName,
                                        NODE_ITERATOR_SIG);

        il.append(classGen.loadTranslet());
        il.append(new GETFIELD(iteratorIndex));
        il.append(DUP);
        iter.setStart(il.append(new ASTORE(iter.getIndex())));
        ifBlock = il.append(new IFNONNULL(null));
        il.append(classGen.loadTranslet());
    }

    // Compile the step created at type checking time
    _step.translate(classGen, methodGen);
    InstructionHandle iterStore = il.append(new ASTORE(iter.getIndex()));

    // If in the main class update the field too
    if (!classGen.isExternal()) {
        il.append(new ALOAD(iter.getIndex()));
        il.append(new PUTFIELD(iteratorIndex));
        ifBlock.setTarget(il.append(NOP));
    } else {
        // If class is not external, start of range for iter variable was
        // set above
        iter.setStart(iterStore);
    }

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

    // Initialize the iterator with the parent
    il.append(new ALOAD(iter.getIndex()));
    il.append(SWAP);
    il.append(methodGen.setStartNode());

    /*
     * Inline loop:
     *
     * int node2;
     * while ((node2 = iter.next()) != NodeIterator.END
     *                && node2 < node);
     * return node2 == node;
     */
    BranchHandle skipNext;
    InstructionHandle begin, next;
    node2 = methodGen.addLocalVariable("step_pattern_tmp3",
                                       Util.getJCRefType(NODE_SIG),
                                       null, null);

    skipNext = il.append(new GOTO(null));
    next = il.append(new ALOAD(iter.getIndex()));
    node2.setStart(next);
    begin = il.append(methodGen.nextNode());
    il.append(DUP);
    il.append(new ISTORE(node2.getIndex()));
    _falseList.add(il.append(new IFLT(null)));      // NodeIterator.END

    il.append(new ILOAD(node2.getIndex()));
    il.append(new ILOAD(node.getIndex()));
    iter.setEnd(il.append(new IF_ICMPLT(next)));

    node2.setEnd(il.append(new ILOAD(node2.getIndex())));
    node.setEnd(il.append(new ILOAD(node.getIndex())));
    _falseList.add(il.append(new IF_ICMPNE(null)));

    skipNext.setTarget(begin);
}
 
Example 9
Source File: Number.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
private void compileDefault(ClassGenerator classGen,
                            MethodGenerator methodGen) {
    int index;
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();

    int[] fieldIndexes = getXSLTC().getNumberFieldIndexes();

    if (fieldIndexes[_level] == -1) {
        Field defaultNode = new Field(ACC_PRIVATE,
                                      cpg.addUtf8(FieldNames[_level]),
                                      cpg.addUtf8(NODE_COUNTER_SIG),
                                      null,
                                      cpg.getConstantPool());

        // Add a new private field to this class
        classGen.addField(defaultNode);

        // Get a reference to the newly added field
        fieldIndexes[_level] = cpg.addFieldref(classGen.getClassName(),
                                               FieldNames[_level],
                                               NODE_COUNTER_SIG);
    }

    // Check if field is initialized (runtime)
    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock1 = il.append(new IFNONNULL(null));

    // Create an instance of DefaultNodeCounter
    index = cpg.addMethodref(ClassNames[_level],
                             "getDefaultNodeCounter",
                             "(" + TRANSLET_INTF_SIG
                             + DOM_INTF_SIG
                             + NODE_ITERATOR_SIG
                             + ")" + NODE_COUNTER_SIG);
    il.append(classGen.loadTranslet());
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadIterator());
    il.append(new INVOKESTATIC(index));
    il.append(DUP);

    // Store the node counter in the field
    il.append(classGen.loadTranslet());
    il.append(SWAP);
    il.append(new PUTFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock2 = il.append(new GOTO(null));

    // Backpatch conditionals
    ifBlock1.setTarget(il.append(classGen.loadTranslet()));
    il.append(new GETFIELD(fieldIndexes[_level]));

    ifBlock2.setTarget(il.append(NOP));
}
 
Example 10
Source File: StepPattern.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private void translateGeneralContext(ClassGenerator classGen,
                                     MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    int iteratorIndex = 0;
    BranchHandle ifBlock = null;
    LocalVariableGen iter, node, node2;
    final String iteratorName = getNextFieldName();

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

    // Create a new local to store the iterator
    iter = methodGen.addLocalVariable("step_pattern_tmp2",
                                      Util.getJCRefType(NODE_ITERATOR_SIG),
                                      null, null);

    // Add a new private field if this is the main class
    if (!classGen.isExternal()) {
        final Field iterator =
            new Field(ACC_PRIVATE,
                      cpg.addUtf8(iteratorName),
                      cpg.addUtf8(NODE_ITERATOR_SIG),
                      null, cpg.getConstantPool());
        classGen.addField(iterator);
        iteratorIndex = cpg.addFieldref(classGen.getClassName(),
                                        iteratorName,
                                        NODE_ITERATOR_SIG);

        il.append(classGen.loadTranslet());
        il.append(new GETFIELD(iteratorIndex));
        il.append(DUP);
        iter.setStart(il.append(new ASTORE(iter.getIndex())));
        ifBlock = il.append(new IFNONNULL(null));
        il.append(classGen.loadTranslet());
    }

    // Compile the step created at type checking time
    _step.translate(classGen, methodGen);
    InstructionHandle iterStore = il.append(new ASTORE(iter.getIndex()));

    // If in the main class update the field too
    if (!classGen.isExternal()) {
        il.append(new ALOAD(iter.getIndex()));
        il.append(new PUTFIELD(iteratorIndex));
        ifBlock.setTarget(il.append(NOP));
    } else {
        // If class is not external, start of range for iter variable was
        // set above
        iter.setStart(iterStore);
    }

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

    // Initialize the iterator with the parent
    il.append(new ALOAD(iter.getIndex()));
    il.append(SWAP);
    il.append(methodGen.setStartNode());

    /*
     * Inline loop:
     *
     * int node2;
     * while ((node2 = iter.next()) != NodeIterator.END
     *                && node2 < node);
     * return node2 == node;
     */
    BranchHandle skipNext;
    InstructionHandle begin, next;
    node2 = methodGen.addLocalVariable("step_pattern_tmp3",
                                       Util.getJCRefType(NODE_SIG),
                                       null, null);

    skipNext = il.append(new GOTO(null));
    next = il.append(new ALOAD(iter.getIndex()));
    node2.setStart(next);
    begin = il.append(methodGen.nextNode());
    il.append(DUP);
    il.append(new ISTORE(node2.getIndex()));
    _falseList.add(il.append(new IFLT(null)));      // NodeIterator.END

    il.append(new ILOAD(node2.getIndex()));
    il.append(new ILOAD(node.getIndex()));
    iter.setEnd(il.append(new IF_ICMPLT(next)));

    node2.setEnd(il.append(new ILOAD(node2.getIndex())));
    node.setEnd(il.append(new ILOAD(node.getIndex())));
    _falseList.add(il.append(new IF_ICMPNE(null)));

    skipNext.setTarget(begin);
}
 
Example 11
Source File: Number.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
private void compileDefault(ClassGenerator classGen,
                            MethodGenerator methodGen) {
    int index;
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();

    int[] fieldIndexes = getXSLTC().getNumberFieldIndexes();

    if (fieldIndexes[_level] == -1) {
        Field defaultNode = new Field(ACC_PRIVATE,
                                      cpg.addUtf8(FieldNames[_level]),
                                      cpg.addUtf8(NODE_COUNTER_SIG),
                                      null,
                                      cpg.getConstantPool());

        // Add a new private field to this class
        classGen.addField(defaultNode);

        // Get a reference to the newly added field
        fieldIndexes[_level] = cpg.addFieldref(classGen.getClassName(),
                                               FieldNames[_level],
                                               NODE_COUNTER_SIG);
    }

    // Check if field is initialized (runtime)
    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock1 = il.append(new IFNONNULL(null));

    // Create an instance of DefaultNodeCounter
    index = cpg.addMethodref(ClassNames[_level],
                             "getDefaultNodeCounter",
                             "(" + TRANSLET_INTF_SIG
                             + DOM_INTF_SIG
                             + NODE_ITERATOR_SIG
                             + ")" + NODE_COUNTER_SIG);
    il.append(classGen.loadTranslet());
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadIterator());
    il.append(new INVOKESTATIC(index));
    il.append(DUP);

    // Store the node counter in the field
    il.append(classGen.loadTranslet());
    il.append(SWAP);
    il.append(new PUTFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock2 = il.append(new GOTO(null));

    // Backpatch conditionals
    ifBlock1.setTarget(il.append(classGen.loadTranslet()));
    il.append(new GETFIELD(fieldIndexes[_level]));

    ifBlock2.setTarget(il.append(NOP));
}
 
Example 12
Source File: StepPattern.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void translateGeneralContext(ClassGenerator classGen,
                                     MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    int iteratorIndex = 0;
    BranchHandle ifBlock = null;
    LocalVariableGen iter, node, node2;
    final String iteratorName = getNextFieldName();

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

    // Create a new local to store the iterator
    iter = methodGen.addLocalVariable("step_pattern_tmp2",
                                      Util.getJCRefType(NODE_ITERATOR_SIG),
                                      null, null);

    // Add a new private field if this is the main class
    if (!classGen.isExternal()) {
        final Field iterator =
            new Field(ACC_PRIVATE,
                      cpg.addUtf8(iteratorName),
                      cpg.addUtf8(NODE_ITERATOR_SIG),
                      null, cpg.getConstantPool());
        classGen.addField(iterator);
        iteratorIndex = cpg.addFieldref(classGen.getClassName(),
                                        iteratorName,
                                        NODE_ITERATOR_SIG);

        il.append(classGen.loadTranslet());
        il.append(new GETFIELD(iteratorIndex));
        il.append(DUP);
        iter.setStart(il.append(new ASTORE(iter.getIndex())));
        ifBlock = il.append(new IFNONNULL(null));
        il.append(classGen.loadTranslet());
    }

    // Compile the step created at type checking time
    _step.translate(classGen, methodGen);
    InstructionHandle iterStore = il.append(new ASTORE(iter.getIndex()));

    // If in the main class update the field too
    if (!classGen.isExternal()) {
        il.append(new ALOAD(iter.getIndex()));
        il.append(new PUTFIELD(iteratorIndex));
        ifBlock.setTarget(il.append(NOP));
    } else {
        // If class is not external, start of range for iter variable was
        // set above
        iter.setStart(iterStore);
    }

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

    // Initialize the iterator with the parent
    il.append(new ALOAD(iter.getIndex()));
    il.append(SWAP);
    il.append(methodGen.setStartNode());

    /*
     * Inline loop:
     *
     * int node2;
     * while ((node2 = iter.next()) != NodeIterator.END
     *                && node2 < node);
     * return node2 == node;
     */
    BranchHandle skipNext;
    InstructionHandle begin, next;
    node2 = methodGen.addLocalVariable("step_pattern_tmp3",
                                       Util.getJCRefType(NODE_SIG),
                                       null, null);

    skipNext = il.append(new GOTO(null));
    next = il.append(new ALOAD(iter.getIndex()));
    node2.setStart(next);
    begin = il.append(methodGen.nextNode());
    il.append(DUP);
    il.append(new ISTORE(node2.getIndex()));
    _falseList.add(il.append(new IFLT(null)));      // NodeIterator.END

    il.append(new ILOAD(node2.getIndex()));
    il.append(new ILOAD(node.getIndex()));
    iter.setEnd(il.append(new IF_ICMPLT(next)));

    node2.setEnd(il.append(new ILOAD(node2.getIndex())));
    node.setEnd(il.append(new ILOAD(node.getIndex())));
    _falseList.add(il.append(new IF_ICMPNE(null)));

    skipNext.setTarget(begin);
}
 
Example 13
Source File: Number.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void compileDefault(ClassGenerator classGen,
                            MethodGenerator methodGen) {
    int index;
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();

    int[] fieldIndexes = getXSLTC().getNumberFieldIndexes();

    if (fieldIndexes[_level] == -1) {
        Field defaultNode = new Field(ACC_PRIVATE,
                                      cpg.addUtf8(FieldNames[_level]),
                                      cpg.addUtf8(NODE_COUNTER_SIG),
                                      null,
                                      cpg.getConstantPool());

        // Add a new private field to this class
        classGen.addField(defaultNode);

        // Get a reference to the newly added field
        fieldIndexes[_level] = cpg.addFieldref(classGen.getClassName(),
                                               FieldNames[_level],
                                               NODE_COUNTER_SIG);
    }

    // Check if field is initialized (runtime)
    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock1 = il.append(new IFNONNULL(null));

    // Create an instance of DefaultNodeCounter
    index = cpg.addMethodref(ClassNames[_level],
                             "getDefaultNodeCounter",
                             "(" + TRANSLET_INTF_SIG
                             + DOM_INTF_SIG
                             + NODE_ITERATOR_SIG
                             + ")" + NODE_COUNTER_SIG);
    il.append(classGen.loadTranslet());
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadIterator());
    il.append(new INVOKESTATIC(index));
    il.append(DUP);

    // Store the node counter in the field
    il.append(classGen.loadTranslet());
    il.append(SWAP);
    il.append(new PUTFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock2 = il.append(new GOTO(null));

    // Backpatch conditionals
    ifBlock1.setTarget(il.append(classGen.loadTranslet()));
    il.append(new GETFIELD(fieldIndexes[_level]));

    ifBlock2.setTarget(il.append(NOP));
}
 
Example 14
Source File: StepPattern.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
private void translateGeneralContext(ClassGenerator classGen,
                                     MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    int iteratorIndex = 0;
    BranchHandle ifBlock = null;
    LocalVariableGen iter, node, node2;
    final String iteratorName = getNextFieldName();

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

    // Create a new local to store the iterator
    iter = methodGen.addLocalVariable("step_pattern_tmp2",
                                      Util.getJCRefType(NODE_ITERATOR_SIG),
                                      null, null);

    // Add a new private field if this is the main class
    if (!classGen.isExternal()) {
        final Field iterator =
            new Field(ACC_PRIVATE,
                      cpg.addUtf8(iteratorName),
                      cpg.addUtf8(NODE_ITERATOR_SIG),
                      null, cpg.getConstantPool());
        classGen.addField(iterator);
        iteratorIndex = cpg.addFieldref(classGen.getClassName(),
                                        iteratorName,
                                        NODE_ITERATOR_SIG);

        il.append(classGen.loadTranslet());
        il.append(new GETFIELD(iteratorIndex));
        il.append(DUP);
        iter.setStart(il.append(new ASTORE(iter.getIndex())));
        ifBlock = il.append(new IFNONNULL(null));
        il.append(classGen.loadTranslet());
    }

    // Compile the step created at type checking time
    _step.translate(classGen, methodGen);
    InstructionHandle iterStore = il.append(new ASTORE(iter.getIndex()));

    // If in the main class update the field too
    if (!classGen.isExternal()) {
        il.append(new ALOAD(iter.getIndex()));
        il.append(new PUTFIELD(iteratorIndex));
        ifBlock.setTarget(il.append(NOP));
    } else {
        // If class is not external, start of range for iter variable was
        // set above
        iter.setStart(iterStore);
    }

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

    // Initialize the iterator with the parent
    il.append(new ALOAD(iter.getIndex()));
    il.append(SWAP);
    il.append(methodGen.setStartNode());

    /*
     * Inline loop:
     *
     * int node2;
     * while ((node2 = iter.next()) != NodeIterator.END
     *                && node2 < node);
     * return node2 == node;
     */
    BranchHandle skipNext;
    InstructionHandle begin, next;
    node2 = methodGen.addLocalVariable("step_pattern_tmp3",
                                       Util.getJCRefType(NODE_SIG),
                                       null, null);

    skipNext = il.append(new GOTO(null));
    next = il.append(new ALOAD(iter.getIndex()));
    node2.setStart(next);
    begin = il.append(methodGen.nextNode());
    il.append(DUP);
    il.append(new ISTORE(node2.getIndex()));
    _falseList.add(il.append(new IFLT(null)));      // NodeIterator.END

    il.append(new ILOAD(node2.getIndex()));
    il.append(new ILOAD(node.getIndex()));
    iter.setEnd(il.append(new IF_ICMPLT(next)));

    node2.setEnd(il.append(new ILOAD(node2.getIndex())));
    node.setEnd(il.append(new ILOAD(node.getIndex())));
    _falseList.add(il.append(new IF_ICMPNE(null)));

    skipNext.setTarget(begin);
}
 
Example 15
Source File: Number.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
private void compileDefault(ClassGenerator classGen,
                            MethodGenerator methodGen) {
    int index;
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();

    int[] fieldIndexes = getXSLTC().getNumberFieldIndexes();

    if (fieldIndexes[_level] == -1) {
        Field defaultNode = new Field(ACC_PRIVATE,
                                      cpg.addUtf8(FieldNames[_level]),
                                      cpg.addUtf8(NODE_COUNTER_SIG),
                                      null,
                                      cpg.getConstantPool());

        // Add a new private field to this class
        classGen.addField(defaultNode);

        // Get a reference to the newly added field
        fieldIndexes[_level] = cpg.addFieldref(classGen.getClassName(),
                                               FieldNames[_level],
                                               NODE_COUNTER_SIG);
    }

    // Check if field is initialized (runtime)
    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock1 = il.append(new IFNONNULL(null));

    // Create an instance of DefaultNodeCounter
    index = cpg.addMethodref(ClassNames[_level],
                             "getDefaultNodeCounter",
                             "(" + TRANSLET_INTF_SIG
                             + DOM_INTF_SIG
                             + NODE_ITERATOR_SIG
                             + ")" + NODE_COUNTER_SIG);
    il.append(classGen.loadTranslet());
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadIterator());
    il.append(new INVOKESTATIC(index));
    il.append(DUP);

    // Store the node counter in the field
    il.append(classGen.loadTranslet());
    il.append(SWAP);
    il.append(new PUTFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock2 = il.append(new GOTO(null));

    // Backpatch conditionals
    ifBlock1.setTarget(il.append(classGen.loadTranslet()));
    il.append(new GETFIELD(fieldIndexes[_level]));

    ifBlock2.setTarget(il.append(NOP));
}
 
Example 16
Source File: StepPattern.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void translateGeneralContext(ClassGenerator classGen,
                                     MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    int iteratorIndex = 0;
    BranchHandle ifBlock = null;
    LocalVariableGen iter, node, node2;
    final String iteratorName = getNextFieldName();

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

    // Create a new local to store the iterator
    iter = methodGen.addLocalVariable("step_pattern_tmp2",
                                      Util.getJCRefType(NODE_ITERATOR_SIG),
                                      null, null);

    // Add a new private field if this is the main class
    if (!classGen.isExternal()) {
        final Field iterator =
            new Field(ACC_PRIVATE,
                      cpg.addUtf8(iteratorName),
                      cpg.addUtf8(NODE_ITERATOR_SIG),
                      null, cpg.getConstantPool());
        classGen.addField(iterator);
        iteratorIndex = cpg.addFieldref(classGen.getClassName(),
                                        iteratorName,
                                        NODE_ITERATOR_SIG);

        il.append(classGen.loadTranslet());
        il.append(new GETFIELD(iteratorIndex));
        il.append(DUP);
        iter.setStart(il.append(new ASTORE(iter.getIndex())));
        ifBlock = il.append(new IFNONNULL(null));
        il.append(classGen.loadTranslet());
    }

    // Compile the step created at type checking time
    _step.translate(classGen, methodGen);
    InstructionHandle iterStore = il.append(new ASTORE(iter.getIndex()));

    // If in the main class update the field too
    if (!classGen.isExternal()) {
        il.append(new ALOAD(iter.getIndex()));
        il.append(new PUTFIELD(iteratorIndex));
        ifBlock.setTarget(il.append(NOP));
    } else {
        // If class is not external, start of range for iter variable was
        // set above
        iter.setStart(iterStore);
    }

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

    // Initialize the iterator with the parent
    il.append(new ALOAD(iter.getIndex()));
    il.append(SWAP);
    il.append(methodGen.setStartNode());

    /*
     * Inline loop:
     *
     * int node2;
     * while ((node2 = iter.next()) != NodeIterator.END
     *                && node2 < node);
     * return node2 == node;
     */
    BranchHandle skipNext;
    InstructionHandle begin, next;
    node2 = methodGen.addLocalVariable("step_pattern_tmp3",
                                       Util.getJCRefType(NODE_SIG),
                                       null, null);

    skipNext = il.append(new GOTO(null));
    next = il.append(new ALOAD(iter.getIndex()));
    node2.setStart(next);
    begin = il.append(methodGen.nextNode());
    il.append(DUP);
    il.append(new ISTORE(node2.getIndex()));
    _falseList.add(il.append(new IFLT(null)));      // NodeIterator.END

    il.append(new ILOAD(node2.getIndex()));
    il.append(new ILOAD(node.getIndex()));
    iter.setEnd(il.append(new IF_ICMPLT(next)));

    node2.setEnd(il.append(new ILOAD(node2.getIndex())));
    node.setEnd(il.append(new ILOAD(node.getIndex())));
    _falseList.add(il.append(new IF_ICMPNE(null)));

    skipNext.setTarget(begin);
}
 
Example 17
Source File: Number.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void compileDefault(ClassGenerator classGen,
                            MethodGenerator methodGen) {
    int index;
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();

    int[] fieldIndexes = getXSLTC().getNumberFieldIndexes();

    if (fieldIndexes[_level] == -1) {
        Field defaultNode = new Field(ACC_PRIVATE,
                                      cpg.addUtf8(FieldNames[_level]),
                                      cpg.addUtf8(NODE_COUNTER_SIG),
                                      null,
                                      cpg.getConstantPool());

        // Add a new private field to this class
        classGen.addField(defaultNode);

        // Get a reference to the newly added field
        fieldIndexes[_level] = cpg.addFieldref(classGen.getClassName(),
                                               FieldNames[_level],
                                               NODE_COUNTER_SIG);
    }

    // Check if field is initialized (runtime)
    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock1 = il.append(new IFNONNULL(null));

    // Create an instance of DefaultNodeCounter
    index = cpg.addMethodref(ClassNames[_level],
                             "getDefaultNodeCounter",
                             "(" + TRANSLET_INTF_SIG
                             + DOM_INTF_SIG
                             + NODE_ITERATOR_SIG
                             + ")" + NODE_COUNTER_SIG);
    il.append(classGen.loadTranslet());
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadIterator());
    il.append(new INVOKESTATIC(index));
    il.append(DUP);

    // Store the node counter in the field
    il.append(classGen.loadTranslet());
    il.append(SWAP);
    il.append(new PUTFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock2 = il.append(new GOTO(null));

    // Backpatch conditionals
    ifBlock1.setTarget(il.append(classGen.loadTranslet()));
    il.append(new GETFIELD(fieldIndexes[_level]));

    ifBlock2.setTarget(il.append(NOP));
}
 
Example 18
Source File: StepPattern.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private void translateGeneralContext(ClassGenerator classGen,
                                     MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    int iteratorIndex = 0;
    BranchHandle ifBlock = null;
    LocalVariableGen iter, node, node2;
    final String iteratorName = getNextFieldName();

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

    // Create a new local to store the iterator
    iter = methodGen.addLocalVariable("step_pattern_tmp2",
                                      Util.getJCRefType(NODE_ITERATOR_SIG),
                                      null, null);

    // Add a new private field if this is the main class
    if (!classGen.isExternal()) {
        final Field iterator =
            new Field(ACC_PRIVATE,
                      cpg.addUtf8(iteratorName),
                      cpg.addUtf8(NODE_ITERATOR_SIG),
                      null, cpg.getConstantPool());
        classGen.addField(iterator);
        iteratorIndex = cpg.addFieldref(classGen.getClassName(),
                                        iteratorName,
                                        NODE_ITERATOR_SIG);

        il.append(classGen.loadTranslet());
        il.append(new GETFIELD(iteratorIndex));
        il.append(DUP);
        iter.setStart(il.append(new ASTORE(iter.getIndex())));
        ifBlock = il.append(new IFNONNULL(null));
        il.append(classGen.loadTranslet());
    }

    // Compile the step created at type checking time
    _step.translate(classGen, methodGen);
    InstructionHandle iterStore = il.append(new ASTORE(iter.getIndex()));

    // If in the main class update the field too
    if (!classGen.isExternal()) {
        il.append(new ALOAD(iter.getIndex()));
        il.append(new PUTFIELD(iteratorIndex));
        ifBlock.setTarget(il.append(NOP));
    } else {
        // If class is not external, start of range for iter variable was
        // set above
        iter.setStart(iterStore);
    }

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

    // Initialize the iterator with the parent
    il.append(new ALOAD(iter.getIndex()));
    il.append(SWAP);
    il.append(methodGen.setStartNode());

    /*
     * Inline loop:
     *
     * int node2;
     * while ((node2 = iter.next()) != NodeIterator.END
     *                && node2 < node);
     * return node2 == node;
     */
    BranchHandle skipNext;
    InstructionHandle begin, next;
    node2 = methodGen.addLocalVariable("step_pattern_tmp3",
                                       Util.getJCRefType(NODE_SIG),
                                       null, null);

    skipNext = il.append(new GOTO(null));
    next = il.append(new ALOAD(iter.getIndex()));
    node2.setStart(next);
    begin = il.append(methodGen.nextNode());
    il.append(DUP);
    il.append(new ISTORE(node2.getIndex()));
    _falseList.add(il.append(new IFLT(null)));      // NodeIterator.END

    il.append(new ILOAD(node2.getIndex()));
    il.append(new ILOAD(node.getIndex()));
    iter.setEnd(il.append(new IF_ICMPLT(next)));

    node2.setEnd(il.append(new ILOAD(node2.getIndex())));
    node.setEnd(il.append(new ILOAD(node.getIndex())));
    _falseList.add(il.append(new IF_ICMPNE(null)));

    skipNext.setTarget(begin);
}
 
Example 19
Source File: Number.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private void compileDefault(ClassGenerator classGen,
                            MethodGenerator methodGen) {
    int index;
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();

    int[] fieldIndexes = getXSLTC().getNumberFieldIndexes();

    if (fieldIndexes[_level] == -1) {
        Field defaultNode = new Field(ACC_PRIVATE,
                                      cpg.addUtf8(FieldNames[_level]),
                                      cpg.addUtf8(NODE_COUNTER_SIG),
                                      null,
                                      cpg.getConstantPool());

        // Add a new private field to this class
        classGen.addField(defaultNode);

        // Get a reference to the newly added field
        fieldIndexes[_level] = cpg.addFieldref(classGen.getClassName(),
                                               FieldNames[_level],
                                               NODE_COUNTER_SIG);
    }

    // Check if field is initialized (runtime)
    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock1 = il.append(new IFNONNULL(null));

    // Create an instance of DefaultNodeCounter
    index = cpg.addMethodref(ClassNames[_level],
                             "getDefaultNodeCounter",
                             "(" + TRANSLET_INTF_SIG
                             + DOM_INTF_SIG
                             + NODE_ITERATOR_SIG
                             + ")" + NODE_COUNTER_SIG);
    il.append(classGen.loadTranslet());
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadIterator());
    il.append(new INVOKESTATIC(index));
    il.append(DUP);

    // Store the node counter in the field
    il.append(classGen.loadTranslet());
    il.append(SWAP);
    il.append(new PUTFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock2 = il.append(new GOTO(null));

    // Backpatch conditionals
    ifBlock1.setTarget(il.append(classGen.loadTranslet()));
    il.append(new GETFIELD(fieldIndexes[_level]));

    ifBlock2.setTarget(il.append(NOP));
}
 
Example 20
Source File: StepPattern.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
private void translateGeneralContext(ClassGenerator classGen,
                                     MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    int iteratorIndex = 0;
    BranchHandle ifBlock = null;
    LocalVariableGen iter, node, node2;
    final String iteratorName = getNextFieldName();

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

    // Create a new local to store the iterator
    iter = methodGen.addLocalVariable("step_pattern_tmp2",
                                      Util.getJCRefType(NODE_ITERATOR_SIG),
                                      null, null);

    // Add a new private field if this is the main class
    if (!classGen.isExternal()) {
        final Field iterator =
            new Field(ACC_PRIVATE,
                      cpg.addUtf8(iteratorName),
                      cpg.addUtf8(NODE_ITERATOR_SIG),
                      null, cpg.getConstantPool());
        classGen.addField(iterator);
        iteratorIndex = cpg.addFieldref(classGen.getClassName(),
                                        iteratorName,
                                        NODE_ITERATOR_SIG);

        il.append(classGen.loadTranslet());
        il.append(new GETFIELD(iteratorIndex));
        il.append(DUP);
        iter.setStart(il.append(new ASTORE(iter.getIndex())));
        ifBlock = il.append(new IFNONNULL(null));
        il.append(classGen.loadTranslet());
    }

    // Compile the step created at type checking time
    _step.translate(classGen, methodGen);
    InstructionHandle iterStore = il.append(new ASTORE(iter.getIndex()));

    // If in the main class update the field too
    if (!classGen.isExternal()) {
        il.append(new ALOAD(iter.getIndex()));
        il.append(new PUTFIELD(iteratorIndex));
        ifBlock.setTarget(il.append(NOP));
    } else {
        // If class is not external, start of range for iter variable was
        // set above
        iter.setStart(iterStore);
    }

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

    // Initialize the iterator with the parent
    il.append(new ALOAD(iter.getIndex()));
    il.append(SWAP);
    il.append(methodGen.setStartNode());

    /*
     * Inline loop:
     *
     * int node2;
     * while ((node2 = iter.next()) != NodeIterator.END
     *                && node2 < node);
     * return node2 == node;
     */
    BranchHandle skipNext;
    InstructionHandle begin, next;
    node2 = methodGen.addLocalVariable("step_pattern_tmp3",
                                       Util.getJCRefType(NODE_SIG),
                                       null, null);

    skipNext = il.append(new GOTO(null));
    next = il.append(new ALOAD(iter.getIndex()));
    node2.setStart(next);
    begin = il.append(methodGen.nextNode());
    il.append(DUP);
    il.append(new ISTORE(node2.getIndex()));
    _falseList.add(il.append(new IFLT(null)));      // NodeIterator.END

    il.append(new ILOAD(node2.getIndex()));
    il.append(new ILOAD(node.getIndex()));
    iter.setEnd(il.append(new IF_ICMPLT(next)));

    node2.setEnd(il.append(new ILOAD(node2.getIndex())));
    node.setEnd(il.append(new ILOAD(node.getIndex())));
    _falseList.add(il.append(new IF_ICMPNE(null)));

    skipNext.setTarget(begin);
}