From 1e59fcab01d5cfa4b334c8d59b70973dd4a4a3be Mon Sep 17 00:00:00 2001 From: Ian Graves Date: Wed, 28 May 2025 16:21:23 -0500 Subject: [PATCH 1/5] Making VectorShape.largestShapeFor public and documenting --- .../jdk/incubator/vector/VectorShape.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java index 89e0d38bcb06c..e71d820ca657e 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java @@ -208,13 +208,21 @@ static VectorShape ofSwitchKey(int sk) { } } - // non-public support for computing preferred shapes - - /*package-private*/ - static VectorShape largestShapeFor(Class etype) { + /** + * Finds the largest vector shape supported by the current + * platform for the element type {@code etype}. + * + * @param etype the element type + * @return the largest vector shape supported by the platform + * for {@code etype} + * @throws IllegalArgumentException if no such vector shape exists + */ + public static VectorShape largestShapeFor(Class etype) { return VectorShape.forBitSize(getMaxVectorBitSize(etype)); } + // non-public support for computing preferred shapes + /** * Finds the vector shape preferred by the current platform * for all vector element types. From a00420b224cf59e998027eef6513f519c7ea1e99 Mon Sep 17 00:00:00 2001 From: Ian Graves Date: Thu, 29 May 2025 11:02:07 -0500 Subject: [PATCH 2/5] Tweaking doc language. Co-authored-by: Paul Sandoz --- .../share/classes/jdk/incubator/vector/VectorShape.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java index e71d820ca657e..9bdb5387fc0af 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java @@ -216,6 +216,7 @@ static VectorShape ofSwitchKey(int sk) { * @return the largest vector shape supported by the platform * for {@code etype} * @throws IllegalArgumentException if no such vector shape exists + * for the element type or the type is not a valid {@code ETYPE}. */ public static VectorShape largestShapeFor(Class etype) { return VectorShape.forBitSize(getMaxVectorBitSize(etype)); From 8b3f6fc4ca224be1177f0a628c29fcd2f5cb7788 Mon Sep 17 00:00:00 2001 From: Ian Graves Date: Thu, 29 May 2025 11:11:40 -0500 Subject: [PATCH 3/5] Fixing tabbing --- .../share/classes/jdk/incubator/vector/VectorShape.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java index 9bdb5387fc0af..e14afa70774ad 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java @@ -214,7 +214,7 @@ static VectorShape ofSwitchKey(int sk) { * * @param etype the element type * @return the largest vector shape supported by the platform - * for {@code etype} + * for {@code etype} * @throws IllegalArgumentException if no such vector shape exists * for the element type or the type is not a valid {@code ETYPE}. */ From 097bd9dd30d8c0fd2348e4ce8bd4e06a92869111 Mon Sep 17 00:00:00 2001 From: Ian Graves Date: Thu, 29 May 2025 16:48:38 -0500 Subject: [PATCH 4/5] Adding test coverage --- .../vector/PreferredSpeciesTest.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/test/jdk/jdk/incubator/vector/PreferredSpeciesTest.java b/test/jdk/jdk/incubator/vector/PreferredSpeciesTest.java index f105df5756cf3..eb8b03585382c 100644 --- a/test/jdk/jdk/incubator/vector/PreferredSpeciesTest.java +++ b/test/jdk/jdk/incubator/vector/PreferredSpeciesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, 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 @@ -29,6 +29,7 @@ /** * @test + * @bug 8356549 * @modules jdk.incubator.vector java.base/jdk.internal.vm.vector * @run testng PreferredSpeciesTest */ @@ -126,4 +127,45 @@ void testVectorShape(Class c) { Assert.assertEquals(largestSpecies.length(), maxLaneCount); Assert.assertEquals(largestSpecies.length(), Math.max(species.length(), maxLaneCount)); } + + // Testing VectorShape.largestShapeFor() for 8356549 + @Test(dataProvider = "classesProvider") + void testLargestShapeFor(Class c) { + final int S_64_BITS = 64; + int elemSize = 0; + VectorSpecies maxVectorSpecies; + if (c == byte.class) { + elemSize = Byte.SIZE; + maxVectorSpecies = ByteVector.SPECIES_MAX; + } else if (c == short.class) { + elemSize = Short.SIZE; + maxVectorSpecies = ShortVector.SPECIES_MAX; + } else if (c == int.class) { + elemSize = Integer.SIZE; + maxVectorSpecies = IntVector.SPECIES_MAX; + } else if (c == long.class) { + elemSize = Long.SIZE; + maxVectorSpecies = LongVector.SPECIES_MAX; + } else if (c == float.class) { + elemSize = Float.SIZE; + maxVectorSpecies = FloatVector.SPECIES_MAX; + } else if (c == double.class) { + elemSize = Double.SIZE; + maxVectorSpecies = DoubleVector.SPECIES_MAX; + } else { + throw new IllegalArgumentException("Bad vector element type: " + c.getName()); + } + + VectorShape vs = VectorShape.largestShapeFor(c); + + int maxLaneCount = VectorSupport.getMaxLaneCount(c); + int max = Math.max(maxLaneCount * elemSize, S_64_BITS); + + //Assert we're using the same element when comparing shapes + Assert.assertEquals(c, maxVectorSpecies.elementType()); + + Assert.assertEquals(vs.vectorBitSize(), max); + Assert.assertEquals(vs.vectorBitSize(), maxVectorSpecies.vectorBitSize()); + + } } From 90066a23b6839ef49ad2e0e87e77074e73d86cee Mon Sep 17 00:00:00 2001 From: Ian Graves Date: Thu, 29 May 2025 16:58:38 -0500 Subject: [PATCH 5/5] Updating copyrights --- .../share/classes/jdk/incubator/vector/VectorShape.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java index e14afa70774ad..f6e36450ce088 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2025, 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