[OpenJDK 2D-Dev] Cleaner usage in java2 / awt

Laurent Bourgès bourges.laurent at gmail.com
Wed Jan 13 16:48:01 UTC 2016


Phil & Roger,

Please review this first webrev refactoring Marlin OffHeapArray to use the
new jdk.internal.ref.CleanerFactory (new Cleaner API):
http://cr.openjdk.java.net/~lbourges/marlin/marlin-Cleaner.0/

The new API is really great as it just needs few lines:

+        // Register a cleaning function to ensure freeing off-heap
memory:+        final OffHeapArray local_array = this; // local to
prevent capture of this+
CleanerFactory.cleaner().register(parent, () -> local_array.free());


I added a qualified export in modules.xml:

     <export>+      <name>jdk.internal.ref</name>+
<to>java.desktop</to>+    </export>+    <export>

Who can review such changes to modules.xml (out of my scope) ?

Please check I made it right as I cannot test it with jake !


I tested it using the following settings to use weak references to Marlin
RendererContexts and log all allocations / free buffers in OffHeapArray:
-Dsun.java2d.renderer.log=true
-Dsun.java2d.renderer.logUnsafeMalloc=true
-Dsun.java2d.renderer.useRef=weak

INFO: 1452703097931: OffHeapArray.allocateMemory = 65536 to addr =
140642864899472
INFO: 1452703097931: OffHeapArray.allocateMemory = 98304 to addr =
140642864965024
...
INFO: 1452703103321: OffHeapEdgeArray.free = 98304 at addr = 140642864965024
INFO: 1452703103321: OffHeapEdgeArray.free = 65536 at addr = 140642864899472
...
INFO: 1452703103827: OffHeapArray.allocateMemory = 65536 to addr =
140642864910240
INFO: 1452703103827: OffHeapArray.allocateMemory = 98304 to addr =
140642864975792
...
INFO: 1452703113822: OffHeapEdgeArray.free = 98304 at addr = 140642864975792
INFO: 1452703113822: OffHeapEdgeArray.free = 65536 at addr = 140642864910240
...

PS: I did not create a bug yet.

Cheers,
Laurent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/2d-dev/attachments/20160113/bd09a66c/attachment.html>


More information about the 2d-dev mailing list