Bug 888338 - 4 - post barrier CTypes r=terrence

This commit is contained in:
Jon Coppeard 2013-07-23 10:58:27 +01:00
parent 3b22308eee
commit cde9c3d3cd
2 changed files with 37 additions and 25 deletions

View File

@ -3325,11 +3325,12 @@ CType::Trace(JSTracer* trc, JSObject* obj)
FieldInfoHash* fields =
static_cast<FieldInfoHash*>(JSVAL_TO_PRIVATE(slot));
for (FieldInfoHash::Range r = fields->all(); !r.empty(); r.popFront()) {
JSString *key = r.front().key;
for (FieldInfoHash::Enum e(*fields); !e.empty(); e.popFront()) {
JSString *key = e.front().key;
JS_CallStringTracer(trc, &key, "fieldName");
JS_ASSERT(key == r.front().key);
JS_CallObjectTracer(trc, &r.front().value.mType, "fieldType");
if (key != e.front().key)
e.rekeyFront(JS_ASSERT_STRING_IS_FLAT(key));
JS_CallHeapObjectTracer(trc, &e.front().value.mType, "fieldType");
}
break;
@ -3344,10 +3345,10 @@ CType::Trace(JSTracer* trc, JSObject* obj)
JS_ASSERT(fninfo);
// Identify our objects to the tracer.
JS_CallObjectTracer(trc, &fninfo->mABI, "abi");
JS_CallObjectTracer(trc, &fninfo->mReturnType, "returnType");
JS_CallHeapObjectTracer(trc, &fninfo->mABI, "abi");
JS_CallHeapObjectTracer(trc, &fninfo->mReturnType, "returnType");
for (size_t i = 0; i < fninfo->mArgTypes.length(); ++i)
JS_CallObjectTracer(trc, &fninfo->mArgTypes[i], "argType");
JS_CallHeapObjectTracer(trc, &fninfo->mArgTypes[i], "argType");
break;
}
@ -4733,6 +4734,16 @@ StructType::Create(JSContext* cx, unsigned argc, jsval* vp)
return JS_TRUE;
}
static void
PostBarrierCallback(JSTracer *trc, void *k, void *d)
{
JSString *prior = static_cast<JSString*>(k);
FieldInfoHash *table = static_cast<FieldInfoHash*>(d);
JSString *key = prior;
JS_CallStringTracer(trc, &key, "CType fieldName");
table->rekey(JS_ASSERT_STRING_IS_FLAT(prior), JS_ASSERT_STRING_IS_FLAT(key));
}
JSBool
StructType::DefineInternal(JSContext* cx, JSObject* typeObj_, JSObject* fieldsObj_)
{
@ -4823,6 +4834,7 @@ StructType::DefineInternal(JSContext* cx, JSObject* typeObj_, JSObject* fieldsOb
info.mIndex = i;
info.mOffset = fieldOffset;
ASSERT_OK(fields->add(entryPtr, name, info));
JS_StoreStringPostBarrierCallback(cx, PostBarrierCallback, name, fields.get());
structSize = fieldOffset + fieldSize;
@ -6082,10 +6094,10 @@ CClosure::Trace(JSTracer* trc, JSObject* obj)
// Identify our objects to the tracer. (There's no need to identify
// 'closureObj', since that's us.)
JS_CallObjectTracer(trc, &cinfo->typeObj, "typeObj");
JS_CallObjectTracer(trc, &cinfo->jsfnObj, "jsfnObj");
JS_CallHeapObjectTracer(trc, &cinfo->typeObj, "typeObj");
JS_CallHeapObjectTracer(trc, &cinfo->jsfnObj, "jsfnObj");
if (cinfo->thisObj)
JS_CallObjectTracer(trc, &cinfo->thisObj, "thisObj");
JS_CallHeapObjectTracer(trc, &cinfo->thisObj, "thisObj");
}
void

View File

@ -211,9 +211,9 @@ enum TypeCode {
// as the key to the hash entry.
struct FieldInfo
{
JSObject* mType; // CType of the field
size_t mIndex; // index of the field in the struct (first is 0)
size_t mOffset; // offset of the field in the struct, in bytes
JS::Heap<JSObject*> mType; // CType of the field
size_t mIndex; // index of the field in the struct (first is 0)
size_t mOffset; // offset of the field in the struct, in bytes
};
// Hash policy for FieldInfos.
@ -255,14 +255,14 @@ struct FunctionInfo
// Calling convention of the function. Convert to ffi_abi using GetABI
// and OBJECT_TO_JSVAL. Stored as a JSObject* for ease of tracing.
JSObject* mABI;
JS::Heap<JSObject*> mABI;
// The CType of the value returned by the function.
JSObject* mReturnType;
JS::Heap<JSObject*> mReturnType;
// A fixed array of known parameter types, excluding any variadic
// parameters (if mIsVariadic).
Array<JSObject*> mArgTypes;
Array<JS::Heap<JSObject*> > mArgTypes;
// A variable array of ffi_type*s corresponding to both known parameter
// types and dynamic (variadic) parameter types. Longer than mArgTypes
@ -277,15 +277,15 @@ struct FunctionInfo
// Parameters necessary for invoking a JS function from a C closure.
struct ClosureInfo
{
JSContext* cx; // JSContext to use
JSRuntime* rt; // Used in the destructor, where cx might have already
// been GCed.
JSObject* closureObj; // CClosure object
JSObject* typeObj; // FunctionType describing the C function
JSObject* thisObj; // 'this' object to use for the JS function call
JSObject* jsfnObj; // JS function
void* errResult; // Result that will be returned if the closure throws
ffi_closure* closure; // The C closure itself
JSContext* cx; // JSContext to use
JSRuntime* rt; // Used in the destructor, where cx might have already
// been GCed.
JS::Heap<JSObject*> closureObj; // CClosure object
JS::Heap<JSObject*> typeObj; // FunctionType describing the C function
JS::Heap<JSObject*> thisObj; // 'this' object to use for the JS function call
JS::Heap<JSObject*> jsfnObj; // JS function
void* errResult; // Result that will be returned if the closure throws
ffi_closure* closure; // The C closure itself
// Anything conditionally freed in the destructor should be initialized to
// NULL here.