Skip to content

Commit b6ae53c

Browse files
committed
Improve some java declarations of vector stuff
1 parent 6b156ab commit b6ae53c

53 files changed

Lines changed: 530 additions & 596 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

make/jdk/src/classes/build/tools/taglet/SealedGraph.java

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -138,20 +138,25 @@ private final class Renderer {
138138

139139
// Generates a graph in DOT format
140140
String graph(TypeElement rootClass, Set<String> exports) {
141+
if (!isInPublicApi(rootClass, exports)) {
142+
// Alternatively we can return "" for the graph since there is no single root to render
143+
throw new IllegalArgumentException("Root not in public API: " + rootClass.getQualifiedName());
144+
}
141145
final State state = new State(rootClass);
142146
traverse(state, rootClass, exports);
143147
return state.render();
144148
}
145149

146150
static void traverse(State state, TypeElement node, Set<String> exports) {
151+
if (!isInPublicApi(node, exports)) {
152+
throw new IllegalArgumentException("Bad request, not in public API: " + node.getQualifiedName());
153+
}
147154
state.addNode(node);
148155
if (!(node.getModifiers().contains(Modifier.SEALED) || node.getModifiers().contains(Modifier.FINAL))) {
149156
state.addNonSealedEdge(node);
150157
} else {
151158
for (TypeElement subNode : permittedSubclasses(node, exports)) {
152-
if (isInPublicApi(node, exports) && isInPublicApi(subNode, exports)) {
153-
state.addEdge(node, subNode);
154-
}
159+
state.addEdge(node, subNode);
155160
traverse(state, subNode, exports);
156161
}
157162
}
@@ -292,14 +297,30 @@ private String simpleName(String name) {
292297
}
293298

294299
private static List<TypeElement> permittedSubclasses(TypeElement node, Set<String> exports) {
295-
return node.getPermittedSubclasses().stream()
296-
.filter(DeclaredType.class::isInstance)
297-
.map(DeclaredType.class::cast)
298-
.map(DeclaredType::asElement)
299-
.filter(TypeElement.class::isInstance)
300-
.map(TypeElement.class::cast)
301-
.filter(te -> isInPublicApi(te, exports))
302-
.toList();
300+
List<TypeElement> dfsStack = new ArrayList<TypeElement>().reversed(); // Faster operations to head
301+
List<TypeElement> result = new ArrayList<>();
302+
// The starting node may be in the public API - still expand it
303+
prependSubclasses(node, dfsStack);
304+
305+
while (!dfsStack.isEmpty()) {
306+
TypeElement now = dfsStack.removeFirst();
307+
if (isInPublicApi(now, exports)) {
308+
result.addLast(now);
309+
} else {
310+
// Skip the non-exported classes in the hierarchy
311+
prependSubclasses(now, dfsStack);
312+
}
313+
}
314+
315+
return List.copyOf(result);
316+
}
317+
318+
private static void prependSubclasses(TypeElement node, List<TypeElement> dfs) {
319+
for (var e : node.getPermittedSubclasses().reversed()) {
320+
if (e instanceof DeclaredType dt && dt.asElement() instanceof TypeElement te) {
321+
dfs.addFirst(te);
322+
}
323+
}
303324
}
304325

305326
private static boolean isInPublicApi(TypeElement typeElement, Set<String> exports) {

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractMask.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@
2424
*/
2525
package jdk.incubator.vector;
2626

27-
import java.util.Objects;
28-
29-
import jdk.internal.vm.annotation.ForceInline;
30-
3127
import jdk.internal.misc.Unsafe;
32-
28+
import jdk.internal.vm.annotation.ForceInline;
3329
import jdk.internal.vm.vector.VectorSupport;
3430

3531
import static jdk.incubator.vector.VectorOperators.*;
3632

37-
abstract class AbstractMask<E> extends VectorMask<E> {
33+
abstract sealed class AbstractMask<E> extends VectorMask<E>
34+
permits ByteVector64.ByteMask64, ByteVector128.ByteMask128, ByteVector256.ByteMask256, ByteVector512.ByteMask512, ByteVectorMax.ByteMaskMax,
35+
DoubleVector64.DoubleMask64, DoubleVector128.DoubleMask128, DoubleVector256.DoubleMask256, DoubleVector512.DoubleMask512, DoubleVectorMax.DoubleMaskMax,
36+
FloatVector64.FloatMask64, FloatVector128.FloatMask128, FloatVector256.FloatMask256, FloatVector512.FloatMask512, FloatVectorMax.FloatMaskMax,
37+
IntVector64.IntMask64, IntVector128.IntMask128, IntVector256.IntMask256, IntVector512.IntMask512, IntVectorMax.IntMaskMax,
38+
LongVector64.LongMask64, LongVector128.LongMask128, LongVector256.LongMask256, LongVector512.LongMask512, LongVectorMax.LongMaskMax,
39+
ShortVector64.ShortMask64, ShortVector128.ShortMask128, ShortVector256.ShortMask256, ShortVector512.ShortMask512, ShortVectorMax.ShortMaskMax {
3840
AbstractMask(boolean[] bits) {
3941
super(bits);
4042
}

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractShuffle.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,17 @@
2525
package jdk.incubator.vector;
2626

2727
import java.util.function.IntUnaryOperator;
28+
2829
import jdk.internal.vm.annotation.ForceInline;
2930
import jdk.internal.vm.vector.VectorSupport;
3031

31-
abstract class AbstractShuffle<E> extends VectorShuffle<E> {
32+
abstract sealed class AbstractShuffle<E> extends VectorShuffle<E>
33+
permits ByteVector64.ByteShuffle64, ByteVector128.ByteShuffle128, ByteVector256.ByteShuffle256, ByteVector512.ByteShuffle512, ByteVectorMax.ByteShuffleMax,
34+
DoubleVector64.DoubleShuffle64, DoubleVector128.DoubleShuffle128, DoubleVector256.DoubleShuffle256, DoubleVector512.DoubleShuffle512, DoubleVectorMax.DoubleShuffleMax,
35+
FloatVector64.FloatShuffle64, FloatVector128.FloatShuffle128, FloatVector256.FloatShuffle256, FloatVector512.FloatShuffle512, FloatVectorMax.FloatShuffleMax,
36+
IntVector64.IntShuffle64, IntVector128.IntShuffle128, IntVector256.IntShuffle256, IntVector512.IntShuffle512, IntVectorMax.IntShuffleMax,
37+
LongVector64.LongShuffle64, LongVector128.LongShuffle128, LongVector256.LongShuffle256, LongVector512.LongShuffle512, LongVectorMax.LongShuffleMax,
38+
ShortVector64.ShortShuffle64, ShortVector128.ShortShuffle128, ShortVector256.ShortShuffle256, ShortVector512.ShortShuffle512, ShortVectorMax.ShortShuffleMax {
3239
static final IntUnaryOperator IDENTITY = i -> i;
3340

3441
// Internal representation allows for a maximum index of E.MAX_VALUE - 1

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractSpecies.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,31 @@
2424
*/
2525
package jdk.incubator.vector;
2626

27-
import java.lang.foreign.MemorySegment;
28-
import jdk.internal.vm.annotation.ForceInline;
29-
import jdk.internal.vm.annotation.Stable;
3027
import java.lang.reflect.Array;
31-
import java.nio.ByteOrder;
3228
import java.util.Arrays;
3329
import java.util.function.Function;
3430
import java.util.function.IntUnaryOperator;
3531

36-
abstract class AbstractSpecies<E> extends jdk.internal.vm.vector.VectorSupport.VectorSpecies<E>
37-
implements VectorSpecies<E> {
38-
@Stable
32+
import jdk.internal.vm.annotation.ForceInline;
33+
import jdk.internal.vm.annotation.Stable;
34+
import jdk.internal.vm.annotation.TrustFinalFields;
35+
36+
@TrustFinalFields
37+
abstract sealed class AbstractSpecies<E> extends jdk.internal.vm.vector.VectorSupport.VectorSpecies<E>
38+
implements VectorSpecies<E>
39+
permits ByteVector.ByteSpecies, DoubleVector.DoubleSpecies, FloatVector.FloatSpecies,
40+
IntVector.IntSpecies, LongVector.LongSpecies, ShortVector.ShortSpecies {
3941
final VectorShape vectorShape;
40-
@Stable
4142
final LaneType laneType;
42-
@Stable
4343
final int laneCount;
44-
@Stable
4544
final int laneCountLog2P1;
46-
@Stable
4745
final Class<? extends AbstractVector<E>> vectorType;
48-
@Stable
4946
final Class<? extends AbstractMask<E>> maskType;
50-
@Stable
5147
final Class<? extends AbstractShuffle<E>> shuffleType;
52-
@Stable
5348
final Function<Object, ? extends AbstractVector<E>> vectorFactory;
5449

55-
@Stable
5650
final VectorShape indexShape;
57-
@Stable
5851
final int maxScale, minScale;
59-
@Stable
6052
final int vectorBitSize, vectorByteSize;
6153

6254
AbstractSpecies(VectorShape vectorShape,

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractVector.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,17 @@
2525
package jdk.incubator.vector;
2626

2727
import java.lang.foreign.MemorySegment;
28+
import java.nio.ByteOrder;
29+
import java.util.function.IntUnaryOperator;
2830

29-
import jdk.internal.foreign.AbstractMemorySegmentImpl;
30-
import jdk.internal.foreign.Utils;
3131
import jdk.internal.vm.annotation.ForceInline;
3232
import jdk.internal.vm.vector.VectorSupport;
3333

34-
import java.lang.foreign.ValueLayout;
35-
import java.lang.reflect.Array;
36-
import java.nio.ByteOrder;
37-
import java.util.Objects;
38-
import java.util.function.IntUnaryOperator;
39-
4034
import static jdk.incubator.vector.VectorOperators.*;
4135

4236
@SuppressWarnings("cast")
43-
abstract class AbstractVector<E> extends Vector<E> {
37+
abstract sealed class AbstractVector<E> extends Vector<E>
38+
permits ByteVector, DoubleVector, FloatVector, IntVector, LongVector, ShortVector {
4439
/**
4540
* The order of vector bytes when stored in natural,
4641
* array elements of the same lane type.

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
* {@code byte} values.
5050
*/
5151
@SuppressWarnings("cast") // warning: redundant cast
52-
public abstract class ByteVector extends AbstractVector<Byte> {
52+
public abstract sealed class ByteVector extends AbstractVector<Byte>
53+
permits ByteVector64, ByteVector128, ByteVector256, ByteVector512, ByteVectorMax {
5354

5455
ByteVector(byte[] vec) {
5556
super(vec);

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector128.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
package jdk.incubator.vector;
2626

2727
import java.lang.foreign.MemorySegment;
28-
import java.lang.foreign.ValueLayout;
2928
import java.nio.ByteOrder;
3029
import java.util.Arrays;
3130
import java.util.Objects;
@@ -34,9 +33,8 @@
3433
import jdk.internal.vm.annotation.ForceInline;
3534
import jdk.internal.vm.vector.VectorSupport;
3635

37-
import static jdk.internal.vm.vector.VectorSupport.*;
38-
3936
import static jdk.incubator.vector.VectorOperators.*;
37+
import static jdk.internal.vm.vector.VectorSupport.*;
4038

4139
// -- This file was mechanically generated: Do not edit! -- //
4240

@@ -371,7 +369,7 @@ final <F> VectorShuffle<F> bitsToShuffle(AbstractSpecies<F> dsp) {
371369
@Override
372370
@ForceInline
373371
public final ByteShuffle128 toShuffle() {
374-
return (ByteShuffle128) toShuffle(vspecies(), false);
372+
return (ByteShuffle128) toShuffle(VSPECIES, false);
375373
}
376374

377375
// Specialized unary testing
@@ -646,7 +644,7 @@ boolean[] getBits() {
646644

647645
@Override
648646
ByteMask128 uOp(MUnOp f) {
649-
boolean[] res = new boolean[vspecies().laneCount()];
647+
boolean[] res = new boolean[VSPECIES.laneCount()];
650648
boolean[] bits = getBits();
651649
for (int i = 0; i < res.length; i++) {
652650
res[i] = f.apply(i, bits[i]);
@@ -656,7 +654,7 @@ ByteMask128 uOp(MUnOp f) {
656654

657655
@Override
658656
ByteMask128 bOp(VectorMask<Byte> m, MBinOp f) {
659-
boolean[] res = new boolean[vspecies().laneCount()];
657+
boolean[] res = new boolean[VSPECIES.laneCount()];
660658
boolean[] bits = getBits();
661659
boolean[] mbits = ((ByteMask128)m).getBits();
662660
for (int i = 0; i < res.length; i++) {
@@ -806,24 +804,24 @@ public boolean laneIsSet(int i) {
806804
@ForceInline
807805
public boolean anyTrue() {
808806
return VectorSupport.test(BT_ne, ByteMask128.class, LANEBITS_TYPE_ORDINAL, VLENGTH,
809-
this, vspecies().maskAll(true),
810-
(m, __) -> anyTrueHelper(((ByteMask128)m).getBits()));
807+
this, VSPECIES.maskAll(true),
808+
(m, _) -> anyTrueHelper(((ByteMask128)m).getBits()));
811809
}
812810

813811
@Override
814812
@ForceInline
815813
public boolean allTrue() {
816814
return VectorSupport.test(BT_overflow, ByteMask128.class, LANEBITS_TYPE_ORDINAL, VLENGTH,
817-
this, vspecies().maskAll(true),
818-
(m, __) -> allTrueHelper(((ByteMask128)m).getBits()));
815+
this, VSPECIES.maskAll(true),
816+
(m, _) -> allTrueHelper(((ByteMask128)m).getBits()));
819817
}
820818

821819
@ForceInline
822820
/*package-private*/
823821
static ByteMask128 maskAll(boolean bit) {
824822
return VectorSupport.fromBitsCoerced(ByteMask128.class, LANEBITS_TYPE_ORDINAL, VLENGTH,
825823
(bit ? -1 : 0), MODE_BROADCAST, null,
826-
(v, __) -> (v != 0 ? TRUE_MASK : FALSE_MASK));
824+
(v, _) -> (v != 0 ? TRUE_MASK : FALSE_MASK));
827825
}
828826
private static final ByteMask128 TRUE_MASK = new ByteMask128(true);
829827
private static final ByteMask128 FALSE_MASK = new ByteMask128(false);
@@ -883,7 +881,7 @@ ByteVector128 toBitsVector() {
883881

884882
@Override
885883
ByteVector128 toBitsVector0() {
886-
return ((ByteVector128) vspecies().asIntegral().dummyVector()).vectorFactory(indices());
884+
return ((ByteVector128) VSPECIES.asIntegral().dummyVector()).vectorFactory(indices());
887885
}
888886

889887
@Override
@@ -934,15 +932,15 @@ public void intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo) {
934932
@ForceInline
935933
public final ByteMask128 laneIsValid() {
936934
return (ByteMask128) toBitsVector().compare(VectorOperators.GE, 0)
937-
.cast(vspecies());
935+
.cast(VSPECIES);
938936
}
939937

940938
@ForceInline
941939
@Override
942940
public final ByteShuffle128 rearrange(VectorShuffle<Byte> shuffle) {
943941
ByteShuffle128 concreteShuffle = (ByteShuffle128) shuffle;
944942
return (ByteShuffle128) toBitsVector().rearrange(concreteShuffle)
945-
.toShuffle(vspecies(), false);
943+
.toShuffle(VSPECIES, false);
946944
}
947945

948946
@ForceInline
@@ -955,7 +953,7 @@ public final ByteShuffle128 wrapIndexes() {
955953
v = (ByteVector128) v.blend(v.lanewise(VectorOperators.ADD, length()),
956954
v.compare(VectorOperators.LT, 0));
957955
}
958-
return (ByteShuffle128) v.toShuffle(vspecies(), false);
956+
return (ByteShuffle128) v.toShuffle(VSPECIES, false);
959957
}
960958

961959
private static byte[] prepare(int[] indices, int offset) {

0 commit comments

Comments
 (0)