256 }
257 guarantee(InstanceKlass::cast(k)->contains_field_offset(offset),
258 "Bug in native code: jfieldID offset must address interior of object");
259 }
260
261 // Wrapper to trace JNI functions
262
263 #ifdef ASSERT
264 Histogram* JNIHistogram;
265 static volatile int JNIHistogram_lock = 0;
266
267 class JNIHistogramElement : public HistogramElement {
268 public:
269 JNIHistogramElement(const char* name);
270 };
271
272 JNIHistogramElement::JNIHistogramElement(const char* elementName) {
273 _name = elementName;
274 uintx count = 0;
275
276 while (Atomic::cmpxchg(1, &JNIHistogram_lock, 0) != 0) {
277 while (Atomic::load_acquire(&JNIHistogram_lock) != 0) {
278 count +=1;
279 if ( (WarnOnStalledSpinLock > 0)
280 && (count % WarnOnStalledSpinLock == 0)) {
281 warning("JNIHistogram_lock seems to be stalled");
282 }
283 }
284 }
285
286
287 if(JNIHistogram == NULL)
288 JNIHistogram = new Histogram("JNI Call Counts",100);
289
290 JNIHistogram->add_element(this);
291 Atomic::dec(&JNIHistogram_lock);
292 }
293
294 #define JNICountWrapper(arg) \
295 static JNIHistogramElement* e = new JNIHistogramElement(arg); \
296 /* There is a MT-race condition in VC++. So we need to make sure that that e has been initialized */ \
3216 return result;
3217 }
3218
3219 // These lookups are done with the NULL (bootstrap) ClassLoader to
3220 // circumvent any security checks that would be done by jni_FindClass.
3221 JNI_ENTRY(bool, lookupDirectBufferClasses(JNIEnv* env))
3222 {
3223 if ((bufferClass = lookupOne(env, "java/nio/Buffer", thread)) == NULL) { return false; }
3224 if ((directBufferClass = lookupOne(env, "sun/nio/ch/DirectBuffer", thread)) == NULL) { return false; }
3225 if ((directByteBufferClass = lookupOne(env, "java/nio/DirectByteBuffer", thread)) == NULL) { return false; }
3226 return true;
3227 }
3228 JNI_END
3229
3230
3231 static bool initializeDirectBufferSupport(JNIEnv* env, JavaThread* thread) {
3232 if (directBufferSupportInitializeFailed) {
3233 return false;
3234 }
3235
3236 if (Atomic::cmpxchg(1, &directBufferSupportInitializeStarted, 0) == 0) {
3237 if (!lookupDirectBufferClasses(env)) {
3238 directBufferSupportInitializeFailed = 1;
3239 return false;
3240 }
3241
3242 // Make global references for these
3243 bufferClass = (jclass) env->NewGlobalRef(bufferClass);
3244 directBufferClass = (jclass) env->NewGlobalRef(directBufferClass);
3245 directByteBufferClass = (jclass) env->NewGlobalRef(directByteBufferClass);
3246
3247 // Get needed field and method IDs
3248 directByteBufferConstructor = env->GetMethodID(directByteBufferClass, "<init>", "(JI)V");
3249 if (env->ExceptionCheck()) {
3250 env->ExceptionClear();
3251 directBufferSupportInitializeFailed = 1;
3252 return false;
3253 }
3254 directBufferAddressField = env->GetFieldID(bufferClass, "address", "J");
3255 if (env->ExceptionCheck()) {
3256 env->ExceptionClear();
|
256 }
257 guarantee(InstanceKlass::cast(k)->contains_field_offset(offset),
258 "Bug in native code: jfieldID offset must address interior of object");
259 }
260
261 // Wrapper to trace JNI functions
262
263 #ifdef ASSERT
264 Histogram* JNIHistogram;
265 static volatile int JNIHistogram_lock = 0;
266
267 class JNIHistogramElement : public HistogramElement {
268 public:
269 JNIHistogramElement(const char* name);
270 };
271
272 JNIHistogramElement::JNIHistogramElement(const char* elementName) {
273 _name = elementName;
274 uintx count = 0;
275
276 while (Atomic::cmpxchg(&JNIHistogram_lock, 0, 1) != 0) {
277 while (Atomic::load_acquire(&JNIHistogram_lock) != 0) {
278 count +=1;
279 if ( (WarnOnStalledSpinLock > 0)
280 && (count % WarnOnStalledSpinLock == 0)) {
281 warning("JNIHistogram_lock seems to be stalled");
282 }
283 }
284 }
285
286
287 if(JNIHistogram == NULL)
288 JNIHistogram = new Histogram("JNI Call Counts",100);
289
290 JNIHistogram->add_element(this);
291 Atomic::dec(&JNIHistogram_lock);
292 }
293
294 #define JNICountWrapper(arg) \
295 static JNIHistogramElement* e = new JNIHistogramElement(arg); \
296 /* There is a MT-race condition in VC++. So we need to make sure that that e has been initialized */ \
3216 return result;
3217 }
3218
3219 // These lookups are done with the NULL (bootstrap) ClassLoader to
3220 // circumvent any security checks that would be done by jni_FindClass.
3221 JNI_ENTRY(bool, lookupDirectBufferClasses(JNIEnv* env))
3222 {
3223 if ((bufferClass = lookupOne(env, "java/nio/Buffer", thread)) == NULL) { return false; }
3224 if ((directBufferClass = lookupOne(env, "sun/nio/ch/DirectBuffer", thread)) == NULL) { return false; }
3225 if ((directByteBufferClass = lookupOne(env, "java/nio/DirectByteBuffer", thread)) == NULL) { return false; }
3226 return true;
3227 }
3228 JNI_END
3229
3230
3231 static bool initializeDirectBufferSupport(JNIEnv* env, JavaThread* thread) {
3232 if (directBufferSupportInitializeFailed) {
3233 return false;
3234 }
3235
3236 if (Atomic::cmpxchg(&directBufferSupportInitializeStarted, 0, 1) == 0) {
3237 if (!lookupDirectBufferClasses(env)) {
3238 directBufferSupportInitializeFailed = 1;
3239 return false;
3240 }
3241
3242 // Make global references for these
3243 bufferClass = (jclass) env->NewGlobalRef(bufferClass);
3244 directBufferClass = (jclass) env->NewGlobalRef(directBufferClass);
3245 directByteBufferClass = (jclass) env->NewGlobalRef(directByteBufferClass);
3246
3247 // Get needed field and method IDs
3248 directByteBufferConstructor = env->GetMethodID(directByteBufferClass, "<init>", "(JI)V");
3249 if (env->ExceptionCheck()) {
3250 env->ExceptionClear();
3251 directBufferSupportInitializeFailed = 1;
3252 return false;
3253 }
3254 directBufferAddressField = env->GetFieldID(bufferClass, "address", "J");
3255 if (env->ExceptionCheck()) {
3256 env->ExceptionClear();
|