diff --git a/jdk/make/com/sun/tools/attach/Makefile b/jdk/make/com/sun/tools/attach/Makefile index 0fa41d9d9ca26d87ba1242ef9c85220b6781fe44..1e450133451228d8dda4a335239e5a3a505e8493 100644 --- a/jdk/make/com/sun/tools/attach/Makefile +++ b/jdk/make/com/sun/tools/attach/Makefile @@ -48,6 +48,9 @@ include Exportedfiles.gmk ifeq ($(PLATFORM), solaris) OTHER_LDLIBS += -ldoor endif +ifeq ($(PLATFORM), windows) +EXTRA_LIBS += psapi.lib +endif vpath %.c $(PLATFORM_SRC)/native/sun/tools/attach diff --git a/jdk/src/windows/classes/sun/tools/attach/WindowsAttachProvider.java b/jdk/src/windows/classes/sun/tools/attach/WindowsAttachProvider.java index b915ab89534958626134e12348510b8c2b9f895a..cda6a73bc29fb813c4f0244cdb74f75daa8cfbaf 100644 --- a/jdk/src/windows/classes/sun/tools/attach/WindowsAttachProvider.java +++ b/jdk/src/windows/classes/sun/tools/attach/WindowsAttachProvider.java @@ -126,16 +126,6 @@ public class WindowsAttachProvider extends HotSpotAttachProvider { * of the process list. */ private List listJavaProcesses() { - // ensure that process status helper is loaded (psapi.dll) - if (!isProcessStatusHelperInitialized) { - synchronized (WindowsAttachProvider.class) { - if (!isProcessStatusHelperInitialized) { - initializeProcessStatusHelper(); - isProcessStatusHelperInitialized = true; - } - } - } - ArrayList list = new ArrayList(); @@ -172,12 +162,6 @@ public class WindowsAttachProvider extends HotSpotAttachProvider { return list; } - // indicates if psapi.dll has been initialized - private static volatile boolean isProcessStatusHelperInitialized; - - // loads psapi - private static native void initializeProcessStatusHelper(); - // enumerates processes using psapi's EnumProcesses private static native int enumProcesses(int[] processes, int max); diff --git a/jdk/src/windows/native/sun/tools/attach/WindowsAttachProvider.c b/jdk/src/windows/native/sun/tools/attach/WindowsAttachProvider.c index 8ddccd7ce21123d5af098e2b4fed7563e2fb6141..bbd6f400a24e2bf4465570bcd06c7bc833a8d345 100644 --- a/jdk/src/windows/native/sun/tools/attach/WindowsAttachProvider.c +++ b/jdk/src/windows/native/sun/tools/attach/WindowsAttachProvider.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "jni.h" #include "jni_util.h" @@ -96,41 +97,6 @@ Java_sun_tools_attach_WindowsAttachProvider_volumeFlags(JNIEnv *env, jclass cls, } -/* - * Process status helper library functions - */ -static BOOL (WINAPI *_EnumProcesses) (DWORD *, DWORD, DWORD *); -static BOOL (WINAPI *_EnumProcessModules)(HANDLE, HMODULE *, DWORD, LPDWORD); -static DWORD (WINAPI *_GetModuleBaseName) (HANDLE, HMODULE, LPTSTR, DWORD); - - -/* - * Class: sun_tools_attach_WindowsAttachProvider - * Method: initializeProcessStatusHelper - * Signature: ()V - */ -JNIEXPORT void JNICALL -Java_sun_tools_attach_WindowsAttachProvider_initializeProcessStatusHelper(JNIEnv *env, jclass cls) -{ - HINSTANCE psapi = LoadLibrary("PSAPI.DLL") ; - if (psapi != NULL) { - _EnumProcesses = (BOOL(WINAPI *)(DWORD *, DWORD, DWORD *)) - GetProcAddress(psapi, "EnumProcesses") ; - _EnumProcessModules = (BOOL(WINAPI *)(HANDLE, HMODULE *, DWORD, LPDWORD)) - GetProcAddress(psapi, "EnumProcessModules"); - _GetModuleBaseName = (DWORD(WINAPI *)(HANDLE, HMODULE, LPTSTR, DWORD)) - GetProcAddress(psapi, "GetModuleBaseNameA"); - } - - if ((_EnumProcesses == NULL) || - (_EnumProcessModules == NULL) || - (_GetModuleBaseName == NULL)) - { - JNU_ThrowInternalError(env, "Unable to initialize process status helper library"); - } -} - - /* * Class: sun_tools_attach_WindowsAttachProvider * Method: enumProcesses @@ -147,7 +113,7 @@ Java_sun_tools_attach_WindowsAttachProvider_enumProcesses(JNIEnv *env, jclass cl size = max * sizeof(DWORD); ptr = (DWORD*)malloc(size); if (ptr != NULL) { - BOOL res = (*_EnumProcesses)(ptr, size, &bytesReturned); + BOOL res = EnumProcesses(ptr, size, &bytesReturned); if (res != 0) { result = (jint)(bytesReturned / sizeof(DWORD)); (*env)->SetIntArrayRegion(env, arr, 0, (jsize)result, (jint*)ptr); @@ -192,13 +158,13 @@ Java_sun_tools_attach_WindowsAttachProvider_isLibraryLoadedByProcess(JNIEnv *env size = 1024 * sizeof(HMODULE); ptr = (HMODULE*)malloc(size); if (ptr != NULL) { - BOOL res = (*_EnumProcessModules)(hProcess, ptr, size, &bytesReturned); + BOOL res = EnumProcessModules(hProcess, ptr, size, &bytesReturned); if (res != 0) { int count = bytesReturned / sizeof(HMODULE); int i = 0; while (i < count) { char base[256]; - BOOL res = (*_GetModuleBaseName)(hProcess, ptr[i], base, sizeof(base)); + BOOL res = GetModuleBaseName(hProcess, ptr[i], base, sizeof(base)); if (res != 0) { if (strcmp(base, lib) == 0) { result = JNI_TRUE; diff --git a/jdk/src/windows/native/sun/tools/attach/WindowsVirtualMachine.c b/jdk/src/windows/native/sun/tools/attach/WindowsVirtualMachine.c index 6086ddf30f0b7befcb6e377b7e0b77ee7173137c..a956730d8cad95b89a71b19cf878dfc8ccf0cdf2 100644 --- a/jdk/src/windows/native/sun/tools/attach/WindowsVirtualMachine.c +++ b/jdk/src/windows/native/sun/tools/attach/WindowsVirtualMachine.c @@ -32,13 +32,13 @@ /* kernel32 */ -typedef HINSTANCE (WINAPI* LoadLibraryFunc) (LPCTSTR); +typedef HINSTANCE (WINAPI* GetModuleHandleFunc) (LPCTSTR); typedef FARPROC (WINAPI* GetProcAddressFunc)(HMODULE, LPCSTR); /* only on Windows 64-bit or 32-bit application running under WOW64 */ typedef BOOL (WINAPI *IsWow64ProcessFunc) (HANDLE, PBOOL); -static LoadLibraryFunc _LoadLibrary; +static GetModuleHandleFunc _GetModuleHandle; static GetProcAddressFunc _GetProcAddress; static IsWow64ProcessFunc _IsWow64Process; @@ -70,7 +70,7 @@ static void jstring_to_cstring(JNIEnv* env, jstring jstr, char* cstr, int len); #define MAX_PIPE_NAME_LENGTH 256 typedef struct { - LoadLibraryFunc _LoadLibrary; + GetModuleHandleFunc _GetModuleHandle; GetProcAddressFunc _GetProcAddress; char jvmLib[MAX_LIBNAME_LENGTH]; /* "jvm.dll" */ char func1[MAX_FUNC_LENGTH]; @@ -96,7 +96,7 @@ static DWORD WINAPI thread_func(DataBlock *pData) HINSTANCE h; EnqueueOperationFunc addr; - h = pData->_LoadLibrary(pData->jvmLib); + h = pData->_GetModuleHandle(pData->jvmLib); if (h == NULL) { return ERR_OPEN_JVM_FAIL; } @@ -131,15 +131,10 @@ static void thread_end (void) { JNIEXPORT void JNICALL Java_sun_tools_attach_WindowsVirtualMachine_init (JNIEnv *env, jclass cls) { - HINSTANCE h = LoadLibrary("kernel32"); - if (h != NULL) { - _LoadLibrary = (LoadLibraryFunc) GetProcAddress(h, "LoadLibraryA"); - _GetProcAddress = (GetProcAddressFunc)GetProcAddress(h, "GetProcAddress"); - _IsWow64Process = (IsWow64ProcessFunc)GetProcAddress(h, "IsWow64Process"); - } - if (_LoadLibrary == NULL || _GetProcAddress == NULL) { - JNU_ThrowInternalError(env, "Unable to get address of LoadLibraryA or GetProcAddress"); - } + // All following APIs exist on Windows XP with SP2/Windows Server 2008 + _GetModuleHandle = (GetModuleHandleFunc)GetModuleHandle; + _GetProcAddress = (GetProcAddressFunc)GetProcAddress; + _IsWow64Process = (IsWow64ProcessFunc)IsWow64Process; } @@ -375,7 +370,7 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_WindowsVirtualMachine_enqueue /* * Setup data to copy to target process */ - data._LoadLibrary = _LoadLibrary; + data._GetModuleHandle = _GetModuleHandle; data._GetProcAddress = _GetProcAddress; strcpy(data.jvmLib, "jvm"); diff --git a/jdk/src/windows/native/sun/tracing/dtrace/jvm_symbols_md.c b/jdk/src/windows/native/sun/tracing/dtrace/jvm_symbols_md.c index f7ae46ecd8f23ab7bbaef9aadb033b454e9fcf23..dd4d5d03fc868aab90ccea176e87cd90eda29a8b 100644 --- a/jdk/src/windows/native/sun/tracing/dtrace/jvm_symbols_md.c +++ b/jdk/src/windows/native/sun/tracing/dtrace/jvm_symbols_md.c @@ -35,7 +35,7 @@ JvmSymbols* lookupJvmSymbols() { JvmSymbols* syms = (JvmSymbols*)malloc(sizeof(JvmSymbols)); if (syms != NULL) { - HINSTANCE jvm = LoadLibrary("jvm.dll"); + HINSTANCE jvm = GetModuleHandle("jvm.dll"); if (jvm == NULL) { free(syms); return NULL; diff --git a/jdk/src/windows/npt/npt_md.h b/jdk/src/windows/npt/npt_md.h index 394a8dc3b5ebdb757396675ba0ee7258014650ed..4cf2176db1c1b90ec76c94429e4a2220dfee2f65 100644 --- a/jdk/src/windows/npt/npt_md.h +++ b/jdk/src/windows/npt/npt_md.h @@ -47,7 +47,7 @@ _handle = NULL; \ *(pnpt) = NULL; \ buf[0] = 0; \ - jvm = LoadLibrary("jvm.dll"); \ + jvm = GetModuleHandle("jvm.dll"); \ if ( jvm == NULL ) NPT_ERROR("Cannot find jvm.dll"); \ GetModuleFileName(jvm, buf, FILENAME_MAX); \ lastSlash = strrchr(buf, '\\'); \