BaselineCompileQueue.h (2151B)
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 bool enqueue(JSScript* script) { 50 if (numQueued_ >= JitOptions.baselineQueueCapacity) { 51 return false; // Queue is full 52 } 53 queue_[numQueued_] = script; 54 numQueued_++; 55 assertInvariants(); 56 return true; 57 } 58 59 MOZ_ALWAYS_INLINE 60 void assertInvariants() const { 61 // The queue always contains |numQueued| JSScript* pointers, 62 // followed by |Capacity - numQueued| null pointers. 63 #ifdef DEBUG 64 MOZ_ASSERT(numQueued_ <= JitOptions.baselineQueueCapacity); 65 MOZ_ASSERT(JitOptions.baselineQueueCapacity <= MaxCapacity); 66 for (uint32_t i = 0; i < numQueued_; i++) { 67 MOZ_ASSERT(queue_[i]); 68 } 69 for (uint32_t i = numQueued_; i < MaxCapacity; i++) { 70 MOZ_ASSERT(!queue_[i]); 71 } 72 #endif 73 } 74 void trace(JSTracer* trc); 75 void remove(JSScript* script); 76 }; 77 78 } // namespace jit 79 } // namespace js 80 81 #endif // jit_BaselineCompileQueue_h