Skip to content

Commit d6b5544

Browse files
committed
8278607: Misc issues in foreign API javadoc
Reviewed-by: sundar
1 parent 918e339 commit d6b5544

File tree

7 files changed

+55
-40
lines changed

7 files changed

+55
-40
lines changed

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/CLinker.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
* {@linkplain #downcallHandle(FunctionDescriptor) Linking a foreign function} is a process which requires a function descriptor,
5656
* a set of memory layouts which, together, specify the signature of the foreign function to be linked, and returns,
5757
* when complete, a downcall method handle, that is, a method handle that can be used to invoke the target native function.
58-
* The Java {@link java.lang.invoke.MethodType method type} associated with the returned method handle is
58+
* The Java {@linkplain java.lang.invoke.MethodType method type} associated with the returned method handle is
5959
* {@linkplain #downcallType(FunctionDescriptor) derived} from the argument and return layouts in the function descriptor.
6060
* More specifically, given each layout {@code L} in the function descriptor, a corresponding carrier {@code C} is inferred,
6161
* as described below:
@@ -69,7 +69,8 @@
6969
* <li>or, if {@code L} is a {@link GroupLayout}, then {@code C} is set to {@code MemorySegment.class}</li>
7070
* </ul>
7171
* <p>
72-
* The downcall method handle type, derived as above, might be decorated by additional leading parameters:
72+
* The downcall method handle type, derived as above, might be decorated by additional leading parameters,
73+
* in the given order if both are present:
7374
* <ul>
7475
* <li>If the downcall method handle is created {@linkplain #downcallHandle(FunctionDescriptor) without specifying a native symbol},
7576
* the downcall method handle type features a leading parameter of type {@link NativeSymbol}, from which the
@@ -91,7 +92,7 @@
9192
* handle and a function descriptor; in this case, the set of memory layouts in the function descriptor
9293
* specify the signature of the function pointer associated with the upcall stub.
9394
* <p>
94-
* The type of the provided method handle has to match the Java {@link java.lang.invoke.MethodType method type}
95+
* The type of the provided method handle has to match the Java {@linkplain java.lang.invoke.MethodType method type}
9596
* associated with the upcall stub, which is derived from the argument and return layouts in the function descriptor.
9697
* More specifically, given each layout {@code L} in the function descriptor, a corresponding carrier {@code C} is inferred, as described below:
9798
* <ul>
@@ -109,7 +110,7 @@
109110
*
110111
* <h2>System lookup</h2>
111112
*
112-
* This class implements the {@link SymbolLookup} interface; as such clients can {@linkplain #lookup(String) lookup} symbols
113+
* This class implements the {@link SymbolLookup} interface; as such clients can {@linkplain #lookup(String) look up} symbols
113114
* in the standard libraries associated with this linker. The set of symbols available for lookup is unspecified,
114115
* as it depends on the platform and on the operating system.
115116
*
@@ -163,7 +164,7 @@ static CLinker systemCLinker() {
163164
}
164165

165166
/**
166-
* Lookup a symbol in the standard libraries associated with this linker.
167+
* Look up a symbol in the standard libraries associated with this linker.
167168
* The set of symbols available for lookup is unspecified, as it depends on the platform and on the operating system.
168169
* @return a symbol in the standard libraries associated with this linker.
169170
*/

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAddress.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@
2929
import jdk.internal.foreign.MemoryAddressImpl;
3030
import jdk.internal.reflect.CallerSensitive;
3131

32+
import java.lang.invoke.MethodHandle;
3233
import java.nio.ByteOrder;
3334

3435
/**
35-
* A memory address models a reference into a memory location. Memory addresses are typically obtained in three ways:
36+
* A memory address models a reference into a memory location. Memory addresses are typically obtained in one of the following ways:
3637
* <ul>
3738
* <li>By calling {@link Addressable#address()} on an instance of type {@link Addressable} (e.g. a memory segment);</li>
3839
* <li>By invoking a {@linkplain CLinker#downcallHandle(FunctionDescriptor) downcall method handle} which returns a pointer;</li>
3940
* <li>By reading an address from memory, e.g. via {@link MemorySegment#get(ValueLayout.OfAddress, long)}.</li>
41+
* <li>By the invocation of an {@linkplain CLinker#upcallStub(MethodHandle, FunctionDescriptor, ResourceScope) upcall stub} which accepts a pointer.
4042
* </ul>
4143
* A memory address is backed by a raw machine pointer, expressed as a {@linkplain #toRawLongValue() long value}.
4244
*

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegment.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
* A memory segment models a contiguous region of memory. A memory segment is associated with both spatial
5757
* and temporal bounds (e.g. a {@link ResourceScope}). Spatial bounds ensure that memory access operations on a memory segment cannot affect a memory location
5858
* which falls <em>outside</em> the boundaries of the memory segment being accessed. Temporal bounds ensure that memory access
59-
* operations on a segment cannot occur after the resource scope associated with a memory segment has been closed (see {@link ResourceScope#close()}).
59+
* operations on a segment cannot occur <em>after</em> the resource scope associated with a memory segment has been closed (see {@link ResourceScope#close()}).
6060
* <p>
6161
* All implementations of this interface must be <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>;
6262
* programmers should treat instances that are {@linkplain Object#equals(Object) equal} as interchangeable and should not
@@ -157,7 +157,7 @@
157157
* scope, it can only be accessed by the thread which owns the scope.
158158
* <p>
159159
* Heap and buffer segments are always associated with a <em>global</em>, shared scope. This scope cannot be closed,
160-
* and can be considered as <em>always alive</em>.
160+
* and segments associated with it can be considered as <em>always alive</em>.
161161
*
162162
* <h2>Memory segment views</h2>
163163
*
@@ -217,11 +217,11 @@ public sealed interface MemorySegment extends Addressable permits AbstractMemory
217217
* The returned spliterator splits this segment according to the specified element layout; that is,
218218
* if the supplied layout has size N, then calling {@link Spliterator#trySplit()} will result in a spliterator serving
219219
* approximately {@code S/N/2} elements (depending on whether N is even or not), where {@code S} is the size of
220-
* this segment. As such, splitting is possible as long as {@code S/N >= 2}. The spliterator returns segments that feature the same
221-
* scope as this given segment.
220+
* this segment. As such, splitting is possible as long as {@code S/N >= 2}. The spliterator returns segments that
221+
* are associated with the same scope as this segment.
222222
* <p>
223-
* The returned spliterator effectively allows to slice this segment into disjoint sub-segments, which can then
224-
* be processed in parallel by multiple threads.
223+
* The returned spliterator effectively allows to slice this segment into disjoint {@linkplain #asSlice(long, long) slices},
224+
* which can then be processed in parallel by multiple threads.
225225
*
226226
* @param elementLayout the layout to be used for splitting.
227227
* @return the element spliterator for this segment
@@ -679,7 +679,7 @@ static MemorySegment ofByteBuffer(ByteBuffer bb) {
679679

680680
/**
681681
* Creates a new array memory segment that models the memory associated with a given heap-allocated byte array.
682-
* The returned segment's resource scope is set to the {@linkplain ResourceScope#globalScope() global} resource scope.
682+
* The returned segment is associated with the {@linkplain ResourceScope#globalScope() global} resource scope.
683683
*
684684
* @param arr the primitive array backing the array memory segment.
685685
* @return a new array memory segment.
@@ -690,7 +690,7 @@ static MemorySegment ofArray(byte[] arr) {
690690

691691
/**
692692
* Creates a new array memory segment that models the memory associated with a given heap-allocated char array.
693-
* The returned segment's resource scope is set to the {@linkplain ResourceScope#globalScope() global} resource scope.
693+
* The returned segment is associated with the {@linkplain ResourceScope#globalScope() global} resource scope.
694694
*
695695
* @param arr the primitive array backing the array memory segment.
696696
* @return a new array memory segment.
@@ -701,7 +701,7 @@ static MemorySegment ofArray(char[] arr) {
701701

702702
/**
703703
* Creates a new array memory segment that models the memory associated with a given heap-allocated short array.
704-
* The returned segment's resource scope is set to the {@linkplain ResourceScope#globalScope() global} resource scope.
704+
* The returned segment is associated with the {@linkplain ResourceScope#globalScope() global} resource scope.
705705
*
706706
* @param arr the primitive array backing the array memory segment.
707707
* @return a new array memory segment.
@@ -712,7 +712,7 @@ static MemorySegment ofArray(short[] arr) {
712712

713713
/**
714714
* Creates a new array memory segment that models the memory associated with a given heap-allocated int array.
715-
* The returned segment's resource scope is set to the {@linkplain ResourceScope#globalScope() global} resource scope.
715+
* The returned segment is associated with the {@linkplain ResourceScope#globalScope() global} resource scope.
716716
*
717717
* @param arr the primitive array backing the array memory segment.
718718
* @return a new array memory segment.
@@ -723,7 +723,7 @@ static MemorySegment ofArray(int[] arr) {
723723

724724
/**
725725
* Creates a new array memory segment that models the memory associated with a given heap-allocated float array.
726-
* The returned segment's resource scope is set to the {@linkplain ResourceScope#globalScope() global} resource scope.
726+
* The returned segment is associated with the {@linkplain ResourceScope#globalScope() global} resource scope.
727727
*
728728
* @param arr the primitive array backing the array memory segment.
729729
* @return a new array memory segment.
@@ -734,7 +734,7 @@ static MemorySegment ofArray(float[] arr) {
734734

735735
/**
736736
* Creates a new array memory segment that models the memory associated with a given heap-allocated long array.
737-
* The returned segment's resource scope is set to the {@linkplain ResourceScope#globalScope() global} resource scope.
737+
* The returned segment is associated with the {@linkplain ResourceScope#globalScope() global} resource scope.
738738
*
739739
* @param arr the primitive array backing the array memory segment.
740740
* @return a new array memory segment.
@@ -745,7 +745,7 @@ static MemorySegment ofArray(long[] arr) {
745745

746746
/**
747747
* Creates a new array memory segment that models the memory associated with a given heap-allocated double array.
748-
* The returned segment's resource scope is set to the {@linkplain ResourceScope#globalScope() global} resource scope.
748+
* The returned segment is associated with the {@linkplain ResourceScope#globalScope() global} resource scope.
749749
*
750750
* @param arr the primitive array backing the array memory segment.
751751
* @return a new array memory segment.

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/SegmentAllocator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ static SegmentAllocator nativeAllocator(ResourceScope scope) {
456456
* Returns a native allocator which allocates segments in independent {@linkplain ResourceScope#newImplicitScope() implicit scopes}.
457457
* Equivalent to (but likely more efficient than) the following code:
458458
* {@snippet lang=java :
459-
* ResourceScope scope = ...
460459
* SegmentAllocator implicitAllocator = (size, align) -> MemorySegment.allocateNative(size, align, ResourceScope.newImplicitScope());
461460
* }
462461
*

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/VaList.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
sealed public interface VaList extends Addressable permits WinVaList, SysVVaList, LinuxAArch64VaList, MacOsAArch64VaList, SharedUtils.EmptyVaList {
6060

6161
/**
62-
* Reads the next value as an {@code int} and advances this variable argument list's position.
62+
* Reads the next value as an {@code int} and advances this variable argument list's position. The behavior of this
63+
* method is equivalent to the C {@code va_arg} function.
6364
*
6465
* @param layout the layout of the value to be read.
6566
* @return the {@code int} value read from this variable argument list.
@@ -69,7 +70,8 @@ sealed public interface VaList extends Addressable permits WinVaList, SysVVaList
6970
int nextVarg(ValueLayout.OfInt layout);
7071

7172
/**
72-
* Reads the next value as a {@code long} and advances this variable argument list's position.
73+
* Reads the next value as a {@code long} and advances this variable argument list's position. The behavior of this
74+
* method is equivalent to the C {@code va_arg} function.
7375
*
7476
* @param layout the layout of the value to be read.
7577
* @return the {@code long} value read from this variable argument list.
@@ -79,7 +81,8 @@ sealed public interface VaList extends Addressable permits WinVaList, SysVVaList
7981
long nextVarg(ValueLayout.OfLong layout);
8082

8183
/**
82-
* Reads the next value as a {@code double} and advances this variable argument list's position.
84+
* Reads the next value as a {@code double} and advances this variable argument list's position. The behavior of this
85+
* method is equivalent to the C {@code va_arg} function.
8386
*
8487
* @param layout the layout of the value
8588
* @return the {@code double} value read from this variable argument list.
@@ -89,7 +92,8 @@ sealed public interface VaList extends Addressable permits WinVaList, SysVVaList
8992
double nextVarg(ValueLayout.OfDouble layout);
9093

9194
/**
92-
* Reads the next value as a {@code MemoryAddress} and advances this variable argument list's position.
95+
* Reads the next value as a {@code MemoryAddress} and advances this variable argument list's position. The behavior of this
96+
* method is equivalent to the C {@code va_arg} function.
9397
*
9498
* @param layout the layout of the value to be read.
9599
* @return the {@code MemoryAddress} value read from this variable argument list.
@@ -99,7 +103,13 @@ sealed public interface VaList extends Addressable permits WinVaList, SysVVaList
99103
MemoryAddress nextVarg(ValueLayout.OfAddress layout);
100104

101105
/**
102-
* Reads the next value as a {@code MemorySegment}, and advances this variable argument list's position.
106+
* Reads the next value as a {@code MemorySegment}, and advances this variable argument list's position. The behavior of this
107+
* method is equivalent to the C {@code va_arg} function. The provided group layout must correspond to a C struct or union
108+
* type.
109+
* <p>
110+
* How the value is read in the returned segment is ABI-dependent: calling this method on a group layout
111+
* with member layouts {@code L_1, L_2, ... L_n} is not guaranteed to be semantically equivalent to perform distinct
112+
* calls to {@code nextVarg} for each of the layouts in {@code L_1, L_2, ... L_n}.
103113
* <p>
104114
* The memory segment returned by this method will be allocated using the given {@link SegmentAllocator}.
105115
*
@@ -129,9 +139,12 @@ sealed public interface VaList extends Addressable permits WinVaList, SysVVaList
129139

130140
/**
131141
* Copies this variable argument list at its current position into a new variable argument list associated
132-
* with the same scope as this variable argument list. Copying is useful to
133-
* traverse the variable argument list elements, starting from the current position, without affecting the state
134-
* of the original variable argument list, essentially allowing the elements to be traversed multiple times.
142+
* with the same scope as this variable argument list. The behavior of this method is equivalent to the C
143+
* {@code va_copy} function.
144+
* <p>
145+
* Copying is useful to traverse the variable argument list elements, starting from the current position,
146+
* without affecting the state of the original variable argument list, essentially allowing the elements to be
147+
* traversed multiple times.
135148
*
136149
* @return a copy of this variable argument list.
137150
* @throws IllegalStateException if the scope associated with this variable argument list has been closed, or if access occurs from
@@ -187,8 +200,8 @@ static VaList ofAddress(MemoryAddress address, ResourceScope scope) {
187200
* of the underlying variable argument list.
188201
* @param scope scope the scope to be associated with the new variable arity list.
189202
* @return a new variable argument list.
190-
* @throws IllegalStateException if the scope associated with {@code allocator} has been already closed,
191-
* or if access occurs from a thread other than the thread owning that scope.
203+
* @throws IllegalStateException if {@code scope} has been already closed, or if access occurs from a thread other
204+
* than the thread owning {@code scope}.
192205
*/
193206
static VaList make(Consumer<Builder> actions, ResourceScope scope) {
194207
Objects.requireNonNull(actions);

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/ValueLayout.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
/**
4343
* A value layout. A value layout is used to model the memory layout associated with values of basic data types, such as <em>integral</em> types
44-
* (either signed or unsigned) and <em>floating-point</em> types. Each value layout has a size, a {@linkplain ByteOrder byte order})
44+
* (either signed or unsigned) and <em>floating-point</em> types. Each value layout has a size, an alignment, a {@linkplain ByteOrder byte order})
4545
* and a <em>carrier</em>, that is, the Java type that should be used when {@linkplain MemorySegment#get(OfInt, long) accessing}
4646
* a memory region using the value layout.
4747
* <p>

0 commit comments

Comments
 (0)