Function level try recourse directives.
Nathan Reynolds
numeralnathan at gmail.com
Tue Dec 27 17:42:53 UTC 2022
If the CloseableCollection doesn't escape (likely), then JIT will get rid
of the object allocation. The internal Closeable[] (?) may still stick
around... unless JIT can determine it doesn't escape too. Can JIT escape
analysis get rid of small arrays? If so, the CloseableCollection's
footprint disappears. The only thing remaining is the logic. That's
exactly what an enhanced try-with-resources would do.
So, instead of putting effort into a risky Java language change, I world
suggest we put the effort into JIT to get rid of the allocations. This
will benefit not only CloseableCollection but a whole lot more.
Switching topics... Please do a code analysis of where multiple try with
resources are used. Figure out the typical number of resources that are
closed. Then, set the default size of the internal array (?) to that
size. The default size may be too large and many elements in the array
will be null. By setting the default size smaller, there will be less
unused space allocated and hence GC won't happen as often.
On Tue, Dec 27, 2022, 8:25 AM Brian Goetz <brian.goetz at oracle.com> wrote:
> I think Mark’s solution is quite practical. I think you’re greatly
> overestimating the benefits (“enormous ergonomic advantage”) of your idea
> (a common trap to fall into) and enormously^2 underestimating where the bar
> is for “add features to everyone’s Java.”
>
>
>
> On Dec 27, 2022, at 9:16 AM, Red IO <redio.development at gmail.com> wrote:
>
> This is a nice workaround but allocates additional resources and adds
> clutter in form of (still) a level of nesting and an unnecessary
> collection. Considering that try resource is only a syntactic sugar. It
> shouldn't be difficult to add this simple addition of syntax to provide
> this enormous ergonomic advantage. Also I think it's unlikely that try (...
> ); would find another useful use.
>
> On Tue, Dec 27, 2022, 15:07 Mark Raynsford <org.openjdk at io7m.com> wrote:
>
>> On 2022-12-27T14:49:13 +0100
>> Red IO <redio.development at gmail.com> wrote:
>> >
>> > Sometimes we need to initialize something between the resources and we
>> get
>> > multiple levels of nesting.
>> > And I was wondering if we could not just lose the block and auto close
>> at
>> > the end of a method like this :
>>
>> I work with Vulkan a lot, and that involves a metric ton of closeable
>> resources that also have to be closed in stack order. I have a
>> library-level solution for this:
>>
>> https://www.io7m.com/software/jmulticlose/
>>
>> --
>> Mark Raynsford | https://www.io7m.com
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20221227/3a7f9ee4/attachment.htm>
More information about the amber-dev
mailing list