Skip to content

Commit 2d75f95

Browse files
committed
Rename isOwnedBy -> isCloseableBy
Fix minor typos Fix StrLenTest/RingAllocator
1 parent df29e6a commit 2d75f95

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/java.base/share/classes/java/lang/foreign/Arena.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@
6565
* and <em>shared</em> arenas.
6666
* <p>
6767
* Confined arenas, support strong thread-confinement guarantees. Upon creation, they are assigned an
68-
* {@linkplain #isOwnedBy(Thread) owner thread}, typically the thread which initiated the creation operation.
68+
* {@linkplain #isCloseableBy(Thread) owner thread}, typically the thread which initiated the creation operation.
6969
* The segments created by a confined arena can only be {@linkplain MemorySession#isAccessibleBy(Thread) accessed}
7070
* by the thread that created the arena. Moreover, any attempt to close the confined arena from a thread other than the owner thread will
7171
* fail with {@link WrongThreadException}.
7272
* <p>
7373
* Shared memory sessions, on the other hand, have no owner thread. The segments created by a shared arena
7474
* can be {@linkplain MemorySession#isAccessibleBy(Thread) accessed} by multiple threads. This might be useful when
7575
* multiple threads need to access the same memory segment concurrently (e.g. in the case of parallel processing).
76-
* Moreover, a shared arena can be closed by any thread.
76+
* Moreover, a shared arena {@linkplain #isCloseableBy(Thread) can be closed} by any thread.
7777
*
7878
* @since 20
7979
*/
@@ -128,7 +128,7 @@ default MemorySegment allocate(long byteSize, long byteAlignment) {
128128
* {@return {@code true} if the provided thread can close this arena}
129129
* @param thread the thread to be tested.
130130
*/
131-
boolean isOwnedBy(Thread thread);
131+
boolean isCloseableBy(Thread thread);
132132

133133
/**
134134
* Creates a new confined arena.
@@ -159,9 +159,10 @@ public void close() {
159159
}
160160

161161
@Override
162-
public boolean isOwnedBy(Thread thread) {
162+
public boolean isCloseableBy(Thread thread) {
163163
Objects.requireNonNull(thread);
164-
return sessionImpl.ownerThread() == thread;
164+
return sessionImpl.ownerThread() == null || // shared
165+
sessionImpl.ownerThread() == thread;
165166
}
166167
};
167168
}

src/java.base/share/classes/java/lang/foreign/MemorySession.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@
4343
* explicitly, (i.e. using an {@linkplain Arena arena}) or implicitly, by the garbage collector. When a bounded memory
4444
* session ends, it is no longer {@linkplain #isAlive() alive}, and subsequent operations
4545
* on the segments associated with that bounded session (e.g. {@link MemorySegment#get(ValueLayout.OfInt, long)})
46-
* will fail with {@link IllegalStateException}. Moreover, to prevent temporal safety, access to memory segments associated with
46+
* will fail with {@link IllegalStateException}. Moreover, to guarantee temporal safety, access to memory segments associated with
4747
* bounded sessions might be <a href="Arena.html#thread-confinement">restricted to specific threads</a>.
4848
*
4949
* <h2 id="implicit">Implicitly-managed bounded memory sessions</h2>
5050
*
5151
* Managing bounded memory session explicitly, using arenas, while powerful, must be used with caution. An arena must always
5252
* be closed when no longer in use (this is done using {@link Arena#close()}). A failure to do so
53-
* might result in memory leaks. To mitigate this problem, clients can obtain an {@linkplain MemorySession#implicit() obtain}
53+
* might result in memory leaks. To mitigate this problem, clients can {@linkplain MemorySession#implicit() obtain}
5454
* bounded memory sessions that are managed implicitly, by the garbage collector. These sessions end at some unspecified
5555
* time <em>after</em> they become <a href="../../../java/lang/ref/package.html#reachability">unreachable</a>, as shown below:
5656
*
@@ -60,7 +60,7 @@
6060
* segment = null; // the session might end after this instruction
6161
*}
6262
*
63-
* Bounded sessions that are managed implicitly can be useful to manage long-lived segments, where timely deallocation
63+
* Bounded sessions that are managed implicitly can be useful to allocate long-lived segments, where timely deallocation
6464
* is not critical, or in unstructured cases where the boundaries of the lifetime associated with a memory session
6565
* cannot be easily determined. As shown in the example above, a memory session that is managed implicitly cannot end
6666
* if a program references to one or more segments associated with that session. This means that memory segments associated

test/micro/org/openjdk/bench/java/lang/foreign/StrLenTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ public MemorySegment allocate(long byteSize, long byteAlignment) {
159159
reset();
160160
}
161161
MemorySegment res = current.allocate(byteSize, byteAlignment);
162-
rem = segment.byteSize() - segment.segmentOffset(res);
162+
long lastOffset = segment.segmentOffset(res) + res.byteSize();
163+
rem = segment.byteSize() - lastOffset;
163164
return res;
164165
}
165166

0 commit comments

Comments
 (0)