Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8323526

Consider adding some text re. memory zeroing in Arena::allocate

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 22, 23
    • core-libs
    • None
    • behavioral
    • minimal
    • No behavioral change occurs here. This CSR is to change the javadoc to reflect what the FFM API implementation was already doing.
    • Java API
    • SE

    Description

      Summary

      Specify that segments allocated from an arena created using a factory in the Arena class are always zeroed out.

      Problem

      Previously, there was no specification of the contents of segments allocated from an arena created using a factory in the Arena class. Such factories are:

      • Arena::ofConfined()
      • Arena::ofShared()
      • Arena::ofAuto()

      Solution

      Specify that segments allocated from an arena created using a factory in the Arena class are always zeroed out. This is also the behavior that is currently implemented (so, no change in the API implementation is required).

      Specification

      
      diff --git a/src/java.base/share/classes/java/lang/foreign/Arena.java b/src/java.base/share/classes/java/lang/foreign/Arena.java
      index 195f8a44db6e..280338fbcbdd 100644
      --- a/src/java.base/share/classes/java/lang/foreign/Arena.java
      +++ b/src/java.base/share/classes/java/lang/foreign/Arena.java
      @@ -219,6 +219,9 @@ public interface Arena extends SegmentAllocator, AutoCloseable {
            * Segments allocated with the returned arena can be
            * {@linkplain MemorySegment#isAccessibleBy(Thread) accessed} by any thread.
            * Calling {@link #close()} on the returned arena will result in an {@link UnsupportedOperationException}.
      +     * <p>
      +     * Memory segments {@linkplain #allocate(long, long) allocated} by the returned arena
      +     * are zero-initialized.
            *
            * @return a new arena that is managed, automatically, by the garbage collector
            */
      @@ -231,6 +234,9 @@ static Arena ofAuto() {
            *          {@linkplain MemorySegment#isAccessibleBy(Thread) accessed} by any thread.
            *          Calling {@link #close()} on the returned arena will result in
            *          an {@link UnsupportedOperationException}.
      +     * <p>
      +     * Memory segments {@linkplain #allocate(long, long) allocated} by the returned arena
      +     * are zero-initialized.
            */
           static Arena global() {
               class Holder {
      @@ -243,6 +249,9 @@ class Holder {
            * {@return a new confined arena} Segments allocated with the confined arena can be
            *          {@linkplain MemorySegment#isAccessibleBy(Thread) accessed} by the thread
            *          that created the arena, the arena's <em>owner thread</em>.
      +     * <p>
      +     * Memory segments {@linkplain #allocate(long, long) allocated} by the returned arena
      +     * are zero-initialized.
            */
           static Arena ofConfined() {
               return MemorySessionImpl.createConfined(Thread.currentThread()).asArena();
      @@ -251,6 +260,9 @@ static Arena ofConfined() {
           /**
            * {@return a new shared arena} Segments allocated with the global arena can be
            *          {@linkplain MemorySegment#isAccessibleBy(Thread) accessed} by any thread.
      +     * <p>
      +     * Memory segments {@linkplain #allocate(long, long) allocated} by the returned arena
      +     * are zero-initialized.
            */
           static Arena ofShared() {
               return MemorySessionImpl.createShared().asArena();```
      

      Attachments

        Issue Links

          Activity

            People

              pminborg Per-Ake Minborg
              mcimadamore Maurizio Cimadamore
              Maurizio Cimadamore
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: