Changeset 188887 in webkit


Ignore:
Timestamp:
Aug 24, 2015 2:51:26 PM (9 years ago)
Author:
mark.lam@apple.com
Message:

Add support for setting JSC options from a file.
https://bugs.webkit.org/show_bug.cgi?id=148394

Reviewed by Saam Barati.

This is needed for environments where the JSC executable does not have access to
environmental variables. This is only needed for debugging, and is currently
guarded under a #define USE_OPTIONS_FILE in Options.cpp, and is disabled by
default.

Also fixed Options::setOptions() to be allow for whitespace that is not a single
' '. This makes setOptions() much more flexible and friendlier to use for loading
options in general.

For example, this current use case of loading options from a file may have '\n's
in the character stream, and this feature is easier to implement if setOptions()
just support more than 1 whitespace char between options, and recognize whitespace
characters other than ' '.

  • runtime/Options.cpp:

(JSC::parse):
(JSC::Options::initialize):
(JSC::Options::setOptions):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r188886 r188887  
     12015-08-24  Mark Lam  <mark.lam@apple.com>
     2
     3        Add support for setting JSC options from a file.
     4        https://bugs.webkit.org/show_bug.cgi?id=148394
     5
     6        Reviewed by Saam Barati.
     7
     8        This is needed for environments where the JSC executable does not have access to
     9        environmental variables.  This is only needed for debugging, and is currently
     10        guarded under a #define USE_OPTIONS_FILE in Options.cpp, and is disabled by
     11        default.
     12
     13        Also fixed Options::setOptions() to be allow for whitespace that is not a single
     14        ' '.  This makes setOptions() much more flexible and friendlier to use for loading
     15        options in general.
     16
     17        For example, this current use case of loading options from a file may have '\n's
     18        in the character stream, and this feature is easier to implement if setOptions()
     19        just support more than 1 whitespace char between options, and recognize whitespace
     20        characters other than ' '.
     21
     22        * runtime/Options.cpp:
     23        (JSC::parse):
     24        (JSC::Options::initialize):
     25        (JSC::Options::setOptions):
     26
    1272015-08-24  Filip Pizlo  <fpizlo@apple.com>
    228
  • trunk/Source/JavaScriptCore/runtime/Options.cpp

    r188648 r188887  
    3434#include <stdlib.h>
    3535#include <string.h>
     36#include <wtf/ASCIICType.h>
    3637#include <wtf/DataLog.h>
    3738#include <wtf/NumberOfCores.h>
     
    4849#include "MacroAssemblerX86.h"
    4950#endif
     51
     52#define USE_OPTIONS_FILE 0
     53#define OPTIONS_FILENAME "/tmp/jsc.options"
    5054
    5155namespace JSC {
     
    362366   
    363367            recomputeDependentOptions();
     368
     369#if USE(OPTIONS_FILE)
     370            {
     371                const char* filename = OPTIONS_FILENAME;
     372                FILE* optionsFile = fopen(filename, "r");
     373                if (!optionsFile) {
     374                    dataLogF("Failed to open file %s. Did you add the file-read-data entitlement to WebProcess.sb?\n", filename);
     375                    return;
     376                }
     377               
     378                StringBuilder builder;
     379                char* line;
     380                char buffer[BUFSIZ];
     381                while ((line = fgets(buffer, sizeof(buffer), optionsFile)))
     382                    builder.append(buffer);
     383               
     384                const char* optionsStr = builder.toString().utf8().data();
     385                dataLogF("Setting options: %s\n", optionsStr);
     386                setOptions(optionsStr);
     387               
     388                int result = fclose(optionsFile);
     389                if (result)
     390                    dataLogF("Failed to close file %s: %s\n", filename, strerror(errno));
     391            }
     392#endif
    364393
    365394            // Do range checks where needed and make corrections to the options:
     
    411440
    412441    while (p < end) {
     442        // Skip white space.
     443        while (p < end && isASCIISpace(*p))
     444            p++;
     445        if (p == end)
     446            break;
     447
    413448        char* optionStart = p;
    414449        p = strstr(p, "=");
     
    431466        }
    432467
    433         p = strstr(p, " ");
     468        // Find next white space.
     469        while (p < end && !isASCIISpace(*p))
     470            p++;
    434471        if (!p)
    435472            p = end; // No more " " separator. Hence, this is the last arg.
Note: See TracChangeset for help on using the changeset viewer.