comparison src/os/windows/vm/os_windows.cpp @ 8883:b9a918201d47

Merge with hsx25
author Gilles Duboscq <duboscq@ssw.jku.at>
date Sat, 06 Apr 2013 20:04:06 +0200
parents 5fc51c1ecdeb 0ca3dd0ffaba
children 89e4d67fdd2a
comparison
equal deleted inserted replaced
8660:d47b52b0ff68 8883:b9a918201d47
58 #include "runtime/stubRoutines.hpp" 58 #include "runtime/stubRoutines.hpp"
59 #include "runtime/thread.inline.hpp" 59 #include "runtime/thread.inline.hpp"
60 #include "runtime/threadCritical.hpp" 60 #include "runtime/threadCritical.hpp"
61 #include "runtime/timer.hpp" 61 #include "runtime/timer.hpp"
62 #include "services/attachListener.hpp" 62 #include "services/attachListener.hpp"
63 #include "services/memTracker.hpp"
63 #include "services/runtimeService.hpp" 64 #include "services/runtimeService.hpp"
64 #include "utilities/decoder.hpp" 65 #include "utilities/decoder.hpp"
65 #include "utilities/defaultStream.hpp" 66 #include "utilities/defaultStream.hpp"
66 #include "utilities/events.hpp" 67 #include "utilities/events.hpp"
67 #include "utilities/growableArray.hpp" 68 #include "utilities/growableArray.hpp"
683 684
684 julong os::physical_memory() { 685 julong os::physical_memory() {
685 return win32::physical_memory(); 686 return win32::physical_memory();
686 } 687 }
687 688
688 julong os::allocatable_physical_memory(julong size) { 689 bool os::has_allocatable_memory_limit(julong* limit) {
690 MEMORYSTATUSEX ms;
691 ms.dwLength = sizeof(ms);
692 GlobalMemoryStatusEx(&ms);
689 #ifdef _LP64 693 #ifdef _LP64
690 return size; 694 *limit = (julong)ms.ullAvailVirtual;
695 return true;
691 #else 696 #else
692 // Limit to 1400m because of the 2gb address space wall 697 // Limit to 1400m because of the 2gb address space wall
693 return MIN2(size, (julong)1400*M); 698 *limit = MIN2((julong)1400*M, (julong)ms.ullAvailVirtual);
699 return true;
694 #endif 700 #endif
695 } 701 }
696 702
697 // VC6 lacks DWORD_PTR 703 // VC6 lacks DWORD_PTR
698 #if _MSC_VER < 1300 704 #if _MSC_VER < 1300
2850 size_of_reserve, // size of Reserve 2856 size_of_reserve, // size of Reserve
2851 MEM_RESERVE, 2857 MEM_RESERVE,
2852 PAGE_READWRITE); 2858 PAGE_READWRITE);
2853 // If reservation failed, return NULL 2859 // If reservation failed, return NULL
2854 if (p_buf == NULL) return NULL; 2860 if (p_buf == NULL) return NULL;
2855 2861 MemTracker::record_virtual_memory_reserve((address)p_buf, size_of_reserve, CALLER_PC);
2856 os::release_memory(p_buf, bytes + chunk_size); 2862 os::release_memory(p_buf, bytes + chunk_size);
2857 2863
2858 // we still need to round up to a page boundary (in case we are using large pages) 2864 // we still need to round up to a page boundary (in case we are using large pages)
2859 // but not to a chunk boundary (in case InterleavingGranularity doesn't align with page size) 2865 // but not to a chunk boundary (in case InterleavingGranularity doesn't align with page size)
2860 // instead we handle this in the bytes_to_rq computation below 2866 // instead we handle this in the bytes_to_rq computation below
2912 if (p_new == NULL) { 2918 if (p_new == NULL) {
2913 // Free any allocated pages 2919 // Free any allocated pages
2914 if (next_alloc_addr > p_buf) { 2920 if (next_alloc_addr > p_buf) {
2915 // Some memory was committed so release it. 2921 // Some memory was committed so release it.
2916 size_t bytes_to_release = bytes - bytes_remaining; 2922 size_t bytes_to_release = bytes - bytes_remaining;
2923 // NMT has yet to record any individual blocks, so it
2924 // need to create a dummy 'reserve' record to match
2925 // the release.
2926 MemTracker::record_virtual_memory_reserve((address)p_buf,
2927 bytes_to_release, CALLER_PC);
2917 os::release_memory(p_buf, bytes_to_release); 2928 os::release_memory(p_buf, bytes_to_release);
2918 } 2929 }
2919 #ifdef ASSERT 2930 #ifdef ASSERT
2920 if (should_inject_error) { 2931 if (should_inject_error) {
2921 if (TracePageSizes && Verbose) { 2932 if (TracePageSizes && Verbose) {
2923 } 2934 }
2924 } 2935 }
2925 #endif 2936 #endif
2926 return NULL; 2937 return NULL;
2927 } 2938 }
2939
2928 bytes_remaining -= bytes_to_rq; 2940 bytes_remaining -= bytes_to_rq;
2929 next_alloc_addr += bytes_to_rq; 2941 next_alloc_addr += bytes_to_rq;
2930 count++; 2942 count++;
2931 } 2943 }
2944 // Although the memory is allocated individually, it is returned as one.
2945 // NMT records it as one block.
2946 address pc = CALLER_PC;
2947 MemTracker::record_virtual_memory_reserve((address)p_buf, bytes, pc);
2948 if ((flags & MEM_COMMIT) != 0) {
2949 MemTracker::record_virtual_memory_commit((address)p_buf, bytes, pc);
2950 }
2951
2932 // made it this far, success 2952 // made it this far, success
2933 return p_buf; 2953 return p_buf;
2934 } 2954 }
2935 2955
2936 2956
3113 3133
3114 } else { 3134 } else {
3115 // normal policy just allocate it all at once 3135 // normal policy just allocate it all at once
3116 DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES; 3136 DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES;
3117 char * res = (char *)VirtualAlloc(NULL, bytes, flag, prot); 3137 char * res = (char *)VirtualAlloc(NULL, bytes, flag, prot);
3138 if (res != NULL) {
3139 address pc = CALLER_PC;
3140 MemTracker::record_virtual_memory_reserve((address)res, bytes, pc);
3141 MemTracker::record_virtual_memory_commit((address)res, bytes, pc);
3142 }
3143
3118 return res; 3144 return res;
3119 } 3145 }
3120 } 3146 }
3121 3147
3122 bool os::release_memory_special(char* base, size_t bytes) { 3148 bool os::release_memory_special(char* base, size_t bytes) {
3149 assert(base != NULL, "Sanity check");
3150 // Memory allocated via reserve_memory_special() is committed
3151 MemTracker::record_virtual_memory_uncommit((address)base, bytes);
3123 return release_memory(base, bytes); 3152 return release_memory(base, bytes);
3124 } 3153 }
3125 3154
3126 void os::print_statistics() { 3155 void os::print_statistics() {
3127 } 3156 }
3758 static void perfMemory_exit_helper() { 3787 static void perfMemory_exit_helper() {
3759 perfMemory_exit(); 3788 perfMemory_exit();
3760 } 3789 }
3761 } 3790 }
3762 3791
3792 static jint initSock();
3793
3763 // this is called _after_ the global arguments have been parsed 3794 // this is called _after_ the global arguments have been parsed
3764 jint os::init_2(void) { 3795 jint os::init_2(void) {
3765 // Allocate a single page and mark it as readable for safepoint polling 3796 // Allocate a single page and mark it as readable for safepoint polling
3766 address polling_page = (address)VirtualAlloc(NULL, os::vm_page_size(), MEM_RESERVE, PAGE_READONLY); 3797 address polling_page = (address)VirtualAlloc(NULL, os::vm_page_size(), MEM_RESERVE, PAGE_READONLY);
3767 guarantee( polling_page != NULL, "Reserve Failed for polling page"); 3798 guarantee( polling_page != NULL, "Reserve Failed for polling page");
3886 3917
3887 if (UseNUMAInterleaving) { 3918 if (UseNUMAInterleaving) {
3888 // first check whether this Windows OS supports VirtualAllocExNuma, if not ignore this flag 3919 // first check whether this Windows OS supports VirtualAllocExNuma, if not ignore this flag
3889 bool success = numa_interleaving_init(); 3920 bool success = numa_interleaving_init();
3890 if (!success) UseNUMAInterleaving = false; 3921 if (!success) UseNUMAInterleaving = false;
3922 }
3923
3924 if (initSock() != JNI_OK) {
3925 return JNI_ERR;
3891 } 3926 }
3892 3927
3893 return JNI_OK; 3928 return JNI_OK;
3894 } 3929 }
3895 3930
4884 } 4919 }
4885 4920
4886 // We don't build a headless jre for Windows 4921 // We don't build a headless jre for Windows
4887 bool os::is_headless_jre() { return false; } 4922 bool os::is_headless_jre() { return false; }
4888 4923
4889 4924 static jint initSock() {
4890 typedef CRITICAL_SECTION mutex_t;
4891 #define mutexInit(m) InitializeCriticalSection(m)
4892 #define mutexDestroy(m) DeleteCriticalSection(m)
4893 #define mutexLock(m) EnterCriticalSection(m)
4894 #define mutexUnlock(m) LeaveCriticalSection(m)
4895
4896 static bool sock_initialized = FALSE;
4897 static mutex_t sockFnTableMutex;
4898
4899 static void initSock() {
4900 WSADATA wsadata; 4925 WSADATA wsadata;
4901 4926
4902 if (!os::WinSock2Dll::WinSock2Available()) { 4927 if (!os::WinSock2Dll::WinSock2Available()) {
4903 jio_fprintf(stderr, "Could not load Winsock 2 (error: %d)\n", 4928 jio_fprintf(stderr, "Could not load Winsock (error: %d)\n",
4904 ::GetLastError()); 4929 ::GetLastError());
4905 return; 4930 return JNI_ERR;
4906 } 4931 }
4907 if (sock_initialized == TRUE) return; 4932
4908 4933 if (os::WinSock2Dll::WSAStartup(MAKEWORD(2,2), &wsadata) != 0) {
4909 ::mutexInit(&sockFnTableMutex); 4934 jio_fprintf(stderr, "Could not initialize Winsock (error: %d)\n",
4910 ::mutexLock(&sockFnTableMutex); 4935 ::GetLastError());
4911 if (os::WinSock2Dll::WSAStartup(MAKEWORD(1,1), &wsadata) != 0) { 4936 return JNI_ERR;
4912 jio_fprintf(stderr, "Could not initialize Winsock\n"); 4937 }
4913 } 4938 return JNI_OK;
4914 sock_initialized = TRUE;
4915 ::mutexUnlock(&sockFnTableMutex);
4916 } 4939 }
4917 4940
4918 struct hostent* os::get_host_by_name(char* name) { 4941 struct hostent* os::get_host_by_name(char* name) {
4919 if (!sock_initialized) {
4920 initSock();
4921 }
4922 if (!os::WinSock2Dll::WinSock2Available()) {
4923 return NULL;
4924 }
4925 return (struct hostent*)os::WinSock2Dll::gethostbyname(name); 4942 return (struct hostent*)os::WinSock2Dll::gethostbyname(name);
4926 } 4943 }
4927 4944
4928 int os::socket_close(int fd) { 4945 int os::socket_close(int fd) {
4929 return ::closesocket(fd); 4946 return ::closesocket(fd);