Wed, 03 Jul 2019 20:42:37 +0800
Merge
aoqi@0 | 1 | /* |
mchinnathamb@9058 | 2 | * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #include "precompiled.hpp" |
aoqi@0 | 26 | #include "classfile/systemDictionary.hpp" |
aoqi@0 | 27 | #include "code/codeCache.hpp" |
aoqi@0 | 28 | #include "code/icBuffer.hpp" |
aoqi@0 | 29 | #include "code/nmethod.hpp" |
aoqi@0 | 30 | #include "code/vtableStubs.hpp" |
aoqi@0 | 31 | #include "compiler/compileBroker.hpp" |
aoqi@0 | 32 | #include "compiler/disassembler.hpp" |
aoqi@0 | 33 | #include "gc_implementation/shared/markSweep.hpp" |
aoqi@0 | 34 | #include "gc_interface/collectedHeap.hpp" |
aoqi@0 | 35 | #include "interpreter/bytecodeHistogram.hpp" |
aoqi@0 | 36 | #include "interpreter/interpreter.hpp" |
aoqi@0 | 37 | #include "memory/resourceArea.hpp" |
aoqi@0 | 38 | #include "memory/universe.hpp" |
aoqi@0 | 39 | #include "oops/oop.inline.hpp" |
aoqi@0 | 40 | #include "prims/privilegedStack.hpp" |
aoqi@0 | 41 | #include "runtime/arguments.hpp" |
aoqi@0 | 42 | #include "runtime/frame.hpp" |
aoqi@0 | 43 | #include "runtime/java.hpp" |
aoqi@0 | 44 | #include "runtime/sharedRuntime.hpp" |
aoqi@0 | 45 | #include "runtime/stubCodeGenerator.hpp" |
aoqi@0 | 46 | #include "runtime/stubRoutines.hpp" |
aoqi@0 | 47 | #include "runtime/thread.inline.hpp" |
aoqi@0 | 48 | #include "runtime/vframe.hpp" |
aoqi@0 | 49 | #include "services/heapDumper.hpp" |
aoqi@0 | 50 | #include "utilities/defaultStream.hpp" |
aoqi@0 | 51 | #include "utilities/events.hpp" |
aoqi@0 | 52 | #include "utilities/top.hpp" |
aoqi@0 | 53 | #include "utilities/vmError.hpp" |
aoqi@0 | 54 | #ifdef TARGET_OS_FAMILY_linux |
aoqi@0 | 55 | # include "os_linux.inline.hpp" |
aoqi@0 | 56 | #endif |
aoqi@0 | 57 | #ifdef TARGET_OS_FAMILY_solaris |
aoqi@0 | 58 | # include "os_solaris.inline.hpp" |
aoqi@0 | 59 | #endif |
aoqi@0 | 60 | #ifdef TARGET_OS_FAMILY_windows |
aoqi@0 | 61 | # include "os_windows.inline.hpp" |
aoqi@0 | 62 | #endif |
aoqi@0 | 63 | #ifdef TARGET_OS_FAMILY_bsd |
aoqi@0 | 64 | # include "os_bsd.inline.hpp" |
aoqi@0 | 65 | #endif |
aoqi@0 | 66 | |
aoqi@0 | 67 | #ifndef ASSERT |
aoqi@0 | 68 | # ifdef _DEBUG |
aoqi@0 | 69 | // NOTE: don't turn the lines below into a comment -- if you're getting |
aoqi@0 | 70 | // a compile error here, change the settings to define ASSERT |
aoqi@0 | 71 | ASSERT should be defined when _DEBUG is defined. It is not intended to be used for debugging |
aoqi@0 | 72 | functions that do not slow down the system too much and thus can be left in optimized code. |
aoqi@0 | 73 | On the other hand, the code should not be included in a production version. |
aoqi@0 | 74 | # endif // _DEBUG |
aoqi@0 | 75 | #endif // ASSERT |
aoqi@0 | 76 | |
aoqi@0 | 77 | |
aoqi@0 | 78 | #ifdef _DEBUG |
aoqi@0 | 79 | # ifndef ASSERT |
aoqi@0 | 80 | configuration error: ASSERT must be defined in debug version |
aoqi@0 | 81 | # endif // ASSERT |
aoqi@0 | 82 | #endif // _DEBUG |
aoqi@0 | 83 | |
aoqi@0 | 84 | |
aoqi@0 | 85 | #ifdef PRODUCT |
aoqi@0 | 86 | # if -defined _DEBUG || -defined ASSERT |
aoqi@0 | 87 | configuration error: ASSERT et al. must not be defined in PRODUCT version |
aoqi@0 | 88 | # endif |
aoqi@0 | 89 | #endif // PRODUCT |
aoqi@0 | 90 | |
aoqi@0 | 91 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
aoqi@0 | 92 | |
aoqi@0 | 93 | FormatBufferResource::FormatBufferResource(const char * format, ...) |
aoqi@0 | 94 | : FormatBufferBase((char*)resource_allocate_bytes(RES_BUFSZ)) { |
aoqi@0 | 95 | va_list argp; |
aoqi@0 | 96 | va_start(argp, format); |
aoqi@0 | 97 | jio_vsnprintf(_buf, RES_BUFSZ, format, argp); |
aoqi@0 | 98 | va_end(argp); |
aoqi@0 | 99 | } |
aoqi@0 | 100 | |
aoqi@0 | 101 | ATTRIBUTE_PRINTF(1, 2) |
aoqi@0 | 102 | void warning(const char* format, ...) { |
aoqi@0 | 103 | if (PrintWarnings) { |
aoqi@0 | 104 | FILE* const err = defaultStream::error_stream(); |
aoqi@0 | 105 | jio_fprintf(err, "%s warning: ", VM_Version::vm_name()); |
aoqi@0 | 106 | va_list ap; |
aoqi@0 | 107 | va_start(ap, format); |
aoqi@0 | 108 | vfprintf(err, format, ap); |
aoqi@0 | 109 | va_end(ap); |
aoqi@0 | 110 | fputc('\n', err); |
aoqi@0 | 111 | } |
aoqi@0 | 112 | if (BreakAtWarning) BREAKPOINT; |
aoqi@0 | 113 | } |
aoqi@0 | 114 | |
aoqi@0 | 115 | #ifndef PRODUCT |
aoqi@0 | 116 | |
aoqi@0 | 117 | #define is_token_break(ch) (isspace(ch) || (ch) == ',') |
aoqi@0 | 118 | |
aoqi@0 | 119 | static const char* last_file_name = NULL; |
aoqi@0 | 120 | static int last_line_no = -1; |
aoqi@0 | 121 | |
aoqi@0 | 122 | // assert/guarantee/... may happen very early during VM initialization. |
aoqi@0 | 123 | // Don't rely on anything that is initialized by Threads::create_vm(). For |
aoqi@0 | 124 | // example, don't use tty. |
aoqi@0 | 125 | bool error_is_suppressed(const char* file_name, int line_no) { |
aoqi@0 | 126 | // The following 1-element cache requires that passed-in |
aoqi@0 | 127 | // file names are always only constant literals. |
aoqi@0 | 128 | if (file_name == last_file_name && line_no == last_line_no) return true; |
aoqi@0 | 129 | |
aoqi@0 | 130 | int file_name_len = (int)strlen(file_name); |
aoqi@0 | 131 | char separator = os::file_separator()[0]; |
aoqi@0 | 132 | const char* base_name = strrchr(file_name, separator); |
aoqi@0 | 133 | if (base_name == NULL) |
aoqi@0 | 134 | base_name = file_name; |
aoqi@0 | 135 | |
aoqi@0 | 136 | // scan the SuppressErrorAt option |
aoqi@0 | 137 | const char* cp = SuppressErrorAt; |
aoqi@0 | 138 | for (;;) { |
aoqi@0 | 139 | const char* sfile; |
aoqi@0 | 140 | int sfile_len; |
aoqi@0 | 141 | int sline; |
aoqi@0 | 142 | bool noisy; |
aoqi@0 | 143 | while ((*cp) != '\0' && is_token_break(*cp)) cp++; |
aoqi@0 | 144 | if ((*cp) == '\0') break; |
aoqi@0 | 145 | sfile = cp; |
aoqi@0 | 146 | while ((*cp) != '\0' && !is_token_break(*cp) && (*cp) != ':') cp++; |
aoqi@0 | 147 | sfile_len = cp - sfile; |
aoqi@0 | 148 | if ((*cp) == ':') cp++; |
aoqi@0 | 149 | sline = 0; |
aoqi@0 | 150 | while ((*cp) != '\0' && isdigit(*cp)) { |
aoqi@0 | 151 | sline *= 10; |
aoqi@0 | 152 | sline += (*cp) - '0'; |
aoqi@0 | 153 | cp++; |
aoqi@0 | 154 | } |
aoqi@0 | 155 | // "file:line!" means the assert suppression is not silent |
aoqi@0 | 156 | noisy = ((*cp) == '!'); |
aoqi@0 | 157 | while ((*cp) != '\0' && !is_token_break(*cp)) cp++; |
aoqi@0 | 158 | // match the line |
aoqi@0 | 159 | if (sline != 0) { |
aoqi@0 | 160 | if (sline != line_no) continue; |
aoqi@0 | 161 | } |
aoqi@0 | 162 | // match the file |
aoqi@0 | 163 | if (sfile_len > 0) { |
aoqi@0 | 164 | const char* look = file_name; |
aoqi@0 | 165 | const char* look_max = file_name + file_name_len - sfile_len; |
aoqi@0 | 166 | const char* foundp; |
aoqi@0 | 167 | bool match = false; |
aoqi@0 | 168 | while (!match |
aoqi@0 | 169 | && (foundp = strchr(look, sfile[0])) != NULL |
aoqi@0 | 170 | && foundp <= look_max) { |
aoqi@0 | 171 | match = true; |
aoqi@0 | 172 | for (int i = 1; i < sfile_len; i++) { |
aoqi@0 | 173 | if (sfile[i] != foundp[i]) { |
aoqi@0 | 174 | match = false; |
aoqi@0 | 175 | break; |
aoqi@0 | 176 | } |
aoqi@0 | 177 | } |
aoqi@0 | 178 | look = foundp + 1; |
aoqi@0 | 179 | } |
aoqi@0 | 180 | if (!match) continue; |
aoqi@0 | 181 | } |
aoqi@0 | 182 | // got a match! |
aoqi@0 | 183 | if (noisy) { |
aoqi@0 | 184 | fdStream out(defaultStream::output_fd()); |
aoqi@0 | 185 | out.print_raw("[error suppressed at "); |
aoqi@0 | 186 | out.print_raw(base_name); |
aoqi@0 | 187 | char buf[16]; |
aoqi@0 | 188 | jio_snprintf(buf, sizeof(buf), ":%d]", line_no); |
aoqi@0 | 189 | out.print_raw_cr(buf); |
aoqi@0 | 190 | } else { |
aoqi@0 | 191 | // update 1-element cache for fast silent matches |
aoqi@0 | 192 | last_file_name = file_name; |
aoqi@0 | 193 | last_line_no = line_no; |
aoqi@0 | 194 | } |
aoqi@0 | 195 | return true; |
aoqi@0 | 196 | } |
aoqi@0 | 197 | |
aoqi@0 | 198 | if (!is_error_reported()) { |
aoqi@0 | 199 | // print a friendly hint: |
aoqi@0 | 200 | fdStream out(defaultStream::output_fd()); |
aoqi@0 | 201 | out.print_raw_cr("# To suppress the following error report, specify this argument"); |
aoqi@0 | 202 | out.print_raw ("# after -XX: or in .hotspotrc: SuppressErrorAt="); |
aoqi@0 | 203 | out.print_raw (base_name); |
aoqi@0 | 204 | char buf[16]; |
aoqi@0 | 205 | jio_snprintf(buf, sizeof(buf), ":%d", line_no); |
aoqi@0 | 206 | out.print_raw_cr(buf); |
aoqi@0 | 207 | } |
aoqi@0 | 208 | return false; |
aoqi@0 | 209 | } |
aoqi@0 | 210 | |
aoqi@0 | 211 | #undef is_token_break |
aoqi@0 | 212 | |
aoqi@0 | 213 | #else |
aoqi@0 | 214 | |
aoqi@0 | 215 | // Place-holder for non-existent suppression check: |
aoqi@0 | 216 | #define error_is_suppressed(file_name, line_no) (false) |
aoqi@0 | 217 | |
aoqi@0 | 218 | #endif // !PRODUCT |
aoqi@0 | 219 | |
aoqi@0 | 220 | void report_vm_error(const char* file, int line, const char* error_msg, |
aoqi@0 | 221 | const char* detail_msg) |
aoqi@0 | 222 | { |
aoqi@0 | 223 | if (Debugging || error_is_suppressed(file, line)) return; |
aoqi@0 | 224 | Thread* const thread = ThreadLocalStorage::get_thread_slow(); |
aoqi@0 | 225 | VMError err(thread, file, line, error_msg, detail_msg); |
aoqi@0 | 226 | err.report_and_die(); |
aoqi@0 | 227 | } |
aoqi@0 | 228 | |
aoqi@0 | 229 | void report_fatal(const char* file, int line, const char* message) |
aoqi@0 | 230 | { |
aoqi@0 | 231 | report_vm_error(file, line, "fatal error", message); |
aoqi@0 | 232 | } |
aoqi@0 | 233 | |
aoqi@0 | 234 | void report_vm_out_of_memory(const char* file, int line, size_t size, |
aoqi@0 | 235 | VMErrorType vm_err_type, const char* message) { |
aoqi@0 | 236 | if (Debugging) return; |
aoqi@0 | 237 | |
aoqi@0 | 238 | Thread* thread = ThreadLocalStorage::get_thread_slow(); |
aoqi@0 | 239 | VMError(thread, file, line, size, vm_err_type, message).report_and_die(); |
aoqi@0 | 240 | |
aoqi@0 | 241 | // The UseOSErrorReporting option in report_and_die() may allow a return |
aoqi@0 | 242 | // to here. If so then we'll have to figure out how to handle it. |
aoqi@0 | 243 | guarantee(false, "report_and_die() should not return here"); |
aoqi@0 | 244 | } |
aoqi@0 | 245 | |
aoqi@0 | 246 | void report_should_not_call(const char* file, int line) { |
aoqi@0 | 247 | report_vm_error(file, line, "ShouldNotCall()"); |
aoqi@0 | 248 | } |
aoqi@0 | 249 | |
aoqi@0 | 250 | void report_should_not_reach_here(const char* file, int line) { |
aoqi@0 | 251 | report_vm_error(file, line, "ShouldNotReachHere()"); |
aoqi@0 | 252 | } |
aoqi@0 | 253 | |
aoqi@0 | 254 | void report_unimplemented(const char* file, int line) { |
aoqi@0 | 255 | report_vm_error(file, line, "Unimplemented()"); |
aoqi@0 | 256 | } |
aoqi@0 | 257 | |
aoqi@0 | 258 | void report_untested(const char* file, int line, const char* message) { |
aoqi@0 | 259 | #ifndef PRODUCT |
aoqi@0 | 260 | warning("Untested: %s in %s: %d\n", message, file, line); |
aoqi@0 | 261 | #endif // !PRODUCT |
aoqi@0 | 262 | } |
aoqi@0 | 263 | |
aoqi@0 | 264 | void report_out_of_shared_space(SharedSpaceType shared_space) { |
aoqi@0 | 265 | static const char* name[] = { |
aoqi@0 | 266 | "native memory for metadata", |
aoqi@0 | 267 | "shared read only space", |
aoqi@0 | 268 | "shared read write space", |
ccheung@7300 | 269 | "shared miscellaneous data space", |
ccheung@7300 | 270 | "shared miscellaneous code space" |
aoqi@0 | 271 | }; |
aoqi@0 | 272 | static const char* flag[] = { |
aoqi@0 | 273 | "Metaspace", |
aoqi@0 | 274 | "SharedReadOnlySize", |
aoqi@0 | 275 | "SharedReadWriteSize", |
ccheung@7300 | 276 | "SharedMiscDataSize", |
ccheung@7300 | 277 | "SharedMiscCodeSize" |
aoqi@0 | 278 | }; |
aoqi@0 | 279 | |
aoqi@0 | 280 | warning("\nThe %s is not large enough\n" |
ccheung@7300 | 281 | "to preload requested classes. Use -XX:%s=<size>\n" |
aoqi@0 | 282 | "to increase the initial size of %s.\n", |
aoqi@0 | 283 | name[shared_space], flag[shared_space], name[shared_space]); |
aoqi@0 | 284 | exit(2); |
aoqi@0 | 285 | } |
aoqi@0 | 286 | |
aoqi@0 | 287 | void report_java_out_of_memory(const char* message) { |
aoqi@0 | 288 | static jint out_of_memory_reported = 0; |
aoqi@0 | 289 | |
aoqi@0 | 290 | // A number of threads may attempt to report OutOfMemoryError at around the |
aoqi@0 | 291 | // same time. To avoid dumping the heap or executing the data collection |
aoqi@0 | 292 | // commands multiple times we just do it once when the first threads reports |
aoqi@0 | 293 | // the error. |
aoqi@0 | 294 | if (Atomic::cmpxchg(1, &out_of_memory_reported, 0) == 0) { |
aoqi@0 | 295 | // create heap dump before OnOutOfMemoryError commands are executed |
aoqi@0 | 296 | if (HeapDumpOnOutOfMemoryError) { |
aoqi@0 | 297 | tty->print_cr("java.lang.OutOfMemoryError: %s", message); |
aoqi@0 | 298 | HeapDumper::dump_heap_from_oome(); |
aoqi@0 | 299 | } |
aoqi@0 | 300 | |
aoqi@0 | 301 | if (OnOutOfMemoryError && OnOutOfMemoryError[0]) { |
aoqi@0 | 302 | VMError err(message); |
aoqi@0 | 303 | err.report_java_out_of_memory(); |
aoqi@0 | 304 | } |
kevinw@8209 | 305 | |
kevinw@8209 | 306 | if (CrashOnOutOfMemoryError) { |
kevinw@8209 | 307 | tty->print_cr("Aborting due to java.lang.OutOfMemoryError: %s", message); |
kevinw@8209 | 308 | fatal(err_msg("OutOfMemory encountered: %s", message)); |
kevinw@8209 | 309 | } |
kevinw@8209 | 310 | |
kevinw@8209 | 311 | if (ExitOnOutOfMemoryError) { |
kevinw@8209 | 312 | tty->print_cr("Terminating due to java.lang.OutOfMemoryError: %s", message); |
kevinw@8209 | 313 | exit(3); |
kevinw@8209 | 314 | } |
aoqi@0 | 315 | } |
aoqi@0 | 316 | } |
aoqi@0 | 317 | |
mchinnathamb@9058 | 318 | void report_insufficient_metaspace(size_t required_size) { |
mchinnathamb@9058 | 319 | warning("\nThe MaxMetaspaceSize of " SIZE_FORMAT " bytes is not large enough.\n" |
mchinnathamb@9058 | 320 | "Either don't specify the -XX:MaxMetaspaceSize=<size>\n" |
mchinnathamb@9058 | 321 | "or increase the size to at least " SIZE_FORMAT ".\n", |
mchinnathamb@9058 | 322 | MaxMetaspaceSize, required_size); |
mchinnathamb@9058 | 323 | exit(2); |
mchinnathamb@9058 | 324 | } |
mchinnathamb@9058 | 325 | |
aoqi@0 | 326 | static bool error_reported = false; |
aoqi@0 | 327 | |
aoqi@0 | 328 | // call this when the VM is dying--it might loosen some asserts |
aoqi@0 | 329 | void set_error_reported() { |
aoqi@0 | 330 | error_reported = true; |
aoqi@0 | 331 | } |
aoqi@0 | 332 | |
aoqi@0 | 333 | bool is_error_reported() { |
aoqi@0 | 334 | return error_reported; |
aoqi@0 | 335 | } |
aoqi@0 | 336 | |
aoqi@0 | 337 | #ifndef PRODUCT |
aoqi@0 | 338 | #include <signal.h> |
aoqi@0 | 339 | |
aoqi@0 | 340 | void test_error_handler() { |
aoqi@0 | 341 | uintx test_num = ErrorHandlerTest; |
aoqi@0 | 342 | if (test_num == 0) return; |
aoqi@0 | 343 | |
aoqi@0 | 344 | // If asserts are disabled, use the corresponding guarantee instead. |
aoqi@0 | 345 | size_t n = test_num; |
aoqi@0 | 346 | NOT_DEBUG(if (n <= 2) n += 2); |
aoqi@0 | 347 | |
aoqi@0 | 348 | const char* const str = "hello"; |
aoqi@0 | 349 | const size_t num = (size_t)os::vm_page_size(); |
aoqi@0 | 350 | |
aoqi@0 | 351 | const char* const eol = os::line_separator(); |
aoqi@0 | 352 | const char* const msg = "this message should be truncated during formatting"; |
aoqi@0 | 353 | char * const dataPtr = NULL; // bad data pointer |
aoqi@0 | 354 | const void (*funcPtr)(void) = (const void(*)()) 0xF; // bad function pointer |
aoqi@0 | 355 | |
aoqi@0 | 356 | // Keep this in sync with test/runtime/6888954/vmerrors.sh. |
aoqi@0 | 357 | switch (n) { |
aoqi@0 | 358 | case 1: assert(str == NULL, "expected null"); |
aoqi@0 | 359 | case 2: assert(num == 1023 && *str == 'X', |
aoqi@0 | 360 | err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str)); |
aoqi@0 | 361 | case 3: guarantee(str == NULL, "expected null"); |
aoqi@0 | 362 | case 4: guarantee(num == 1023 && *str == 'X', |
aoqi@0 | 363 | err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str)); |
aoqi@0 | 364 | case 5: fatal("expected null"); |
aoqi@0 | 365 | case 6: fatal(err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str)); |
aoqi@0 | 366 | case 7: fatal(err_msg("%s%s# %s%s# %s%s# %s%s# %s%s# " |
aoqi@0 | 367 | "%s%s# %s%s# %s%s# %s%s# %s%s# " |
aoqi@0 | 368 | "%s%s# %s%s# %s%s# %s%s# %s", |
aoqi@0 | 369 | msg, eol, msg, eol, msg, eol, msg, eol, msg, eol, |
aoqi@0 | 370 | msg, eol, msg, eol, msg, eol, msg, eol, msg, eol, |
aoqi@0 | 371 | msg, eol, msg, eol, msg, eol, msg, eol, msg)); |
aoqi@0 | 372 | case 8: vm_exit_out_of_memory(num, OOM_MALLOC_ERROR, "ChunkPool::allocate"); |
aoqi@0 | 373 | case 9: ShouldNotCallThis(); |
aoqi@0 | 374 | case 10: ShouldNotReachHere(); |
aoqi@0 | 375 | case 11: Unimplemented(); |
aoqi@0 | 376 | // There's no guarantee the bad data pointer will crash us |
aoqi@0 | 377 | // so "break" out to the ShouldNotReachHere(). |
aoqi@0 | 378 | case 12: *dataPtr = '\0'; break; |
aoqi@0 | 379 | // There's no guarantee the bad function pointer will crash us |
aoqi@0 | 380 | // so "break" out to the ShouldNotReachHere(). |
aoqi@0 | 381 | case 13: (*funcPtr)(); break; |
aoqi@0 | 382 | |
aoqi@0 | 383 | default: tty->print_cr("ERROR: %d: unexpected test_num value.", n); |
aoqi@0 | 384 | } |
aoqi@0 | 385 | ShouldNotReachHere(); |
aoqi@0 | 386 | } |
aoqi@0 | 387 | #endif // !PRODUCT |
aoqi@0 | 388 | |
aoqi@0 | 389 | // ------ helper functions for debugging go here ------------ |
aoqi@0 | 390 | |
aoqi@0 | 391 | // All debug entries should be wrapped with a stack allocated |
aoqi@0 | 392 | // Command object. It makes sure a resource mark is set and |
aoqi@0 | 393 | // flushes the logfile to prevent file sharing problems. |
aoqi@0 | 394 | |
aoqi@0 | 395 | class Command : public StackObj { |
aoqi@0 | 396 | private: |
aoqi@0 | 397 | ResourceMark rm; |
aoqi@0 | 398 | ResetNoHandleMark rnhm; |
aoqi@0 | 399 | HandleMark hm; |
aoqi@0 | 400 | bool debug_save; |
aoqi@0 | 401 | public: |
aoqi@0 | 402 | static int level; |
aoqi@0 | 403 | Command(const char* str) { |
aoqi@0 | 404 | debug_save = Debugging; |
aoqi@0 | 405 | Debugging = true; |
aoqi@0 | 406 | if (level++ > 0) return; |
aoqi@0 | 407 | tty->cr(); |
aoqi@0 | 408 | tty->print_cr("\"Executing %s\"", str); |
aoqi@0 | 409 | } |
aoqi@0 | 410 | |
aoqi@0 | 411 | ~Command() { |
aoqi@0 | 412 | tty->flush(); |
aoqi@0 | 413 | Debugging = debug_save; |
aoqi@0 | 414 | level--; |
aoqi@0 | 415 | } |
aoqi@0 | 416 | }; |
aoqi@0 | 417 | |
aoqi@0 | 418 | int Command::level = 0; |
aoqi@0 | 419 | |
aoqi@0 | 420 | #ifndef PRODUCT |
aoqi@0 | 421 | |
aoqi@0 | 422 | extern "C" void blob(CodeBlob* cb) { |
aoqi@0 | 423 | Command c("blob"); |
aoqi@0 | 424 | cb->print(); |
aoqi@0 | 425 | } |
aoqi@0 | 426 | |
aoqi@0 | 427 | |
aoqi@0 | 428 | extern "C" void dump_vtable(address p) { |
aoqi@0 | 429 | Command c("dump_vtable"); |
aoqi@0 | 430 | Klass* k = (Klass*)p; |
aoqi@0 | 431 | InstanceKlass::cast(k)->vtable()->print(); |
aoqi@0 | 432 | } |
aoqi@0 | 433 | |
aoqi@0 | 434 | |
aoqi@0 | 435 | extern "C" void nm(intptr_t p) { |
aoqi@0 | 436 | // Actually we look through all CodeBlobs (the nm name has been kept for backwards compatability) |
aoqi@0 | 437 | Command c("nm"); |
aoqi@0 | 438 | CodeBlob* cb = CodeCache::find_blob((address)p); |
aoqi@0 | 439 | if (cb == NULL) { |
aoqi@0 | 440 | tty->print_cr("NULL"); |
aoqi@0 | 441 | } else { |
aoqi@0 | 442 | cb->print(); |
aoqi@0 | 443 | } |
aoqi@0 | 444 | } |
aoqi@0 | 445 | |
aoqi@0 | 446 | |
aoqi@0 | 447 | extern "C" void disnm(intptr_t p) { |
aoqi@0 | 448 | Command c("disnm"); |
aoqi@0 | 449 | CodeBlob* cb = CodeCache::find_blob((address) p); |
aoqi@0 | 450 | nmethod* nm = cb->as_nmethod_or_null(); |
aoqi@0 | 451 | if (nm) { |
aoqi@0 | 452 | nm->print(); |
aoqi@0 | 453 | Disassembler::decode(nm); |
aoqi@0 | 454 | } else { |
aoqi@0 | 455 | cb->print(); |
aoqi@0 | 456 | Disassembler::decode(cb); |
aoqi@0 | 457 | } |
aoqi@0 | 458 | } |
aoqi@0 | 459 | |
aoqi@0 | 460 | |
aoqi@0 | 461 | extern "C" void printnm(intptr_t p) { |
aoqi@0 | 462 | char buffer[256]; |
aoqi@0 | 463 | sprintf(buffer, "printnm: " INTPTR_FORMAT, p); |
aoqi@0 | 464 | Command c(buffer); |
aoqi@0 | 465 | CodeBlob* cb = CodeCache::find_blob((address) p); |
aoqi@0 | 466 | if (cb->is_nmethod()) { |
aoqi@0 | 467 | nmethod* nm = (nmethod*)cb; |
aoqi@0 | 468 | nm->print_nmethod(true); |
aoqi@0 | 469 | } |
aoqi@0 | 470 | } |
aoqi@0 | 471 | |
aoqi@0 | 472 | |
aoqi@0 | 473 | extern "C" void universe() { |
aoqi@0 | 474 | Command c("universe"); |
aoqi@0 | 475 | Universe::print(); |
aoqi@0 | 476 | } |
aoqi@0 | 477 | |
aoqi@0 | 478 | |
aoqi@0 | 479 | extern "C" void verify() { |
aoqi@0 | 480 | // try to run a verify on the entire system |
aoqi@0 | 481 | // note: this may not be safe if we're not at a safepoint; for debugging, |
aoqi@0 | 482 | // this manipulates the safepoint settings to avoid assertion failures |
aoqi@0 | 483 | Command c("universe verify"); |
aoqi@0 | 484 | bool safe = SafepointSynchronize::is_at_safepoint(); |
aoqi@0 | 485 | if (!safe) { |
aoqi@0 | 486 | tty->print_cr("warning: not at safepoint -- verify may fail"); |
aoqi@0 | 487 | SafepointSynchronize::set_is_at_safepoint(); |
aoqi@0 | 488 | } |
aoqi@0 | 489 | // Ensure Eden top is correct before verification |
aoqi@0 | 490 | Universe::heap()->prepare_for_verify(); |
aoqi@0 | 491 | Universe::verify(); |
aoqi@0 | 492 | if (!safe) SafepointSynchronize::set_is_not_at_safepoint(); |
aoqi@0 | 493 | } |
aoqi@0 | 494 | |
aoqi@0 | 495 | |
aoqi@0 | 496 | extern "C" void pp(void* p) { |
aoqi@0 | 497 | Command c("pp"); |
aoqi@0 | 498 | FlagSetting fl(PrintVMMessages, true); |
aoqi@0 | 499 | FlagSetting f2(DisplayVMOutput, true); |
aoqi@0 | 500 | if (Universe::heap()->is_in(p)) { |
aoqi@0 | 501 | oop obj = oop(p); |
aoqi@0 | 502 | obj->print(); |
aoqi@0 | 503 | } else { |
aoqi@0 | 504 | tty->print(PTR_FORMAT, p); |
aoqi@0 | 505 | } |
aoqi@0 | 506 | } |
aoqi@0 | 507 | |
aoqi@0 | 508 | |
aoqi@0 | 509 | // pv: print vm-printable object |
aoqi@0 | 510 | extern "C" void pa(intptr_t p) { ((AllocatedObj*) p)->print(); } |
aoqi@0 | 511 | extern "C" void findpc(intptr_t x); |
aoqi@0 | 512 | |
aoqi@0 | 513 | #endif // !PRODUCT |
aoqi@0 | 514 | |
aoqi@0 | 515 | extern "C" void ps() { // print stack |
aoqi@0 | 516 | if (Thread::current() == NULL) return; |
aoqi@0 | 517 | Command c("ps"); |
aoqi@0 | 518 | |
aoqi@0 | 519 | |
aoqi@0 | 520 | // Prints the stack of the current Java thread |
aoqi@0 | 521 | JavaThread* p = JavaThread::active(); |
aoqi@0 | 522 | tty->print(" for thread: "); |
aoqi@0 | 523 | p->print(); |
aoqi@0 | 524 | tty->cr(); |
aoqi@0 | 525 | |
aoqi@0 | 526 | if (p->has_last_Java_frame()) { |
aoqi@0 | 527 | // If the last_Java_fp is set we are in C land and |
aoqi@0 | 528 | // can call the standard stack_trace function. |
aoqi@0 | 529 | #ifdef PRODUCT |
aoqi@0 | 530 | p->print_stack(); |
aoqi@0 | 531 | } else { |
aoqi@0 | 532 | tty->print_cr("Cannot find the last Java frame, printing stack disabled."); |
aoqi@0 | 533 | #else // !PRODUCT |
aoqi@0 | 534 | p->trace_stack(); |
aoqi@0 | 535 | } else { |
aoqi@0 | 536 | frame f = os::current_frame(); |
aoqi@0 | 537 | RegisterMap reg_map(p); |
aoqi@0 | 538 | f = f.sender(®_map); |
aoqi@0 | 539 | tty->print("(guessing starting frame id=%#p based on current fp)\n", f.id()); |
aoqi@0 | 540 | p->trace_stack_from(vframe::new_vframe(&f, ®_map, p)); |
aoqi@0 | 541 | pd_ps(f); |
aoqi@0 | 542 | #endif // PRODUCT |
aoqi@0 | 543 | } |
aoqi@0 | 544 | |
aoqi@0 | 545 | } |
aoqi@0 | 546 | |
aoqi@0 | 547 | extern "C" void pfl() { |
aoqi@0 | 548 | // print frame layout |
aoqi@0 | 549 | Command c("pfl"); |
aoqi@0 | 550 | JavaThread* p = JavaThread::active(); |
aoqi@0 | 551 | tty->print(" for thread: "); |
aoqi@0 | 552 | p->print(); |
aoqi@0 | 553 | tty->cr(); |
aoqi@0 | 554 | if (p->has_last_Java_frame()) { |
aoqi@0 | 555 | p->print_frame_layout(); |
aoqi@0 | 556 | } |
aoqi@0 | 557 | } |
aoqi@0 | 558 | |
aoqi@0 | 559 | #ifndef PRODUCT |
aoqi@0 | 560 | |
aoqi@0 | 561 | extern "C" void psf() { // print stack frames |
aoqi@0 | 562 | { |
aoqi@0 | 563 | Command c("psf"); |
aoqi@0 | 564 | JavaThread* p = JavaThread::active(); |
aoqi@0 | 565 | tty->print(" for thread: "); |
aoqi@0 | 566 | p->print(); |
aoqi@0 | 567 | tty->cr(); |
aoqi@0 | 568 | if (p->has_last_Java_frame()) { |
aoqi@0 | 569 | p->trace_frames(); |
aoqi@0 | 570 | } |
aoqi@0 | 571 | } |
aoqi@0 | 572 | } |
aoqi@0 | 573 | |
aoqi@0 | 574 | |
aoqi@0 | 575 | extern "C" void threads() { |
aoqi@0 | 576 | Command c("threads"); |
aoqi@0 | 577 | Threads::print(false, true); |
aoqi@0 | 578 | } |
aoqi@0 | 579 | |
aoqi@0 | 580 | |
aoqi@0 | 581 | extern "C" void psd() { |
aoqi@0 | 582 | Command c("psd"); |
aoqi@0 | 583 | SystemDictionary::print(); |
aoqi@0 | 584 | } |
aoqi@0 | 585 | |
aoqi@0 | 586 | |
aoqi@0 | 587 | extern "C" void safepoints() { |
aoqi@0 | 588 | Command c("safepoints"); |
aoqi@0 | 589 | SafepointSynchronize::print_state(); |
aoqi@0 | 590 | } |
aoqi@0 | 591 | |
aoqi@0 | 592 | #endif // !PRODUCT |
aoqi@0 | 593 | |
aoqi@0 | 594 | extern "C" void pss() { // print all stacks |
aoqi@0 | 595 | if (Thread::current() == NULL) return; |
aoqi@0 | 596 | Command c("pss"); |
aoqi@0 | 597 | Threads::print(true, PRODUCT_ONLY(false) NOT_PRODUCT(true)); |
aoqi@0 | 598 | } |
aoqi@0 | 599 | |
aoqi@0 | 600 | #ifndef PRODUCT |
aoqi@0 | 601 | |
aoqi@0 | 602 | extern "C" void debug() { // to set things up for compiler debugging |
aoqi@0 | 603 | Command c("debug"); |
aoqi@0 | 604 | WizardMode = true; |
aoqi@0 | 605 | PrintVMMessages = PrintCompilation = true; |
aoqi@0 | 606 | PrintInlining = PrintAssembly = true; |
aoqi@0 | 607 | tty->flush(); |
aoqi@0 | 608 | } |
aoqi@0 | 609 | |
aoqi@0 | 610 | |
aoqi@0 | 611 | extern "C" void ndebug() { // undo debug() |
aoqi@0 | 612 | Command c("ndebug"); |
aoqi@0 | 613 | PrintCompilation = false; |
aoqi@0 | 614 | PrintInlining = PrintAssembly = false; |
aoqi@0 | 615 | tty->flush(); |
aoqi@0 | 616 | } |
aoqi@0 | 617 | |
aoqi@0 | 618 | |
aoqi@0 | 619 | extern "C" void flush() { |
aoqi@0 | 620 | Command c("flush"); |
aoqi@0 | 621 | tty->flush(); |
aoqi@0 | 622 | } |
aoqi@0 | 623 | |
aoqi@0 | 624 | extern "C" void events() { |
aoqi@0 | 625 | Command c("events"); |
aoqi@0 | 626 | Events::print(); |
aoqi@0 | 627 | } |
aoqi@0 | 628 | |
aoqi@0 | 629 | extern "C" Method* findm(intptr_t pc) { |
aoqi@0 | 630 | Command c("findm"); |
aoqi@0 | 631 | nmethod* nm = CodeCache::find_nmethod((address)pc); |
aoqi@0 | 632 | return (nm == NULL) ? (Method*)NULL : nm->method(); |
aoqi@0 | 633 | } |
aoqi@0 | 634 | |
aoqi@0 | 635 | |
aoqi@0 | 636 | extern "C" nmethod* findnm(intptr_t addr) { |
aoqi@0 | 637 | Command c("findnm"); |
aoqi@0 | 638 | return CodeCache::find_nmethod((address)addr); |
aoqi@0 | 639 | } |
aoqi@0 | 640 | |
aoqi@0 | 641 | // Another interface that isn't ambiguous in dbx. |
aoqi@0 | 642 | // Can we someday rename the other find to hsfind? |
aoqi@0 | 643 | extern "C" void hsfind(intptr_t x) { |
aoqi@0 | 644 | Command c("hsfind"); |
aoqi@0 | 645 | os::print_location(tty, x, false); |
aoqi@0 | 646 | } |
aoqi@0 | 647 | |
aoqi@0 | 648 | |
aoqi@0 | 649 | extern "C" void find(intptr_t x) { |
aoqi@0 | 650 | Command c("find"); |
aoqi@0 | 651 | os::print_location(tty, x, false); |
aoqi@0 | 652 | } |
aoqi@0 | 653 | |
aoqi@0 | 654 | |
aoqi@0 | 655 | extern "C" void findpc(intptr_t x) { |
aoqi@0 | 656 | Command c("findpc"); |
aoqi@0 | 657 | os::print_location(tty, x, true); |
aoqi@0 | 658 | } |
aoqi@0 | 659 | |
aoqi@0 | 660 | |
aoqi@0 | 661 | // Need method pointer to find bcp, when not in permgen. |
aoqi@0 | 662 | extern "C" void findbcp(intptr_t method, intptr_t bcp) { |
aoqi@0 | 663 | Command c("findbcp"); |
aoqi@0 | 664 | Method* mh = (Method*)method; |
aoqi@0 | 665 | if (!mh->is_native()) { |
aoqi@0 | 666 | tty->print_cr("bci_from(%p) = %d; print_codes():", |
aoqi@0 | 667 | mh, mh->bci_from(address(bcp))); |
aoqi@0 | 668 | mh->print_codes_on(tty); |
aoqi@0 | 669 | } |
aoqi@0 | 670 | } |
aoqi@0 | 671 | |
aoqi@0 | 672 | // int versions of all methods to avoid having to type type casts in the debugger |
aoqi@0 | 673 | |
aoqi@0 | 674 | void pp(intptr_t p) { pp((void*)p); } |
aoqi@0 | 675 | void pp(oop p) { pp((void*)p); } |
aoqi@0 | 676 | |
aoqi@0 | 677 | void help() { |
aoqi@0 | 678 | Command c("help"); |
aoqi@0 | 679 | tty->print_cr("basic"); |
aoqi@0 | 680 | tty->print_cr(" pp(void* p) - try to make sense of p"); |
aoqi@0 | 681 | tty->print_cr(" pv(intptr_t p)- ((PrintableResourceObj*) p)->print()"); |
aoqi@0 | 682 | tty->print_cr(" ps() - print current thread stack"); |
aoqi@0 | 683 | tty->print_cr(" pss() - print all thread stacks"); |
aoqi@0 | 684 | tty->print_cr(" pm(int pc) - print Method* given compiled PC"); |
aoqi@0 | 685 | tty->print_cr(" findm(intptr_t pc) - finds Method*"); |
aoqi@0 | 686 | tty->print_cr(" find(intptr_t x) - finds & prints nmethod/stub/bytecode/oop based on pointer into it"); |
simonis@7553 | 687 | tty->print_cr(" pns(void* sp, void* fp, void* pc) - print native (i.e. mixed) stack trace. E.g."); |
simonis@7553 | 688 | tty->print_cr(" pns($sp, $rbp, $pc) on Linux/amd64 and Solaris/amd64 or"); |
simonis@7553 | 689 | tty->print_cr(" pns($sp, $ebp, $pc) on Linux/x86 or"); |
simonis@7553 | 690 | tty->print_cr(" pns($sp, 0, $pc) on Linux/ppc64 or"); |
aoqi@8011 | 691 | tty->print_cr(" pns($sp, $s8, $pc) on Linux/mips or"); |
simonis@7553 | 692 | tty->print_cr(" pns($sp + 0x7ff, 0, $pc) on Solaris/SPARC"); |
simonis@7553 | 693 | tty->print_cr(" - in gdb do 'set overload-resolution off' before calling pns()"); |
simonis@7553 | 694 | tty->print_cr(" - in dbx do 'frame 1' before calling pns()"); |
aoqi@0 | 695 | |
aoqi@0 | 696 | tty->print_cr("misc."); |
aoqi@0 | 697 | tty->print_cr(" flush() - flushes the log file"); |
aoqi@0 | 698 | tty->print_cr(" events() - dump events from ring buffers"); |
aoqi@0 | 699 | |
aoqi@0 | 700 | |
aoqi@0 | 701 | tty->print_cr("compiler debugging"); |
aoqi@0 | 702 | tty->print_cr(" debug() - to set things up for compiler debugging"); |
aoqi@0 | 703 | tty->print_cr(" ndebug() - undo debug"); |
aoqi@0 | 704 | } |
aoqi@0 | 705 | |
aoqi@0 | 706 | #endif // !PRODUCT |
simonis@7553 | 707 | |
simonis@7553 | 708 | void print_native_stack(outputStream* st, frame fr, Thread* t, char* buf, int buf_size) { |
simonis@7553 | 709 | |
simonis@7553 | 710 | // see if it's a valid frame |
simonis@7553 | 711 | if (fr.pc()) { |
simonis@7553 | 712 | st->print_cr("Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)"); |
simonis@7553 | 713 | |
simonis@7553 | 714 | int count = 0; |
simonis@7553 | 715 | while (count++ < StackPrintLimit) { |
simonis@7553 | 716 | fr.print_on_error(st, buf, buf_size); |
simonis@7553 | 717 | st->cr(); |
simonis@7553 | 718 | // Compiled code may use EBP register on x86 so it looks like |
simonis@7553 | 719 | // non-walkable C frame. Use frame.sender() for java frames. |
simonis@7553 | 720 | if (t && t->is_Java_thread()) { |
simonis@7553 | 721 | // Catch very first native frame by using stack address. |
simonis@7553 | 722 | // For JavaThread stack_base and stack_size should be set. |
simonis@7553 | 723 | if (!t->on_local_stack((address)(fr.real_fp() + 1))) { |
simonis@7553 | 724 | break; |
simonis@7553 | 725 | } |
simonis@7553 | 726 | if (fr.is_java_frame() || fr.is_native_frame() || fr.is_runtime_frame()) { |
simonis@7553 | 727 | RegisterMap map((JavaThread*)t, false); // No update |
simonis@7553 | 728 | fr = fr.sender(&map); |
simonis@7553 | 729 | } else { |
simonis@7553 | 730 | fr = os::get_sender_for_C_frame(&fr); |
simonis@7553 | 731 | } |
simonis@7553 | 732 | } else { |
simonis@7553 | 733 | // is_first_C_frame() does only simple checks for frame pointer, |
simonis@7553 | 734 | // it will pass if java compiled code has a pointer in EBP. |
simonis@7553 | 735 | if (os::is_first_C_frame(&fr)) break; |
simonis@7553 | 736 | fr = os::get_sender_for_C_frame(&fr); |
simonis@7553 | 737 | } |
simonis@7553 | 738 | } |
simonis@7553 | 739 | |
simonis@7553 | 740 | if (count > StackPrintLimit) { |
simonis@7553 | 741 | st->print_cr("...<more frames>..."); |
simonis@7553 | 742 | } |
simonis@7553 | 743 | |
simonis@7553 | 744 | st->cr(); |
simonis@7553 | 745 | } |
simonis@7553 | 746 | } |
simonis@7553 | 747 | |
simonis@7553 | 748 | #ifndef PRODUCT |
simonis@7553 | 749 | |
simonis@7553 | 750 | extern "C" void pns(void* sp, void* fp, void* pc) { // print native stack |
simonis@7553 | 751 | Command c("pns"); |
simonis@7553 | 752 | static char buf[O_BUFLEN]; |
simonis@7553 | 753 | Thread* t = ThreadLocalStorage::get_thread_slow(); |
simonis@7553 | 754 | // Call generic frame constructor (certain arguments may be ignored) |
simonis@7553 | 755 | frame fr(sp, fp, pc); |
simonis@7553 | 756 | print_native_stack(tty, fr, t, buf, sizeof(buf)); |
simonis@7553 | 757 | } |
simonis@7553 | 758 | |
simonis@7553 | 759 | #endif // !PRODUCT |