301
302 size_t JNIHandles::weak_global_handle_memory_usage() {
303 return weak_global_handles()->total_memory_usage();
304 }
305
306
307 // We assume this is called at a safepoint: no lock is needed.
308 void JNIHandles::print_on(outputStream* st) {
309 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
310
311 st->print_cr("JNI global refs: " SIZE_FORMAT ", weak refs: " SIZE_FORMAT,
312 global_handles()->allocation_count(),
313 weak_global_handles()->allocation_count());
314 st->cr();
315 st->flush();
316 }
317
318 class VerifyJNIHandles: public OopClosure {
319 public:
320 virtual void do_oop(oop* root) {
321 (*root)->verify();
322 }
323 virtual void do_oop(narrowOop* root) { ShouldNotReachHere(); }
324 };
325
326 void JNIHandles::verify() {
327 VerifyJNIHandles verify_handle;
328
329 oops_do(&verify_handle);
330
331 // JNI weaks are handled concurrently in ZGC, so they can't be verified here
332 if (!UseZGC) {
333 weak_oops_do(&verify_handle);
334 }
335 }
336
337 // This method is implemented here to avoid circular includes between
338 // jniHandles.hpp and thread.hpp.
339 bool JNIHandles::current_thread_in_native() {
340 Thread* thread = Thread::current();
341 return (thread->is_Java_thread() &&
|
301
302 size_t JNIHandles::weak_global_handle_memory_usage() {
303 return weak_global_handles()->total_memory_usage();
304 }
305
306
307 // We assume this is called at a safepoint: no lock is needed.
308 void JNIHandles::print_on(outputStream* st) {
309 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
310
311 st->print_cr("JNI global refs: " SIZE_FORMAT ", weak refs: " SIZE_FORMAT,
312 global_handles()->allocation_count(),
313 weak_global_handles()->allocation_count());
314 st->cr();
315 st->flush();
316 }
317
318 class VerifyJNIHandles: public OopClosure {
319 public:
320 virtual void do_oop(oop* root) {
321 oopDesc::verify(*root);
322 }
323 virtual void do_oop(narrowOop* root) { ShouldNotReachHere(); }
324 };
325
326 void JNIHandles::verify() {
327 VerifyJNIHandles verify_handle;
328
329 oops_do(&verify_handle);
330
331 // JNI weaks are handled concurrently in ZGC, so they can't be verified here
332 if (!UseZGC) {
333 weak_oops_do(&verify_handle);
334 }
335 }
336
337 // This method is implemented here to avoid circular includes between
338 // jniHandles.hpp and thread.hpp.
339 bool JNIHandles::current_thread_in_native() {
340 Thread* thread = Thread::current();
341 return (thread->is_Java_thread() &&
|