Java 问题,目前遇到了一个比较奇怪的问题:
- 内部公司使用了一些奇怪安全软件,登录了账号后,发现 IDEA 打不开了;
- 通过 JvisualVM 监控到一个 windows native 的本地方法发生了堵塞,CPU 达到了 100%;
- 写了一个简单的案例,去调用这个方法,发现确实会在扫描大量文件时发生堵塞。
想找到一种方式查看到当前 jvm ( windows 平台)的 C++的方法调用栈的情况呢? 具体是那个位置造成了死循环(目前看 jdk 层 java 代码未产生死循环)。
方法名是 WindowsNativeDispatcher.CreateFile0 ,通过 JDK 源码,找到了 natvie 方法的 c 文件
下面是具体代码:
JNIEXPORT jlong JNICALL Java_sun_nio_fs_WindowsNativeDispatcher_CreateFile0(JNIEnv* env, jclass this, jlong address, jint dwDesiredAccess, jint dwShareMode, jlong sdAddress, jint dwCreationDisposition, jint dwFlagsAndAttributes) { HANDLE handle; LPCWSTR lpFileName = jlong_to_ptr(address); SECURITY_ATTRIBUTES securityAttributes; LPSECURITY_ATTRIBUTES lpSecurityAttributes; PSECURITY_DESCRIPTOR lpSecurityDescriptor = jlong_to_ptr(sdAddress); if (lpSecurityDescriptor == NULL) { lpSecurityAttributes = NULL; } else { securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); securityAttributes.lpSecurityDescriptor = lpSecurityDescriptor; securityAttributes.bInheritHandle = FALSE; lpSecurityAttributes = &securityAttributes; } handle = CreateFileW(lpFileName, (DWORD)dwDesiredAccess, (DWORD)dwShareMode, lpSecurityAttributes, (DWORD)dwCreationDisposition, (DWORD)dwFlagsAndAttributes, NULL); if (handle == INVALID_HANDLE_VALUE) { throwWindowsException(env, GetLastError()); } return ptr_to_jlong(handle); } 