1 package gov.nasa.jpf.jvm; 20 21 import gov.nasa.jpf.jvm.MJIEnv; 22 23 26 public class JPF_java_lang_StringBuffer { 27 28 static boolean hasSharedField = false; 30 public static void $clinit (MJIEnv env, int clsObjRef) { 31 ClassInfo ci = env.getClassInfo(); 40 if (ci.getInstanceField("shared") != null) { 41 hasSharedField = true; 42 } 43 } 44 45 static int appendString (MJIEnv env, int objref, String s) { 46 int slen = s.length(); 47 int aref = env.getReferenceField(objref, "value"); 48 int alen = env.getArrayLength(aref); 49 int count = env.getIntField(objref, "count"); 50 int i, j; 51 int n = count + slen; 52 53 if (n < alen) { 54 for (i=count, j=0; i<n; i++, j++) { 55 env.setCharArrayElement(aref, i, s.charAt(j)); 56 } 57 } else { 58 int m = 3 * alen / 2; 59 if (m < n) { 60 m = n; 61 } 62 int arefNew = env.newCharArray(m); 63 for (i=0; i<count; i++) { 64 env.setCharArrayElement(arefNew, i, env.getCharArrayElement(aref, i)); 65 } 66 for (j=0; i<n; i++, j++) { 67 env.setCharArrayElement(arefNew, i, s.charAt(j)); 68 } 69 env.setReferenceField(objref, "value", arefNew); 70 } 71 72 if (hasSharedField) { 73 env.setBooleanField(objref, "shared", false); 74 } 75 env.setIntField(objref, "count", n); 76 77 return objref; 78 } 79 80 public static int append__Ljava_lang_StringBuffer_2 (MJIEnv env, int objref, int sbref) { 81 int vref = env.getReferenceField(sbref, "value"); 82 int sbCount = env.getIntField(sbref, "count"); 83 84 char[] b = env.getCharArrayObject(vref); 86 String s = new String (b, 0, sbCount); 87 88 return appendString(env, objref, s); 89 } 90 91 public static int append__Ljava_lang_String_2 (MJIEnv env, int objref, int sref) { 92 String s = env.getStringObject(sref); 93 94 return appendString(env, objref, s); 95 } 96 97 public static int append__I (MJIEnv env, int objref, int i) { 98 String s = Integer.toString(i); 99 100 return appendString(env, objref, s); 101 } 102 103 public static int append__F (MJIEnv env, int objref, float f) { 104 String s = Float.toString(f); 105 106 return appendString(env, objref, s); 107 } 108 109 public static int append__D (MJIEnv env, int objref, double d) { 110 String s = Double.toString(d); 111 112 return appendString(env, objref, s); 113 } 114 115 public static int append__J (MJIEnv env, int objref, long l) { 116 String s = Long.toString(l); 117 118 return appendString(env, objref, s); 119 } 120 121 public static int append__Z (MJIEnv env, int objref, boolean b) { 122 String s = b ? "true" : "false"; 123 124 return appendString(env, objref, s); 125 } 126 127 public static int append__B (MJIEnv env, int objref, byte b) { 128 return append__C(env, objref, (char)b); 129 } 130 131 public static int append__C (MJIEnv env, int objref, char c) { 132 int aref = env.getReferenceField(objref, "value"); 133 int alen = env.getArrayLength(aref); 134 int count = env.getIntField(objref, "count"); 135 int i, j; 136 int n = count +1; 137 138 if (n < alen) { 139 env.setCharArrayElement(aref, count, c); 140 } else { 141 int m = 3 * alen / 2; 142 int arefNew = env.newCharArray(m); 143 for (i=0; i<count; i++) { 144 env.setCharArrayElement(arefNew, i, env.getCharArrayElement(aref, i)); 145 } 146 env.setCharArrayElement(arefNew, count, c); 147 env.setReferenceField(objref, "value", arefNew); 148 } 149 150 if (hasSharedField) { 151 env.setBooleanField(objref, "shared", false); 152 } 153 env.setIntField(objref, "count", n); 154 155 return objref; 156 157 } 158 } 159 160 | Popular Tags |