private void registerInstructionSinks() throws DataflowAnalysisException { TypeQualifierAnnotation returnValueAnnotation = null; if (!xmethod.getSignature().endsWith(")V")) { returnValueAnnotation = TypeQualifierApplications.getEffectiveTypeQualifierAnnotation(xmethod, typeQualifierValue); } for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Location location = i.next(); Instruction ins = location.getHandle().getInstruction(); if (ins instanceof ReturnInstruction && !(ins instanceof RETURN)) { // Return instruction which returns a value modelReturn(returnValueAnnotation, location); } else { short opcode = ins.getOpcode(); if (opcode == Constants.PUTFIELD || opcode == Constants.PUTSTATIC) { modelFieldStore(location); } else if (location.getHandle().getInstruction() instanceof InvokeInstruction) { modelArguments(location); } } } }
@Override public void inspectResult(ClassContext classContext, MethodGen methodGen, CFG cfg, Dataflow<ResourceValueFrame, ResourceValueAnalysis<Lock>> dataflow, Lock resource) { JavaClass javaClass = classContext.getJavaClass(); ResourceValueFrame exitFrame = dataflow.getResultFact(cfg.getExit()); if (DEBUG) { System.out.println("Resource value at exit: " + exitFrame); } int exitStatus = exitFrame.getStatus(); if (exitStatus == ResourceValueFrame.OPEN || exitStatus == ResourceValueFrame.OPEN_ON_EXCEPTION_PATH) { String bugType; int priority; if (exitStatus == ResourceValueFrame.OPEN) { bugType = "UL_UNRELEASED_LOCK"; priority = HIGH_PRIORITY; } else { bugType = "UL_UNRELEASED_LOCK_EXCEPTION_PATH"; priority = NORMAL_PRIORITY; } String sourceFile = javaClass.getSourceFileName(); Location location = resource.getLocation(); InstructionHandle handle = location.getHandle(); InstructionHandle nextInstruction = handle.getNext(); if (nextInstruction.getInstruction() instanceof RETURN) return; // don't report as error; intentional bugAccumulator.accumulateBug(new BugInstance(this, bugType, priority).addClassAndMethod(methodGen, sourceFile), SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile, handle)); } }
private void createConstructor(GenScope scope, ClassGen cg) { InstructionList il = new InstructionList(); InstructionFactory ifact = new InstructionFactory(cg); MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, new Type[] { } , null, "<init>", cg.getClassName(), il, cg.getConstantPool()); scope.processMethod(mg); // call super il.append(InstructionConstants.THIS); // Push `this' il.append(new INVOKESPECIAL(cg.getConstantPool().addMethodref(cg.getSuperclassName(), "<init>", "()V"))); // Set name il.append( InstructionConstants.THIS ); il.append( ifact.createConstant(this.getName()) ); il.append( ifact.createPutField(cg.getClassName(), "name", Type.STRING) ); Collection<Queue> queues = CommonGen.allQueues(this); for (Queue q : queues) { QueueJVMGen jvmQ = (QueueJVMGen) q; jvmQ.generateInitField(il, ifact, scope); } il.append(InstructionConstants.RETURN); mg.setMaxStack(); cg.addMethod(mg.getMethod()); }
public JavaClass build(GenericRootClass klass) { optimize = (klass.getStreamerInfo().getBits() & (1 << 12)) == 0; //System.out.println("bits=" + Integer.toHexString(klass.getStreamerInfo().getBits()) + " optimize=" + optimize); String className = nameMangler.mangleFullClassName(getStem(),klass.getClassName()); ClassGen cg = new ClassGen(className, "org/dianahep/root4j/core/Clones", "<generated>", ACC_PUBLIC | ACC_SUPER, null); ConstantPoolGen cp = cg.getConstantPool(); InstructionList il = new InstructionList(); InstructionFactory factory = new InstructionFactory(cg); cg.addEmptyConstructor(ACC_PUBLIC); // Build the complete list of superclasses List sup = new ArrayList(); RootClass[] superClasses = klass.getSuperClasses(); iterativelyAdd(sup, superClasses); sup.add(klass); // Generate the fields for (Iterator i = sup.iterator(); i.hasNext();) generateFields((RootClass) i.next(), cp, cg); // Generate the streamer method MethodGen mg = new MethodGen(ACC_PUBLIC, Type.VOID, new Type[] { new ObjectType("org/dianahep/root4j/core/RootInput"), Type.INT }, new String[] { "in", "nClones" }, "read", className, il, cp); mg.addException("java/io/IOException"); for (Iterator i = sup.iterator(); i.hasNext();) generateStreamer((RootClass) i.next(), cp, il, factory, className); il.append(new RETURN()); mg.setMaxStack(); mg.setMaxLocals(); cg.addMethod(mg.getMethod()); il.dispose(); return cg.getJavaClass(); }
void generateMain(ClassGen clg, Method origMain) { InstructionList il = new InstructionList(); MethodGen new_main = new MethodGen(Constants.ACC_STATIC | Constants.ACC_PUBLIC, Type.VOID, new Type[] { new ArrayType( Type.STRING, 1) }, new String[] { "argv" }, "main", clg .getClassName(), il, clg.getConstantPool()); il.append(ins_f.createNew(cashmereType)); il.append(new DUP()); il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL)); il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "isMaster", Type.BOOLEAN, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); BranchHandle ifcmp = il.append(new IFEQ(null)); InstructionHandle origMain_handle = il.append(new ALOAD(0)); InstructionHandle try_start = il.append(ins_f.createInvoke(clg .getClassName(), origMain.getName(), Type.VOID, new Type[] { new ArrayType(Type.STRING, 1) }, Constants.INVOKESTATIC)); BranchHandle try_end = il.append(new GOTO(null)); InstructionHandle e_handler = il.append(getCashmere(ins_f)); il.append(new SWAP()); il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "exit", Type.VOID, new Type[] { new ObjectType("java.lang.Throwable")}, Constants.INVOKEVIRTUAL)); BranchHandle gto2 = il.append(new GOTO(null)); InstructionHandle ifeq_target = il.append(getCashmere(ins_f)); ifcmp.setTarget(ifeq_target); il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "client", Type.VOID, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); il.append(getCashmere(ins_f)); il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "isMaster", Type.BOOLEAN, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); il.append(new IFNE(origMain_handle)); InstructionHandle gto_target = il.append(getCashmere(ins_f)); try_end.setTarget(gto_target); il.append(ins_f.createInvoke("ibis.cashmere.impl.Cashmere", "exit", Type.VOID, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); InstructionHandle gto2_target = il.append(new RETURN()); gto2.setTarget(gto2_target); new_main.addExceptionHandler(try_start, try_end, e_handler, new ObjectType("java.lang.Throwable")); new_main.setMaxStack(); new_main.setMaxLocals(); new_main.addLocalVariable("argv", new ArrayType(Type.STRING, 1), 0, origMain_handle, null); removeLocalTypeTables(new_main); Method main = new_main.getMethod(); gen_c.addMethod(main); }
private String generateObserverClass(ModelDefinition model, ObserverDescription observer, TransformationContext context) { final String className = context.getRuntimeClassName() + "$" + observer.getName(); final String transformationFieldName = "transformation_"; ClassGen cg = new ClassGen(className, observer.getObserverClass(), context.getFilename(), Constants.ACC_PUBLIC | Constants.ACC_SUPER, new String[] {}); cg.addField(new FieldGen(Constants.ACC_PUBLIC, DefaultTypes.QoolTransformation, transformationFieldName, cg.getConstantPool()).getField()); // constructor InstructionList constructorIl = new InstructionList(); InstructionFactory constructorIfact = new InstructionFactory(cg); MethodGen constructor = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, new Type[] { DefaultTypes.QoolTransformation } , null, "<init>", cg.getClassName(), constructorIl, cg.getConstantPool()); constructorIl.append(InstructionConstants.THIS); // Push `this' constructorIl.append(new INVOKESPECIAL(cg.getConstantPool().addMethodref(cg.getSuperclassName(), "<init>", "()V"))); constructorIl.append(InstructionFactory.THIS); constructorIl.append(new ALOAD(1)); constructorIl.append( constructorIfact.createPutField(cg.getClassName(), transformationFieldName, DefaultTypes.QoolTransformation) ); constructorIl.append(InstructionFactory.RETURN); constructor.setMaxLocals(); constructor.setMaxStack(); cg.addMethod(constructor.getMethod()); // end-of constructor EList<UpdateMethod> methods = observer.getUpdateMethods(); for (UpdateMethod updateMethod : methods) { EList<String> ptypes = updateMethod.getParameterTypes(); InstructionList il = new InstructionList(); InstructionFactory ifact = new InstructionFactory(cg); // TODO: Assuming void return type // TODO: Assuming object types Type[] types = new Type[ptypes.size()]; int i = 0; for(String strType : ptypes) { types[i++] = new ObjectType(strType); } MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, types, null, updateMethod.getName(), cg.getClassName(), il, cg.getConstantPool()); // TODO: assuming only 1 interest parameter assert(updateMethod.getInterest().size() == 1); il.append(InstructionConstants.THIS); il.append(ifact.createGetField(className, transformationFieldName, DefaultTypes.QoolTransformation)); il.append(ifact.createConstant(model.getName())); il.append(new ALOAD(updateMethod.getInterest().get(0) + 1)); il.append(ifact.createInvoke(DefaultTypes.QoolTransformation.getClassName(), "addObjectToQueues", Type.VOID, new Type[] { Type.STRING, Type.OBJECT }, Constants.INVOKEVIRTUAL)); il.append(InstructionFactory.RETURN); mg.setMaxLocals(); mg.setMaxStack(); cg.addMethod(mg.getMethod()); } context.addExtraClass(cg.getJavaClass()); return className; }