Beispiel #1
0
  /**
   * Returns a new JVM Class object corresponding to the given JPF class. If such a Class object
   * already exists, it is returned. Otherwise a new one is created.
   */
  protected Class<?> getJVMCls(int JPFRef, MJIEnv env, FeatureExpr ctx) throws ConversionException {
    Class<?> JVMCls = null;
    if (JPFRef != MJIEnv.NULL) {
      // First check if the class object has been already created.
      JVMCls = ConverterBase.classMapJPF2JVM.get(JPFRef);

      /**
       * If the Class object has not been created & the given JPF class is not NULL, the
       * corresponding JVM class object is created from JPFRef
       */
      if (JVMCls == null) {
        ClassInfo ci = env.getReferredClassInfo(ctx, JPFRef);

        // Used to store static fields
        StaticElementInfo sei = ci.getStaticElementInfo();

        try {
          JVMCls = loadClass(sei.getClassInfo().getName(), env, ctx);
          ConverterBase.classMapJPF2JVM.put(JPFRef, JVMCls);
        } catch (ClassNotFoundException e) {
          throw new NoClassDefFoundError(sei.getClassInfo().getName());
        }

        assert (JVMCls.getName() != ci.getName());

        setStaticFields(JVMCls, sei, env, ctx);
      }
    }
    return JVMCls;
  }
Beispiel #2
0
  /**
   * 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;
  }
Beispiel #3
0
  public static Class<?> obtainJVMCls(int JPFRef, MJIEnv env, FeatureExpr ctx)
      throws ConversionException {
    if (JPFRef == MJIEnv.NULL) {
      return null;
    }

    ClassInfo ci = env.getReferredClassInfo(ctx, JPFRef);
    JPF2JVMConverter converter = ConverterBase.converterFactory.getJPF2JVMConverter(ci.getName());
    return converter.getJVMCls(JPFRef, env, ctx);
  }