| 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 |
#ifndef jit_WarpOracle_h |
| 8 |
#define jit_WarpOracle_h |
| 9 |
|
| 10 |
#include "jit/JitAllocPolicy.h" |
| 11 |
#include "jit/JitContext.h" |
| 12 |
#include "jit/WarpSnapshot.h" |
| 13 |
|
| 14 |
namespace js { |
| 15 |
namespace jit { |
| 16 |
|
| 17 |
class MIRGenerator; |
| 18 |
|
| 19 |
// WarpOracle creates a WarpSnapshot data structure that's used by WarpBuilder |
| 20 |
// to generate the MIR graph off-thread. |
| 21 |
class MOZ_STACK_CLASS WarpOracle { |
| 22 |
JSContext* cx_; |
| 23 |
MIRGenerator& mirGen_; |
| 24 |
TempAllocator& alloc_; |
| 25 |
HandleScript outerScript_; |
| 26 |
WarpBailoutInfo bailoutInfo_; |
| 27 |
WarpScriptSnapshotList scriptSnapshots_; |
| 28 |
WarpZoneStubsSnapshot zoneStubs_{}; |
| 29 |
size_t accumulatedBytecodeSize_ = 0; |
| 30 |
#ifdef DEBUG |
| 31 |
mozilla::HashNumber runningScriptHash_ = 0; |
| 32 |
#endif |
| 33 |
|
| 34 |
// List of nursery objects to copy to the snapshot. See WarpObjectField. |
| 35 |
// The HashMap is used to de-duplicate the Vector. It maps each object to the |
| 36 |
// corresponding nursery index (index into the Vector). |
| 37 |
// Note: this stores raw object pointers because WarpOracle can't GC. |
| 38 |
Vector<JSObject*, 8, SystemAllocPolicy> nurseryObjects_; |
| 39 |
using NurseryObjectsMap = |
| 40 |
HashMap<JSObject*, uint32_t, DefaultHasher<JSObject*>, SystemAllocPolicy>; |
| 41 |
NurseryObjectsMap nurseryObjectsMap_; |
| 42 |
|
| 43 |
public: |
| 44 |
WarpOracle(JSContext* cx, MIRGenerator& mirGen, HandleScript outerScript); |
| 45 |
~WarpOracle() { scriptSnapshots_.clear(); } |
| 46 |
|
| 47 |
MIRGenerator& mirGen() { return mirGen_; } |
| 48 |
WarpBailoutInfo& bailoutInfo() { return bailoutInfo_; } |
| 49 |
|
| 50 |
[[nodiscard]] bool registerNurseryObject(JSObject* obj, |
| 51 |
uint32_t* nurseryIndex); |
| 52 |
|
| 53 |
[[nodiscard]] bool snapshotJitZoneStub(JitZone::StubKind kind); |
| 54 |
|
| 55 |
AbortReasonOr<WarpSnapshot*> createSnapshot(); |
| 56 |
|
| 57 |
mozilla::GenericErrorResult<AbortReason> abort(HandleScript script, |
| 58 |
AbortReason r); |
| 59 |
mozilla::GenericErrorResult<AbortReason> abort(HandleScript script, |
| 60 |
AbortReason r, |
| 61 |
const char* message, ...); |
| 62 |
void addScriptSnapshot(WarpScriptSnapshot* scriptSnapshot, ICScript* icScript, |
| 63 |
size_t bytecodeLength); |
| 64 |
|
| 65 |
size_t accumulatedBytecodeSize() { return accumulatedBytecodeSize_; } |
| 66 |
void ignoreFailedICHash(); |
| 67 |
}; |
| 68 |
|
| 69 |
} // namespace jit |
| 70 |
} // namespace js |
| 71 |
|
| 72 |
#endif /* jit_WarpOracle_h */ |