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

Event NativeLibraryLoad breaks invariant by taking a stacktrace when thread is in state _thread_in_native

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 22
    • 22
    • hotspot
    • None
    • jfr
    • b15

    Description

      prims/jvm.cpp:

      JVM_ENTRY_NO_ENV(void*, JVM_LoadLibrary(const char* name, jboolean throwException))
        //%note jvm_ct
        char ebuf[1024];
        void *load_result;
        {
          ThreadToNativeFromVM ttnfvm(thread); // <-- This construct has the thread enter _thread_in_native.
          load_result = os::dll_load(name, ebuf, sizeof ebuf);
        }

      A thread running in state _thread_in_native cannot capture a stack trace, because tagging of artefacts (klasses, methods etc.) is a function of an epoch, which evolves during safepoints.

      In addition, for virtual threads, this can lead to assertions in the Access API, such as the following:

      # A fatal error has been detected by the Java Runtime Environment:
      #
      # Internal Error (/workspace/open/src/hotspot/share/oops/accessBackend.cpp:224), pid=77881, tid=86379
      # assert(state == _thread_in_vm || state == _thread_in_Java || state == _thread_new) failed: Wrong thread state for accesses: 4

      Current thread (0x0000000124c59a10): JavaThread "ForkJoinPool-1-worker-22" daemon [_thread_in_native, id=86379, stack(0x0000000174900000,0x0000000174b03000) (2060K)]

      Stack: [0x0000000174900000,0x0000000174b03000], sp=0x0000000174affbb0, free space=2046k
      Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
      V [libjvm.dylib+0x13cccc0] VMError::report_and_die(int, char const*, char const*, char*, Thread*, unsigned char*, void*, void*, char const*, int, unsigned long)+0x4bc (accessBackend.cpp:224)
      V [libjvm.dylib+0x13cd668] VMError::report_and_die(Thread*, void*, char const*, int, char const*, char const*, char*)+0x40
      V [libjvm.dylib+0x6bbbcc] report_vm_error(char const*, int, char const*, char const*, ...)+0x6c
      V [libjvm.dylib+0x92f8] AccessInternal::check_access_thread_state()+0x11c
      V [libjvm.dylib+0x34ccc4] oopDesc::obj_field(int) const+0x164
      V [libjvm.dylib+0x6693c8] ContinuationWrapper::read()+0x80
      V [libjvm.dylib+0x669204] ContinuationWrapper::ContinuationWrapper(oop)+0x12c
      V [libjvm.dylib+0x666fdc] Continuation::top_frame(frame const&, RegisterMap*)+0x170
      V [libjvm.dylib+0x38e3fc] frame::sender_raw(RegisterMap*) const+0x15c
      V [libjvm.dylib+0xab2000] JfrVframeStream::next_vframe()+0xf4
      V [libjvm.dylib+0xab286c] JfrStackTrace::record(JavaThread*, frame const&, int)+0x340
      V [libjvm.dylib+0xab2a98] JfrStackTrace::record(JavaThread*, int)+0xf4
      V [libjvm.dylib+0xab3a4c] JfrStackTraceRepository::record(JavaThread*, int, JfrStackFrame*, unsigned int)+0x3c
      V [libjvm.dylib+0x105916c] JfrEvent<EventNativeLibraryLoad>::write_event()+0x90
      V [libjvm.dylib+0x1056704] os::dll_load(char const*, char*, int)+0x1ec
      V [libjvm.dylib+0xba7c84] JVM_LoadLibrary+0x298
      C [libjava.dylib+0x47ac] Java_jdk_internal_loader_NativeLibraries_load+0x164
      j jdk.internal.loader.NativeLibraries.load(Ljdk/internal/loader/NativeLibraries$NativeLibraryImpl;Ljava/lang/String;ZZ)Z+0 java.base@22-loom
      j jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open()Z+57 java.base@22-loom
      j jdk.internal.loader.NativeLibraries.loadLibrary(Ljava/lang/Class;Ljava/lang/String;Z)Ljdk/internal/loader/NativeLibrary;+254 java.base@22-loom
      j jdk.internal.loader.NativeLibraries.loadLibrary(Ljava/lang/Class;Ljava/io/File;)Ljdk/internal/loader/NativeLibrary;+51 java.base@22-loom
      j jdk.internal.loader.NativeLibraries.findFromPaths([Ljava/lang/String;Ljava/lang/Class;Ljava/lang/String;)Ljdk/internal/loader/NativeLibrary;+44 java.base@22-loom


      Attachments

        Issue Links

          Activity

            People

              mgronlun Markus Grönlund
              mgronlun Markus Grönlund
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: