From 5952b13ce9230ecb500e94b8dfab6f3ce50959ed Mon Sep 17 00:00:00 2001 From: "beard%netscape.com" Date: Sat, 12 Jan 2002 17:40:36 +0000 Subject: [PATCH] Switch to Collector::InstanceOwner templates --- js2/src/js2runtime.h | 103 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 88 insertions(+), 15 deletions(-) diff --git a/js2/src/js2runtime.h b/js2/src/js2runtime.h index 7bd00ff285dc..1e19333e4de1 100644 --- a/js2/src/js2runtime.h +++ b/js2/src/js2runtime.h @@ -238,7 +238,7 @@ static const double two31 = 2147483648.0; void* operator new(size_t n, Collector& gc) { - static Collector::Owner owner; + static Collector::InstanceOwner owner; return gc.allocateObject(n, &owner); } @@ -629,6 +629,9 @@ XXX ...couldn't get this to work... } } + protected: + typedef Collector::InstanceOwner JSObjectOwner; + friend class JSObjectOwner; /** * Scans through the object, and copies all references. */ @@ -645,7 +648,7 @@ XXX ...couldn't get this to work... public: void* operator new(size_t n, Collector& gc) { - static Collector::Owner owner; + static JSObjectOwner owner; return gc.allocateObject(n, &owner); } @@ -700,6 +703,9 @@ XXX ...couldn't get this to work... JSValue *mInstanceValues; + protected: + typedef Collector::InstanceOwner JSInstanceOwner; + friend class JSInstanceOwner; /** * Scans through the object, and copies all references. */ @@ -712,10 +718,11 @@ XXX ...couldn't get this to work... mInstanceValues = (JSValue*) collector->copy(mInstanceValues); return sizeof(JSInstance); } - + + public: void* operator new(size_t n, Collector& gc) { - static Collector::Owner owner; + static JSInstanceOwner owner; return gc.allocateObject(n, &owner); } @@ -748,12 +755,6 @@ XXX ...couldn't get this to work... virtual ~JSType() { } // keeping gcc happy -#ifdef DEBUG - void* operator new(size_t s) { void *t = STD::malloc(s); trace_alloc("JSType", s, t); return t; } - void operator delete(void* t) { trace_release("JSType", t); STD::free(t); } -#endif - - void setSuperType(JSType *super); void setStaticInitializer(Context *cx, JSFunction *f); @@ -853,6 +854,41 @@ XXX ...couldn't get this to work... void printSlotsNStuff(Formatter& f) const; + protected: + typedef Collector::InstanceOwner JSTypeOwner; + friend class JSTypeOwner; + /** + * Scans through the object, and copies all references. + */ + Collector::size_type scan(Collector* collector) + { + JSObject::scan(collector); + mSuperType = (JSType*) collector->copy(mSuperType); + mInstanceInitializer = (JSFunction*) collector->copy(mInstanceInitializer); + mDefaultConstructor = (JSFunction*) collector->copy(mDefaultConstructor); + mTypeCast = (JSFunction*) collector->copy(mTypeCast); + // scan mMethods. + // scan mClassName. + // scan mPrivateNamespace. + uint32 i; + for (i = 0; i < OperatorCount; ++i) + mUnaryOperators[i] = (JSFunction*) collector->copy(mUnaryOperators[i]); + // scan mUninitializedValue. + mPrototypeObject = (JSObject*) collector->copy(mPrototypeObject); + return sizeof(JSType); + } + + public: + void* operator new(size_t n, Collector& gc) + { + static JSTypeOwner owner; + return gc.allocateObject(n, &owner); + } + +#ifdef DEBUG + void* operator new(size_t s) { void *t = STD::malloc(s); trace_alloc("JSType", s, t); return t; } + void operator delete(void* t) { trace_release("JSType", t); STD::free(t); } +#endif }; Formatter& operator<<(Formatter& f, const JSType& obj); @@ -1365,7 +1401,9 @@ XXX ...couldn't get this to work... JSType *mClass; // pointer to owning class if this function is a method FunctionName *mFunctionName; - public: + protected: + typedef Collector::InstanceOwner JSFunctionOwner; + friend class JSFunctionOwner; /** * Scans through the object, and copies all references. */ @@ -1379,9 +1417,10 @@ XXX ...couldn't get this to work... return sizeof(JSFunction); } + public: void* operator new(size_t n, Collector& gc) { - static Collector::Owner owner; + static JSFunctionOwner owner; return gc.allocateObject(n, &owner); } @@ -1454,6 +1493,9 @@ XXX ...couldn't get this to work... JSFunction *getFunction() { return mFunction; } + protected: + typedef Collector::InstanceOwner JBoundFunctionOwner; + friend class JBoundFunctionOwner; /** * Scans through the object, and copies all references. */ @@ -1461,12 +1503,14 @@ XXX ...couldn't get this to work... { JSFunction::scan(collector); // copy the appropriate members. + mFunction = (JSFunction*) collector->copy(mFunction); return sizeof(JSBoundFunction); } + public: void* operator new(size_t n, Collector& gc) { - static Collector::Owner owner; + static JBoundFunctionOwner owner; return gc.allocateObject(n, &owner); } @@ -1845,6 +1889,31 @@ XXX ...couldn't get this to work... JSValue mValue; const String *mName; + + protected: + typedef Collector::InstanceOwner NamedArgumentOwner; + friend class NamedArgumentOwner; + /** + * Scans through the object, and copies all references. + */ + Collector::size_type scan(Collector* collector) + { + JSObject::scan(collector); + mValue.scan(collector); + return sizeof(NamedArgument); + } + + public: + void* operator new(size_t n, Collector& gc) + { + static NamedArgumentOwner owner; + return gc.allocateObject(n, &owner); + } + +#ifdef DEBUG + void* operator new(size_t s) { void *t = STD::malloc(s); trace_alloc("NamedArgument", s, t); return t; } + void operator delete(void* t) { trace_release("NamedArgument", t); STD::free(t); } +#endif }; @@ -1859,6 +1928,9 @@ XXX ...couldn't get this to work... JSType *mExtendArgument; NamespaceList *mNamespaceList; + protected: + typedef Collector::InstanceOwner AttributeOwner; + friend class AttributeOwner; /** * Scans through the object, and copies all references. */ @@ -1868,10 +1940,11 @@ XXX ...couldn't get this to work... mExtendArgument = (JSType*) collector->copy(mExtendArgument); return sizeof(Attribute); } - + + public: void* operator new(size_t n, Collector& gc) { - static Collector::Owner owner; + static AttributeOwner owner; return gc.allocateObject(n, &owner); }