< prev index next >

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

Print this page

180             } else if (type instanceof GroupLayout groupLayout) {
181                 return ofStruct(groupLayout);
182             } else {
183                 throw new IllegalArgumentException("Unsupported layout: " + type);
184             }
185         } catch (UnsupportedOperationException e) {
186             System.err.println("Failed to classify layout: " + type);
187             throw e;
188         }
189     }
190 
191     private static List<ArgumentClassImpl>[] groupByEightBytes(GroupLayout group) {
192         long offset = 0L;
193         int nEightbytes;
194         try {
195             // alignUp can overflow the value, but it's okay since toIntExact still catches it
196             nEightbytes = Math.toIntExact(Utils.alignUp(group.byteSize(), 8) / 8);
197         } catch (ArithmeticException e) {
198             throw new IllegalArgumentException("GroupLayout is too large: " + group, e);
199         }
200         @SuppressWarnings({"unchecked", "rawtypes"})
201         List<ArgumentClassImpl>[] groups = new List[nEightbytes];
202         for (MemoryLayout l : group.memberLayouts()) {
203             groupByEightBytes(l, offset, groups);
204             if (group instanceof StructLayout) {
205                 offset += l.byteSize();
206             }
207         }
208         return groups;
209     }
210 
211     private static void groupByEightBytes(MemoryLayout layout,
212                                           long offset,
213                                           List<ArgumentClassImpl>[] groups) {
214         switch (layout) {
215             case GroupLayout group -> {
216                 for (MemoryLayout m : group.memberLayouts()) {
217                     groupByEightBytes(m, offset, groups);
218                     if (group instanceof StructLayout) {
219                         offset += m.byteSize();
220                     }

180             } else if (type instanceof GroupLayout groupLayout) {
181                 return ofStruct(groupLayout);
182             } else {
183                 throw new IllegalArgumentException("Unsupported layout: " + type);
184             }
185         } catch (UnsupportedOperationException e) {
186             System.err.println("Failed to classify layout: " + type);
187             throw e;
188         }
189     }
190 
191     private static List<ArgumentClassImpl>[] groupByEightBytes(GroupLayout group) {
192         long offset = 0L;
193         int nEightbytes;
194         try {
195             // alignUp can overflow the value, but it's okay since toIntExact still catches it
196             nEightbytes = Math.toIntExact(Utils.alignUp(group.byteSize(), 8) / 8);
197         } catch (ArithmeticException e) {
198             throw new IllegalArgumentException("GroupLayout is too large: " + group, e);
199         }
200         @SuppressWarnings({"unchecked", "rawtypes"}) // rawtypes warnings need to be suppressed
201         List<ArgumentClassImpl>[] groups = new List[nEightbytes];
202         for (MemoryLayout l : group.memberLayouts()) {
203             groupByEightBytes(l, offset, groups);
204             if (group instanceof StructLayout) {
205                 offset += l.byteSize();
206             }
207         }
208         return groups;
209     }
210 
211     private static void groupByEightBytes(MemoryLayout layout,
212                                           long offset,
213                                           List<ArgumentClassImpl>[] groups) {
214         switch (layout) {
215             case GroupLayout group -> {
216                 for (MemoryLayout m : group.memberLayouts()) {
217                     groupByEightBytes(m, offset, groups);
218                     if (group instanceof StructLayout) {
219                         offset += m.byteSize();
220                     }
< prev index next >