Port of: https://github.com/openjdk/panama-foreign/pull/898

Original PR body:

> 
> This patch addresses some issues with `MemorySegment.Scope::equals`. More 
> specifically, when two segments are created from the same array/buffer, their 
> underlying scope should be equal, but currently it is not, which is confusing.
> 
> This patch addesses that by adding a new subclass of `GlobalSession` 
> (`HeapSession`) whose `equals`/`hashcode` methods are defined in terms of the 
> heap reference it wraps. Note that the reference is deduped on construction - 
> that is, we always try to find the "bottom" refrence that we should try to 
> keep alive with the session, and we use that for comparisons (which avoid 
> issues when comparing buffer slices and views).
> 
> As part of the changes, this patch also adds more javadoc on 
> `MemorySegment.Scope` to document how equality works. And, this patch also 
> makes all zero-length memory segments associate with the same "native" scope. 
> This is a scope that is always alive, but is not the global scope (not to 
> confuse with segments created by the global arena). While what the 
> implementation does today is technically correct (a new fresh scope is 
> returned with each new ZLMS), it seems also overkill given that the scope 
> associated with segments originated outside Java code is not very interesting 
> - if users really care about lifetime of such segments they should override 
> the scope with `MemorySegment::reinterpret`. This leads to some changes in 
> the javadoc of other methods where I replaced `fresh scope that is always 
> alive` with just `scope that is always alive`, to avoid suggesting that a new 
> scope should be created each time.

-------------

Commit messages:
 - add M's javadoc rrefinements
 - 8317050: Scope should reflect lifetime of underying resource

Changes: https://git.openjdk.org/jdk/pull/16126/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=16126&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8317819
  Stats: 268 lines in 12 files changed: 210 ins; 13 del; 45 mod
  Patch: https://git.openjdk.org/jdk/pull/16126.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/16126/head:pull/16126

PR: https://git.openjdk.org/jdk/pull/16126

Reply via email to