Top Description Inners Fields Constructors Methods
org.jruby.runtime

public Class ObjectSpace

extends Object
Class Inheritance
Imports
java.lang.ref.Reference, .ReferenceQueue, .WeakReference, java.util.AbstractList, .ArrayList, .HashMap, .Iterator, .Map, java.util.concurrent.atomic.AtomicLong, .AtomicReferenceArray, org.jruby.RubyBasicObject, .RubyModule, org.jruby.java.proxies.JavaProxy, org.jruby.javasupport.JavaPackage, org.jruby.runtime.builtin.IRubyObject, org.jruby.util.WeakIdentityHashMap

FIXME: This version is faster than the previous, but both suffer from a crucial flaw: It is impossible to create an ObjectSpace with an iterator that doesn't either: a. hold on to objects that might otherwise be collected or b. have no way to guarantee that a call to hasNext() will be correct or that a subsequent call to next() will produce an object. For our purposes, for now, this may be acceptable.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static class
private static class
private class

Field Summary

Modifier and TypeField and Description
private final ThreadLocal<Reference<ObjectSpace.ObjectGroup>>
private final ReferenceQueue<T>
private final ReferenceQueue<Object>
private Reference<ObjectSpace.GroupSweeper>
private final Map<Long, ObjectSpace.IdReference>
private final Map<IRubyObject, Long>
private static final AtomicLong
private final ReferenceQueue<ObjectSpace.ObjectGroup>
private ObjectSpace.WeakReferenceListNode<T>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
add(IRubyObject object)

public void
addFinalizer(IRubyObject object, IRubyObject proc)
Deprecated

public IRubyObject
private synchronized void
private synchronized ObjectSpace.ObjectGroup
public static long
private void
private void
cleanup(ReferenceQueue<?> referenceQueue)

public long
private long
private ObjectSpace.ObjectGroup
public IRubyObject
id2ref(long id)

public long
idOf(IRubyObject rubyObject)
Deprecated

public synchronized Iterator<E>
iterator(RubyModule rubyClass)

private synchronized void
public void
registerObjectId(long id, IRubyObject object)

public void
private synchronized void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentObjectGroupback to summary
private final ThreadLocal<Reference<ObjectSpace.ObjectGroup>> currentObjectGroup
deadIdentityReferencesback to summary
private final ReferenceQueue<T> deadIdentityReferences
deadReferencesback to summary
private final ReferenceQueue<Object> deadReferences
groupSweeperReferenceback to summary
private Reference<ObjectSpace.GroupSweeper> groupSweeperReference
identitiesback to summary
private final Map<Long, ObjectSpace.IdReference> identities
identitiesByObjectback to summary
private final Map<IRubyObject, Long> identitiesByObject
maxIdback to summary
private static final AtomicLong maxId
objectGroupReferenceQueueback to summary
private final ReferenceQueue<ObjectSpace.ObjectGroup> objectGroupReferenceQueue
topback to summary
private ObjectSpace.WeakReferenceListNode<T> top

Constructor Detail

ObjectSpaceback to summary
public ObjectSpace()

Method Detail

addback to summary
public void add(IRubyObject object)
addFinalizerback to summary
public void addFinalizer(IRubyObject object, IRubyObject proc)

Deprecated

Annotations
@Deprecated
addFinalizerback to summary
public IRubyObject addFinalizer(ThreadContext context, IRubyObject object, IRubyObject proc)
addIndividualWeakReferenceback to summary
private synchronized void addIndividualWeakReference(IRubyObject object)
addObjectGroupback to summary
private synchronized ObjectSpace.ObjectGroup addObjectGroup()
calculateObjectIdback to summary
public static long calculateObjectId(Object object)
cleanIdentitiesback to summary
private void cleanIdentities()
cleanupback to summary
private void cleanup(ReferenceQueue<?> referenceQueue)
createAndRegisterObjectIdback to summary
public long createAndRegisterObjectId(IRubyObject rubyObject)
createIdback to summary
private long createId(IRubyObject object)
getObjectGroupback to summary
private ObjectSpace.ObjectGroup getObjectGroup()
id2refback to summary
public IRubyObject id2ref(long id)
idOfback to summary
public long idOf(IRubyObject rubyObject)

Deprecated

Annotations
@Deprecated
iteratorback to summary
public synchronized Iterator<E> iterator(RubyModule rubyClass)
registerGroupSweeperback to summary
private synchronized void registerGroupSweeper()
registerObjectIdback to summary
public void registerObjectId(long id, IRubyObject object)
removeFinalizersback to summary
public void removeFinalizers(long id)
splitObjectGroupsback to summary
private synchronized void splitObjectGroups()
org.jruby.runtime back to summary

private final Class ObjectSpace.GroupSweeper

extends Object
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

GroupSweeperback to summary
private GroupSweeper()

Method Detail

finalizeback to summary
protected void finalize() throws Throwable

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Annotations
@Override
Exceptions
Throwable:
the Exception raised by this method
org.jruby.runtime back to summary

private Class ObjectSpace.IdReference

extends WeakReference<IRubyObject>
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final long

Constructor Summary

AccessConstructor and Description
pack-priv
IdReference(IRubyObject object, long id, ReferenceQueue<T> queue)

Field Detail

idback to summary
pack-priv final long id

Constructor Detail

IdReferenceback to summary
pack-priv IdReference(IRubyObject object, long id, ReferenceQueue<T> queue)
org.jruby.runtime back to summary

private final Class ObjectSpace.ObjectGroup

extends AbstractList<IRubyObject>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final int
private int
private final AtomicReferenceArray<IRubyObject>
Inherited from java.util.AbstractList:
modCount

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
add(IRubyObject
element to be appended to this list
obj
)

Overrides java.util.AbstractList.add.

Implements java.util.List.add, java.util.Collection.add.

Appends the specified element to the end of this list (optional operation).

public IRubyObject
get(int
index of the element to return
index
)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Returns the element at the specified position in this list.

private boolean
public IRubyObject
set(int
index of the element to replace
index
,
IRubyObject
element to be stored at the specified position
element
)

Overrides java.util.AbstractList.set.

Implements java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).

public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Returns the number of elements in this list.

Inherited from java.util.AbstractList:
addaddAllclearequalshashCodeindexOfiteratorlastIndexOflistIteratorlistIteratorremoveremoveRangesubList

Field Detail

MAX_OBJECTS_PER_GROUPback to summary
private static final int MAX_OBJECTS_PER_GROUP
nextIndexback to summary
private int nextIndex
objectsback to summary
private final AtomicReferenceArray<IRubyObject> objects

Constructor Detail

ObjectGroupback to summary
private ObjectGroup()

Method Detail

addback to summary
public boolean add(IRubyObject obj)

Overrides java.util.AbstractList.add.

Implements java.util.List.add, java.util.Collection.add.

Doc from java.util.AbstractList.add.

Appends the specified element to the end of this list (optional operation).

Lists that support this operation may place limitations on what elements may be added to this list. In particular, some lists will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. List classes should clearly specify in their documentation any restrictions on what elements may be added.

Parameters
obj:IRubyObject

element to be appended to this list

Returns:boolean

true (as specified by Collection#add)

getback to summary
public IRubyObject get(int index)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Doc from java.util.AbstractList.get.

Returns the element at the specified position in this list.

Parameters
index:int

Doc from java.util.List.get.

index of the element to return

Returns:IRubyObject

Doc from java.util.List.get.

the element at the specified position in this list

Annotations
@Override
isFullback to summary
private boolean isFull()
setback to summary
public IRubyObject set(int index, IRubyObject element)

Overrides java.util.AbstractList.set.

Implements java.util.List.set.

Doc from java.util.AbstractList.set.

Replaces the element at the specified position in this list with the specified element (optional operation).

Parameters
index:int

Doc from java.util.List.set.

index of the element to replace

element:IRubyObject

Doc from java.util.List.set.

element to be stored at the specified position

Returns:IRubyObject

Doc from java.util.List.set.

the element previously at the specified position

Annotations
@Override
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this list

org.jruby.runtime back to summary

private Class ObjectSpace.WeakReferenceListNode<T>

extends WeakReference<T>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private ObjectSpace.WeakReferenceListNode<T>
private ObjectSpace.WeakReferenceListNode<T>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void

Field Detail

nextNodeback to summary
private ObjectSpace.WeakReferenceListNode<T> nextNode
prevNodeback to summary
private ObjectSpace.WeakReferenceListNode<T> prevNode

Constructor Detail

WeakReferenceListNodeback to summary
public WeakReferenceListNode(T referent, ReferenceQueue<T> queue, ObjectSpace.WeakReferenceListNode<?> next)

Method Detail

removeback to summary
private void remove()