Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef jswatchpoint_h |
michael@0 | 8 | #define jswatchpoint_h |
michael@0 | 9 | |
michael@0 | 10 | #include "jsalloc.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "gc/Barrier.h" |
michael@0 | 13 | #include "js/HashTable.h" |
michael@0 | 14 | #include "js/OldDebugAPI.h" |
michael@0 | 15 | |
michael@0 | 16 | namespace js { |
michael@0 | 17 | |
michael@0 | 18 | struct WeakMapTracer; |
michael@0 | 19 | |
michael@0 | 20 | struct WatchKey { |
michael@0 | 21 | WatchKey() {} |
michael@0 | 22 | WatchKey(JSObject *obj, jsid id) : object(obj), id(id) {} |
michael@0 | 23 | WatchKey(const WatchKey &key) : object(key.object.get()), id(key.id.get()) {} |
michael@0 | 24 | EncapsulatedPtrObject object; |
michael@0 | 25 | EncapsulatedId id; |
michael@0 | 26 | |
michael@0 | 27 | bool operator!=(const WatchKey &other) const { |
michael@0 | 28 | return object != other.object || id != other.id; |
michael@0 | 29 | } |
michael@0 | 30 | }; |
michael@0 | 31 | |
michael@0 | 32 | struct Watchpoint { |
michael@0 | 33 | JSWatchPointHandler handler; |
michael@0 | 34 | EncapsulatedPtrObject closure; /* This is always marked in minor GCs and so doesn't require a postbarrier. */ |
michael@0 | 35 | bool held; /* true if currently running handler */ |
michael@0 | 36 | Watchpoint(JSWatchPointHandler handler, JSObject* closure, bool held) |
michael@0 | 37 | : handler(handler), closure(closure), held(held) {} |
michael@0 | 38 | }; |
michael@0 | 39 | |
michael@0 | 40 | template <> |
michael@0 | 41 | struct DefaultHasher<WatchKey> |
michael@0 | 42 | { |
michael@0 | 43 | typedef WatchKey Lookup; |
michael@0 | 44 | static inline js::HashNumber hash(const Lookup &key); |
michael@0 | 45 | |
michael@0 | 46 | static bool match(const WatchKey &k, const Lookup &l) { |
michael@0 | 47 | return k.object == l.object && k.id.get() == l.id.get(); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | static void rekey(WatchKey &k, const WatchKey& newKey) { |
michael@0 | 51 | k.object.unsafeSet(newKey.object); |
michael@0 | 52 | k.id.unsafeSet(newKey.id); |
michael@0 | 53 | } |
michael@0 | 54 | }; |
michael@0 | 55 | |
michael@0 | 56 | class WatchpointMap { |
michael@0 | 57 | public: |
michael@0 | 58 | typedef HashMap<WatchKey, Watchpoint, DefaultHasher<WatchKey>, SystemAllocPolicy> Map; |
michael@0 | 59 | |
michael@0 | 60 | bool init(); |
michael@0 | 61 | bool watch(JSContext *cx, HandleObject obj, HandleId id, |
michael@0 | 62 | JSWatchPointHandler handler, HandleObject closure); |
michael@0 | 63 | void unwatch(JSObject *obj, jsid id, |
michael@0 | 64 | JSWatchPointHandler *handlerp, JSObject **closurep); |
michael@0 | 65 | void unwatchObject(JSObject *obj); |
michael@0 | 66 | void clear(); |
michael@0 | 67 | |
michael@0 | 68 | bool triggerWatchpoint(JSContext *cx, HandleObject obj, HandleId id, MutableHandleValue vp); |
michael@0 | 69 | |
michael@0 | 70 | static bool markCompartmentIteratively(JSCompartment *c, JSTracer *trc); |
michael@0 | 71 | bool markIteratively(JSTracer *trc); |
michael@0 | 72 | void markAll(JSTracer *trc); |
michael@0 | 73 | static void sweepAll(JSRuntime *rt); |
michael@0 | 74 | void sweep(); |
michael@0 | 75 | |
michael@0 | 76 | static void traceAll(WeakMapTracer *trc); |
michael@0 | 77 | void trace(WeakMapTracer *trc); |
michael@0 | 78 | |
michael@0 | 79 | private: |
michael@0 | 80 | Map map; |
michael@0 | 81 | }; |
michael@0 | 82 | |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | #endif /* jswatchpoint_h */ |