6651256: jstack: DeleteGlobalRef method call doesn't lead to descreasing of global refs count shown by jstack
authorminqi
Thu, 23 Jan 2014 09:40:32 -0800
changeset 22530 d1a70d79c50e
parent 22526 a04e9851fb0a
child 22531 f3c6f25d2072
6651256: jstack: DeleteGlobalRef method call doesn't lead to descreasing of global refs count shown by jstack Summary: jni_DeleteGlobalRef does not really release the jni handle, instead, set the handle point to JNIHandles::_deleted_handle which holds an oop instance (java/lang/Object) in Java heap and never be GC'ed. When counting number of global reference, it counts all the handles on the chain list, which includes the already deleted ones. Reviewed-by: zgu, sla, coleenp Contributed-by: yumin.qi@oracle.com
hotspot/src/share/vm/runtime/jniHandles.cpp
--- a/hotspot/src/share/vm/runtime/jniHandles.cpp	Mon Jan 20 09:56:47 2014 +0000
+++ b/hotspot/src/share/vm/runtime/jniHandles.cpp	Thu Jan 23 09:40:32 2014 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -195,8 +195,10 @@
   int _count;
 public:
   CountHandleClosure(): _count(0) {}
-  virtual void do_oop(oop* unused) {
-    _count++;
+  virtual void do_oop(oop* ooph) {
+    if (*ooph != JNIHandles::deleted_handle()) {
+      _count++;
+    }
   }
   virtual void do_oop(narrowOop* unused) { ShouldNotReachHere(); }
   int count() { return _count; }