JDK-8279822 : CI: Constant pool entries in error state are not supported
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 11,17,18,19
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2022-01-07
  • Updated: 2022-04-04
  • Resolved: 2022-02-09
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 17 JDK 19
17.0.4-oracleFixed 19 b10Fixed
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)

A DESCRIPTION OF THE PROBLEM :
JVM crashes after some time due to erorr in C2 compiler while processing potentially invalid bytecode.
Flags -XX:-TieredCompilation -Xcomp -Xbatch were used to simplify the test case.

Part of the core dump:
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (ciEnv.cpp:687), pid=1404, tid=4804
#  Error: ShouldNotReachHere()
#
# JRE version: Java(TM) SE Runtime Environment (17.0.1+12) (build 17.0.1+12-LTS-39)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (17.0.1+12-LTS-39, compiled mode, sharing, compressed oops, compressed class ptrs, g1 gc, windows-amd64)
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
#



REGRESSION : Last worked in version 16.0.2

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile a class that contains virtual/static method in it.
Change it's access to be virtual if it was static, and vice versa.
Keep invoking the method till C2 compiler crashes.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JVM does not crash
ACTUAL -
JVM crashes with core dump

---------- BEGIN SOURCE ----------
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Type;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import static org.objectweb.asm.Opcodes.*;

public class CompilerCrash {

  public static void main(String[] args) throws Exception {
    var cw = new ClassWriter(0);
    cw.visit(V17, ACC_PUBLIC, "BadClass", null, "java/lang/Object", null);
    var mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "crash", "()V", null, null);
    mv.visitCode();
    mv.visitLdcInsn(
        new Handle(
            H_INVOKESTATIC,
            "java/lang/Class",
            "cast",
            "(Ljava/lang/Object;)Ljava/lang/Object;",
            false));
    mv.visitLdcInsn(Type.getType(String.class));
    mv.visitLdcInsn("some object");
    mv.visitMethodInsn(
        INVOKEVIRTUAL,
        "java/lang/invoke/MethodHandle",
        "invoke",
        "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
        false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(3, 0);
    byte[] classBytes = cw.toByteArray();
    var loader = new BytesClassLoader("BadClass", classBytes);
    var method = Class.forName("BadClass", true, loader).getMethod("crash");
    for (int i = 0; i < 16000; i++)
      try {
        method.invoke(null);
      } catch (InvocationTargetException ignored) {
      }
  }

  private static final class BytesClassLoader extends ClassLoader {

    private final String name;
    private final byte[] bytes;

    BytesClassLoader(String name, byte[] bytes) {
      this.name = name;
      this.bytes = bytes;
    }

    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
      if (!this.name.equals(name)) {
        throw new ClassNotFoundException(name);
      }
      byte[] bytes = this.bytes;
      return defineClass(name, bytes, 0, bytes.length);
    }
  }
}

---------- END SOURCE ----------

FREQUENCY : always



Comments
Fix Request (17u): Should get backported for parity with 17.0.4-oracle. Applies cleanly, but I had to set the class file version of the test to V17 (like Tobias in his 18u backport). Included test has passed. Nightly tests as well.
02-04-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk17u-dev/pull/334 Date: 2022-04-01 10:34:15 +0000
01-04-2022

Fix Request (JDK 18u) Fixes a ShouldNotReachHere. The fix is low risk and applies cleanly but I had to adapt the class file version of a test. Already tested and about to be backported to Oracle JDK 17u. Tier 1-3 testing is running for JDK 18u.
30-03-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk18u/pull/83 Date: 2022-03-30 05:50:59 +0000
30-03-2022

Changeset: c5c8c064 Author: Vladimir Ivanov <vlivanov@openjdk.org> Date: 2022-02-09 13:56:23 +0000 URL: https://git.openjdk.java.net/jdk/commit/c5c8c0644d9442846de15422285fffeb91c3e0a1
09-02-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/7314 Date: 2022-02-01 19:09:31 +0000
01-02-2022

ILW = Compiler assertion and not recent regression, only when processing potentially invalid bytecode, disable compilation of affected method = HLM = P3
11-01-2022

Additional Information from submitter: =========================== Also happens with C1 compiler without flags.
11-01-2022

Issue is reproduced. OS: Windows 10 JDK 10 : Fail JDK 11 : Fail JDK 17 : Fail JDK 18 ea : Fail hs_err_pid and replay_pid files are attached
11-01-2022