1 21 22 package org.apache.derby.impl.services.bytecode; 23 24 import org.apache.derby.iapi.services.compiler.JavaFactory; 25 import org.apache.derby.iapi.services.compiler.ClassBuilder; 26 import org.apache.derby.iapi.services.compiler.MethodBuilder; 27 import org.apache.derby.iapi.services.loader.ClassFactory; 28 import org.apache.derby.iapi.services.classfile.ClassHolder; 29 30 import org.apache.derby.iapi.services.cache.Cacheable; 31 import org.apache.derby.iapi.services.cache.CacheableFactory; 32 33 import org.apache.derby.iapi.services.cache.CacheFactory; 34 import org.apache.derby.iapi.services.cache.CacheManager; 35 36 import org.apache.derby.iapi.services.monitor.Monitor; 37 import org.apache.derby.iapi.services.monitor.ModuleControl; 38 39 import org.apache.derby.iapi.error.StandardException; 40 41 import org.apache.derby.iapi.services.sanity.SanityManager; 42 43 import org.apache.derby.iapi.services.classfile.VMDescriptor; 44 45 import java.util.Properties ; 46 import java.util.Hashtable ; 47 48 137 public class BCJava implements JavaFactory, CacheableFactory, ModuleControl { 138 139 145 146 private CacheManager vmTypeIdCache; 147 148 public BCJava() { 152 } 153 154 162 public void boot(boolean create, Properties properties) throws StandardException { 163 164 CacheFactory cf = 165 (CacheFactory) Monitor.startSystemModule(org.apache.derby.iapi.reference.Module.CacheFactory); 166 167 175 vmTypeIdCache = 176 cf.newCacheManager( 177 this, 178 "VMTypeIdCache", 179 64, 180 256); 181 } 182 183 186 public void stop() { 187 } 188 189 193 215 public ClassBuilder newClassBuilder(ClassFactory cf, String packageName, 216 int modifiers, String className, String superClass) { 217 218 return new BCClass(cf, packageName, modifiers, className, superClass, this); 219 } 220 221 224 public Cacheable newCacheable(CacheManager cm) { 225 return new VMTypeIdCacheable(); 226 } 227 228 234 242 Type type(String javaType) { 243 244 Type retval; 245 246 try { 247 248 VMTypeIdCacheable vtic = (VMTypeIdCacheable) vmTypeIdCache.find(javaType); 249 250 retval = (Type) vtic.descriptor(); 251 252 vmTypeIdCache.release(vtic); 253 254 return retval; 255 256 } catch (StandardException se) { 257 if (SanityManager.DEBUG) { 258 SanityManager.THROWASSERT("Unexpected exception " + se, se); 259 } 260 261 266 retval = new Type(javaType, ClassHolder.convertToInternalDescriptor(javaType)); 267 } 268 269 return retval; 270 } 271 272 String vmType(BCMethodDescriptor md) { 273 String retval; 274 275 try { 276 277 VMTypeIdCacheable vtic = (VMTypeIdCacheable) vmTypeIdCache.find(md); 278 279 retval = vtic.descriptor().toString(); 280 281 vmTypeIdCache.release(vtic); 282 283 } catch (StandardException se) { 284 if (SanityManager.DEBUG) { 285 SanityManager.THROWASSERT("Unexpected exception " + se, se); 286 } 287 288 293 retval = md.buildMethodDescriptor(); 294 } 295 296 return retval; 297 } 298 303 static short vmTypeId(String vmTypeS) { 304 char vmTypeC = vmTypeS.charAt(0); 305 switch(vmTypeC) { 306 case VMDescriptor.C_CLASS : return BCExpr.vm_reference; 307 case VMDescriptor.C_BYTE : return BCExpr.vm_byte; 308 case VMDescriptor.C_CHAR : return BCExpr.vm_char; 309 case VMDescriptor.C_DOUBLE : return BCExpr.vm_double; 310 case VMDescriptor.C_FLOAT : return BCExpr.vm_float; 311 case VMDescriptor.C_INT : return BCExpr.vm_int; 312 case VMDescriptor.C_LONG : return BCExpr.vm_long; 313 case VMDescriptor.C_SHORT : return BCExpr.vm_short; 314 case VMDescriptor.C_BOOLEAN : return BCExpr.vm_int; 315 case VMDescriptor.C_ARRAY : return BCExpr.vm_reference; 316 case VMDescriptor.C_VOID : return BCExpr.vm_void; 317 default: 318 if (SanityManager.DEBUG) 319 SanityManager.THROWASSERT("No type match for "+vmTypeS); 320 } 321 return BCExpr.vm_void; 322 } 323 } 324 | Popular Tags |