Spec-Zone.ru › OpenJDK 27

Interface MemorySegment.Scope

Enclosing interface:
MemorySegment
public static sealed interface MemorySegment.Scope
A scope models the lifetime of all the memory segments associated with it.

That is, a memory segment cannot be accessed if its associated scope is not alive. Scope instances can be compared for equality. That is, two scopes are considered equal if they denote the same lifetime.

The lifetime of a memory segment can be either unbounded or bounded. An unbounded lifetime is modeled with the global scope. The global scope is always alive. As such, a segment associated with the global scope features trivial temporal bounds and is always accessible. Segments associated with the global scope are:

  • Segments obtained from the global arena;
  • Segments obtained from a raw address, using the MemorySegment.ofAddress(long) factory; and
  • Zero-length memory segments.

Conversely, a bounded lifetime is modeled with a segment scope that can be invalidated, either explicitly, or automatically, by the garbage collector. A segment scope that is invalidated automatically is an automatic scope. An automatic scope is always alive as long as it is reachable. Segments associated with an automatic scope are:

  • Segments obtained from an automatic arena;
  • Segments obtained from a Java array, e.g. using the MemorySegment.ofArray(int[]) factory;
  • Segments obtained from a buffer, using the MemorySegment.ofBuffer(Buffer) factory; and
  • Segments obtained from loader lookup.
If two memory segments are obtained from the same buffer or array, the automatic scopes associated with said segments are considered equal, as the two segments have the same lifetime:
byte[] arr = new byte[10];
MemorySegment segment1 = MemorySegment.ofArray(arr);
MemorySegment segment2 = MemorySegment.ofArray(arr);
assert segment1.scope().equals(segment2.scope());
Since:
22

Method Summary

Modifier and Type Method Description
boolean equals(Object that)
Returns true, if the provided object is also a scope, which models the same lifetime as that modeled by this scope.
int hashCode()
Returns the hash code of this scope object.
boolean isAlive()
Returns true, if the regions of memory backing the memory segments associated with this scope are still valid.

Method Details

isAlive

boolean isAlive()
Returns true, if the regions of memory backing the memory segments associated with this scope are still valid.
Returns:
true, if the regions of memory backing the memory segments associated with this scope are still valid

equals

boolean equals(Object that)
Returns true, if the provided object is also a scope, which models the same lifetime as that modeled by this scope.. In that case, it is always the case that this.isAlive() == ((Scope)that).isAlive().
Overrides:
equals in class Object
Parameters:
that - the object to be tested
Returns:
true, if the provided object is also a scope, which models the same lifetime as that modeled by this scope
See Also:
  • Object.hashCode()
  • HashMap

hashCode

int hashCode()
Returns the hash code of this scope object.
Overrides:
hashCode in class Object
Implementation Requirements:
Implementations of this method obey the general contract of Object.hashCode().
Returns:
the hash code of this scope object
See Also:
  • equals(Object)

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2026, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API