Skip to content
Permalink
Browse files
8212083: Handle remaining gc/lock native code and fix two strings
Migrate code to using wrapping JNI for exceptions

Backport-of: 7afa700
  • Loading branch information
GoeLin committed Nov 29, 2021
1 parent 9e695bb commit ccb0ed39a57b5b4f5a60b22be04fc612109b373c
Showing 28 changed files with 140 additions and 160 deletions.
@@ -23,6 +23,7 @@
#include <jni.h>
#include <stdio.h>
#include <time.h>
#include "ExceptionCheckingJniEnv.hpp"
#include "jni_tools.h"

extern "C" {
@@ -35,7 +36,9 @@ static jfieldID objFieldId = NULL;
* Signature: ([Z)Z
*/
JNIEXPORT jboolean JNICALL Java_nsk_share_gc_lock_jni_BooleanArrayCriticalLocker_criticalNative
(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) {
(JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
ExceptionCheckingJniEnvPtr env(jni_env);

jsize size, i;
jbooleanArray arr;
jboolean *pa;
@@ -44,22 +47,11 @@ JNIEXPORT jboolean JNICALL Java_nsk_share_gc_lock_jni_BooleanArrayCriticalLocker

if (objFieldId == NULL) {
jclass klass = env->GetObjectClass(o);
if (klass == NULL) {
printf("Error: GetObjectClass returned NULL\n");
return JNI_FALSE;
}
objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
if (objFieldId == NULL) {
printf("Error: GetFieldID returned NULL\n");
return JNI_FALSE;
}
}
arr = (jbooleanArray) env->GetObjectField(o, objFieldId);
if (arr == NULL) {
printf("Error: GetObjectField returned NULL\n");
return JNI_FALSE;
}
env->SetObjectField(o, objFieldId, NULL);

size = env->GetArrayLength(arr);
start_time = time(NULL);
enterTime /= 1000;
@@ -23,6 +23,7 @@
#include <jni.h>
#include <stdio.h>
#include <time.h>
#include "ExceptionCheckingJniEnv.hpp"
#include "jni_tools.h"

extern "C" {
@@ -34,7 +35,9 @@ static jfieldID objFieldId = NULL;
* Method: criticalNative
*/
JNIEXPORT jbyte JNICALL Java_nsk_share_gc_lock_jni_ByteArrayCriticalLocker_criticalNative
(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) {
(JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
ExceptionCheckingJniEnvPtr env(jni_env);

jsize size, i;
jbyteArray arr;
jbyte *pa;
@@ -43,22 +46,11 @@ JNIEXPORT jbyte JNICALL Java_nsk_share_gc_lock_jni_ByteArrayCriticalLocker_criti

if (objFieldId == NULL) {
jclass klass = env->GetObjectClass(o);
if (klass == NULL) {
printf("Error: GetObjectClass returned NULL\n");
return 0;
}
objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
if (objFieldId == NULL) {
printf("Error: GetFieldID returned NULL\n");
return 0;
}
}
arr = (jbyteArray) env->GetObjectField(o, objFieldId);
if (arr == NULL) {
printf("Error: GetObjectField returned NULL\n");
return 0;
}
env->SetObjectField(o, objFieldId, NULL);

size = env->GetArrayLength(arr);
start_time = time(NULL);
enterTime /= 1000;
@@ -23,6 +23,7 @@
#include <jni.h>
#include <stdio.h>
#include <time.h>
#include "ExceptionCheckingJniEnv.hpp"
#include "jni_tools.h"

extern "C" {
@@ -35,7 +36,9 @@ static jfieldID objFieldId = NULL;
* Signature: ([Z)Z
*/
JNIEXPORT jchar JNICALL Java_nsk_share_gc_lock_jni_CharArrayCriticalLocker_criticalNative
(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) {
(JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
ExceptionCheckingJniEnvPtr env(jni_env);

jsize size, i;
jcharArray arr;
jchar *pa;
@@ -44,22 +47,11 @@ JNIEXPORT jchar JNICALL Java_nsk_share_gc_lock_jni_CharArrayCriticalLocker_criti

if (objFieldId == NULL) {
jclass klass = env->GetObjectClass(o);
if (klass == NULL) {
printf("Error: GetObjectClass returned NULL\n");
return 0;
}
objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
if (objFieldId == NULL) {
printf("Error: GetFieldID returned NULL\n");
return 0;
}
}
arr = (jcharArray) env->GetObjectField(o, objFieldId);
if (arr == NULL) {
printf("Error: GetObjectField returned NULL\n");
return JNI_FALSE;
}
env->SetObjectField(o, objFieldId, NULL);

size = env->GetArrayLength(arr);
start_time = time(NULL);
current_time = 0;
@@ -23,6 +23,7 @@
#include <jni.h>
#include <stdio.h>
#include <time.h>
#include "ExceptionCheckingJniEnv.hpp"
#include "jni_tools.h"

extern "C" {
@@ -35,7 +36,9 @@ static jfieldID objFieldId = NULL;
* Signature: ([Z)Z
*/
JNIEXPORT jdouble JNICALL Java_nsk_share_gc_lock_jni_DoubleArrayCriticalLocker_criticalNative
(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) {
(JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
ExceptionCheckingJniEnvPtr env(jni_env);

jsize size, i;
jdoubleArray arr;
jdouble *pa;
@@ -44,22 +47,11 @@ JNIEXPORT jdouble JNICALL Java_nsk_share_gc_lock_jni_DoubleArrayCriticalLocker_c

if (objFieldId == NULL) {
jclass klass = env->GetObjectClass(o);
if (klass == NULL) {
printf("Error: GetObjectClass returned NULL\n");
return 0;
}
objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
if (objFieldId == NULL) {
printf("Error: GetFieldID returned NULL\n");
return 0;
}
}
arr = (jdoubleArray) env->GetObjectField(o, objFieldId);
if (arr == NULL) {
printf("Error: GetObjectField returned NULL\n");
return JNI_FALSE;
}
env->SetObjectField(o, objFieldId, NULL);

size = env->GetArrayLength(arr);
start_time = time(NULL);
enterTime /= 1000;
@@ -23,6 +23,7 @@
#include <jni.h>
#include <stdio.h>
#include <time.h>
#include "ExceptionCheckingJniEnv.hpp"
#include "jni_tools.h"

extern "C" {
@@ -35,7 +36,9 @@ static jfieldID objFieldId = NULL;
* Signature: ([Z)Z
*/
JNIEXPORT jfloat JNICALL Java_nsk_share_gc_lock_jni_FloatArrayCriticalLocker_criticalNative
(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) {
(JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
ExceptionCheckingJniEnvPtr env(jni_env);

jsize size, i;
jfloatArray arr;
jfloat *pa;
@@ -44,22 +47,11 @@ JNIEXPORT jfloat JNICALL Java_nsk_share_gc_lock_jni_FloatArrayCriticalLocker_cri

if (objFieldId == NULL) {
jclass klass = env->GetObjectClass(o);
if (klass == NULL) {
printf("Error: GetObjectClass returned NULL\n");
return 0;
}
objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
if (objFieldId == NULL) {
printf("Error: GetFieldID returned NULL\n");
return 0;
}
}
arr = (jfloatArray) env->GetObjectField(o, objFieldId);
if (arr == NULL) {
printf("Error: GetObjectField returned NULL\n");
return JNI_FALSE;
}
env->SetObjectField(o, objFieldId, NULL);

size = env->GetArrayLength(arr);
start_time = time(NULL);
enterTime /= 1000;
@@ -23,6 +23,7 @@
#include <jni.h>
#include <stdio.h>
#include <time.h>
#include "ExceptionCheckingJniEnv.hpp"
#include "jni_tools.h"

extern "C" {
@@ -35,7 +36,9 @@ static jfieldID objFieldId = NULL;
* Signature: ([Z)Z
*/
JNIEXPORT jint JNICALL Java_nsk_share_gc_lock_jni_IntArrayCriticalLocker_criticalNative
(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) {
(JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
ExceptionCheckingJniEnvPtr env(jni_env);

jsize size, i;
jintArray arr;
jint *pa;
@@ -44,22 +47,11 @@ JNIEXPORT jint JNICALL Java_nsk_share_gc_lock_jni_IntArrayCriticalLocker_critica

if (objFieldId == NULL) {
jclass klass = env->GetObjectClass(o);
if (klass == NULL) {
printf("Error: GetObjectClass returned NULL\n");
return 0;
}
objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
if (objFieldId == NULL) {
printf("Error: GetFieldID returned NULL\n");
return 0;
}
}
arr = (jintArray) env->GetObjectField(o, objFieldId);
if (arr == NULL) {
printf("Error: GetObjectField returned NULL\n");
return JNI_FALSE;
}
env->SetObjectField(o, objFieldId, NULL);

size = env->GetArrayLength(arr);
start_time = time(NULL);
enterTime /= 1000;
@@ -23,6 +23,7 @@
#include <jni.h>
#include <stdio.h>
#include <time.h>
#include "ExceptionCheckingJniEnv.hpp"
#include "jni_tools.h"

extern "C" {
@@ -35,7 +36,9 @@ static jfieldID objFieldId = NULL;
* Signature: ([Z)Z
*/
JNIEXPORT jlong JNICALL Java_nsk_share_gc_lock_jni_LongArrayCriticalLocker_criticalNative
(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) {
(JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
ExceptionCheckingJniEnvPtr env(jni_env);

jsize size, i;
jlongArray arr;
jlong *pa;
@@ -44,22 +47,11 @@ JNIEXPORT jlong JNICALL Java_nsk_share_gc_lock_jni_LongArrayCriticalLocker_criti

if (objFieldId == NULL) {
jclass klass = env->GetObjectClass(o);
if (klass == NULL) {
printf("Error: GetObjectClass returned NULL\n");
return 0;
}
objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
if (objFieldId == NULL) {
printf("Error: GetFieldID returned NULL\n");
return 0;
}
}
arr = (jlongArray) env->GetObjectField(o, objFieldId);
if (arr == NULL) {
printf("Error: GetObjectField returned NULL\n");
return JNI_FALSE;
}
env->SetObjectField(o, objFieldId, NULL);

size = env->GetArrayLength(arr);
start_time = time(NULL);
enterTime /= 1000;
@@ -23,6 +23,7 @@
#include <jni.h>
#include <stdio.h>
#include <time.h>
#include "ExceptionCheckingJniEnv.hpp"
#include "jni_tools.h"

extern "C" {
@@ -35,7 +36,9 @@ static jfieldID objFieldId = NULL;
* Signature: ([Z)Z
*/
JNIEXPORT jshort JNICALL Java_nsk_share_gc_lock_jni_ShortArrayCriticalLocker_criticalNative
(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) {
(JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
ExceptionCheckingJniEnvPtr env(jni_env);

jsize size, i;
jshortArray arr;
jshort *pa;
@@ -44,22 +47,11 @@ JNIEXPORT jshort JNICALL Java_nsk_share_gc_lock_jni_ShortArrayCriticalLocker_cri

if (objFieldId == NULL) {
jclass klass = env->GetObjectClass(o);
if (klass == NULL) {
printf("Error: GetObjectClass returned NULL\n");
return 0;
}
objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
if (objFieldId == NULL) {
printf("Error: GetFieldID returned NULL\n");
return 0;
}
}
arr = (jshortArray) env->GetObjectField(o, objFieldId);
if (arr == NULL) {
printf("Error: GetObjectField returned NULL\n");
return JNI_FALSE;
}
env->SetObjectField(o, objFieldId, NULL);

size = env->GetArrayLength(arr);
start_time = time(NULL);
enterTime /= 1000;
@@ -23,6 +23,7 @@
#include <jni.h>
#include <stdio.h>
#include <time.h>
#include "ExceptionCheckingJniEnv.hpp"
#include "jni_tools.h"

extern "C" {
@@ -35,7 +36,9 @@ static jfieldID objFieldId = NULL;
* Signature: ([Z)Z
*/
JNIEXPORT jchar JNICALL Java_nsk_share_gc_lock_jni_StringCriticalLocker_criticalNative
(JNIEnv *env, jobject o, jlong enterTime, jlong sleepTime) {
(JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
ExceptionCheckingJniEnvPtr env(jni_env);

jsize size, i;
jstring str;
const jchar *pa;
@@ -44,22 +47,11 @@ JNIEXPORT jchar JNICALL Java_nsk_share_gc_lock_jni_StringCriticalLocker_critical

if (objFieldId == NULL) {
jclass klass = env->GetObjectClass(o);
if (klass == NULL) {
printf("Error: GetObjectClass returned NULL\n");
return JNI_FALSE;
}
objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
if (objFieldId == NULL) {
printf("Error: GetFieldID returned NULL\n");
return JNI_FALSE;
}
}
str = (jstring) env->GetObjectField(o, objFieldId);
if (str == NULL) {
printf("Error: GetObjectField returned NULL\n");
return JNI_FALSE;
}
env->SetObjectField(o, objFieldId, NULL);

size = env->GetStringLength(str);
start_time = time(NULL);
enterTime /= 1000;
@@ -22,5 +22,6 @@
*/

#include "BooleanArrayCriticalLocker.cpp"
#include "ExceptionCheckingJniEnv.cpp"
#include "jni_tools.cpp"
#include "nsk_tools.cpp"

1 comment on commit ccb0ed3

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on ccb0ed3 Nov 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.