/** * @see org.apache.bcel.classfile.Visitor#visitCode */ public void visitCode(Code aCode) { for (Iterator iter = mVisitors.iterator(); iter.hasNext();) { IDeepVisitor visitor = (IDeepVisitor) iter.next(); Visitor v = visitor.getClassFileVisitor(); aCode.accept(v); } // perform a deep visit final byte[] code = aCode.getCode(); final InstructionList list = new InstructionList(code); final Iterator it = list.iterator(); for (Iterator iter = list.iterator(); iter.hasNext();) { InstructionHandle instruction = (InstructionHandle) iter.next(); visitInstructionHandle(instruction); } }
private void fillSpawnTable(MethodTableEntry me) { InstructionList il = me.mg.getInstructionList(); InstructionHandle[] ins = il.getInstructionHandles(); il.setPositions(); int spawnId = 0; for (int k = 0; k < ins.length; k++) { if (ins[k].getInstruction() instanceof INVOKEVIRTUAL) { Method target = self.findMethod((INVOKEVIRTUAL) (ins[k] .getInstruction())); JavaClass cl = self.findMethodClass((INVOKEVIRTUAL) (ins[k] .getInstruction())); if (isSpawnable(target, cl)) { // we have a spawn! analyzeSpawn(me, ins[k], spawnId); spawnId++; } } } }
private int calcNrSpawns(MethodGen mg) { InstructionList il = mg.getInstructionList(); if (il == null) { return 0; } InstructionHandle[] ins = il.getInstructionHandles(); int count = 0; for (int i = 0; i < ins.length; i++) { if (ins[i].getInstruction() instanceof INVOKEVIRTUAL) { Method target = self.findMethod((INVOKEVIRTUAL) (ins[i] .getInstruction())); JavaClass cl = self.findMethodClass((INVOKEVIRTUAL) (ins[i] .getInstruction())); if (isSpawnable(target, cl)) { count++; } } } return count; }
boolean containsSpawnedCall(MethodGen m) { InstructionList code = m.getInstructionList(); if (code == null) { return false; } InstructionHandle ih[] = code.getInstructionHandles(); for (int i = 0; i < ih.length; i++) { Instruction ins = ih[i].getInstruction(); if (ins instanceof INVOKEVIRTUAL) { Method target = self.findMethod((INVOKEVIRTUAL) (ins)); JavaClass cl = self.findMethodClass((INVOKEVIRTUAL) (ins)); if (isSpawnable(target, cl)) { return true; } } } return false; }
InstructionHandle insertDeleteSpawncounter(InstructionList il, InstructionHandle i, int maxLocals) { // In this case, jumps to the return must in fact jump to // the new instruction sequence! So, we change the instruction // at the handle. // First, save the return instruction. Instruction r = i.getInstruction(); i.setInstruction(new ALOAD(maxLocals)); i = il .append(i, ins_f.createInvoke( "ibis.cashmere.impl.spawnSync.SpawnCounter", "deleteSpawnCounter", Type.VOID, new Type[] { spawnCounterType }, Constants.INVOKESTATIC)); i = il.append(i, r); return i; }
static private void deleteIns(InstructionList il, InstructionHandle ih, InstructionHandle new_target) { // System.out.println("deleteIns: instructionList = " + il); // System.out.println(" handle = " + ih); try { il.delete(ih); } catch (TargetLostException e) { InstructionHandle[] targets = e.getTargets(); for (int i = 0; i < targets.length; i++) { InstructionTargeter[] targeters = targets[i].getTargeters(); for (int j = 0; j < targeters.length; j++) { targeters[j].updateTarget(targets[i], new_target); } } } }
InstructionHandle pushParams(InstructionList il, Method m) { Type[] params = mtab.typesOfParams(m); InstructionHandle pos = il.getStart(); for (int i = 0, param = 0; i < params.length; i++, param++) { if (params[i].equals(Type.BOOLEAN) || params[i].equals(Type.BYTE) || params[i].equals(Type.SHORT) || params[i].equals(Type.CHAR) || params[i].equals(Type.INT)) { il.insert(pos, new ILOAD(param)); } else if (params[i].equals(Type.FLOAT)) { il.insert(pos, new FLOAD(param)); } else if (params[i].equals(Type.LONG)) { il.insert(pos, new LLOAD(param)); param++; } else if (params[i].equals(Type.DOUBLE)) { il.insert(pos, new DLOAD(param)); param++; } else { il.insert(pos, new ALOAD(param)); } } return pos; }
InstructionHandle rewriteStore(MethodGen m, InstructionList il, InstructionHandle i, int maxLocals, String localClassName) { LocalVariableInstruction curr = (LocalVariableInstruction) (i .getInstruction()); Type type = mtab.getLocalType(m, curr, i.getPosition()); if (type == null) { return i; } String name = mtab.getLocalName(m, curr, i.getPosition()); String fieldName = MethodTable.generatedLocalName(type, name); i.setInstruction(new ALOAD(maxLocals)); i = i.getNext(); if (type.equals(Type.LONG) || type.equals(Type.DOUBLE)) { il.insert(i, new DUP_X2()); il.insert(i, new POP()); } else { il.insert(i, new SWAP()); } i = il.insert(i, ins_f.createFieldAccess(localClassName, fieldName, type, Constants.PUTFIELD)); return i; }
InstructionHandle rewriteLoad(MethodGen m, InstructionList il, InstructionHandle i, int maxLocals, String localClassName) { LocalVariableInstruction curr = (LocalVariableInstruction) (i .getInstruction()); Type type = mtab.getLocalType(m, curr, i.getPosition()); if (type == null) { return i; } String name = mtab.getLocalName(m, curr, i.getPosition()); String fieldName = MethodTable.generatedLocalName(type, name); i.setInstruction(new ALOAD(maxLocals)); i = i.getNext(); i = il.insert(i, ins_f.createFieldAccess(localClassName, fieldName, type, Constants.GETFIELD)); return i; }
private void insertSync(Analyzer analyzer) throws MethodRewriteFailure { d.log(1, "trying to insert sync statement(s)\n"); InstructionHandle[] ihs = analyzer.proposeSyncInsertion(this, new Debug(d.turnedOn(), d.getStartLevel() + 2)); InstructionList instructionList = getInstructionList(); for (InstructionHandle ih : ihs) { InstructionHandle syncInvoke = instructionList.insert(ih, new INVOKEVIRTUAL(indexSync)); InstructionHandle newTarget = instructionList.insert(syncInvoke, spawnableCalls.get(0).getObjectReference().getInstruction()); // the same objectReference for every sync insertion instructionList.redirectBranches(ih, newTarget); d.log(2, "inserted sync()\n"); } d.log(1, "inserted sync statement(s)\n"); }
private boolean callsSync() { ConstantPoolGen cpg = getConstantPool(); InstructionList instructionList = getInstructionList(); InstructionHandle handle = instructionList.getStart(); while (handle != null) { Instruction ins = handle.getInstruction(); if (ins instanceof INVOKEVIRTUAL) { INVOKEVIRTUAL inv = (INVOKEVIRTUAL) ins; if (inv.getMethodName(cpg).equals("sync") && inv.getSignature(cpg).equals("()V")) { JavaClass cl = findMethodClass(inv, cpg); if (cl != null && cl.getClassName().equals("ibis.cashmere.CashmereObject")) { return true; } } } handle = handle.getNext(); } return false; }
private InstructionHandle getLoadInstruction(InstructionList il, SpawnableCall spawnableCall) throws SyncInsertionProposalFailure { InstructionHandle ih = spawnableCall.getInvokeInstruction(); while ((ih = ih.getNext()) != null) { try { LoadInstruction loadInstruction = (LoadInstruction) (ih.getInstruction()); if (spawnableCall.storesIn(loadInstruction.getIndex(), ih)) { return ih; } } catch (ClassCastException e) { } } throw new SyncInsertionProposalFailure(); }
/** * Creates a method class$(String) which is used * during SomeClass.class instruction * * @param generatedClassName the instance class name */ protected void createHelperMethodForDotClassCalls(String generatedClassName) { InstructionList il = new InstructionList(); MethodGen method = new MethodGen(Constants.ACC_STATIC, new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, new String[]{"arg0"}, "class$", generatedClassName, il, constantsPool); InstructionHandle ih0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); il.append(factory.createInvoke("java.lang.Class", "forName", new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, Constants.INVOKESTATIC)); InstructionHandle ih4 = il.append(InstructionFactory.createReturn(Type.OBJECT)); InstructionHandle ih5 = il.append(InstructionFactory.createStore(Type.OBJECT, 1)); il.append(factory.createNew("java.lang.NoClassDefFoundError")); il.append(InstructionConstants.DUP); il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); il.append(factory.createInvoke("java.lang.Throwable", "getMessage", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); il.append(factory.createInvoke("java.lang.NoClassDefFoundError", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL)); il.append(InstructionConstants.ATHROW); method.addExceptionHandler(ih0, ih4, ih5, new ObjectType("java.lang.ClassNotFoundException")); method.setMaxStack(); method.setMaxLocals(); classGen.addMethod(method.getMethod()); il.dispose(); }
private void generateEqualsMethod(String generatedClassName) { /* public boolean equals(Object o) { * return stubHelper.isEquals(this,o); * } */ InstructionList il = new InstructionList(); MethodGen method = new MethodGen(Constants.ACC_PUBLIC, Type.BOOLEAN, new Type[]{Type.OBJECT}, new String[]{"arg0"}, "equals", generatedClassName, il, constantsPool); il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); il.append(factory.createFieldAccess(generatedClassName, "stubHelper", new ObjectType("org.codehaus.jremoting.client.StubHelper"), Constants.GETFIELD)); il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); il.append(factory.createInvoke("org.codehaus.jremoting.client.StubHelper", "isEquals", Type.BOOLEAN, new Type[]{Type.OBJECT, Type.OBJECT}, Constants.INVOKEINTERFACE)); il.append(InstructionFactory.createReturn(Type.INT)); method.setMaxStack(); method.setMaxLocals(); classGen.addMethod(method.getMethod()); il.dispose(); }
/** Handles a single code fragment. */ private void handleCodeFragment(List<String> resultList, ConstantPoolGen cpg, Code code) { for (Instruction i : new InstructionList(code.getCode()) .getInstructions()) { if (i instanceof NEW) { NEW newInstruction = (NEW) i; ObjectType ot = newInstruction.getLoadClassType(cpg); if (ot == null) { // ot is primitive type continue; } String newClassName = ot.getClassName(); if (!resultList.contains(newClassName) && !isBlacklisted(newClassName)) { resultList.add(newClassName); } } } }
@SuppressWarnings("unchecked") private static List<InstructionHandle> get_instr(int mid, long pid) { Util.log("-----------------------------------instr for (" + mid + ", " + pid + ")"); List<InstructionHandle> ret = new ArrayList<InstructionHandle>(); String prefix = "/var/tmp/sifa/path/reconstruction/"; CFG dag = (CFG) Util.readFromFile(prefix + "epp_data/" + mid + ".dag"); Hashtable<Edge, Long> labeled_edge = (Hashtable<Edge, Long>) Util.readFromFile(prefix + "epp_data/" + mid + ".le"); Hashtable<Edge, Long> ldde = (Hashtable<Edge, Long>) Util.readFromFile(prefix + "epp_data/" + mid + ".ldde"); InstructionList ilist = (InstructionList) Util.readFromFile(prefix + "epp_data/" + mid + ".ilist"); PathRegenerator pr = new PathRegenerator(dag, labeled_edge, ldde); List<Integer> path = pr.findPath(pid); Util.log(path.toString()); // for no path sensitivity calculation for (int j = 0; j < path.size(); j++) { InstructionHandle ihdl = ilist.findHandle(path.get(j)); ret.add(ihdl); } // Util.log(new SIFInstructionBlock(mid, ret).toString()); return ret; }
protected void addTransactionMethod(ParsedMethod pm) { String et = EntityTransaction.class.getCanonicalName(); GeneratedMethod gm = new GeneratedMethod(pm); InstructionList il = gm.start(); writeMethodPreamble(gm, il); il.append(_factory.createInvoke(EM_TYPE, "getTransaction", new ObjectType(et), Type.NO_ARGS, Constants.INVOKEINTERFACE)); il.append(_factory.createInvoke(et, pm.getMethod().getName(), Type.VOID, Type.NO_ARGS, Constants.INVOKEINTERFACE)); il.append(InstructionFactory.createReturn(Type.VOID)); gm.done(); }
protected void addPassThruMethod(ParsedMethod m) { GeneratedMethod gm = new GeneratedMethod(m); InstructionList il = gm.start(); Type returnType = gm.getReturnType(); boolean hasArg = m.getArgumentLength() > 0; writeMethodPreamble(gm, il); if (hasArg) il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); il.append(_factory.createInvoke(EM_TYPE, m.getMethod().getName(), returnType == Type.VOID ? Type.VOID : Type.OBJECT, hasArg ? new Type[] { Type.OBJECT } : Type.NO_ARGS, Constants.INVOKEINTERFACE)); if (returnType != Type.VOID) { il.append(_factory.createCheckCast(((ReferenceType) returnType))); } il.append(InstructionFactory.createReturn(returnType)); gm.done(); }
protected void addFindMethod(ParsedMethod m) { GeneratedMethod gm = new GeneratedMethod(m); InstructionList il = gm.start(); writeMethodPreamble(gm, il); il.append(new PUSH(_cp, (ObjectType) gm.getReturnType())); m.getArguments()[0].pushAsObject(il); il.append(_factory.createInvoke(EM_TYPE, "find", Type.OBJECT, new Type[] { Type.CLASS, Type.OBJECT }, Constants.INVOKEINTERFACE)); il.append(_factory.createCheckCast(((ReferenceType) gm.getReturnType()))); il.append(InstructionFactory.createReturn(gm.getReturnType())); gm.done(); }
protected void processMethodAnnotations(ParsedMethod m, InstructionList il) { MaxResults mr = m.getMethod().getAnnotation(MaxResults.class); if (mr != null) { if (mr.value() < 0) { throw new IllegalArgumentException( "MaxResults without a value on " + m.getMethod()); } il.append(new PUSH(_cp, mr.value())); il.append(_factory.createInvoke(TQ_CLASS, "setMaxResults", new ObjectType(TQ_CLASS), new Type[] { Type.INT }, Constants.INVOKEINTERFACE)); } FirstResult fr = m.getMethod().getAnnotation(FirstResult.class); if (fr != null && fr.value() > -1) { il.append(new PUSH(_cp, fr.value())); il.append(_factory.createInvoke(TQ_CLASS, "setFirstResult", new ObjectType(TQ_CLASS), new Type[] { Type.INT }, Constants.INVOKEINTERFACE)); } }
protected void processQuerySetOperation(ParsedMethod m, Argument arg, InstructionList il, String methodName, String queryClass) { Class<?> type = arg.getArgumentClass(); if (type == Integer.class) { arg.push(il); il.append(_factory.createInvoke(INT_CLASS, "intValue", Type.INT, Type.NO_ARGS, Constants.INVOKEINTERFACE)); } else if (type == int.class) { arg.pushPrimitive(il); } else { throw new IllegalArgumentException("Parameter #" + arg.getArgNo() + " of " + m.getMethod() + " needs to be Integer or int."); } il.append(_factory .createInvoke(queryClass, methodName, new ObjectType(queryClass), new Type[] { Type.INT }, Constants.INVOKEINTERFACE)); }
@Test public void testRepositoryClassLookup() throws ClassNotFoundException { JavaClass clazz = Repository.lookupClass("org.treewalk.scms.integration.java.bcel.BcelTest"); ConstantPool pool = clazz.getConstantPool(); System.out.println("Constants:"); for(Constant c: pool.getConstantPool()) { System.out.println(" "+c); } System.out.println("Methods:"); for (Method method: clazz.getMethods()) { System.out.println(" Method: " + method.getName()); Code code = method.getCode(); InstructionList il = new InstructionList(code.getCode()); for (Instruction i: il.getInstructions()) { System.out.println(" "+i); } } }
public void generateGetModel(Variable v, GenScope scope) { InstructionList il = scope.getInstructionList(); InstructionFactory ifact = scope.getInstructionFactory(); try { String modelName = Processor.getModel(v, scope.getTransformationContext()).getModelName(); generateGetModel(modelName, il, ifact, scope); } catch ( IdcException e ) { // System.out.println("Warning: " + e.getMessage()); // no model found! -> obtain model dynamically generateGetModelManager(il, ifact, scope.getTransformationContext(), scope); // get the namespace for the EObject scope.loadVariable(v, il); il.append(ifact.createInvoke(DefaultTypes.ModelManager.getClassName(), "getNamespace", DefaultTypes.IModel, new Type[] { ObjectType.OBJECT }, Constants.INVOKEVIRTUAL)); } }
/** * <<GET_IMODEL(THIS)>> * LDC className * INVOKEINTERFACE createObject */ @Override public void genCreate(Create c, GenScope scope) { InstructionList il = scope.getInstructionList(); InstructionFactory ifact = scope.getInstructionFactory(); ConstantPoolGen cpg = scope.getConstantPool(); // generate model access scope.generateGetModel(modelName); // CommonGen.generateGetModel(modelName, il, ifact, scope.getTransformationContext() ); // push className il.append(new LDC(cpg.addString(c.getClassName()))); // invoke il.append(ifact.createInvoke(DefaultTypes.IModel.getClassName(), "createObject", Type.OBJECT, new Type[] { Type.STRING }, DefaultTypes.IModelCall)); }
private void castIfNeeded(InstructionList il, InstructionFactory ifact, String paramType) { if ( paramType.equals("boolean") ) { il.append(ifact.createCheckCast(new ObjectType(Boolean.class.getName()))); il.append(ifact.createInvoke(Boolean.class.getName(), "booleanValue", Type.BOOLEAN, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); } else if ( paramType.equals("double") ) { il.append(ifact.createCheckCast(new ObjectType(Double.class.getName()))); il.append(ifact.createInvoke(Double.class.getName(), "doubleValue", Type.DOUBLE, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); } else if ( paramType.equals("int") ) { il.append(ifact.createInvoke(DefaultTypes.RuntimeUtil.getClassName(), "convertInt", Type.INT, new Type[] { Type.OBJECT }, Constants.INVOKESTATIC)); //il.append(ifact.createCheckCast(new ObjectType(Integer.class.getName()))); //il.append(ifact.createInvoke(Integer.class.getName(), "intValue", Type.INT, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); } else { ObjectType objectType = new ObjectType(paramType); il.append(ifact.createCheckCast(objectType)); } }
private void appendMethodCall(GenScope scope, InstructionList il, InstructionFactory ifact) { MethodCallJVMGen gen = new MethodCallJVMGen(); gen.setColumn( getColumn() ); gen.setRow( getRow() ); gen.setFile( getFile() ); gen.setName( this.getName() ); gen.setReceptor( this.getReceptor() ); gen.setMethodName( this.getFeatureName() ); gen.generateWithNoVar(scope); // calling MethodHandler.execute(Object receptor, String methodName, IModel model) /* il.append(ifact.createInvoke(DefaultTypes.MethodCallHandler.getClassName(), "execute", Type.OBJECT, new Type[] { DefaultTypes.IModel, Type.OBJECT, Type.STRING }, Constants.INVOKESTATIC)); */ }
private MethodGen createCallMethod(ClassGen closureClass, ClosureScope scope, GenScope parentScope) { InstructionList il = new InstructionList(); MethodGen mg = new MethodGen(Constants.ACC_PUBLIC,// access flags Type.OBJECT, // return type getParameterTypes(), getParameterNames(), // arg // names "call", closureClass.getClassName(), // method, class il, closureClass.getConstantPool()); // TODO: Do it directly in the constructor!! scope.processMethod(mg); GenUtil.generate(this, closureClass, mg, scope, true); // Create proper fields in the class, they will be set when the // instance is created Set<Variable> o = scope.getOuterVariables().get(); for (Variable variable : o) { closureClass.addField(new FieldGen(Constants.ACC_PUBLIC, Type.OBJECT, variable.getName(), closureClass.getConstantPool()).getField()); } return mg; }
@Override public void generate(GenScope scope) { QueueJVMGen jvmQ = (QueueJVMGen) this.getQueue(); // Load the closure into InstructionList il = scope.getInstructionList(); InstructionFactory ifact = scope.getInstructionFactory(); // Get the queue CommonGen.generateGetQueue(scope, jvmQ); // Register the closure scope.loadVariable(this.getValue(), il); il.append(ifact.createInvoke(jvmQ.getClassName(), "put", Type.VOID, new Type[] { Type.OBJECT }, Constants.INVOKEVIRTUAL)); }
@Override public void generateInitField(InstructionList il, InstructionFactory ifact, GenScope scope) { RequiredQueueJVMGen jvmQ = this; ClassGen cg = scope.getClassGen(); il.append(ifact.createNew(jvmQ.getType().getClassName())); il.append(new DUP()); il.append(ifact.createConstant(jvmQ.getName())); // il.append(InstructionConstants.THIS); /* il.append(ifact.createInvoke(jvmQ.getClassName(), "<init>", Type.VOID, new Type[] { Type.STRING, DefaultTypes.QoolTransformation }, Constants.INVOKESPECIAL)); */ // required queues do not take a qool transformation, but just delegates in one il.append(ifact.createInvoke(jvmQ.getClassName(), "<init>", Type.VOID, new Type[] { Type.STRING }, Constants.INVOKESPECIAL)); // Set the field il.append(InstructionConstants.THIS); il.append(InstructionConstants.SWAP); il.append( ifact.createPutField(cg.getClassName(), jvmQ.getFieldName(), jvmQ.getType()) ); }
public void generateConfigure(InstructionList il, InstructionFactory ifact, GenScope scope) { RequiredQueueJVMGen jvmQ = this; ClassGen cg = scope.getClassGen(); // Set the delegate // 1. Get the transformation (as a model) // 2. Obtain the queue il.append( InstructionFactory.THIS ); il.append( ifact.createGetField(cg.getClassName(), jvmQ.getFieldName(), jvmQ.getType()) ); scope.generateGetModel(getImportedModel().getName()); il.append(ifact.createCheckCast(DefaultTypes.QoolTransformation)); il.append(ifact.createConstant(this.getName())); il.append(ifact.createInvoke(DefaultTypes.QoolTransformation.getClassName(), "getQueue", DefaultTypes.IQueue, new Type[] { Type.STRING }, Constants.INVOKEVIRTUAL)); //CommonGen.print(il, ifact); il.append(ifact.createInvoke(jvmQ.getClassName(), "setDelegate", Type.VOID, new Type[] { DefaultTypes.IQueue }, Constants.INVOKEVIRTUAL)); }
@Override public void generate(GenScope scope) { QueueJVMGen jvmQ = (QueueJVMGen) this.getQueue(); // Generate a closure that will be called QForAllContents closureGen = new QForAllContents(); closureGen.generate(scope); // Load the closure into InstructionList il = scope.getInstructionList(); InstructionFactory ifact = scope.getInstructionFactory(); // Get the queue // TODO: I need to find out a better way of getting the transformation // because when I put some class that is not a closure and the code need // the transformation this just does not work (and fail in the validation with // "incompatible argument for function call" ! scope.generateGetTransformation(); il.append(ifact.createCheckCast(new ObjectType(scope.getTransformationContext().getRuntimeClassName()))); il.append(ifact.createGetField(scope.getTransformationContext().getRuntimeClassName(), jvmQ.getFieldName(), jvmQ.getType())); // Register the closure org.eclectic.idc.jvm.runtime scope.loadVariable(closureGen, il); il.append(ifact.createInvoke(jvmQ.getType().getClassName(), "requestAll", Type.VOID, new Type[] { DefaultTypes.IClosure }, Constants.INVOKEVIRTUAL)); }
private void createObserverCreatorMethod(ClassGen cg, ObserverDescription observer, String observerClassName) { final String methodName = "create" + observer.getName(); InstructionList il = new InstructionList(); InstructionFactory ifact = new InstructionFactory(cg); MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, new ObjectType(observerClassName), new Type[] { } , null, methodName, cg.getClassName(), il, cg.getConstantPool()); il.append(ifact.createNew(observerClassName)); il.append(InstructionConstants.DUP); il.append(InstructionConstants.THIS); il.append(ifact.createInvoke(observerClassName, "<init>", Type.VOID, new Type[] { DefaultTypes.QoolTransformation }, Constants.INVOKESPECIAL)); il.append(InstructionFactory.ARETURN); mg.setMaxLocals(); mg.setMaxStack(); cg.addMethod(mg.getMethod()); }
@Override public void generateInitField(InstructionList il, InstructionFactory ifact, GenScope scope) { LocalQueueJVMGen jvmQ = this; ClassGen cg = scope.getClassGen(); il.append(ifact.createNew(jvmQ.getType().getClassName())); il.append(new DUP()); il.append(ifact.createConstant(jvmQ.getName())); il.append(InstructionConstants.THIS); il.append(ifact.createInvoke(jvmQ.getClassName(), "<init>", Type.VOID, new Type[] { Type.STRING, DefaultTypes.QoolTransformation }, Constants.INVOKESPECIAL)); // Stack: queue il.append(InstructionConstants.THIS); il.append(InstructionConstants.SWAP); il.append( ifact.createPutField(cg.getClassName(), jvmQ.getFieldName(), jvmQ.getType()) ); }
@Override public void generateConfigureOptimizations(InstructionList il, InstructionFactory ifact, GenScope scope) { if ( getOptimizations().size() > 1 ) throw new UnsupportedOperationException("Only one optimization at a time supported by now"); if ( getOptimizations().size() == 1 ) { AccessByFeatureOptimization opt = (AccessByFeatureOptimization) getOptimizations().get(0); il.append(new DUP()); il.append(ifact.createConstant(opt.getFeatureName())); il.append(ifact.createInvoke(this.getClassName(), "configureAccessByFeatureOptimization", Type.VOID, new Type[] { Type.STRING }, Constants.INVOKEVIRTUAL)); // TODO: Configure if the access is speculative... } // Sets the model of the queue statically // It is compulsory to have a type for the queue to enable optimizations if ( getOptimizations().size() > 0 ) { il.append(new DUP()); scope.generateGetModel(this.getType_().getModel().getName()); il.append(ifact.createInvoke(this.getClassName(), "setModel", Type.VOID, new Type[] { DefaultTypes.IModel }, Constants.INVOKEVIRTUAL)); } }
public void generate(ClassGen cg, GenScope scope, String methodName) { InstructionList il = new InstructionList(); MethodGen mg = new MethodGen(Constants.ACC_PUBLIC,// access flags Type.VOID, // return type null, null, // arg // names methodName, cg.getClassName(), // method, class il, cg.getConstantPool()); scope.processMethod(mg); GenUtil.generate(this, cg, mg, scope); cg.addMethod(mg.getMethod()); }
public void genContinuableCallCode(GenScope transformationScope, ClassGen cg, MethodGen mg) { InstructionList il = mg.getInstructionList(); InstructionFactory ifact = new InstructionFactory(cg); il.append(InstructionConstants.THIS); il.append(ifact.createConstant(getSegmentClassName())); transformationScope.generateGetTransformation(); transformationScope.generateGetModelManager(); il.append(ifact.createInvoke(DefaultTypes.QoolTransformation.getClassName(), "startSegment", Type.VOID, new Type[] { Type.STRING, DefaultTypes.IdcTransformation, DefaultTypes.ModelManager }, Constants.INVOKEVIRTUAL)); /* il.append(ifact.createConstant(getSegmentClassName())); transformationScope.generateGetTransformation(); transformationScope.generateGetModelManager(); il.append(ifact.createInvoke(DefaultTypes.RuntimeUtil.getClassName(), "startSegment", Type.VOID, new Type[] { Type.STRING, DefaultTypes.IdcTransformation, DefaultTypes.ModelManager }, Constants.INVOKESTATIC)); */ }
private void createStartMethod(GenScope scope, ClassGen cg) { InstructionList il = new InstructionList(); InstructionFactory ifact = new InstructionFactory(cg); MethodGen startMg = new MethodGen(Constants.ACC_PUBLIC,// access flags Type.VOID, // return type null, null, // arg // names START_METHOD, null, // method, class il, cg.getConstantPool()); scope.processMethod(startMg); il.append(InstructionConstants.RETURN); startMg.setMaxLocals(); startMg.setMaxStack(); cg.addMethod(startMg.getMethod()); }
public void generateReadCode(InstructionList il, InstructionFactory factory, ConstantPoolGen cp, String className) { String leafClassName = getClass().getName(); int arrayDim = getArrayDim(); if (arrayDim == 0) il.append(factory.createInvoke(leafClassName, "getValue", Type.BOOLEAN, new Type[] { Type.LONG }, INVOKEVIRTUAL)); else il.append(factory.createInvoke(leafClassName, "getWrappedValue", Type.OBJECT, new Type[] { Type.LONG }, INVOKEVIRTUAL)); }