| 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_InlineScriptTree_inl_h |
| 8 |
#define jit_InlineScriptTree_inl_h |
| 9 |
|
| 10 |
#include "jit/InlineScriptTree.h" |
| 11 |
|
| 12 |
#include "mozilla/Assertions.h" |
| 13 |
|
| 14 |
#include "jit/JitAllocPolicy.h" |
| 15 |
#include "js/TypeDecls.h" |
| 16 |
#include "vm/JSScript.h" |
| 17 |
|
| 18 |
namespace js { |
| 19 |
namespace jit { |
| 20 |
|
| 21 |
InlineScriptTree* InlineScriptTree::New(TempAllocator* allocator, |
| 22 |
InlineScriptTree* callerTree, |
| 23 |
jsbytecode* callerPc, JSScript* script, |
| 24 |
bool isMonomorphicallyInlined) { |
| 25 |
MOZ_ASSERT_IF(!callerTree, !callerPc); |
| 26 |
MOZ_ASSERT_IF(callerTree, callerTree->script()->containsPC(callerPc)); |
| 27 |
|
| 28 |
// Allocate a new InlineScriptTree |
| 29 |
void* treeMem = allocator->allocate(sizeof(InlineScriptTree)); |
| 30 |
if (!treeMem) { |
| 31 |
return nullptr; |
| 32 |
} |
| 33 |
|
| 34 |
// Initialize it. |
| 35 |
return new (treeMem) |
| 36 |
InlineScriptTree(callerTree, callerPc, script, isMonomorphicallyInlined); |
| 37 |
} |
| 38 |
|
| 39 |
InlineScriptTree* InlineScriptTree::addCallee(TempAllocator* allocator, |
| 40 |
jsbytecode* callerPc, |
| 41 |
JSScript* calleeScript, |
| 42 |
bool isMonomorphicallyInlined) { |
| 43 |
MOZ_ASSERT(script_ && script_->containsPC(callerPc)); |
| 44 |
InlineScriptTree* calleeTree = |
| 45 |
New(allocator, this, callerPc, calleeScript, isMonomorphicallyInlined); |
| 46 |
if (!calleeTree) { |
| 47 |
return nullptr; |
| 48 |
} |
| 49 |
|
| 50 |
calleeTree->nextCallee_ = children_; |
| 51 |
children_ = calleeTree; |
| 52 |
return calleeTree; |
| 53 |
} |
| 54 |
|
| 55 |
void InlineScriptTree::removeCallee(InlineScriptTree* callee) { |
| 56 |
InlineScriptTree** prevPtr = &children_; |
| 57 |
for (InlineScriptTree* child = children_; child; child = child->nextCallee_) { |
| 58 |
if (child == callee) { |
| 59 |
*prevPtr = child->nextCallee_; |
| 60 |
return; |
| 61 |
} |
| 62 |
prevPtr = &child->nextCallee_; |
| 63 |
} |
| 64 |
MOZ_CRASH("Callee not found"); |
| 65 |
} |
| 66 |
|
| 67 |
} // namespace jit |
| 68 |
} // namespace js |
| 69 |
|
| 70 |
#endif /* jit_InlineScriptTree_inl_h */ |