src/share/vm/compiler/compilerOracle.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 8056964 Sdiff src/share/vm/compiler

src/share/vm/compiler/compilerOracle.cpp

Print this page




 156 
 157   case Suffix: {
 158     size_t clen = strlen(candidate_string);
 159     size_t mlen = strlen(match_string);
 160     return clen >= mlen && strcmp(candidate_string + clen - mlen, match_string) == 0;
 161   }
 162 
 163   case Substring:
 164     return strstr(candidate_string, match_string) != NULL;
 165 
 166   default:
 167     return false;
 168   }
 169 }
 170 
 171 enum OptionType {
 172   IntxType,
 173   UintxType,
 174   BoolType,
 175   CcstrType,
 176   CcstrListType,
 177   UnknownType
 178 };
 179 
 180 /* Methods to map real type names to OptionType */
 181 template<typename T>
 182 static OptionType get_type_for() {
 183   return UnknownType;
 184 };
 185 
 186 template<> OptionType get_type_for<intx>() {
 187   return IntxType;
 188 }
 189 
 190 template<> OptionType get_type_for<uintx>() {
 191   return UintxType;
 192 }
 193 
 194 template<> OptionType get_type_for<bool>() {
 195   return BoolType;
 196 }
 197 













 198 template <typename T>
 199 class TypedMethodOptionMatcher : public MethodMatcher {
 200   const char* _option;
 201   OptionType _type;
 202   const T _value;
 203 
 204 public:
 205   TypedMethodOptionMatcher(Symbol* class_name, Mode class_mode,
 206                            Symbol* method_name, Mode method_mode,
 207                            Symbol* signature, const char* opt,
 208                            const T value,  MethodMatcher* next) :
 209     MethodMatcher(class_name, class_mode, method_name, method_mode, signature, next),
 210                   _type(get_type_for<T>()), _value(value) {
 211     _option = os::strdup_check_oom(opt);
 212   }
 213 
 214   ~TypedMethodOptionMatcher() {
 215     os::free((void*)_option);
 216   }
 217 
 218   TypedMethodOptionMatcher* match(methodHandle method, const char* opt) {
 219     TypedMethodOptionMatcher* current = this;
 220     while (current != NULL) {
 221       current = (TypedMethodOptionMatcher*)current->find(method);
 222       if (current == NULL) {
 223         return NULL;
 224       }
 225       if (strcmp(current->_option, opt) == 0) {
 226         return current;
 227       }
 228       current = current->next();
 229     }
 230     return NULL;


 236 
 237   OptionType get_type(void) {
 238       return _type;
 239   };
 240 
 241   T value() { return _value; }
 242 
 243   void print() {
 244     ttyLocker ttyl;
 245     print_base();
 246     tty->print(" %s", _option);
 247     tty->print(" <unknown option type>");
 248     tty->cr();
 249   }
 250 };
 251 
 252 template<>
 253 void TypedMethodOptionMatcher<intx>::print() {
 254   ttyLocker ttyl;
 255   print_base();
 256   tty->print(" %s", _option);
 257   tty->print(" " INTX_FORMAT, _value);
 258   tty->cr();
 259 };
 260 
 261 template<>
 262 void TypedMethodOptionMatcher<uintx>::print() {
 263   ttyLocker ttyl;
 264   print_base();
 265   tty->print(" %s", _option);
 266   tty->print(" " UINTX_FORMAT, _value);
 267   tty->cr();
 268 };
 269 
 270 template<>
 271 void TypedMethodOptionMatcher<bool>::print() {
 272   ttyLocker ttyl;
 273   print_base();
 274   tty->print(" %s", _option);
 275   tty->print(" %s", _value ? "true" : "false");









 276   tty->cr();
 277 };
 278 
 279 // this must parallel the command_names below
 280 enum OracleCommand {
 281   UnknownCommand = -1,
 282   OracleFirstCommand = 0,
 283   BreakCommand = OracleFirstCommand,
 284   PrintCommand,
 285   ExcludeCommand,
 286   InlineCommand,
 287   DontInlineCommand,
 288   CompileOnlyCommand,
 289   LogCommand,
 290   OptionCommand,
 291   QuietCommand,
 292   HelpCommand,
 293   OracleCommandCount
 294 };
 295 


 351    } else {
 352      return false;
 353    }
 354 }
 355 
 356 bool CompilerOracle::has_option_string(methodHandle method, const char* option) {
 357   bool value = false;
 358   get_option_value(method, option, value);
 359   return value;
 360 }
 361 
 362 template<typename T>
 363 bool CompilerOracle::has_option_value(methodHandle method, const char* option, T& value) {
 364   return get_option_value(method, option, value);
 365 }
 366 
 367 // Explicit instantiation for all OptionTypes supported.
 368 template bool CompilerOracle::has_option_value<intx>(methodHandle method, const char* option, intx& value);
 369 template bool CompilerOracle::has_option_value<uintx>(methodHandle method, const char* option, uintx& value);
 370 template bool CompilerOracle::has_option_value<bool>(methodHandle method, const char* option, bool& value);

 371 
 372 bool CompilerOracle::should_exclude(methodHandle method, bool& quietly) {
 373   quietly = true;
 374   if (lists[ExcludeCommand] != NULL) {
 375     if (lists[ExcludeCommand]->match(method)) {
 376       quietly = _quiet;
 377       return true;
 378     }
 379   }
 380 
 381   if (lists[CompileOnlyCommand] != NULL) {
 382     return !lists[CompileOnlyCommand]->match(method);
 383   }
 384   return false;
 385 }
 386 
 387 
 388 bool CompilerOracle::should_inline(methodHandle method) {
 389   return (check_predicate(InlineCommand, method));
 390 }


 526     line += bytes_read;
 527     total_bytes_read += bytes_read;
 528 
 529     // Read value.
 530     if (strcmp(type, "intx") == 0) {
 531       intx value;
 532       if (sscanf(line, "%*[ \t]" INTX_FORMAT "%n", &value, &bytes_read) == 1) {
 533         total_bytes_read += bytes_read;
 534         return add_option_string(c_name, c_match, m_name, m_match, signature, flag, value);
 535       } else {
 536         jio_snprintf(errorbuf, buf_size, "  Value cannot be read for flag %s of type %s ", flag, type);
 537       }
 538     } else if (strcmp(type, "uintx") == 0) {
 539       uintx value;
 540       if (sscanf(line, "%*[ \t]" UINTX_FORMAT "%n", &value, &bytes_read) == 1) {
 541         total_bytes_read += bytes_read;
 542         return add_option_string(c_name, c_match, m_name, m_match, signature, flag, value);
 543       } else {
 544         jio_snprintf(errorbuf, buf_size, "  Value cannot be read for flag %s of type %s", flag, type);
 545       }






























 546     } else if (strcmp(type, "bool") == 0) {
 547       char value[256];
 548       if (sscanf(line, "%*[ \t]%255[a-zA-Z]%n", value, &bytes_read) == 1) {
 549         if (strcmp(value, "true") == 0) {
 550           total_bytes_read += bytes_read;
 551           return add_option_string(c_name, c_match, m_name, m_match, signature, flag, true);



 552         } else {
 553           jio_snprintf(errorbuf, buf_size, "  Value cannot be read for flag %s of type %s", flag, type);
 554         }
 555       } else {
 556         jio_snprintf(errorbuf, sizeof(errorbuf), "  Value cannot be read for flag %s of type %s", flag, type);
 557       }
 558     } else {
 559       jio_snprintf(errorbuf, sizeof(errorbuf), "  Type %s not supported ", type);
 560     }
 561   } else {
 562     jio_snprintf(errorbuf, sizeof(errorbuf), "  Flag name for type %s should be alphanumeric ", type);
 563   }
 564   return NULL;
 565 }
 566 
 567 void CompilerOracle::parse_from_line(char* line) {
 568   if (line[0] == '\0') return;
 569   if (line[0] == '#')  return;
 570 
 571   bool have_colon = (strstr(line, "::") != NULL);


 632     // signatures always begin with ( so match that by hand
 633     if (1 == sscanf(line, "%*[ \t](%254[[);/" RANGEBASE "]%n", sig + 1, &bytes_read)) {
 634       sig[0] = '(';
 635       line += bytes_read;
 636       signature = SymbolTable::new_symbol(sig, CHECK);
 637     }
 638 
 639     if (command == OptionCommand) {
 640       // Look for trailing options.
 641       //
 642       // Two types of trailing options are
 643       // supported:
 644       //
 645       // (1) CompileCommand=option,Klass::method,flag
 646       // (2) CompileCommand=option,Klass::method,type,flag,value
 647       //
 648       // Type (1) is used to support ciMethod::has_option("someflag")
 649       // (i.e., to check if a flag "someflag" is enabled for a method).
 650       //
 651       // Type (2) is used to support options with a value. Values can have the
 652       // the following types: intx, uintx, bool, ccstr, and ccstrlist. Currently,
 653       // values of type intx, uintx, and bool are supported.
 654       //
 655       // For future extensions: extend scan_flag_and_value()
 656       char option[256]; // stores flag for Type (1) and type of Type (2)
 657       while (sscanf(line, "%*[ \t]%255[a-zA-Z0-9]%n", option, &bytes_read) == 1) {
 658         if (match != NULL && !_quiet) {
 659           // Print out the last match added
 660           ttyLocker ttyl;
 661           tty->print("CompilerOracle: %s ", command_names[command]);
 662           match->print();
 663         }
 664         line += bytes_read;
 665 
 666         if (strcmp(option, "intx") == 0
 667             || strcmp(option, "uintx") == 0
 668             || strcmp(option, "bool") == 0
 669             || strcmp(option, "ccstr") == 0
 670             || strcmp(option, "ccstrlist") == 0
 671             ) {
 672 
 673           // Type (2) option: parse flag name and value.




 156 
 157   case Suffix: {
 158     size_t clen = strlen(candidate_string);
 159     size_t mlen = strlen(match_string);
 160     return clen >= mlen && strcmp(candidate_string + clen - mlen, match_string) == 0;
 161   }
 162 
 163   case Substring:
 164     return strstr(candidate_string, match_string) != NULL;
 165 
 166   default:
 167     return false;
 168   }
 169 }
 170 
 171 enum OptionType {
 172   IntxType,
 173   UintxType,
 174   BoolType,
 175   CcstrType,

 176   UnknownType
 177 };
 178 
 179 /* Methods to map real type names to OptionType */
 180 template<typename T>
 181 static OptionType get_type_for() {
 182   return UnknownType;
 183 };
 184 
 185 template<> OptionType get_type_for<intx>() {
 186   return IntxType;
 187 }
 188 
 189 template<> OptionType get_type_for<uintx>() {
 190   return UintxType;
 191 }
 192 
 193 template<> OptionType get_type_for<bool>() {
 194   return BoolType;
 195 }
 196 
 197 template<> OptionType get_type_for<ccstr>() {
 198   return CcstrType;
 199 }
 200 
 201 template<typename T>
 202 static const T copy_value(const T value) {
 203   return value;
 204 }
 205 
 206 template<> const ccstr copy_value<ccstr>(const ccstr value) {
 207   return (const ccstr)os::strdup_check_oom(value);
 208 }
 209 
 210 template <typename T>
 211 class TypedMethodOptionMatcher : public MethodMatcher {
 212   const char* _option;
 213   OptionType _type;
 214   const T _value;
 215 
 216 public:
 217   TypedMethodOptionMatcher(Symbol* class_name, Mode class_mode,
 218                            Symbol* method_name, Mode method_mode,
 219                            Symbol* signature, const char* opt,
 220                            const T value,  MethodMatcher* next) :
 221     MethodMatcher(class_name, class_mode, method_name, method_mode, signature, next),
 222                   _type(get_type_for<T>()), _value(copy_value<T>(value)) {
 223     _option = os::strdup_check_oom(opt);
 224   }
 225 
 226   ~TypedMethodOptionMatcher() {
 227     os::free((void*)_option);
 228   }
 229 
 230   TypedMethodOptionMatcher* match(methodHandle method, const char* opt) {
 231     TypedMethodOptionMatcher* current = this;
 232     while (current != NULL) {
 233       current = (TypedMethodOptionMatcher*)current->find(method);
 234       if (current == NULL) {
 235         return NULL;
 236       }
 237       if (strcmp(current->_option, opt) == 0) {
 238         return current;
 239       }
 240       current = current->next();
 241     }
 242     return NULL;


 248 
 249   OptionType get_type(void) {
 250       return _type;
 251   };
 252 
 253   T value() { return _value; }
 254 
 255   void print() {
 256     ttyLocker ttyl;
 257     print_base();
 258     tty->print(" %s", _option);
 259     tty->print(" <unknown option type>");
 260     tty->cr();
 261   }
 262 };
 263 
 264 template<>
 265 void TypedMethodOptionMatcher<intx>::print() {
 266   ttyLocker ttyl;
 267   print_base();
 268   tty->print(" intx %s", _option);
 269   tty->print(" = " INTX_FORMAT, _value);
 270   tty->cr();
 271 };
 272 
 273 template<>
 274 void TypedMethodOptionMatcher<uintx>::print() {
 275   ttyLocker ttyl;
 276   print_base();
 277   tty->print(" uintx %s", _option);
 278   tty->print(" = " UINTX_FORMAT, _value);
 279   tty->cr();
 280 };
 281 
 282 template<>
 283 void TypedMethodOptionMatcher<bool>::print() {
 284   ttyLocker ttyl;
 285   print_base();
 286   tty->print(" bool %s", _option);
 287   tty->print(" = %s", _value ? "true" : "false");
 288   tty->cr();
 289 };
 290 
 291 template<>
 292 void TypedMethodOptionMatcher<ccstr>::print() {
 293   ttyLocker ttyl;
 294   print_base();
 295   tty->print(" const char* %s", _option);
 296   tty->print(" = '%s'", _value);
 297   tty->cr();
 298 };
 299 
 300 // this must parallel the command_names below
 301 enum OracleCommand {
 302   UnknownCommand = -1,
 303   OracleFirstCommand = 0,
 304   BreakCommand = OracleFirstCommand,
 305   PrintCommand,
 306   ExcludeCommand,
 307   InlineCommand,
 308   DontInlineCommand,
 309   CompileOnlyCommand,
 310   LogCommand,
 311   OptionCommand,
 312   QuietCommand,
 313   HelpCommand,
 314   OracleCommandCount
 315 };
 316 


 372    } else {
 373      return false;
 374    }
 375 }
 376 
 377 bool CompilerOracle::has_option_string(methodHandle method, const char* option) {
 378   bool value = false;
 379   get_option_value(method, option, value);
 380   return value;
 381 }
 382 
 383 template<typename T>
 384 bool CompilerOracle::has_option_value(methodHandle method, const char* option, T& value) {
 385   return get_option_value(method, option, value);
 386 }
 387 
 388 // Explicit instantiation for all OptionTypes supported.
 389 template bool CompilerOracle::has_option_value<intx>(methodHandle method, const char* option, intx& value);
 390 template bool CompilerOracle::has_option_value<uintx>(methodHandle method, const char* option, uintx& value);
 391 template bool CompilerOracle::has_option_value<bool>(methodHandle method, const char* option, bool& value);
 392 template bool CompilerOracle::has_option_value<ccstr>(methodHandle method, const char* option, ccstr& value);
 393 
 394 bool CompilerOracle::should_exclude(methodHandle method, bool& quietly) {
 395   quietly = true;
 396   if (lists[ExcludeCommand] != NULL) {
 397     if (lists[ExcludeCommand]->match(method)) {
 398       quietly = _quiet;
 399       return true;
 400     }
 401   }
 402 
 403   if (lists[CompileOnlyCommand] != NULL) {
 404     return !lists[CompileOnlyCommand]->match(method);
 405   }
 406   return false;
 407 }
 408 
 409 
 410 bool CompilerOracle::should_inline(methodHandle method) {
 411   return (check_predicate(InlineCommand, method));
 412 }


 548     line += bytes_read;
 549     total_bytes_read += bytes_read;
 550 
 551     // Read value.
 552     if (strcmp(type, "intx") == 0) {
 553       intx value;
 554       if (sscanf(line, "%*[ \t]" INTX_FORMAT "%n", &value, &bytes_read) == 1) {
 555         total_bytes_read += bytes_read;
 556         return add_option_string(c_name, c_match, m_name, m_match, signature, flag, value);
 557       } else {
 558         jio_snprintf(errorbuf, buf_size, "  Value cannot be read for flag %s of type %s ", flag, type);
 559       }
 560     } else if (strcmp(type, "uintx") == 0) {
 561       uintx value;
 562       if (sscanf(line, "%*[ \t]" UINTX_FORMAT "%n", &value, &bytes_read) == 1) {
 563         total_bytes_read += bytes_read;
 564         return add_option_string(c_name, c_match, m_name, m_match, signature, flag, value);
 565       } else {
 566         jio_snprintf(errorbuf, buf_size, "  Value cannot be read for flag %s of type %s", flag, type);
 567       }
 568     } else if (strcmp(type, "ccstr") == 0) {
 569       ResourceMark rm;
 570       char* value = NEW_RESOURCE_ARRAY(char, strlen(line) + 1);
 571       if (sscanf(line, "%*[ \t]%255[_a-zA-Z0-9]%n", value, &bytes_read) == 1) {
 572         total_bytes_read += bytes_read;
 573         return add_option_string(c_name, c_match, m_name, m_match, signature, flag, (ccstr)value);
 574       } else {
 575         jio_snprintf(errorbuf, buf_size, "  Value cannot be read for flag %s of type %s", flag, type);
 576       }
 577     } else if (strcmp(type, "ccstrlist") == 0) {
 578       // Accumulates several strings into one. The internal type is ccstr.
 579       ResourceMark rm;
 580       char* value = NEW_RESOURCE_ARRAY(char, strlen(line) + 1);
 581       char* next_value = value;
 582       if (sscanf(line, "%*[ \t]%255[_a-zA-Z0-9]%n", next_value, &bytes_read) == 1) {
 583         total_bytes_read += bytes_read;
 584         line += bytes_read;
 585         next_value += bytes_read;
 586         char* end_value = next_value-1;
 587         while (sscanf(line, "%*[ \t]%255[_a-zA-Z0-9]%n", next_value, &bytes_read) == 1) {
 588           total_bytes_read += bytes_read;
 589           line += bytes_read;
 590           *end_value = ' '; // override '\0'
 591           next_value += bytes_read;
 592           end_value = next_value-1;
 593         }
 594         return add_option_string(c_name, c_match, m_name, m_match, signature, flag, (ccstr)value);
 595       } else {
 596         jio_snprintf(errorbuf, buf_size, "  Value cannot be read for flag %s of type %s", flag, type);
 597       }
 598     } else if (strcmp(type, "bool") == 0) {
 599       char value[256];
 600       if (sscanf(line, "%*[ \t]%255[a-zA-Z]%n", value, &bytes_read) == 1) {
 601         if (strcmp(value, "true") == 0) {
 602           total_bytes_read += bytes_read;
 603           return add_option_string(c_name, c_match, m_name, m_match, signature, flag, true);
 604         } else if (strcmp(value, "false") == 0) {
 605           total_bytes_read += bytes_read;
 606           return add_option_string(c_name, c_match, m_name, m_match, signature, flag, false);
 607         } else {
 608           jio_snprintf(errorbuf, buf_size, "  Value cannot be read for flag %s of type %s", flag, type);
 609         }
 610       } else {
 611         jio_snprintf(errorbuf, sizeof(errorbuf), "  Value cannot be read for flag %s of type %s", flag, type);
 612       }
 613     } else {
 614       jio_snprintf(errorbuf, sizeof(errorbuf), "  Type %s not supported ", type);
 615     }
 616   } else {
 617     jio_snprintf(errorbuf, sizeof(errorbuf), "  Flag name for type %s should be alphanumeric ", type);
 618   }
 619   return NULL;
 620 }
 621 
 622 void CompilerOracle::parse_from_line(char* line) {
 623   if (line[0] == '\0') return;
 624   if (line[0] == '#')  return;
 625 
 626   bool have_colon = (strstr(line, "::") != NULL);


 687     // signatures always begin with ( so match that by hand
 688     if (1 == sscanf(line, "%*[ \t](%254[[);/" RANGEBASE "]%n", sig + 1, &bytes_read)) {
 689       sig[0] = '(';
 690       line += bytes_read;
 691       signature = SymbolTable::new_symbol(sig, CHECK);
 692     }
 693 
 694     if (command == OptionCommand) {
 695       // Look for trailing options.
 696       //
 697       // Two types of trailing options are
 698       // supported:
 699       //
 700       // (1) CompileCommand=option,Klass::method,flag
 701       // (2) CompileCommand=option,Klass::method,type,flag,value
 702       //
 703       // Type (1) is used to support ciMethod::has_option("someflag")
 704       // (i.e., to check if a flag "someflag" is enabled for a method).
 705       //
 706       // Type (2) is used to support options with a value. Values can have the
 707       // the following types: intx, uintx, bool, ccstr, and ccstrlist.

 708       //
 709       // For future extensions: extend scan_flag_and_value()
 710       char option[256]; // stores flag for Type (1) and type of Type (2)
 711       while (sscanf(line, "%*[ \t]%255[a-zA-Z0-9]%n", option, &bytes_read) == 1) {
 712         if (match != NULL && !_quiet) {
 713           // Print out the last match added
 714           ttyLocker ttyl;
 715           tty->print("CompilerOracle: %s ", command_names[command]);
 716           match->print();
 717         }
 718         line += bytes_read;
 719 
 720         if (strcmp(option, "intx") == 0
 721             || strcmp(option, "uintx") == 0
 722             || strcmp(option, "bool") == 0
 723             || strcmp(option, "ccstr") == 0
 724             || strcmp(option, "ccstrlist") == 0
 725             ) {
 726 
 727           // Type (2) option: parse flag name and value.


src/share/vm/compiler/compilerOracle.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File