1 2 32 package com.hp.hpl.jena.rdf.arp; 33 34 import java.util.*; 35 36 46 47 public class Token implements RDFParserConstants, Cloneable { 48 51 static public boolean COUNT = false; 52 53 57 static public boolean COUNTTEST = false; 58 59 63 static private int DBGSIZE = 3000; 64 65 69 static private int BIGSIZE = 99000; 70 71 74 static private boolean GIVEUP = true; 75 76 static private int SLEEPTIME = 0; 77 82 static volatile public int highTide; 83 84 static volatile private int dead = 0; 85 86 static volatile private int alive = 0; 87 88 static public void reinitHighTide() { 89 PullingTokenPipe.lastMade = null; 90 Runtime.getRuntime().gc(); 91 Runtime.getRuntime().gc(); 92 try { 93 Thread.sleep(SLEEPTIME); 94 } 95 catch (Exception e){} 96 highTide = 0; 97 dead=0; 98 alive=0; 99 } 100 101 static private Map countMap = new HashMap(); 102 103 static private Map weakMap = new WeakHashMap(); 104 105 private boolean isDead = false; 106 107 protected void finalize() { 108 if (COUNT && !isDead) { 109 isDead = true; 110 dead++; 111 Integer oldCnt = (Integer ) countMap 112 .get(getClass()); 113 if (oldCnt != null) 114 countMap.put(getClass(), new Integer (oldCnt.intValue() - 1)); 115 } 116 } 117 118 final Location location; 119 120 Token(int kind, Location where) { 121 if (COUNT) 122 initCounting(); 123 this.kind = kind; 124 this.location = where; 125 } 126 127 Token() { 128 if (COUNT) 129 initCounting(); 130 location = null; 131 } 132 133 private void initCounting() { 134 alive++; 135 weakMap.put(this, null); 136 Integer oldCnt = (Integer ) countMap.get(getClass()); 137 if (oldCnt == null) 138 oldCnt = new Integer (0); 139 countMap.put(getClass(), new Integer (oldCnt.intValue() + 1)); 140 141 if (alive % DBGSIZE == 0) { 142 boolean big = alive % BIGSIZE == 0; 143 Runtime.getRuntime().gc(); 144 Runtime.getRuntime().gc(); 145 try { 146 Thread.sleep(SLEEPTIME); 147 } 148 catch (Exception e){} 149 if (COUNTTEST) { 150 int inUse = alive - dead; 151 152 if (highTide < inUse) 154 highTide = inUse; 155 } else { 156 System.err.println("[" + (alive-dead)+"]"+dead + "/" + alive); 157 if (big) { 158 System.err.println("Total: " + (alive - dead)); 159 Iterator it = countMap.keySet().iterator(); 160 while (it.hasNext()) { 161 Object key = it.next(); 162 System.err.println(key.toString() + ": " 163 + countMap.get(key).toString()); 164 } 165 166 if (GIVEUP || (alive - dead) < 10000) { 167 Map prev = new HashMap(); 168 it = weakMap.keySet().iterator(); 169 while (it.hasNext()) { 170 Object o = it.next(); 171 if (o != null) { 172 Token t = (Token) o; 173 Token n = t.next; 174 if (n != null) { 175 prev.put(n, t); 176 } 177 } 178 } 179 it = weakMap.keySet().iterator(); 180 while (it.hasNext()) { 181 Object o = it.next(); 182 if (o != null) { 183 Token t = (Token) o; 184 if (!prev.containsKey(t)) { 185 System.err.println("No prev: " + t + " " 186 + t.location); 187 } 188 } 189 } 190 it = PullingTokenPipe.lastMade.pipe.iterator(); 191 while (it.hasNext()) { 192 Object o = it.next(); 193 if (o != null) { 194 Token t = (Token) o; 195 System.err.println("Pipe: " + t + " " 196 + t.location); 197 } 198 } 199 } 200 RDFParser rdfp = ((SingleThreadedParser) PullingTokenPipe.lastMade.arp).rdfParser; 201 Token t = rdfp.startAttr; 202 if (t != null) 203 System.err 204 .println("startAttr: " + t + " " + t.location); 205 t = rdfp.token; 206 if (t != null) 207 System.err.println("token: " + t + " " + t.location); 208 t = rdfp.jj_nt; 209 if (t != null) 210 System.err.println("jj_nt: " + t + " " + t.location); 211 t = rdfp.jj_scanpos; 213 if (t != null) 214 System.err.println("jj_scanpos: " + t + " " 215 + t.location); 216 t = rdfp.jj_lastpos; 217 if (t != null) 218 System.err.println("jj_lastpos: " + t + " " 219 + t.location); 220 if (GIVEUP) 221 System.exit(0); 222 } 223 } 224 } 225 } 226 227 232 public int kind; 233 234 239 public Token next; 240 241 public Object clone() { 242 try { 243 Token rslt = (Token) super.clone(); 244 if (COUNT) 245 rslt.initCounting(); 246 return rslt; 247 } catch (CloneNotSupportedException e) { 248 return "Impossible"; 249 } 250 } 251 252 255 public String toString() { 256 return tokenImage[kind]; 257 } 258 259 273 274 } | Popular Tags |