hotspot/src/os/windows/vm/os_windows.cpp
changeset 46619 a3919f5e8d2b
parent 46618 d503911aa948
child 46620 750c6edff33b
equal deleted inserted replaced
46618:d503911aa948 46619:a3919f5e8d2b
  2384       //
  2384       //
  2385       // 15 bytes seems to be a (very) safe value for max instruction size.
  2385       // 15 bytes seems to be a (very) safe value for max instruction size.
  2386       bool pc_is_near_addr =
  2386       bool pc_is_near_addr =
  2387         (pointer_delta((void*) addr, (void*) pc, sizeof(char)) < 15);
  2387         (pointer_delta((void*) addr, (void*) pc, sizeof(char)) < 15);
  2388       bool instr_spans_page_boundary =
  2388       bool instr_spans_page_boundary =
  2389         (align_size_down((intptr_t) pc ^ (intptr_t) addr,
  2389         (align_down((intptr_t) pc ^ (intptr_t) addr,
  2390                          (intptr_t) page_size) > 0);
  2390                          (intptr_t) page_size) > 0);
  2391 
  2391 
  2392       if (pc == addr || (pc_is_near_addr && instr_spans_page_boundary)) {
  2392       if (pc == addr || (pc_is_near_addr && instr_spans_page_boundary)) {
  2393         static volatile address last_addr =
  2393         static volatile address last_addr =
  2394           (address) os::non_memory_address_word();
  2394           (address) os::non_memory_address_word();
  2396         // In conservative mode, don't unguard unless the address is in the VM
  2396         // In conservative mode, don't unguard unless the address is in the VM
  2397         if (UnguardOnExecutionViolation > 0 && addr != last_addr &&
  2397         if (UnguardOnExecutionViolation > 0 && addr != last_addr &&
  2398             (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) {
  2398             (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) {
  2399 
  2399 
  2400           // Set memory to RWX and retry
  2400           // Set memory to RWX and retry
  2401           address page_start = align_ptr_down(addr, page_size);
  2401           address page_start = align_down(addr, page_size);
  2402           bool res = os::protect_memory((char*) page_start, page_size,
  2402           bool res = os::protect_memory((char*) page_start, page_size,
  2403                                         os::MEM_PROT_RWX);
  2403                                         os::MEM_PROT_RWX);
  2404 
  2404 
  2405           log_debug(os)("Execution protection violation "
  2405           log_debug(os)("Execution protection violation "
  2406                         "at " INTPTR_FORMAT
  2406                         "at " INTPTR_FORMAT
  2773   bool warn_on_failure = use_numa_interleaving_specified;
  2773   bool warn_on_failure = use_numa_interleaving_specified;
  2774 #define WARN(msg) if (warn_on_failure) { warning(msg); }
  2774 #define WARN(msg) if (warn_on_failure) { warning(msg); }
  2775 
  2775 
  2776   // NUMAInterleaveGranularity cannot be less than vm_allocation_granularity (or _large_page_size if using large pages)
  2776   // NUMAInterleaveGranularity cannot be less than vm_allocation_granularity (or _large_page_size if using large pages)
  2777   size_t min_interleave_granularity = UseLargePages ? _large_page_size : os::vm_allocation_granularity();
  2777   size_t min_interleave_granularity = UseLargePages ? _large_page_size : os::vm_allocation_granularity();
  2778   NUMAInterleaveGranularity = align_size_up(NUMAInterleaveGranularity, min_interleave_granularity);
  2778   NUMAInterleaveGranularity = align_up(NUMAInterleaveGranularity, min_interleave_granularity);
  2779 
  2779 
  2780   if (numa_node_list_holder.build()) {
  2780   if (numa_node_list_holder.build()) {
  2781     if (log_is_enabled(Debug, os, cpu)) {
  2781     if (log_is_enabled(Debug, os, cpu)) {
  2782       Log(os, cpu) log;
  2782       Log(os, cpu) log;
  2783       log.debug("NUMA UsedNodeCount=%d, namely ", numa_node_list_holder.get_count());
  2783       log.debug("NUMA UsedNodeCount=%d, namely ", numa_node_list_holder.get_count());
  2830   os::release_memory(p_buf, bytes + chunk_size);
  2830   os::release_memory(p_buf, bytes + chunk_size);
  2831 
  2831 
  2832   // we still need to round up to a page boundary (in case we are using large pages)
  2832   // we still need to round up to a page boundary (in case we are using large pages)
  2833   // but not to a chunk boundary (in case InterleavingGranularity doesn't align with page size)
  2833   // but not to a chunk boundary (in case InterleavingGranularity doesn't align with page size)
  2834   // instead we handle this in the bytes_to_rq computation below
  2834   // instead we handle this in the bytes_to_rq computation below
  2835   p_buf = align_ptr_up(p_buf, page_size);
  2835   p_buf = align_up(p_buf, page_size);
  2836 
  2836 
  2837   // now go through and allocate one chunk at a time until all bytes are
  2837   // now go through and allocate one chunk at a time until all bytes are
  2838   // allocated
  2838   // allocated
  2839   size_t  bytes_remaining = bytes;
  2839   size_t  bytes_remaining = bytes;
  2840   // An overflow of align_size_up() would have been caught above
  2840   // An overflow of align_up() would have been caught above
  2841   // in the calculation of size_of_reserve.
  2841   // in the calculation of size_of_reserve.
  2842   char * next_alloc_addr = p_buf;
  2842   char * next_alloc_addr = p_buf;
  2843   HANDLE hProc = GetCurrentProcess();
  2843   HANDLE hProc = GetCurrentProcess();
  2844 
  2844 
  2845 #ifdef ASSERT
  2845 #ifdef ASSERT
  2994     char* extra_base = os::reserve_memory(extra_size, NULL, alignment);
  2994     char* extra_base = os::reserve_memory(extra_size, NULL, alignment);
  2995     if (extra_base == NULL) {
  2995     if (extra_base == NULL) {
  2996       return NULL;
  2996       return NULL;
  2997     }
  2997     }
  2998     // Do manual alignment
  2998     // Do manual alignment
  2999     aligned_base = align_ptr_up(extra_base, alignment);
  2999     aligned_base = align_up(extra_base, alignment);
  3000 
  3000 
  3001     os::release_memory(extra_base, extra_size);
  3001     os::release_memory(extra_base, extra_size);
  3002 
  3002 
  3003     aligned_base = os::reserve_memory(size, aligned_base);
  3003     aligned_base = os::reserve_memory(size, aligned_base);
  3004 
  3004 
  3063 
  3063 
  3064 char* os::reserve_memory_special(size_t bytes, size_t alignment, char* addr,
  3064 char* os::reserve_memory_special(size_t bytes, size_t alignment, char* addr,
  3065                                  bool exec) {
  3065                                  bool exec) {
  3066   assert(UseLargePages, "only for large pages");
  3066   assert(UseLargePages, "only for large pages");
  3067 
  3067 
  3068   if (!is_size_aligned(bytes, os::large_page_size()) || alignment > os::large_page_size()) {
  3068   if (!is_aligned(bytes, os::large_page_size()) || alignment > os::large_page_size()) {
  3069     return NULL; // Fallback to small pages.
  3069     return NULL; // Fallback to small pages.
  3070   }
  3070   }
  3071 
  3071 
  3072   const DWORD prot = exec ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
  3072   const DWORD prot = exec ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
  3073   const DWORD flags = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES;
  3073   const DWORD flags = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES;
  4064   size_t min_stack_allowed =
  4064   size_t min_stack_allowed =
  4065             (size_t)(JavaThread::stack_guard_zone_size() +
  4065             (size_t)(JavaThread::stack_guard_zone_size() +
  4066                      JavaThread::stack_shadow_zone_size() +
  4066                      JavaThread::stack_shadow_zone_size() +
  4067                      (4*BytesPerWord COMPILER2_PRESENT(+2)) * 4 * K);
  4067                      (4*BytesPerWord COMPILER2_PRESENT(+2)) * 4 * K);
  4068 
  4068 
  4069   min_stack_allowed = align_size_up(min_stack_allowed, os::vm_page_size());
  4069   min_stack_allowed = align_up(min_stack_allowed, os::vm_page_size());
  4070 
  4070 
  4071   if (actual_reserve_size < min_stack_allowed) {
  4071   if (actual_reserve_size < min_stack_allowed) {
  4072     tty->print_cr("\nThe Java thread stack size specified is too small. "
  4072     tty->print_cr("\nThe Java thread stack size specified is too small. "
  4073                   "Specify at least %dk",
  4073                   "Specify at least %dk",
  4074                   min_stack_allowed / K);
  4074                   min_stack_allowed / K);