src/os/windows/vm/os_windows.cpp

changeset 9334
95b3ba140211
parent 9327
f96fcd9e1e1b
child 9338
6c864bb55b0b
equal deleted inserted replaced
9333:2fccf735a116 9334:95b3ba140211
1 /* 1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
2185 #endif 2185 #endif
2186 2186
2187 // Windows Vista/2008 heap corruption check 2187 // Windows Vista/2008 heap corruption check
2188 #define EXCEPTION_HEAP_CORRUPTION 0xC0000374 2188 #define EXCEPTION_HEAP_CORRUPTION 0xC0000374
2189 2189
2190 #define def_excpt(val) #val, val
2191
2192 struct siglabel {
2193 char *name;
2194 int number;
2195 };
2196
2197 // All Visual C++ exceptions thrown from code generated by the Microsoft Visual 2190 // All Visual C++ exceptions thrown from code generated by the Microsoft Visual
2198 // C++ compiler contain this error code. Because this is a compiler-generated 2191 // C++ compiler contain this error code. Because this is a compiler-generated
2199 // error, the code is not listed in the Win32 API header files. 2192 // error, the code is not listed in the Win32 API header files.
2200 // The code is actually a cryptic mnemonic device, with the initial "E" 2193 // The code is actually a cryptic mnemonic device, with the initial "E"
2201 // standing for "exception" and the final 3 bytes (0x6D7363) representing the 2194 // standing for "exception" and the final 3 bytes (0x6D7363) representing the
2202 // ASCII values of "msc". 2195 // ASCII values of "msc".
2203 2196
2204 #define EXCEPTION_UNCAUGHT_CXX_EXCEPTION 0xE06D7363 2197 #define EXCEPTION_UNCAUGHT_CXX_EXCEPTION 0xE06D7363
2205 2198
2206 2199 #define def_excpt(val) { #val, (val) }
2207 struct siglabel exceptlabels[] = { 2200
2201 static const struct { char* name; uint number; } exceptlabels[] = {
2208 def_excpt(EXCEPTION_ACCESS_VIOLATION), 2202 def_excpt(EXCEPTION_ACCESS_VIOLATION),
2209 def_excpt(EXCEPTION_DATATYPE_MISALIGNMENT), 2203 def_excpt(EXCEPTION_DATATYPE_MISALIGNMENT),
2210 def_excpt(EXCEPTION_BREAKPOINT), 2204 def_excpt(EXCEPTION_BREAKPOINT),
2211 def_excpt(EXCEPTION_SINGLE_STEP), 2205 def_excpt(EXCEPTION_SINGLE_STEP),
2212 def_excpt(EXCEPTION_ARRAY_BOUNDS_EXCEEDED), 2206 def_excpt(EXCEPTION_ARRAY_BOUNDS_EXCEEDED),
2227 def_excpt(EXCEPTION_STACK_OVERFLOW), 2221 def_excpt(EXCEPTION_STACK_OVERFLOW),
2228 def_excpt(EXCEPTION_INVALID_DISPOSITION), 2222 def_excpt(EXCEPTION_INVALID_DISPOSITION),
2229 def_excpt(EXCEPTION_GUARD_PAGE), 2223 def_excpt(EXCEPTION_GUARD_PAGE),
2230 def_excpt(EXCEPTION_INVALID_HANDLE), 2224 def_excpt(EXCEPTION_INVALID_HANDLE),
2231 def_excpt(EXCEPTION_UNCAUGHT_CXX_EXCEPTION), 2225 def_excpt(EXCEPTION_UNCAUGHT_CXX_EXCEPTION),
2232 def_excpt(EXCEPTION_HEAP_CORRUPTION), 2226 def_excpt(EXCEPTION_HEAP_CORRUPTION)
2233 #ifdef _M_IA64 2227 #ifdef _M_IA64
2234 def_excpt(EXCEPTION_REG_NAT_CONSUMPTION), 2228 , def_excpt(EXCEPTION_REG_NAT_CONSUMPTION)
2235 #endif 2229 #endif
2236 NULL, 0
2237 }; 2230 };
2238 2231
2239 const char* os::exception_name(int exception_code, char *buf, size_t size) { 2232 const char* os::exception_name(int exception_code, char *buf, size_t size) {
2240 for (int i = 0; exceptlabels[i].name != NULL; i++) { 2233 uint code = static_cast<uint>(exception_code);
2241 if (exceptlabels[i].number == exception_code) { 2234 for (uint i = 0; i < ARRAY_SIZE(exceptlabels); ++i) {
2235 if (exceptlabels[i].number == code) {
2242 jio_snprintf(buf, size, "%s", exceptlabels[i].name); 2236 jio_snprintf(buf, size, "%s", exceptlabels[i].name);
2243 return buf; 2237 return buf;
2244 } 2238 }
2245 } 2239 }
2246 2240
5780 // do an allocation at an address selected by the OS to get a good one. 5774 // do an allocation at an address selected by the OS to get a good one.
5781 const size_t large_allocation_size = os::large_page_size() * 4; 5775 const size_t large_allocation_size = os::large_page_size() * 4;
5782 char* result = os::reserve_memory_special(large_allocation_size, os::large_page_size(), NULL, false); 5776 char* result = os::reserve_memory_special(large_allocation_size, os::large_page_size(), NULL, false);
5783 if (result == NULL) { 5777 if (result == NULL) {
5784 if (VerboseInternalVMTests) { 5778 if (VerboseInternalVMTests) {
5785 gclog_or_tty->print("Failed to allocate control block with size " SIZE_FORMAT ". Skipping remainder of test.", 5779 gclog_or_tty->print("Failed to allocate control block with size "SIZE_FORMAT". Skipping remainder of test.",
5786 large_allocation_size); 5780 large_allocation_size);
5787 } 5781 }
5788 } else { 5782 } else {
5789 os::release_memory_special(result, large_allocation_size); 5783 os::release_memory_special(result, large_allocation_size);
5790 5784
5793 const size_t expected_allocation_size = os::large_page_size(); 5787 const size_t expected_allocation_size = os::large_page_size();
5794 char* expected_location = result + os::large_page_size(); 5788 char* expected_location = result + os::large_page_size();
5795 char* actual_location = os::reserve_memory_special(expected_allocation_size, os::large_page_size(), expected_location, false); 5789 char* actual_location = os::reserve_memory_special(expected_allocation_size, os::large_page_size(), expected_location, false);
5796 if (actual_location == NULL) { 5790 if (actual_location == NULL) {
5797 if (VerboseInternalVMTests) { 5791 if (VerboseInternalVMTests) {
5798 gclog_or_tty->print("Failed to allocate any memory at " PTR_FORMAT " size " SIZE_FORMAT ". Skipping remainder of test.", 5792 gclog_or_tty->print("Failed to allocate any memory at "PTR_FORMAT" size "SIZE_FORMAT". Skipping remainder of test.",
5799 expected_location, large_allocation_size); 5793 expected_location, large_allocation_size);
5800 } 5794 }
5801 } else { 5795 } else {
5802 // release memory 5796 // release memory
5803 os::release_memory_special(actual_location, expected_allocation_size); 5797 os::release_memory_special(actual_location, expected_allocation_size);
5804 // only now check, after releasing any memory to avoid any leaks. 5798 // only now check, after releasing any memory to avoid any leaks.
5805 assert(actual_location == expected_location, 5799 assert(actual_location == expected_location,
5806 err_msg("Failed to allocate memory at requested location " PTR_FORMAT " of size " SIZE_FORMAT ", is " PTR_FORMAT " instead", 5800 err_msg("Failed to allocate memory at requested location "PTR_FORMAT" of size "SIZE_FORMAT", is "PTR_FORMAT" instead",
5807 expected_location, expected_allocation_size, actual_location)); 5801 expected_location, expected_allocation_size, actual_location));
5808 } 5802 }
5809 } 5803 }
5810 5804
5811 // restore globals 5805 // restore globals

mercurial