Java 类com.sun.org.apache.bcel.internal.generic.PUTFIELD 实例源码

项目:OpenJSharp    文件:Variable.java   
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
项目:OpenJSharp    文件:Number.java   
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));
}
项目:OpenJSharp    文件:Predicate.java   
/**
 * Translate a predicate expression. This translation pushes
 * two references on the stack: a reference to a newly created
 * filter object and a reference to the predicate's closure.
 */
public void translateFilter(ClassGenerator classGen,
                            MethodGenerator methodGen)
{
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Compile auxiliary class for filter
    compileFilter(classGen, methodGen);

    // Create new instance of filter
    il.append(new NEW(cpg.addClass(_className)));
    il.append(DUP);
    il.append(new INVOKESPECIAL(cpg.addMethodref(_className,
                                                 "<init>", "()V")));

    // Initialize closure variables
    final int length = (_closureVars == null) ? 0 : _closureVars.size();

    for (int i = 0; i < length; i++) {
        VariableRefBase varRef = (VariableRefBase) _closureVars.get(i);
        VariableBase var = varRef.getVariable();
        Type varType = var.getType();

        il.append(DUP);

        // Find nearest closure implemented as an inner class
        Closure variableClosure = _parentClosure;
        while (variableClosure != null) {
            if (variableClosure.inInnerClass()) break;
            variableClosure = variableClosure.getParentClosure();
        }

        // Use getfield if in an inner class
        if (variableClosure != null) {
            il.append(ALOAD_0);
            il.append(new GETFIELD(
                cpg.addFieldref(variableClosure.getInnerClassName(),
                    var.getEscapedName(), varType.toSignature())));
        }
        else {
            // Use a load of instruction if in translet class
            il.append(var.loadInstruction());
        }

        // Store variable in new closure
        il.append(new PUTFIELD(
                cpg.addFieldref(_className, var.getEscapedName(),
                    varType.toSignature())));
    }
}
项目:openjdk-jdk10    文件:Variable.java   
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
项目:openjdk-jdk10    文件:Number.java   
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));
}
项目:openjdk-jdk10    文件:Predicate.java   
/**
 * Translate a predicate expression. This translation pushes
 * two references on the stack: a reference to a newly created
 * filter object and a reference to the predicate's closure.
 */
public void translateFilter(ClassGenerator classGen,
                            MethodGenerator methodGen)
{
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Compile auxiliary class for filter
    compileFilter(classGen, methodGen);

    // Create new instance of filter
    il.append(new NEW(cpg.addClass(_className)));
    il.append(DUP);
    il.append(new INVOKESPECIAL(cpg.addMethodref(_className,
                                                 "<init>", "()V")));

    // Initialize closure variables
    final int length = (_closureVars == null) ? 0 : _closureVars.size();

    for (int i = 0; i < length; i++) {
        VariableRefBase varRef = (VariableRefBase) _closureVars.get(i);
        VariableBase var = varRef.getVariable();
        Type varType = var.getType();

        il.append(DUP);

        // Find nearest closure implemented as an inner class
        Closure variableClosure = _parentClosure;
        while (variableClosure != null) {
            if (variableClosure.inInnerClass()) break;
            variableClosure = variableClosure.getParentClosure();
        }

        // Use getfield if in an inner class
        if (variableClosure != null) {
            il.append(ALOAD_0);
            il.append(new GETFIELD(
                cpg.addFieldref(variableClosure.getInnerClassName(),
                    var.getEscapedName(), varType.toSignature())));
        }
        else {
            // Use a load of instruction if in translet class
            il.append(var.loadInstruction());
        }

        // Store variable in new closure
        il.append(new PUTFIELD(
                cpg.addFieldref(_className, var.getEscapedName(),
                    varType.toSignature())));
    }
}
项目:openjdk9    文件:Variable.java   
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
项目:openjdk9    文件:Number.java   
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));
}
项目:openjdk9    文件:Predicate.java   
/**
 * Translate a predicate expression. This translation pushes
 * two references on the stack: a reference to a newly created
 * filter object and a reference to the predicate's closure.
 */
public void translateFilter(ClassGenerator classGen,
                            MethodGenerator methodGen)
{
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Compile auxiliary class for filter
    compileFilter(classGen, methodGen);

    // Create new instance of filter
    il.append(new NEW(cpg.addClass(_className)));
    il.append(DUP);
    il.append(new INVOKESPECIAL(cpg.addMethodref(_className,
                                                 "<init>", "()V")));

    // Initialize closure variables
    final int length = (_closureVars == null) ? 0 : _closureVars.size();

    for (int i = 0; i < length; i++) {
        VariableRefBase varRef = (VariableRefBase) _closureVars.get(i);
        VariableBase var = varRef.getVariable();
        Type varType = var.getType();

        il.append(DUP);

        // Find nearest closure implemented as an inner class
        Closure variableClosure = _parentClosure;
        while (variableClosure != null) {
            if (variableClosure.inInnerClass()) break;
            variableClosure = variableClosure.getParentClosure();
        }

        // Use getfield if in an inner class
        if (variableClosure != null) {
            il.append(ALOAD_0);
            il.append(new GETFIELD(
                cpg.addFieldref(variableClosure.getInnerClassName(),
                    var.getEscapedName(), varType.toSignature())));
        }
        else {
            // Use a load of instruction if in translet class
            il.append(var.loadInstruction());
        }

        // Store variable in new closure
        il.append(new PUTFIELD(
                cpg.addFieldref(_className, var.getEscapedName(),
                    varType.toSignature())));
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:Variable.java   
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:Number.java   
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));
}
项目:lookaside_java-1.8.0-openjdk    文件:Predicate.java   
/**
 * Translate a predicate expression. This translation pushes
 * two references on the stack: a reference to a newly created
 * filter object and a reference to the predicate's closure.
 */
public void translateFilter(ClassGenerator classGen,
                            MethodGenerator methodGen)
{
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Compile auxiliary class for filter
    compileFilter(classGen, methodGen);

    // Create new instance of filter
    il.append(new NEW(cpg.addClass(_className)));
    il.append(DUP);
    il.append(new INVOKESPECIAL(cpg.addMethodref(_className,
                                                 "<init>", "()V")));

    // Initialize closure variables
    final int length = (_closureVars == null) ? 0 : _closureVars.size();

    for (int i = 0; i < length; i++) {
        VariableRefBase varRef = (VariableRefBase) _closureVars.get(i);
        VariableBase var = varRef.getVariable();
        Type varType = var.getType();

        il.append(DUP);

        // Find nearest closure implemented as an inner class
        Closure variableClosure = _parentClosure;
        while (variableClosure != null) {
            if (variableClosure.inInnerClass()) break;
            variableClosure = variableClosure.getParentClosure();
        }

        // Use getfield if in an inner class
        if (variableClosure != null) {
            il.append(ALOAD_0);
            il.append(new GETFIELD(
                cpg.addFieldref(variableClosure.getInnerClassName(),
                    var.getEscapedName(), varType.toSignature())));
        }
        else {
            // Use a load of instruction if in translet class
            il.append(var.loadInstruction());
        }

        // Store variable in new closure
        il.append(new PUTFIELD(
                cpg.addFieldref(_className, var.getEscapedName(),
                    varType.toSignature())));
    }
}
项目:infobip-open-jdk-8    文件:Variable.java   
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
项目:infobip-open-jdk-8    文件:Number.java   
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));
}
项目:infobip-open-jdk-8    文件:Predicate.java   
/**
 * Translate a predicate expression. This translation pushes
 * two references on the stack: a reference to a newly created
 * filter object and a reference to the predicate's closure.
 */
public void translateFilter(ClassGenerator classGen,
                            MethodGenerator methodGen)
{
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Compile auxiliary class for filter
    compileFilter(classGen, methodGen);

    // Create new instance of filter
    il.append(new NEW(cpg.addClass(_className)));
    il.append(DUP);
    il.append(new INVOKESPECIAL(cpg.addMethodref(_className,
                                                 "<init>", "()V")));

    // Initialize closure variables
    final int length = (_closureVars == null) ? 0 : _closureVars.size();

    for (int i = 0; i < length; i++) {
        VariableRefBase varRef = (VariableRefBase) _closureVars.get(i);
        VariableBase var = varRef.getVariable();
        Type varType = var.getType();

        il.append(DUP);

        // Find nearest closure implemented as an inner class
        Closure variableClosure = _parentClosure;
        while (variableClosure != null) {
            if (variableClosure.inInnerClass()) break;
            variableClosure = variableClosure.getParentClosure();
        }

        // Use getfield if in an inner class
        if (variableClosure != null) {
            il.append(ALOAD_0);
            il.append(new GETFIELD(
                cpg.addFieldref(variableClosure.getInnerClassName(),
                    var.getEscapedName(), varType.toSignature())));
        }
        else {
            // Use a load of instruction if in translet class
            il.append(var.loadInstruction());
        }

        // Store variable in new closure
        il.append(new PUTFIELD(
                cpg.addFieldref(_className, var.getEscapedName(),
                    varType.toSignature())));
    }
}
项目:OLD-OpenJDK8    文件:Variable.java   
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
项目:OLD-OpenJDK8    文件:Number.java   
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));
}
项目:OLD-OpenJDK8    文件:Predicate.java   
/**
 * Translate a predicate expression. This translation pushes
 * two references on the stack: a reference to a newly created
 * filter object and a reference to the predicate's closure.
 */
public void translateFilter(ClassGenerator classGen,
                            MethodGenerator methodGen)
{
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Compile auxiliary class for filter
    compileFilter(classGen, methodGen);

    // Create new instance of filter
    il.append(new NEW(cpg.addClass(_className)));
    il.append(DUP);
    il.append(new INVOKESPECIAL(cpg.addMethodref(_className,
                                                 "<init>", "()V")));

    // Initialize closure variables
    final int length = (_closureVars == null) ? 0 : _closureVars.size();

    for (int i = 0; i < length; i++) {
        VariableRefBase varRef = (VariableRefBase) _closureVars.get(i);
        VariableBase var = varRef.getVariable();
        Type varType = var.getType();

        il.append(DUP);

        // Find nearest closure implemented as an inner class
        Closure variableClosure = _parentClosure;
        while (variableClosure != null) {
            if (variableClosure.inInnerClass()) break;
            variableClosure = variableClosure.getParentClosure();
        }

        // Use getfield if in an inner class
        if (variableClosure != null) {
            il.append(ALOAD_0);
            il.append(new GETFIELD(
                cpg.addFieldref(variableClosure.getInnerClassName(),
                    var.getEscapedName(), varType.toSignature())));
        }
        else {
            // Use a load of instruction if in translet class
            il.append(var.loadInstruction());
        }

        // Store variable in new closure
        il.append(new PUTFIELD(
                cpg.addFieldref(_className, var.getEscapedName(),
                    varType.toSignature())));
    }
}
项目:openjdk-icedtea7    文件:Variable.java   
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
项目:openjdk-icedtea7    文件:Number.java   
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));
}
项目:openjdk-icedtea7    文件:Predicate.java   
/**
 * Translate a predicate expression. This translation pushes
 * two references on the stack: a reference to a newly created
 * filter object and a reference to the predicate's closure.
 */
public void translateFilter(ClassGenerator classGen,
                            MethodGenerator methodGen)
{
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Compile auxiliary class for filter
    compileFilter(classGen, methodGen);

    // Create new instance of filter
    il.append(new NEW(cpg.addClass(_className)));
    il.append(DUP);
    il.append(new INVOKESPECIAL(cpg.addMethodref(_className,
                                                 "<init>", "()V")));

    // Initialize closure variables
    final int length = (_closureVars == null) ? 0 : _closureVars.size();

    for (int i = 0; i < length; i++) {
        VariableRefBase varRef = (VariableRefBase) _closureVars.get(i);
        VariableBase var = varRef.getVariable();
        Type varType = var.getType();

        il.append(DUP);

        // Find nearest closure implemented as an inner class
        Closure variableClosure = _parentClosure;
        while (variableClosure != null) {
            if (variableClosure.inInnerClass()) break;
            variableClosure = variableClosure.getParentClosure();
        }

        // Use getfield if in an inner class
        if (variableClosure != null) {
            il.append(ALOAD_0);
            il.append(new GETFIELD(
                cpg.addFieldref(variableClosure.getInnerClassName(),
                    var.getEscapedName(), varType.toSignature())));
        }
        else {
            // Use a load of instruction if in translet class
            il.append(var.loadInstruction());
        }

        // Store variable in new closure
        il.append(new PUTFIELD(
                cpg.addFieldref(_className, var.getEscapedName(),
                    varType.toSignature())));
    }
}