Starting from JDK 8u112 certain JVMTI functions became extremely slow. All these functions accept jmethodID as an argument.
- GetMethodName
- GetMethodDeclaringClass
- GetMethodModifiers
- GetLineNumberTable
- GetBytecodes
etc.
The attached code demonstrates the problem. This code executes GetMethodDeclaringClass one million times. It works 86 ms on JDK 8u102, but it takes 360'000 ms on JDK 8u141.
The problem appeared after JDK-8147451. The fix introduced a validity check Method::is_method_id for each translation of jmethodID argument. This involves a linear search among all jmethodIDs. Various tools like profilers allocate jmethodIDs for many loaded classes, so that the total number of jmethodIDs may reach hundreds of thousands. Linear search is not going to work in such cases.