OpenJDK / jdk / jdk
changeset 60076:de18e527b3be
8245021: Adding method 'remove_if_existing' to growableArray.
Reviewed-by: thartmann, neliasso
author | phedlin |
---|---|
date | Tue, 21 Apr 2020 10:35:53 +0200 |
parents | a37f2e2b6fee |
children | a0f6d9504107 |
files | src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp src/hotspot/share/opto/compile.hpp src/hotspot/share/prims/jvmtiRawMonitor.hpp src/hotspot/share/utilities/growableArray.hpp |
diffstat | 4 files changed, 33 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp Mon Jul 06 23:11:37 2020 -0700 +++ b/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp Tue Apr 21 10:35:53 2020 +0200 @@ -65,9 +65,7 @@ } void ShenandoahBarrierSetC2State::remove_enqueue_barrier(ShenandoahEnqueueBarrierNode * n) { - if (_enqueue_barriers->contains(n)) { - _enqueue_barriers->remove(n); - } + _enqueue_barriers->remove_if_existing(n); } int ShenandoahBarrierSetC2State::load_reference_barriers_count() const {
--- a/src/hotspot/share/opto/compile.hpp Mon Jul 06 23:11:37 2020 -0700 +++ b/src/hotspot/share/opto/compile.hpp Tue Apr 21 10:35:53 2020 +0200 @@ -667,23 +667,20 @@ assert(!_macro_nodes->contains(n), "duplicate entry in expand list"); _macro_nodes->append(n); } - void remove_macro_node(Node * n) { - // this function may be called twice for a node so check - // that the node is in the array before attempting to remove it - if (_macro_nodes->contains(n)) - _macro_nodes->remove(n); + void remove_macro_node(Node* n) { + // this function may be called twice for a node so we can only remove it + // if it's still existing. + _macro_nodes->remove_if_existing(n); // remove from _predicate_opaqs list also if it is there - if (predicate_count() > 0 && _predicate_opaqs->contains(n)){ - _predicate_opaqs->remove(n); + if (predicate_count() > 0) { + _predicate_opaqs->remove_if_existing(n); } } - void add_expensive_node(Node * n); - void remove_expensive_node(Node * n) { - if (_expensive_nodes->contains(n)) { - _expensive_nodes->remove(n); - } + void add_expensive_node(Node* n); + void remove_expensive_node(Node* n) { + _expensive_nodes->remove_if_existing(n); } - void add_predicate_opaq(Node * n) { + void add_predicate_opaq(Node* n) { assert(!_predicate_opaqs->contains(n), "duplicate entry in predicate opaque1"); assert(_macro_nodes->contains(n), "should have already been in macro list"); _predicate_opaqs->append(n); @@ -692,9 +689,7 @@ // Range check dependent CastII nodes that can be removed after loop optimizations void add_range_check_cast(Node* n); void remove_range_check_cast(Node* n) { - if (_range_check_casts->contains(n)) { - _range_check_casts->remove(n); - } + _range_check_casts->remove_if_existing(n); } Node* range_check_cast_node(int idx) const { return _range_check_casts->at(idx); } int range_check_cast_count() const { return _range_check_casts->length(); } @@ -703,9 +698,7 @@ void add_opaque4_node(Node* n); void remove_opaque4_node(Node* n) { - if (_opaque4_nodes->contains(n)) { - _opaque4_nodes->remove(n); - } + _opaque4_nodes->remove_if_existing(n); } Node* opaque4_node(int idx) const { return _opaque4_nodes->at(idx); } int opaque4_count() const { return _opaque4_nodes->length(); }
--- a/src/hotspot/share/prims/jvmtiRawMonitor.hpp Mon Jul 06 23:11:37 2020 -0700 +++ b/src/hotspot/share/prims/jvmtiRawMonitor.hpp Tue Apr 21 10:35:53 2020 +0200 @@ -137,12 +137,7 @@ // Return false if monitor is not found in the list. static bool exit(JvmtiRawMonitor* monitor) { - if (monitors()->contains(monitor)) { - monitors()->remove(monitor); - return true; - } else { - return false; - } + return monitors()->remove_if_existing(monitor); } static void transition_raw_monitors();
--- a/src/hotspot/share/utilities/growableArray.hpp Mon Jul 06 23:11:37 2020 -0700 +++ b/src/hotspot/share/utilities/growableArray.hpp Tue Apr 21 10:35:53 2020 +0200 @@ -207,21 +207,31 @@ return -1; } + // Order preserving remove operations. + void remove(const E& elem) { - for (int i = 0; i < _len; i++) { - if (_data[i] == elem) { - for (int j = i + 1; j < _len; j++) _data[j-1] = _data[j]; - _len--; - return; - } - } + // Assuming that element does exist. + bool removed = remove_if_existing(elem); + if (removed) return; ShouldNotReachHere(); } - // The order is preserved. + bool remove_if_existing(const E& elem) { + // Returns TRUE if elem is removed. + for (int i = 0; i < _len; i++) { + if (_data[i] == elem) { + remove_at(i); + return true; + } + } + return false; + } + void remove_at(int index) { assert(0 <= index && index < _len, "illegal index"); - for (int j = index + 1; j < _len; j++) _data[j-1] = _data[j]; + for (int j = index + 1; j < _len; j++) { + _data[j-1] = _data[j]; + } _len--; }