85 // Check for env being the one value appropriate for this thread.
86
87 #define JNI_ENTRY_CHECKED(result_type, header) \
88 extern "C" { \
89 result_type JNICALL header { \
90 JavaThread* thr = (JavaThread*)ThreadLocalStorage::get_thread_slow();\
91 if (thr == NULL || !thr->is_Java_thread()) { \
92 tty->print_cr("%s", fatal_using_jnienv_in_nonjava); \
93 os::abort(true); \
94 } \
95 JNIEnv* xenv = thr->jni_environment(); \
96 if (env != xenv) { \
97 NativeReportJNIFatalError(thr, warn_wrong_jnienv); \
98 } \
99 VM_ENTRY_BASE(result_type, header, thr)
100
101
102 #define UNCHECKED() (unchecked_jni_NativeInterface)
103
104 static const char * warn_wrong_jnienv = "Using JNIEnv in the wrong thread";
105 static const char * warn_bad_class_descriptor = "JNI FindClass received a bad class descriptor \"%s\". A correct class descriptor " \
106 "has no leading \"L\" or trailing \";\". Incorrect descriptors will not be accepted in future releases.";
107 static const char * fatal_using_jnienv_in_nonjava = "FATAL ERROR in native method: Using JNIEnv in non-Java thread";
108 static const char * warn_other_function_in_critical = "Warning: Calling other JNI functions in the scope of " \
109 "Get/ReleasePrimitiveArrayCritical or Get/ReleaseStringCritical";
110 static const char * fatal_bad_ref_to_jni = "Bad global or local ref passed to JNI";
111 static const char * fatal_received_null_class = "JNI received a null class";
112 static const char * fatal_class_not_a_class = "JNI received a class argument that is not a class";
113 static const char * fatal_class_not_a_throwable_class = "JNI Throw or ThrowNew received a class argument that is not a Throwable or Throwable subclass";
114 static const char * fatal_wrong_class_or_method = "Wrong object class or methodID passed to JNI call";
115 static const char * fatal_non_weak_method = "non-weak methodID passed to JNI call";
116 static const char * fatal_unknown_array_object = "Unknown array object passed to JNI array operations";
117 static const char * fatal_object_array_expected = "Object array expected but not received for JNI array operation";
118 static const char * fatal_prim_type_array_expected = "Primitive type array expected but not received for JNI array operation";
119 static const char * fatal_non_array = "Non-array passed to JNI array operations";
120 static const char * fatal_element_type_mismatch = "Array element type mismatch in JNI";
121 static const char * fatal_should_be_static = "Non-static field ID passed to JNI";
122 static const char * fatal_wrong_static_field = "Wrong static field ID passed to JNI";
123 static const char * fatal_static_field_not_found = "Static field not found in JNI get/set field operations";
124 static const char * fatal_static_field_mismatch = "Field type (static) mismatch in JNI get/set field operations";
125 static const char * fatal_should_be_nonstatic = "Static field ID passed to JNI";
467 ASSERT_OOPS_ALLOWED;
468 oop oopObj = jniCheck::validate_handle(thr, obj);
469 if (!oopObj) {
470 ReportJNIFatalError(thr, fatal_bad_ref_to_jni);
471 }
472 return oopObj;
473 }
474
475 // Warn if a class descriptor is in decorated form; class descriptors
476 // passed to JNI findClass should not be decorated unless they are
477 // array descriptors.
478 void jniCheck::validate_class_descriptor(JavaThread* thr, const char* name) {
479 if (name == NULL) return; // implementation accepts NULL so just return
480
481 size_t len = strlen(name);
482
483 if (len >= 2 &&
484 name[0] == JVM_SIGNATURE_CLASS && // 'L'
485 name[len-1] == JVM_SIGNATURE_ENDCLASS ) { // ';'
486 char msg[JVM_MAXPATHLEN];
487 jio_snprintf(msg, JVM_MAXPATHLEN, warn_bad_class_descriptor, name);
488 ReportJNIWarning(thr, msg);
489 }
490 }
491
492 Klass* jniCheck::validate_class(JavaThread* thr, jclass clazz, bool allow_primitive) {
493 ASSERT_OOPS_ALLOWED;
494 oop mirror = jniCheck::validate_handle(thr, clazz);
495 if (!mirror) {
496 ReportJNIFatalError(thr, fatal_received_null_class);
497 }
498
499 if (mirror->klass() != SystemDictionary::Class_klass()) {
500 ReportJNIFatalError(thr, fatal_class_not_a_class);
501 }
502
503 Klass* k = java_lang_Class::as_Klass(mirror);
504 // Make allowances for primitive classes ...
505 if (!(k != NULL || allow_primitive && java_lang_Class::is_primitive(mirror))) {
506 ReportJNIFatalError(thr, fatal_class_not_a_class);
507 }
|
85 // Check for env being the one value appropriate for this thread.
86
87 #define JNI_ENTRY_CHECKED(result_type, header) \
88 extern "C" { \
89 result_type JNICALL header { \
90 JavaThread* thr = (JavaThread*)ThreadLocalStorage::get_thread_slow();\
91 if (thr == NULL || !thr->is_Java_thread()) { \
92 tty->print_cr("%s", fatal_using_jnienv_in_nonjava); \
93 os::abort(true); \
94 } \
95 JNIEnv* xenv = thr->jni_environment(); \
96 if (env != xenv) { \
97 NativeReportJNIFatalError(thr, warn_wrong_jnienv); \
98 } \
99 VM_ENTRY_BASE(result_type, header, thr)
100
101
102 #define UNCHECKED() (unchecked_jni_NativeInterface)
103
104 static const char * warn_wrong_jnienv = "Using JNIEnv in the wrong thread";
105 static const char * warn_bad_class_descriptor1 = "JNI FindClass received a bad class descriptor \"";
106 static const char * warn_bad_class_descriptor2 = "\". A correct class descriptor " \
107 "has no leading \"L\" or trailing \";\". Incorrect descriptors will not be accepted in future releases.";
108 static const char * fatal_using_jnienv_in_nonjava = "FATAL ERROR in native method: Using JNIEnv in non-Java thread";
109 static const char * warn_other_function_in_critical = "Warning: Calling other JNI functions in the scope of " \
110 "Get/ReleasePrimitiveArrayCritical or Get/ReleaseStringCritical";
111 static const char * fatal_bad_ref_to_jni = "Bad global or local ref passed to JNI";
112 static const char * fatal_received_null_class = "JNI received a null class";
113 static const char * fatal_class_not_a_class = "JNI received a class argument that is not a class";
114 static const char * fatal_class_not_a_throwable_class = "JNI Throw or ThrowNew received a class argument that is not a Throwable or Throwable subclass";
115 static const char * fatal_wrong_class_or_method = "Wrong object class or methodID passed to JNI call";
116 static const char * fatal_non_weak_method = "non-weak methodID passed to JNI call";
117 static const char * fatal_unknown_array_object = "Unknown array object passed to JNI array operations";
118 static const char * fatal_object_array_expected = "Object array expected but not received for JNI array operation";
119 static const char * fatal_prim_type_array_expected = "Primitive type array expected but not received for JNI array operation";
120 static const char * fatal_non_array = "Non-array passed to JNI array operations";
121 static const char * fatal_element_type_mismatch = "Array element type mismatch in JNI";
122 static const char * fatal_should_be_static = "Non-static field ID passed to JNI";
123 static const char * fatal_wrong_static_field = "Wrong static field ID passed to JNI";
124 static const char * fatal_static_field_not_found = "Static field not found in JNI get/set field operations";
125 static const char * fatal_static_field_mismatch = "Field type (static) mismatch in JNI get/set field operations";
126 static const char * fatal_should_be_nonstatic = "Static field ID passed to JNI";
468 ASSERT_OOPS_ALLOWED;
469 oop oopObj = jniCheck::validate_handle(thr, obj);
470 if (!oopObj) {
471 ReportJNIFatalError(thr, fatal_bad_ref_to_jni);
472 }
473 return oopObj;
474 }
475
476 // Warn if a class descriptor is in decorated form; class descriptors
477 // passed to JNI findClass should not be decorated unless they are
478 // array descriptors.
479 void jniCheck::validate_class_descriptor(JavaThread* thr, const char* name) {
480 if (name == NULL) return; // implementation accepts NULL so just return
481
482 size_t len = strlen(name);
483
484 if (len >= 2 &&
485 name[0] == JVM_SIGNATURE_CLASS && // 'L'
486 name[len-1] == JVM_SIGNATURE_ENDCLASS ) { // ';'
487 char msg[JVM_MAXPATHLEN];
488 jio_snprintf(msg, JVM_MAXPATHLEN, "%s%s%s",
489 warn_bad_class_descriptor1, name, warn_bad_class_descriptor2);
490 ReportJNIWarning(thr, msg);
491 }
492 }
493
494 Klass* jniCheck::validate_class(JavaThread* thr, jclass clazz, bool allow_primitive) {
495 ASSERT_OOPS_ALLOWED;
496 oop mirror = jniCheck::validate_handle(thr, clazz);
497 if (!mirror) {
498 ReportJNIFatalError(thr, fatal_received_null_class);
499 }
500
501 if (mirror->klass() != SystemDictionary::Class_klass()) {
502 ReportJNIFatalError(thr, fatal_class_not_a_class);
503 }
504
505 Klass* k = java_lang_Class::as_Klass(mirror);
506 // Make allowances for primitive classes ...
507 if (!(k != NULL || allow_primitive && java_lang_Class::is_primitive(mirror))) {
508 ReportJNIFatalError(thr, fatal_class_not_a_class);
509 }
|