Skip to content

Commit 485194c

Browse files
author
Patric Hedlin
committedApr 21, 2020
8245021: Adding method 'remove_if_existing' to growableArray
Reviewed-by: thartmann, neliasso
1 parent 3d1b1a6 commit 485194c

File tree

4 files changed

+30
-34
lines changed

4 files changed

+30
-34
lines changed
 

‎src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ void ShenandoahBarrierSetC2State::add_enqueue_barrier(ShenandoahEnqueueBarrierNo
6565
}
6666

6767
void ShenandoahBarrierSetC2State::remove_enqueue_barrier(ShenandoahEnqueueBarrierNode * n) {
68-
if (_enqueue_barriers->contains(n)) {
69-
_enqueue_barriers->remove(n);
70-
}
68+
_enqueue_barriers->remove_if_existing(n);
7169
}
7270

7371
int ShenandoahBarrierSetC2State::load_reference_barriers_count() const {

‎src/hotspot/share/opto/compile.hpp

+12-19
Original file line numberDiff line numberDiff line change
@@ -667,23 +667,20 @@ class Compile : public Phase {
667667
assert(!_macro_nodes->contains(n), "duplicate entry in expand list");
668668
_macro_nodes->append(n);
669669
}
670-
void remove_macro_node(Node * n) {
671-
// this function may be called twice for a node so check
672-
// that the node is in the array before attempting to remove it
673-
if (_macro_nodes->contains(n))
674-
_macro_nodes->remove(n);
670+
void remove_macro_node(Node* n) {
671+
// this function may be called twice for a node so we can only remove it
672+
// if it's still existing.
673+
_macro_nodes->remove_if_existing(n);
675674
// remove from _predicate_opaqs list also if it is there
676-
if (predicate_count() > 0 && _predicate_opaqs->contains(n)){
677-
_predicate_opaqs->remove(n);
675+
if (predicate_count() > 0) {
676+
_predicate_opaqs->remove_if_existing(n);
678677
}
679678
}
680-
void add_expensive_node(Node * n);
681-
void remove_expensive_node(Node * n) {
682-
if (_expensive_nodes->contains(n)) {
683-
_expensive_nodes->remove(n);
684-
}
679+
void add_expensive_node(Node* n);
680+
void remove_expensive_node(Node* n) {
681+
_expensive_nodes->remove_if_existing(n);
685682
}
686-
void add_predicate_opaq(Node * n) {
683+
void add_predicate_opaq(Node* n) {
687684
assert(!_predicate_opaqs->contains(n), "duplicate entry in predicate opaque1");
688685
assert(_macro_nodes->contains(n), "should have already been in macro list");
689686
_predicate_opaqs->append(n);
@@ -692,9 +689,7 @@ class Compile : public Phase {
692689
// Range check dependent CastII nodes that can be removed after loop optimizations
693690
void add_range_check_cast(Node* n);
694691
void remove_range_check_cast(Node* n) {
695-
if (_range_check_casts->contains(n)) {
696-
_range_check_casts->remove(n);
697-
}
692+
_range_check_casts->remove_if_existing(n);
698693
}
699694
Node* range_check_cast_node(int idx) const { return _range_check_casts->at(idx); }
700695
int range_check_cast_count() const { return _range_check_casts->length(); }
@@ -703,9 +698,7 @@ class Compile : public Phase {
703698

704699
void add_opaque4_node(Node* n);
705700
void remove_opaque4_node(Node* n) {
706-
if (_opaque4_nodes->contains(n)) {
707-
_opaque4_nodes->remove(n);
708-
}
701+
_opaque4_nodes->remove_if_existing(n);
709702
}
710703
Node* opaque4_node(int idx) const { return _opaque4_nodes->at(idx); }
711704
int opaque4_count() const { return _opaque4_nodes->length(); }

‎src/hotspot/share/prims/jvmtiRawMonitor.hpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,7 @@ class JvmtiPendingMonitors : public AllStatic {
137137

138138
// Return false if monitor is not found in the list.
139139
static bool exit(JvmtiRawMonitor* monitor) {
140-
if (monitors()->contains(monitor)) {
141-
monitors()->remove(monitor);
142-
return true;
143-
} else {
144-
return false;
145-
}
140+
return monitors()->remove_if_existing(monitor);
146141
}
147142

148143
static void transition_raw_monitors();

‎src/hotspot/share/utilities/growableArray.hpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -207,21 +207,31 @@ class GrowableArrayView : public GrowableArrayBase {
207207
return -1;
208208
}
209209

210+
// Order preserving remove operations.
211+
210212
void remove(const E& elem) {
213+
// Assuming that element does exist.
214+
bool removed = remove_if_existing(elem);
215+
if (removed) return;
216+
ShouldNotReachHere();
217+
}
218+
219+
bool remove_if_existing(const E& elem) {
220+
// Returns TRUE if elem is removed.
211221
for (int i = 0; i < _len; i++) {
212222
if (_data[i] == elem) {
213-
for (int j = i + 1; j < _len; j++) _data[j-1] = _data[j];
214-
_len--;
215-
return;
223+
remove_at(i);
224+
return true;
216225
}
217226
}
218-
ShouldNotReachHere();
227+
return false;
219228
}
220229

221-
// The order is preserved.
222230
void remove_at(int index) {
223231
assert(0 <= index && index < _len, "illegal index");
224-
for (int j = index + 1; j < _len; j++) _data[j-1] = _data[j];
232+
for (int j = index + 1; j < _len; j++) {
233+
_data[j-1] = _data[j];
234+
}
225235
_len--;
226236
}
227237

0 commit comments

Comments
 (0)
Please sign in to comment.