Skip to content

Commit

Permalink
8245021: Adding method 'remove_if_existing' to growableArray
Browse files Browse the repository at this point in the history
Reviewed-by: thartmann, neliasso
  • Loading branch information
Patric Hedlin committed Apr 21, 2020
1 parent 3d1b1a6 commit 485194c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 34 deletions.
Expand Up @@ -65,9 +65,7 @@ void ShenandoahBarrierSetC2State::add_enqueue_barrier(ShenandoahEnqueueBarrierNo
} }


void ShenandoahBarrierSetC2State::remove_enqueue_barrier(ShenandoahEnqueueBarrierNode * n) { void ShenandoahBarrierSetC2State::remove_enqueue_barrier(ShenandoahEnqueueBarrierNode * n) {
if (_enqueue_barriers->contains(n)) { _enqueue_barriers->remove_if_existing(n);
_enqueue_barriers->remove(n);
}
} }


int ShenandoahBarrierSetC2State::load_reference_barriers_count() const { int ShenandoahBarrierSetC2State::load_reference_barriers_count() const {
Expand Down
31 changes: 12 additions & 19 deletions src/hotspot/share/opto/compile.hpp
Expand Up @@ -667,23 +667,20 @@ class Compile : public Phase {
assert(!_macro_nodes->contains(n), "duplicate entry in expand list"); assert(!_macro_nodes->contains(n), "duplicate entry in expand list");
_macro_nodes->append(n); _macro_nodes->append(n);
} }
void remove_macro_node(Node * n) { void remove_macro_node(Node* n) {
// this function may be called twice for a node so check // this function may be called twice for a node so we can only remove it
// that the node is in the array before attempting to remove it // if it's still existing.
if (_macro_nodes->contains(n)) _macro_nodes->remove_if_existing(n);
_macro_nodes->remove(n);
// remove from _predicate_opaqs list also if it is there // remove from _predicate_opaqs list also if it is there
if (predicate_count() > 0 && _predicate_opaqs->contains(n)){ if (predicate_count() > 0) {
_predicate_opaqs->remove(n); _predicate_opaqs->remove_if_existing(n);
} }
} }
void add_expensive_node(Node * n); void add_expensive_node(Node* n);
void remove_expensive_node(Node * n) { void remove_expensive_node(Node* n) {
if (_expensive_nodes->contains(n)) { _expensive_nodes->remove_if_existing(n);
_expensive_nodes->remove(n);
}
} }
void add_predicate_opaq(Node * n) { void add_predicate_opaq(Node* n) {
assert(!_predicate_opaqs->contains(n), "duplicate entry in predicate opaque1"); assert(!_predicate_opaqs->contains(n), "duplicate entry in predicate opaque1");
assert(_macro_nodes->contains(n), "should have already been in macro list"); assert(_macro_nodes->contains(n), "should have already been in macro list");
_predicate_opaqs->append(n); _predicate_opaqs->append(n);
Expand All @@ -692,9 +689,7 @@ class Compile : public Phase {
// Range check dependent CastII nodes that can be removed after loop optimizations // Range check dependent CastII nodes that can be removed after loop optimizations
void add_range_check_cast(Node* n); void add_range_check_cast(Node* n);
void remove_range_check_cast(Node* n) { void remove_range_check_cast(Node* n) {
if (_range_check_casts->contains(n)) { _range_check_casts->remove_if_existing(n);
_range_check_casts->remove(n);
}
} }
Node* range_check_cast_node(int idx) const { return _range_check_casts->at(idx); } 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(); } int range_check_cast_count() const { return _range_check_casts->length(); }
Expand All @@ -703,9 +698,7 @@ class Compile : public Phase {


void add_opaque4_node(Node* n); void add_opaque4_node(Node* n);
void remove_opaque4_node(Node* n) { void remove_opaque4_node(Node* n) {
if (_opaque4_nodes->contains(n)) { _opaque4_nodes->remove_if_existing(n);
_opaque4_nodes->remove(n);
}
} }
Node* opaque4_node(int idx) const { return _opaque4_nodes->at(idx); } Node* opaque4_node(int idx) const { return _opaque4_nodes->at(idx); }
int opaque4_count() const { return _opaque4_nodes->length(); } int opaque4_count() const { return _opaque4_nodes->length(); }
Expand Down
7 changes: 1 addition & 6 deletions src/hotspot/share/prims/jvmtiRawMonitor.hpp
Expand Up @@ -137,12 +137,7 @@ class JvmtiPendingMonitors : public AllStatic {


// Return false if monitor is not found in the list. // Return false if monitor is not found in the list.
static bool exit(JvmtiRawMonitor* monitor) { static bool exit(JvmtiRawMonitor* monitor) {
if (monitors()->contains(monitor)) { return monitors()->remove_if_existing(monitor);
monitors()->remove(monitor);
return true;
} else {
return false;
}
} }


static void transition_raw_monitors(); static void transition_raw_monitors();
Expand Down
22 changes: 16 additions & 6 deletions src/hotspot/share/utilities/growableArray.hpp
Expand Up @@ -207,21 +207,31 @@ class GrowableArrayView : public GrowableArrayBase {
return -1; return -1;
} }


// Order preserving remove operations.

void remove(const E& elem) { void remove(const E& elem) {
// Assuming that element does exist.
bool removed = remove_if_existing(elem);
if (removed) return;
ShouldNotReachHere();
}

bool remove_if_existing(const E& elem) {
// Returns TRUE if elem is removed.
for (int i = 0; i < _len; i++) { for (int i = 0; i < _len; i++) {
if (_data[i] == elem) { if (_data[i] == elem) {
for (int j = i + 1; j < _len; j++) _data[j-1] = _data[j]; remove_at(i);
_len--; return true;
return;
} }
} }
ShouldNotReachHere(); return false;
} }


// The order is preserved.
void remove_at(int index) { void remove_at(int index) {
assert(0 <= index && index < _len, "illegal 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--; _len--;
} }


Expand Down

0 comments on commit 485194c

Please sign in to comment.