diff options
author | Sven Gothel <[email protected]> | 2011-07-17 16:34:39 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-07-17 16:34:39 +0200 |
commit | f733203dfbd034a6b1aa3eb2cd616437c982c435 (patch) | |
tree | 4ace71d4b129870b02f962b714c9dce9f83bc294 /src/native/common | |
parent | ad3dc39ccfddb007c3e91acf454f804573969419 (diff) |
GlueGen proper size / alignment of primitive and compound types usage [1/2] - Preparation.
Currently GlueGen fails for type long (size) and some alignments (see package.html).
- The size and alignment values shall be queried at runtime.
- Compound alignment needs to follow the described natural alignment (also @runtime).
-
- Build
- add Linux Arm7 (EABI)
- junit test
- added compound/struct tests, pointing out the shortcomings of current impl.
- package.html
- Added alignment documentation
- remove intptr.cfg
- add GluGen types int8_t, int16_t, uint8_t, uint16_t
- move MachineDescription* into runtime
- Platform
- has runtime MachineDescription
- moved size, .. to MachineDescription
- use enums for OSType, CPUArch and CPUType defined by os.name/os.arch,
triggering exception if os/arch is not supported.
This avoids Java String comparison and conscious os/arch detection.
- MachineDescription:
- compile time instances MachineDescription32Bits, MachineDescription64Bits
- runtime queried instance MachineDescriptionRuntime
- correct size, alignment, page size, ..
Diffstat (limited to 'src/native/common')
-rw-r--r-- | src/native/common/MachineDescriptionRuntime.c | 174 | ||||
-rw-r--r-- | src/native/common/Platform.c | 29 |
2 files changed, 174 insertions, 29 deletions
diff --git a/src/native/common/MachineDescriptionRuntime.c b/src/native/common/MachineDescriptionRuntime.c new file mode 100644 index 0000000..4cd6088 --- /dev/null +++ b/src/native/common/MachineDescriptionRuntime.c @@ -0,0 +1,174 @@ + +#include <jni.h> + +#include <assert.h> + +#include "jogamp_common_os_MachineDescriptionRuntime.h" + +#if defined(_WIN32) + #include <windows.h> +#else /* assume POSIX sysconf() availability */ + #include <unistd.h> +#endif + +#include <gluegen_stdint.h> + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getPointerSizeInBytesImpl(JNIEnv *env, jclass _unused) { + return sizeof(void *); +} + +JNIEXPORT jlong JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getPageSizeInBytesImpl(JNIEnv *env, jclass _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; + char v; +} struct_alignment_char; + +typedef struct { + int8_t c1; + short v; +} struct_alignment_short; + +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; + +// 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; } + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getAlignmentInt8Impl(JNIEnv *env, jclass _unused) { + return alignment(sizeof( struct_alignment_int8 ), sizeof(int8_t)); +} + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getAlignmentInt16Impl(JNIEnv *env, jclass _unused) { + return alignment(sizeof( struct_alignment_int16 ), sizeof(int16_t)); +} + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getAlignmentInt32Impl(JNIEnv *env, jclass _unused) { + return alignment(sizeof( struct_alignment_int32 ), sizeof(int32_t)); +} + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getAlignmentInt64Impl(JNIEnv *env, jclass _unused) { + return alignment(sizeof( struct_alignment_int64 ), sizeof(int64_t)); +} + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getAlignmentCharImpl(JNIEnv *env, jclass _unused) { + return alignment(sizeof( struct_alignment_char ), sizeof(char)); +} + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getAlignmentShortImpl(JNIEnv *env, jclass _unused) { + return alignment(sizeof( struct_alignment_short ), sizeof(short)); +} + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getAlignmentIntImpl(JNIEnv *env, jclass _unused) { + return alignment(sizeof( struct_alignment_int ), sizeof(int)); +} + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getAlignmentLongImpl(JNIEnv *env, jclass _unused) { + return alignment(sizeof( struct_alignment_long ), sizeof(long)); +} + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getAlignmentPointerImpl(JNIEnv *env, jclass _unused) { + return alignment(sizeof( struct_alignment_pointer ), sizeof(void *)); +} + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getAlignmentFloatImpl(JNIEnv *env, jclass _unused) { + return alignment(sizeof( struct_alignment_float ), sizeof(float)); +} + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getAlignmentDoubleImpl(JNIEnv *env, jclass _unused) { + return alignment(sizeof( struct_alignment_double ), sizeof(double)); +} + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getSizeOfCharImpl(JNIEnv *env, jclass _unused) { + return sizeof(char); +} + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getSizeOfShortImpl(JNIEnv *env, jclass _unused) { + return sizeof(short); +} + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getSizeOfIntImpl(JNIEnv *env, jclass _unused) { + return sizeof(int); +} + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getSizeOfLongImpl(JNIEnv *env, jclass _unused) { + return sizeof(long); +} + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getSizeOfFloatImpl(JNIEnv *env, jclass _unused) { + return sizeof(float); +} + +JNIEXPORT jint JNICALL +Java_jogamp_common_os_MachineDescriptionRuntime_getSizeOfDoubleImpl(JNIEnv *env, jclass _unused) { + return sizeof(double); +} + diff --git a/src/native/common/Platform.c b/src/native/common/Platform.c deleted file mode 100644 index c385e12..0000000 --- a/src/native/common/Platform.c +++ /dev/null @@ -1,29 +0,0 @@ - -#include <jni.h> - -#include <assert.h> - -#include "com_jogamp_common_os_Platform.h" - -#if defined(_WIN32) - #include <windows.h> -#else /* assume POSIX sysconf() availability */ - #include <unistd.h> -#endif - -JNIEXPORT jint JNICALL -Java_com_jogamp_common_os_Platform_getPointerSizeInBitsImpl(JNIEnv *env, jclass _unused) { - return sizeof(void *) * 8; -} - -JNIEXPORT jlong JNICALL -Java_com_jogamp_common_os_Platform_getPageSizeImpl(JNIEnv *env, jclass _unused) { -#if defined(_WIN32) - SYSTEM_INFO si; - GetSystemInfo(&si); - return (jlong) si.dwPageSize; -#else - return (jlong) sysconf(_SC_PAGESIZE); -#endif -} - |