changeset 24102:d1a869fb73c2

Performance fix for JNI handle allocation.
author Christian Haeubl <christian.haeubl@oracle.com>
date Tue, 14 Feb 2017 11:10:26 +0100
parents efea6cfade16
children b48ccfe53101
files src/share/vm/runtime/jniHandles.cpp
diffstat 1 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/runtime/jniHandles.cpp	Fri Feb 10 13:07:50 2017 +0100
+++ b/src/share/vm/runtime/jniHandles.cpp	Tue Feb 14 11:10:26 2017 +0100
@@ -420,14 +420,28 @@
     // This is the first allocation or the initial block got zapped when
     // entering a native function. If we have any following blocks they are
     // not valid anymore.
-    for (JNIHandleBlock* current = _next; current != NULL;
-         current = current->_next) {
+    JNIHandleBlock* current = _next;
+    while (current != NULL) {
       assert(current->_last == NULL, "only first block should have _last set");
       assert(current->_free_list == NULL,
              "only first block should have _free_list set");
+
+      // all blocks after the first free block must already be empty
+      if (current->_top == 0) break;
+
       current->_top = 0;
       if (ZapJNIHandleArea) current->zap();
+      
+      current = current->_next;
     }
+
+#ifdef ASSERT
+    while (current != NULL) {
+      assert(current->_top == 0, "all blocks must already have been reset before");
+      current = current->_next;
+    }
+#endif // ASSERT
+
     // Clear initial block
     _free_list = NULL;
     _allocate_before_rebuild = 0;