01.12.2012 Views

Architecture of Computing Systems (Lecture Notes in Computer ...

Architecture of Computing Systems (Lecture Notes in Computer ...

Architecture of Computing Systems (Lecture Notes in Computer ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

An Embedded GC Module with Support for Multiple Mutators 33<br />

its capability to retrieve the referent, which is usually achieved by clear<strong>in</strong>g it to<br />

null. Reference queues may establish an additional notification scheme allow<strong>in</strong>g<br />

cleared references to be enqueued for process<strong>in</strong>g by an application thread.<br />

The Java 2 Standard Edition knows <strong>of</strong> several different strengths <strong>of</strong> weak references,<br />

which gives rise to the class hierarchy shown <strong>in</strong> Fig. 5. While the CLDC 1.1<br />

only requires the WeakReference, our architecture additonally supports their<br />

s<strong>of</strong>t variant and reference queu<strong>in</strong>g.<br />

Weak references are implemented as proxy objects conta<strong>in</strong><strong>in</strong>g a special reference<br />

member <strong>in</strong>itialized from a strong reference provided to the constructor.<br />

The garbage collector must be enabled to recognize these special references <strong>in</strong><br />

order to treat them appropriately <strong>in</strong> the heap scan and to clear them when it is<br />

about to collect their referents.<br />

Instead <strong>of</strong> provid<strong>in</strong>g the GC with <strong>in</strong>formation about the hierarchy <strong>of</strong> the reference<br />

classes, we designated two bits <strong>of</strong> the reference word to tag the supported<br />

weak reference types as shown <strong>in</strong> Fig. 4. While these bits are generally cleared,<br />

they are set by the constructors <strong>of</strong> reference objects. This approach even enables<br />

a more flexible use <strong>of</strong> weak references outside the hierarchy <strong>of</strong> the reference classes.<br />

Dur<strong>in</strong>g the heap scan, weak references are not followed. The treatment <strong>of</strong> s<strong>of</strong>t<br />

references is decided once at the beg<strong>in</strong>n<strong>in</strong>g <strong>of</strong> a GC cycle accord<strong>in</strong>g to the current<br />

memory utilization so that they are followed as long as free storage is available. The<br />

objects conta<strong>in</strong><strong>in</strong>g unfollowed references are, however, enlisted dur<strong>in</strong>g the scan. After<br />

its completion, this list <strong>of</strong> proxies is scanned for references to unreached referents.<br />

Any one found will be cleared, and the effected proxy will be communicated<br />

to the mutators for its possible enqueu<strong>in</strong>g <strong>in</strong>to a reference queue. For this purpose,<br />

the SHAP runtime system forks a designated service thread that ma<strong>in</strong>ta<strong>in</strong>s the<br />

communication with the memory manager via its Wishbone connection.<br />

Special care is to be taken upon the retrieval <strong>of</strong> a strong reference from a weak<br />

proxy. Assume that an object only rema<strong>in</strong>s reachable through a weak reference. As<br />

long as the garbage collector does not discover this condition, the reference is not<br />

cleared but totally valid. The <strong>in</strong>vocation <strong>of</strong> the get() method on the<br />

WeakReference proxy object will return with a normal strong reference to the<br />

referent effectively resurrect<strong>in</strong>g the object from the br<strong>in</strong>k <strong>of</strong> death. A race condition<br />

may, however, arise when such a resurrection <strong>in</strong>terferes with an ongo<strong>in</strong>g heap<br />

scan. It must be ensured that the reference to be returned by get() is either entered<br />

<strong>in</strong>to the mark table prior to the completion <strong>of</strong> the heap scan or <strong>in</strong>validated by<br />

return<strong>in</strong>g null. Not know<strong>in</strong>g whether an ongo<strong>in</strong>g heap scan will render the referent<br />

strongly-reachable or not, a consistent resurrection with a mark table entry is<br />

attempted first. Only if the scan has f<strong>in</strong>ished <strong>in</strong> the meanwhile, the actually determ<strong>in</strong>ed<br />

reachability is evaluated. If necessary, null will be returned <strong>in</strong> conformance<br />

to the <strong>in</strong>evitable clear<strong>in</strong>g <strong>of</strong> the orig<strong>in</strong>al reference field.<br />

4 Evaluation <strong>in</strong> SHAP<br />

The described design was implemented for SHAP and <strong>in</strong>tegrated <strong>in</strong>to the runtime<br />

system through adapted microcode implementations access<strong>in</strong>g the port to the

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!