summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/js
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2012-07-16 06:48:11 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2012-07-16 06:48:11 +0000
commit574ccee478b9da9457cdf0e476b8df6eb584b580 (patch)
tree5a8166f47057ed322294db7816e2732d1d18f7bc /sca-cpp/trunk/modules/js
parent419f903ff44a22debba43976baae1e86c1e5d871 (diff)
Minor memory management, performance, and tracing improvements.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1361917 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-cpp/trunk/modules/js/eval.hpp15
-rw-r--r--sca-cpp/trunk/modules/js/js-test.cpp1
-rw-r--r--sca-cpp/trunk/modules/json/json-test.cpp38
3 files changed, 50 insertions, 4 deletions
diff --git a/sca-cpp/trunk/modules/js/eval.hpp b/sca-cpp/trunk/modules/js/eval.hpp
index 21fa274d2c..f8f4cbe598 100644
--- a/sca-cpp/trunk/modules/js/eval.hpp
+++ b/sca-cpp/trunk/modules/js/eval.hpp
@@ -65,7 +65,7 @@ public:
JSRuntime() {
// Create JS runtime
debug("js::jsruntime");
- rt = JS_NewRuntime(32L * 1024L * 1024L);
+ rt = JS_NewRuntime(1L * 512L * 1024L);
if(rt == NULL)
cleanup();
}
@@ -114,14 +114,19 @@ public:
debug("js::jscontext");
if (jsContext != NULL) {
cx = jsContext;
+ JS_BeginRequest(cx);
return;
}
+ debug("js::jsnewcontext");
cx = JS_NewContext(jsRuntime, 8192);
if(cx == NULL)
return;
+ JS_BeginRequest(cx);
+
JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT);
JS_SetVersion(cx, JSVERSION_LATEST);
JS_SetErrorReporter(cx, reportError);
+ //JS_SetGCZeal(cx, 2);
// Create global JS object
global = JS_NewCompartmentAndGlobalObject(cx, &jsGlobalClass, NULL);
@@ -140,8 +145,6 @@ public:
~JSContext() {
debug("js::~jscontext");
- if (cx != NULL)
- JS_MaybeGC(cx);
cleanup();
}
@@ -156,8 +159,12 @@ public:
private:
bool cleanup() {
if(cx != NULL) {
- if (cx != jsContext)
+ JS_MaybeGC(cx);
+ JS_EndRequest(cx);
+ if (cx != jsContext) {
+ debug("js::jsdestroycontext");
JS_DestroyContext(cx);
+ }
cx = NULL;
}
return true;
diff --git a/sca-cpp/trunk/modules/js/js-test.cpp b/sca-cpp/trunk/modules/js/js-test.cpp
index 9cbf000ac3..a7e5597610 100644
--- a/sca-cpp/trunk/modules/js/js-test.cpp
+++ b/sca-cpp/trunk/modules/js/js-test.cpp
@@ -42,6 +42,7 @@ bool testJSEval() {
}
int main() {
+ tuscany::gc_scoped_pool p;
tuscany::cout << "Testing..." << tuscany::endl;
tuscany::js::testJSEval();
diff --git a/sca-cpp/trunk/modules/json/json-test.cpp b/sca-cpp/trunk/modules/json/json-test.cpp
index 61aac4ee02..945b6c072c 100644
--- a/sca-cpp/trunk/modules/json/json-test.cpp
+++ b/sca-cpp/trunk/modules/json/json-test.cpp
@@ -27,6 +27,7 @@
#include "stream.hpp"
#include "string.hpp"
#include "json.hpp"
+#include "perf.hpp"
namespace tuscany {
namespace json {
@@ -74,6 +75,7 @@ const string jsarray("{\n"
"}");
bool testJSON() {
+ gc_scoped_pool pool;
const js::JSContext cx;
{
@@ -217,6 +219,7 @@ const string jsechores("{\n"
"}");
bool testJSONRPC() {
+ gc_scoped_pool pool;
js::JSContext cx;
{
const string lm("{\"id\": 1, \"method\": \"test\", \"params\": []}");
@@ -283,14 +286,49 @@ bool testJSONRPC() {
return true;
}
+struct testReadWrite {
+ testReadWrite() {
+ }
+ const bool operator()() const {
+ gc_scoped_pool pool;
+ js::JSContext cx;
+
+ const list<value> ad = mklist<value>(mklist<value>(attribute, "city", string("san francisco")), mklist<value>(attribute, "state", string("ca")));
+ const list<value> ac = mklist<value>(mklist<value>(element, "id", string("1234")), mklist<value>(attribute, "balance", 1000));
+ const list<value> cr = mklist<value>(mklist<value> (attribute, "name", string("jdoe")), cons<value>(element, cons<value>("address", ad)), cons<value>(element, cons<value>("account", ac)));
+ const list<value> c = mklist<value>(cons<value>(element, cons<value>("customer", cr)));
+
+ ostringstream os;
+ writeJSON<ostream*>(jsonWriter, &os, c, cx);
+ assert(str(os) == jscustomer);
+
+ istringstream is(jscustomer);
+ const list<string> il = streamList(is);
+ const list<value> r = content(readJSON(il, cx));
+ assert(r == c);
+ return true;
+ }
+};
+
+bool testJSONPerf() {
+ gc_scoped_pool pool;
+
+ const lambda<bool()> rwl = lambda<bool()>(testReadWrite());
+ cout << "JSON read + write test " << time(rwl, 5, 200) << " ms" << endl;
+
+ return true;
+}
+
}
}
int main() {
+ tuscany::gc_scoped_pool p;
tuscany::cout << "Testing..." << tuscany::endl;
tuscany::json::testJSON();
tuscany::json::testJSONRPC();
+ tuscany::json::testJSONPerf();
tuscany::cout << "OK" << tuscany::endl;