From 68f889e9bde68b9a186f040e7a68b9e65a8931c5 Mon Sep 17 00:00:00 2001 From: "brendan%mozilla.org" Date: Tue, 21 Aug 2001 02:53:19 +0000 Subject: [PATCH] Checking in shaver's patch for bug 78100, adding JS_GetExternalStringGCType (sr=brendan&jband). --- js/src/jsapi.c | 11 +++++++++++ js/src/jsapi.h | 7 +++++++ js/src/jsgc.c | 20 +++++++++++--------- js/src/jsgc.h | 3 +++ js/src/jspubtd.h | 15 ++++++++++----- 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/js/src/jsapi.c b/js/src/jsapi.c index e327b5931658..e3c55b109ae7 100644 --- a/js/src/jsapi.c +++ b/js/src/jsapi.c @@ -1690,6 +1690,17 @@ JS_NewExternalString(JSContext *cx, jschar *chars, size_t length, intN type) return str; } +JS_PUBLIC_API(intN) +JS_GetExternalStringGCType(JSRuntime *rt, JSString *str) +{ + uint8 type = *js_GetGCThingFlags(str) & GCF_TYPEMASK; + + JS_ASSERT(type == GCX_STRING || type >= GCX_EXTERNAL_STRING); + if (type == GCX_STRING) + return -1; + return (intN)type; +} + /************************************************************************/ JS_PUBLIC_API(void) diff --git a/js/src/jsapi.h b/js/src/jsapi.h index ad1b4658cd72..f64b1184972c 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -640,6 +640,13 @@ JS_RemoveExternalStringFinalizer(JSStringFinalizeOp finalizer); extern JS_PUBLIC_API(JSString *) JS_NewExternalString(JSContext *cx, jschar *chars, size_t length, intN type); +/* + * Returns the external-string finalizer index for this string, or -1 if it is + * an "internal" (native to JS engine) string. + */ +extern JS_PUBLIC_API(intN) +JS_GetExternalStringGCType(JSRuntime *rt, JSString *str); + /************************************************************************/ /* diff --git a/js/src/jsgc.c b/js/src/jsgc.c index 6eb153c3fa78..51089efd4377 100644 --- a/js/src/jsgc.c +++ b/js/src/jsgc.c @@ -201,8 +201,8 @@ gc_new_arena(JSArenaPool *pool) return thing; } -static uint8 * -gc_find_flags(void *thing) +uint8 * +js_GetGCThingFlags(void *thing) { JSGCPageInfo *pi; uint8 *flagp; @@ -214,9 +214,11 @@ gc_find_flags(void *thing) return flagp; } -JSBool js_IsAboutToBeFinalized(JSContext *cx, void *thing) +JSBool +js_IsAboutToBeFinalized(JSContext *cx, void *thing) { - uint8 flags = *gc_find_flags(thing); + uint8 flags = *js_GetGCThingFlags(thing); + return !(flags & (GCF_MARK | GCF_LOCKMASK | GCF_FINAL)); } @@ -518,7 +520,7 @@ retry: } /* Find the flags pointer given thing's address. */ - flagp = gc_find_flags(thing); + flagp = js_GetGCThingFlags(thing); } *flagp = (uint8)flags; rt->gcBytes += sizeof(JSGCThing) + sizeof(uint8); @@ -544,7 +546,7 @@ js_LockGCThing(JSContext *cx, void *thing) if (!thing) return JS_TRUE; - flagp = gc_find_flags(thing); + flagp = js_GetGCThingFlags(thing); flags = *flagp; ok = JS_TRUE; @@ -616,7 +618,7 @@ js_UnlockGCThing(JSContext *cx, void *thing) if (!thing) return JS_TRUE; - flagp = gc_find_flags(thing); + flagp = js_GetGCThingFlags(thing); flags = *flagp; rt = cx->runtime; @@ -668,7 +670,7 @@ JS_EXPORT_DATA(void *) js_LiveThingToFind; static const char * gc_object_class_name(void* thing) { - uint8 *flagp = gc_find_flags(thing); + uint8 *flagp = js_GetGCThingFlags(thing); const char *className = ""; if (flagp && ((*flagp & GCF_TYPEMASK) == GCX_OBJECT)) { @@ -788,7 +790,7 @@ js_MarkGCThing(JSContext *cx, void *thing, void *arg) if (!thing) return; - flagp = gc_find_flags(thing); + flagp = js_GetGCThingFlags(thing); flags = *flagp; JS_ASSERT(flags != GCF_FINAL); #ifdef GC_MARK_DEBUG diff --git a/js/src/jsgc.h b/js/src/jsgc.h index 9a781c622b76..dc59d473fb13 100644 --- a/js/src/jsgc.h +++ b/js/src/jsgc.h @@ -59,6 +59,9 @@ JS_BEGIN_EXTERN_C #define GCF_LOCKMASK (JS_BITMASK(8 - GCF_LOCKSHIFT) << GCF_LOCKSHIFT) #define GCF_LOCK JS_BIT(GCF_LOCKSHIFT) /* lock request bit in API */ +extern uint8 * +js_GetGCThingFlags(void *thing); + /* These are compatible with JSDHashEntryStub. */ struct JSGCRootHashEntry { JSDHashEntryHdr hdr; diff --git a/js/src/jspubtd.h b/js/src/jspubtd.h index d600036e7f0c..959f8e4f8717 100644 --- a/js/src/jspubtd.h +++ b/js/src/jspubtd.h @@ -275,11 +275,16 @@ typedef JSBool JSBool *bp); /* - * Function type for JSClass.mark and JSObjectOps.mark, called from the GC - * to scan live GC-things reachable from obj's private data. For each such - * private thing, an implementation must call js_MarkGCThing(cx, thing, arg). - * The trailing arg is used for GC_MARK_DEBUG-mode heap dumping and ref-path - * tracing. + * Function type for JSClass.mark and JSObjectOps.mark, called from the GC to + * scan live GC-things reachable from obj's private data structure. For each + * such thing, a mark implementation must call + * + * JS_MarkGCThing(cx, thing, name, arg); + * + * The trailing name and arg parameters are used for GC_MARK_DEBUG-mode heap + * dumping and ref-path tracing. The mark function should pass a (typically + * literal) string naming the private data member for name, and it must pass + * the opaque arg parameter through from its caller. * * For the JSObjectOps.mark hook, the return value is the number of slots at * obj->slots to scan. For JSClass.mark, the return value is ignored.