Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Raise NoMemoryError as appropriate; acccept a size parameter or env v…

…ariable for runtime size

* Allow a size parameter to runtime constructor or JOHNSON_HEAP_SIZE env
  variable or default
* Raise a NoMemoryError if script execution errors out
* tweak tracing of split globals (compiled in but not active outside gdb)
* Mem heap debugging that's off for non-debug compiles
  • Loading branch information...
commit 091117c82ef5c2a3f2280cb8986694646492ebd5 1 parent 74b5876
Steven Parkes smparkes authored
12 ext/tracemonkey/js.cc
View
@@ -278,7 +278,7 @@ split_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
static void
split_finalize(JSContext *cx, JSObject *obj)
{
- if (trace_split) fprintf(stderr,"finalize %016x\n", obj);
+ if (trace_split) fprintf(stderr,"finalize 0x%08x\n", obj);
JS_free(cx, JS_GetPrivate(cx, obj));
}
@@ -287,10 +287,10 @@ split_mark(JSContext *cx, JSObject *obj, void *arg)
{
ComplexObject *cpx;
- if (trace_mark) fprintf(stderr,"mark %016x\n", obj);
-
cpx = (ComplexObject *) JS_GetPrivate(cx, obj);
+ if (trace_mark) fprintf(stderr,"mark 0x%08x %s\n", obj, cpx->isInner ? "" : "outer");
+
/*
if (!cpx->isInner) {
fprintf(stderr,"mark %016x\n", obj);
@@ -298,7 +298,7 @@ split_mark(JSContext *cx, JSObject *obj, void *arg)
*/
if (!cpx->isInner && cpx->inner) {
- if (trace_mark) fprintf(stderr,"mark inner %016x\n", cpx->inner);
+ // if (trace_mark) fprintf(stderr,"mark inner 0x%08x\n", cpx->inner);
/* Mark the inner object. */
JS_MarkGCThing(cx, cpx->inner, "ComplexObject.inner", arg);
}
@@ -420,7 +420,7 @@ split_create_outer(JSContext *cx)
return NULL;
}
- if (trace_split) fprintf(stderr,"outer %016x\n", obj);
+ if (trace_split) fprintf(stderr,"outer 0x%08x\n", obj);
return obj;
}
@@ -453,7 +453,7 @@ split_create_inner(JSContext *cx, JSObject *outer)
outercpx->inner = obj;
outercpx->frozen = JS_FALSE;
- if (trace_split) fprintf(stderr,"inner %016x\n", obj);
+ if (trace_split) fprintf(stderr,"inner 0x%08x 0x%08x\n", outer, obj);
return obj;
}
25 ext/tracemonkey/runtime.cc
View
@@ -247,8 +247,10 @@ static VALUE evaluate_compiled_script(VALUE self, VALUE compiled_script, VALUE r
if (johnson_context->ex) {
RAISE_JS_ERROR(self, johnson_context->ex);
- return Qnil;
+ } else {
+ rb_raise(rb_eNoMemError,"spidermonkey ran out of memory");
}
+ return Qnil;
}
return convert_to_ruby(runtime, js);
@@ -279,11 +281,11 @@ set_gc_zeal(VALUE self, VALUE zeal)
}
#endif
-/*
+#ifdef DEBUG
void* from = 0;
void* thing = 0;
unsigned depth = 0;
-*/
+#endif DEBUG
/*
* call-seq:
@@ -301,13 +303,13 @@ gc(VALUE self)
JS_GC(context);
-/*
+#ifdef DEBUG
if(depth){
fprintf(stderr,"dumping\n");
JS_DumpHeap(context, stderr, from, 0, thing, depth, 0);
fprintf(stderr,"done\n");
}
-*/
+#endif
return Qnil;
}
@@ -382,18 +384,23 @@ JSBool gc_callback(JSContext *context, JSGCStatus status)
/**
* call-seq:
- * initialize_native(options)
+ * initialize_native(size, options)
*
* Create the underlying TraceMonkey runtime. This must be called
* first, and only once. Called by +initialize+ by default.
*/
static VALUE
-initialize_native(VALUE self, VALUE UNUSED(options))
+initialize_native(VALUE self, VALUE size, VALUE UNUSED(options))
{
JohnsonRuntime* runtime;
Data_Get_Struct(self, JohnsonRuntime, runtime);
- if ((runtime->js = JS_NewRuntime(0x2000000))
+ size_t s = NUM2INT(size);
+ if (s == 0) {
+ s = 0x2000000;
+ }
+
+ if ((runtime->js = JS_NewRuntime(s))
&& (runtime->jsids = create_id_hash())
&& (runtime->rbids = create_id_hash()))
{
@@ -515,7 +522,7 @@ void init_Johnson_TraceMonkey_Runtime(VALUE tracemonkey)
VALUE klass = rb_define_class_under(tracemonkey, "Runtime", johnson_runtime);
rb_define_alloc_func(klass, allocate);
- rb_define_private_method(klass, "initialize_native", (ruby_callback)initialize_native, 1);
+ rb_define_private_method(klass, "initialize_native", (ruby_callback)initialize_native, 2);
rb_define_method(klass, "global", (ruby_callback)global, 0);
rb_define_method(klass, "new_global", (ruby_callback)global, 0);
13 lib/johnson/runtime.rb
View
@@ -26,8 +26,11 @@ def delegate
# this is deprecated; instead, just create an instance of that
# engine's runtime directly.
#
+ # options passed to the underlying runtime
+ # Use size to specify heap limit
+ #
# :call-seq:
- # new(runtime_class=nil)
+ # new(runtime_class=nil, options)
#
def self.new(*args)
return super if self < Johnson::Runtime
@@ -35,12 +38,10 @@ def self.new(*args)
delegate = args.first
if delegate.is_a? Class
delegate.new
- elsif delegate
+ elsif !delegate.nil? && !delegate.is_a?( Hash )
delegate
- elsif
- v = default.new( *args )
- raise "hell" if !v
- v
+ else
+ default.new( *args )
end
end
4 lib/johnson/tracemonkey/runtime.rb
View
@@ -12,7 +12,9 @@ def initialize(options={})
@debugger = nil
@gcthings = {}
@traps = []
- initialize_native(options)
+ size = (options[:size] || options["size"] || ENV["JOHNSON_HEAP_SIZE"] || 0x2000000).to_i
+ options.delete(:size)
+ initialize_native(size, options)
super()
end
Please sign in to comment.
Something went wrong with that request. Please try again.