aboutsummaryrefslogtreecommitdiffstats
path: root/java_jni/jni/jau
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-01-02 01:38:49 +0100
committerSven Gothel <[email protected]>2023-01-02 01:38:49 +0100
commit72078b1948e3b8aa12f0a598631218341a8b9970 (patch)
treea6e5e6723b5e15609bec593481062390e79cc594 /java_jni/jni/jau
parentbe182521054eebeccddf5b11221e23b7c0bdb6fd (diff)
Bug 574: Java_org_jau_sys_Clock_get[Monotonic|WallClock]TimeImpl(): Avoid GetPrimitiveArrayCritical(), which occasionally hangs on system call ::clock_gettime()
Resolves Bug 574, detected via Java application utilizing Cypherpack on RPI4 arm64.
Diffstat (limited to 'java_jni/jni/jau')
-rw-r--r--java_jni/jni/jau/jau_sys_Clock.cxx34
1 files changed, 14 insertions, 20 deletions
diff --git a/java_jni/jni/jau/jau_sys_Clock.cxx b/java_jni/jni/jau/jau_sys_Clock.cxx
index 0e845f3..dde56de 100644
--- a/java_jni/jni/jau/jau_sys_Clock.cxx
+++ b/java_jni/jni/jau/jau_sys_Clock.cxx
@@ -44,19 +44,16 @@ void Java_org_jau_sys_Clock_getMonotonicTimeImpl(JNIEnv *env, jclass clazz, jlon
if( nullptr == jval ) {
throw jau::IllegalArgumentException("val null", E_FILE_LINE);
}
- const size_t in_size = env->GetArrayLength(jval);
- if( 2 > in_size ) {
- throw jau::IllegalArgumentException("val size "+std::to_string(in_size)+" < 2", E_FILE_LINE);
- }
- jau::jni::JNICriticalArray<int64_t, jlongArray> criticalArray(env); // RAII - release
- int64_t * val_ptr = criticalArray.get(jval, criticalArray.Mode::UPDATE_AND_RELEASE);
- if( nullptr == val_ptr ) {
- throw jau::InternalError("GetPrimitiveArrayCritical(address val array) is null", E_FILE_LINE);
+ const size_t jval_size = env->GetArrayLength(jval);
+ if( 2 > jval_size ) {
+ throw jau::IllegalArgumentException("val size "+std::to_string(jval_size)+" < 2", E_FILE_LINE);
}
+ // Avoid GetPrimitiveArrayCritical(), which occasionally hangs on system call ::clock_gettime()
struct timespec t { 0, 0 };
::clock_gettime(CLOCK_MONOTONIC, &t);
- val_ptr[0] = (int64_t)t.tv_sec;
- val_ptr[1] = (int64_t)t.tv_nsec;
+ const jlong val[] = { (jlong)t.tv_sec, (jlong)t.tv_nsec };
+ env->SetLongArrayRegion(jval, 0, (jsize)jval_size, val);
+ jau::jni::java_exception_check_and_throw(env, E_FILE_LINE);
} catch(...) {
rethrow_and_raise_java_exception_jau(env);
}
@@ -68,19 +65,16 @@ void Java_org_jau_sys_Clock_getWallClockTimeImpl(JNIEnv *env, jclass clazz, jlon
if( nullptr == jval ) {
throw jau::IllegalArgumentException("val null", E_FILE_LINE);
}
- const size_t in_size = env->GetArrayLength(jval);
- if( 2 > in_size ) {
- throw jau::IllegalArgumentException("val size "+std::to_string(in_size)+" < 2", E_FILE_LINE);
- }
- jau::jni::JNICriticalArray<int64_t, jlongArray> criticalArray(env); // RAII - release
- int64_t * val_ptr = criticalArray.get(jval, criticalArray.Mode::UPDATE_AND_RELEASE);
- if( nullptr == val_ptr ) {
- throw jau::InternalError("GetPrimitiveArrayCritical(address val array) is null", E_FILE_LINE);
+ const size_t jval_size = env->GetArrayLength(jval);
+ if( 2 > jval_size ) {
+ throw jau::IllegalArgumentException("val size "+std::to_string(jval_size)+" < 2", E_FILE_LINE);
}
+ // Avoid GetPrimitiveArrayCritical(), which occasionally hangs on system call ::clock_gettime()
struct timespec t { 0, 0 };
::clock_gettime(CLOCK_REALTIME, &t);
- val_ptr[0] = (int64_t)t.tv_sec;
- val_ptr[1] = (int64_t)t.tv_nsec;
+ const jlong val[] = { (jlong)t.tv_sec, (jlong)t.tv_nsec };
+ env->SetLongArrayRegion(jval, 0, (jsize)jval_size, val);
+ jau::jni::java_exception_check_and_throw(env, E_FILE_LINE);
} catch(...) {
rethrow_and_raise_java_exception_jau(env);
}