public void put(Object javaObject, T proxy) { if (javaObject == null || proxy == null) return; int hash = hash(javaObject); segmentFor(hash).put(javaObject, hash, proxy); }
@Override @SuppressWarnings("unchecked") public <T> T toJava(Class<T> type) { final Object object = getObject(); final Class clazz = object.getClass(); if ( type.isPrimitive() ) { if ( type == Void.TYPE ) return null; if ( object instanceof Number && type != Boolean.TYPE || object instanceof Character && type == Character.TYPE || object instanceof Boolean && type == Boolean.TYPE ) { // FIXME in more permissive call paths, like invokedynamic, this can allow // precision-loading downcasts to happen silently return (T) object; } } else if ( type.isAssignableFrom(clazz) ) { if ( Java.OBJECT_PROXY_CACHE || metaClass.getCacheProxy() ) { getRuntime().getJavaSupport().getObjectProxyCache().put(object, this); } return type.cast(object); } else if ( type.isAssignableFrom(getClass()) ) return type.cast(this); // e.g. IRubyObject.class throw getRuntime().newTypeError("failed to coerce " + clazz.getName() + " to " + type.getName()); } }
public void run() { for ( ;; ) { try { sleep(VULTURE_RUN_FREQ_SECONDS * 1000); } catch (InterruptedException e) {} boolean dump = size() > 200; if (dump) { LOG.debug("***Vulture {} waking, stats:", id); LOG.debug(stats()); } for (int i = segments.length; --i >= 0; ) { Segment<T,A> seg = segments[i]; seg.lock(); try { seg.expunge(); } finally { seg.unlock(); } yield(); } if (dump) { LOG.debug("***Vulture {} sleeping, stats:", id); LOG.debug(stats()); } } } };
proxy = cache.allocateProxy(object, allocator); e = new Entry<T>(object, hash, proxy, cache.referenceType, table[index], referenceQueue); table[index] = e;
throw new IllegalArgumentException(); this.id = nextId(); this.referenceType = refType; if (numSegments > MAX_SEGMENTS) numSegments = MAX_SEGMENTS;
/** * Returns a new proxy instance of a type corresponding to rawJavaObject's class, * or the cached proxy if we've already seen this object. Note that primitives * and strings are <em>not</em> coerced to corresponding Ruby types; use * JavaUtil.convertJavaToUsableRubyObject to get coerced types or proxies as * appropriate. * * @param runtime the JRuby runtime * @param rawJavaObject the object to get a wrapper for * @param forceCache whether to force the use of the proxy cache * @return the new (or cached) proxy for the specified Java object * @see JavaUtil#convertJavaToUsableRubyObject */ public static IRubyObject getInstance(Ruby runtime, Object rawJavaObject, boolean forceCache) { if (rawJavaObject != null) { RubyClass proxyClass = (RubyClass) getProxyClass(runtime, rawJavaObject.getClass()); if (OBJECT_PROXY_CACHE || forceCache || proxyClass.getCacheProxy()) { return runtime.getJavaSupport().getObjectProxyCache().getOrCreate(rawJavaObject, proxyClass); } else { return allocateProxy(rawJavaObject, proxyClass); } } return runtime.getNil(); }
@Override @SuppressWarnings("unchecked") public <T> T toJava(Class<T> type) { final Object object = getObject(); final Class clazz = object.getClass(); if ( type.isPrimitive() ) { if ( type == Void.TYPE ) return null; if ( object instanceof Number && type != Boolean.TYPE || object instanceof Character && type == Character.TYPE || object instanceof Boolean && type == Boolean.TYPE ) { // FIXME in more permissive call paths, like invokedynamic, this can allow // precision-loading downcasts to happen silently return (T) object; } } else if ( type.isAssignableFrom(clazz) ) { if ( Java.OBJECT_PROXY_CACHE || metaClass.getCacheProxy() ) { getRuntime().getJavaSupport().getObjectProxyCache().put(object, this); } return type.cast(object); } else if ( type.isAssignableFrom(getClass()) ) return type.cast(this); // e.g. IRubyObject.class throw getRuntime().newTypeError("failed to coerce " + clazz.getName() + " to " + type.getName()); } }
public void run() { for ( ;; ) { try { sleep(VULTURE_RUN_FREQ_SECONDS * 1000); } catch (InterruptedException e) {} boolean dump = size() > 200; if (dump) { LOG.debug("***Vulture {} waking, stats:", id); LOG.debug(stats()); } for (int i = segments.length; --i >= 0; ) { Segment<T,A> seg = segments[i]; seg.lock(); try { seg.expunge(); } finally { seg.unlock(); } yield(); } if (dump) { LOG.debug("***Vulture {} sleeping, stats:", id); LOG.debug(stats()); } } } };
proxy = cache.allocateProxy(object, allocator); e = new Entry<T>(object, hash, proxy, cache.referenceType, table[index], referenceQueue); table[index] = e;
throw new IllegalArgumentException(); this.id = nextId(); this.referenceType = refType; if (numSegments > MAX_SEGMENTS) numSegments = MAX_SEGMENTS;
/** * Returns a new proxy instance of a type corresponding to rawJavaObject's class, * or the cached proxy if we've already seen this object. Note that primitives * and strings are <em>not</em> coerced to corresponding Ruby types; use * JavaUtil.convertJavaToUsableRubyObject to get coerced types or proxies as * appropriate. * * @param runtime the JRuby runtime * @param rawJavaObject the object to get a wrapper for * @param forceCache whether to force the use of the proxy cache * @return the new (or cached) proxy for the specified Java object * @see JavaUtil#convertJavaToUsableRubyObject */ public static IRubyObject getInstance(Ruby runtime, Object rawJavaObject, boolean forceCache) { if (rawJavaObject != null) { RubyClass proxyClass = (RubyClass) getProxyClass(runtime, rawJavaObject.getClass()); if (OBJECT_PROXY_CACHE || forceCache || proxyClass.getCacheProxy()) { return runtime.getJavaSupport().getObjectProxyCache().getOrCreate(rawJavaObject, proxyClass); } return allocateProxy(rawJavaObject, proxyClass); } return runtime.getNil(); }
public void put(Object javaObject, T proxy) { if (javaObject == null || proxy == null) return; int hash = hash(javaObject); segmentFor(hash).put(javaObject, hash, proxy); }
private void setAndCacheProxyObject(ThreadContext context, RubyModule clazz, JavaProxy proxy, Object object) { proxy.setObject(object); if (Java.OBJECT_PROXY_CACHE || clazz.getCacheProxy()) { context.runtime.getJavaSupport().getObjectProxyCache().put(object, proxy); } } }
public void run() { for ( ;; ) { try { sleep(VULTURE_RUN_FREQ_SECONDS * 1000); } catch (InterruptedException e) {} boolean dump = size() > 200; if (dump) { LOG.debug("***Vulture {} waking, stats:", id); LOG.debug(stats()); } for (int i = segments.length; --i >= 0; ) { Segment<T,A> seg = segments[i]; seg.lock(); try { seg.expunge(); } finally { seg.unlock(); } yield(); } if (dump) { LOG.debug("***Vulture {} sleeping, stats:", id); LOG.debug(stats()); } } } };
proxy = cache.allocateProxy(object, allocator); e = new Entry<T>(object, hash, proxy, cache.referenceType, table[index], referenceQueue); table[index] = e;
throw new IllegalArgumentException(); this.id = nextId(); this.referenceType = refType; if (numSegments > MAX_SEGMENTS) numSegments = MAX_SEGMENTS;
/** * Returns a new proxy instance of a type corresponding to rawJavaObject's class, * or the cached proxy if we've already seen this object. Note that primitives * and strings are <em>not</em> coerced to corresponding Ruby types; use * JavaUtil.convertJavaToUsableRubyObject to get coerced types or proxies as * appropriate. * * @param runtime the JRuby runtime * @param rawJavaObject the object to get a wrapper for * @param forceCache whether to force the use of the proxy cache * @return the new (or cached) proxy for the specified Java object * @see JavaUtil#convertJavaToUsableRubyObject */ public static IRubyObject getInstance(Ruby runtime, Object rawJavaObject, boolean forceCache) { if (rawJavaObject != null) { RubyClass proxyClass = (RubyClass) getProxyClass(runtime, rawJavaObject.getClass()); if (OBJECT_PROXY_CACHE || forceCache || proxyClass.getCacheProxy()) { return runtime.getJavaSupport().getObjectProxyCache().getOrCreate(rawJavaObject, proxyClass); } return allocateProxy(rawJavaObject, proxyClass); } return runtime.getNil(); }
public T get(Object javaObject) { if (javaObject == null) return null; int hash = hash(javaObject); return segmentFor(hash).get(javaObject, hash); }
@Override public Object toJava(Class type) { Object obj = getObject(); Class cls = obj.getClass(); if (type.isPrimitive()) { if (type == Void.TYPE) return null; if (obj instanceof Number && type != Boolean.TYPE || obj instanceof Character && type == Character.TYPE || obj instanceof Boolean && type == Boolean.TYPE) { // FIXME in more permissive call paths, like invokedynamic, this can allow // precision-loading downcasts to happen silently return obj; } } else if (type.isAssignableFrom(cls)) { if (Java.OBJECT_PROXY_CACHE || metaClass.getCacheProxy()) { getRuntime().getJavaSupport().getObjectProxyCache().put(obj, this); } return obj; } throw getRuntime().newTypeError("failed to coerce " + cls.getName() + " to " + type.getName()); } }
public void run() { for ( ;; ) { try { sleep(VULTURE_RUN_FREQ_SECONDS * 1000); } catch (InterruptedException e) {} boolean dump = size() > 200; if (dump) { LOG.debug("***Vulture {} waking, stats:", id); LOG.debug(stats()); } for (int i = segments.length; --i >= 0; ) { Segment<T,A> seg = segments[i]; seg.lock(); try { seg.expunge(); } finally { seg.unlock(); } yield(); } if (dump) { LOG.debug("***Vulture {} sleeping, stats:", id); LOG.debug(stats()); } } } };