Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need help for making tests of compiled js script

51 views
Skip to first unread message

riadh chtara

unread,
Oct 30, 2012, 2:38:03 PM10/30/12
to
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

Josh Matthews

unread,
Oct 30, 2012, 3:01:52 PM10/30/12
to
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_and_patch_files.3F

Cheers,
Josh

riadh chtara

unread,
Oct 30, 2012, 4:27:59 PM10/30/12
to
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
0 new messages