jaulib v1.3.0
Jau Support Library (C++, Java, ..)
MachineDataInfoRuntime.java
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2021 Gothel Software e.K.
4 * Copyright (c) 2010 Gothel Software e.K.
5 * Copyright (c) 2010 JogAmp Community.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27package jau.sys;
28
29import org.jau.sys.PlatformProps;
30import org.jau.sys.MachineDataInfo;
31import org.jau.sys.RuntimeProps;
32
33/**
34 * Runtime operations of {@link MachineDataInfo}.
35 */
37
38 static volatile boolean initialized = false;
39 static volatile MachineDataInfo runtimeMD = null;
40 static volatile MachineDataInfo.StaticConfig staticMD = null;
41
42 public static void initialize() {
43 if( !initialized ) {
44 synchronized(MachineDataInfo.class) { // volatile dbl-checked-locking OK
45 if( !initialized ) {
47
48 final MachineDataInfo runtimeMD = getRuntimeImpl();
49 final MachineDataInfo.StaticConfig staticMD = MachineDataInfo.StaticConfig.findCompatible(runtimeMD);
50 if( null == staticMD ) {
51 throw new RuntimeException("No compatible MachineDataInfo.StaticConfig for runtime:"+PlatformProps.NEWLINE+runtimeMD);
52 }
53 if( !staticMD.md.compatible(runtimeMD) ) {
54 throw new RuntimeException("Incompatible MachineDataInfo:"+PlatformProps.NEWLINE+
55 " Static "+staticMD+PlatformProps.NEWLINE+
56 " Runtime "+runtimeMD);
57 }
58 MachineDataInfoRuntime.runtimeMD = runtimeMD;
59 MachineDataInfoRuntime.staticMD = staticMD;
60 initialized=true;
61 if( PlatformProps.DEBUG ) {
62 System.err.println("MachineDataInfoRuntime.initialize():"+PlatformProps.NEWLINE+
63 " Static "+staticMD+PlatformProps.NEWLINE+
64 " Runtime "+runtimeMD);
65 }
66 return;
67 }
68 }
69 }
70 throw new InternalError("Already initialized");
71 }
72 /**
73 * The static {@link MachineDataInfo} is utilized for high performance
74 * precompiled size, offset, etc table lookup within generated structures
75 * using the {@link MachineDataInfo.StaticConfig} index.
76 */
77 public static MachineDataInfo.StaticConfig getStatic() {
78 if(!initialized) {
79 synchronized(MachineDataInfo.class) { // volatile dbl-checked-locking OK
80 if(!initialized) {
81 throw new InternalError("Not set");
82 }
83 }
84 }
85 return staticMD;
86 }
87 public static MachineDataInfo getRuntime() {
88 if(!initialized) {
89 synchronized(MachineDataInfo.class) { // volatile dbl-checked-locking OK
90 if(!initialized) {
91 throw new InternalError("Not set");
92 }
93 }
94 }
95 return runtimeMD;
96 }
97
98 private static MachineDataInfo getRuntimeImpl() {
99 try {
101 } catch (final Throwable err) {
102 return null;
103 }
104
105 final int pointerSizeInBytes = getPointerSizeInBytesImpl();
106 switch(pointerSizeInBytes) {
107 case 4:
108 case 8:
109 break;
110 default:
111 throw new RuntimeException("Unsupported pointer size "+pointerSizeInBytes+"bytes, please implement.");
112 }
113
114 final long pageSizeL = getPageSizeInBytesImpl();
115 if(Integer.MAX_VALUE < pageSizeL) {
116 throw new InternalError("PageSize exceeds integer value: " + pageSizeL);
117 }
118
119 // size: int, long, float, double, pointer, pageSize
120 // alignment: int8, int16, int32, int64, int, long, float, double, pointer
121 return new MachineDataInfo(
122 true /* runtime validated */,
123
124 getSizeOfIntImpl(), getSizeOfLongImpl(),
125 getSizeOfFloatImpl(), getSizeOfDoubleImpl(), getSizeOfLongDoubleImpl(),
126 pointerSizeInBytes, (int)pageSizeL,
127
128 getAlignmentInt8Impl(), getAlignmentInt16Impl(), getAlignmentInt32Impl(), getAlignmentInt64Impl(),
129 getAlignmentIntImpl(), getAlignmentLongImpl(),
130 getAlignmentFloatImpl(), getAlignmentDoubleImpl(), getAlignmentLongDoubleImpl(),
131 getAlignmentPointerImpl());
132 }
133
134 private static native int getPointerSizeInBytesImpl();
135 private static native long getPageSizeInBytesImpl();
136
137 private static native int getAlignmentInt8Impl();
138 private static native int getAlignmentInt16Impl();
139 private static native int getAlignmentInt32Impl();
140 private static native int getAlignmentInt64Impl();
141 private static native int getAlignmentIntImpl();
142 private static native int getAlignmentLongImpl();
143 private static native int getAlignmentPointerImpl();
144 private static native int getAlignmentFloatImpl();
145 private static native int getAlignmentDoubleImpl();
146 private static native int getAlignmentLongDoubleImpl();
147 private static native int getSizeOfIntImpl();
148 private static native int getSizeOfLongImpl();
149 private static native int getSizeOfPointerImpl();
150 private static native int getSizeOfFloatImpl();
151 private static native int getSizeOfDoubleImpl();
152 private static native int getSizeOfLongDoubleImpl();
153}
154
Runtime operations of MachineDataInfo.
static MachineDataInfo.StaticConfig getStatic()
The static MachineDataInfo is utilized for high performance precompiled size, offset,...
Machine data description for alignment and size onle, see com.jogamp.gluegen.
Platform Properties derived from Java properties.
static final boolean DEBUG
static final String NEWLINE
Runtime platform properties derived from PlatformProps and runtime query.
Static enumeration of MachineDataInfo instances used for high performance data size and alignment loo...
static final StaticConfig findCompatible(final MachineDataInfo md)
static final void validateUniqueMachineDataInfo()
Static's MachineDataInfo shall be unique by the compatible criteria.