< prev index next >

src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/sysv/TypeClass.java

Print this page

  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 package jdk.internal.foreign.abi.x64.sysv;
 26 
 27 import jdk.incubator.foreign.GroupLayout;

 28 import jdk.incubator.foreign.MemoryLayout;
 29 import jdk.incubator.foreign.SequenceLayout;
 30 import jdk.incubator.foreign.ValueLayout;
 31 import jdk.internal.foreign.PlatformLayouts;
 32 import jdk.internal.foreign.Utils;
 33 
 34 import java.util.ArrayList;
 35 import java.util.List;
 36 import java.util.stream.Collectors;
 37 import java.util.stream.IntStream;
 38 
 39 class TypeClass {
 40     enum Kind {
 41         STRUCT,
 42         POINTER,
 43         INTEGER,
 44         FLOAT
 45     }
 46 
 47     private final Kind kind;
 48     final List<ArgumentClassImpl> classes;
 49 
 50     private TypeClass(Kind kind, List<ArgumentClassImpl> classes) {
 51         this.kind = kind;

 90 
 91     // layout classification
 92 
 93     // The AVX 512 enlightened ABI says "eight eightbytes"
 94     // Although AMD64 0.99.6 states 4 eightbytes
 95     private static final int MAX_AGGREGATE_REGS_SIZE = 8;
 96     static final List<ArgumentClassImpl> COMPLEX_X87_CLASSES = List.of(
 97          ArgumentClassImpl.X87,
 98          ArgumentClassImpl.X87UP,
 99          ArgumentClassImpl.X87,
100          ArgumentClassImpl.X87UP
101     );
102 
103     private static List<ArgumentClassImpl> createMemoryClassArray(long size) {
104         return IntStream.range(0, (int)size)
105                 .mapToObj(i -> ArgumentClassImpl.MEMORY)
106                 .collect(Collectors.toCollection(ArrayList::new));
107     }
108 
109     private static ArgumentClassImpl argumentClassFor(MemoryLayout layout) {
110         return switch (PlatformLayouts.getKind(layout)) {
111             case CHAR, SHORT, INT, LONG, LONG_LONG -> ArgumentClassImpl.INTEGER;
112             case FLOAT, DOUBLE -> ArgumentClassImpl.SSE;
113             case POINTER -> ArgumentClassImpl.POINTER;
114         };






115     }
116 
117     // TODO: handle zero length arrays
118     private static List<ArgumentClassImpl> classifyStructType(GroupLayout type) {
119         List<ArgumentClassImpl>[] eightbytes = groupByEightBytes(type);
120         long nWords = eightbytes.length;
121         if (nWords > MAX_AGGREGATE_REGS_SIZE) {
122             return createMemoryClassArray(nWords);
123         }
124 
125         ArrayList<ArgumentClassImpl> classes = new ArrayList<>();
126 
127         for (int idx = 0; idx < nWords; idx++) {
128             List<ArgumentClassImpl> subclasses = eightbytes[idx];
129             ArgumentClassImpl result = subclasses.stream()
130                     .reduce(ArgumentClassImpl.NO_CLASS, ArgumentClassImpl::merge);
131             classes.add(result);
132         }
133 
134         for (int i = 0; i < classes.size(); i++) {

  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 package jdk.internal.foreign.abi.x64.sysv;
 26 
 27 import jdk.incubator.foreign.GroupLayout;
 28 import jdk.incubator.foreign.MemoryAddress;
 29 import jdk.incubator.foreign.MemoryLayout;
 30 import jdk.incubator.foreign.SequenceLayout;
 31 import jdk.incubator.foreign.ValueLayout;

 32 import jdk.internal.foreign.Utils;
 33 
 34 import java.util.ArrayList;
 35 import java.util.List;
 36 import java.util.stream.Collectors;
 37 import java.util.stream.IntStream;
 38 
 39 class TypeClass {
 40     enum Kind {
 41         STRUCT,
 42         POINTER,
 43         INTEGER,
 44         FLOAT
 45     }
 46 
 47     private final Kind kind;
 48     final List<ArgumentClassImpl> classes;
 49 
 50     private TypeClass(Kind kind, List<ArgumentClassImpl> classes) {
 51         this.kind = kind;

 90 
 91     // layout classification
 92 
 93     // The AVX 512 enlightened ABI says "eight eightbytes"
 94     // Although AMD64 0.99.6 states 4 eightbytes
 95     private static final int MAX_AGGREGATE_REGS_SIZE = 8;
 96     static final List<ArgumentClassImpl> COMPLEX_X87_CLASSES = List.of(
 97          ArgumentClassImpl.X87,
 98          ArgumentClassImpl.X87UP,
 99          ArgumentClassImpl.X87,
100          ArgumentClassImpl.X87UP
101     );
102 
103     private static List<ArgumentClassImpl> createMemoryClassArray(long size) {
104         return IntStream.range(0, (int)size)
105                 .mapToObj(i -> ArgumentClassImpl.MEMORY)
106                 .collect(Collectors.toCollection(ArrayList::new));
107     }
108 
109     private static ArgumentClassImpl argumentClassFor(MemoryLayout layout) {
110         Class<?> carrier = ((ValueLayout)layout).carrier();
111         if (carrier == boolean.class || carrier == byte.class || carrier == char.class ||
112                 carrier == short.class || carrier == int.class || carrier == long.class) {
113             return ArgumentClassImpl.INTEGER;
114         } else if (carrier == float.class || carrier == double.class) {
115             return ArgumentClassImpl.SSE;
116         } else if (carrier == MemoryAddress.class) {
117             return ArgumentClassImpl.POINTER;
118         } else {
119             throw new IllegalStateException("Cannot get here: " + carrier.getName());
120         }
121     }
122 
123     // TODO: handle zero length arrays
124     private static List<ArgumentClassImpl> classifyStructType(GroupLayout type) {
125         List<ArgumentClassImpl>[] eightbytes = groupByEightBytes(type);
126         long nWords = eightbytes.length;
127         if (nWords > MAX_AGGREGATE_REGS_SIZE) {
128             return createMemoryClassArray(nWords);
129         }
130 
131         ArrayList<ArgumentClassImpl> classes = new ArrayList<>();
132 
133         for (int idx = 0; idx < nWords; idx++) {
134             List<ArgumentClassImpl> subclasses = eightbytes[idx];
135             ArgumentClassImpl result = subclasses.stream()
136                     .reduce(ArgumentClassImpl.NO_CLASS, ArgumentClassImpl::merge);
137             classes.add(result);
138         }
139 
140         for (int i = 0; i < classes.size(); i++) {
< prev index next >