Mercurial > spidermonkey-playground
annotate memory_profiler.cpp @ 58:0b66a265df13
Fixed some bugs that raised assertions in debug builds of SpiderMonkey.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Wed, 24 Jun 2009 21:15:45 -0700 |
parents | 1fd63ee398dc |
children | ab600a5e6516 |
rev | line source |
---|---|
50
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
1 #include "jsdhash.h" |
56
b36c15de56f6
added a size property to info
Atul Varma <varmaa@toolness.com>
parents:
55
diff
changeset
|
2 #include "jsdbgapi.h" |
50
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
3 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
4 #include "memory_profiler.h" |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
5 #include "server_socket.h" |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
6 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
7 #define SERVER_FILENAME "memory_profiler_server.js" |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
8 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
9 // TODO: Lots of code here is copied from spidermonkey-playground.cpp; we should |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
10 // consolidate it. |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
11 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
12 /* The error reporter callback. */ |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
13 static void reportError(JSContext *cx, const char *message, JSErrorReport *report) |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
14 { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
15 fprintf(stderr, "%s:%u:%s\n", |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
16 report->filename ? report->filename : "<no filename>", |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
17 (unsigned int) report->lineno, |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
18 message); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
19 } |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
20 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
21 static JSClass global_class = { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
22 "serverGlobal", JSCLASS_GLOBAL_FLAGS, |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
23 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
24 JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
25 JSCLASS_NO_OPTIONAL_MEMBERS |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
26 }; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
27 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
28 // This native JS function prints the given string to the console. |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
29 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
30 static JSBool print(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
31 jsval *rval) |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
32 { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
33 char *str; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
34 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
35 if (!JS_ConvertArguments(cx, argc, argv, "s", &str)) |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
36 return JS_FALSE; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
37 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
38 printf("%s\n", str); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
39 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
40 return JS_TRUE; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
41 } |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
42 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
43 // Private structure to track the state of tracing the JS heap. |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
44 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
45 typedef struct TracingState { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
46 // Keeps track of what objects we've visited so far. |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
47 JSDHashTable visited; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
48 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
49 // Whether the tracing operation is successful or failed. |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
50 JSBool result; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
51 |
51
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
52 // Runtime that we're tracing. |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
53 JSRuntime *runtime; |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
54 |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
55 // Structure required to use JS tracing functions. |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
56 JSTracer tracer; |
50
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
57 }; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
58 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
59 // Static singleton for tracking the state of tracing the JS heap. |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
60 static TracingState tracingState; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
61 |
57
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
62 typedef struct ChildTracingState { |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
63 int num; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
64 void **things; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
65 uint32 *kinds; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
66 JSTracer tracer; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
67 }; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
68 |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
69 static ChildTracingState childTracingState; |
50
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
70 |
57
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
71 // JSTraceCallback to build a hashtable of children. |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
72 static void childCountBuilder(JSTracer *trc, void *thing, uint32 kind) |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
73 { |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
74 childTracingState.num++; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
75 } |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
76 |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
77 // JSTraceCallback to build a hashtable of children. |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
78 static void childBuilder(JSTracer *trc, void *thing, uint32 kind) |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
79 { |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
80 *childTracingState.kinds = kind; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
81 childTracingState.kinds++; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
82 *childTracingState.things = thing; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
83 childTracingState.things++; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
84 } |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
85 |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
86 // JSTraceCallback to build a hashtable of existing object references. |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
87 static void visitedBuilder(JSTracer *trc, void *thing, uint32 kind) |
50
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
88 { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
89 switch (kind) { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
90 case JSTRACE_OBJECT: |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
91 JSDHashEntryStub *entry = (JSDHashEntryStub *) |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
92 JS_DHashTableOperate(&tracingState.visited, |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
93 thing, |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
94 JS_DHASH_LOOKUP); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
95 if (JS_DHASH_ENTRY_IS_FREE((JSDHashEntryHdr *)entry)) { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
96 entry = (JSDHashEntryStub *) JS_DHashTableOperate(&tracingState.visited, |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
97 thing, |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
98 JS_DHASH_ADD); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
99 if (entry == NULL) { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
100 JS_ReportOutOfMemory(trc->context); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
101 tracingState.result = JS_FALSE; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
102 return; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
103 } |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
104 entry->key = thing; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
105 JS_TraceChildren(trc, thing, kind); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
106 } |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
107 break; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
108 case JSTRACE_DOUBLE: |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
109 break; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
110 case JSTRACE_STRING: |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
111 break; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
112 } |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
113 } |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
114 |
51
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
115 static intN countRoots(void *rp, const char *name, void *data) |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
116 { |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
117 return JS_MAP_GCROOT_NEXT; |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
118 } |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
119 |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
120 static intN rootMapFun(void *rp, const char *name, void *data) |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
121 { |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
122 jsval **currIndex = (jsval **) data; |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
123 **currIndex = INT_TO_JSVAL((unsigned int) rp); |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
124 *currIndex++; |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
125 return JS_MAP_GCROOT_NEXT; |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
126 } |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
127 |
57
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
128 static JSBool getChildrenInfo(JSContext *cx, JSObject *info, |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
129 JSObject *target, JSContext *targetCx) |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
130 { |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
131 childTracingState.tracer.context = targetCx; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
132 childTracingState.tracer.callback = childCountBuilder; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
133 childTracingState.num = 0; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
134 JS_TraceChildren(&childTracingState.tracer, target, JSTRACE_OBJECT); |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
135 |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
136 void *things[childTracingState.num]; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
137 uint32 kinds[childTracingState.num]; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
138 |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
139 childTracingState.things = things; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
140 childTracingState.kinds = kinds; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
141 |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
142 childTracingState.tracer.callback = childBuilder; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
143 JS_TraceChildren(&childTracingState.tracer, target, JSTRACE_OBJECT); |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
144 |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
145 int numObjectChildren = 0; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
146 for (int i = 0; i < childTracingState.num; i++) { |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
147 if (kinds[i] == JSTRACE_OBJECT) |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
148 numObjectChildren++; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
149 } |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
150 |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
151 jsval childrenVals[numObjectChildren]; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
152 |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
153 int currChild = 0; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
154 for (int i = 0; i < childTracingState.num; i++) { |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
155 if (kinds[i] == JSTRACE_OBJECT) { |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
156 childrenVals[currChild] = INT_TO_JSVAL((unsigned int) things[i]); |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
157 currChild += 1; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
158 } |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
159 } |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
160 |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
161 JSObject *children = JS_NewArrayObject(cx, numObjectChildren, childrenVals); |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
162 if (children == NULL) { |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
163 JS_ReportOutOfMemory(cx); |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
164 return JS_FALSE; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
165 } |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
166 |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
167 return JS_DefineProperty(cx, info, "children", OBJECT_TO_JSVAL(children), |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
168 NULL, NULL, JSPROP_ENUMERATE); |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
169 } |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
170 |
54
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
171 static JSBool getObjInfo(JSContext *cx, JSObject *obj, uintN argc, |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
172 jsval *argv, jsval *rval) |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
173 { |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
174 uint32 id; |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
175 |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
176 if (!JS_ConvertArguments(cx, argc, argv, "u", &id)) |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
177 return JS_FALSE; |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
178 |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
179 JSDHashEntryStub *entry = (JSDHashEntryStub *) |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
180 JS_DHashTableOperate(&tracingState.visited, |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
181 (void *) id, |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
182 JS_DHASH_LOOKUP); |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
183 if (entry == NULL) { |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
184 JS_ReportOutOfMemory(cx); |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
185 return JS_FALSE; |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
186 } |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
187 |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
188 if (JS_DHASH_ENTRY_IS_BUSY((JSDHashEntryHdr *)entry)) { |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
189 JSObject *info = JS_NewObject(cx, NULL, NULL, NULL); |
55
1aba1b7a0a2c
Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
190 |
1aba1b7a0a2c
Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
191 JSObject *target = (JSObject *) id; |
56
b36c15de56f6
added a size property to info
Atul Varma <varmaa@toolness.com>
parents:
55
diff
changeset
|
192 JSContext *targetCx = tracingState.tracer.context; |
b36c15de56f6
added a size property to info
Atul Varma <varmaa@toolness.com>
parents:
55
diff
changeset
|
193 JSClass *classp = JS_GET_CLASS(targetCx, target); |
55
1aba1b7a0a2c
Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
194 if (classp != NULL) { |
1aba1b7a0a2c
Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
195 // TODO: Should really be using an interned string here or something. |
1aba1b7a0a2c
Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
196 JSString *name = JS_NewStringCopyZ(cx, classp->name); |
1aba1b7a0a2c
Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
197 if (name == NULL) { |
1aba1b7a0a2c
Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
198 JS_ReportOutOfMemory(cx); |
1aba1b7a0a2c
Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
199 return JS_FALSE; |
1aba1b7a0a2c
Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
200 } |
1aba1b7a0a2c
Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
201 if (!JS_DefineProperty(cx, info, "nativeClass", STRING_TO_JSVAL(name), |
1aba1b7a0a2c
Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
202 NULL, NULL, JSPROP_ENUMERATE)) { |
1aba1b7a0a2c
Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
203 JS_ReportOutOfMemory(cx); |
1aba1b7a0a2c
Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
204 return JS_FALSE; |
1aba1b7a0a2c
Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
205 } |
1aba1b7a0a2c
Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
206 } |
1aba1b7a0a2c
Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
207 |
56
b36c15de56f6
added a size property to info
Atul Varma <varmaa@toolness.com>
parents:
55
diff
changeset
|
208 if (!JS_DefineProperty( |
b36c15de56f6
added a size property to info
Atul Varma <varmaa@toolness.com>
parents:
55
diff
changeset
|
209 cx, info, "size", |
b36c15de56f6
added a size property to info
Atul Varma <varmaa@toolness.com>
parents:
55
diff
changeset
|
210 INT_TO_JSVAL(JS_GetObjectTotalSize(targetCx, target)), |
b36c15de56f6
added a size property to info
Atul Varma <varmaa@toolness.com>
parents:
55
diff
changeset
|
211 NULL, NULL, JSPROP_ENUMERATE)) { |
b36c15de56f6
added a size property to info
Atul Varma <varmaa@toolness.com>
parents:
55
diff
changeset
|
212 JS_ReportOutOfMemory(cx); |
b36c15de56f6
added a size property to info
Atul Varma <varmaa@toolness.com>
parents:
55
diff
changeset
|
213 return JS_FALSE; |
b36c15de56f6
added a size property to info
Atul Varma <varmaa@toolness.com>
parents:
55
diff
changeset
|
214 } |
b36c15de56f6
added a size property to info
Atul Varma <varmaa@toolness.com>
parents:
55
diff
changeset
|
215 |
57
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
216 if (!getChildrenInfo(cx, info, target, targetCx)) |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
217 return JS_FALSE; |
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
218 |
54
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
219 *rval = OBJECT_TO_JSVAL(info); |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
220 } else |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
221 *rval = JSVAL_NULL; |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
222 |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
223 return JS_TRUE; |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
224 } |
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
225 |
51
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
226 static JSBool getGCRoots(JSContext *cx, JSObject *obj, uintN argc, |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
227 jsval *argv, jsval *rval) |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
228 { |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
229 uint32 numRoots = JS_MapGCRoots(tracingState.runtime, countRoots, NULL); |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
230 jsval rootList[numRoots]; |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
231 jsval *currIndex = rootList; |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
232 |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
233 JS_MapGCRoots(tracingState.runtime, rootMapFun, &currIndex); |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
234 |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
235 JSObject *roots = JS_NewArrayObject(cx, numRoots, rootList); |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
236 if (roots == NULL) { |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
237 JS_ReportError(cx, "Creating array failed."); |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
238 return JS_FALSE; |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
239 } |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
240 |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
241 *rval = OBJECT_TO_JSVAL(roots); |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
242 return JS_TRUE; |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
243 } |
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
244 |
50
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
245 static JSFunctionSpec server_global_functions[] = { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
246 JS_FS("print", print, 1, 0, 0), |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
247 JS_FS("ServerSocket", createServerSocket, 0, 0, 0), |
51
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
248 JS_FS("getGCRoots", getGCRoots, 0, 0, 0), |
54
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
249 JS_FS("getObjectInfo", getObjInfo, 1, 0, 0), |
50
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
250 JS_FS_END |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
251 }; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
252 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
253 JSBool profileMemory(JSContext *cx, JSObject *obj, uintN argc, |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
254 jsval *argv, jsval *rval) |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
255 { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
256 if (!JS_DHashTableInit(&tracingState.visited, JS_DHashGetStubOps(), |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
257 NULL, sizeof(JSDHashEntryStub), |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
258 JS_DHASH_DEFAULT_CAPACITY(100))) { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
259 JS_ReportOutOfMemory(cx); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
260 return JS_FALSE; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
261 } |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
262 |
51
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
263 tracingState.runtime = JS_GetRuntime(cx); |
50
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
264 tracingState.result = JS_TRUE; |
51
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
265 tracingState.tracer.context = cx; |
57
1fd63ee398dc
Added some really terrible code that adds a 'children' array property to object info.
Atul Varma <varmaa@toolness.com>
parents:
56
diff
changeset
|
266 tracingState.tracer.callback = visitedBuilder; |
51
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
267 JS_TraceRuntime(&tracingState.tracer); |
50
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
268 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
269 if (!tracingState.result) |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
270 return JS_FALSE; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
271 |
51
8750e9ecf3af
Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents:
50
diff
changeset
|
272 JSRuntime *serverRuntime = JS_NewRuntime(8L * 1024L * 1024L); |
50
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
273 if (serverRuntime == NULL) { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
274 JS_ReportError(cx, "Couldn't create server JS runtime."); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
275 return JS_FALSE; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
276 } |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
277 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
278 JSContext *serverCx = JS_NewContext(serverRuntime, 8192); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
279 if (serverCx == NULL) { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
280 JS_ReportError(cx, "Couldn't create server JS context."); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
281 return JS_FALSE; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
282 } |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
283 JS_SetOptions(serverCx, JSOPTION_VAROBJFIX); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
284 JS_SetVersion(serverCx, JSVERSION_LATEST); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
285 JS_SetErrorReporter(serverCx, reportError); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
286 |
58
0b66a265df13
Fixed some bugs that raised assertions in debug builds of SpiderMonkey.
Atul Varma <varmaa@toolness.com>
parents:
57
diff
changeset
|
287 JS_BeginRequest(serverCx); |
0b66a265df13
Fixed some bugs that raised assertions in debug builds of SpiderMonkey.
Atul Varma <varmaa@toolness.com>
parents:
57
diff
changeset
|
288 |
50
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
289 JSObject *serverGlobal = JS_NewObject(serverCx, &global_class, NULL, NULL); |
58
0b66a265df13
Fixed some bugs that raised assertions in debug builds of SpiderMonkey.
Atul Varma <varmaa@toolness.com>
parents:
57
diff
changeset
|
290 |
50
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
291 if (serverGlobal == NULL) { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
292 JS_ReportError(cx, "Couldn't create server JS global."); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
293 return JS_FALSE; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
294 } |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
295 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
296 if (!JS_InitStandardClasses(serverCx, serverGlobal)) { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
297 JS_ReportError(cx, "Couldn't init standard classes on server JS global."); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
298 return JS_FALSE; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
299 } |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
300 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
301 if (!JS_DefineFunctions(serverCx, serverGlobal, server_global_functions)) { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
302 JS_ReportError(cx, "Couldn't define functions on server JS global."); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
303 return JS_FALSE; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
304 } |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
305 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
306 FILE *f = fopen(SERVER_FILENAME, "r"); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
307 if (!f) { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
308 JS_ReportError(cx, "Couldn't open " SERVER_FILENAME); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
309 return JS_FALSE; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
310 } |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
311 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
312 fseek(f, 0, SEEK_END); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
313 long fileSize = ftell(f); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
314 fseek(f, 0, SEEK_SET); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
315 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
316 char source[fileSize]; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
317 fread(source, fileSize, 1, f); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
318 fclose(f); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
319 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
320 jsval serverRval; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
321 if (!JS_EvaluateScript(serverCx, serverGlobal, source, |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
322 fileSize, SERVER_FILENAME, 1, |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
323 &serverRval)) { |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
324 JS_ReportError(cx, "Server failed."); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
325 return JS_FALSE; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
326 } |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
327 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
328 /* Cleanup. */ |
54
c451579bf83c
Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
329 JS_DHashTableFinish(&tracingState.visited); |
58
0b66a265df13
Fixed some bugs that raised assertions in debug builds of SpiderMonkey.
Atul Varma <varmaa@toolness.com>
parents:
57
diff
changeset
|
330 JS_EndRequest(serverCx); |
50
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
331 JS_DestroyContext(serverCx); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
332 JS_DestroyRuntime(serverRuntime); |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
333 |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
334 *rval = JSVAL_VOID; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
335 return JS_TRUE; |
853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
336 } |