/** * Returns a non-array JVM object corresponding to the given non-array JPF object. If such an * object already exists, it is returned. Otherwise a new one is created. */ protected Object getJVMNonArrObj(int JPFRef, MJIEnv env, FeatureExpr ctx) throws ConversionException { Object JVMObj = null; if (JPFRef != MJIEnv.NULL) { // First check if the object has been already created JVMObj = ConverterBase.objMapJPF2JVM.get(JPFRef); /** * If the object has not been created & the given JPF object is not NULL, the corresponding * JVM object is created from JPFRef */ if (JVMObj == null) { // Used to store instance fields DynamicElementInfo dei = (DynamicElementInfo) env.getHeap().get(JPFRef); ClassInfo JPFCl = dei.getClassInfo(); if (!JPFCl.isRegistered()) { JPFCl.registerClass(ctx, env.getThreadInfo()); } // we treat Strings differently if (JPFCl.isStringClassInfo()) { JVMObj = createStringObject(JPFRef, env, ctx); } else { int JPFClsRef = JPFCl.getStaticElementInfo().getClassObjectRef(); Class<?> JVMCl = this.getJVMCls(JPFClsRef, env, ctx); // There is only one instance of every class. There is no need to update // Class objects if (JVMCl == Class.class) { try { String name = env.getReferredClassInfo(ctx, JPFRef).getName(); if (Utilities.isPrimitiveClass(name)) { JVMObj = Utilities.getPrimitiveClass(name); } else { JVMObj = loadClass(name, env, ctx); } } catch (ClassNotFoundException e) { e.printStackTrace(); } return JVMObj; } else { // Creates a new instance of JVMCl JVMObj = instantiateFrom(JVMCl); } ConverterBase.objMapJPF2JVM.put(JPFRef, JVMObj); setInstanceFields(JVMObj, dei, env, ctx); } } else { // Need to update the JVM object fields DynamicElementInfo dei = (DynamicElementInfo) env.getHeap().get(JPFRef); updateInstanceFields(JVMObj, dei, env, ctx); } } return JVMObj; }
@MJI public void $init(MJIEnv env, int objref, FeatureExpr ctx) { ThreadInfo ti = env.getThreadInfo(); StackFrame caller = ti.getCallerStackFrame(); Instruction insn = caller.getPC().getValue(); InsnExecCount a = insn.getAttr(InsnExecCount.class); if (a == null) { a = new InsnExecCount(); insn.addAttr(a); } SystemState ss = env.getSystemState(); if (!ss.hasRestorer(a)) { env.getSystemState().putRestorer(a, new InsnCountRestorer(a)); } a.count++; env.setIntField(ctx, objref, "id", new One<>(a.count)); }