JDK-8057799 : G1: Unnecessary NULL check in G1KeepAliveClosure
  • Type: Bug
  • Component: hotspot
  • Sub-Component: gc
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2014-09-08
  • Updated: 2015-06-03
  • Resolved: 2014-09-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u40Fixed 9 b33Fixed
Description
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.