| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
/* JS symbol tables. */ |
| 8 |
|
| 9 |
#include "vm/ShapeZone.h" |
| 10 |
|
| 11 |
#include "gc/Marking-inl.h" |
| 12 |
#include "vm/Shape-inl.h" |
| 13 |
|
| 14 |
using namespace js; |
| 15 |
using namespace js::gc; |
| 16 |
|
| 17 |
void ShapeZone::fixupPropMapShapeTableAfterMovingGC() { |
| 18 |
for (PropMapShapeSet::Enum e(propMapShapes); !e.empty(); e.popFront()) { |
| 19 |
SharedShape* shape = MaybeForwarded(e.front().unbarrieredGet()); |
| 20 |
SharedPropMap* map = shape->propMapMaybeForwarded(); |
| 21 |
BaseShape* base = MaybeForwarded(shape->base()); |
| 22 |
|
| 23 |
PropMapShapeSet::Lookup lookup(base, shape->numFixedSlots(), map, |
| 24 |
shape->propMapLength(), |
| 25 |
shape->objectFlags()); |
| 26 |
e.rekeyFront(lookup, shape); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
#ifdef JSGC_HASH_TABLE_CHECKS |
| 31 |
void ShapeZone::checkTablesAfterMovingGC(JS::Zone* zone) { |
| 32 |
CheckTableAfterMovingGC(initialPropMaps, [zone](const auto& entry) { |
| 33 |
SharedPropMap* map = entry.unbarrieredGet(); |
| 34 |
CheckGCThingAfterMovingGC(map, zone); |
| 35 |
PropertyKey key = map->getKey(0); |
| 36 |
if (key.isGCThing()) { |
| 37 |
CheckGCThingAfterMovingGC(key.toGCThing(), zone); |
| 38 |
} |
| 39 |
|
| 40 |
return InitialPropMapHasher::Lookup(key, map->getPropertyInfo(0)); |
| 41 |
}); |
| 42 |
|
| 43 |
CheckTableAfterMovingGC(baseShapes, [zone](const auto& entry) { |
| 44 |
BaseShape* base = entry.unbarrieredGet(); |
| 45 |
CheckGCThingAfterMovingGC(base, zone); |
| 46 |
CheckProtoAfterMovingGC(base->proto(), zone); |
| 47 |
|
| 48 |
return BaseShapeHasher::Lookup(base->clasp(), base->realm(), base->proto()); |
| 49 |
}); |
| 50 |
|
| 51 |
CheckTableAfterMovingGC(initialShapes, [zone](const auto& entry) { |
| 52 |
SharedShape* shape = entry.unbarrieredGet(); |
| 53 |
CheckGCThingAfterMovingGC(shape, zone); |
| 54 |
CheckProtoAfterMovingGC(shape->proto(), zone); |
| 55 |
|
| 56 |
return InitialShapeHasher::Lookup(shape->getObjectClass(), shape->realm(), |
| 57 |
shape->proto(), shape->numFixedSlots(), |
| 58 |
shape->objectFlags()); |
| 59 |
}); |
| 60 |
|
| 61 |
CheckTableAfterMovingGC(propMapShapes, [zone](const auto& entry) { |
| 62 |
SharedShape* shape = entry.unbarrieredGet(); |
| 63 |
CheckGCThingAfterMovingGC(shape, zone); |
| 64 |
CheckGCThingAfterMovingGC(shape->base(), zone); |
| 65 |
CheckGCThingAfterMovingGC(shape->propMap(), zone); |
| 66 |
|
| 67 |
return PropMapShapeHasher::Lookup(shape->base(), shape->numFixedSlots(), |
| 68 |
shape->propMap(), shape->propMapLength(), |
| 69 |
shape->objectFlags()); |
| 70 |
}); |
| 71 |
|
| 72 |
CheckTableAfterMovingGC(proxyShapes, [zone](const auto& entry) { |
| 73 |
ProxyShape* shape = entry.unbarrieredGet(); |
| 74 |
CheckGCThingAfterMovingGC(shape, zone); |
| 75 |
CheckProtoAfterMovingGC(shape->proto(), zone); |
| 76 |
|
| 77 |
return ProxyShapeHasher::Lookup(shape->getObjectClass(), shape->realm(), |
| 78 |
shape->proto(), shape->objectFlags()); |
| 79 |
}); |
| 80 |
|
| 81 |
CheckTableAfterMovingGC(wasmGCShapes, [zone](const auto& entry) { |
| 82 |
WasmGCShape* shape = entry.unbarrieredGet(); |
| 83 |
CheckGCThingAfterMovingGC(shape, zone); |
| 84 |
CheckProtoAfterMovingGC(shape->proto(), zone); |
| 85 |
|
| 86 |
return WasmGCShapeHasher::Lookup(shape->getObjectClass(), shape->realm(), |
| 87 |
shape->proto(), shape->recGroup(), |
| 88 |
shape->objectFlags()); |
| 89 |
}); |
| 90 |
} |
| 91 |
#endif // JSGC_HASH_TABLE_CHECKS |
| 92 |
|
| 93 |
ShapeZone::ShapeZone(Zone* zone) |
| 94 |
: baseShapes(zone), |
| 95 |
initialPropMaps(zone), |
| 96 |
initialShapes(zone), |
| 97 |
propMapShapes(zone), |
| 98 |
proxyShapes(zone), |
| 99 |
wasmGCShapes(zone) {} |
| 100 |
|
| 101 |
void ShapeZone::purgeShapeCaches(JS::GCContext* gcx) { |
| 102 |
for (Shape* shape : shapesWithCache) { |
| 103 |
MaybeForwarded(shape)->purgeCache(gcx); |
| 104 |
} |
| 105 |
shapesWithCache.clearAndFree(); |
| 106 |
} |
| 107 |
|
| 108 |
bool ShapeZone::useDictionaryModeTeleportation() { |
| 109 |
if (!JS::Prefs::experimental_dictionary_teleporting()) { |
| 110 |
return false; |
| 111 |
} |
| 112 |
|
| 113 |
if (reshapeCounter > RESHAPE_MAX) { |
| 114 |
return false; |
| 115 |
} |
| 116 |
|
| 117 |
reshapeCounter++; |
| 118 |
return true; |
| 119 |
} |
| 120 |
|
| 121 |
void ShapeZone::addSizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf, |
| 122 |
size_t* initialPropMapTable, |
| 123 |
size_t* shapeTables) { |
| 124 |
*shapeTables += baseShapes.sizeOfExcludingThis(mallocSizeOf); |
| 125 |
*initialPropMapTable += initialPropMaps.sizeOfExcludingThis(mallocSizeOf); |
| 126 |
*shapeTables += initialShapes.sizeOfExcludingThis(mallocSizeOf); |
| 127 |
*shapeTables += propMapShapes.sizeOfExcludingThis(mallocSizeOf); |
| 128 |
*shapeTables += proxyShapes.sizeOfExcludingThis(mallocSizeOf); |
| 129 |
*shapeTables += wasmGCShapes.sizeOfExcludingThis(mallocSizeOf); |
| 130 |
*shapeTables += shapesWithCache.sizeOfExcludingThis(mallocSizeOf); |
| 131 |
} |