final int namespaceCount = namespaces.size() + 1; final int namesCount = names.size(); final InstructionList il = new InstructionList(); final int[] types = new int[namespaceCount]; final InstructionHandle[] targets = new InstructionHandle[types.length]; String name = (String)names.elementAt(i-DTM.NTYPES); String namespace = name.substring(0,name.lastIndexOf(':')); final int type = xsltc.registerNamespace(namespace); final int getNS = cpg.addInterfaceMethodref(DOM_INTF, "getNamespaceType", "(I)I"); il.append(methodGen.loadDOM()); il.append(new ILOAD(_currentIndex)); il.append(new INVOKEINTERFACE(getNS, 2)); il.append(new SWITCH(types, targets, defaultTarget)); return(il);
System.out.println("Method: " + methodGen.getName() + " - " + methodGen.getSignature() + "in class " + methodGen.getClassName()); InstructionHandle handle = methodGen.getInstructionList().getStart(); while (handle != null) { int bytecodeOffset = handle.getPosition(); if (bytecodeOffset < 0) { throw new IllegalStateException("Bad bytecode offset: " + bytecodeOffset); handle = handle.getNext(); ++numBytecodes;
il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); il.append(methodGen.loadIterator()); il.append(methodGen.loadHandler()); il.append(methodGen.loadCurrentNode()); il.append(new INVOKEVIRTUAL(cpg.addMethodref(className, methodName, "(" int numParams = _parameters.size(); NamedMethodGenerator namedMethodGen = (NamedMethodGenerator)methodGen; Param param = (Param)_parameters.elementAt(i); param.setLoadInstruction(namedMethodGen.loadParameter(i)); param.setStoreInstruction(namedMethodGen.storeParameter(i)); il.setPositions(true);
/** * Create a constructor for the new class. Updates the reference to the * collator in the super calls only when the stylesheet specifies a new * language in xsl:sort. */ private static MethodGenerator compileInit(Vector sortObjects, NodeSortRecordGenerator sortRecord, ConstantPoolGen cpg, String className) { final InstructionList il = new InstructionList(); final MethodGenerator init = new MethodGenerator(ACC_PUBLIC, org.apache.bcel.generic.Type.VOID, null, null, "<init>", className, il, cpg); // Call the constructor in the NodeSortRecord superclass il.append(ALOAD_0); il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD, "<init>", "()V"))); il.append(RETURN); return init; }
/** * 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; }
/** * 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; }
final InstructionList mainIL = new InstructionList(); final MethodGenerator methodGen = new MethodGenerator(ACC_PUBLIC | ACC_FINAL, mainIL.append(new ILOAD(methodGen.getLocalIndex(NODE_PNAME))); current.setStart(mainIL.append(new ISTORE(_currentIndex))); final InstructionList body = new InstructionList(); body.append(NOP); final InstructionList ilLoop = new InstructionList(); ilLoop.append(RETURN); final InstructionHandle ihLoop = ilLoop.getStart(); InstructionHandle ihRecurse = ilRecurse.getStart(); InstructionHandle ihText = ilText.getStart(); isNamespace, isAttribute, false, ihElem); if (nsElem != null) elemNamespaceHandle = nsElem.getStart(); true, ihAttr); InstructionHandle attrNamespaceHandle = ihAttr; if (nsAttr != null) attrNamespaceHandle = nsAttr.getStart(); if (ilKey != null) body.insert(ilKey); final int getType = cpg.addInterfaceMethodref(DOM_INTF,
/** * Translate the fallback element (if any). */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { if (_fallbacks != null) { int count = _fallbacks.size(); for (int i = 0; i < count; i++) { Fallback fallback = (Fallback)_fallbacks.elementAt(i); fallback.translate(classGen, methodGen); } } // We only go into the else block in forward-compatibility mode, when // the unsupported element has no fallback. else { // If the unsupported element does not have any fallback child, then // at runtime, a runtime error should be raised when the unsupported // element is instantiated. Otherwise, no error is thrown. ConstantPoolGen cpg = classGen.getConstantPool(); InstructionList il = methodGen.getInstructionList(); final int unsupportedElem = cpg.addMethodref(BASIS_LIBRARY_CLASS, "unsupported_ElementF", "(" + STRING_SIG + "Z)V"); il.append(new PUSH(cpg, getQName().toString())); il.append(new PUSH(cpg, _isExtension)); il.append(new INVOKESTATIC(unsupportedElem)); } } }
il.append(methodGen.loadCurrentNode()); il.append(SWAP); il.append(methodGen.storeCurrentNode()); 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))); il.append(new PUSH(cpg, _name)); il.append(methodGen.loadDOM()); il.append(methodGen.loadCurrentNode()); il.append(new INVOKEINTERFACE(gname, 2)); il.append(new INVOKEVIRTUAL(cmp)); _falseList.add(il.append(new IFEQ(null))); restore = il.append(methodGen.storeCurrentNode()); backPatchTrueList(restore); BranchHandle skipFalse = il.append(new GOTO(null)); restore = il.append(methodGen.storeCurrentNode());
final InstructionList il = new InstructionList(); final MethodGenerator transf = new MethodGenerator(ACC_PUBLIC, il.append(classGen.loadTranslet()); il.append(new NEW(cpg.addClass(MULTI_DOM_CLASS))); il.append(DUP); il.append(classGen.loadTranslet()); il.append(transf.loadDOM()); il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, "makeDOMAdapter", "("+DOM_INTF_SIG+")"+ "<init>", "("+DOM_INTF_SIG+")V"); il.append(new INVOKESPECIAL(init)); il.append(new PUTFIELD(domField)); "getIterator", "()"+NODE_ITERATOR_SIG); il.append(transf.loadDOM()); il.append(new INVOKEINTERFACE(gitr, 1)); il.append(transf.nextNode()); current.setStart(il.append(new ISTORE(current.getIndex()))); il.append(classGen.loadTranslet());
Util.getJCRefType(NODE_SIG), null, null); match.setStart(il.append(new ISTORE(match.getIndex()))); il.append(new ILOAD(match.getIndex())); translateKernel(classGen, methodGen); il.append(methodGen.loadCurrentNode()); il.append(methodGen.loadIterator()); null, null); stepIteratorTemp.setStart( il.append(new ASTORE(stepIteratorTemp.getIndex()))); il.append(new NEW(cpg.addClass(MATCHING_ITERATOR))); il.append(DUP); il.append(new ILOAD(match.getIndex())); stepIteratorTemp.setEnd( il.append(new ALOAD(stepIteratorTemp.getIndex()))); il.append(new INVOKESPECIAL(index)); il.append(methodGen.loadDOM()); il.append(new ILOAD(match.getIndex())); index = cpg.addInterfaceMethodref(DOM_INTF, GET_PARENT, GET_PARENT_SIG); il.append(new INVOKEINTERFACE(index, 2)); il.append(methodGen.setStartNode()); il.append(methodGen.storeIterator());
il.append(loadInstruction()); BranchHandle ifBlock = il.append(new IFNONNULL(null)); translateValue(classGen, methodGen); il.append(storeInstruction()); ifBlock.setTarget(il.append(NOP)); return; il.append(classGen.loadTranslet()); il.append(new PUSH(cpg, name)); translateValue(classGen, methodGen); il.append(new PUSH(cpg, true)); il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, ADD_PARAMETER, ADD_PARAMETER_SIG))); if (className != EMPTYSTRING) { il.append(new CHECKCAST(cpg.addClass(className))); if (_refs.isEmpty()) { // nobody uses the value il.append(_type.POP()); _local = null; _local.setStart(il.append(_type.STORE(_local.getIndex()))); il.append(classGen.loadTranslet()); il.append(DUP); il.append(new PUSH(cpg, name)); translateValue(classGen, methodGen); il.append(new PUSH(cpg, true));
if (_refs.isEmpty()) { _ignore = true; il.append(_type.STORE(_local.getIndex())); cpg.addUtf8(name), cpg.addUtf8(signature), null, cpg.getConstantPool())); il.append(classGen.loadTranslet()); il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(), name, signature)));
/** * Expects a double on the stack and pushes a boxed double. Boxed * double are represented by an instance of <code>java.lang.Double</code>. * * @see org.apache.xalan.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, ReferenceType type) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); il.append(new NEW(cpg.addClass(DOUBLE_CLASS))); il.append(DUP_X2); il.append(DUP_X2); il.append(POP); il.append(new INVOKESPECIAL(cpg.addMethodref(DOUBLE_CLASS, "<init>", "(D)V"))); }
private void createSetMethod(String method_name, String field_name, Class field_type) { InstructionList tmpIl = new InstructionList(); MethodGen method = new MethodGen(ACC_PUBLIC | ACC_FINAL, Type.VOID, buildArgs(new Class[] {field_type}), new String[] {"arg"}, method_name, classname, tmpIl, cp); tmpIl.append(InstructionConstants.ALOAD_0); tmpIl.append(InstructionConstants.ALOAD_1); tmpIl.append(factory.createFieldAccess(classname, field_name, getObjectType(Object.class), Constants.PUTFIELD)); tmpIl.append(InstructionFactory.createReturn(Type.VOID)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); tmpIl.dispose(); }
InstructionList ctor = new InstructionList(); MethodGen ctorMethod = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, new Type[] {Type.OBJECT}, new String[] {"arg0"}, "<init>", "org.apache.geode.internal.util.bcel.SerializableImplWithValue", ctor, cp); ctorMethod.setMaxStack(2); InstructionHandle ctor_ih_0 = ctor.append(fac.createLoad(Type.OBJECT, 0)); ctor.append(fac.createInvoke(CLASS_NAME_SERIALIZABLE_IMPL, "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL)); InstructionHandle ctor_ih_4 = ctor.append(fac.createLoad(Type.OBJECT, 0)); ctor.append(fac.createLoad(Type.OBJECT, 1)); ctor.append(fac.createFieldAccess(CLASS_NAME_SERIALIZABLE_IMPL_WITH_VALUE, "value", Type.OBJECT, Constants.PUTFIELD)); InstructionHandle ctor_ih_9 = ctor.append(fac.createReturn(Type.VOID)); cg.addMethod(ctorMethod.getMethod()); ctor.dispose(); InstructionList getter = new InstructionList(); InstructionHandle getter_ih_0 = getter.append(fac.createLoad(Type.OBJECT, 0)); InstructionHandle getter_ih_1 = getter.append(fac.createGetField(cg.getClassName(), field.getName(), Type.getType(field.getSignature()))); InstructionHandle getter_ih_4 = getter.append(fac.createReturn(Type.OBJECT)); getter.dispose(); InstructionList setter = new InstructionList();
final InstructionList newIL = new InstructionList(); InstructionList oldMethCopyInIL = new InstructionList(); InstructionList oldMethCopyOutIL = new InstructionList(); InstructionList newMethCopyInIL = new InstructionList(); InstructionList newMethCopyOutIL = new InstructionList(); oldMethCopyInIL.append(new NEW(cpg.addClass(argTypeName))); oldMethCopyInIL.append(InstructionConstants.DUP); oldMethCopyInIL.append(InstructionConstants.DUP); oldMethCopyInIL.append( new INVOKESPECIAL(cpg.addMethodref(argTypeName, "<init>", "()V"))); oldMethCopyOutIL.append( new INVOKESTATIC(cpg.addMethodref( classGen.getClassName(), outlinedMethodName, outlinedMethodGen.getSignature()))); } else { oldMethCopyOutIL.append(InstructionConstants.THIS); oldMethCopyOutIL.append(InstructionConstants.SWAP); outlinedMethodRef = oldMethCopyOutIL.append( new INVOKEVIRTUAL(cpg.addMethodref( classGen.getClassName(), outlinedMethodName, lastCopyHandle = newIL.append((BranchInstruction)c); } else {
/** * Translates an object of this type to its unboxed representation. */ public void translateUnBox(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); il.append(new CHECKCAST(cpg.addClass(BOOLEAN_CLASS))); il.append(new INVOKEVIRTUAL(cpg.addMethodref(BOOLEAN_CLASS, BOOLEAN_VALUE, BOOLEAN_VALUE_SIG))); }
JavaClass target; try { target = Repository.lookupClass("Target"); } catch (final ClassNotFoundException ex) { throw new RuntimeException("unable to resolve Target", ex); } final ClassGen targetGen = new ClassGen(target); final ConstantPoolGen pool = targetGen.getConstantPool(); final ConstantMethodref ref = (ConstantMethodref) pool.getConstant( pool.lookupMethodref("Name", "getName", "()Ljava/lang/String;")); ref.setClassIndex(pool.lookupClass("Target")); ref.setNameAndTypeIndex(pool.addNameAndType("$Name$getName", "()Ljava/lang/String;")); final InstructionList code = new InstructionList(); final InstructionFactory factory = new InstructionFactory(targetGen, pool); code.append(factory.createConstant("overriden-name")); code.append(factory.createReturn(Type.STRING)); code.setPositions(); final MethodGen methodGen = new MethodGen( Constants.ACC_PRIVATE | Constants.ACC_SYNTHETIC | Constants.ACC_STATIC, Type.STRING, new Type[0], new String[0], "$Name$getName", "Target", code, pool); methodGen.setMaxLocals(0); methodGen.setMaxStack(1); targetGen.addMethod(methodGen.getMethod()); try { targetGen.getJavaClass().dump("Target.class"); } catch (final IOException ex) { throw new RuntimeException("unable to save Target", ex); }
private void createMethod_2() { InstructionList il = new InstructionList(); MethodGen method = new MethodGen(ACC_STATIC | ACC_SYNTHETIC, Type.BOOLEAN, Type.NO_ARGS, new String[] { }, "access$0", "StopThread", il, _cp); InstructionHandle ih_0 = il.append(_factory.createFieldAccess("StopThread", "stopRequested", Type.BOOLEAN, Constants.GETSTATIC)); il.append(_factory.createReturn(Type.INT)); method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); }