The null check in the following code is not necessary:
class G1KeepAliveClosure: public OopClosure {
...
void do_oop(oop* p) {
oop obj = *p;
G1CollectedHeap::in_cset_state_t cset_state = _g1->in_cset_state(obj);
if (obj == NULL || cset_state == G1CollectedHeap::InNeither) {
return;
}
As Thomas pointed out, G1KeepAliveClosure is only called from JNIHandleBlock::weak_oops_do which already filters out NULL values.