JDK-4725563 : Need JNI call to validate a jobject pointer
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 1.4.1
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2002-08-02
  • Updated: 2017-05-16
  • Resolved: 2004-11-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
JDK 6
6 b13Fixed
Description
Name: pa48320			Date: 08/02/2002

In developing our applications we have found that it is desirable to be able to validate a jobject. The types of validations required are is it a jobject and is it a local ref or a global ref. This should cause no problems with existing APIs as changes have been put in the JNI previously without breaking things.
======================================================================
###@###.### 10/5/04 17:24 GMT

Comments
SUGGESTED FIX From a discussion with the bug submitter, I suggest the following API. It will return one of the following enumerated types. This api will not distinguish between an object that's live or one that has recently been deleted. // Return values from jobjectRefType typedef enum _jobjectType { JNIUnknownRefType = 0, JNILocalRefType = 1, JNIGlobalRefType = 2, JNIWeakGlobalRefType = 3 } jobjectRefType; JNI_LEAF(jobjectRefType, jni_ObjectReferenceType(JNIEnv *env, jobject obj)) JNIWrapper("ObjectReferenceType"); if (JNIHandles::is_local_handle(thread, obj) || JNIHandles::is_frame_handle(thread, obj)) return JNILocalRefType; if (JNIHandles::is_global_handle(obj)) return JNIGlobalRefType; if (JNIHandles::is_weak_global_handle(obj)) return JNIWeakGlobalRefType; return JNIUnknownRefType; JNI_END ###@###.### 10/6/04 15:42 GMT
2004-10-06

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: dragon
2004-08-06

EVALUATION ###@###.### 2002-11-13 This is a perfectly good suggestion. Will try for JDK 1.5 because this involves a specification change. ###@###.### 2003-02-03 I suggest a new JNI method: int HandleType(JNIEnv* env, jobject obj); which examines obj returns 0: obj is not a valid reference. 1: obj is unknown. The JVM cannot determine if obj is a valid reference to an object. 2: obj is not a valid reference. 3: obj is a valid local reference for a thread other than the current thread. 4: obj is a valid local reference for the current thread. 5: obj is a valid strong global reference. 6: obj is a valid weak global reference. ---------------------------------------------------------------------------------- I took a look at what it would take to provide a jni service that Fred Oliver suggested in his evaluation of the bug and I'm concerned about the performance impact of this call. int HandleType(JNIEnv* env, jobject obj); We maintain at least 3 different linked lists of JNI Handles for global, local and weak global references. The overhead of calling into the VM is bad enough but if you had to call this function for each handle that you'd like to delete, I'd be concerned with the performance impact on your applications. So, I have a few questions for the RFE submitter that might help me design a better solution: If I gave you a new service called DeleteHandle(JNIEnv *env, jojbect); Which could accept any type of handle, would this be sufficient? Do you have any idea of the number of handles that you typically create in your application? If I doubled the size of the jni handle object and maintained a type field for each handle, you could have the functionality that you need and you could check the type of handle without calling into the VM. I'm not sure how well this type of solution would go over in the Java technical review committee but it might be worth a try. A jobject would be a pointer to a _jobject structure, something like: struct { void *object; int handle_type; } _jobject; struct _jobject *jobject; We would then add jni.h macros to determine the type of a handle. is_local_ref is_global_reg is_weak_ref etc. ###@###.### 10/5/04 17:24 GMT See suggested fix section for a proposed implementation. ###@###.### 10/6/04 15:42 GMT
4-10-05 00:00:00