Package gov.nasa.jpf.vm

Examples of gov.nasa.jpf.vm.ClassInfo


    TestJPF.assertEquals(JVM2JPFTestConversion.i, 10);

    ConverterBase.reset(env);
   
    // converting JVM class to JPF class
    ClassInfo ci = JVM2JPFConverter.obtainJPFCls(cls, env);

    return ci.getClassObjectRef();
  }
View Full Code Here


*/
public class JPF2JVMGenericConverter extends JPF2JVMConverter {
 
  @Override
  protected void setStaticFields(Class<?> JVMCls, StaticElementInfo sei, MJIEnv env) throws ConversionException {
    ClassInfo ci = sei.getClassInfo();
    while (JVMCls!=null) {
      Field fld[] = JVMCls.getDeclaredFields();

      for (int i = 0; i < fld.length; i++) {
        boolean isStatic = ((Modifier.toString(fld[i].getModifiers())).indexOf("static") != -1);
        boolean isFinal = ((Modifier.toString(fld[i].getModifiers())).indexOf("final") != -1);

        // Provide access to private and final fields
        fld[i].setAccessible(true);
        FieldInfo fi = sei.getFieldInfo(fld[i].getName());

        // For class only set the values of static fields
        if (fi != null && isStatic) {
          /**
           * Why we check for !(isFinal)?
           *
           * We do not set the value for "static final" fields. But we take
           * care of "non-static final" fields.
           *
           * static final fields can be initialized at the declaration time,
           * OW it MUST be initialized inside the static block. By using
           * Class.forName() the class is initialized. Since when the class
           * is initialized the static blocks are executed, the static final
           * fields of object returned by Class.forName() have already have
           * the right values and we do not need to update their value.
           *
           * Non-static final fields can be initialized at the declaration
           * time. But if the non-static field is final blank, it MUST be
           * initialized in the constructor. By using Class.newInstance()
           * the class is instantiated as if by a new expression with an
           * empty argument list. If the object represented by JPFRef
           * created using different constructor, the value of final blank
           * fields might be different when using the constructor with an
           * empty argument list. Therefore the values of non-static final
           * fields have to be set.
           */
          if (!isFinal) {
            // If the current field is of reference type
            if (fi.isReference()) {
              int fieldValueRef = sei.getFields().getReferenceValue(fi.getStorageOffset());
              Object JVMField = obtainJVMObj(fieldValueRef, env);
              try {
                fld[i].set(null, JVMField);
              } catch (IllegalArgumentException e) {
                e.printStackTrace();
              } catch (IllegalAccessException e) {
                e.printStackTrace();
              }
            }
            // If the current field is of primitive type
            else {
              try {
                Utilities.setJVMPrimitiveField(fld[i], JVMCls, sei, fi);
              } catch (IllegalAccessException e) {
                e.printStackTrace();
              }
            }
          }
        }
      }

      JVMCls = JVMCls.getSuperclass();
      ci = ci.getSuperClass();
      if(ci != null) {
        sei = ci.getStaticElementInfo();
      }
    }
  }
View Full Code Here

  }

  @Override
  protected void setInstanceFields(Object JVMObj, DynamicElementInfo dei, MJIEnv env) throws ConversionException {
    Class<?> cls = JVMObj.getClass();
    ClassInfo JPFCl = dei.getClassInfo();

    while (cls!=null) {
      Field fld[] = cls.getDeclaredFields();

      for (int i = 0; i < fld.length; i++) {

        // It is true if the field is declared as static.
        boolean isNonStaticField = ((Modifier.toString(fld[i].getModifiers())).indexOf("static") == -1);

        // Provide access to private and final fields
        fld[i].setAccessible(true);
        FieldInfo fi = JPFCl.getInstanceField(fld[i].getName());

        if (fi != null && isNonStaticField) {
          // Field is of reference type
          if (fi.isReference()) {
            int fieldValueRef = dei.getFields().getReferenceValue(fi.getStorageOffset());
            Object JVMField = obtainJVMObj(fieldValueRef, env);

            try {
              fld[i].set(JVMObj, JVMField);
            } catch (IllegalArgumentException e) {
              e.printStackTrace();
            } catch (IllegalAccessException e) {
              e.printStackTrace();
            }
          }
          // Field is of primitive type
          else {
            try {
              Utilities.setJVMPrimitiveField(fld[i], JVMObj, dei, fi);
            } catch (IllegalAccessException e) {
              e.printStackTrace();
            }
          }
        }
      }
      cls = cls.getSuperclass();
      JPFCl = JPFCl.getSuperClass();
    }
  }
View Full Code Here

  public static Class<?> obtainJVMCls (int JPFRef, MJIEnv env) throws ConversionException {
    if (JPFRef == MJIEnv.NULL) {
      return null;
    }

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

    if (JPFRef == MJIEnv.NULL) {
      return null;
    }

    DynamicElementInfo dei = (DynamicElementInfo) env.getHeap().get(JPFRef);
    ClassInfo ci = dei.getClassInfo();
    JPF2JVMConverter converter = ConverterBase.converterFactory.getJPF2JVMConverter(ci.getName());
    return converter.getJVMObj(JPFRef, env);
  }
View Full Code Here

      /**
       * 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(JPFRef);

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

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

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

        setStaticFields(JVMCls, sei, env);
      }
    }
    return JVMCls;
View Full Code Here

       * 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(env.getThreadInfo());
        }
       
        // we treat Strings differently
        if(JPFCl.isStringClassInfo()) {
          JVMObj = createStringObject(JPFRef, env);
        } else {
          int JPFClsRef = JPFCl.getStaticElementInfo().getClassObjectRef();
          Class<?> JVMCl = this.getJVMCls(JPFClsRef, env);

          // There is only one instance of every class. There is no need to update
          // Class objects
          if (JVMCl == Class.class) {
View Full Code Here

  }

  @Override
  protected void setInstanceFields(Object JVMObj, DynamicElementInfo dei, MJIEnv env) throws ConversionException {
    Class<?> JVMCl = JVMObj.getClass();
    ClassInfo JPFCl = this.getJPFCls(JVMObj.getClass(), env);

    while (JVMCl!=null){
      Field fld[] = JVMCl.getDeclaredFields();

      for (int i = 0; i < fld.length; i++){
        // Check if the field is declared as non-static
        boolean isNonStaticField = ((Modifier.toString(fld[i].getModifiers())).indexOf("static") == -1);
        FieldInfo fi = JPFCl.getInstanceField(fld[i].getName());
        fld[i].setAccessible(true);

        if (fi != null && isNonStaticField){
          // If the current field is of reference type
          if (fi.isReference()){
            int JPFfldValue = MJIEnv.NULL;
            Object JVMfldValue = null;

            try{
              // retrieving the value of the field in JVM
              JVMfldValue = fld[i].get(JVMObj);
            } catch (IllegalAccessException e2){
              e2.printStackTrace();
            }

            JPFfldValue = dei.getReferenceField(fi);

            if (JVMfldValue == null){
              JPFfldValue = MJIEnv.NULL;
            } else if (JPFfldValue == MJIEnv.NULL || ConverterBase.objMapJPF2JVM.get(JPFfldValue) != JVMfldValue){
              JPFfldValue = obtainJPFObj(JVMfldValue, env);
            } else if (ConverterBase.objMapJPF2JVM.get(JPFfldValue) == JVMfldValue){
              updateJPFObj(JVMfldValue, JPFfldValue, env);
            } else{
              throw new ConversionException("Unconsidered case observed! - JVM2JPF.updateObj()");
            }
            dei.setReferenceField(fi, JPFfldValue);
          }
          // If the current field is of primitive type
          else{
            try{
              Utilities.setJPFPrimitiveField(dei, fi.getStorageOffset(), fld[i], JVMObj);
            } catch (IllegalAccessException e){
              e.printStackTrace();
            }
          }
        }
      }
      JVMCl = JVMCl.getSuperclass();
      JPFCl = JPFCl.getSuperClass();
    }
  }
View Full Code Here

   *
   * @throws ConversionException
   *           if any incorrect input parameter is observed
   */
  protected ClassInfo getJPFCls (Class<?> JVMCls, MJIEnv env) throws ConversionException{
    ClassInfo JPFCls = null;
    int JPFClsRef = Integer.MIN_VALUE;

    if (JVMCls != null){
      // retrieving the integer representing the Class in JPF
      JPFCls = ClassLoaderInfo.getCurrentResolvedClassInfo(JVMCls.getName());

      // First check if the class has been already updated
      if (!ConverterBase.updatedJPFCls.contains(JPFClsRef)){
        StaticElementInfo sei = null;
       
        /**
         * If the corresponding ClassInfo does not exist, a new ClassInfo object
         * is created and will be added to the loadedClasses.
         */
        if (!JPFCls.isRegistered()){
          JPFCls.registerClass(env.getThreadInfo());
          sei = JPFCls.getStaticElementInfo();
          JPFClsRef = sei.getObjectRef();
        } else {
          sei = JPFCls.getModifiableStaticElementInfo();
        }

        // This is to avoid JPF to initialized the class
        JPFCls.setInitialized();

        ConverterBase.updatedJPFCls.add(JPFClsRef);

        setStaticFields(JVMCls, sei, env);
      }
View Full Code Here

    if (!JVMCls.isArray()){
      // we treat Strings differently, until we immigrate to JDK7
      if(JVMObj.getClass()==String.class) {
        JPFRef = env.newString(JVMObj.toString());
      } else {
        ClassInfo fci = null;
        try{
          fci = this.getJPFCls(JVMCls, env);
        } catch (ClassInfoException e){
          System.out.println("WARNING: the class " + JVMCls + " is ignored!");
          return MJIEnv.NULL;
View Full Code Here

TOP

Related Classes of gov.nasa.jpf.vm.ClassInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.