Debian Codegraph @

js/src/jit/BaselineCompileQueue.h

raw
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_BaselineCompileQueue_h
8 #define jit_BaselineCompileQueue_h
9
10 #include "gc/Barrier.h"
11 #include "jit/JitOptions.h"
12
13 class JSScript;
14
15 namespace js {
16 namespace jit {
17
18 class BaselineCompileQueue {
19 public:
20 static constexpr uint32_t MaxCapacity = 64;
21
22 private:
23 uint32_t numQueued_ = 0;
24 HeapPtr<JSScript*> queue_[MaxCapacity];
25
26 public:
27 uint32_t numQueued() const { return numQueued_; }
28
29 static constexpr size_t offsetOfQueue() {
30 return offsetof(BaselineCompileQueue, queue_);
31 }
32 static constexpr size_t offsetOfNumQueued() {
33 return offsetof(BaselineCompileQueue, numQueued_);
34 }
35
36 JSScript* pop() {
37 // To keep our invariants simple, we pop from the end of the queue.
38 MOZ_ASSERT(!isEmpty());
39 assertInvariants();
40 numQueued_--;
41 JSScript* result = queue_[numQueued_];
42 queue_[numQueued_] = nullptr;
43 assertInvariants();
44 return result;
45 }
46
47 bool isEmpty() const { return numQueued_ == 0; }
48
49 MOZ_ALWAYS_INLINE
50 void assertInvariants() const {
51 // The queue always contains |numQueued| JSScript* pointers,
52 // followed by |Capacity - numQueued| null pointers.
53 #ifdef DEBUG
54 MOZ_ASSERT(numQueued_ <= JitOptions.baselineQueueCapacity);
55 MOZ_ASSERT(JitOptions.baselineQueueCapacity <= MaxCapacity);
56 for (uint32_t i = 0; i < numQueued_; i++) {
57 MOZ_ASSERT(queue_[i]);
58 }
59 for (uint32_t i = numQueued_; i < MaxCapacity; i++) {
60 MOZ_ASSERT(!queue_[i]);
61 }
62 #endif
63 }
64 void trace(JSTracer* trc);
65 void remove(JSScript* script);
66 };
67
68 } // namespace jit
69 } // namespace js
70
71 #endif // jit_BaselineCompileQueue_h