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 #include "jit/JitHints-inl.h"
8 #include "vm/BytecodeLocation-inl.h"
9 #include "vm/JSScript-inl.h"
12 using namespace js::jit
;
14 JitHintsMap::~JitHintsMap() {
15 while (!ionHintQueue_
.isEmpty()) {
16 IonHint
* e
= ionHintQueue_
.popFirst();
22 JitHintsMap::IonHint
* JitHintsMap::addIonHint(ScriptKey key
,
23 ScriptToHintMap::AddPtr
& p
) {
24 IonHint
* hint
= js_new
<IonHint
>(key
);
29 if (!ionHintMap_
.add(p
, key
, hint
)) {
33 ionHintQueue_
.insertBack(hint
);
35 if (ionHintMap_
.count() > IonHintMaxEntries
) {
36 IonHint
* h
= ionHintQueue_
.popFirst();
37 ionHintMap_
.remove(h
->key());
44 void JitHintsMap::updateAsRecentlyUsed(IonHint
* hint
) {
46 ionHintQueue_
.insertBack(hint
);
49 bool JitHintsMap::recordIonCompilation(JSScript
* script
) {
50 ScriptKey key
= getScriptKey(script
);
55 // Only add hints for scripts that will be eager baseline compiled.
56 if (!baselineHintMap_
.mightContain(key
)) {
60 auto p
= ionHintMap_
.lookupForAdd(key
);
61 IonHint
* hint
= nullptr;
63 // Don't modify existing threshold values.
65 updateAsRecentlyUsed(hint
);
67 hint
= addIonHint(key
, p
);
73 hint
->initThreshold(script
->warmUpCountAtLastICStub());
77 bool JitHintsMap::getIonThresholdHint(JSScript
* script
,
78 uint32_t& thresholdOut
) {
79 ScriptKey key
= getScriptKey(script
);
81 auto p
= ionHintMap_
.lookup(key
);
83 IonHint
* hint
= p
->value();
84 // If the threshold is 0, the hint only contains
85 // monomorphic inlining location information and
86 // may not have entered Ion before.
87 if (hint
->threshold() != 0) {
88 updateAsRecentlyUsed(hint
);
89 thresholdOut
= hint
->threshold();
97 void JitHintsMap::recordInvalidation(JSScript
* script
) {
98 ScriptKey key
= getScriptKey(script
);
100 auto p
= ionHintMap_
.lookup(key
);
102 p
->value()->incThreshold(InvalidationThresholdIncrement
);
107 bool JitHintsMap::addMonomorphicInlineLocation(JSScript
* script
,
108 BytecodeLocation loc
) {
109 ScriptKey key
= getScriptKey(script
);
114 // Only add inline hints for scripts that will be eager baseline compiled.
115 if (!baselineHintMap_
.mightContain(key
)) {
119 auto p
= ionHintMap_
.lookupForAdd(key
);
120 IonHint
* hint
= nullptr;
124 hint
= addIonHint(key
, p
);
130 if (!hint
->hasSpaceForMonomorphicInlineEntry()) {
134 uint32_t offset
= loc
.bytecodeToOffset(script
);
135 return hint
->addMonomorphicInlineOffset(offset
);
138 bool JitHintsMap::hasMonomorphicInlineHintAtOffset(JSScript
* script
,
140 ScriptKey key
= getScriptKey(script
);
145 auto p
= ionHintMap_
.lookup(key
);
147 return p
->value()->hasMonomorphicInlineOffset(offset
);