What's the best way to append an oop to a GrowableArray?
Ioi Lam
ioi.lam at oracle.com
Thu Nov 29 05:56:06 UTC 2018
I have a memory model question:
I need to create lots of objects and append them into a GrowableArray
GrowableArray<oop>* arr = new (ResourceObj::C_HEAP, mtInternal)
GrowableArray<oop>(10000, true);;
void doit() {
while (...) {
oop o = allocate_from_heap(.....);
arr->append(o);
}
}
There is only a single thread that can append to the array, so I am not
using any locks.
However, GC could happen inside this loop, so I have written a do_oops()
function that would scan the array during GC. (For convenience, I am
calling my_oops_do() from within SystemDictionary:oops_do() for now ...).
void my_oops_do(OopClosure* f) {
int len = arr->length();
for (int i = 0; i < len; i++) {
f->do_oop(arr->adr_at(i));
}
}
}
This seems to work fine on my dual socket Xeon, but will it work
everywhere? Do I need to do anything to ensure that the GC threads can
read the up-to-date values of the array elements, and the array length?
Thanks
- Ioi
More information about the hotspot-dev
mailing list