changeset 22549:f39ccee58e7a

cleanup GrowableArray sorted find and insert
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Thu, 10 Sep 2015 16:25:32 -0700
parents 02fc27dc1da7
children 94ba89d56936
files src/share/vm/code/debugInfoRec.cpp src/share/vm/code/oopRecorder.cpp src/share/vm/code/oopRecorder.hpp src/share/vm/utilities/growableArray.hpp
diffstat 4 files changed, 10 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/code/debugInfoRec.cpp	Wed Sep 09 17:56:30 2015 -0700
+++ b/src/share/vm/code/debugInfoRec.cpp	Thu Sep 10 16:25:32 2015 -0700
@@ -85,7 +85,7 @@
   }
 
 #if INCLUDE_JVMCI
-  static int compare(DIR_Chunk* a, DIR_Chunk* b) {
+  static int compare(DIR_Chunk*& a, DIR_Chunk*& b) {
     if (b->_hash > a->_hash) {
       return 1;
     }
@@ -278,7 +278,7 @@
   DIR_Chunk* ns = new(this) DIR_Chunk(stream_offset, stream_length, this);
 
 #if INCLUDE_JVMCI
-  DIR_Chunk* match = _all_chunks->find_insert_binary<DIR_Chunk::compare>(ns);
+  DIR_Chunk* match = _all_chunks->insert_sorted<DIR_Chunk::compare>(ns);
   if (match != ns) {
     // Found an existing chunk
     NOT_PRODUCT(++dir_stats.chunks_shared);
--- a/src/share/vm/code/oopRecorder.cpp	Wed Sep 09 17:56:30 2015 -0700
+++ b/src/share/vm/code/oopRecorder.cpp	Thu Sep 10 16:25:32 2015 -0700
@@ -181,7 +181,7 @@
   return sort_by_address(a->oop_value(), b->oop_value());
 }
 
-int ObjectLookup::sort_oop_by_address(oop a, ObjectEntry b) {
+int ObjectLookup::sort_oop_by_address(oop& a, ObjectEntry& b) {
   return sort_by_address(a, b.oop_value());
 }
   
@@ -192,12 +192,12 @@
   oop object = JNIHandles::resolve(handle);
   maybe_resort();
   bool found;
-  int location = _values.find_binary<oop, sort_oop_by_address>(object, found);
+  int location = _values.find_sorted<oop, sort_oop_by_address>(object, found);
   if (!found) {
     assert(location <= _values.length(), "out of range");
     jobject handle = JNIHandles::make_local(object);
     ObjectEntry r(handle, oop_recorder->allocate_oop_index(handle));
-    _values.insert_binary(location, r);
+    _values.insert_before(location, r);
     return r.index();
   }
   return _values.at(location).index();
--- a/src/share/vm/code/oopRecorder.hpp	Wed Sep 09 17:56:30 2015 -0700
+++ b/src/share/vm/code/oopRecorder.hpp	Thu Sep 10 16:25:32 2015 -0700
@@ -168,7 +168,7 @@
   // Utility sort functions
   static int sort_by_address(oop a, oop b);
   static int sort_by_address(ObjectEntry* a, ObjectEntry* b);
-  static int sort_oop_by_address(oop a, ObjectEntry b);
+  static int sort_oop_by_address(oop& a, ObjectEntry& b);
 
  public:
   ObjectLookup();
--- a/src/share/vm/utilities/growableArray.hpp	Wed Sep 09 17:56:30 2015 -0700
+++ b/src/share/vm/utilities/growableArray.hpp	Thu Sep 10 16:25:32 2015 -0700
@@ -377,17 +377,17 @@
   // matching key according to the static compare function.  Insert
   // that element is not already in the list.  Assumes the list is
   // already sorted according to compare function.
-  template <int compare(E, E)> E find_insert_binary(E key) {
+  template <int compare(E&, E&)> E insert_sorted(E& key) {
     bool found;
-    int location = find_binary<E, compare>(key, found);
+    int location = find_sorted<E, compare>(key, found);
     if (!found) {
       assert(location <= length(), "out of range");
-      insert_binary(location, key);
+      insert_before(location, key);
     }
     return at(location);
   }
 
-  template <typename K, int compare(K, E)> int find_binary(K key, bool& found) {
+  template <typename K, int compare(K&, E&)> int find_sorted(K& key, bool& found) {
     found = false;
     int min = 0;
     int max = length() - 1;
@@ -407,21 +407,6 @@
     }
     return min;
   }
-
-  // Insert a new element at location, moving values as needed.
-  void insert_binary(int location, E element) {
-    int len = length();
-    if (len == location) {
-      append(element);
-    } else {
-      append(at(len-1));
-      int pos;
-      for (pos = len-2; pos >= location; pos--) {
-        at_put(pos+1, at(pos));
-      }
-      at_put(location, element);
-    }
-  }
 };
 
 // Global GrowableArray methods (one instance in the library per each 'E' type).