# HG changeset patch # User dbuck # Date 1503329681 14400 # Node ID 16939858a716655165759a306696867ffe8a0c7f # Parent 79d7902dcb958d72ade3a4b19383b61dd1eabd75 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 diff -r 79d7902dcb95 -r 16939858a716 src/share/vm/runtime/jniHandles.cpp --- a/src/share/vm/runtime/jniHandles.cpp Mon Aug 21 05:20:03 2017 -0400 +++ b/src/share/vm/runtime/jniHandles.cpp Mon Aug 21 11:34:41 2017 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2017, 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 @@ -196,8 +196,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; }