accessing unknown value type element in Object[] array & GC barriers
Roland Westrelin
rwestrel at redhat.com
Wed Aug 29 12:02:44 UTC 2018
A question for someone familiar with GC barriers below...
Currently for:
Object array_load(Object[] array) {
return array[0];
}
we roughly emit:
Object array_load(Object[] array) {
if (is_flattened(array)) { deoptimize(); }
return array[0];
}
Same thing for:
void array_store(Object[] array, Object o) {
array[0] = o;
}
roughly emitted as:
void array_store(Object[] array, Object o) {
if (is_flattened(array)) { deoptimize(); }
array[0] = o;
}
Instead we would want:
Object array_load(Object[] array) {
Object v;
if (is_flattened(array)) {
v = array.getComponentType().newInstance();
copy(v, array[0]);
} else {
v = array[0];
}
return v;
}
The first if branch is similar to the clone intrinsic (we're not copying
from an instance but from some flattened array element) so reusing that
machinery is possible (and prototyped). The problem here is that if the
unknown value has oop fields, depending on the gc, barriers might be
needed. In its current state ZGC doesn't support the clone intrinsic and
so we wouldn't support the pattern above with ZGC either.
void array_store(Object[] array, Object o) {
if (is_flattened(array)) {
copy(array[0], o);
post_barrier();
} else {
array[0] = o;
}
}
Again somewhat similar to the clone intrinsic but copy is not to a newly
allocated object so we need a barrier. C2 has some support for non
precise post barrier but I'm unclear what to pass to that barrier for
serial/parallel/CMS or G1: the array oop? &array[0]? Are there cases
where several cards need to be marked?
Other unrelated question: how does the size of the element of a
flattened array compare to the size of value instance? Do they differ or
can we use either one interchangeably?
Roland.
More information about the valhalla-dev
mailing list