Changeset 182331 in webkit


Ignore:
Timestamp:
Apr 3, 2015 2:01:43 PM (9 years ago)
Author:
mark.lam@apple.com
Message:

Some JSC Options refactoring and enhancements.
<https://webkit.org/b/143384>

Rubber stamped by Benjamin Poulain.

Create a better encapsulated Option class to make working with options easier. This
is a building block towards a JIT policy scaling debugging option I will introduce later.

This work entails:

  1. Convert Options::Option into a public class Option (who works closely with Options).
  2. Convert Options::EntryType into an enum class Options::Type and make it public.
  3. Renamed Options::OPT_<option name> to Options::<option name>ID because it reads better.
  4. Add misc methods to class Option to make it more useable.
  • runtime/Options.cpp:

(JSC::Options::dumpOption):
(JSC::Option::dump):
(JSC::Option::operator==):
(JSC::Options::Option::dump): Deleted.
(JSC::Options::Option::operator==): Deleted.

  • runtime/Options.h:

(JSC::Option::Option):
(JSC::Option::operator!=):
(JSC::Option::name):
(JSC::Option::description):
(JSC::Option::type):
(JSC::Option::isOverridden):
(JSC::Option::defaultOption):
(JSC::Option::boolVal):
(JSC::Option::unsignedVal):
(JSC::Option::doubleVal):
(JSC::Option::int32Val):
(JSC::Option::optionRangeVal):
(JSC::Option::optionStringVal):
(JSC::Option::gcLogLevelVal):
(JSC::Options::Option::Option): Deleted.
(JSC::Options::Option::operator!=): Deleted.

Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r182328 r182331  
     12015-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
    1412015-04-03  Geoffrey Garen  <ggaren@apple.com>
    242
  • trunk/Source/JavaScriptCore/runtime/Options.cpp

    r182314 r182331  
    208208const Options::EntryInfo Options::s_optionsInfo[Options::numberOfOptions] = {
    209209#define FOR_EACH_OPTION(type_, name_, defaultValue_, description_) \
    210     { #name_, description_, Options::type_##Type },
     210    { #name_, description_, Options::Type::type_##Type },
    211211    JSC_OPTIONS(FOR_EACH_OPTION)
    212212#undef FOR_EACH_OPTION
     
    367367        return; // Illegal option.
    368368
    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());
    375372
    376373    if (level == DumpLevel::Overridden && !wasOverridden)
    377374        return;
    378375
    379     fprintf(stream, "%s%s: ", header, s_optionsInfo[id].name);
     376    fprintf(stream, "%s%s: ", header, option.name());
    380377    option.dump(stream);
    381378
    382379    if (wasOverridden) {
    383380        fprintf(stream, " (default: ");
    384         defaultOption.dump(stream);
     381        option.defaultOption().dump(stream);
    385382        fprintf(stream, ")");
    386383    }
    387384
    388385    if (needsDescription)
    389         fprintf(stream, "\n%s   - %s", header, s_optionsInfo[id].description);
     386        fprintf(stream, "   ... %s", option.description());
    390387
    391388    fprintf(stream, "%s", footer);
    392389}
    393390
    394 void Options::Option::dump(FILE* stream) const
    395 {
    396     switch (m_type) {
    397     case boolType:
     391void Option::dump(FILE* stream) const
     392{
     393    switch (type()) {
     394    case Options::Type::boolType:
    398395        fprintf(stream, "%s", m_entry.boolVal ? "true" : "false");
    399396        break;
    400     case unsignedType:
     397    case Options::Type::unsignedType:
    401398        fprintf(stream, "%u", m_entry.unsignedVal);
    402399        break;
    403     case doubleType:
     400    case Options::Type::doubleType:
    404401        fprintf(stream, "%lf", m_entry.doubleVal);
    405402        break;
    406     case int32Type:
     403    case Options::Type::int32Type:
    407404        fprintf(stream, "%d", m_entry.int32Val);
    408405        break;
    409     case optionRangeType:
     406    case Options::Type::optionRangeType:
    410407        fprintf(stream, "%s", m_entry.optionRangeVal.rangeString());
    411408        break;
    412     case optionStringType: {
     409    case Options::Type::optionStringType: {
    413410        const char* option = m_entry.optionStringVal;
    414411        if (!option)
     
    417414        break;
    418415    }
    419     case gcLogLevelType: {
     416    case Options::Type::gcLogLevelType: {
    420417        fprintf(stream, "%s", GCLogging::levelAsString(m_entry.gcLogLevelVal));
    421418        break;
     
    424421}
    425422
    426 bool Options::Option::operator==(const Options::Option& other) const
    427 {
    428     switch (m_type) {
    429     case boolType:
     423bool Option::operator==(const Option& other) const
     424{
     425    switch (type()) {
     426    case Options::Type::boolType:
    430427        return m_entry.boolVal == other.m_entry.boolVal;
    431     case unsignedType:
     428    case Options::Type::unsignedType:
    432429        return m_entry.unsignedVal == other.m_entry.unsignedVal;
    433     case doubleType:
     430    case Options::Type::doubleType:
    434431        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:
    436433        return m_entry.int32Val == other.m_entry.int32Val;
    437     case optionRangeType:
     434    case Options::Type::optionRangeType:
    438435        return m_entry.optionRangeVal.rangeString() == other.m_entry.optionRangeVal.rangeString();
    439     case optionStringType:
     436    case Options::Type::optionStringType:
    440437        return (m_entry.optionStringVal == other.m_entry.optionStringVal)
    441438            || (m_entry.optionStringVal && other.m_entry.optionStringVal && !strcmp(m_entry.optionStringVal, other.m_entry.optionStringVal));
    442     case gcLogLevelType:
     439    case Options::Type::gcLogLevelType:
    443440        return m_entry.gcLogLevelVal == other.m_entry.gcLogLevelVal;
    444441    }
  • trunk/Source/JavaScriptCore/runtime/Options.h

    r182318 r182331  
    322322    enum OptionID {
    323323#define FOR_EACH_OPTION(type_, name_, defaultValue_, description_) \
    324         OPT_##name_,
     324        name_##ID,
    325325        JSC_OPTIONS(FOR_EACH_OPTION)
    326326#undef FOR_EACH_OPTION
     
    328328    };
    329329
    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 {
    349331        boolType,
    350332        unsignedType,
     
    356338    };
    357339
     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
     356private:
    358357    // For storing for an option value:
    359358    union Entry {
     
    367366    };
    368367
    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 
    386368    // For storing constant meta data about each option:
    387369    struct EntryInfo {
    388370        const char* name;
    389371        const char* description;
    390         EntryType type;
     372        Type type;
    391373    };
    392374
     
    397379    static Entry s_defaultOptions[numberOfOptions];
    398380    static const EntryInfo s_optionsInfo[numberOfOptions];
     381
     382    friend class Option;
    399383};
    400384
     385class Option {
     386public:
     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   
     411private:
     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
     423inline const char* Option::name() const
     424{
     425    return Options::s_optionsInfo[m_id].name;
     426}
     427
     428inline const char* Option::description() const
     429{
     430    return Options::s_optionsInfo[m_id].description;
     431}
     432
     433inline Options::Type Option::type() const
     434{
     435    return Options::s_optionsInfo[m_id].type;
     436}
     437
     438inline bool Option::isOverridden() const
     439{
     440    return *this != defaultOption();
     441}
     442
     443inline const Option Option::defaultOption() const
     444{
     445    return Option(m_id, Options::s_defaultOptions[m_id]);
     446}
     447
     448inline bool& Option::boolVal()
     449{
     450    return m_entry.boolVal;
     451}
     452
     453inline unsigned& Option::unsignedVal()
     454{
     455    return m_entry.unsignedVal;
     456}
     457
     458inline double& Option::doubleVal()
     459{
     460    return m_entry.doubleVal;
     461}
     462
     463inline int32_t& Option::int32Val()
     464{
     465    return m_entry.int32Val;
     466}
     467
     468inline OptionRange Option::optionRangeVal()
     469{
     470    return m_entry.optionRangeVal;
     471}
     472
     473inline const char* Option::optionStringVal()
     474{
     475    return m_entry.optionStringVal;
     476}
     477
     478inline GCLogging::Level& Option::gcLogLevelVal()
     479{
     480    return m_entry.gcLogLevelVal;
     481}
     482
    401483} // namespace JSC
    402484
Note: See TracChangeset for help on using the changeset viewer.