< prev index next >

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

Print this page

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

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