# HG changeset patch # User Tom Rodriguez # Date 1441927532 25200 # Node ID f39ccee58e7a2ddee809ad66d1c73a09f0b59e36 # Parent 02fc27dc1da7103e751a69f6c7bef3a6d2ca7116 cleanup GrowableArray sorted find and insert diff -r 02fc27dc1da7 -r f39ccee58e7a src/share/vm/code/debugInfoRec.cpp --- 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(ns); + DIR_Chunk* match = _all_chunks->insert_sorted(ns); if (match != ns) { // Found an existing chunk NOT_PRODUCT(++dir_stats.chunks_shared); diff -r 02fc27dc1da7 -r f39ccee58e7a src/share/vm/code/oopRecorder.cpp --- 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(object, found); + int location = _values.find_sorted(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(); diff -r 02fc27dc1da7 -r f39ccee58e7a src/share/vm/code/oopRecorder.hpp --- 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(); diff -r 02fc27dc1da7 -r f39ccee58e7a src/share/vm/utilities/growableArray.hpp --- 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 E find_insert_binary(E key) { + template E insert_sorted(E& key) { bool found; - int location = find_binary(key, found); + int location = find_sorted(key, found); if (!found) { assert(location <= length(), "out of range"); - insert_binary(location, key); + insert_before(location, key); } return at(location); } - template int find_binary(K key, bool& found) { + template 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).