com.sun.org.apache.bcel.internal.generic.InstructionHandle Java Examples
The following examples show how to use
com.sun.org.apache.bcel.internal.generic.InstructionHandle.
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: Mode.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * Compiles the default action for DOM text nodes and attribute nodes: * output the node's text value */ private InstructionList compileDefaultText(ClassGenerator classGen, MethodGenerator methodGen, InstructionHandle next) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = new InstructionList(); final int chars = cpg.addInterfaceMethodref(DOM_INTF, CHARACTERS, CHARACTERS_SIG); il.append(methodGen.loadDOM()); il.append(new ILOAD(_currentIndex)); il.append(methodGen.loadHandler()); il.append(new INVOKEINTERFACE(chars, 3)); il.append(new GOTO_W(next)); return il; }
Example #2
Source File: Mode.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private void compileTemplateCalls(ClassGenerator classGen, MethodGenerator methodGen, InstructionHandle next, int min, int max){ for (Template template : _neededTemplates.keySet()) { final int prec = template.getImportPrecedence(); if ((prec >= min) && (prec < max)) { if (template.hasContents()) { InstructionList til = template.compile(classGen, methodGen); til.append(new GOTO_W(next)); _templateILs.put(template, til); _templateIHs.put(template, til.getStart()); } else { // empty template _templateIHs.put(template, next); } } } }
Example #3
Source File: Mode.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Compiles the default handling for DOM elements: traverse all children */ private InstructionList compileDefaultRecursion(ClassGenerator classGen, MethodGenerator methodGen, InstructionHandle next) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = new InstructionList(); final String applyTemplatesSig = classGen.getApplyTemplatesSig(); final int git = cpg.addInterfaceMethodref(DOM_INTF, GET_CHILDREN, GET_CHILDREN_SIG); final int applyTemplates = cpg.addMethodref(getClassName(), functionName(), applyTemplatesSig); il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); il.append(methodGen.loadDOM()); il.append(new ILOAD(_currentIndex)); il.append(new INVOKEINTERFACE(git, 2)); il.append(methodGen.loadHandler()); il.append(new INVOKEVIRTUAL(applyTemplates)); il.append(new GOTO_W(next)); return il; }
Example #4
Source File: FlowList.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Redirect the handles from oldList to newList. "This" flow list * is assumed to be relative to oldList. */ public FlowList copyAndRedirect(InstructionList oldList, InstructionList newList) { final FlowList result = new FlowList(); if (_elements == null) { return result; } final int n = _elements.size(); final Iterator oldIter = oldList.iterator(); final Iterator newIter = newList.iterator(); while (oldIter.hasNext()) { final InstructionHandle oldIh = (InstructionHandle) oldIter.next(); final InstructionHandle newIh = (InstructionHandle) newIter.next(); for (int i = 0; i < n; i++) { if (_elements.elementAt(i) == oldIh) { result.add(newIh); } } } return result; }
Example #5
Source File: FlowList.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Redirect the handles from oldList to newList. "This" flow list * is assumed to be relative to oldList. */ public FlowList copyAndRedirect(InstructionList oldList, InstructionList newList) { final FlowList result = new FlowList(); if (_elements == null) { return result; } final int n = _elements.size(); final Iterator oldIter = oldList.iterator(); final Iterator newIter = newList.iterator(); while (oldIter.hasNext()) { final InstructionHandle oldIh = (InstructionHandle) oldIter.next(); final InstructionHandle newIh = (InstructionHandle) newIter.next(); for (int i = 0; i < n; i++) { if (_elements.elementAt(i) == oldIh) { result.add(newIh); } } } return result; }
Example #6
Source File: Mode.java From JDKSourceCode1.8 with MIT License | 6 votes |
/** * Compiles the default action for DOM text nodes and attribute nodes: * output the node's text value */ private InstructionList compileDefaultText(ClassGenerator classGen, MethodGenerator methodGen, InstructionHandle next) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = new InstructionList(); final int chars = cpg.addInterfaceMethodref(DOM_INTF, CHARACTERS, CHARACTERS_SIG); il.append(methodGen.loadDOM()); il.append(new ILOAD(_currentIndex)); il.append(methodGen.loadHandler()); il.append(new INVOKEINTERFACE(chars, 3)); il.append(new GOTO_W(next)); return il; }
Example #7
Source File: MethodGenerator.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public LocalVariableGen addLocalVariable2(String name, Type type, InstructionHandle start) { LocalVariableGen lvg = super.addLocalVariable(name, type, _slotAllocator.allocateSlot(type), start, null); getLocalVariableRegistry().registerLocalVariable(lvg); return lvg; }
Example #8
Source File: FlowList.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Back patch a flow list. All instruction handles must be branch handles. */ public void backPatch(InstructionHandle target) { if (_elements != null) { final int n = _elements.size(); for (int i = 0; i < n; i++) { BranchHandle bh = (BranchHandle)_elements.elementAt(i); bh.setTarget(target); } _elements.clear(); // avoid backpatching more than once } }
Example #9
Source File: MethodGenerator.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * <p>Get all {@link Method}s generated by this {@link MethodGenerator}. * The {@link MethodGen#getMethod()} only returns a single * <code>Method</code> object. This method takes into account the Java * Virtual Machine Specification limit of 64KB on the size of a method, and * may return more than one <code>Method</code>.</p> * <p>If the code associated with the <code>MethodGenerator</code> would * exceed the 64KB limit, this method will attempt to split the code in * the {@link InstructionList} associated with this * <code>MethodGenerator</code> into several methods.</p> * @param classGen the {@link ClassGenerator} of which these methods are * members * @return an array of all the <code>Method</code>s generated */ Method[] getGeneratedMethods(ClassGenerator classGen) { Method[] generatedMethods; InstructionList il = getInstructionList(); InstructionHandle last = il.getEnd(); il.setPositions(); int instructionListSize = last.getPosition() + last.getInstruction().getLength(); // Need to look for any branch target offsets that exceed the range // [-32768,32767] if (instructionListSize > MAX_BRANCH_TARGET_OFFSET) { boolean ilChanged = widenConditionalBranchTargetOffsets(); // If any branch instructions needed widening, recompute the size // of the byte code for the method if (ilChanged) { il.setPositions(); last = il.getEnd(); instructionListSize = last.getPosition() + last.getInstruction().getLength(); } } if (instructionListSize > MAX_METHOD_SIZE) { generatedMethods = outlineChunks(classGen, instructionListSize); } else { generatedMethods = new Method[] {getThisMethod()}; } return generatedMethods; }
Example #10
Source File: AlternativePattern.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final InstructionList il = methodGen.getInstructionList(); _left.translate(classGen, methodGen); final InstructionHandle gotot = il.append(new GOTO(null)); il.append(methodGen.loadContextNode()); _right.translate(classGen, methodGen); _left._trueList.backPatch(gotot); _left._falseList.backPatch(gotot.getNext()); _trueList.append(_right._trueList.add(gotot)); _falseList.append(_right._falseList); }
Example #11
Source File: MethodGenerator.java From JDKSourceCode1.8 with MIT License | 5 votes |
public LocalVariableGen addLocalVariable2(String name, Type type, InstructionHandle start) { LocalVariableGen lvg = super.addLocalVariable(name, type, _slotAllocator.allocateSlot(type), start, null); getLocalVariableRegistry().registerLocalVariable(lvg); return lvg; }
Example #12
Source File: MethodGenerator.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * <p>Get all {@link Method}s generated by this {@link MethodGenerator}. * The {@link MethodGen#getMethod()} only returns a single * <code>Method</code> object. This method takes into account the Java * Virtual Machine Specification limit of 64KB on the size of a method, and * may return more than one <code>Method</code>.</p> * <p>If the code associated with the <code>MethodGenerator</code> would * exceed the 64KB limit, this method will attempt to split the code in * the {@link InstructionList} associated with this * <code>MethodGenerator</code> into several methods.</p> * @param classGen the {@link ClassGenerator} of which these methods are * members * @return an array of all the <code>Method</code>s generated */ Method[] getGeneratedMethods(ClassGenerator classGen) { Method[] generatedMethods; InstructionList il = getInstructionList(); InstructionHandle last = il.getEnd(); il.setPositions(); int instructionListSize = last.getPosition() + last.getInstruction().getLength(); // Need to look for any branch target offsets that exceed the range // [-32768,32767] if (instructionListSize > MAX_BRANCH_TARGET_OFFSET) { boolean ilChanged = widenConditionalBranchTargetOffsets(); // If any branch instructions needed widening, recompute the size // of the byte code for the method if (ilChanged) { il.setPositions(); last = il.getEnd(); instructionListSize = last.getPosition() + last.getInstruction().getLength(); } } if (instructionListSize > MAX_METHOD_SIZE) { generatedMethods = outlineChunks(classGen, instructionListSize); } else { generatedMethods = new Method[] {getThisMethod()}; } return generatedMethods; }
Example #13
Source File: FlowList.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Back patch a flow list. All instruction handles must be branch handles. */ public void backPatch(InstructionHandle target) { if (_elements != null) { final int n = _elements.size(); for (int i = 0; i < n; i++) { BranchHandle bh = (BranchHandle)_elements.elementAt(i); bh.setTarget(target); } _elements.clear(); // avoid backpatching more than once } }
Example #14
Source File: MethodGenerator.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Allocates a local variable. If the slot allocator has already been * initialized, then call addLocalVariable2() so that the new variable * is known to the allocator. Failing to do this may cause the allocator * to return a slot that is already in use. */ public LocalVariableGen addLocalVariable(String name, Type type, InstructionHandle start, InstructionHandle end) { LocalVariableGen lvg; if (_allocatorInit) { lvg = addLocalVariable2(name, type, start); } else { lvg = super.addLocalVariable(name, type, start, end); getLocalVariableRegistry().registerLocalVariable(lvg); } return lvg; }
Example #15
Source File: Whitespace.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void compilePreserveSpace(BranchHandle preserve[], int pCount, InstructionList il) { final InstructionHandle target = il.append(ICONST_0); il.append(IRETURN); for (int i = 0; i < pCount; i++) { preserve[i].setTarget(target); } }
Example #16
Source File: If.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Translate the "test" expression and contents of this element. * The contents will be ignored if we know the test will always fail. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final InstructionList il = methodGen.getInstructionList(); _test.translateDesynthesized(classGen, methodGen); // remember end of condition final InstructionHandle truec = il.getEnd(); if (!_ignore) { translateContents(classGen, methodGen); } _test.backPatchFalseList(il.append(NOP)); _test.backPatchTrueList(truec.getNext()); }
Example #17
Source File: If.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Translate the "test" expression and contents of this element. * The contents will be ignored if we know the test will always fail. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final InstructionList il = methodGen.getInstructionList(); _test.translateDesynthesized(classGen, methodGen); // remember end of condition final InstructionHandle truec = il.getEnd(); if (!_ignore) { translateContents(classGen, methodGen); } _test.backPatchFalseList(il.append(NOP)); _test.backPatchTrueList(truec.getNext()); }
Example #18
Source File: Stylesheet.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Peephole optimization: Remove sequences of [ALOAD, POP]. */ private void peepHoleOptimization(MethodGenerator methodGen) { final String pattern = "`aload'`pop'`instruction'"; final InstructionList il = methodGen.getInstructionList(); final InstructionFinder find = new InstructionFinder(il); for(Iterator iter=find.search(pattern); iter.hasNext(); ) { InstructionHandle[] match = (InstructionHandle[])iter.next(); try { il.delete(match[0], match[1]); } catch (TargetLostException e) { // TODO: move target down into the list } } }
Example #19
Source File: Stylesheet.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Peephole optimization: Remove sequences of [ALOAD, POP]. */ private void peepHoleOptimization(MethodGenerator methodGen) { final String pattern = "`aload'`pop'`instruction'"; final InstructionList il = methodGen.getInstructionList(); final InstructionFinder find = new InstructionFinder(il); for(Iterator iter=find.search(pattern); iter.hasNext(); ) { InstructionHandle[] match = (InstructionHandle[])iter.next(); try { il.delete(match[0], match[1]); } catch (TargetLostException e) { // TODO: move target down into the list } } }
Example #20
Source File: Whitespace.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
public static void compileStripSpace(BranchHandle strip[], int sCount, InstructionList il) { final InstructionHandle target = il.append(ICONST_1); il.append(IRETURN); for (int i = 0; i < sCount; i++) { strip[i].setTarget(target); } }
Example #21
Source File: ProcessingInstructionPattern.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // context node is on the stack int gname = cpg.addInterfaceMethodref(DOM_INTF, "getNodeName", "(I)Ljava/lang/String;"); int cmp = cpg.addMethodref(STRING_CLASS, "equals", "(Ljava/lang/Object;)Z"); // Push current node on the stack il.append(methodGen.loadCurrentNode()); il.append(SWAP); // Overwrite current node with matching node il.append(methodGen.storeCurrentNode()); // If pattern not reduced then check kernel if (!_typeChecked) { il.append(methodGen.loadCurrentNode()); final int getType = cpg.addInterfaceMethodref(DOM_INTF, "getExpandedTypeID", "(I)I"); il.append(methodGen.loadDOM()); il.append(methodGen.loadCurrentNode()); il.append(new INVOKEINTERFACE(getType, 2)); il.append(new PUSH(cpg, DTM.PROCESSING_INSTRUCTION_NODE)); _falseList.add(il.append(new IF_ICMPEQ(null))); } // Load the requested processing instruction name il.append(new PUSH(cpg, _name)); // Load the current processing instruction's name il.append(methodGen.loadDOM()); il.append(methodGen.loadCurrentNode()); il.append(new INVOKEINTERFACE(gname, 2)); // Compare the two strings il.append(new INVOKEVIRTUAL(cmp)); _falseList.add(il.append(new IFEQ(null))); // Compile the expressions within the predicates if (hasPredicates()) { final int n = _predicates.size(); for (int i = 0; i < n; i++) { Predicate pred = (Predicate)_predicates.elementAt(i); Expression exp = pred.getExpr(); exp.translateDesynthesized(classGen, methodGen); _trueList.append(exp._trueList); _falseList.append(exp._falseList); } } // Backpatch true list and restore current iterator/node InstructionHandle restore; restore = il.append(methodGen.storeCurrentNode()); backPatchTrueList(restore); BranchHandle skipFalse = il.append(new GOTO(null)); // Backpatch false list and restore current iterator/node restore = il.append(methodGen.storeCurrentNode()); backPatchFalseList(restore); _falseList.add(il.append(new GOTO(null))); // True list falls through skipFalse.setTarget(il.append(NOP)); }
Example #22
Source File: Expression.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void backPatchFalseList(InstructionHandle ih) { _falseList.backPatch(ih); }
Example #23
Source File: Variable.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
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))); } } }
Example #24
Source File: Expression.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void backPatchTrueList(InstructionHandle ih) { _trueList.backPatch(ih); }
Example #25
Source File: TestSeq.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Compile the code for this test sequence. Compile patterns * from highest to lowest priority. Note that since patterns * can be share by multiple test sequences, instruction lists * must be copied before backpatching. */ public InstructionHandle compile(ClassGenerator classGen, MethodGenerator methodGen, InstructionHandle continuation) { // Returned cached value if already compiled if (_start != null) { return _start; } // If not patterns, then return handle for default template final int count = _patterns.size(); if (count == 0) { return (_start = getTemplateHandle(_default)); } // Init handle to jump when all patterns failed InstructionHandle fail = (_default == null) ? continuation : getTemplateHandle(_default); // Compile all patterns in reverse order for (int n = count - 1; n >= 0; n--) { final LocationPathPattern pattern = getPattern(n); final Template template = pattern.getTemplate(); final InstructionList il = new InstructionList(); // Patterns expect current node on top of stack il.append(methodGen.loadCurrentNode()); // Apply the test-code compiled for the pattern InstructionList ilist = methodGen.getInstructionList(pattern); if (ilist == null) { ilist = pattern.compile(classGen, methodGen); methodGen.addInstructionList(pattern, ilist); } // Make a copy of the instruction list for backpatching InstructionList copyOfilist = ilist.copy(); FlowList trueList = pattern.getTrueList(); if (trueList != null) { trueList = trueList.copyAndRedirect(ilist, copyOfilist); } FlowList falseList = pattern.getFalseList(); if (falseList != null) { falseList = falseList.copyAndRedirect(ilist, copyOfilist); } il.append(copyOfilist); // On success branch to the template code final InstructionHandle gtmpl = getTemplateHandle(template); final InstructionHandle success = il.append(new GOTO_W(gtmpl)); if (trueList != null) { trueList.backPatch(success); } if (falseList != null) { falseList.backPatch(fail); } // Next pattern's 'fail' target is this pattern's first instruction fail = il.getStart(); // Append existing instruction list to the end of this one if (_instructionList != null) { il.append(_instructionList); } // Set current instruction list to be this one _instructionList = il; } return (_start = fail); }
Example #26
Source File: Variable.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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))); } } }
Example #27
Source File: FlowList.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public FlowList(InstructionHandle bh) { _elements = new Vector(); _elements.addElement(bh); }
Example #28
Source File: AbsolutePathPattern.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); if (_left != null) { if (_left instanceof StepPattern) { final LocalVariableGen local = // absolute path pattern temporary methodGen.addLocalVariable2("apptmp", Util.getJCRefType(NODE_SIG), null); il.append(DUP); local.setStart(il.append(new ISTORE(local.getIndex()))); _left.translate(classGen, methodGen); il.append(methodGen.loadDOM()); local.setEnd(il.append(new ILOAD(local.getIndex()))); methodGen.removeLocalVariable(local); } else { _left.translate(classGen, methodGen); } } final int getParent = cpg.addInterfaceMethodref(DOM_INTF, GET_PARENT, GET_PARENT_SIG); final int getType = cpg.addInterfaceMethodref(DOM_INTF, "getExpandedTypeID", "(I)I"); InstructionHandle begin = il.append(methodGen.loadDOM()); il.append(SWAP); il.append(new INVOKEINTERFACE(getParent, 2)); if (_left instanceof AncestorPattern) { il.append(methodGen.loadDOM()); il.append(SWAP); } il.append(new INVOKEINTERFACE(getType, 2)); il.append(new PUSH(cpg, DTM.DOCUMENT_NODE)); final BranchHandle skip = il.append(new IF_ICMPEQ(null)); _falseList.add(il.append(new GOTO_W(null))); skip.setTarget(il.append(NOP)); if (_left != null) { _left.backPatchTrueList(begin); /* * If _left is an ancestor pattern, backpatch this pattern's false * list to the loop that searches for more ancestors. */ if (_left instanceof AncestorPattern) { final AncestorPattern ancestor = (AncestorPattern) _left; _falseList.backPatch(ancestor.getLoopHandle()); // clears list } _falseList.append(_left._falseList); } }
Example #29
Source File: Key.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * This method is called if the "use" attribute of the key contains a * node set. In this case we must traverse all nodes in the set and * create one entry in this key's index for each node in the set. */ public void traverseNodeSet(ClassGenerator classGen, MethodGenerator methodGen, int buildKeyIndex) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // DOM.getStringValueX(nodeIndex) => String final int getNodeValue = cpg.addInterfaceMethodref(DOM_INTF, GET_NODE_VALUE, "(I)"+STRING_SIG); final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF, "getNodeIdent", "(I)"+NODE_SIG); // AbstractTranslet.SetKeyIndexDom(name, Dom) => void final int keyDom = cpg.addMethodref(TRANSLET_CLASS, "setKeyIndexDom", "("+STRING_SIG+DOM_INTF_SIG+")V"); // This variable holds the id of the node we found with the "match" // attribute of xsl:key. This is the id we store, with the value we // get from the nodes we find here, in the index for this key. final LocalVariableGen parentNode = methodGen.addLocalVariable("parentNode", Util.getJCRefType("I"), null, null); // Get the 'parameter' from the stack and store it in a local var. parentNode.setStart(il.append(new ISTORE(parentNode.getIndex()))); // Save current node and current iterator on the stack il.append(methodGen.loadCurrentNode()); il.append(methodGen.loadIterator()); // Overwrite current iterator with one that gives us only what we want _use.translate(classGen, methodGen); _use.startIterator(classGen, methodGen); il.append(methodGen.storeIterator()); final BranchHandle nextNode = il.append(new GOTO(null)); final InstructionHandle loop = il.append(NOP); // Prepare to call buildKeyIndex(String name, int node, String value); il.append(classGen.loadTranslet()); il.append(new PUSH(cpg, _name.toString())); parentNode.setEnd(il.append(new ILOAD(parentNode.getIndex()))); // Now get the node value and push it on the parameter stack il.append(methodGen.loadDOM()); il.append(methodGen.loadCurrentNode()); il.append(new INVOKEINTERFACE(getNodeValue, 2)); // Finally do the call to add an entry in the index for this key. il.append(new INVOKEVIRTUAL(buildKeyIndex)); il.append(classGen.loadTranslet()); il.append(new PUSH(cpg, getName())); il.append(methodGen.loadDOM()); il.append(new INVOKEVIRTUAL(keyDom)); nextNode.setTarget(il.append(methodGen.loadIterator())); il.append(methodGen.nextNode()); il.append(DUP); il.append(methodGen.storeCurrentNode()); il.append(new IFGE(loop)); // Go on to next matching node.... // Restore current node and current iterator from the stack il.append(methodGen.storeIterator()); il.append(methodGen.storeCurrentNode()); }
Example #30
Source File: Key.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Gather all nodes that match the expression in the attribute "match" * and add one (or more) entries in this key's index. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final int current = methodGen.getLocalIndex("current"); // AbstractTranslet.buildKeyIndex(name,node_id,value) => void final int key = cpg.addMethodref(TRANSLET_CLASS, "buildKeyIndex", "("+STRING_SIG+"I"+OBJECT_SIG+")V"); // AbstractTranslet.SetKeyIndexDom(name, Dom) => void final int keyDom = cpg.addMethodref(TRANSLET_CLASS, "setKeyIndexDom", "("+STRING_SIG+DOM_INTF_SIG+")V"); final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF, "getNodeIdent", "(I)"+NODE_SIG); // DOM.getAxisIterator(root) => NodeIterator final int git = cpg.addInterfaceMethodref(DOM_INTF, "getAxisIterator", "(I)"+NODE_ITERATOR_SIG); il.append(methodGen.loadCurrentNode()); il.append(methodGen.loadIterator()); // Get an iterator for all nodes in the DOM il.append(methodGen.loadDOM()); il.append(new PUSH(cpg,Axis.DESCENDANT)); il.append(new INVOKEINTERFACE(git, 2)); // Reset the iterator to start with the root node il.append(methodGen.loadCurrentNode()); il.append(methodGen.setStartNode()); il.append(methodGen.storeIterator()); // Loop for traversing all nodes in the DOM final BranchHandle nextNode = il.append(new GOTO(null)); final InstructionHandle loop = il.append(NOP); // Check if the current node matches the pattern in "match" il.append(methodGen.loadCurrentNode()); _match.translate(classGen, methodGen); _match.synthesize(classGen, methodGen); // Leaves 0 or 1 on stack final BranchHandle skipNode = il.append(new IFEQ(null)); // If this is a node-set we must go through each node in the set if (_useType instanceof NodeSetType) { // Pass current node as parameter (we're indexing on that node) il.append(methodGen.loadCurrentNode()); traverseNodeSet(classGen, methodGen, key); } else { il.append(classGen.loadTranslet()); il.append(DUP); il.append(new PUSH(cpg, _name.toString())); il.append(DUP_X1); il.append(methodGen.loadCurrentNode()); _use.translate(classGen, methodGen); il.append(new INVOKEVIRTUAL(key)); il.append(methodGen.loadDOM()); il.append(new INVOKEVIRTUAL(keyDom)); } // Get the next node from the iterator and do loop again... final InstructionHandle skip = il.append(NOP); il.append(methodGen.loadIterator()); il.append(methodGen.nextNode()); il.append(DUP); il.append(methodGen.storeCurrentNode()); il.append(new IFGT(loop)); // Restore current node and current iterator from the stack il.append(methodGen.storeIterator()); il.append(methodGen.storeCurrentNode()); nextNode.setTarget(skip); skipNode.setTarget(skip); }