[OpenJDK 2D-Dev] Cleaner usage in java2 / awt
Roger Riggs
roger.riggs at oracle.com
Wed Jan 13 16:56:35 UTC 2016
Hi Laurent,
Nice use.
You don't need to use the local_array in this case.
Since the reference being cleaned is a the parent object it is ok that
the closure captures 'this'.
The modules.xml qualified export is fine.
Roger
On 1/13/16 11:48 AM, Laurent Bourgès wrote:
> 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/
> <http://cr.openjdk.java.net/%7Elbourges/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/d61f146c/attachment.html>
More information about the 2d-dev
mailing list