1 package gov.nasa.jpf.jvm; 20 21 22 25 public class JPF_java_lang_Class { 26 public static boolean isArray (MJIEnv env, int robj) { 27 return getReferringClassInfo(env, robj).isArray(); 28 } 29 30 public static int getComponentType (MJIEnv env, int robj) { 31 if (isArray(env, robj)) { 32 ClassInfo ci = getReferringClassInfo(env, robj).getComponentClassInfo(); 33 34 if (ci != null) { 35 return ci.getClassObjectRef(); 36 } 37 } 38 39 return MJIEnv.NULL; 40 } 41 42 public static boolean isInstance__Ljava_lang_Object_2 (MJIEnv env, int robj, 43 int r1) { 44 ElementInfo sei = env.getClassElementInfo(robj); 45 ClassInfo ci = sei.getClassInfo(); 46 ClassInfo ciOther = env.getClassInfo(r1); 47 48 return (ciOther.instanceOf(ci.getName())); 49 } 50 51 public static boolean isAssignableFrom__Ljava_lang_Class_2 (MJIEnv env, int rcls, 52 int r1) { 53 ElementInfo sei1 = env.getClassElementInfo(rcls); 54 ClassInfo ci1 = sei1.getClassInfo(); 55 56 ElementInfo sei2 = env.getClassElementInfo(r1); 57 ClassInfo ci2 = sei2.getClassInfo(); 58 59 return ci2.instanceOf( ci1.getName()); 60 } 61 62 public static boolean isPrimitiveClass__ (MJIEnv env, int robj) { 63 return false; 64 } 65 66 public static int getPrimitiveClass__Ljava_lang_String_2 (MJIEnv env, 67 int rcls, 68 int stringRef) { 69 String clsName = env.getStringObject(stringRef); 70 71 StaticArea sa = env.getStaticArea(); 78 StaticElementInfo ei = sa.get(clsName); 79 int cref = ei.getClassObjectRef(); 80 env.setBooleanField(cref, "isPrimitive", true); 81 82 return cref; 83 } 84 85 public static boolean desiredAssertionStatus (MJIEnv env, int robj) { 86 ClassInfo ci = getReferringClassInfo(env,robj); 87 return ci.areAssertionsEnabled(); 88 } 89 90 public static int forName__Ljava_lang_String_2 (MJIEnv env, int rcls, 91 int stringRef) { 92 String clsName = env.getStringObject(stringRef); 93 StaticElementInfo ei = env.getStaticArea().get(clsName); 94 int ref = ei.getClassObjectRef(); 95 96 return ref; 97 } 98 99 public static int newInstance (MJIEnv env, int robj) { 100 ClassInfo ci = getReferringClassInfo(env,robj); ThreadInfo ti = env.getThreadInfo(); 102 int ref = env.getDynamicArea().newObject(ci, ti); 104 MethodInfo mi = ci.getMethod("<init>()", true); 105 106 if (mi != null) { 107 117 ti.push(ref, true); 118 ti.executeMethod(mi); 119 } 120 121 return ref; 122 } 123 124 public static int getSuperclass (MJIEnv env, int robj) { 125 ClassInfo ci = getReferringClassInfo(env, robj); 126 ClassInfo sci = ci.getSuperClass(); 127 if (sci != null) { 128 return sci.getClassObjectRef(); 129 } else { 130 return MJIEnv.NULL; 131 } 132 } 133 134 static ClassInfo getReferringClassInfo (MJIEnv env, int robj) { 135 ElementInfo ei = env.getElementInfo(robj); 137 138 int idx = env.getIntField(robj, "cref"); 140 StaticArea sa = env.getStaticArea(); 141 ElementInfo sei = sa.get(idx); 142 143 return sei.getClassInfo(); 144 } 145 } 146 | Popular Tags |