]>
git.saurik.com Git - apple/javascriptcore.git/blob - heap/JITStubRoutineSet.cpp
2 * Copyright (C) 2012 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "JITStubRoutineSet.h"
31 #include "GCAwareJITStubRoutine.h"
32 #include "JSCInlines.h"
33 #include "SlotVisitor.h"
37 JITStubRoutineSet::JITStubRoutineSet() { }
38 JITStubRoutineSet::~JITStubRoutineSet()
40 for (size_t i
= m_listOfRoutines
.size(); i
--;) {
41 GCAwareJITStubRoutine
* routine
= m_listOfRoutines
[i
];
43 routine
->m_mayBeExecuting
= false;
45 if (!routine
->m_isJettisoned
) {
46 // Inform the deref() routine that it should delete this guy as soon
47 // as the ref count reaches zero.
48 routine
->m_isJettisoned
= true;
52 routine
->deleteFromGC();
56 void JITStubRoutineSet::add(GCAwareJITStubRoutine
* routine
)
58 ASSERT(!routine
->m_isJettisoned
);
60 m_listOfRoutines
.append(routine
);
62 uintptr_t start
= routine
->startAddress();
63 uintptr_t end
= routine
->endAddress();
64 uintptr_t step
= JITStubRoutine::addressStep();
65 for (uintptr_t iter
= start
; iter
< end
; iter
+= step
) {
66 ASSERT(m_addressToRoutineMap
.find(iter
) == m_addressToRoutineMap
.end());
67 m_addressToRoutineMap
.add(iter
, routine
);
71 void JITStubRoutineSet::clearMarks()
73 for (size_t i
= m_listOfRoutines
.size(); i
--;)
74 m_listOfRoutines
[i
]->m_mayBeExecuting
= false;
77 void JITStubRoutineSet::markSlow(uintptr_t address
)
79 HashMap
<uintptr_t, GCAwareJITStubRoutine
*>::iterator iter
=
80 m_addressToRoutineMap
.find(address
& ~(JITStubRoutine::addressStep() - 1));
82 if (iter
== m_addressToRoutineMap
.end())
85 iter
->value
->m_mayBeExecuting
= true;
88 void JITStubRoutineSet::deleteUnmarkedJettisonedStubRoutines()
90 for (size_t i
= 0; i
< m_listOfRoutines
.size(); i
++) {
91 GCAwareJITStubRoutine
* routine
= m_listOfRoutines
[i
];
92 if (!routine
->m_isJettisoned
|| routine
->m_mayBeExecuting
)
95 uintptr_t start
= routine
->startAddress();
96 uintptr_t end
= routine
->endAddress();
97 uintptr_t step
= JITStubRoutine::addressStep();
98 for (uintptr_t iter
= start
; iter
< end
; iter
+= step
) {
99 ASSERT(m_addressToRoutineMap
.find(iter
) != m_addressToRoutineMap
.end());
100 ASSERT(m_addressToRoutineMap
.find(iter
)->value
== routine
);
101 m_addressToRoutineMap
.remove(iter
);
104 routine
->deleteFromGC();
106 m_listOfRoutines
[i
] = m_listOfRoutines
.last();
107 m_listOfRoutines
.removeLast();
112 void JITStubRoutineSet::traceMarkedStubRoutines(SlotVisitor
& visitor
)
114 for (size_t i
= m_listOfRoutines
.size(); i
--;) {
115 GCAwareJITStubRoutine
* routine
= m_listOfRoutines
[i
];
116 if (!routine
->m_mayBeExecuting
)
119 routine
->markRequiredObjects(visitor
);
125 #endif // ENABLE(JIT)