diff --git a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAddress.java b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAddress.java
index 73c1c6a6957..111ed671673 100644
--- a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAddress.java
+++ b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAddress.java
@@ -74,7 +74,13 @@ public interface MemoryAddress {
/**
* Compares the specified object with this address for equality. Returns {@code true} if and only if the specified
- * object is also a address, and it is equal to this address.
+ * object is also an address, and it refers to the same memory location as this address.
+ *
+ * @apiNote two addresses might be considered equal despite their associated segments differ. This
+ * can happen, for instance, if the segment associated with one address is a slice
+ * (see {@link MemorySegment#asSlice(long, long)}) of the segment associated with the other address. Moreover,
+ * two addresses might be considered equals despite differences in the temporal bounds associated with their
+ * corresponding segments (this is possible, for example, as a result of calls to {@link MemorySegment#acquire()}).
*
* @param that the object to be compared for equality with this address.
* @return {@code true} if the specified object is equal to this address.
diff --git a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayout.java b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayout.java
index bbb44e07594..45f02ba5228 100644
--- a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayout.java
+++ b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayout.java
@@ -55,14 +55,14 @@ import java.util.OptionalLong;
*
* Non-platform classes should not implement {@linkplain MemoryLayout} directly.
*
- *
Size, alignment and byte order
+ *
*
* All layouts have a size; layout size for value and padding layouts is always explicitly denoted; this means that a layout description
* always has the same size in bits, regardless of the platform in which it is used. For derived layouts, the size is computed
* as follows:
*
* - for a finite sequence layout S whose element layout is E and size is L,
- * the size of S is that of E, multiplied by L
+ * the size of S is that of E, multiplied by L
* - the size of an unbounded sequence layout is unknown
* - for a group layout G with member layouts M1, M2, ... Mn whose sizes are
* S1, S2, ... Sn, respectively, the size of G is either S1 + S2 + ... + Sn or
@@ -180,6 +180,9 @@ public interface MemoryLayout extends Constable {
*
- {@code A=512} is the most strict alignment required by the x86/SV ABI (for AVX-512 data).
*
*
+ * If no explicit alignment constraint was set on this layout (see {@link #withBitAlignment(long)}),
+ * then this method returns the natural alignment constraint (in bits) associated with this layout.
+ *
* @return the layout alignment constraint, in bits.
*/
long bitAlignment();
@@ -195,6 +198,9 @@ public interface MemoryLayout extends Constable {
* {@code A=64} is the most strict alignment required by the x86/SV ABI (for AVX-512 data).
*
*
+ * If no explicit alignment constraint was set on this layout (see {@link #withBitAlignment(long)}),
+ * then this method returns the natural alignment constraint (in bytes) associated with this layout.
+ *
* @return the layout alignment constraint, in bytes.
* @throws UnsupportedOperationException if {@code bitAlignment()} is not a multiple of 8.
*/
@@ -352,7 +358,16 @@ E * (S + I * F)
/**
* Compares the specified object with this layout for equality. Returns {@code true} if and only if the specified
- * object is also a layout, and it is equal to this layout.
+ * object is also a layout, and it is equal to this layout. Two layouts are considered equal if they are of
+ * the same kind, have the same size, name and alignment constraints. Furthermore, depending on the layout kind, additional
+ * conditions must be satisfied:
+ *
+ * - two value layouts are considered equal if they have the same endianness (see {@link ValueLayout#order()})
+ * - two sequence layouts are considered equal if they have the same element count (see {@link SequenceLayout#elementCount()}), and
+ * if their element layouts (see {@link SequenceLayout#elementLayout()}) are also equal
+ * - two group layouts are considered equal if they are of the same kind (see {@link GroupLayout#isStruct()},
+ * {@link GroupLayout#isUnion()}) and if their member layouts (see {@link GroupLayout#memberLayouts()}) are also equal
+ *
*
* @param that the object to be compared for equality with this layout.
* @return {@code true} if the specified object is equal to this layout.
diff --git a/test/jdk/java/foreign/TestTypeAccess.java b/test/jdk/java/foreign/TestTypeAccess.java
new file mode 100644
index 00000000000..b555f0987ac
--- /dev/null
+++ b/test/jdk/java/foreign/TestTypeAccess.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test
+ * @run testng TestTypeAccess
+ */
+
+import jdk.incubator.foreign.MemorySegment;
+import jdk.incubator.foreign.MemoryLayouts;
+import org.testng.annotations.*;
+
+import java.lang.invoke.VarHandle;
+import java.lang.invoke.WrongMethodTypeException;
+
+public class TestTypeAccess {
+
+ static final VarHandle INT_HANDLE = MemoryLayouts.JAVA_INT.varHandle(int.class);
+
+ @Test(expectedExceptions=ClassCastException.class)
+ public void testMemoryAddressCoordinateAsString() {
+ try (MemorySegment s = MemorySegment.allocateNative(8)) {
+ int v = (int)INT_HANDLE.get("string");
+ }
+ }
+
+ @Test(expectedExceptions=WrongMethodTypeException.class)
+ public void testMemoryCoordinatePrimitive() {
+ try (MemorySegment s = MemorySegment.allocateNative(8)) {
+ int v = (int)INT_HANDLE.get(1);
+ }
+ }
+}