Question on recommended practice with FMA

leerho leerho at gmail.com
Wed Apr 14 18:45:10 UTC 2021


I am using Java 16 GA for now to migrate our entire library as I don't want
to track a moving target while I'm doing this migration.  And, I am hoping
that the migration from 16 to 17 won't be too severe and certainly easier
than the migration from 8 to 16.

Nonetheless, with the code snippet I gave above.  I would think that a
simple slice view should never trigger a resource-leak warning.  The slice
view object would go out of scope with the closing brace and would be
collected by the GC.  With the code as it is now, where every new Segment
is AutoCloseable, and to avoid the warnings, I have to explicitly refactor
the code to allow me to close segments that shouldn't need closing, which
is a PITA :)

I do wonder why you even allow the close() on a slice view to close the
underlying, parent segment.  I would think that it is the responsibility of
the owner of the originating segment to close.  So, in my mind the ability
to close should never be delegated by default and only delegated with an
explicit handoff.

In my Memory package I solved this problem by assigning the close
responsibility of the Segment to a Handle. These Handles were only used
where AutoCloseable was really necessary, e.g., segments of off-heap, or
memory-mapped files.  When a segment wraps a heap-array or a ByteBuffer, AC
is not needed.  As a result, when passing a segment to another method the
close() does not go with it.

I thought at some point you were going to use handles.  No?

(Forgive me, I haven't followed all of the changes you have made since 16
GA :) )

Lee.

On Wed, Apr 14, 2021 at 3:52 AM Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:

>
> On 14/04/2021 11:49, Maurizio Cimadamore wrote:
> > Agree - this seems odd. I'm not super sure as to why that check was
> > added to memory segment calls and what it does precisely (Eclipse uses
> > a different compiler for generating this warnings than javac, which is
> > the compiler that comes with OpenJDK).
> >
> > Maurizio
>
> Ok - it seems like the warning blindly assumes that every new
> AutoCloseable that is obtained must be closed.
>
> This probably means that you are using the Java 16 API, not the new one?
> But, in any case, even in the new API there might be issue when using
> implicit resource scopes (as these are managed by the GC and not closed
> by clients).
>
> Maurizio
>
>


More information about the panama-dev mailing list