Skip to content

Commit 70dacba

Browse files
committed
8357156: [lworld] ValueClass.newNullRestrictedAtomicArray and newNullableAtomicArray do not respect FlatArrayElementMaxOops
1 parent 8f0e624 commit 70dacba

File tree

2 files changed

+82
-3
lines changed

2 files changed

+82
-3
lines changed

src/hotspot/share/prims/jvm.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,12 +514,12 @@ JVM_ENTRY(jarray, JVM_NewNullRestrictedAtomicArray(JNIEnv *env, jclass elmClass,
514514
validate_array_arguments(klass, len, CHECK_NULL);
515515
InlineKlass* vk = InlineKlass::cast(klass);
516516
oop array = nullptr;
517-
if (UseArrayFlattening && vk->is_naturally_atomic() && vk->has_non_atomic_layout()) {
517+
if (vk->maybe_flat_in_array() && vk->is_naturally_atomic() && vk->has_non_atomic_layout()) {
518518
array = oopFactory::new_flatArray(vk, len, LayoutKind::NON_ATOMIC_FLAT, CHECK_NULL);
519519
for (int i = 0; i < len; i++) {
520520
((flatArrayOop)array)->write_value_to_flat_array(init_h(), i, CHECK_NULL);
521521
}
522-
} else if (UseArrayFlattening && vk->has_atomic_layout()) {
522+
} else if (vk->maybe_flat_in_array() && vk->has_atomic_layout()) {
523523
array = oopFactory::new_flatArray(vk, len, LayoutKind::ATOMIC_FLAT, CHECK_NULL);
524524
for (int i = 0; i < len; i++) {
525525
((flatArrayOop)array)->write_value_to_flat_array(init_h(), i, CHECK_NULL);
@@ -542,7 +542,7 @@ JVM_ENTRY(jarray, JVM_NewNullableAtomicArray(JNIEnv *env, jclass elmClass, jint
542542
validate_array_arguments(klass, len, CHECK_NULL);
543543
InlineKlass* vk = InlineKlass::cast(klass);
544544
oop array = nullptr;
545-
if (UseArrayFlattening && vk->has_nullable_atomic_layout()) {
545+
if (vk->maybe_flat_in_array() && vk->has_nullable_atomic_layout()) {
546546
array = oopFactory::new_flatArray(vk, len, LayoutKind::NULLABLE_ATOMIC_FLAT, CHECK_NULL);
547547
} else {
548548
array = oopFactory::new_objArray(vk, len, CHECK_NULL);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package runtime.valhalla.inlinetypes;
25+
26+
import jdk.internal.value.ValueClass;
27+
import jdk.internal.vm.annotation.LooselyConsistentValue;
28+
29+
import jdk.test.lib.Asserts;
30+
31+
/*
32+
* @test TestFlatArrayElementMaxOops
33+
* @summary Test that the FlatArrayElementMaxOops flag works as expected.
34+
* @requires vm.flagless
35+
* @modules java.base/jdk.internal.vm.annotation
36+
* java.base/jdk.internal.value
37+
* @library /test/lib
38+
* @enablePreview
39+
* @run main/othervm -XX:+UseArrayFlattening -XX:FlatArrayElementMaxOops=0
40+
* -XX:+UseNullableValueFlattening -XX:+UseAtomicValueFlattening -XX:+UseNonAtomicValueFlattening
41+
* runtime.valhalla.inlinetypes.TestFlatArrayElementMaxOops 0
42+
* @run main/othervm -XX:+UseArrayFlattening -XX:FlatArrayElementMaxOops=1
43+
* -XX:+UseNullableValueFlattening -XX:+UseAtomicValueFlattening -XX:+UseNonAtomicValueFlattening
44+
* runtime.valhalla.inlinetypes.TestFlatArrayElementMaxOops 1
45+
* @run main/othervm -XX:+UseArrayFlattening -XX:FlatArrayElementMaxOops=2
46+
* -XX:+UseNullableValueFlattening -XX:+UseAtomicValueFlattening -XX:+UseNonAtomicValueFlattening
47+
* runtime.valhalla.inlinetypes.TestFlatArrayElementMaxOops 2
48+
*/
49+
50+
public class TestFlatArrayElementMaxOops {
51+
52+
@LooselyConsistentValue
53+
static value class ValueWithOneOoop {
54+
Object obj1 = null;
55+
}
56+
57+
@LooselyConsistentValue
58+
static value class ValueWithTwoOoops {
59+
Object obj1 = null;
60+
Object obj2 = null;
61+
}
62+
63+
public static void main(String[] args) {
64+
int FlatArrayElementMaxOops = Integer.valueOf(args[0]);
65+
Object[] array = ValueClass.newNullRestrictedNonAtomicArray(ValueWithOneOoop.class, 1, new ValueWithOneOoop());
66+
Asserts.assertEquals(ValueClass.isFlatArray(array), FlatArrayElementMaxOops >= 1);
67+
array = ValueClass.newNullRestrictedAtomicArray(ValueWithOneOoop.class, 1, new ValueWithOneOoop());
68+
Asserts.assertEquals(ValueClass.isFlatArray(array), FlatArrayElementMaxOops >= 1);
69+
array = ValueClass.newNullableAtomicArray(ValueWithOneOoop.class, 1);
70+
Asserts.assertEquals(ValueClass.isFlatArray(array), FlatArrayElementMaxOops >= 1);
71+
72+
array = ValueClass.newNullRestrictedNonAtomicArray(ValueWithTwoOoops.class, 1, new ValueWithTwoOoops());
73+
Asserts.assertEquals(ValueClass.isFlatArray(array), FlatArrayElementMaxOops >= 2);
74+
array = ValueClass.newNullRestrictedAtomicArray(ValueWithTwoOoops.class, 1, new ValueWithTwoOoops());
75+
Asserts.assertEquals(ValueClass.isFlatArray(array), FlatArrayElementMaxOops >= 2);
76+
array = ValueClass.newNullableAtomicArray(ValueWithTwoOoops.class, 1);
77+
Asserts.assertFalse(ValueClass.isFlatArray(array));
78+
}
79+
}

0 commit comments

Comments
 (0)