[OpenJDK 2D-Dev] Cleaner usage in java2 / awt
Roger Riggs
roger.riggs at oracle.com
Fri Jan 15 20:28:12 UTC 2016
Hi Laurent,
Looks good.
Thanks, Roger
On 1/15/16 4:28 AM, Laurent Bourgès wrote:
> Phil & Roger,
>
> Please review the updated webrev according to Roger's comment:
> http://cr.openjdk.java.net/~lbourges/marlin/marlin-Cleaner.1/
> <http://cr.openjdk.java.net/%7Elbourges/marlin/marlin-Cleaner.1/>
>
> Changes:
> + // Register a cleaning function to ensure freeing off-heap memory:
> + CleanerFactory.cleaner().register(parent, () -> this.free());
>
> I created the bug: https://bugs.openjdk.java.net/browse/JDK-8147443
> Could you add the proper tags (no-reg, jigsaw ?)
>
> Phil, can I push it myself as modules.xml is modified or you should do
> it for me ?
>
> Regards,
> Laurent
>
>
> 2016-01-13 17:56 GMT+01:00 Roger Riggs <roger.riggs at oracle.com
> <mailto:roger.riggs at oracle.com>>:
>
> 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
>
>
>
>
> --
> --
> Laurent Bourgès
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/2d-dev/attachments/20160115/1ac23ada/attachment.html>
More information about the 2d-dev
mailing list