comparison src/os/windows/vm/os_windows.cpp @ 717:c8152ae3f339

6830069: UseLargePages is broken on Win64 Summary: Making VirtualAlloc/VirtualProtect two calls for PAGE_EXECUTE_READWRITE doesn't work for MEM_LARGE_PAGES. Reviewed-by: xlu, kvn, jcoomes
author coleenp
date Tue, 21 Apr 2009 16:12:51 -0400
parents 956304450e80
children 8c79517a9300
comparison
equal deleted inserted replaced
714:981375ca07b7 717:c8152ae3f339
2630 return true; 2630 return true;
2631 } 2631 }
2632 2632
2633 char* os::reserve_memory_special(size_t bytes, char* addr, bool exec) { 2633 char* os::reserve_memory_special(size_t bytes, char* addr, bool exec) {
2634 2634
2635 const DWORD prot = exec ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
2636
2635 if (UseLargePagesIndividualAllocation) { 2637 if (UseLargePagesIndividualAllocation) {
2636 if (TracePageSizes && Verbose) { 2638 if (TracePageSizes && Verbose) {
2637 tty->print_cr("Reserving large pages individually."); 2639 tty->print_cr("Reserving large pages individually.");
2638 } 2640 }
2639 char * p_buf; 2641 char * p_buf;
2692 p_new = NULL; 2694 p_new = NULL;
2693 } else { 2695 } else {
2694 p_new = (char *) VirtualAlloc(next_alloc_addr, 2696 p_new = (char *) VirtualAlloc(next_alloc_addr,
2695 bytes_to_rq, 2697 bytes_to_rq,
2696 MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES, 2698 MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES,
2697 PAGE_READWRITE); 2699 prot);
2698 if (p_new != NULL && exec) {
2699 DWORD oldprot;
2700 // Windows doc says to use VirtualProtect to get execute permissions
2701 VirtualProtect(next_alloc_addr, bytes_to_rq,
2702 PAGE_EXECUTE_READWRITE, &oldprot);
2703 }
2704 } 2700 }
2705 2701
2706 if (p_new == NULL) { 2702 if (p_new == NULL) {
2707 // Free any allocated pages 2703 // Free any allocated pages
2708 if (next_alloc_addr > p_buf) { 2704 if (next_alloc_addr > p_buf) {
2727 return p_buf; 2723 return p_buf;
2728 2724
2729 } else { 2725 } else {
2730 // normal policy just allocate it all at once 2726 // normal policy just allocate it all at once
2731 DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES; 2727 DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES;
2732 char * res = (char *)VirtualAlloc(NULL, bytes, flag, PAGE_READWRITE); 2728 char * res = (char *)VirtualAlloc(NULL, bytes, flag, prot);
2733 if (res != NULL && exec) {
2734 DWORD oldprot;
2735 // Windows doc says to use VirtualProtect to get execute permissions
2736 VirtualProtect(res, bytes, PAGE_EXECUTE_READWRITE, &oldprot);
2737 }
2738 return res; 2729 return res;
2739 } 2730 }
2740 } 2731 }
2741 2732
2742 bool os::release_memory_special(char* base, size_t bytes) { 2733 bool os::release_memory_special(char* base, size_t bytes) {