I am getting JS OUT OF MEMORY error from the spider monkey. In my test,
I am using run time size of 8 MB and JS context stack size as 8k.
In my stress testing of my browser, where I run parallel sessions about
100 with help automated scripts, I found that after 20 mins, it start
reporting out of memory and CPU usage reaches to 100%. Here, increase in CPU
is time function, and even after I stop session and start again with min 5
sessions parallel it shooting up to 100%.
On analyzing exe callstack, I found stack to be in JS_GC.
At first moment, I tried to check if I am leaking memory in GC by not
un-rooting JS Objects. For that, I tried to dump JS rooted vars vai
JS_MapGCRoots. But, even after long run I found that map size is same after
each execution of GC.
I have doubt, it is happening because of leak in GC, where spider
monkey's allowable limit of memory is getting exhausted after some period of
time. And to recover that memory it has to run GC, which is a probable cause
of CPU usage blast.
Pls suggest mechanism to resolve. Thanks.
Regards
Puneet
I don't know exactly what's going on but I have a few ideas that *might*
help to get more information.
> I am getting JS OUT OF MEMORY error from the spider monkey. In my test,
> I am using run time size of 8 MB and JS context stack size as 8k.
What happens if you vary these parameters? Say 2, 32, and 128MB for the
run time size, and similar variations for the context stack size?
> In my stress testing of my browser, where I run parallel sessions about
> 100 with help automated scripts,
Exactly what does that mean? 100 threads in parallel? 100 contexts on
one thread? Etc.
> I found that after 20 mins, it start reporting out of memory
And exactly what does that mean? OS out-of-memory messages? JSAPI
functions return false and JS reports out of memory?
> and CPU usage reaches to 100%. Here, increase in CPU
> is time function, and even after I stop session and start again with min 5
> sessions parallel it shooting up to 100%.
>
> On analyzing exe callstack, I found stack to be in JS_GC.
Do you know if it finishes a GC cycle? In other words, does it seem to
be stuck in an infinite loop in one GC run, or is it just running lots
of GC one after the other.
One idea that occurs to me is that maybe the heuristics for when to run
a GC get confused and it keeps GC'ing again and again.
I have reproduced, with much better scenario.
Configuration details:
1. JS context size : 4K (this problem is independent of context size)
2. Run time size : 16K (more the runtime size more time it takes to
reproduce)
3. JS version : 1.5
4: JS Script:
function isnull{}()
5. C evaluation:
For(i = 0; i< 2000 ; i++)
JS_EvaluateScriptForPrincipals();
It seems, there is problem with definition of problem.
Now, this problem does not exist in JS 1.8. But, there is again a problem
with JS 1.8, its memory requirement for initialization
(JS_InitStandardClasses) is almost 4 times,i.e. minimum runtime size
required for just initialization is 55K, which is highly unrealistic fo
which makes it unusable for my application.
Now, there are some intermediate versions,JS 1.6 and JS 1.7, for them
mailing list has already warned about their stability, so I haven't tried
them.
Can you please suggest a patch for this defect over JS 1.5 ? Thanks.
Regards
Puneet
_______________________________________________
dev-tech-js-engine mailing list
dev-tech-...@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-js-engine
I tried JS 1.5 with this source code on a MacBook Pro:
-----------------------------------------------------------------
#define XP_UNIX
#include <stdio.h>
#include <string.h>
#include <jsapi.h>
int main()
{
const char *src = "function isnull{}()";
int length = strlen(src);
JSRuntime *rt = JS_NewRuntime(16 << 10);
JSContext *cx = JS_NewContext(rt, 4 << 10);
JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL);
jsval rv;
int i;
for (i = 0; i < 2000; i++) {
JS_EvaluateScript(cx, obj, src, length, "a", 1, &rv);
}
return 0;
}
-----------------------------------------------------------------
I didn't get any problem. Are you running on a device with small memory?
Is it possible that it is thrashing in some way because it's using too
much memory, or that it is running out of memory constantly and thus
having to do GC over and over?
I tried JS 1.5 with this source code on a MacBook Pro:
-----------------------------------------------------------------
#define XP_UNIX
#include <stdio.h>
#include <string.h>
#include <jsapi.h>
int main()
{
const char *src = "function isnull{}()";
int length = strlen(src);
JSRuntime *rt = JS_NewRuntime(16 << 10);
JSContext *cx = JS_NewContext(rt, 4 << 10);
JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL);
jsval rv;
int i;
for (i = 0; i < 2000; i++) {
JS_EvaluateScript(cx, obj, src, length, "a", 1, &rv);
}
return 0;
}
-----------------------------------------------------------------
I didn't get any problem. Are you running on a device with small memory?
Is it possible that it is thrashing in some way because it's using too
much memory, or that it is running out of memory constantly and thus
having to do GC over and over?
> It seems, there is problem with definition of problem.
I would like to correct your testcase for required checks and have
corrected my mistake as well.
#define XP_UNIX
#include <stdio.h>
#include <string.h>
#include <jsapi.h>
Void TestJSEngineEcmaErrorReporter
(
JSContext * hdlCtx,
Const char * pszMessage,
JSErrorReport *pstReport
)
{
Printf("\r\n Error reported : %s",pszMessage);
}
int main()
{
// puneet : it was typo const char *src = "function isnull{}()";
//correct one is : isnull(){} instead of isnull{}()
const char *src = "function isnull(){}";
int length = strlen(src);
JSRuntime *rt = JS_NewRuntime(16 << 10);
JSContext *cx = JS_NewContext(rt, 4 << 10);
JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL);
jsval rv;
JSBool rc;
int i;
/*log all JS errors*/
(void)JS_SetErrorReporter(cx, TestJSEngineEcmaErrorReporter);
/* usually problem occurs*/
for (i = 0; i < 2000; i++) {
rc = JS_EvaluateScript(cx, obj, src, length, "a", 1, &rv);
if (rc == JS_FALSE)
{
printf("\r\n Error while processing EvaluateScript ");
break;
}
}
JS_DestroyContext(cx);
JS_DestroyRuntime(rt);
return 0;
This problem is consistently reproducible with Spidermonkey version of
JS 1.5, JS 1.6 and JS 1.7. The only variable is the loop count.
Platforms : Windows and Suse10Sp2
Same is reproducible with only JS_CompileScript API also.
JS 1.8Rc1 does not seems to have this problem, but I am not able to
find list of change logs for JS 1.8RC1. Seems Mozilla has maintained change
logs till JS 1.7 but not after that.
It would be great help to find change logs.
Regards
Puneet
-----Original Message-----
From:
dev-tech-js-engine-bounces+engg.puneetsharma=gmai...@lists.mozilla.org
[mailto:dev-tech-js-engine-bounces+engg.puneetsharma=gmai...@lists.mozilla
.org] On Behalf Of Puneet Sharma
Sent: Thursday, December 31, 2009 1:43 PM
To: 'David Mandelin'
Cc: dev-tech-...@lists.mozilla.org
Subject: RE: JS Out of memory
Hi,
I would like to correct your testcase for required checks and have
corrected my mistake as well.
#define XP_UNIX
#include <stdio.h>
#include <string.h>
#include <jsapi.h>
Void TestJSEngineEcmaErrorReporter
(
JSContext * hdlCtx,
Const char * pszMessage,
JSErrorReport *pstReport
)
{
Printf("\r\n Error reported : %s",pszMessage);
}
int main()
{
// puneet : it was typo const char *src = "function isnull{}()";
//correct one is : isnull(){} instead of isnull{}()
const char *src = "function isnull(){}";
int length = strlen(src);
JSRuntime *rt = JS_NewRuntime(16 << 10);
JSContext *cx = JS_NewContext(rt, 4 << 10);
JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL);
jsval rv;
JSBool rc;
int i;
/*log all JS errors*/
(void)JS_SetErrorReporter(cx, TestJSEngineEcmaErrorReporter);
/* usually problem occurs*/
for (i = 0; i < 2000; i++) {
rc = JS_EvaluateScript(cx, obj, src, length, "a", 1, &rv);
if (rc == JS_FALSE)
{
printf("\r\n Error while processing EvaluateScript ");
break;
}
}
JS_DestroyContext(cx);
JS_DestroyRuntime(rt);
return 0;
}
Regards
Puneet
-----Original Message-----
From:
dev-tech-js-engine-bounces+engg.puneetsharma=gmai...@lists.mozilla.org
[mailto:dev-tech-js-engine-bounces+engg.puneetsharma=gmai...@lists.mozilla
.org] On Behalf Of David Mandelin
Sent: Thursday, December 31, 2009 1:33 AM
To: Puneet Sharma