0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd::js: GC related fixes.

This commit is contained in:
Jason Volk 2016-11-06 23:12:38 -08:00
parent c3e6c52192
commit c8402577c3
7 changed files with 32 additions and 17 deletions

View file

@ -128,7 +128,7 @@ void set(context &c, const JSGCParamKey &, const uint32_t &val);
uint32_t get(context &c, const JSGCParamKey &);
void out_of_memory(context &c);
void allocation_overflow(context &c);
void run_gc(context &c);
bool run_gc(context &c) noexcept;
// Exception
bool pending_exception(const context &c);

View file

@ -26,7 +26,7 @@ namespace ircd {
namespace js {
struct global
:heap_object
:persist_object
{
global(trap &, JSPrincipals *const & = nullptr);
};

View file

@ -97,6 +97,7 @@ struct object
using object = basic::object<lifetime::stack>;
using heap_object = basic::object<lifetime::heap>;
using persist_object = basic::object<lifetime::persist>;
//
// Implementation

View file

@ -92,15 +92,9 @@ runtime &our_runtime(JSFreeOp &);
// Do not call interrupt() unless you know what you're doing; see context.h.
void interrupt(runtime &r);
void run_gc(runtime &r);
bool run_gc(runtime &r) noexcept;
inline void
run_gc(runtime &r)
{
JS_GC(r);
}
inline void
interrupt(runtime &r)
{

View file

@ -44,6 +44,7 @@ class trap
virtual bool on_has(object::handle, id::handle);
virtual void on_enu(object::handle);
virtual void on_new(object::handle, object &, const args &);
virtual void on_trace(const JSObject &);
virtual void on_gc(JSObject &);
private:

View file

@ -189,7 +189,8 @@ value<L>::value(const std::string &s)
:value<L>::root::type{[&s]
{
auto buf(native_external_copy(s));
const auto ret(JS_NewExternalString(*cx, buf.release(), s.size(), &native_external_delete));
const auto ret(JS_NewExternalString(*cx, buf.get(), s.size(), &native_external_delete));
buf.release();
return JS::StringValue(ret);
}()}
{
@ -201,7 +202,8 @@ value<L>::value(const char *const &s)
{
const auto len(strlen(s));
auto buf(native_external_copy(s, len));
const auto ret(JS_NewExternalString(*cx, buf.release(), len, &native_external_delete));
const auto ret(JS_NewExternalString(*cx, buf.get(), len, &native_external_delete));
buf.release();
return JS::StringValue(ret);
}()}
{

View file

@ -274,6 +274,7 @@ catch(const std::exception &e)
ircd::js::task::~task()
noexcept
{
run_gc(*rt);
tasks_remove();
}
@ -371,7 +372,7 @@ ircd::js::task::tasks_next_pid()
ircd::js::global::global(trap &trap,
JSPrincipals *const &principals)
:heap_object
:persist_object
{
JS_NewGlobalObject(*cx, &trap.jsclass(), principals, JS::DontFireOnNewGlobalHook)
}
@ -542,10 +543,6 @@ noexcept
//_class->trace = nullptr;
memset(_class.get(), 0x0, sizeof(JSClass));
class_drain.emplace_front(std::move(_class));
// Must run GC here to force reclamation of objects before
// the JSClass hosted by this trap destructs.
//run_gc(*rt);
}
void
@ -973,8 +970,13 @@ ircd::js::trap::handle_trace(JSTracer *const tracer,
JSObject *const obj)
noexcept try
{
assert(cx);
assert(tracer);
assert(obj);
auto &trap(from(*obj));
trap.debug("trace");
trap.on_trace(*obj);
}
catch(const jserror &e)
{
@ -2548,10 +2550,17 @@ ircd::js::save_exception(context &c,
c.report = report;
}
void
bool
ircd::js::run_gc(context &c)
noexcept
{
// JS_MaybeGC dereferences the context's current zone without checking if the context
// is even in a compartment/has a current zone; we must check here.
if(!current_zone(c))
return false;
JS_MaybeGC(c);
return true;
}
void
@ -2808,6 +2817,14 @@ noexcept
{
}
bool
ircd::js::run_gc(runtime &r)
noexcept
{
JS_GC(r);
return true;
}
bool
ircd::js::runtime::handle_interrupt(JSContext *const ctx)
noexcept