src/os/windows/vm/os_windows.cpp

changeset 7074
833b0f92429a
parent 6918
d22136881b85
child 7081
aef17e6b4abf
equal deleted inserted replaced
7073:4d3a43351904 7074:833b0f92429a
129 timeBeginPeriod(1L); 129 timeBeginPeriod(1L);
130 break; 130 break;
131 case DLL_PROCESS_DETACH: 131 case DLL_PROCESS_DETACH:
132 if(ForceTimeHighResolution) 132 if(ForceTimeHighResolution)
133 timeEndPeriod(1L); 133 timeEndPeriod(1L);
134
135 // Workaround for issue when a custom launcher doesn't call
136 // DestroyJavaVM and NMT is trying to track memory when free is
137 // called from a static destructor
138 MemTracker::shutdown();
139
134 break; 140 break;
135 default: 141 default:
136 break; 142 break;
137 } 143 }
138 return true; 144 return true;
151 bool os::getenv(const char* name, char* buffer, int len) { 157 bool os::getenv(const char* name, char* buffer, int len) {
152 int result = GetEnvironmentVariable(name, buffer, len); 158 int result = GetEnvironmentVariable(name, buffer, len);
153 return result > 0 && result < len; 159 return result > 0 && result < len;
154 } 160 }
155 161
162 bool os::unsetenv(const char* name) {
163 assert(name != NULL, "Null pointer");
164 return (SetEnvironmentVariable(name, NULL) == TRUE);
165 }
156 166
157 // No setuid programs under Windows. 167 // No setuid programs under Windows.
158 bool os::have_special_privileges() { 168 bool os::have_special_privileges() {
159 return false; 169 return false;
160 } 170 }
309 /* 319 /*
310 * RtlCaptureStackBackTrace Windows API may not exist prior to Windows XP. 320 * RtlCaptureStackBackTrace Windows API may not exist prior to Windows XP.
311 * So far, this method is only used by Native Memory Tracking, which is 321 * So far, this method is only used by Native Memory Tracking, which is
312 * only supported on Windows XP or later. 322 * only supported on Windows XP or later.
313 */ 323 */
314 address os::get_caller_pc(int n) { 324
325 int os::get_native_stack(address* stack, int frames, int toSkip) {
315 #ifdef _NMT_NOINLINE_ 326 #ifdef _NMT_NOINLINE_
316 n ++; 327 toSkip ++;
317 #endif 328 #endif
318 address pc; 329 int captured = Kernel32Dll::RtlCaptureStackBackTrace(toSkip + 1, frames,
319 if (os::Kernel32Dll::RtlCaptureStackBackTrace(n + 1, 1, (PVOID*)&pc, NULL) == 1) { 330 (PVOID*)stack, NULL);
320 return pc; 331 for (int index = captured; index < frames; index ++) {
321 } 332 stack[index] = NULL;
322 return NULL; 333 }
334 return captured;
323 } 335 }
324 336
325 337
326 // os::current_stack_base() 338 // os::current_stack_base()
327 // 339 //
2902 size_of_reserve, // size of Reserve 2914 size_of_reserve, // size of Reserve
2903 MEM_RESERVE, 2915 MEM_RESERVE,
2904 PAGE_READWRITE); 2916 PAGE_READWRITE);
2905 // If reservation failed, return NULL 2917 // If reservation failed, return NULL
2906 if (p_buf == NULL) return NULL; 2918 if (p_buf == NULL) return NULL;
2907 MemTracker::record_virtual_memory_reserve((address)p_buf, size_of_reserve, mtNone, CALLER_PC); 2919 MemTracker::record_virtual_memory_reserve((address)p_buf, size_of_reserve, CALLER_PC);
2908 os::release_memory(p_buf, bytes + chunk_size); 2920 os::release_memory(p_buf, bytes + chunk_size);
2909 2921
2910 // we still need to round up to a page boundary (in case we are using large pages) 2922 // we still need to round up to a page boundary (in case we are using large pages)
2911 // but not to a chunk boundary (in case InterleavingGranularity doesn't align with page size) 2923 // but not to a chunk boundary (in case InterleavingGranularity doesn't align with page size)
2912 // instead we handle this in the bytes_to_rq computation below 2924 // instead we handle this in the bytes_to_rq computation below
2968 size_t bytes_to_release = bytes - bytes_remaining; 2980 size_t bytes_to_release = bytes - bytes_remaining;
2969 // NMT has yet to record any individual blocks, so it 2981 // NMT has yet to record any individual blocks, so it
2970 // need to create a dummy 'reserve' record to match 2982 // need to create a dummy 'reserve' record to match
2971 // the release. 2983 // the release.
2972 MemTracker::record_virtual_memory_reserve((address)p_buf, 2984 MemTracker::record_virtual_memory_reserve((address)p_buf,
2973 bytes_to_release, mtNone, CALLER_PC); 2985 bytes_to_release, CALLER_PC);
2974 os::release_memory(p_buf, bytes_to_release); 2986 os::release_memory(p_buf, bytes_to_release);
2975 } 2987 }
2976 #ifdef ASSERT 2988 #ifdef ASSERT
2977 if (should_inject_error) { 2989 if (should_inject_error) {
2978 if (TracePageSizes && Verbose) { 2990 if (TracePageSizes && Verbose) {
2987 next_alloc_addr += bytes_to_rq; 2999 next_alloc_addr += bytes_to_rq;
2988 count++; 3000 count++;
2989 } 3001 }
2990 // Although the memory is allocated individually, it is returned as one. 3002 // Although the memory is allocated individually, it is returned as one.
2991 // NMT records it as one block. 3003 // NMT records it as one block.
2992 address pc = CALLER_PC;
2993 if ((flags & MEM_COMMIT) != 0) { 3004 if ((flags & MEM_COMMIT) != 0) {
2994 MemTracker::record_virtual_memory_reserve_and_commit((address)p_buf, bytes, mtNone, pc); 3005 MemTracker::record_virtual_memory_reserve_and_commit((address)p_buf, bytes, CALLER_PC);
2995 } else { 3006 } else {
2996 MemTracker::record_virtual_memory_reserve((address)p_buf, bytes, mtNone, pc); 3007 MemTracker::record_virtual_memory_reserve((address)p_buf, bytes, CALLER_PC);
2997 } 3008 }
2998 3009
2999 // made it this far, success 3010 // made it this far, success
3000 return p_buf; 3011 return p_buf;
3001 } 3012 }
3189 } 3200 }
3190 // normal policy just allocate it all at once 3201 // normal policy just allocate it all at once
3191 DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES; 3202 DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES;
3192 char * res = (char *)VirtualAlloc(addr, bytes, flag, prot); 3203 char * res = (char *)VirtualAlloc(addr, bytes, flag, prot);
3193 if (res != NULL) { 3204 if (res != NULL) {
3194 address pc = CALLER_PC; 3205 MemTracker::record_virtual_memory_reserve_and_commit((address)res, bytes, CALLER_PC);
3195 MemTracker::record_virtual_memory_reserve_and_commit((address)res, bytes, mtNone, pc);
3196 } 3206 }
3197 3207
3198 return res; 3208 return res;
3199 } 3209 }
3200 } 3210 }

mercurial