Skip to content
This repository has been archived by the owner on Aug 18, 2018. It is now read-only.

Commit

Permalink
Raise NoMemoryError as appropriate; acccept a size parameter or env v…
Browse files Browse the repository at this point in the history
…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
smparkes committed Feb 24, 2010
1 parent 74b5876 commit 091117c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
12 changes: 6 additions & 6 deletions ext/tracemonkey/js.cc
Expand Up @@ -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));
}

Expand All @@ -287,18 +287,18 @@ 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);
}
*/

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);
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
25 changes: 16 additions & 9 deletions ext/tracemonkey/runtime.cc
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand All @@ -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;
}
Expand Down Expand Up @@ -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()))
{
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 7 additions & 6 deletions lib/johnson/runtime.rb
Expand Up @@ -26,21 +26,22 @@ 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

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

Expand Down
4 changes: 3 additions & 1 deletion lib/johnson/tracemonkey/runtime.rb
Expand Up @@ -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

Expand Down

0 comments on commit 091117c

Please sign in to comment.