Mon, 21 Aug 2017 11:34:41 -0400
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
src/share/vm/runtime/jniHandles.cpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/runtime/jniHandles.cpp Mon Aug 21 05:20:03 2017 -0400 1.2 +++ b/src/share/vm/runtime/jniHandles.cpp Mon Aug 21 11:34:41 2017 -0400 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -196,8 +196,10 @@ 1.11 int _count; 1.12 public: 1.13 CountHandleClosure(): _count(0) {} 1.14 - virtual void do_oop(oop* unused) { 1.15 - _count++; 1.16 + virtual void do_oop(oop* ooph) { 1.17 + if (*ooph != JNIHandles::deleted_handle()) { 1.18 + _count++; 1.19 + } 1.20 } 1.21 virtual void do_oop(narrowOop* unused) { ShouldNotReachHere(); } 1.22 int count() { return _count; }