--- old/src/java.base/share/classes/java/lang/ref/PhantomReference.java 2019-05-23 15:39:18.441433248 -0400 +++ new/src/java.base/share/classes/java/lang/ref/PhantomReference.java 2019-05-23 15:39:18.045431284 -0400 @@ -30,6 +30,9 @@ * Phantom reference objects, which are enqueued after the collector * determines that their referents may otherwise be reclaimed. Phantom * references are most often used to schedule post-mortem cleanup actions. + *

+ * The referent must not be an instance of an inline class; such a value + * can never have another reference to it and cannot be held in a reference type. * *

Suppose the garbage collector determines at a certain point in time * that an object is @@ -72,6 +75,8 @@ * @param referent the object the new phantom reference will refer to * @param q the queue with which the reference is to be registered, * or {@code null} if registration is not required + * @throws IllegalArgumentException if the referent is an instance of an + * {@link Class#isInlineClass() inlineClass} */ public PhantomReference(T referent, ReferenceQueue q) { super(referent, q); --- old/src/java.base/share/classes/java/lang/ref/Reference.java 2019-05-23 15:39:19.657439278 -0400 +++ new/src/java.base/share/classes/java/lang/ref/Reference.java 2019-05-23 15:39:19.257437294 -0400 @@ -396,6 +396,10 @@ } Reference(T referent, ReferenceQueue queue) { + if (referent != null && referent.getClass().isInlineClass()) { + throw new IllegalArgumentException("cannot reference an inline value of type: " + + referent.getClass().getName()); + } this.referent = referent; this.queue = (queue == null) ? ReferenceQueue.NULL : queue; } --- old/src/java.base/share/classes/java/lang/ref/SoftReference.java 2019-05-23 15:39:20.833445109 -0400 +++ new/src/java.base/share/classes/java/lang/ref/SoftReference.java 2019-05-23 15:39:20.441443165 -0400 @@ -30,6 +30,9 @@ * Soft reference objects, which are cleared at the discretion of the garbage * collector in response to memory demand. Soft references are most often used * to implement memory-sensitive caches. + *

+ * The referent must not be an instance of an inline class; such a value + * can never have another reference to it and cannot be held in a reference type. * *

Suppose that the garbage collector determines at a certain point in time * that an object is softly @@ -80,6 +83,8 @@ * reference is not registered with any queue. * * @param referent object the new soft reference will refer to + * @throws IllegalArgumentException if the referent is an instance of an + * {@link Class#isInlineClass() inlineClass} */ public SoftReference(T referent) { super(referent); @@ -93,7 +98,8 @@ * @param referent object the new soft reference will refer to * @param q the queue with which the reference is to be registered, * or {@code null} if registration is not required - * + * @throws IllegalArgumentException if the referent is an instance of an + * {@link Class#isInlineClass() inlineClass} */ public SoftReference(T referent, ReferenceQueue q) { super(referent, q); --- old/src/java.base/share/classes/java/lang/ref/WeakReference.java 2019-05-23 15:39:21.961450703 -0400 +++ new/src/java.base/share/classes/java/lang/ref/WeakReference.java 2019-05-23 15:39:21.573448779 -0400 @@ -30,6 +30,9 @@ * Weak reference objects, which do not prevent their referents from being * made finalizable, finalized, and then reclaimed. Weak references are most * often used to implement canonicalizing mappings. + *

+ * The referent must not be an instance of an inline class; such a value + * can never have another reference to it and cannot be held in a reference type. * *

Suppose that the garbage collector determines at a certain point in time * that an object is weakly @@ -52,6 +55,8 @@ * reference is not registered with any queue. * * @param referent object the new weak reference will refer to + * @throws IllegalArgumentException if the referent is an instance of an + * {@link Class#isInlineClass() inlineClass} */ public WeakReference(T referent) { super(referent); @@ -64,6 +69,8 @@ * @param referent object the new weak reference will refer to * @param q the queue with which the reference is to be registered, * or {@code null} if registration is not required + * @throws IllegalArgumentException if the referent is an instance of an + * {@link Class#isInlineClass() inlineClass} */ public WeakReference(T referent, ReferenceQueue q) { super(referent, q); --- old/test/jdk/valhalla/valuetypes/Point.java 2019-05-23 15:39:23.001455860 -0400 +++ new/test/jdk/valhalla/valuetypes/Point.java 2019-05-23 15:39:22.609453916 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -35,4 +35,9 @@ p = __WithField(p.y, y); return p; } + + public Point(int x, int y) { + this.x = x; + this.y = y; + } } --- /dev/null 2019-05-01 12:58:11.532074540 -0400 +++ new/test/jdk/valhalla/valuetypes/InlineReferenceTest.java 2019-05-23 15:39:23.641459033 -0400 @@ -0,0 +1,53 @@ +/* + * 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. + */ + +import java.lang.ref.WeakReference; +import java.lang.ref.ReferenceQueue; + +import org.testng.annotations.BeforeTest; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +/* + * @test + * @summary Test inline classes with Reference types + * @compile -XDallowWithFieldOperator Point.java + * @run testng/othervm -XX:+EnableValhalla InlineReferenceTest + */ +@Test +public class InlineReferenceTest { + + @Test(expectedExceptions = IllegalArgumentException.class) + static void test1() { + Point? p = new Point(10,20); + WeakReference r = new WeakReference<>(p); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + static void test2() { + ReferenceQueue q = new ReferenceQueue<>(); + Point? p = new Point(1,2); + WeakReference r = new WeakReference<>(p, q); + } +}