< prev index next >

src/share/vm/utilities/debug.cpp

Print this page
rev 7615 : [mq]: debug_test
rev 7616 : [mq]: copyrights
   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 309 #include <signal.h>
 310 
 311 void test_error_handler() {
 312   uintx test_num = ErrorHandlerTest;
 313   if (test_num == 0) return;
 314 
 315   // If asserts are disabled, use the corresponding guarantee instead.
 316   size_t n = test_num;
 317   NOT_DEBUG(if (n <= 2) n += 2);
 318 
 319   const char* const str = "hello";
 320   const size_t      num = (size_t)os::vm_page_size();
 321 
 322   const char* const eol = os::line_separator();
 323   const char* const msg = "this message should be truncated during formatting";
 324   char * const dataPtr = NULL;  // bad data pointer
 325   const void (*funcPtr)(void) = (const void(*)()) 0xF;  // bad function pointer
 326 
 327   // Keep this in sync with test/runtime/6888954/vmerrors.sh.
 328   switch (n) {
 329     case  1: assert(str == NULL, "expected null");
 330     case  2: assert(num == 1023 && *str == 'X',
 331                     err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str));
 332     case  3: guarantee(str == NULL, "expected null");
 333     case  4: guarantee(num == 1023 && *str == 'X',
 334                        err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str));
 335     case  5: fatal("expected null");
 336     case  6: fatal(err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str));
 337     case  7: fatal(err_msg("%s%s#    %s%s#    %s%s#    %s%s#    %s%s#    "
 338                            "%s%s#    %s%s#    %s%s#    %s%s#    %s%s#    "
 339                            "%s%s#    %s%s#    %s%s#    %s%s#    %s",
 340                            msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
 341                            msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
 342                            msg, eol, msg, eol, msg, eol, msg, eol, msg));
 343     case  8: vm_exit_out_of_memory(num, OOM_MALLOC_ERROR, "ChunkPool::allocate");
 344     case  9: ShouldNotCallThis();
 345     case 10: ShouldNotReachHere();
 346     case 11: Unimplemented();
 347     // There's no guarantee the bad data pointer will crash us
 348     // so "break" out to the ShouldNotReachHere().
 349     case 12: *dataPtr = '\0'; break;
 350     // There's no guarantee the bad function pointer will crash us


   1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 309 #include <signal.h>
 310 
 311 void test_error_handler() {
 312   uintx test_num = ErrorHandlerTest;
 313   if (test_num == 0) return;
 314 
 315   // If asserts are disabled, use the corresponding guarantee instead.
 316   size_t n = test_num;
 317   NOT_DEBUG(if (n <= 2) n += 2);
 318 
 319   const char* const str = "hello";
 320   const size_t      num = (size_t)os::vm_page_size();
 321 
 322   const char* const eol = os::line_separator();
 323   const char* const msg = "this message should be truncated during formatting";
 324   char * const dataPtr = NULL;  // bad data pointer
 325   const void (*funcPtr)(void) = (const void(*)()) 0xF;  // bad function pointer
 326 
 327   // Keep this in sync with test/runtime/6888954/vmerrors.sh.
 328   switch (n) {
 329     case  1: vmassert(str == NULL, "expected null");
 330     case  2: vmassert(num == 1023 && *str == 'X',
 331                       err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str));
 332     case  3: guarantee(str == NULL, "expected null");
 333     case  4: guarantee(num == 1023 && *str == 'X',
 334                        err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str));
 335     case  5: fatal("expected null");
 336     case  6: fatal(err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str));
 337     case  7: fatal(err_msg("%s%s#    %s%s#    %s%s#    %s%s#    %s%s#    "
 338                            "%s%s#    %s%s#    %s%s#    %s%s#    %s%s#    "
 339                            "%s%s#    %s%s#    %s%s#    %s%s#    %s",
 340                            msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
 341                            msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
 342                            msg, eol, msg, eol, msg, eol, msg, eol, msg));
 343     case  8: vm_exit_out_of_memory(num, OOM_MALLOC_ERROR, "ChunkPool::allocate");
 344     case  9: ShouldNotCallThis();
 345     case 10: ShouldNotReachHere();
 346     case 11: Unimplemented();
 347     // There's no guarantee the bad data pointer will crash us
 348     // so "break" out to the ShouldNotReachHere().
 349     case 12: *dataPtr = '\0'; break;
 350     // There's no guarantee the bad function pointer will crash us


< prev index next >