Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8264760

JVM crashes when two threads encounter the same resolution error

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b22
    • CPU:
      generic
    • OS:
      generic

      Description

      Reproduce:
       javac Test.java
       java -jar asmtools.jar jcoder Host.jcod
       java Test

      Then in most time (for it is a multithread bug) , we will get the crash :

      #
      # A fatal error has been detected by the Java Runtime Environment:
      #
      # Internal Error (/home/wanghuang/repo/openjdk/jdk/src/hotspot/share/classfile/systemDictionary.cpp:1939), pid=89089, tid=87530
      # assert(entry->nest_host_error() == __null) failed: Nest host error message already set!
      #
      # JRE version: OpenJDK Runtime Environment (17.0) (fastdebug build 17-internal+0-adhoc.wanghuang.jdk)
      # Java VM: OpenJDK 64-Bit Server VM (fastdebug 17-internal+0-adhoc.wuyan.jdk, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-aarch64)
      # Problematic frame:
      # V [libjvm.so+0x16b915c] SystemDictionary::add_nest_host_error(constantPoolHandle const&, int, char const*)+0x114
      #
      # Core dump will be written. Default location: /home/wanghuang/bug/0406/core.%e.89089.%t
      #
      # If you would like to submit a bug report, please visit:
      # https://bugreport.java.com/bugreport/crash.jsp
      #

      The main reason of this crash is this code:

      ``` java
      void SystemDictionary::add_nest_host_error(const constantPoolHandle& pool,
                                                 int which,
                                                 const char* message) {
        unsigned int hash = resolution_errors()->compute_hash(pool, which);
        int index = resolution_errors()->hash_to_index(hash);
        {
          MutexLocker ml(Thread::current(), SystemDictionary_lock);
          ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
          if (entry != NULL) {
            assert(entry->nest_host_error() == NULL, "Nest host error message already set!");
            entry->set_nest_host_error(message);
          } else {
            resolution_errors()->add_entry(index, hash, pool, which, message);
          }
        }
      }
      ```

      This bug will reproduce in two interpret threads(In our case) or compiler threads(if we resolve the classes from compiler thread without interpret thread) executing. Thread A get a `resolution_errors` and called `add_entry`. Thread B will get `entry` from `find_entry` and trigger the assert.

        Attachments

        1. Host.java
          1 kB
        2. Host.jcod
          3 kB
        3. Test.java
          2 kB

          Issue Links

            Activity

              People

              Assignee:
              whuang Wang Huang
              Reporter:
              whuang Wang Huang
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: