5025 }
5026
5027 int os::bind(int fd, struct sockaddr* him, socklen_t len) {
5028 return ::bind(fd, him, len);
5029 }
5030
5031 int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
5032 return ::getsockname(fd, him, len);
5033 }
5034
5035 int os::get_sock_opt(int fd, int level, int optname,
5036 char* optval, socklen_t* optlen) {
5037 return ::getsockopt(fd, level, optname, optval, optlen);
5038 }
5039
5040 int os::set_sock_opt(int fd, int level, int optname,
5041 const char* optval, socklen_t optlen) {
5042 return ::setsockopt(fd, level, optname, optval, optlen);
5043 }
5044
5045
5046 // Kernel32 API
5047 typedef SIZE_T (WINAPI* GetLargePageMinimum_Fn)(void);
5048 typedef LPVOID (WINAPI *VirtualAllocExNuma_Fn) (HANDLE, LPVOID, SIZE_T, DWORD, DWORD, DWORD);
5049 typedef BOOL (WINAPI *GetNumaHighestNodeNumber_Fn) (PULONG);
5050 typedef BOOL (WINAPI *GetNumaNodeProcessorMask_Fn) (UCHAR, PULONGLONG);
5051 typedef USHORT (WINAPI* RtlCaptureStackBackTrace_Fn)(ULONG, ULONG, PVOID*, PULONG);
5052
5053 GetLargePageMinimum_Fn os::Kernel32Dll::_GetLargePageMinimum = NULL;
5054 VirtualAllocExNuma_Fn os::Kernel32Dll::_VirtualAllocExNuma = NULL;
5055 GetNumaHighestNodeNumber_Fn os::Kernel32Dll::_GetNumaHighestNodeNumber = NULL;
5056 GetNumaNodeProcessorMask_Fn os::Kernel32Dll::_GetNumaNodeProcessorMask = NULL;
5057 RtlCaptureStackBackTrace_Fn os::Kernel32Dll::_RtlCaptureStackBackTrace = NULL;
5058
5059
5060 BOOL os::Kernel32Dll::initialized = FALSE;
5061 SIZE_T os::Kernel32Dll::GetLargePageMinimum() {
5062 assert(initialized && _GetLargePageMinimum != NULL,
5063 "GetLargePageMinimumAvailable() not yet called");
5064 return _GetLargePageMinimum();
|
5025 }
5026
5027 int os::bind(int fd, struct sockaddr* him, socklen_t len) {
5028 return ::bind(fd, him, len);
5029 }
5030
5031 int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
5032 return ::getsockname(fd, him, len);
5033 }
5034
5035 int os::get_sock_opt(int fd, int level, int optname,
5036 char* optval, socklen_t* optlen) {
5037 return ::getsockopt(fd, level, optname, optval, optlen);
5038 }
5039
5040 int os::set_sock_opt(int fd, int level, int optname,
5041 const char* optval, socklen_t optlen) {
5042 return ::setsockopt(fd, level, optname, optval, optlen);
5043 }
5044
5045 // WINDOWS CONTEXT Flags for THREAD_SAMPLING
5046 #if defined(IA32)
5047 # define sampling_context_flags (CONTEXT_FULL | CONTEXT_FLOATING_POINT | CONTEXT_EXTENDED_REGISTERS)
5048 #elif defined (AMD64)
5049 # define sampling_context_flags (CONTEXT_FULL | CONTEXT_FLOATING_POINT)
5050 #endif
5051
5052 // returns true if thread could be suspended,
5053 // false otherwise
5054 static bool do_suspend(HANDLE* h) {
5055 if (h != NULL) {
5056 if (SuspendThread(*h) != ~0) {
5057 return true;
5058 }
5059 }
5060 return false;
5061 }
5062
5063 // resume the thread
5064 // calling resume on an active thread is a no-op
5065 static void do_resume(HANDLE* h) {
5066 if (h != NULL) {
5067 ResumeThread(*h);
5068 }
5069 }
5070
5071 // retrieve a suspend/resume context capable handle
5072 // from the tid. Caller validates handle return value.
5073 void get_thread_handle_for_extended_context(HANDLE* h, OSThread::thread_id_t tid) {
5074 if (h != NULL) {
5075 *h = OpenThread(THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION, FALSE, tid);
5076 }
5077 }
5078
5079 //
5080 // Thread sampling implementation
5081 //
5082 void os::SuspendedThreadTask::internal_do_task() {
5083 CONTEXT ctxt;
5084 HANDLE h = NULL;
5085
5086 // get context capable handle for thread
5087 get_thread_handle_for_extended_context(&h, _thread->osthread()->thread_id());
5088
5089 // sanity
5090 if (h == NULL || h == INVALID_HANDLE_VALUE) {
5091 return;
5092 }
5093
5094 // suspend the thread
5095 if (do_suspend(&h)) {
5096 ctxt.ContextFlags = sampling_context_flags;
5097 // get thread context
5098 GetThreadContext(h, &ctxt);
5099 SuspendedThreadTaskContext context(_thread, &ctxt);
5100 // pass context to Thread Sampling impl
5101 do_task(context);
5102 // resume thread
5103 do_resume(&h);
5104 }
5105
5106 // close handle
5107 CloseHandle(h);
5108 }
5109
5110
5111 // Kernel32 API
5112 typedef SIZE_T (WINAPI* GetLargePageMinimum_Fn)(void);
5113 typedef LPVOID (WINAPI *VirtualAllocExNuma_Fn) (HANDLE, LPVOID, SIZE_T, DWORD, DWORD, DWORD);
5114 typedef BOOL (WINAPI *GetNumaHighestNodeNumber_Fn) (PULONG);
5115 typedef BOOL (WINAPI *GetNumaNodeProcessorMask_Fn) (UCHAR, PULONGLONG);
5116 typedef USHORT (WINAPI* RtlCaptureStackBackTrace_Fn)(ULONG, ULONG, PVOID*, PULONG);
5117
5118 GetLargePageMinimum_Fn os::Kernel32Dll::_GetLargePageMinimum = NULL;
5119 VirtualAllocExNuma_Fn os::Kernel32Dll::_VirtualAllocExNuma = NULL;
5120 GetNumaHighestNodeNumber_Fn os::Kernel32Dll::_GetNumaHighestNodeNumber = NULL;
5121 GetNumaNodeProcessorMask_Fn os::Kernel32Dll::_GetNumaNodeProcessorMask = NULL;
5122 RtlCaptureStackBackTrace_Fn os::Kernel32Dll::_RtlCaptureStackBackTrace = NULL;
5123
5124
5125 BOOL os::Kernel32Dll::initialized = FALSE;
5126 SIZE_T os::Kernel32Dll::GetLargePageMinimum() {
5127 assert(initialized && _GetLargePageMinimum != NULL,
5128 "GetLargePageMinimumAvailable() not yet called");
5129 return _GetLargePageMinimum();
|