GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
MachineDataInfo.java
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
3 * Copyright (c) 2010 JogAmp Community. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * - Redistribution of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistribution in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of Sun Microsystems, Inc. or the names of
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * This software is provided "AS IS," without a warranty of any kind. ALL
21 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
22 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
23 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
24 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
25 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
26 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
27 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
28 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
29 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
30 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
31 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 *
33 * You acknowledge that this software is not designed or intended for use
34 * in the design, construction, operation or maintenance of any nuclear
35 * facility.
36 *
37 * Sun gratefully acknowledges that this software was originally authored
38 * and developed by Kenneth Bradley Russell and Christopher John Kline.
39 */
40
41package com.jogamp.common.os;
42
43import jogamp.common.os.PlatformPropsImpl;
44
45/**
46 * Machine data description for alignment and size onle, see {@link com.jogamp.gluegen}.
47 * <p>
48 * {@code little-endian} / {@code big/endian} description is left,
49 * allowing re-using instances in {@link MachineDataInfo.StaticConfig StaticConfig}.
50 * Use {@link {@link PlatformPropsImpl#LITTLE_ENDIAN}.
51 * </p>
52 * <p>
53 * Further more, the value {@ MachineDataInfo#pageSizeInBytes} shall be ignored
54 * in {@link MachineDataInfo.StaticConfig StaticConfig}, see {@link MachineDataInfo#compatible(MachineDataInfo)}.
55 * </p>
56 */
57public class MachineDataInfo {
58 /* arch os int, long, float, doubl, ldoubl, ptr, page */
59 private final static int[] size_arm_mips_32 = { 4, 4, 4, 8, 8, 4, 4096 };
60 private final static int[] size_x86_32_unix = { 4, 4, 4, 8, 12, 4, 4096 };
61 private final static int[] size_x86_32_android = { 4, 4, 4, 8, 8, 4, 4096 };
62 private final static int[] size_x86_32_macos = { 4, 4, 4, 8, 16, 4, 4096 };
63 private final static int[] size_ppc_32_unix = { 4, 4, 4, 8, 16, 4, 4096 };
64 private final static int[] size_sparc_32_sunos = { 4, 4, 4, 8, 16, 4, 8192 };
65 private final static int[] size_x86_32_windows = { 4, 4, 4, 8, 12, 4, 4096 };
66 private final static int[] size_lp64_unix = { 4, 8, 4, 8, 16, 8, 4096 };
67 private final static int[] size_x86_64_windows = { 4, 4, 4, 8, 16, 8, 4096 };
68 private final static int[] size_arm64_ios = { 4, 8, 4, 8, 8, 8, 8192 };
69
70 /* arch os i8, i16, i32, i64, int, long, float, doubl, ldoubl, ptr */
71 private final static int[] align_arm_mips_32 = { 1, 2, 4, 8, 4, 4, 4, 8, 8, 4 };
72 private final static int[] align_x86_32_unix = { 1, 2, 4, 4, 4, 4, 4, 4, 4, 4 };
73 private final static int[] align_x86_32_macos = { 1, 2, 4, 4, 4, 4, 4, 4, 16, 4 };
74 private final static int[] align_ppc_32_unix = { 1, 2, 4, 8, 4, 4, 4, 8, 16, 4 };
75 private final static int[] align_sparc_32_sunos = { 1, 2, 4, 8, 4, 4, 4, 8, 8, 4 };
76 private final static int[] align_x86_32_windows = { 1, 2, 4, 8, 4, 4, 4, 8, 4, 4 };
77 private final static int[] align_lp64_unix = { 1, 2, 4, 8, 4, 8, 4, 8, 16, 8 };
78 private final static int[] align_x86_64_windows = { 1, 2, 4, 8, 4, 4, 4, 8, 16, 8 };
79 private final static int[] align_arm64_ios = { 1, 2, 4, 8, 4, 8, 4, 8, 8, 8 };
80
81 /**
82 * Static enumeration of {@link MachineDataInfo} instances
83 * used for high performance data size and alignment lookups,
84 * e.g. for generated structures using the {@link MachineDataInfo.StaticConfig} index.
85 * <p>
86 * The value {@link MachineDataInfo#pageSizeInBytes} shall be ignored
87 * for static instances!
88 * </p>
89 * <p>
90 * If changing this table, you need to:
91 * <ul>
92 * <li>Rebuild GlueGen.</li>
93 * <li>Run ant {@code build.xml} target {@code generate.os.sources}.</li>
94 * <li>Rebuild everything.</li>
95 * </ul>
96 * .. b/c the generated code for glued structures must reflect this change!
97 * </p>
98 */
99 public enum StaticConfig {
100 /** {@link Platform.CPUType#ARM} or {@link Platform.CPUType#MIPS_32} */
101 ARM_MIPS_32( size_arm_mips_32, align_arm_mips_32),
102 /** {@link Platform.CPUType#X86_32} Unix */
103 X86_32_UNIX( size_x86_32_unix, align_x86_32_unix),
104 /** {@link Platform.CPUType#X86_32} Android/Bionic */
105 X86_32_ANDROID( size_x86_32_android, align_x86_32_unix),
106 /** {@link Platform.CPUType#X86_32} MacOS (Special case gcc4/OSX) */
107 X86_32_MACOS( size_x86_32_macos, align_x86_32_macos),
108 /** {@link Platform.CPUType#PPC} Unix */
109 PPC_32_UNIX( size_ppc_32_unix, align_ppc_32_unix),
110 /** {@link Platform.CPUType#SPARC_32} Solaris */
111 SPARC_32_SUNOS( size_sparc_32_sunos, align_sparc_32_sunos),
112 /** {@link Platform.CPUType#X86_32} Windows */
113 X86_32_WINDOWS( size_x86_32_windows, align_x86_32_windows),
114 /** LP64 Unix, e.g.: {@link Platform.CPUType#X86_64} Unix, {@link Platform.CPUType#ARM64} EABI, {@link Platform.CPUType#PPC64} Unix, .. */
115 LP64_UNIX( size_lp64_unix, align_lp64_unix),
116 /** {@link Platform.CPUType#X86_64} Windows */
117 X86_64_WINDOWS( size_x86_64_windows, align_x86_64_windows),
118 /** {@link Platform.CPUType#ARM64 } iOS */
119 ARM64_IOS( size_arm64_ios, align_arm64_ios);
120 // 9
121
122 public final MachineDataInfo md;
123
124 StaticConfig(final int[] sizes, final int[] alignments) {
125 int i=0, j=0;
126 this.md = new MachineDataInfo(false,
127 sizes[i++],
128 sizes[i++],
129 sizes[i++],
130 sizes[i++],
131 sizes[i++],
132 sizes[i++],
133 sizes[i++],
134 alignments[j++],
135 alignments[j++],
136 alignments[j++],
137 alignments[j++],
138 alignments[j++],
139 alignments[j++],
140 alignments[j++],
141 alignments[j++],
142 alignments[j++],
143 alignments[j++]);
144 }
145
146 public final StringBuilder toString(StringBuilder sb) {
147 if(null==sb) {
148 sb = new StringBuilder();
149 }
150 sb.append("MachineDataInfoStatic: ").append(this.name()).append("(").append(this.ordinal()).append("): ");
151 md.toString(sb);
152 return sb;
153 }
154 public final String toShortString() {
155 return this.name()+"("+this.ordinal()+")";
156 }
157 @Override
158 public String toString() {
159 return toString(null).toString();
160 }
161
162 /**
163 * Static's {@link MachineDataInfo} shall be unique by the
164 * {@link MachineDataInfo#compatible(MachineDataInfo) compatible} criteria.
165 */
166 public static final void validateUniqueMachineDataInfo() {
167 final StaticConfig[] scs = StaticConfig.values();
168 for(int i=scs.length-1; i>=0; i--) {
169 final StaticConfig a = scs[i];
170 for(int j=scs.length-1; j>=0; j--) {
171 if( i != j ) {
172 final StaticConfig b = scs[j];
173 if( a.md.compatible(b.md) ) {
174 // oops
175 final String msg = "Duplicate/Compatible MachineDataInfo in StaticConfigs: Elements ["+i+": "+a.toShortString()+"] and ["+j+": "+b.toShortString()+"]";
176 System.err.println(msg);
177 System.err.println(a);
178 System.err.println(b);
179 throw new InternalError(msg);
180 }
181 }
182 }
183 }
184 }
185 public static final StaticConfig findCompatible(final MachineDataInfo md) {
186 final StaticConfig[] scs = StaticConfig.values();
187 for(int i=scs.length-1; i>=0; i--) {
188 final StaticConfig a = scs[i];
189 if( a.md.compatible(md) ) {
190 return a;
191 }
192 }
193 return null;
194 }
195 }
196
197 final private boolean runtimeValidated;
198
199 final private int int8SizeInBytes = 1;
200 final private int int16SizeInBytes = 2;
201 final private int int32SizeInBytes = 4;
202 final private int int64SizeInBytes = 8;
203
204 final private int intSizeInBytes;
205 final private int longSizeInBytes;
206 final private int floatSizeInBytes;
207 final private int doubleSizeInBytes;
208 final private int ldoubleSizeInBytes;
209 final private int pointerSizeInBytes;
210 final private int pageSizeInBytes;
211
212 final private int int8AlignmentInBytes;
213 final private int int16AlignmentInBytes;
214 final private int int32AlignmentInBytes;
215 final private int int64AlignmentInBytes;
216 final private int intAlignmentInBytes;
217 final private int longAlignmentInBytes;
218 final private int floatAlignmentInBytes;
219 final private int doubleAlignmentInBytes;
220 final private int ldoubleAlignmentInBytes;
221 final private int pointerAlignmentInBytes;
222
223 public MachineDataInfo(final boolean runtimeValidated,
224
225 final int intSizeInBytes,
226 final int longSizeInBytes,
227 final int floatSizeInBytes,
228 final int doubleSizeInBytes,
229 final int ldoubleSizeInBytes,
230 final int pointerSizeInBytes,
231 final int pageSizeInBytes,
232
233 final int int8AlignmentInBytes,
234 final int int16AlignmentInBytes,
235 final int int32AlignmentInBytes,
236 final int int64AlignmentInBytes,
237 final int intAlignmentInBytes,
238 final int longAlignmentInBytes,
239 final int floatAlignmentInBytes,
240 final int doubleAlignmentInBytes,
241 final int ldoubleAlignmentInBytes,
242 final int pointerAlignmentInBytes) {
243 this.runtimeValidated = runtimeValidated;
244
245 this.intSizeInBytes = intSizeInBytes;
246 this.longSizeInBytes = longSizeInBytes;
247 this.floatSizeInBytes = floatSizeInBytes;
248 this.doubleSizeInBytes = doubleSizeInBytes;
249 this.ldoubleSizeInBytes = ldoubleSizeInBytes;
250 this.pointerSizeInBytes = pointerSizeInBytes;
251 this.pageSizeInBytes = pageSizeInBytes;
252
253 this.int8AlignmentInBytes = int8AlignmentInBytes;
254 this.int16AlignmentInBytes = int16AlignmentInBytes;
255 this.int32AlignmentInBytes = int32AlignmentInBytes;
256 this.int64AlignmentInBytes = int64AlignmentInBytes;
257 this.intAlignmentInBytes = intAlignmentInBytes;
258 this.longAlignmentInBytes = longAlignmentInBytes;
259 this.floatAlignmentInBytes = floatAlignmentInBytes;
260 this.doubleAlignmentInBytes = doubleAlignmentInBytes;
261 this.ldoubleAlignmentInBytes = ldoubleAlignmentInBytes;
262 this.pointerAlignmentInBytes = pointerAlignmentInBytes;
263 }
264
265 /**
266 * @return true if all values are validated at runtime, otherwise false (i.e. for static compilation w/ preset values)
267 */
268 public final boolean isRuntimeValidated() {
269 return runtimeValidated;
270 }
271
272 public final int intSizeInBytes() { return intSizeInBytes; }
273 public final int longSizeInBytes() { return longSizeInBytes; }
274 public final int int8SizeInBytes() { return int8SizeInBytes; }
275 public final int int16SizeInBytes() { return int16SizeInBytes; }
276 public final int int32SizeInBytes() { return int32SizeInBytes; }
277 public final int int64SizeInBytes() { return int64SizeInBytes; }
278 public final int floatSizeInBytes() { return floatSizeInBytes; }
279 public final int doubleSizeInBytes() { return doubleSizeInBytes; }
280 public final int ldoubleSizeInBytes() { return ldoubleSizeInBytes; }
281 public final int pointerSizeInBytes() { return pointerSizeInBytes; }
282 public final int pageSizeInBytes() { return pageSizeInBytes; }
283
284 public final int intAlignmentInBytes() { return intAlignmentInBytes; }
285 public final int longAlignmentInBytes() { return longAlignmentInBytes; }
286 public final int int8AlignmentInBytes() { return int8AlignmentInBytes; }
287 public final int int16AlignmentInBytes() { return int16AlignmentInBytes; }
288 public final int int32AlignmentInBytes() { return int32AlignmentInBytes; }
289 public final int int64AlignmentInBytes() { return int64AlignmentInBytes; }
290 public final int floatAlignmentInBytes() { return floatAlignmentInBytes; }
291 public final int doubleAlignmentInBytes() { return doubleAlignmentInBytes; }
294
295 /**
296 * @return number of pages required for size in bytes
297 */
298 public int pageCount(final int size) {
299 return ( size + ( pageSizeInBytes - 1) ) / pageSizeInBytes ; // integer arithmetic
300 }
301
302 /**
303 * @return page aligned size in bytes
304 */
305 public int pageAlignedSize(final int size) {
306 return pageCount(size) * pageSizeInBytes;
307 }
308
309 /**
310 * Checks whether two size objects are equal. Two instances
311 * of <code>MachineDataInfo</code> are considered equal if all components
312 * match but {@link #runtimeValidated}, {@link #isRuntimeValidated()}.
313 * @return <code>true</code> if the two MachineDataInfo are equal;
314 * otherwise <code>false</code>.
315 */
316 @Override
317 public final boolean equals(final Object obj) {
318 if (this == obj) { return true; }
319 if ( !(obj instanceof MachineDataInfo) ) { return false; }
320 final MachineDataInfo md = (MachineDataInfo) obj;
321
322 return pageSizeInBytes == md.pageSizeInBytes &&
323 compatible(md);
324 }
325
326 /**
327 * Checks whether two {@link MachineDataInfo} objects are equal.
328 * <p>
329 * Two {@link MachineDataInfo} instances are considered equal if all components
330 * match but {@link #isRuntimeValidated()} and {@link #pageSizeInBytes()}.
331 * </p>
332 * @return <code>true</code> if the two {@link MachineDataInfo} are equal;
333 * otherwise <code>false</code>.
334 */
335 public final boolean compatible(final MachineDataInfo md) {
336 return intSizeInBytes == md.intSizeInBytes &&
337 longSizeInBytes == md.longSizeInBytes &&
338 floatSizeInBytes == md.floatSizeInBytes &&
339 doubleSizeInBytes == md.doubleSizeInBytes &&
340 ldoubleSizeInBytes == md.ldoubleSizeInBytes &&
341 pointerSizeInBytes == md.pointerSizeInBytes &&
342
343 int8AlignmentInBytes == md.int8AlignmentInBytes &&
344 int16AlignmentInBytes == md.int16AlignmentInBytes &&
345 int32AlignmentInBytes == md.int32AlignmentInBytes &&
346 int64AlignmentInBytes == md.int64AlignmentInBytes &&
347 intAlignmentInBytes == md.intAlignmentInBytes &&
348 longAlignmentInBytes == md.longAlignmentInBytes &&
349 floatAlignmentInBytes == md.floatAlignmentInBytes &&
350 doubleAlignmentInBytes == md.doubleAlignmentInBytes &&
351 ldoubleAlignmentInBytes == md.ldoubleAlignmentInBytes &&
352 pointerAlignmentInBytes == md.pointerAlignmentInBytes ;
353 }
354
355 public StringBuilder toString(StringBuilder sb) {
356 if(null==sb) {
357 sb = new StringBuilder();
358 }
359 sb.append("MachineDataInfo: runtimeValidated ").append(isRuntimeValidated()).append(", 32Bit ").append(4 == pointerAlignmentInBytes).append(", primitive size / alignment:").append(PlatformPropsImpl.NEWLINE);
360 sb.append(" int8 ").append(int8SizeInBytes) .append(" / ").append(int8AlignmentInBytes);
361 sb.append(", int16 ").append(int16SizeInBytes) .append(" / ").append(int16AlignmentInBytes).append(Platform.getNewline());
362 sb.append(" int ").append(intSizeInBytes) .append(" / ").append(intAlignmentInBytes);
363 sb.append(", long ").append(longSizeInBytes) .append(" / ").append(longAlignmentInBytes).append(Platform.getNewline());
364 sb.append(" int32 ").append(int32SizeInBytes) .append(" / ").append(int32AlignmentInBytes);
365 sb.append(", int64 ").append(int64SizeInBytes) .append(" / ").append(int64AlignmentInBytes).append(Platform.getNewline());
366 sb.append(" float ").append(floatSizeInBytes) .append(" / ").append(floatAlignmentInBytes);
367 sb.append(", double ").append(doubleSizeInBytes) .append(" / ").append(doubleAlignmentInBytes);
368 sb.append(", ldouble ").append(ldoubleSizeInBytes).append(" / ").append(ldoubleAlignmentInBytes).append(Platform.getNewline());
369 sb.append(" pointer ").append(pointerSizeInBytes).append(" / ").append(pointerAlignmentInBytes);
370 sb.append(", page ").append(pageSizeInBytes);
371 return sb;
372 }
373
374 @Override
375 public String toString() {
376 return toString(null).toString();
377 }
378
379}
Machine data description for alignment and size onle, see com.jogamp.gluegen.
final boolean compatible(final MachineDataInfo md)
Checks whether two MachineDataInfo objects are equal.
final boolean equals(final Object obj)
Checks whether two size objects are equal.
StringBuilder toString(StringBuilder sb)
MachineDataInfo(final boolean runtimeValidated, final int intSizeInBytes, final int longSizeInBytes, final int floatSizeInBytes, final int doubleSizeInBytes, final int ldoubleSizeInBytes, final int pointerSizeInBytes, final int pageSizeInBytes, final int int8AlignmentInBytes, final int int16AlignmentInBytes, final int int32AlignmentInBytes, final int int64AlignmentInBytes, final int intAlignmentInBytes, final int longAlignmentInBytes, final int floatAlignmentInBytes, final int doubleAlignmentInBytes, final int ldoubleAlignmentInBytes, final int pointerAlignmentInBytes)
Utility class for querying platform specific properties.
Definition: Platform.java:58
static String getNewline()
Returns the platform's line separator.
Definition: Platform.java:503
Static enumeration of MachineDataInfo instances used for high performance data size and alignment loo...
StaticConfig(final int[] sizes, final int[] alignments)
X86_32_MACOS
Platform.CPUType#X86_32 MacOS (Special case gcc4/OSX)
static final void validateUniqueMachineDataInfo()
Static's MachineDataInfo shall be unique by the compatible criteria.
X86_32_ANDROID
Platform.CPUType#X86_32 Android/Bionic
ARM_MIPS_32
Platform.CPUType#ARM or Platform.CPUType#MIPS_32
SPARC_32_SUNOS
Platform.CPUType#SPARC_32 Solaris
final StringBuilder toString(StringBuilder sb)
static final StaticConfig findCompatible(final MachineDataInfo md)