aboutsummaryrefslogtreecommitdiffstats
path: root/java_jni/jni/jau/MachineDataInfoRuntime.cxx
blob: 647b0c8b6d1027988649b4fb1e116ce4f319016f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

#include <jni.h>

#include <cassert>

#include "jau_sys_MachineDataInfoRuntime.h"

#include "jau/jni/helper_jni.hpp"

#if defined(_WIN32)
    #include <windows.h>
#else /* assume POSIX sysconf() availability */
    #include <unistd.h>
#endif

JNIEXPORT jint JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getPointerSizeInBytesImpl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

    return sizeof(void *);
}

JNIEXPORT jlong JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getPageSizeInBytesImpl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

#if defined(_WIN32)
    SYSTEM_INFO si;
    GetSystemInfo(&si);
    return (jlong) si.dwPageSize;
#else
    return (jlong) sysconf(_SC_PAGESIZE);
#endif
}

typedef struct { 
    int8_t      c1;
    int8_t      v;
} struct_alignment_int8;

typedef struct { 
    int8_t      c1;
    int16_t     v;
} struct_alignment_int16;

typedef struct { 
    int8_t      c1;
    int32_t      v;
} struct_alignment_int32;

typedef struct { 
    int8_t      c1;
    int64_t      v;
} struct_alignment_int64;

typedef struct { 
    int8_t      c1;
    int         v;
} struct_alignment_int;

typedef struct { 
    int8_t      c1;
    long        v;
} struct_alignment_long;

typedef struct { 
    int8_t      c1;
    void *     v;
} struct_alignment_pointer;

typedef struct { 
    int8_t      c1;
    float     v;
} struct_alignment_float;

typedef struct { 
    int8_t      c1;
    double     v;
} struct_alignment_double;

typedef struct { 
    int8_t      c1;
    long double     v;
} struct_alignment_ldouble;

// size_t padding(size_t totalsize, size_t typesize)   { return totalsize - typesize - sizeof(char); }
// static size_t alignment(size_t totalsize, size_t typesize) { return totalsize - typesize; }
#define ALIGNMENT(a, b) ( (a) - (b) )

JNIEXPORT jint JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getAlignmentInt8Impl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

    return ALIGNMENT(sizeof( struct_alignment_int8 ), sizeof(int8_t));
}

JNIEXPORT jint JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getAlignmentInt16Impl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

    return ALIGNMENT(sizeof( struct_alignment_int16 ), sizeof(int16_t));
}

JNIEXPORT jint JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getAlignmentInt32Impl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

    return ALIGNMENT(sizeof( struct_alignment_int32 ), sizeof(int32_t));
}

JNIEXPORT jint JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getAlignmentInt64Impl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

    return ALIGNMENT(sizeof( struct_alignment_int64 ), sizeof(int64_t));
}

JNIEXPORT jint JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getAlignmentIntImpl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

    return ALIGNMENT(sizeof( struct_alignment_int ), sizeof(int));
}

JNIEXPORT jint JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getAlignmentLongImpl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

    return ALIGNMENT(sizeof( struct_alignment_long ), sizeof(long));
}

JNIEXPORT jint JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getAlignmentPointerImpl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

    return ALIGNMENT(sizeof( struct_alignment_pointer ), sizeof(void *));
}

JNIEXPORT jint JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getAlignmentFloatImpl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

    return ALIGNMENT(sizeof( struct_alignment_float ), sizeof(float));
}

JNIEXPORT jint JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getAlignmentDoubleImpl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

    return ALIGNMENT(sizeof( struct_alignment_double ), sizeof(double));
}

JNIEXPORT jint JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getAlignmentLongDoubleImpl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

    return ALIGNMENT(sizeof( struct_alignment_ldouble ), sizeof(long double));
}

JNIEXPORT jint JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getSizeOfIntImpl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

    return sizeof(int);
}

JNIEXPORT jint JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getSizeOfLongImpl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

    return sizeof(long);
}

JNIEXPORT jint JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getSizeOfFloatImpl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

    return sizeof(float);
}

JNIEXPORT jint JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getSizeOfDoubleImpl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

    return sizeof(double);
}

JNIEXPORT jint JNICALL 
Java_jau_sys_MachineDataInfoRuntime_getSizeOfLongDoubleImpl(JNIEnv *env, jclass _unused) {
    (void)env;
    (void)_unused;

    return sizeof(long double);
}