2424 */
2525package com .oracle .svm .core .jdk ;
2626
27+ import java .lang .foreign .MemorySegment ;
28+ import java .lang .foreign .ValueLayout ;
29+ import java .util .function .IntFunction ;
2730import java .util .stream .Collectors ;
2831
2932import org .graalvm .nativeimage .ImageSingletons ;
@@ -109,6 +112,48 @@ private static final class Target_jdk_incubator_vector_VectorOperators_Conversio
109112 @ AlwaysInline ("Vector API performance" )
110113 private static native Target_jdk_incubator_vector_VectorOperators_ConversionImpl <?, ?> ofReinterpret (Target_jdk_incubator_vector_LaneType dom , Target_jdk_incubator_vector_LaneType ran );
111114 }
115+
116+ @ TargetClass (className = "jdk.incubator.vector.VectorOperators" , innerClass = "Operator" , onlyWith = VectorAPIEnabled .class )
117+ interface Target_jdk_incubator_vector_VectorOperators_Operator {
118+ }
119+
120+ @ TargetClass (className = "jdk.incubator.vector.VectorOperators" , innerClass = "ImplCache" , onlyWith = VectorAPIEnabled .class )
121+ static final class Target_jdk_incubator_vector_VectorOperators_ImplCache <OP extends Target_jdk_incubator_vector_VectorOperators_Operator , T > {
122+
123+ @ Alias Object [] cache ;
124+
125+ /*
126+ * We substitute ImplCache#find to remove the call to isNonCapturingLambda. In the process,
127+ * we simplify the cache lookup by removing lazy cache initialization as we precompute the
128+ * cache.
129+ */
130+ @ Substitute
131+ @ AlwaysInline ("Vector API fast-path" )
132+ @ SuppressWarnings ({"unchecked" , "unused" })
133+ public T find (OP op , int opc , IntFunction <T > supplier ) {
134+ T fn = (T ) cache [opc ];
135+ return fn ;
136+ }
137+ }
138+ }
139+
140+ @ TargetClass (className = "jdk.incubator.vector.AbstractVector" , onlyWith = VectorAPIEnabled .class )
141+ final class Target_jdk_incubator_vector_AbstractVector {
142+ }
143+
144+ @ TargetClass (className = "jdk.incubator.vector.AbstractSpecies" , onlyWith = VectorAPIEnabled .class )
145+ final class Target_jdk_incubator_vector_AbstractSpecies {
146+
147+ @ Alias private Target_jdk_incubator_vector_AbstractVector dummyVector ;
148+
149+ /*
150+ * We initialize the `dummyVector` fields during image build-time using VectorAPIFeature. We can
151+ * have the getter method return the precomputed dummy vector directly.
152+ */
153+ @ Substitute
154+ Target_jdk_incubator_vector_AbstractVector dummyVector () {
155+ return dummyVector ;
156+ }
112157}
113158
114159@ TargetClass (className = "jdk.incubator.vector.ByteVector" , onlyWith = VectorAPIEnabled .class )
@@ -119,6 +164,20 @@ final class Target_jdk_incubator_vector_ByteVector {
119164 @ Alias @ RecomputeFieldValue (kind = RecomputeFieldValue .Kind .ArrayBaseOffset , declClass = byte [].class , isFinal = true ) //
120165 @ TargetElement (name = "ARRAY_BASE" ) //
121166 private static long arrayBase ;
167+
168+ @ Alias @ RecomputeFieldValue (isFinal = true , kind = RecomputeFieldValue .Kind .None ) //
169+ @ TargetElement (name = "ELEMENT_LAYOUT" ) //
170+ static ValueLayout .OfByte elementLayout ;
171+
172+ @ Substitute
173+ static void memorySegmentSet (MemorySegment ms , long o , int i , byte e ) {
174+ elementLayout .varHandle ().set (ms , o + i * 1L , e );
175+ }
176+
177+ @ Substitute
178+ static byte memorySegmentGet (MemorySegment ms , long o , int i ) {
179+ return (byte ) elementLayout .varHandle ().get (ms , o + i * 1L );
180+ }
122181}
123182
124183@ TargetClass (className = "jdk.incubator.vector.ShortVector" , onlyWith = VectorAPIEnabled .class )
@@ -129,6 +188,20 @@ final class Target_jdk_incubator_vector_ShortVector {
129188 @ Alias @ RecomputeFieldValue (kind = RecomputeFieldValue .Kind .ArrayBaseOffset , declClass = short [].class , isFinal = true ) //
130189 @ TargetElement (name = "ARRAY_BASE" ) //
131190 private static long arrayBase ;
191+
192+ @ Alias @ RecomputeFieldValue (isFinal = true , kind = RecomputeFieldValue .Kind .None ) //
193+ @ TargetElement (name = "ELEMENT_LAYOUT" ) //
194+ static ValueLayout .OfShort elementLayout ;
195+
196+ @ Substitute
197+ static void memorySegmentSet (MemorySegment ms , long o , int i , short e ) {
198+ elementLayout .varHandle ().set (ms , o + i * 2L , e );
199+ }
200+
201+ @ Substitute
202+ static short memorySegmentGet (MemorySegment ms , long o , int i ) {
203+ return (short ) elementLayout .varHandle ().get (ms , o + i * 2L );
204+ }
132205}
133206
134207@ TargetClass (className = "jdk.incubator.vector.IntVector" , onlyWith = VectorAPIEnabled .class )
@@ -139,6 +212,20 @@ final class Target_jdk_incubator_vector_IntVector {
139212 @ Alias @ RecomputeFieldValue (kind = RecomputeFieldValue .Kind .ArrayBaseOffset , declClass = int [].class , isFinal = true ) //
140213 @ TargetElement (name = "ARRAY_BASE" ) //
141214 private static long arrayBase ;
215+
216+ @ Alias @ RecomputeFieldValue (isFinal = true , kind = RecomputeFieldValue .Kind .None ) //
217+ @ TargetElement (name = "ELEMENT_LAYOUT" ) //
218+ static ValueLayout .OfInt elementLayout ;
219+
220+ @ Substitute
221+ static void memorySegmentSet (MemorySegment ms , long o , int i , int e ) {
222+ elementLayout .varHandle ().set (ms , o + i * 4L , e );
223+ }
224+
225+ @ Substitute
226+ static int memorySegmentGet (MemorySegment ms , long o , int i ) {
227+ return (int ) elementLayout .varHandle ().get (ms , o + i * 4L );
228+ }
142229}
143230
144231@ TargetClass (className = "jdk.incubator.vector.LongVector" , onlyWith = VectorAPIEnabled .class )
@@ -149,6 +236,20 @@ final class Target_jdk_incubator_vector_LongVector {
149236 @ Alias @ RecomputeFieldValue (kind = RecomputeFieldValue .Kind .ArrayBaseOffset , declClass = long [].class , isFinal = true ) //
150237 @ TargetElement (name = "ARRAY_BASE" ) //
151238 private static long arrayBase ;
239+
240+ @ Alias @ RecomputeFieldValue (isFinal = true , kind = RecomputeFieldValue .Kind .None ) //
241+ @ TargetElement (name = "ELEMENT_LAYOUT" ) //
242+ static ValueLayout .OfLong elementLayout ;
243+
244+ @ Substitute
245+ static void memorySegmentSet (MemorySegment ms , long o , int i , long e ) {
246+ elementLayout .varHandle ().set (ms , o + i * 8L , e );
247+ }
248+
249+ @ Substitute
250+ static long memorySegmentGet (MemorySegment ms , long o , int i ) {
251+ return (long ) elementLayout .varHandle ().get (ms , o + i * 8L );
252+ }
152253}
153254
154255@ TargetClass (className = "jdk.incubator.vector.FloatVector" , onlyWith = VectorAPIEnabled .class )
@@ -159,6 +260,20 @@ final class Target_jdk_incubator_vector_FloatVector {
159260 @ Alias @ RecomputeFieldValue (kind = RecomputeFieldValue .Kind .ArrayBaseOffset , declClass = float [].class , isFinal = true ) //
160261 @ TargetElement (name = "ARRAY_BASE" ) //
161262 private static long arrayBase ;
263+
264+ @ Alias @ RecomputeFieldValue (isFinal = true , kind = RecomputeFieldValue .Kind .None ) //
265+ @ TargetElement (name = "ELEMENT_LAYOUT" ) //
266+ static ValueLayout .OfFloat elementLayout ;
267+
268+ @ Substitute
269+ static void memorySegmentSet (MemorySegment ms , long o , int i , float e ) {
270+ elementLayout .varHandle ().set (ms , o + i * 4L , e );
271+ }
272+
273+ @ Substitute
274+ static float memorySegmentGet (MemorySegment ms , long o , int i ) {
275+ return (float ) elementLayout .varHandle ().get (ms , o + i * 4L );
276+ }
162277}
163278
164279@ TargetClass (className = "jdk.incubator.vector.DoubleVector" , onlyWith = VectorAPIEnabled .class )
@@ -169,4 +284,18 @@ final class Target_jdk_incubator_vector_DoubleVector {
169284 @ Alias @ RecomputeFieldValue (kind = RecomputeFieldValue .Kind .ArrayBaseOffset , declClass = double [].class , isFinal = true ) //
170285 @ TargetElement (name = "ARRAY_BASE" ) //
171286 private static long arrayBase ;
287+
288+ @ Alias @ RecomputeFieldValue (isFinal = true , kind = RecomputeFieldValue .Kind .None ) //
289+ @ TargetElement (name = "ELEMENT_LAYOUT" ) //
290+ static ValueLayout .OfDouble elementLayout ;
291+
292+ @ Substitute
293+ static void memorySegmentSet (MemorySegment ms , long o , int i , double e ) {
294+ elementLayout .varHandle ().set (ms , o + i * 8L , e );
295+ }
296+
297+ @ Substitute
298+ static double memorySegmentGet (MemorySegment ms , long o , int i ) {
299+ return (double ) elementLayout .varHandle ().get (ms , o + i * 8L );
300+ }
172301}
0 commit comments