JDK-8039150 : host_klass invariant fails when verifying newly loaded JSR-292 anonymous classes
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 8u20,9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2014-04-03
  • Updated: 2015-01-21
  • Resolved: 2014-06-18
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
8u20Fixed 9 b22Fixed
Description
At the end of ClassFileParser::parseClassFile, we do:

  instanceKlassHandle this_klass (THREAD, preserve_this_klass);
  debug_only(this_klass->verify();)

Looking at the end of instanceKlass::verify_on (which is being called by Klass::verify):
  
  const Klass* host = host_klass();
  if (host != NULL) {
    guarantee(host->is_klass(), "should be klass");
  }

InstanceKlass::host_klass() has the following implementation:

  Klass* host_klass() const              {
    Klass** hk = (Klass**)adr_host_klass();
    if (hk == NULL) {
      return NULL;
    } else {
      assert(*hk != NULL, "host klass should always be set if the address is not null");
      return *hk;
    }
  }

  
When loading a JSR-292 anonymous klass, ard_host_klass() will return a non-NULL value. But, since the Klass is allocated in Metaspace and Metaspace initialises all memory to NULL,*hk will be NULL and the assert will fail.

To trigger this code path, the following if statement (which is at the beginning of InstanceKlass::verify_on) must fail (since otherwise we won't do any verification):

#ifndef PRODUCT
  // Avoid redundant verifies, this really should be in product.
  if (_verify_count == Universe::verify_count()) return;
#endif

Universe::verify_count is unfortunately zero by default and so is _verify_count. You must also load a JSR-292 anonymous class since they are the only classes with a host_klass.

One possible fix is to simple do:
  
  this_klass->set_host_klass(host_klass)

before calling debug_only(this_klass->verify()).
Comments
SQE is OK with fixing this in 8u20
24-06-2014

Need SQE-OK prior to approval
24-06-2014

Also ran into this on both 8u20 and 9. Can easily be provoked when running dacapo2006, specjbb200 and specjbb2005 with -XX:+VerifyAfterGC. Adding 8u20 to the affected versions and resetting the bug so that it can be triaged properly.
17-06-2014

Log file for eclipse run.
27-05-2014

Also occurs when just running dacapo bach 9.12 eclipse with VerifyAfter/BeforeGC: -Xmx128M -XX:+VerifyBeforeGC -XX:+VerifyAfterGC -jar dacapo.jar eclipse
27-05-2014

Thanks to Andreas Sj��berg for finding this bug!
03-04-2014