< prev index next >

src/share/vm/runtime/globals.cpp

Print this page
rev 12397 : 8170981: Possible access to char array with negative index


 452 }
 453 
 454 bool Flag::is_writeable() const {
 455   return is_manageable() || (is_product() && is_read_write()) || is_writeable_ext();
 456 }
 457 
 458 // All flags except "manageable" are assumed to be internal flags.
 459 // Long term, we need to define a mechanism to specify which flags
 460 // are external/stable and change this function accordingly.
 461 bool Flag::is_external() const {
 462   return is_manageable() || is_external_ext();
 463 }
 464 
 465 void Flag::print_on(outputStream* st, bool withComments, bool printRanges) {
 466   // Don't print notproduct and develop flags in a product build.
 467   if (is_constant_in_binary()) {
 468     return;
 469   }
 470 
 471   if (!printRanges) {




 472     // The print below assumes that the flag name is 40 characters or less.
 473     // This works for most flags, but there are exceptions. Our longest flag
 474     // name right now is UseAdaptiveGenerationSizePolicyAtMajorCollection and
 475     // its minor collection buddy. These are 48 characters. We use a buffer of
 476     // 10 spaces below to adjust the space between the flag value and the
 477     // column of flag type and origin that is printed in the end of the line.
 478     char spaces[10 + 1] = "          ";
 479     st->print("%9s %-40s = ", _type, _name);
 480 
 481     if (is_bool()) {
 482       st->print("%-20s", get_bool() ? "true" : "false");
 483     } else if (is_int()) {
 484       st->print("%-20d", get_int());
 485     } else if (is_uint()) {
 486       st->print("%-20u", get_uint());
 487     } else if (is_intx()) {
 488       st->print(INTX_FORMAT_W(-20), get_intx());
 489     } else if (is_uintx()) {
 490       st->print(UINTX_FORMAT_W(-20), get_uintx());
 491     } else if (is_uint64_t()) {
 492       st->print(UINT64_FORMAT_W(-20), get_uint64_t());
 493     } else if (is_size_t()) {
 494       st->print(SIZE_FORMAT_W(-20), get_size_t());
 495     } else if (is_double()) {
 496       st->print("%-20f", get_double());
 497     } else if (is_ccstr()) {
 498       const char* cp = get_ccstr();
 499       if (cp != NULL) {
 500         const char* eol;
 501         while ((eol = strchr(cp, '\n')) != NULL) {
 502           size_t llen = pointer_delta(eol, cp, sizeof(char));
 503           st->print("%.*s", (int)llen, cp);
 504           st->cr();
 505           cp = eol+1;
 506           st->print("%5s %-35s += ", "", _name);
 507         }
 508         st->print("%-20s", cp);
 509       }
 510       else st->print("%-20s", "");
 511     }
 512     assert(strlen(_name) < 50, "Flag name is longer than expected");
 513     spaces[50 - MAX2((size_t)40, strlen(_name))] = '\0';


 514     st->print("%s", spaces);

 515     print_kind_and_origin(st);
 516 
 517 #ifndef PRODUCT
 518     if (withComments) {
 519       st->print("%s", _doc);
 520     }
 521 #endif
 522 
 523     st->cr();
 524 
 525   } else if (!is_bool() && !is_ccstr()) {
 526     st->print("%9s %-50s ", _type, _name);
 527 
 528     RangeStrFunc func = NULL;
 529     if (is_int()) {
 530       func = Flag::get_int_default_range_str;
 531     } else if (is_uint()) {
 532       func = Flag::get_uint_default_range_str;
 533     } else if (is_intx()) {
 534       func = Flag::get_intx_default_range_str;




 452 }
 453 
 454 bool Flag::is_writeable() const {
 455   return is_manageable() || (is_product() && is_read_write()) || is_writeable_ext();
 456 }
 457 
 458 // All flags except "manageable" are assumed to be internal flags.
 459 // Long term, we need to define a mechanism to specify which flags
 460 // are external/stable and change this function accordingly.
 461 bool Flag::is_external() const {
 462   return is_manageable() || is_external_ext();
 463 }
 464 
 465 void Flag::print_on(outputStream* st, bool withComments, bool printRanges) {
 466   // Don't print notproduct and develop flags in a product build.
 467   if (is_constant_in_binary()) {
 468     return;
 469   }
 470 
 471   if (!printRanges) {
 472     // Use some named constants to make code more readable.
 473     const unsigned int nSpaces    = 10;
 474     const unsigned int maxFlagLen = 40 + nSpaces;
 475 
 476     // The print below assumes that the flag name is 40 characters or less.
 477     // This works for most flags, but there are exceptions. Our longest flag
 478     // name right now is UseAdaptiveGenerationSizePolicyAtMajorCollection and
 479     // its minor collection buddy. These are 48 characters. We use a buffer of
 480     // nSpaces spaces below to adjust the space between the flag value and the
 481     // column of flag type and origin that is printed in the end of the line.
 482     char spaces[nSpaces + 1] = "          ";
 483     st->print("%9s %-*s = ", _type, maxFlagLen-nSpaces, _name);
 484 
 485     if (is_bool()) {
 486       st->print("%-20s", get_bool() ? "true" : "false");
 487     } else if (is_int()) {
 488       st->print("%-20d", get_int());
 489     } else if (is_uint()) {
 490       st->print("%-20u", get_uint());
 491     } else if (is_intx()) {
 492       st->print(INTX_FORMAT_W(-20), get_intx());
 493     } else if (is_uintx()) {
 494       st->print(UINTX_FORMAT_W(-20), get_uintx());
 495     } else if (is_uint64_t()) {
 496       st->print(UINT64_FORMAT_W(-20), get_uint64_t());
 497     } else if (is_size_t()) {
 498       st->print(SIZE_FORMAT_W(-20), get_size_t());
 499     } else if (is_double()) {
 500       st->print("%-20f", get_double());
 501     } else if (is_ccstr()) {
 502       const char* cp = get_ccstr();
 503       if (cp != NULL) {
 504         const char* eol;
 505         while ((eol = strchr(cp, '\n')) != NULL) {
 506           size_t llen = pointer_delta(eol, cp, sizeof(char));
 507           st->print("%.*s", (int)llen, cp);
 508           st->cr();
 509           cp = eol+1;
 510           st->print("%5s %-35s += ", "", _name);
 511         }
 512         st->print("%-20s", cp);
 513       }
 514       else st->print("%-20s", "");
 515     }
 516     // Make sure we do not punch a '\0' at a negative char array index.
 517     unsigned int nameLen = strlen(_name);
 518     if (nameLen <= maxFlagLen) {
 519       spaces[maxFlagLen - MAX2(maxFlagLen-nSpaces, nameLen)] = '\0';
 520       st->print("%s", spaces);
 521     }
 522     print_kind_and_origin(st);
 523 
 524 #ifndef PRODUCT
 525     if (withComments) {
 526       st->print("%s", _doc);
 527     }
 528 #endif
 529 
 530     st->cr();
 531 
 532   } else if (!is_bool() && !is_ccstr()) {
 533     st->print("%9s %-50s ", _type, _name);
 534 
 535     RangeStrFunc func = NULL;
 536     if (is_int()) {
 537       func = Flag::get_int_default_range_str;
 538     } else if (is_uint()) {
 539       func = Flag::get_uint_default_range_str;
 540     } else if (is_intx()) {
 541       func = Flag::get_intx_default_range_str;


< prev index next >