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..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 @@ -208,13 +208,22 @@ 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 + * for the element type or the type is not a valid {@code ETYPE}. + */ + 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. 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()); + + } }