Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/jdk/TEST.groups
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ jdk_util = \
:jdk_stream

valhalla_adopted = \
java/util/Collections/AddAll.java
java/util/Collections/AddAll.java \
java/util/Arrays

# All util components not part of some other util category
jdk_util_other = \
Expand Down
30 changes: 26 additions & 4 deletions test/jdk/java/util/Arrays/ArrayObjectMethods.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2026, 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
Expand Down Expand Up @@ -27,12 +27,19 @@
* @summary Basic test for content-based array object methods
* @author Josh Bloch, Martin Buchholz
* @key randomness
* @library /test/lib
*/

import java.util.*;
import java.io.*;

import jdk.test.lib.valueclass.AsValueClass;

public class ArrayObjectMethods {

@AsValueClass
record V(int x, int y) implements Serializable {}

int[] sizes = {0, 10, 100, 200, 1000};

void test(String[] args) throws Throwable {
Expand Down Expand Up @@ -290,11 +297,11 @@ public static float nextFloat() {
}

public static Object nextObject() {
switch(rnd.nextInt(10)) {
switch(rnd.nextInt(12)) {
case 0: return null;
case 1: return "foo";
case 2: case 3: case 4:
return Double.valueOf(nextDouble());
case 2: case 3: case 4: return Double.valueOf(nextDouble());
case 5: case 6: return nextV();
default: return Integer.valueOf(nextInt());
}
}
Expand Down Expand Up @@ -362,6 +369,17 @@ public static Object[] flatObjectArray(int length) {
return result;
}

public static ArrayObjectMethods.V nextV() {
return new ArrayObjectMethods.V(nextInt(), nextInt());
}

public static ArrayObjectMethods.V[] vArray(int length) {
ArrayObjectMethods.V[] result = new ArrayObjectMethods.V[length];
for (int i = 0; i < length; i++)
result[i] = nextV();
return result;
}

// Calling this for length >> 100 is likely to run out of memory! It
// should be perhaps be tuned to allow for longer arrays
public static Object[] nestedObjectArray(int length) {
Expand All @@ -386,6 +404,10 @@ public static Object[] nestedObjectArray(int length) {
break;
case 8: result[i] = longArray(length/2);
break;
case 9: result[i] = vArray(length/2);
break;
case 10: result[i] = nextV();
break;
default: result[i] = Rnd.nextObject();
}
}
Expand Down
83 changes: 57 additions & 26 deletions test/jdk/java/util/Arrays/ArraysEqCmpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
* @test
* @bug 8033148 8141409
* @summary tests for array equals and compare
* @library /test/lib
* @run junit ArraysEqCmpTest
*/


import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
Expand All @@ -43,6 +43,8 @@
import java.util.function.LongFunction;
import java.util.stream.IntStream;

import jdk.test.lib.valueclass.AsValueClass;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
Expand All @@ -57,6 +59,15 @@ public class ArraysEqCmpTest {

static final Map<Class, Integer> typeToWidth;

@AsValueClass
record Point(int x, int y) implements Comparable<Point> {
@Override
public int compareTo(Point o) {
int r = Integer.compare(this.x, o.x);
return (r != 0) ? r : Integer.compare(this.y, o.y);
}
}

static {
typeToWidth = new HashMap<>();
typeToWidth.put(boolean.class, Byte.SIZE);
Expand Down Expand Up @@ -588,6 +599,24 @@ else if (v instanceof Integer) {
((double[]) a)[i] = pv;
}
}

static class ValuePoints extends ArrayType<Point[]> {
public ValuePoints() {
super(Point[].class);
}

@Override
void set(Object a, int i, Object v) {
if (v == null) {
((Point[]) a)[i] = null;
} else if (v instanceof Point) {
((Point[]) a)[i] = (Point) v;
} else if (v instanceof Integer) {
int val = (Integer) v;
((Point[]) a)[i] = new Point(val, val);
} else throw new IllegalStateException();
}
}
}

static Object[][] arrayTypes;
Expand All @@ -609,6 +638,7 @@ public static Object[][] arrayTypesProvider() {
new Object[]{new ArrayType.Longs(true)},
new Object[]{new ArrayType.Floats()},
new Object[]{new ArrayType.Doubles()},
new Object[]{new ArrayType.ValuePoints()}
};
}
return arrayTypes;
Expand Down Expand Up @@ -639,6 +669,7 @@ public static Object[][] objectArrayTypesProvider() {
objectArrayTypes = new Object[][]{
new Object[]{new ArrayType.BoxedIntegers()},
new Object[]{new ArrayType.BoxedIntegersWithReverseComparator()},
new Object[]{new ArrayType.ValuePoints()},
};
}
return objectArrayTypes;
Expand Down Expand Up @@ -767,37 +798,37 @@ public void testSameRefElementsInObjectArray(ArrayType<?> arrayType) {
// One ref
Integer one = 1;
testArrayType(arrayType,
(at, s) -> {
Integer[] a = (Integer[]) at.construct(s);
for (int x = 0; x < s; x++) {
a[x] = one;
}
return a;
},
cloner);
(at, s) -> {
Object a = at.construct(s);
for (int x = 0; x < s; x++) {
at.set(a, x, one);
}
return a;
},
cloner);

// All ref
testArrayType(arrayType,
(at, s) -> {
Integer[] a = (Integer[]) at.construct(s);
for (int x = 0; x < s; x++) {
a[x] = Integer.valueOf(s);
}
return a;
},
cloner);
(at, s) -> {
Object a = at.construct(s);
for (int x = 0; x < s; x++) {
at.set(a, x, s);
}
return a;
},
cloner);

// Some same ref
testArrayType(arrayType,
(at, s) -> {
Integer[] a = (Integer[]) at.construct(s);
for (int x = 0; x < s; x++) {
int v = x % 8;
a[x] = v == 1 ? one : new Integer(v);
}
return a;
},
cloner);
(at, s) -> {
Object a = at.construct(s);
for (int x = 0; x < s; x++) {
int v = x % 8;
at.set(a, x, v == 1 ? one : v);
}
return a;
},
cloner);
}

@ParameterizedTest
Expand Down
16 changes: 15 additions & 1 deletion test/jdk/java/util/Arrays/AsList.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@
* @test
* @bug 8155600
* @summary Tests for Arrays.asList()
* @library /test/lib
* @run junit AsList
*/

import java.time.LocalDate;
import java.util.Arrays;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.stream.IntStream;

import jdk.test.lib.valueclass.AsValueClass;

import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
Expand All @@ -41,6 +46,10 @@

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class AsList {

@AsValueClass
record V(int x) {}

/*
* Iterator contract test
*/
Expand Down Expand Up @@ -74,7 +83,12 @@ public static Object[][] arrays() {
{ new Object[] { null, null, null } },
{ new Object[] { 1, 2, 3, null, 4 } },
{ new Object[] { "a", "a", "a", "a" } },
{ IntStream.range(0, 100).boxed().toArray() }
{ IntStream.range(0, 100).boxed().toArray() },
{ new Object[] { new V(1), new V(2), null, new V(3) } },
{ new Object[] { Integer.valueOf(1), Integer.valueOf(2), null, Integer.valueOf(3) } },
{ new Object[] { LocalDate.of(2000, 1, 1), LocalDate.of(2000, 12, 31), LocalDate.now() } },
{ new Object[] { Optional.of(1), Optional.empty(), Optional.of("a") } },
{ new Object[] { Boolean.TRUE, Boolean.FALSE, null } }
};
}
}
41 changes: 40 additions & 1 deletion test/jdk/java/util/Arrays/Big.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2026, 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
Expand All @@ -26,6 +26,7 @@
* @bug 5045582
* @summary arrays larger than 1<<30
* @author Martin Buchholz
* @library /test/lib
*/

// A proper regression test for 5045582 requires too much memory.
Expand All @@ -34,8 +35,18 @@

import java.util.*;

import jdk.test.lib.valueclass.AsValueClass;

public class Big {

@AsValueClass
record Point(int x, int y) implements Comparable<Point> {
public int compareTo(Point o) {
int c = Integer.compare(x, o.x);
return c != 0 ? c : Integer.compare(y, o.y);
}
}

private static void realMain(String[] args) throws Throwable {
final int shift = intArg(args, 0, 10); // "30" is real test
final int tasks = intArg(args, 1, ~0); // all tasks
Expand Down Expand Up @@ -94,6 +105,34 @@ private static void realMain(String[] args) throws Throwable {
equal(a[n-3], 43);
equal(a[n-4], 0);
}

// To test value record arrays larger than 1<<30, you need ~25GB. Run like:
// java --enable-preview -Xms25g -Xmx25g Big 30 4
if ((tasks & 0x4) != 0) {
System.out.println("Point[]");
System.gc();
Point[] a = new Point[n];
Point ZERO = new Point(0, 0);
Arrays.fill(a, ZERO);
a[0] = new Point(-44, -44);
a[1] = new Point(-43, -43);
a[n-2] = new Point(+43, +43);
a[n-1] = new Point(+44, +44);
for (int i : new int[] { 0, 1, n-2, n-1 })
try { equal(i, Arrays.binarySearch(a, a[i])); }
catch (Throwable t) { unexpected(t); }
for (int i : new int[] { n-2, n-1 })
try { equal(i, Arrays.binarySearch(a, n-5, n, a[i])); }
catch (Throwable t) { unexpected(t); }

a[n-19] = new Point(45, 45);
try { Arrays.sort(a, n-29, n); }
catch (Throwable t) { unexpected(t); }
equal(a[n-1], new Point(45, 45));
equal(a[n-2], new Point(44, 44));
equal(a[n-3], new Point(43, 43));
equal(a[n-4], new Point(0, 0));
}
}

//--------------------- Infrastructure ---------------------------
Expand Down
19 changes: 18 additions & 1 deletion test/jdk/java/util/Arrays/CopyMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@
* @summary Test for array cloning and slicing methods.
* @author John Rose
* @key randomness
* @library /test/lib
*/

import java.time.LocalDate;
import java.util.*;
import java.lang.reflect.*;

import jdk.test.lib.valueclass.AsValueClass;

public class CopyMethods {
static int muzzle; // if !=0, suppresses ("muzzles") messages

Expand All @@ -42,6 +46,9 @@ public class CopyMethods {
static int testCasesRun = 0;
static long consing = 0;

@AsValueClass
record Point(int x, int y) {}

// very simple tests, mainly to test the framework itself
static void simpleTests() {
int[] a = (int[]) makeArray(3, int.class);
Expand Down Expand Up @@ -353,6 +360,9 @@ static void fullTests() {
static float coerceToFloat(int x) { return x; }
static double coerceToDouble(int x) { return x; }
static boolean coerceToBoolean(int x) { return (x&1) != 0; }
static Point coerceToPoint(int x) { return (x == 0) ? null : new Point(x, x); }
static LocalDate coerceToLocalDate(int x) { return (x == 0) ? null : LocalDate.ofEpochDay(x); }
static Optional coerceToOptional(int x) { return (x == 0) ? null : Optional.of(x); }

static Integer[] copyOfIntegerArray(Object[] a, int len) {
// This guy exercises the API based on a type-token.
Expand All @@ -370,7 +380,8 @@ static Integer[] copyOfIntegerArrayRange(Object[] a, int m, int n) {
{ Object.class, String.class, Integer.class,
byte.class, short.class, int.class, long.class,
char.class, float.class, double.class,
boolean.class
boolean.class, LocalDate.class, Optional.class,
Point.class,
});
static final HashMap<Class<?>,Method> coercers;
static final HashMap<Class<?>,Method> cloners;
Expand Down Expand Up @@ -417,6 +428,12 @@ static Integer[] copyOfIntegerArrayRange(Object[] a, int m, int n) {
cloners.put(Integer.class, cia);
assert(ciar != null);
cloneRangers.put(Integer.class, ciar);
cloners.put(Point.class, cloners.get(Object.class));
cloneRangers.put(Point.class, cloneRangers.get(Object.class));
cloners.put(LocalDate.class, cloners.get(Object.class));
cloneRangers.put(LocalDate.class, cloneRangers.get(Object.class));
cloners.put(Optional.class, cloners.get(Object.class));
cloneRangers.put(Optional.class, cloneRangers.get(Object.class));
nullValues = new HashMap<Class<?>,Object>();
for (Class<?> c : allTypes) {
nullValues.put(c, invoke(coercers.get(c), 0));
Expand Down
Loading