mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8224675: Late GC barrier insertion for ZGC
Reviewed-by: roland, eosterlund, pliden
This commit is contained in:
parent
b34b2d993c
commit
75e9d0a290
28 changed files with 1256 additions and 1217 deletions
|
@ -152,6 +152,12 @@ class GenericGrowableArray : public ResourceObj {
|
|||
template<class E> class GrowableArrayIterator;
|
||||
template<class E, class UnaryPredicate> class GrowableArrayFilterIterator;
|
||||
|
||||
template<class E>
|
||||
class CompareClosure : public Closure {
|
||||
public:
|
||||
virtual int do_compare(const E&, const E&) = 0;
|
||||
};
|
||||
|
||||
template<class E> class GrowableArray : public GenericGrowableArray {
|
||||
friend class VMStructs;
|
||||
|
||||
|
@ -443,6 +449,37 @@ template<class E> class GrowableArray : public GenericGrowableArray {
|
|||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
E insert_sorted(CompareClosure<E>* cc, const E& key) {
|
||||
bool found;
|
||||
int location = find_sorted(cc, key, found);
|
||||
if (!found) {
|
||||
insert_before(location, key);
|
||||
}
|
||||
return at(location);
|
||||
}
|
||||
|
||||
template<typename K>
|
||||
int find_sorted(CompareClosure<E>* cc, const K& key, bool& found) {
|
||||
found = false;
|
||||
int min = 0;
|
||||
int max = length() - 1;
|
||||
|
||||
while (max >= min) {
|
||||
int mid = (int)(((uint)max + min) / 2);
|
||||
E value = at(mid);
|
||||
int diff = cc->do_compare(key, value);
|
||||
if (diff > 0) {
|
||||
min = mid + 1;
|
||||
} else if (diff < 0) {
|
||||
max = mid - 1;
|
||||
} else {
|
||||
found = true;
|
||||
return mid;
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
};
|
||||
|
||||
// Global GrowableArray methods (one instance in the library per each 'E' type).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue