Bug 1885489 - Part 5: Add SnapshotIterator::readInt32(). r=iain
[gecko.git] / js / src / jit / WarpOracle.h
blob94824e3e33c3bf8d27c7e09c7bf30f7e72ba0493
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/. */
7 #ifndef jit_WarpOracle_h
8 #define jit_WarpOracle_h
10 #include "jit/JitAllocPolicy.h"
11 #include "jit/JitContext.h"
12 #include "jit/WarpSnapshot.h"
14 namespace js {
15 namespace jit {
17 class MIRGenerator;
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 size_t accumulatedBytecodeSize_ = 0;
29 #ifdef DEBUG
30 mozilla::HashNumber runningScriptHash_ = 0;
31 #endif
33 // List of nursery objects to copy to the snapshot. See WarpObjectField.
34 // The HashMap is used to de-duplicate the Vector. It maps each object to the
35 // corresponding nursery index (index into the Vector).
36 // Note: this stores raw object pointers because WarpOracle can't GC.
37 Vector<JSObject*, 8, SystemAllocPolicy> nurseryObjects_;
38 using NurseryObjectsMap =
39 HashMap<JSObject*, uint32_t, DefaultHasher<JSObject*>, SystemAllocPolicy>;
40 NurseryObjectsMap nurseryObjectsMap_;
42 public:
43 WarpOracle(JSContext* cx, MIRGenerator& mirGen, HandleScript outerScript);
44 ~WarpOracle() { scriptSnapshots_.clear(); }
46 MIRGenerator& mirGen() { return mirGen_; }
47 WarpBailoutInfo& bailoutInfo() { return bailoutInfo_; }
49 [[nodiscard]] bool registerNurseryObject(JSObject* obj,
50 uint32_t* nurseryIndex);
52 AbortReasonOr<WarpSnapshot*> createSnapshot();
54 mozilla::GenericErrorResult<AbortReason> abort(HandleScript script,
55 AbortReason r);
56 mozilla::GenericErrorResult<AbortReason> abort(HandleScript script,
57 AbortReason r,
58 const char* message, ...);
59 void addScriptSnapshot(WarpScriptSnapshot* scriptSnapshot, ICScript* icScript,
60 size_t bytecodeLength);
62 size_t accumulatedBytecodeSize() { return accumulatedBytecodeSize_; }
63 void ignoreFailedICHash();
66 } // namespace jit
67 } // namespace js
69 #endif /* jit_WarpOracle_h */