Thu, 22 Apr 2010 13:23:15 -0700
6888954: argument formatting for assert() and friends
Reviewed-by: kvn, twisti, apetrusenko, never, dcubed
1.1 --- a/src/cpu/sparc/vm/assembler_sparc.hpp Sun Oct 11 16:19:25 2009 -0700 1.2 +++ b/src/cpu/sparc/vm/assembler_sparc.hpp Thu Apr 22 13:23:15 2010 -0700 1.3 @@ -1065,7 +1065,7 @@ 1.4 } 1.5 void assert_not_delayed(const char* msg) { 1.6 #ifdef CHECK_DELAY 1.7 - assert_msg ( delay_state == no_delay, msg); 1.8 + assert(delay_state == no_delay, msg); 1.9 #endif 1.10 } 1.11
2.1 --- a/src/os/linux/vm/os_linux.cpp Sun Oct 11 16:19:25 2009 -0700 2.2 +++ b/src/os/linux/vm/os_linux.cpp Thu Apr 22 13:23:15 2010 -0700 2.3 @@ -3495,7 +3495,8 @@ 2.4 // libjsig also interposes the sigaction() call below and saves the 2.5 // old sigaction on it own. 2.6 } else { 2.7 - fatal2("Encountered unexpected pre-existing sigaction handler %#lx for signal %d.", (long)oldhand, sig); 2.8 + fatal(err_msg("Encountered unexpected pre-existing sigaction handler " 2.9 + "%#lx for signal %d.", (long)oldhand, sig)); 2.10 } 2.11 } 2.12 2.13 @@ -3817,7 +3818,8 @@ 2.14 2.15 Linux::set_page_size(sysconf(_SC_PAGESIZE)); 2.16 if (Linux::page_size() == -1) { 2.17 - fatal1("os_linux.cpp: os::init: sysconf failed (%s)", strerror(errno)); 2.18 + fatal(err_msg("os_linux.cpp: os::init: sysconf failed (%s)", 2.19 + strerror(errno))); 2.20 } 2.21 init_page_sizes((size_t) Linux::page_size()); 2.22
3.1 --- a/src/os/solaris/vm/os_solaris.cpp Sun Oct 11 16:19:25 2009 -0700 3.2 +++ b/src/os/solaris/vm/os_solaris.cpp Thu Apr 22 13:23:15 2010 -0700 3.3 @@ -1567,7 +1567,8 @@ 3.4 // treat %g2 as a caller-save register, preserving it in a %lN. 3.5 thread_key_t tk; 3.6 if (thr_keycreate( &tk, NULL ) ) 3.7 - fatal1("os::allocate_thread_local_storage: thr_keycreate failed (%s)", strerror(errno)); 3.8 + fatal(err_msg("os::allocate_thread_local_storage: thr_keycreate failed " 3.9 + "(%s)", strerror(errno))); 3.10 return int(tk); 3.11 } 3.12 3.13 @@ -1585,7 +1586,8 @@ 3.14 if (errno == ENOMEM) { 3.15 vm_exit_out_of_memory(SMALLINT, "thr_setspecific: out of swap space"); 3.16 } else { 3.17 - fatal1("os::thread_local_storage_at_put: thr_setspecific failed (%s)", strerror(errno)); 3.18 + fatal(err_msg("os::thread_local_storage_at_put: thr_setspecific failed " 3.19 + "(%s)", strerror(errno))); 3.20 } 3.21 } else { 3.22 ThreadLocalStorage::set_thread_in_slot ((Thread *) value) ; 3.23 @@ -1738,7 +1740,7 @@ 3.24 jlong os::javaTimeMillis() { 3.25 timeval t; 3.26 if (gettimeofday( &t, NULL) == -1) 3.27 - fatal1("os::javaTimeMillis: gettimeofday (%s)", strerror(errno)); 3.28 + fatal(err_msg("os::javaTimeMillis: gettimeofday (%s)", strerror(errno))); 3.29 return jlong(t.tv_sec) * 1000 + jlong(t.tv_usec) / 1000; 3.30 } 3.31 3.32 @@ -4233,7 +4235,8 @@ 3.33 // libjsig also interposes the sigaction() call below and saves the 3.34 // old sigaction on it own. 3.35 } else { 3.36 - fatal2("Encountered unexpected pre-existing sigaction handler %#lx for signal %d.", (long)oldhand, sig); 3.37 + fatal(err_msg("Encountered unexpected pre-existing sigaction handler " 3.38 + "%#lx for signal %d.", (long)oldhand, sig)); 3.39 } 3.40 } 3.41 3.42 @@ -4764,7 +4767,8 @@ 3.43 3.44 page_size = sysconf(_SC_PAGESIZE); 3.45 if (page_size == -1) 3.46 - fatal1("os_solaris.cpp: os::init: sysconf failed (%s)", strerror(errno)); 3.47 + fatal(err_msg("os_solaris.cpp: os::init: sysconf failed (%s)", 3.48 + strerror(errno))); 3.49 init_page_sizes((size_t) page_size); 3.50 3.51 Solaris::initialize_system_info(); 3.52 @@ -4775,7 +4779,7 @@ 3.53 3.54 int fd = open("/dev/zero", O_RDWR); 3.55 if (fd < 0) { 3.56 - fatal1("os::init: cannot open /dev/zero (%s)", strerror(errno)); 3.57 + fatal(err_msg("os::init: cannot open /dev/zero (%s)", strerror(errno))); 3.58 } else { 3.59 Solaris::set_dev_zero_fd(fd); 3.60
4.1 --- a/src/os/solaris/vm/threadCritical_solaris.cpp Sun Oct 11 16:19:25 2009 -0700 4.2 +++ b/src/os/solaris/vm/threadCritical_solaris.cpp Thu Apr 22 13:23:15 2010 -0700 4.3 @@ -47,7 +47,8 @@ 4.4 thread_t owner = thr_self(); 4.5 if (global_mut_owner != owner) { 4.6 if (os::Solaris::mutex_lock(&global_mut)) 4.7 - fatal1("ThreadCritical::ThreadCritical: mutex_lock failed (%s)", strerror(errno)); 4.8 + fatal(err_msg("ThreadCritical::ThreadCritical: mutex_lock failed (%s)", 4.9 + strerror(errno))); 4.10 assert(global_mut_count == 0, "must have clean count"); 4.11 assert(global_mut_owner == -1, "must have clean owner"); 4.12 } 4.13 @@ -66,7 +67,8 @@ 4.14 if (global_mut_count == 0) { 4.15 global_mut_owner = -1; 4.16 if (os::Solaris::mutex_unlock(&global_mut)) 4.17 - fatal1("ThreadCritical::~ThreadCritical: mutex_unlock failed (%s)", strerror(errno)); 4.18 + fatal(err_msg("ThreadCritical::~ThreadCritical: mutex_unlock failed " 4.19 + "(%s)", strerror(errno))); 4.20 } 4.21 } else { 4.22 assert (Threads::number_of_threads() == 0, "valid only during initialization");
5.1 --- a/src/os/windows/vm/os_windows.cpp Sun Oct 11 16:19:25 2009 -0700 5.2 +++ b/src/os/windows/vm/os_windows.cpp Thu Apr 22 13:23:15 2010 -0700 5.3 @@ -724,7 +724,7 @@ 5.4 java_origin.wMilliseconds = 0; 5.5 FILETIME jot; 5.6 if (!SystemTimeToFileTime(&java_origin, &jot)) { 5.7 - fatal1("Error = %d\nWindows error", GetLastError()); 5.8 + fatal(err_msg("Error = %d\nWindows error", GetLastError())); 5.9 } 5.10 _calculated_offset = jlong_from(jot.dwHighDateTime, jot.dwLowDateTime); 5.11 _has_calculated_offset = 1; 5.12 @@ -4095,7 +4095,7 @@ 5.13 } 5.14 int err = GetLastError(); 5.15 if (err != ERROR_NO_MORE_ITEMS && err != ERROR_CALL_NOT_IMPLEMENTED) { 5.16 - fatal1("heap walk aborted with error %d", err); 5.17 + fatal(err_msg("heap walk aborted with error %d", err)); 5.18 } 5.19 HeapUnlock(heap); 5.20 }
6.1 --- a/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp Sun Oct 11 16:19:25 2009 -0700 6.2 +++ b/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp Thu Apr 22 13:23:15 2010 -0700 6.3 @@ -153,7 +153,7 @@ 6.4 if (rslt == ENOMEM) { 6.5 vm_exit_out_of_memory(0, "pthread_getattr_np"); 6.6 } else { 6.7 - fatal1("pthread_getattr_np failed with errno = %d", rslt); 6.8 + fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt)); 6.9 } 6.10 } 6.11
7.1 --- a/src/os_cpu/linux_x86/vm/os_linux_x86.cpp Sun Oct 11 16:19:25 2009 -0700 7.2 +++ b/src/os_cpu/linux_x86/vm/os_linux_x86.cpp Thu Apr 22 13:23:15 2010 -0700 7.3 @@ -680,7 +680,7 @@ 7.4 if (rslt == ENOMEM) { 7.5 vm_exit_out_of_memory(0, "pthread_getattr_np"); 7.6 } else { 7.7 - fatal1("pthread_getattr_np failed with errno = %d", rslt); 7.8 + fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt)); 7.9 } 7.10 } 7.11
8.1 --- a/src/share/vm/asm/assembler.cpp Sun Oct 11 16:19:25 2009 -0700 8.2 +++ b/src/share/vm/asm/assembler.cpp Thu Apr 22 13:23:15 2010 -0700 8.3 @@ -43,7 +43,8 @@ 8.4 _code_pos = cs->end(); 8.5 _oop_recorder= code->oop_recorder(); 8.6 if (_code_begin == NULL) { 8.7 - vm_exit_out_of_memory1(0, "CodeCache: no room for %s", code->name()); 8.8 + vm_exit_out_of_memory(0, err_msg("CodeCache: no room for %s", 8.9 + code->name())); 8.10 } 8.11 } 8.12
9.1 --- a/src/share/vm/classfile/classFileParser.cpp Sun Oct 11 16:19:25 2009 -0700 9.2 +++ b/src/share/vm/classfile/classFileParser.cpp Thu Apr 22 13:23:15 2010 -0700 9.3 @@ -334,7 +334,8 @@ 9.4 } 9.5 break; 9.6 default: 9.7 - fatal1("bad constant pool tag value %u", cp->tag_at(index).value()); 9.8 + fatal(err_msg("bad constant pool tag value %u", 9.9 + cp->tag_at(index).value())); 9.10 ShouldNotReachHere(); 9.11 break; 9.12 } // end of switch
10.1 --- a/src/share/vm/code/exceptionHandlerTable.cpp Sun Oct 11 16:19:25 2009 -0700 10.2 +++ b/src/share/vm/code/exceptionHandlerTable.cpp Thu Apr 22 13:23:15 2010 -0700 10.3 @@ -221,6 +221,6 @@ 10.4 for (uint i = 0; i < len(); i++) { 10.5 if ((*adr(i) > (unsigned int)nm->code_size()) || 10.6 (*(adr(i)+1) > (unsigned int)nm->code_size())) 10.7 - fatal1("Invalid offset in ImplicitExceptionTable at %lx", _data); 10.8 + fatal(err_msg("Invalid offset in ImplicitExceptionTable at " PTR_FORMAT, _data)); 10.9 } 10.10 }
11.1 --- a/src/share/vm/code/nmethod.cpp Sun Oct 11 16:19:25 2009 -0700 11.2 +++ b/src/share/vm/code/nmethod.cpp Thu Apr 22 13:23:15 2010 -0700 11.3 @@ -2124,7 +2124,7 @@ 11.4 ResourceMark rm; 11.5 11.6 if (!CodeCache::contains(this)) { 11.7 - fatal1("nmethod at " INTPTR_FORMAT " not in zone", this); 11.8 + fatal(err_msg("nmethod at " INTPTR_FORMAT " not in zone", this)); 11.9 } 11.10 11.11 if(is_native_method() ) 11.12 @@ -2132,7 +2132,8 @@ 11.13 11.14 nmethod* nm = CodeCache::find_nmethod(verified_entry_point()); 11.15 if (nm != this) { 11.16 - fatal1("findNMethod did not find this nmethod (" INTPTR_FORMAT ")", this); 11.17 + fatal(err_msg("findNMethod did not find this nmethod (" INTPTR_FORMAT ")", 11.18 + this)); 11.19 } 11.20 11.21 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) {
12.1 --- a/src/share/vm/code/stubs.cpp Sun Oct 11 16:19:25 2009 -0700 12.2 +++ b/src/share/vm/code/stubs.cpp Thu Apr 22 13:23:15 2010 -0700 12.3 @@ -62,7 +62,9 @@ 12.4 Mutex* lock, const char* name) : _mutex(lock) { 12.5 intptr_t size = round_to(buffer_size, 2*BytesPerWord); 12.6 BufferBlob* blob = BufferBlob::create(name, size); 12.7 - if( blob == NULL ) vm_exit_out_of_memory1(size, "CodeCache: no room for %s", name); 12.8 + if( blob == NULL) { 12.9 + vm_exit_out_of_memory(size, err_msg("CodeCache: no room for %s", name)); 12.10 + } 12.11 _stub_interface = stub_interface; 12.12 _buffer_size = blob->instructions_size(); 12.13 _buffer_limit = blob->instructions_size();
13.1 --- a/src/share/vm/code/vtableStubs.cpp Sun Oct 11 16:19:25 2009 -0700 13.2 +++ b/src/share/vm/code/vtableStubs.cpp Thu Apr 22 13:23:15 2010 -0700 13.3 @@ -45,7 +45,9 @@ 13.4 if (_chunk == NULL || _chunk + real_size > _chunk_end) { 13.5 const int bytes = chunk_factor * real_size + pd_code_alignment(); 13.6 BufferBlob* blob = BufferBlob::create("vtable chunks", bytes); 13.7 - if( blob == NULL ) vm_exit_out_of_memory1(bytes, "CodeCache: no room for %s", "vtable chunks"); 13.8 + if (blob == NULL) { 13.9 + vm_exit_out_of_memory(bytes, "CodeCache: no room for vtable chunks"); 13.10 + } 13.11 _chunk = blob->instructions_begin(); 13.12 _chunk_end = _chunk + bytes; 13.13 VTune::register_stub("vtable stub", _chunk, _chunk_end); 13.14 @@ -189,7 +191,9 @@ 13.15 instanceKlass* ik = instanceKlass::cast(klass); 13.16 klassVtable* vt = ik->vtable(); 13.17 klass->print(); 13.18 - fatal3("bad compiled vtable dispatch: receiver " INTPTR_FORMAT ", index %d (vtable length %d)", (address)receiver, index, vt->length()); 13.19 + fatal(err_msg("bad compiled vtable dispatch: receiver " INTPTR_FORMAT ", " 13.20 + "index %d (vtable length %d)", 13.21 + (address)receiver, index, vt->length())); 13.22 } 13.23 13.24 #endif // Product
14.1 --- a/src/share/vm/interpreter/bytecodeInterpreter.cpp Sun Oct 11 16:19:25 2009 -0700 14.2 +++ b/src/share/vm/interpreter/bytecodeInterpreter.cpp Thu Apr 22 13:23:15 2010 -0700 14.3 @@ -2339,8 +2339,8 @@ 14.4 goto opcode_switch; 14.5 } 14.6 #endif 14.7 - fatal2("\t*** Unimplemented opcode: %d = %s\n", 14.8 - opcode, Bytecodes::name((Bytecodes::Code)opcode)); 14.9 + fatal(err_msg("Unimplemented opcode %d = %s", opcode, 14.10 + Bytecodes::name((Bytecodes::Code)opcode))); 14.11 goto finish; 14.12 14.13 } /* switch(opc) */
15.1 --- a/src/share/vm/interpreter/bytecodes.cpp Sun Oct 11 16:19:25 2009 -0700 15.2 +++ b/src/share/vm/interpreter/bytecodes.cpp Thu Apr 22 13:23:15 2010 -0700 15.3 @@ -426,7 +426,9 @@ 15.4 if (is_defined(i)) { 15.5 Code code = cast(i); 15.6 Code java = java_code(code); 15.7 - if (can_trap(code) && !can_trap(java)) fatal2("%s can trap => %s can trap, too", name(code), name(java)); 15.8 + if (can_trap(code) && !can_trap(java)) 15.9 + fatal(err_msg("%s can trap => %s can trap, too", name(code), 15.10 + name(java))); 15.11 } 15.12 } 15.13 }
16.1 --- a/src/share/vm/oops/instanceKlass.cpp Sun Oct 11 16:19:25 2009 -0700 16.2 +++ b/src/share/vm/oops/instanceKlass.cpp Thu Apr 22 13:23:15 2010 -0700 16.3 @@ -966,7 +966,7 @@ 16.4 // not found 16.5 #ifdef ASSERT 16.6 int index = linear_search(methods, name, signature); 16.7 - if (index != -1) fatal1("binary search bug: should have found entry %d", index); 16.8 + assert(index == -1, err_msg("binary search should have found entry %d", index)); 16.9 #endif 16.10 return NULL; 16.11 } else if (res < 0) { 16.12 @@ -977,7 +977,7 @@ 16.13 } 16.14 #ifdef ASSERT 16.15 int index = linear_search(methods, name, signature); 16.16 - if (index != -1) fatal1("binary search bug: should have found entry %d", index); 16.17 + assert(index == -1, err_msg("binary search should have found entry %d", index)); 16.18 #endif 16.19 return NULL; 16.20 }
17.1 --- a/src/share/vm/oops/instanceKlassKlass.cpp Sun Oct 11 16:19:25 2009 -0700 17.2 +++ b/src/share/vm/oops/instanceKlassKlass.cpp Thu Apr 22 13:23:15 2010 -0700 17.3 @@ -712,10 +712,10 @@ 17.4 int sib_count = 0; 17.5 while (sib != NULL) { 17.6 if (sib == ik) { 17.7 - fatal1("subclass cycle of length %d", sib_count); 17.8 + fatal(err_msg("subclass cycle of length %d", sib_count)); 17.9 } 17.10 if (sib_count >= 100000) { 17.11 - fatal1("suspiciously long subclass list %d", sib_count); 17.12 + fatal(err_msg("suspiciously long subclass list %d", sib_count)); 17.13 } 17.14 guarantee(sib->as_klassOop()->is_klass(), "should be klass"); 17.15 guarantee(sib->as_klassOop()->is_perm(), "should be in permspace");
18.1 --- a/src/share/vm/oops/klassVtable.cpp Sun Oct 11 16:19:25 2009 -0700 18.2 +++ b/src/share/vm/oops/klassVtable.cpp Thu Apr 22 13:23:15 2010 -0700 18.3 @@ -1180,8 +1180,8 @@ 18.4 oop* end_of_obj = (oop*)_klass() + _klass()->size(); 18.5 oop* end_of_vtable = (oop *)&table()[_length]; 18.6 if (end_of_vtable > end_of_obj) { 18.7 - fatal1("klass %s: klass object too short (vtable extends beyond end)", 18.8 - _klass->internal_name()); 18.9 + fatal(err_msg("klass %s: klass object too short (vtable extends beyond " 18.10 + "end)", _klass->internal_name())); 18.11 } 18.12 18.13 for (int i = 0; i < _length; i++) table()[i].verify(this, st); 18.14 @@ -1224,7 +1224,7 @@ 18.15 #ifndef PRODUCT 18.16 print(); 18.17 #endif 18.18 - fatal1("vtableEntry %#lx: method is from subclass", this); 18.19 + fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this)); 18.20 } 18.21 } 18.22
19.1 --- a/src/share/vm/opto/idealGraphPrinter.cpp Sun Oct 11 16:19:25 2009 -0700 19.2 +++ b/src/share/vm/opto/idealGraphPrinter.cpp Thu Apr 22 13:23:15 2010 -0700 19.3 @@ -151,7 +151,8 @@ 19.4 } else { 19.5 // It would be nice if we could shut down cleanly but it should 19.6 // be an error if we can't connect to the visualizer. 19.7 - fatal2("Couldn't connect to visualizer at %s:%d", PrintIdealGraphAddress, PrintIdealGraphPort); 19.8 + fatal(err_msg("Couldn't connect to visualizer at %s:%d", 19.9 + PrintIdealGraphAddress, PrintIdealGraphPort)); 19.10 } 19.11 } 19.12
20.1 --- a/src/share/vm/opto/output.cpp Sun Oct 11 16:19:25 2009 -0700 20.2 +++ b/src/share/vm/opto/output.cpp Thu Apr 22 13:23:15 2010 -0700 20.3 @@ -2407,7 +2407,7 @@ 20.4 n->dump(); 20.5 tty->print_cr("..."); 20.6 prior_use->dump(); 20.7 - assert_msg(edge_from_to(prior_use,n),msg); 20.8 + assert(edge_from_to(prior_use,n),msg); 20.9 } 20.10 _reg_node.map(def,NULL); // Kill live USEs 20.11 } 20.12 @@ -2446,11 +2446,11 @@ 20.13 OptoReg::Name reg_lo = _regalloc->get_reg_first(def); 20.14 OptoReg::Name reg_hi = _regalloc->get_reg_second(def); 20.15 if( OptoReg::is_valid(reg_lo) ) { 20.16 - assert_msg(!_reg_node[reg_lo] || edge_from_to(_reg_node[reg_lo],def), msg ); 20.17 + assert(!_reg_node[reg_lo] || edge_from_to(_reg_node[reg_lo],def), msg); 20.18 _reg_node.map(reg_lo,n); 20.19 } 20.20 if( OptoReg::is_valid(reg_hi) ) { 20.21 - assert_msg(!_reg_node[reg_hi] || edge_from_to(_reg_node[reg_hi],def), msg ); 20.22 + assert(!_reg_node[reg_hi] || edge_from_to(_reg_node[reg_hi],def), msg); 20.23 _reg_node.map(reg_hi,n); 20.24 } 20.25 }
21.1 --- a/src/share/vm/prims/jni.cpp Sun Oct 11 16:19:25 2009 -0700 21.2 +++ b/src/share/vm/prims/jni.cpp Thu Apr 22 13:23:15 2010 -0700 21.3 @@ -3311,6 +3311,7 @@ 21.4 OrderAccess::release_store(&vm_created, 0); 21.5 } 21.6 21.7 + NOT_PRODUCT(test_error_handler(ErrorHandlerTest)); 21.8 return result; 21.9 } 21.10
22.1 --- a/src/share/vm/runtime/globals.hpp Sun Oct 11 16:19:25 2009 -0700 22.2 +++ b/src/share/vm/runtime/globals.hpp Thu Apr 22 13:23:15 2010 -0700 22.3 @@ -652,6 +652,11 @@ 22.4 product(bool, PrintGCApplicationStoppedTime, false, \ 22.5 "Print the time the application has been stopped") \ 22.6 \ 22.7 + notproduct(uintx, ErrorHandlerTest, 0, \ 22.8 + "If > 0, provokes an error after VM initialization; the value" \ 22.9 + "determines which error to provoke. See test_error_handler()" \ 22.10 + "in debug.cpp.") \ 22.11 + \ 22.12 develop(bool, Verbose, false, \ 22.13 "Prints additional debugging information from other modes") \ 22.14 \
23.1 --- a/src/share/vm/runtime/memprofiler.cpp Sun Oct 11 16:19:25 2009 -0700 23.2 +++ b/src/share/vm/runtime/memprofiler.cpp Thu Apr 22 13:23:15 2010 -0700 23.3 @@ -62,7 +62,7 @@ 23.4 // Create log file 23.5 _log_fp = fopen(log_name , "w+"); 23.6 if (_log_fp == NULL) { 23.7 - fatal1("MemProfiler: Cannot create log file: %s", log_name); 23.8 + fatal(err_msg("MemProfiler: Cannot create log file: %s", log_name)); 23.9 } 23.10 fprintf(_log_fp, "MemProfiler: sizes are in Kb, time is in seconds since startup\n\n"); 23.11 fprintf(_log_fp, " time, #thr, #cls, heap, heap, perm, perm, code, hndls, rescs, oopmp\n");
24.1 --- a/src/share/vm/runtime/mutex.cpp Sun Oct 11 16:19:25 2009 -0700 24.2 +++ b/src/share/vm/runtime/mutex.cpp Thu Apr 22 13:23:15 2010 -0700 24.3 @@ -1288,8 +1288,9 @@ 24.4 !(this == Safepoint_lock && contains(locks, Terminator_lock) && 24.5 SafepointSynchronize::is_synchronizing())) { 24.6 new_owner->print_owned_locks(); 24.7 - fatal4("acquiring lock %s/%d out of order with lock %s/%d -- possible deadlock", 24.8 - this->name(), this->rank(), locks->name(), locks->rank()); 24.9 + fatal(err_msg("acquiring lock %s/%d out of order with lock %s/%d -- " 24.10 + "possible deadlock", this->name(), this->rank(), 24.11 + locks->name(), locks->rank())); 24.12 } 24.13 24.14 this->_next = new_owner->_owned_locks; 24.15 @@ -1342,7 +1343,8 @@ 24.16 || rank() == Mutex::special, "wrong thread state for using locks"); 24.17 if (StrictSafepointChecks) { 24.18 if (thread->is_VM_thread() && !allow_vm_block()) { 24.19 - fatal1("VM thread using lock %s (not allowed to block on)", name()); 24.20 + fatal(err_msg("VM thread using lock %s (not allowed to block on)", 24.21 + name())); 24.22 } 24.23 debug_only(if (rank() != Mutex::special) \ 24.24 thread->check_for_valid_safepoint_state(false);)
25.1 --- a/src/share/vm/runtime/mutexLocker.cpp Sun Oct 11 16:19:25 2009 -0700 25.2 +++ b/src/share/vm/runtime/mutexLocker.cpp Thu Apr 22 13:23:15 2010 -0700 25.3 @@ -136,7 +136,7 @@ 25.4 // see if invoker of VM operation owns it 25.5 VM_Operation* op = VMThread::vm_operation(); 25.6 if (op != NULL && op->calling_thread() == lock->owner()) return; 25.7 - fatal1("must own lock %s", lock->name()); 25.8 + fatal(err_msg("must own lock %s", lock->name())); 25.9 } 25.10 25.11 // a stronger assertion than the above 25.12 @@ -144,7 +144,7 @@ 25.13 if (IgnoreLockingAssertions) return; 25.14 assert(lock != NULL, "Need non-NULL lock"); 25.15 if (lock->owned_by_self()) return; 25.16 - fatal1("must own lock %s", lock->name()); 25.17 + fatal(err_msg("must own lock %s", lock->name())); 25.18 } 25.19 #endif 25.20
26.1 --- a/src/share/vm/runtime/os.cpp Sun Oct 11 16:19:25 2009 -0700 26.2 +++ b/src/share/vm/runtime/os.cpp Thu Apr 22 13:23:15 2010 -0700 26.3 @@ -406,8 +406,10 @@ 26.4 #ifdef ASSERT 26.5 inline size_t get_size(void* obj) { 26.6 size_t size = *size_addr_from_obj(obj); 26.7 - if (size < 0 ) 26.8 - fatal2("free: size field of object #%p was overwritten (%lu)", obj, size); 26.9 + if (size < 0) { 26.10 + fatal(err_msg("free: size field of object #" PTR_FORMAT " was overwritten (" 26.11 + SIZE_FORMAT ")", obj, size)); 26.12 + } 26.13 return size; 26.14 } 26.15
27.1 --- a/src/share/vm/runtime/safepoint.cpp Sun Oct 11 16:19:25 2009 -0700 27.2 +++ b/src/share/vm/runtime/safepoint.cpp Thu Apr 22 13:23:15 2010 -0700 27.3 @@ -594,7 +594,7 @@ 27.4 break; 27.5 27.6 default: 27.7 - fatal1("Illegal threadstate encountered: %d", state); 27.8 + fatal(err_msg("Illegal threadstate encountered: %d", state)); 27.9 } 27.10 27.11 // Check for pending. async. exceptions or suspends - except if the
28.1 --- a/src/share/vm/runtime/signature.cpp Sun Oct 11 16:19:25 2009 -0700 28.2 +++ b/src/share/vm/runtime/signature.cpp Thu Apr 22 13:23:15 2010 -0700 28.3 @@ -57,7 +57,7 @@ 28.4 } 28.5 28.6 void SignatureIterator::expect(char c) { 28.7 - if (_signature->byte_at(_index) != c) fatal1("expecting %c", c); 28.8 + if (_signature->byte_at(_index) != c) fatal(err_msg("expecting %c", c)); 28.9 _index++; 28.10 } 28.11
29.1 --- a/src/share/vm/runtime/stubRoutines.cpp Sun Oct 11 16:19:25 2009 -0700 29.2 +++ b/src/share/vm/runtime/stubRoutines.cpp Thu Apr 22 13:23:15 2010 -0700 29.3 @@ -118,7 +118,10 @@ 29.4 ResourceMark rm; 29.5 TraceTime timer("StubRoutines generation 1", TraceStartupTime); 29.6 _code1 = BufferBlob::create("StubRoutines (1)", code_size1); 29.7 - if( _code1 == NULL) vm_exit_out_of_memory1(code_size1, "CodeCache: no room for %s", "StubRoutines (1)"); 29.8 + if (_code1 == NULL) { 29.9 + vm_exit_out_of_memory(code_size1, 29.10 + "CodeCache: no room for StubRoutines (1)"); 29.11 + } 29.12 CodeBuffer buffer(_code1->instructions_begin(), _code1->instructions_size()); 29.13 StubGenerator_generate(&buffer, false); 29.14 } 29.15 @@ -164,7 +167,10 @@ 29.16 ResourceMark rm; 29.17 TraceTime timer("StubRoutines generation 2", TraceStartupTime); 29.18 _code2 = BufferBlob::create("StubRoutines (2)", code_size2); 29.19 - if( _code2 == NULL) vm_exit_out_of_memory1(code_size2, "CodeCache: no room for %s", "StubRoutines (2)"); 29.20 + if (_code2 == NULL) { 29.21 + vm_exit_out_of_memory(code_size2, 29.22 + "CodeCache: no room for StubRoutines (2)"); 29.23 + } 29.24 CodeBuffer buffer(_code2->instructions_begin(), _code2->instructions_size()); 29.25 StubGenerator_generate(&buffer, true); 29.26 }
30.1 --- a/src/share/vm/runtime/vmThread.cpp Sun Oct 11 16:19:25 2009 -0700 30.2 +++ b/src/share/vm/runtime/vmThread.cpp Thu Apr 22 13:23:15 2010 -0700 30.3 @@ -593,7 +593,8 @@ 30.4 // Check the VM operation allows nested VM operation. This normally not the case, e.g., the compiler 30.5 // does not allow nested scavenges or compiles. 30.6 if (!prev_vm_operation->allow_nested_vm_operations()) { 30.7 - fatal2("Nested VM operation %s requested by operation %s", op->name(), vm_operation()->name()); 30.8 + fatal(err_msg("Nested VM operation %s requested by operation %s", 30.9 + op->name(), vm_operation()->name())); 30.10 } 30.11 op->set_calling_thread(prev_vm_operation->calling_thread(), prev_vm_operation->priority()); 30.12 }
31.1 --- a/src/share/vm/utilities/debug.cpp Sun Oct 11 16:19:25 2009 -0700 31.2 +++ b/src/share/vm/utilities/debug.cpp Thu Apr 22 13:23:15 2010 -0700 31.3 @@ -72,7 +72,7 @@ 31.4 // assert/guarantee/... may happen very early during VM initialization. 31.5 // Don't rely on anything that is initialized by Threads::create_vm(). For 31.6 // example, don't use tty. 31.7 -bool assert_is_suppressed(const char* file_name, int line_no) { 31.8 +bool error_is_suppressed(const char* file_name, int line_no) { 31.9 // The following 1-element cache requires that passed-in 31.10 // file names are always only constant literals. 31.11 if (file_name == last_file_name && line_no == last_line_no) return true; 31.12 @@ -163,38 +163,30 @@ 31.13 #else 31.14 31.15 // Place-holder for non-existent suppression check: 31.16 -#define assert_is_suppressed(file_name, line_no) (false) 31.17 +#define error_is_suppressed(file_name, line_no) (false) 31.18 31.19 #endif //PRODUCT 31.20 31.21 -void report_assertion_failure(const char* file_name, int line_no, const char* message) { 31.22 - if (Debugging || assert_is_suppressed(file_name, line_no)) return; 31.23 - VMError err(ThreadLocalStorage::get_thread_slow(), message, file_name, line_no); 31.24 +void report_vm_error(const char* file, int line, const char* error_msg, 31.25 + const char* detail_msg) 31.26 +{ 31.27 + if (Debugging || error_is_suppressed(file, line)) return; 31.28 + Thread* const thread = ThreadLocalStorage::get_thread_slow(); 31.29 + VMError err(thread, file, line, error_msg, detail_msg); 31.30 err.report_and_die(); 31.31 } 31.32 31.33 -void report_fatal(const char* file_name, int line_no, const char* message) { 31.34 - if (Debugging || assert_is_suppressed(file_name, line_no)) return; 31.35 - VMError err(ThreadLocalStorage::get_thread_slow(), message, file_name, line_no); 31.36 - err.report_and_die(); 31.37 +void report_fatal(const char* file, int line, const char* message) 31.38 +{ 31.39 + report_vm_error(file, line, "fatal error", message); 31.40 } 31.41 31.42 -void report_fatal_vararg(const char* file_name, int line_no, const char* format, ...) { 31.43 - char buffer[256]; 31.44 - va_list ap; 31.45 - va_start(ap, format); 31.46 - jio_vsnprintf(buffer, sizeof(buffer), format, ap); 31.47 - va_end(ap); 31.48 - report_fatal(file_name, line_no, buffer); 31.49 -} 31.50 - 31.51 - 31.52 // Used by report_vm_out_of_memory to detect recursion. 31.53 static jint _exiting_out_of_mem = 0; 31.54 31.55 -// Just passing the flow to VMError to handle error 31.56 -void report_vm_out_of_memory(const char* file_name, int line_no, size_t size, const char* message) { 31.57 - if (Debugging || assert_is_suppressed(file_name, line_no)) return; 31.58 +void report_vm_out_of_memory(const char* file, int line, size_t size, 31.59 + const char* message) { 31.60 + if (Debugging || error_is_suppressed(file, line)) return; 31.61 31.62 // We try to gather additional information for the first out of memory 31.63 // error only; gathering additional data might cause an allocation and a 31.64 @@ -206,46 +198,28 @@ 31.65 31.66 if (first_time_here) { 31.67 Thread* thread = ThreadLocalStorage::get_thread_slow(); 31.68 - VMError(thread, size, message, file_name, line_no).report_and_die(); 31.69 + VMError(thread, file, line, size, message).report_and_die(); 31.70 } 31.71 31.72 // Dump core and abort 31.73 vm_abort(true); 31.74 } 31.75 31.76 -void report_vm_out_of_memory_vararg(const char* file_name, int line_no, size_t size, const char* format, ...) { 31.77 - char buffer[256]; 31.78 - va_list ap; 31.79 - va_start(ap, format); 31.80 - jio_vsnprintf(buffer, sizeof(buffer), format, ap); 31.81 - va_end(ap); 31.82 - report_vm_out_of_memory(file_name, line_no, size, buffer); 31.83 +void report_should_not_call(const char* file, int line) { 31.84 + report_vm_error(file, line, "ShouldNotCall()"); 31.85 } 31.86 31.87 -void report_should_not_call(const char* file_name, int line_no) { 31.88 - if (Debugging || assert_is_suppressed(file_name, line_no)) return; 31.89 - VMError err(ThreadLocalStorage::get_thread_slow(), "ShouldNotCall()", file_name, line_no); 31.90 - err.report_and_die(); 31.91 +void report_should_not_reach_here(const char* file, int line) { 31.92 + report_vm_error(file, line, "ShouldNotReachHere()"); 31.93 } 31.94 31.95 - 31.96 -void report_should_not_reach_here(const char* file_name, int line_no) { 31.97 - if (Debugging || assert_is_suppressed(file_name, line_no)) return; 31.98 - VMError err(ThreadLocalStorage::get_thread_slow(), "ShouldNotReachHere()", file_name, line_no); 31.99 - err.report_and_die(); 31.100 +void report_unimplemented(const char* file, int line) { 31.101 + report_vm_error(file, line, "Unimplemented()"); 31.102 } 31.103 31.104 - 31.105 -void report_unimplemented(const char* file_name, int line_no) { 31.106 - if (Debugging || assert_is_suppressed(file_name, line_no)) return; 31.107 - VMError err(ThreadLocalStorage::get_thread_slow(), "Unimplemented()", file_name, line_no); 31.108 - err.report_and_die(); 31.109 -} 31.110 - 31.111 - 31.112 -void report_untested(const char* file_name, int line_no, const char* msg) { 31.113 +void report_untested(const char* file, int line, const char* message) { 31.114 #ifndef PRODUCT 31.115 - warning("Untested: %s in %s: %d\n", msg, file_name, line_no); 31.116 + warning("Untested: %s in %s: %d\n", message, file, line); 31.117 #endif // PRODUCT 31.118 } 31.119 31.120 @@ -284,6 +258,51 @@ 31.121 return error_reported; 31.122 } 31.123 31.124 +#ifndef PRODUCT 31.125 +#include <signal.h> 31.126 + 31.127 +void test_error_handler(size_t test_num) 31.128 +{ 31.129 + if (test_num == 0) return; 31.130 + 31.131 + // If asserts are disabled, use the corresponding guarantee instead. 31.132 + size_t n = test_num; 31.133 + NOT_DEBUG(if (n <= 2) n += 2); 31.134 + 31.135 + const char* const str = "hello"; 31.136 + const size_t num = (size_t)os::vm_page_size(); 31.137 + 31.138 + const char* const eol = os::line_separator(); 31.139 + const char* const msg = "this message should be truncated during formatting"; 31.140 + 31.141 + // Keep this in sync with test/runtime/6888954/vmerrors.sh. 31.142 + switch (n) { 31.143 + case 1: assert(str == NULL, "expected null"); 31.144 + case 2: assert(num == 1023 && *str == 'X', 31.145 + err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str)); 31.146 + case 3: guarantee(str == NULL, "expected null"); 31.147 + case 4: guarantee(num == 1023 && *str == 'X', 31.148 + err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str)); 31.149 + case 5: fatal("expected null"); 31.150 + case 6: fatal(err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str)); 31.151 + case 7: fatal(err_msg("%s%s# %s%s# %s%s# %s%s# %s%s# " 31.152 + "%s%s# %s%s# %s%s# %s%s# %s%s# " 31.153 + "%s%s# %s%s# %s%s# %s%s# %s", 31.154 + msg, eol, msg, eol, msg, eol, msg, eol, msg, eol, 31.155 + msg, eol, msg, eol, msg, eol, msg, eol, msg, eol, 31.156 + msg, eol, msg, eol, msg, eol, msg, eol, msg)); 31.157 + case 8: vm_exit_out_of_memory(num, "ChunkPool::allocate"); 31.158 + case 9: ShouldNotCallThis(); 31.159 + case 10: ShouldNotReachHere(); 31.160 + case 11: Unimplemented(); 31.161 + // This is last because it does not generate an hs_err* file on Windows. 31.162 + case 12: os::signal_raise(SIGSEGV); 31.163 + 31.164 + default: ShouldNotReachHere(); 31.165 + } 31.166 +} 31.167 +#endif // #ifndef PRODUCT 31.168 + 31.169 // ------ helper functions for debugging go here ------------ 31.170 31.171 #ifndef PRODUCT
32.1 --- a/src/share/vm/utilities/debug.hpp Sun Oct 11 16:19:25 2009 -0700 32.2 +++ b/src/share/vm/utilities/debug.hpp Thu Apr 22 13:23:15 2010 -0700 32.3 @@ -22,28 +22,54 @@ 32.4 * 32.5 */ 32.6 32.7 +#include <stdarg.h> 32.8 + 32.9 +// Simple class to format the ctor arguments into a fixed-sized buffer. 32.10 +template <size_t bufsz = 256> 32.11 +class FormatBuffer { 32.12 +public: 32.13 + inline FormatBuffer(const char * format, ...); 32.14 + operator const char *() const { return _buf; } 32.15 + 32.16 +private: 32.17 + FormatBuffer(const FormatBuffer &); // prevent copies 32.18 + 32.19 +private: 32.20 + char _buf[bufsz]; 32.21 +}; 32.22 + 32.23 +template <size_t bufsz> 32.24 +FormatBuffer<bufsz>::FormatBuffer(const char * format, ...) { 32.25 + va_list argp; 32.26 + va_start(argp, format); 32.27 + vsnprintf(_buf, bufsz, format, argp); 32.28 + va_end(argp); 32.29 +} 32.30 + 32.31 +// Used to format messages for assert(), guarantee(), fatal(), etc. 32.32 +typedef FormatBuffer<> err_msg; 32.33 + 32.34 // assertions 32.35 #ifdef ASSERT 32.36 -// Turn this off by default: 32.37 -//#define USE_REPEATED_ASSERTS 32.38 -#ifdef USE_REPEATED_ASSERTS 32.39 - #define assert(p,msg) \ 32.40 - { for (int __i = 0; __i < AssertRepeat; __i++) { \ 32.41 - if (!(p)) { \ 32.42 - report_assertion_failure(__FILE__, __LINE__, \ 32.43 - "assert(" XSTR(p) ",\"" msg "\")");\ 32.44 - BREAKPOINT; \ 32.45 - } \ 32.46 - } \ 32.47 - } 32.48 -#else 32.49 - #define assert(p,msg) \ 32.50 - if (!(p)) { \ 32.51 - report_assertion_failure(__FILE__, __LINE__, \ 32.52 - "assert(" XSTR(p) ",\"" msg "\")");\ 32.53 - BREAKPOINT; \ 32.54 - } 32.55 -#endif 32.56 +#ifndef USE_REPEATED_ASSERTS 32.57 +#define assert(p, msg) \ 32.58 +do { \ 32.59 + if (!(p)) { \ 32.60 + report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg); \ 32.61 + BREAKPOINT; \ 32.62 + } \ 32.63 +} while (0) 32.64 +#else // #ifndef USE_REPEATED_ASSERTS 32.65 +#define assert(p, msg) 32.66 +do { \ 32.67 + for (int __i = 0; __i < AssertRepeat; __i++) { \ 32.68 + if (!(p)) { \ 32.69 + report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg); \ 32.70 + BREAKPOINT; \ 32.71 + } \ 32.72 + } \ 32.73 +} while (0) 32.74 +#endif // #ifndef USE_REPEATED_ASSERTS 32.75 32.76 // This version of assert is for use with checking return status from 32.77 // library calls that return actual error values eg. EINVAL, 32.78 @@ -52,70 +78,83 @@ 32.79 // what status was actually returned, so we pass the status variable as 32.80 // an extra arg and use strerror to convert it to a meaningful string 32.81 // like "Invalid argument", "out of memory" etc 32.82 -#define assert_status(p, status, msg) \ 32.83 - do { \ 32.84 - if (!(p)) { \ 32.85 - char buf[128]; \ 32.86 - snprintf(buf, 127, \ 32.87 - "assert_status(" XSTR(p) ", error: %s(%d), \"" msg "\")" , \ 32.88 - strerror((status)), (status)); \ 32.89 - report_assertion_failure(__FILE__, __LINE__, buf); \ 32.90 - BREAKPOINT; \ 32.91 - } \ 32.92 - } while (0) 32.93 - 32.94 -// Another version of assert where the message is not a string literal 32.95 -// The boolean condition is not printed out because cpp doesn't like it. 32.96 -#define assert_msg(p, msg) \ 32.97 - if (!(p)) { \ 32.98 - report_assertion_failure(__FILE__, __LINE__, msg); \ 32.99 - BREAKPOINT; \ 32.100 - } 32.101 +#define assert_status(p, status, msg) \ 32.102 +do { \ 32.103 + if (!(p)) { \ 32.104 + report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", \ 32.105 + err_msg("error %s(%d) %s", strerror(status), \ 32.106 + status, msg)); \ 32.107 + BREAKPOINT; \ 32.108 + } \ 32.109 +} while (0) 32.110 32.111 // Do not assert this condition if there's already another error reported. 32.112 #define assert_if_no_error(cond,msg) assert((cond) || is_error_reported(), msg) 32.113 -#else 32.114 +#else // #ifdef ASSERT 32.115 #define assert(p,msg) 32.116 #define assert_status(p,status,msg) 32.117 #define assert_if_no_error(cond,msg) 32.118 - #define assert_msg(cond,msg) 32.119 -#endif 32.120 +#endif // #ifdef ASSERT 32.121 32.122 +// guarantee is like assert except it's always executed -- use it for 32.123 +// cheap tests that catch errors that would otherwise be hard to find. 32.124 +// guarantee is also used for Verify options. 32.125 +#define guarantee(p, msg) \ 32.126 +do { \ 32.127 + if (!(p)) { \ 32.128 + report_vm_error(__FILE__, __LINE__, "guarantee(" #p ") failed", msg); \ 32.129 + BREAKPOINT; \ 32.130 + } \ 32.131 +} while (0) 32.132 32.133 -// fatals 32.134 -#define fatal(m) { report_fatal(__FILE__, __LINE__, m ); BREAKPOINT; } 32.135 -#define fatal1(m,x1) { report_fatal_vararg(__FILE__, __LINE__, m, x1 ); BREAKPOINT; } 32.136 -#define fatal2(m,x1,x2) { report_fatal_vararg(__FILE__, __LINE__, m, x1, x2 ); BREAKPOINT; } 32.137 -#define fatal3(m,x1,x2,x3) { report_fatal_vararg(__FILE__, __LINE__, m, x1, x2, x3 ); BREAKPOINT; } 32.138 -#define fatal4(m,x1,x2,x3,x4) { report_fatal_vararg(__FILE__, __LINE__, m, x1, x2, x3, x4 ); BREAKPOINT; } 32.139 +#define fatal(msg) \ 32.140 +do { \ 32.141 + report_fatal(__FILE__, __LINE__, msg); \ 32.142 + BREAKPOINT; \ 32.143 +} while (0) 32.144 32.145 // out of memory 32.146 -#define vm_exit_out_of_memory(s,m) { report_vm_out_of_memory(__FILE__, __LINE__, s, m ); BREAKPOINT; } 32.147 -#define vm_exit_out_of_memory1(s,m,x1) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1 ); BREAKPOINT; } 32.148 -#define vm_exit_out_of_memory2(s,m,x1,x2) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1, x2 ); BREAKPOINT; } 32.149 -#define vm_exit_out_of_memory3(s,m,x1,x2,x3) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1, x2, x3 ); BREAKPOINT; } 32.150 -#define vm_exit_out_of_memory4(s,m,x1,x2,x3,x4) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1, x2, x3, x4); BREAKPOINT; } 32.151 +#define vm_exit_out_of_memory(size, msg) \ 32.152 +do { \ 32.153 + report_vm_out_of_memory(__FILE__, __LINE__, size, msg); \ 32.154 + BREAKPOINT; \ 32.155 +} while (0) 32.156 32.157 -// guarantee is like assert except it's always executed -- use it for 32.158 -// cheap tests that catch errors that would otherwise be hard to find 32.159 -// guarantee is also used for Verify options. 32.160 -#define guarantee(b,msg) { if (!(b)) fatal("guarantee(" XSTR(b) ",\"" msg "\")"); } 32.161 +#define ShouldNotCallThis() \ 32.162 +do { \ 32.163 + report_should_not_call(__FILE__, __LINE__); \ 32.164 + BREAKPOINT; \ 32.165 +} while (0) 32.166 32.167 -#define ShouldNotCallThis() { report_should_not_call (__FILE__, __LINE__); BREAKPOINT; } 32.168 -#define ShouldNotReachHere() { report_should_not_reach_here (__FILE__, __LINE__); BREAKPOINT; } 32.169 -#define Unimplemented() { report_unimplemented (__FILE__, __LINE__); BREAKPOINT; } 32.170 -#define Untested(msg) { report_untested (__FILE__, __LINE__, msg); BREAKPOINT; } 32.171 +#define ShouldNotReachHere() \ 32.172 +do { \ 32.173 + report_should_not_reach_here(__FILE__, __LINE__); \ 32.174 + BREAKPOINT; \ 32.175 +} while (0) 32.176 + 32.177 +#define Unimplemented() \ 32.178 +do { \ 32.179 + report_unimplemented(__FILE__, __LINE__); \ 32.180 + BREAKPOINT; \ 32.181 +} while (0) 32.182 + 32.183 +#define Untested(msg) \ 32.184 +do { \ 32.185 + report_untested(__FILE__, __LINE__, msg); \ 32.186 + BREAKPOINT; \ 32.187 +} while (0); 32.188 32.189 // error reporting helper functions 32.190 -void report_assertion_failure(const char* file_name, int line_no, const char* message); 32.191 -void report_fatal_vararg(const char* file_name, int line_no, const char* format, ...); 32.192 -void report_fatal(const char* file_name, int line_no, const char* message); 32.193 -void report_vm_out_of_memory_vararg(const char* file_name, int line_no, size_t size, const char* format, ...); 32.194 -void report_vm_out_of_memory(const char* file_name, int line_no, size_t size, const char* message); 32.195 -void report_should_not_call(const char* file_name, int line_no); 32.196 -void report_should_not_reach_here(const char* file_name, int line_no); 32.197 -void report_unimplemented(const char* file_name, int line_no); 32.198 -void report_untested(const char* file_name, int line_no, const char* msg); 32.199 +void report_vm_error(const char* file, int line, const char* error_msg, 32.200 + const char* detail_msg = NULL); 32.201 +void report_fatal(const char* file, int line, const char* message); 32.202 +void report_vm_out_of_memory(const char* file, int line, size_t size, 32.203 + const char* message); 32.204 +void report_should_not_call(const char* file, int line); 32.205 +void report_should_not_reach_here(const char* file, int line); 32.206 +void report_unimplemented(const char* file, int line); 32.207 +void report_untested(const char* file, int line, const char* message); 32.208 + 32.209 void warning(const char* format, ...); 32.210 32.211 // out of memory reporting 32.212 @@ -125,5 +164,8 @@ 32.213 bool is_error_reported(); 32.214 void set_error_reported(); 32.215 32.216 +/* Test assert(), fatal(), guarantee(), etc. */ 32.217 +NOT_PRODUCT(void test_error_handler(size_t test_num);) 32.218 + 32.219 void pd_ps(frame f); 32.220 void pd_obfuscate_location(char *buf, size_t buflen);
33.1 --- a/src/share/vm/utilities/exceptions.cpp Sun Oct 11 16:19:25 2009 -0700 33.2 +++ b/src/share/vm/utilities/exceptions.cpp Thu Apr 22 13:23:15 2010 -0700 33.3 @@ -378,7 +378,7 @@ 33.4 void Exceptions::debug_check_abort(const char *value_string) { 33.5 if (AbortVMOnException != NULL && value_string != NULL && 33.6 strstr(value_string, AbortVMOnException)) { 33.7 - fatal1("Saw %s, aborting", value_string); 33.8 + fatal(err_msg("Saw %s, aborting", value_string)); 33.9 } 33.10 } 33.11
34.1 --- a/src/share/vm/utilities/macros.hpp Sun Oct 11 16:19:25 2009 -0700 34.2 +++ b/src/share/vm/utilities/macros.hpp Thu Apr 22 13:23:15 2010 -0700 34.3 @@ -188,6 +188,4 @@ 34.4 #define NOT_SPARC(code) code 34.5 #endif 34.6 34.7 -#define FIX_THIS(code) report_assertion_failure("FIX_THIS",__FILE__, __LINE__, "") 34.8 - 34.9 #define define_pd_global(type, name, value) const type pd_##name = value;
35.1 --- a/src/share/vm/utilities/vmError.cpp Sun Oct 11 16:19:25 2009 -0700 35.2 +++ b/src/share/vm/utilities/vmError.cpp Thu Apr 22 13:23:15 2010 -0700 35.3 @@ -65,7 +65,8 @@ 35.4 _current_step = 0; 35.5 _current_step_info = NULL; 35.6 35.7 - _message = ""; 35.8 + _message = NULL; 35.9 + _detail_msg = NULL; 35.10 _filename = NULL; 35.11 _lineno = 0; 35.12 35.13 @@ -73,31 +74,36 @@ 35.14 } 35.15 35.16 // Constructor for internal errors 35.17 -VMError::VMError(Thread* thread, const char* message, const char* filename, int lineno) { 35.18 +VMError::VMError(Thread* thread, const char* filename, int lineno, 35.19 + const char* message, const char * detail_msg) 35.20 +{ 35.21 + _thread = thread; 35.22 + _id = internal_error; // Value that's not an OS exception/signal 35.23 + _filename = filename; 35.24 + _lineno = lineno; 35.25 + _message = message; 35.26 + _detail_msg = detail_msg; 35.27 + 35.28 + _verbose = false; 35.29 + _current_step = 0; 35.30 + _current_step_info = NULL; 35.31 + 35.32 + _pc = NULL; 35.33 + _siginfo = NULL; 35.34 + _context = NULL; 35.35 + 35.36 + _size = 0; 35.37 +} 35.38 + 35.39 +// Constructor for OOM errors 35.40 +VMError::VMError(Thread* thread, const char* filename, int lineno, size_t size, 35.41 + const char* message) { 35.42 _thread = thread; 35.43 - _id = internal_error; // set it to a value that's not an OS exception/signal 35.44 + _id = oom_error; // Value that's not an OS exception/signal 35.45 _filename = filename; 35.46 _lineno = lineno; 35.47 _message = message; 35.48 - 35.49 - _verbose = false; 35.50 - _current_step = 0; 35.51 - _current_step_info = NULL; 35.52 - 35.53 - _pc = NULL; 35.54 - _siginfo = NULL; 35.55 - _context = NULL; 35.56 - 35.57 - _size = 0; 35.58 -} 35.59 - 35.60 -// Constructor for OOM errors 35.61 -VMError::VMError(Thread* thread, size_t size, const char* message, const char* filename, int lineno) { 35.62 - _thread = thread; 35.63 - _id = oom_error; // set it to a value that's not an OS exception/signal 35.64 - _filename = filename; 35.65 - _lineno = lineno; 35.66 - _message = message; 35.67 + _detail_msg = NULL; 35.68 35.69 _verbose = false; 35.70 _current_step = 0; 35.71 @@ -114,10 +120,11 @@ 35.72 // Constructor for non-fatal errors 35.73 VMError::VMError(const char* message) { 35.74 _thread = NULL; 35.75 - _id = internal_error; // set it to a value that's not an OS exception/signal 35.76 + _id = internal_error; // Value that's not an OS exception/signal 35.77 _filename = NULL; 35.78 _lineno = 0; 35.79 _message = message; 35.80 + _detail_msg = NULL; 35.81 35.82 _verbose = false; 35.83 _current_step = 0; 35.84 @@ -191,22 +198,27 @@ 35.85 "%s (0x%x) at pc=" PTR_FORMAT ", pid=%d, tid=" UINTX_FORMAT, 35.86 signame, _id, _pc, 35.87 os::current_process_id(), os::current_thread_id()); 35.88 + } else if (_filename != NULL && _lineno > 0) { 35.89 + // skip directory names 35.90 + char separator = os::file_separator()[0]; 35.91 + const char *p = strrchr(_filename, separator); 35.92 + int n = jio_snprintf(buf, buflen, 35.93 + "Internal Error at %s:%d, pid=%d, tid=" UINTX_FORMAT, 35.94 + p ? p + 1 : _filename, _lineno, 35.95 + os::current_process_id(), os::current_thread_id()); 35.96 + if (n >= 0 && n < buflen && _message) { 35.97 + if (_detail_msg) { 35.98 + jio_snprintf(buf + n, buflen - n, "%s%s: %s", 35.99 + os::line_separator(), _message, _detail_msg); 35.100 + } else { 35.101 + jio_snprintf(buf + n, buflen - n, "%sError: %s", 35.102 + os::line_separator(), _message); 35.103 + } 35.104 + } 35.105 } else { 35.106 - if (_filename != NULL && _lineno > 0) { 35.107 - // skip directory names 35.108 - char separator = os::file_separator()[0]; 35.109 - const char *p = strrchr(_filename, separator); 35.110 - 35.111 - jio_snprintf(buf, buflen, 35.112 - "Internal Error at %s:%d, pid=%d, tid=" UINTX_FORMAT " \nError: %s", 35.113 - p ? p + 1 : _filename, _lineno, 35.114 - os::current_process_id(), os::current_thread_id(), 35.115 - _message ? _message : ""); 35.116 - } else { 35.117 - jio_snprintf(buf, buflen, 35.118 - "Internal Error (0x%x), pid=%d, tid=" UINTX_FORMAT, 35.119 - _id, os::current_process_id(), os::current_thread_id()); 35.120 - } 35.121 + jio_snprintf(buf, buflen, 35.122 + "Internal Error (0x%x), pid=%d, tid=" UINTX_FORMAT, 35.123 + _id, os::current_process_id(), os::current_thread_id()); 35.124 } 35.125 35.126 return buf; 35.127 @@ -369,7 +381,9 @@ 35.128 STEP(40, "(printing error message)") 35.129 35.130 // error message 35.131 - if (_message && _message[0] != '\0') { 35.132 + if (_detail_msg) { 35.133 + st->print_cr("# %s: %s", _message ? _message : "Error", _detail_msg); 35.134 + } else if (_message) { 35.135 st->print_cr("# Error: %s", _message); 35.136 } 35.137
36.1 --- a/src/share/vm/utilities/vmError.hpp Sun Oct 11 16:19:25 2009 -0700 36.2 +++ b/src/share/vm/utilities/vmError.hpp Thu Apr 22 13:23:15 2010 -0700 36.3 @@ -37,6 +37,7 @@ 36.4 // 0x8xxxxxxx system warnings 36.5 36.6 const char * _message; 36.7 + const char * _detail_msg; 36.8 36.9 Thread * _thread; // NULL if it's native thread 36.10 36.11 @@ -75,16 +76,19 @@ 36.12 char* buf, int buflen, bool verbose = false); 36.13 36.14 // accessor 36.15 - const char* message() { return _message; } 36.16 + const char* message() const { return _message; } 36.17 + const char* detail_msg() const { return _detail_msg; } 36.18 36.19 public: 36.20 // Constructor for crashes 36.21 VMError(Thread* thread, int sig, address pc, void* siginfo, void* context); 36.22 // Constructor for VM internal errors 36.23 - VMError(Thread* thread, const char* message, const char* filename, int lineno); 36.24 + VMError(Thread* thread, const char* filename, int lineno, 36.25 + const char* message, const char * detail_msg); 36.26 36.27 - // Constructors for VM OOM errors 36.28 - VMError(Thread* thread, size_t size, const char* message, const char* filename, int lineno); 36.29 + // Constructor for VM OOM errors 36.30 + VMError(Thread* thread, const char* filename, int lineno, size_t size, 36.31 + const char* message); 36.32 // Constructor for non-fatal errors 36.33 VMError(const char* message); 36.34
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 37.2 +++ b/test/runtime/6888954/vmerrors.sh Thu Apr 22 13:23:15 2010 -0700 37.3 @@ -0,0 +1,71 @@ 37.4 +# @test 37.5 +# @bug 6888954 37.6 +# @summary exercise HotSpot error handling code 37.7 +# @author John Coomes 37.8 +# @run shell vmerrors.sh 37.9 + 37.10 +# Repeatedly invoke java with a command-line option that causes HotSpot to 37.11 +# produce an error report and terminate just after initialization. Each 37.12 +# invocation is identified by a small integer, <n>, which provokes a different 37.13 +# error (assertion failure, guarantee failure, fatal error, etc.). The output 37.14 +# from stdout/stderr is written to <n>.out and the hs_err_pidXXX.log file is 37.15 +# renamed to <n>.log. 37.16 +# 37.17 +# The automated checking done by this script is minimal. When updating the 37.18 +# fatal error handler it is more useful to run it manually or to use the -retain 37.19 +# option with the jtreg so that test directories are not removed automatically. 37.20 +# To run stand-alone: 37.21 +# 37.22 +# TESTJAVA=/java/home/dir 37.23 +# TESTVMOPTS=... 37.24 +# export TESTJAVA TESTVMOPTS 37.25 +# sh test/runtime/6888954/vmerrors.sh 37.26 + 37.27 +ulimit -c 0 # no core files 37.28 + 37.29 +i=1 37.30 +rc=0 37.31 + 37.32 +assert_re='(assert|guarantee)[(](str|num).*failed: *' 37.33 +guarantee_re='guarantee[(](str|num).*failed: *' 37.34 +fatal_re='fatal error: *' 37.35 +signal_re='(SIGSEGV|EXCEPTION_ACCESS_VIOLATION).* at pc=' 37.36 +tail_1='.*expected null' 37.37 +tail_2='.*num=' 37.38 + 37.39 +for re in \ 37.40 + "${assert_re}${tail_1}" "${assert_re}${tail_2}" \ 37.41 + "${guarantee_re}${tail_1}" "${guarantee_re}${tail_2}" \ 37.42 + "${fatal_re}${tail_1}" "${fatal_re}${tail_2}" \ 37.43 + "${fatal_re}.*truncated" "ChunkPool::allocate" \ 37.44 + "ShouldNotCall" "ShouldNotReachHere" \ 37.45 + "Unimplemented" "$signal_re" 37.46 + 37.47 +do 37.48 + i2=$i 37.49 + [ $i -lt 10 ] && i2=0$i 37.50 + 37.51 + "$TESTJAVA/bin/java" $TESTVMOPTS -XX:+IgnoreUnrecognizedVMOptions \ 37.52 + -XX:ErrorHandlerTest=${i} -version > ${i2}.out 2>&1 37.53 + 37.54 + # If ErrorHandlerTest is ignored (product build), stop. 37.55 + # 37.56 + # Using the built-in variable $! to get the pid does not work reliably on 37.57 + # windows; use a wildcard instead. 37.58 + mv hs_err_pid*.log ${i2}.log || exit $rc 37.59 + 37.60 + for f in ${i2}.log ${i2}.out 37.61 + do 37.62 + egrep -- "$re" $f > $$ 37.63 + if [ $? -ne 0 ] 37.64 + then 37.65 + echo "ErrorHandlerTest=$i failed ($f)" 37.66 + rc=1 37.67 + fi 37.68 + done 37.69 + rm -f $$ 37.70 + 37.71 + i=$(expr $i + 1) 37.72 +done 37.73 + 37.74 +exit $rc