Changeset 182331 in webkit
- Timestamp:
- Apr 3, 2015 2:01:43 PM (9 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r182328 r182331 1 2015-04-03 Mark Lam <mark.lam@apple.com> 2 3 Some JSC Options refactoring and enhancements. 4 <https://webkit.org/b/143384> 5 6 Rubber stamped by Benjamin Poulain. 7 8 Create a better encapsulated Option class to make working with options easier. This 9 is a building block towards a JIT policy scaling debugging option I will introduce later. 10 11 This work entails: 12 1. Convert Options::Option into a public class Option (who works closely with Options). 13 2. Convert Options::EntryType into an enum class Options::Type and make it public. 14 3. Renamed Options::OPT_<option name> to Options::<option name>ID because it reads better. 15 4. Add misc methods to class Option to make it more useable. 16 17 * runtime/Options.cpp: 18 (JSC::Options::dumpOption): 19 (JSC::Option::dump): 20 (JSC::Option::operator==): 21 (JSC::Options::Option::dump): Deleted. 22 (JSC::Options::Option::operator==): Deleted. 23 * runtime/Options.h: 24 (JSC::Option::Option): 25 (JSC::Option::operator!=): 26 (JSC::Option::name): 27 (JSC::Option::description): 28 (JSC::Option::type): 29 (JSC::Option::isOverridden): 30 (JSC::Option::defaultOption): 31 (JSC::Option::boolVal): 32 (JSC::Option::unsignedVal): 33 (JSC::Option::doubleVal): 34 (JSC::Option::int32Val): 35 (JSC::Option::optionRangeVal): 36 (JSC::Option::optionStringVal): 37 (JSC::Option::gcLogLevelVal): 38 (JSC::Options::Option::Option): Deleted. 39 (JSC::Options::Option::operator!=): Deleted. 40 1 41 2015-04-03 Geoffrey Garen <ggaren@apple.com> 2 42 -
trunk/Source/JavaScriptCore/runtime/Options.cpp
r182314 r182331 208 208 const Options::EntryInfo Options::s_optionsInfo[Options::numberOfOptions] = { 209 209 #define FOR_EACH_OPTION(type_, name_, defaultValue_, description_) \ 210 { #name_, description_, Options:: type_##Type },210 { #name_, description_, Options::Type::type_##Type }, 211 211 JSC_OPTIONS(FOR_EACH_OPTION) 212 212 #undef FOR_EACH_OPTION … … 367 367 return; // Illegal option. 368 368 369 EntryType type = s_optionsInfo[id].type; 370 Option option(type, s_options[id]); 371 Option defaultOption(type, s_defaultOptions[id]); 372 373 bool wasOverridden = (option != defaultOption); 374 bool needsDescription = (level == DumpLevel::Verbose && s_optionsInfo[id].description); 369 Option option(id); 370 bool wasOverridden = option.isOverridden(); 371 bool needsDescription = (level == DumpLevel::Verbose && option.description()); 375 372 376 373 if (level == DumpLevel::Overridden && !wasOverridden) 377 374 return; 378 375 379 fprintf(stream, "%s%s: ", header, s_optionsInfo[id].name);376 fprintf(stream, "%s%s: ", header, option.name()); 380 377 option.dump(stream); 381 378 382 379 if (wasOverridden) { 383 380 fprintf(stream, " (default: "); 384 defaultOption.dump(stream);381 option.defaultOption().dump(stream); 385 382 fprintf(stream, ")"); 386 383 } 387 384 388 385 if (needsDescription) 389 fprintf(stream, " \n%s - %s", header, s_optionsInfo[id].description);386 fprintf(stream, " ... %s", option.description()); 390 387 391 388 fprintf(stream, "%s", footer); 392 389 } 393 390 394 void Option s::Option::dump(FILE* stream) const395 { 396 switch ( m_type) {397 case boolType:391 void Option::dump(FILE* stream) const 392 { 393 switch (type()) { 394 case Options::Type::boolType: 398 395 fprintf(stream, "%s", m_entry.boolVal ? "true" : "false"); 399 396 break; 400 case unsignedType:397 case Options::Type::unsignedType: 401 398 fprintf(stream, "%u", m_entry.unsignedVal); 402 399 break; 403 case doubleType:400 case Options::Type::doubleType: 404 401 fprintf(stream, "%lf", m_entry.doubleVal); 405 402 break; 406 case int32Type:403 case Options::Type::int32Type: 407 404 fprintf(stream, "%d", m_entry.int32Val); 408 405 break; 409 case optionRangeType:406 case Options::Type::optionRangeType: 410 407 fprintf(stream, "%s", m_entry.optionRangeVal.rangeString()); 411 408 break; 412 case optionStringType: {409 case Options::Type::optionStringType: { 413 410 const char* option = m_entry.optionStringVal; 414 411 if (!option) … … 417 414 break; 418 415 } 419 case gcLogLevelType: {416 case Options::Type::gcLogLevelType: { 420 417 fprintf(stream, "%s", GCLogging::levelAsString(m_entry.gcLogLevelVal)); 421 418 break; … … 424 421 } 425 422 426 bool Option s::Option::operator==(const Options::Option& other) const427 { 428 switch ( m_type) {429 case boolType:423 bool Option::operator==(const Option& other) const 424 { 425 switch (type()) { 426 case Options::Type::boolType: 430 427 return m_entry.boolVal == other.m_entry.boolVal; 431 case unsignedType:428 case Options::Type::unsignedType: 432 429 return m_entry.unsignedVal == other.m_entry.unsignedVal; 433 case doubleType:430 case Options::Type::doubleType: 434 431 return (m_entry.doubleVal == other.m_entry.doubleVal) || (isnan(m_entry.doubleVal) && isnan(other.m_entry.doubleVal)); 435 case int32Type:432 case Options::Type::int32Type: 436 433 return m_entry.int32Val == other.m_entry.int32Val; 437 case optionRangeType:434 case Options::Type::optionRangeType: 438 435 return m_entry.optionRangeVal.rangeString() == other.m_entry.optionRangeVal.rangeString(); 439 case optionStringType:436 case Options::Type::optionStringType: 440 437 return (m_entry.optionStringVal == other.m_entry.optionStringVal) 441 438 || (m_entry.optionStringVal && other.m_entry.optionStringVal && !strcmp(m_entry.optionStringVal, other.m_entry.optionStringVal)); 442 case gcLogLevelType:439 case Options::Type::gcLogLevelType: 443 440 return m_entry.gcLogLevelVal == other.m_entry.gcLogLevelVal; 444 441 } -
trunk/Source/JavaScriptCore/runtime/Options.h
r182318 r182331 322 322 enum OptionID { 323 323 #define FOR_EACH_OPTION(type_, name_, defaultValue_, description_) \ 324 OPT_##name_,324 name_##ID, 325 325 JSC_OPTIONS(FOR_EACH_OPTION) 326 326 #undef FOR_EACH_OPTION … … 328 328 }; 329 329 330 331 static void initialize(); 332 333 // Parses a single command line option in the format "<optionName>=<value>" 334 // (no spaces allowed) and set the specified option if appropriate. 335 JS_EXPORT_PRIVATE static bool setOption(const char* arg); 336 JS_EXPORT_PRIVATE static void dumpAllOptions(DumpLevel, const char* title = nullptr, FILE* stream = stdout); 337 static void dumpOption(DumpLevel, OptionID, FILE* stream = stdout, const char* header = "", const char* footer = ""); 338 339 // Declare accessors for each option: 340 #define FOR_EACH_OPTION(type_, name_, defaultValue_, description_) \ 341 ALWAYS_INLINE static type_& name_() { return s_options[OPT_##name_].type_##Val; } \ 342 ALWAYS_INLINE static type_& name_##Default() { return s_defaultOptions[OPT_##name_].type_##Val; } 343 344 JSC_OPTIONS(FOR_EACH_OPTION) 345 #undef FOR_EACH_OPTION 346 347 private: 348 enum EntryType { 330 enum class Type { 349 331 boolType, 350 332 unsignedType, … … 356 338 }; 357 339 340 static void initialize(); 341 342 // Parses a single command line option in the format "<optionName>=<value>" 343 // (no spaces allowed) and set the specified option if appropriate. 344 JS_EXPORT_PRIVATE static bool setOption(const char* arg); 345 JS_EXPORT_PRIVATE static void dumpAllOptions(DumpLevel, const char* title = nullptr, FILE* stream = stdout); 346 static void dumpOption(DumpLevel, OptionID, FILE* stream = stdout, const char* header = "", const char* footer = ""); 347 348 // Declare accessors for each option: 349 #define FOR_EACH_OPTION(type_, name_, defaultValue_, description_) \ 350 ALWAYS_INLINE static type_& name_() { return s_options[name_##ID].type_##Val; } \ 351 ALWAYS_INLINE static type_& name_##Default() { return s_defaultOptions[name_##ID].type_##Val; } 352 353 JSC_OPTIONS(FOR_EACH_OPTION) 354 #undef FOR_EACH_OPTION 355 356 private: 358 357 // For storing for an option value: 359 358 union Entry { … … 367 366 }; 368 367 369 class Option {370 public:371 Option(EntryType type, Entry& entry)372 : m_type(type)373 , m_entry(entry)374 {375 }376 377 void dump(FILE*) const;378 bool operator==(const Option& other) const;379 bool operator!=(const Option& other) const { return !(*this == other); }380 381 private:382 EntryType m_type;383 Entry& m_entry;384 };385 386 368 // For storing constant meta data about each option: 387 369 struct EntryInfo { 388 370 const char* name; 389 371 const char* description; 390 EntryType type;372 Type type; 391 373 }; 392 374 … … 397 379 static Entry s_defaultOptions[numberOfOptions]; 398 380 static const EntryInfo s_optionsInfo[numberOfOptions]; 381 382 friend class Option; 399 383 }; 400 384 385 class Option { 386 public: 387 Option(Options::OptionID id) 388 : m_id(id) 389 , m_entry(Options::s_options[m_id]) 390 { 391 } 392 393 void dump(FILE*) const; 394 bool operator==(const Option& other) const; 395 bool operator!=(const Option& other) const { return !(*this == other); } 396 397 const char* name() const; 398 const char* description() const; 399 Options::Type type() const; 400 bool isOverridden() const; 401 const Option defaultOption() const; 402 403 bool& boolVal(); 404 unsigned& unsignedVal(); 405 double& doubleVal(); 406 int32_t& int32Val(); 407 OptionRange optionRangeVal(); 408 const char* optionStringVal(); 409 GCLogging::Level& gcLogLevelVal(); 410 411 private: 412 // Only used for constructing default Options. 413 Option(Options::OptionID id, Options::Entry& entry) 414 : m_id(id) 415 , m_entry(entry) 416 { 417 } 418 419 Options::OptionID m_id; 420 Options::Entry& m_entry; 421 }; 422 423 inline const char* Option::name() const 424 { 425 return Options::s_optionsInfo[m_id].name; 426 } 427 428 inline const char* Option::description() const 429 { 430 return Options::s_optionsInfo[m_id].description; 431 } 432 433 inline Options::Type Option::type() const 434 { 435 return Options::s_optionsInfo[m_id].type; 436 } 437 438 inline bool Option::isOverridden() const 439 { 440 return *this != defaultOption(); 441 } 442 443 inline const Option Option::defaultOption() const 444 { 445 return Option(m_id, Options::s_defaultOptions[m_id]); 446 } 447 448 inline bool& Option::boolVal() 449 { 450 return m_entry.boolVal; 451 } 452 453 inline unsigned& Option::unsignedVal() 454 { 455 return m_entry.unsignedVal; 456 } 457 458 inline double& Option::doubleVal() 459 { 460 return m_entry.doubleVal; 461 } 462 463 inline int32_t& Option::int32Val() 464 { 465 return m_entry.int32Val; 466 } 467 468 inline OptionRange Option::optionRangeVal() 469 { 470 return m_entry.optionRangeVal; 471 } 472 473 inline const char* Option::optionStringVal() 474 { 475 return m_entry.optionStringVal; 476 } 477 478 inline GCLogging::Level& Option::gcLogLevelVal() 479 { 480 return m_entry.gcLogLevelVal; 481 } 482 401 483 } // namespace JSC 402 484
Note: See TracChangeset
for help on using the changeset viewer.