Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Need help for making tests of compiled js script
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
riadh chtara  
View profile  
 More options Oct 30 2012, 2:38 pm
Newsgroups: mozilla.dev.tech.js-engine
From: riadh chtara <riadh.cht...@gmail.com>
Date: Tue, 30 Oct 2012 11:38:03 -0700 (PDT)
Local: Tues, Oct 30 2012 2:38 pm
Subject: Need help for making tests of compiled js script
Hi guys!
I was working on a very basic implementation of compiled cache for js.
I have edited the jsapi.cpp.
I get the following result:
*the first time I open a website it works perfectly.
*the second time: some websites work, other don't and make Firefox close.
(google.com works fine, gmail breaks, ). I'm wondering why such thing happens.
*the results I got in the log files show that there is a small improvement which is very fine for me because js raw scripts are read from the browser cache even if a compiled version exist( it was very complicated for me to remove that), but of course in this case we don't need to read them and we will gain the reading time.

Could someone please check the changes I made, and try it on his computer?
Could you tell me please the cause of the crash?

This are the changes I made.(jsapi.cpp)

size_t hash(char const *input) {
//stupid hash function to give a name to the js compiled file
    const int ret_size = 32;
    size_t ret = 0x555555;
    const int per_char = 7;

    while (*input) {
        ret ^= *input++;
        ret = ((ret << per_char) | (ret >> (ret_size - per_char)));
   }
   return ret;

}

uint32_t load_file_to_memory(const char *filename, char **result)
{
//stupid function to load file to memery and return its size
        uint32_t size = 0;
        FILE *f = fopen(filename, "rb");
        if (f == NULL)
        {
                *result = NULL;
                return -1; // -1 means file opening fail
        }
        fseek(f, 0, SEEK_END);
        size = ftell(f);
        fseek(f, 0, SEEK_SET);
        *result = (char *)malloc(size+1);
        if (size != fread(*result, sizeof(char), size, f))
        {
                free(*result);
                return -2; // -2 means file reading fail
        }
        fclose(f);
        (*result)[size] = 0;
        return size;
}

//important staff here

extern JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, HandleObject obj, CompileOptions options,
             const jschar *chars, size_t length, jsval *rval)
{
    FILE * info;
    JS_ToggleOptions(cx, JSOPTION_COMPILE_N_GO);
    int64_t fdtime;

    info = fopen ("/home/riadh/info.log","a");
    void * jsfile;
    uint32_t size;
    char * buffer;
    FILE *saveFile;
    JSScript * src;

        Maybe<AutoVersionAPI> mava;
    if (options.versionSet) {
        mava.construct(cx, options.version);
        // AutoVersionAPI propagates some compilation flags through.
        options.version = mava.ref().version();
    }

    JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
    AssertHeapIsIdle(cx);
    CHECK_REQUEST(cx);
    assertSameCompartment(cx, obj);
    JS_ASSERT_IF(options.principals, cx->compartment->principals == options.principals);

    AutoLastFrameCheck lfc(cx);

    options.setNoScriptRval(!rval);
    compile = PRMJ_Now();
//disable compile and go
    JS_SetOptions(cx, JS_GetOptions(cx) & ~JSOPTION_COMPILE_N_GO);

    options.setCompileAndGo(false);
//don't save source, I tried with the source but I get the same bug
    options.setSourcePolicy(CompileOptions::NO_SOURCE);
    size_t ha = hash((char * )chars);
    char str [200];

    sprintf (str, "/home/riadh/tmp/js/%u.%u", ha, length);
    fdtime = PRMJ_Now();//reading and deencoding time starts here
    size = load_file_to_memory(str, &buffer);
    JSScript * scr;

    if ((buffer!=NULL) && (length>500) && (size>0))
     {
        scr = JS_DecodeScript(cx,(void *) buffer, size, 0, 0);

        fdtime = PRMJ_Now() - fdtime;//reading and dencoding time ends here
        fprintf(info, "\n\n%u opendencode %.3f ms slength %u csize %u\n\n",ha,
                                double(fdtime) / PRMJ_USEC_PER_MSEC,
                                length,size);

    } else {
        fdtime = PRMJ_Now();//compiling time starts here
        scr = frontend::CompileScript(cx, obj, NULL, options, chars, length);

        fdtime = PRMJ_Now() - fdtime;//compiling time ends here

        if (length>500) {
            jsfile = JS_EncodeScript(cx, scr, &size);//this is not counted as compiling time because this could be launch in a parallel thread after a while (after the end of all scripts execution for the current page)
           fprintf(info, "\n\n%u compile %.3f ms slength %u csize %u\n\n",ha,
                                        double(fdtime) / PRMJ_USEC_PER_MSEC,
                                        length,size);
            saveFile = fopen (str,"w");
            int i;
            char * c;
            for(c=(char *) jsfile; c - (char *) jsfile <size;c++){

                fputc ( *c ,saveFile );
            }
            fclose (saveFile);

        }
    }
    fclose (info);
    RootedScript script(cx, scr);
    if (!script)
        return false;
    JS_PUBLIC_API(bool) tmp = Execute(cx, script, *obj, rval);

    JS_ASSERT(script->getVersion() == options.version);

    return tmp;

}

Best
Riadh

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josh Matthews  
View profile  
 More options Oct 30 2012, 3:01 pm
Newsgroups: mozilla.dev.tech.js-engine
From: Josh Matthews <j...@joshmatthews.net>
Date: Tue, 30 Oct 2012 15:01:52 -0400
Local: Tues, Oct 30 2012 3:01 pm
Subject: Re: Need help for making tests of compiled js script
On 10/30/2012 02:38 PM, riadh chtara wrote:

> Hi guys!
> I was working on a very basic implementation of compiled cache for js.
> I have edited the jsapi.cpp.
> I get the following result:
> *the first time I open a website it works perfectly.
> *the second time: some websites work, other don't and make Firefox close.
> (google.com works fine, gmail breaks, ). I'm wondering why such thing happens.
> *the results I got in the log files show that there is a small improvement which is very fine for me because js raw scripts are read from the browser cache even if a compiled version exist( it was very complicated for me to remove that), but of course in this case we don't need to read them and we will gain the reading time.

> Could someone please check the changes I made, and try it on his computer?
> Could you tell me please the cause of the crash?

It will be easier to comment on and test your changes if you provide a
diff file:
https://developer.mozilla.org/en-US/docs/Mercurial_FAQ#How_can_I_diff...

Cheers,
Josh


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
riadh chtara  
View profile  
 More options Oct 30 2012, 4:27 pm
Newsgroups: mozilla.dev.tech.js-engine
From: riadh chtara <riadh.cht...@gmail.com>
Date: Tue, 30 Oct 2012 13:27:59 -0700 (PDT)
Local: Tues, Oct 30 2012 4:27 pm
Subject: Re: Need help for making tests of compiled js script
Hi
Good idea.
I have already fixed the bug, and firefox works fine
But I still need someone to check if the timers in jsapi.cpp Evaluate() are in a good position),compile, run firefox, go to some websites (at least two time for every website)and send me the log file (info.log)
But before that, please open the patch file with a text editor, replace all occurrences of '/home/riadh/' with the path of the dir you want to save log file. Please create also in this path a folder called tmp and inside tmp a folder called js.

https://docs.google.com/file/d/0B9VtjieUwlMDR0lXWHViTkhPWXc/edit
And thanks a lot
Best
Riadh


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »