OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/heap/mark-compact.h" | 5 #include "src/heap/mark-compact.h" |
6 | 6 |
7 #include "src/base/atomicops.h" | 7 #include "src/base/atomicops.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/base/sys-info.h" | 9 #include "src/base/sys-info.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 2170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2181 heap()->isolate()->global_handles()->RemoveImplicitRefGroups(); | 2181 heap()->isolate()->global_handles()->RemoveImplicitRefGroups(); |
2182 } | 2182 } |
2183 | 2183 |
2184 // Flush code from collected candidates. | 2184 // Flush code from collected candidates. |
2185 if (is_code_flushing_enabled()) { | 2185 if (is_code_flushing_enabled()) { |
2186 GCTracer::Scope gc_scope(heap()->tracer(), | 2186 GCTracer::Scope gc_scope(heap()->tracer(), |
2187 GCTracer::Scope::MC_MARK_CODE_FLUSH); | 2187 GCTracer::Scope::MC_MARK_CODE_FLUSH); |
2188 code_flusher_->ProcessCandidates(); | 2188 code_flusher_->ProcessCandidates(); |
2189 } | 2189 } |
2190 | 2190 |
2191 // Process and clear all optimized code maps. | |
2192 if (!FLAG_flush_optimized_code_cache) { | |
2193 GCTracer::Scope gc_scope(heap()->tracer(), | |
2194 GCTracer::Scope::MC_MARK_OPTIMIZED_CODE_MAPS); | |
2195 ProcessAndClearOptimizedCodeMaps(); | |
2196 } | |
2197 | |
2198 if (FLAG_track_gc_object_stats) { | 2191 if (FLAG_track_gc_object_stats) { |
2199 if (FLAG_trace_gc_object_stats) { | 2192 if (FLAG_trace_gc_object_stats) { |
2200 heap()->object_stats_->TraceObjectStats(); | 2193 heap()->object_stats_->TraceObjectStats(); |
2201 } | 2194 } |
2202 heap()->object_stats_->CheckpointObjectStats(); | 2195 heap()->object_stats_->CheckpointObjectStats(); |
2203 } | 2196 } |
2204 } | 2197 } |
2205 | 2198 |
2206 | 2199 |
2207 void MarkCompactCollector::ProcessAndClearOptimizedCodeMaps() { | |
2208 SharedFunctionInfo::Iterator iterator(isolate()); | |
2209 while (SharedFunctionInfo* shared = iterator.Next()) { | |
2210 if (shared->OptimizedCodeMapIsCleared()) continue; | |
2211 | |
2212 // Process context-dependent entries in the optimized code map. | |
2213 FixedArray* code_map = shared->optimized_code_map(); | |
2214 int new_length = SharedFunctionInfo::kEntriesStart; | |
2215 int old_length = code_map->length(); | |
2216 for (int i = SharedFunctionInfo::kEntriesStart; i < old_length; | |
2217 i += SharedFunctionInfo::kEntryLength) { | |
2218 // Each entry contains [ context, code, literals, ast-id ] as fields. | |
2219 STATIC_ASSERT(SharedFunctionInfo::kEntryLength == 4); | |
2220 Context* context = | |
2221 Context::cast(code_map->get(i + SharedFunctionInfo::kContextOffset)); | |
2222 HeapObject* code = HeapObject::cast( | |
2223 code_map->get(i + SharedFunctionInfo::kCachedCodeOffset)); | |
2224 FixedArray* literals = FixedArray::cast( | |
2225 code_map->get(i + SharedFunctionInfo::kLiteralsOffset)); | |
2226 Smi* ast_id = | |
2227 Smi::cast(code_map->get(i + SharedFunctionInfo::kOsrAstIdOffset)); | |
2228 if (Marking::IsWhite(Marking::MarkBitFrom(context))) continue; | |
2229 DCHECK(Marking::IsBlack(Marking::MarkBitFrom(context))); | |
2230 if (Marking::IsWhite(Marking::MarkBitFrom(code))) continue; | |
2231 DCHECK(Marking::IsBlack(Marking::MarkBitFrom(code))); | |
2232 if (Marking::IsWhite(Marking::MarkBitFrom(literals))) continue; | |
2233 DCHECK(Marking::IsBlack(Marking::MarkBitFrom(literals))); | |
2234 // Move every slot in the entry and record slots when needed. | |
2235 code_map->set(new_length + SharedFunctionInfo::kCachedCodeOffset, code); | |
2236 code_map->set(new_length + SharedFunctionInfo::kContextOffset, context); | |
2237 code_map->set(new_length + SharedFunctionInfo::kLiteralsOffset, literals); | |
2238 code_map->set(new_length + SharedFunctionInfo::kOsrAstIdOffset, ast_id); | |
2239 Object** code_slot = code_map->RawFieldOfElementAt( | |
2240 new_length + SharedFunctionInfo::kCachedCodeOffset); | |
2241 RecordSlot(code_map, code_slot, *code_slot); | |
2242 Object** context_slot = code_map->RawFieldOfElementAt( | |
2243 new_length + SharedFunctionInfo::kContextOffset); | |
2244 RecordSlot(code_map, context_slot, *context_slot); | |
2245 Object** literals_slot = code_map->RawFieldOfElementAt( | |
2246 new_length + SharedFunctionInfo::kLiteralsOffset); | |
2247 RecordSlot(code_map, literals_slot, *literals_slot); | |
2248 new_length += SharedFunctionInfo::kEntryLength; | |
2249 } | |
2250 | |
2251 // Process context-independent entry in the optimized code map. | |
2252 Object* shared_object = code_map->get(SharedFunctionInfo::kSharedCodeIndex); | |
2253 if (shared_object->IsCode()) { | |
2254 Code* shared_code = Code::cast(shared_object); | |
2255 if (Marking::IsWhite(Marking::MarkBitFrom(shared_code))) { | |
2256 code_map->set_undefined(SharedFunctionInfo::kSharedCodeIndex); | |
2257 } else { | |
2258 DCHECK(Marking::IsBlack(Marking::MarkBitFrom(shared_code))); | |
2259 Object** slot = | |
2260 code_map->RawFieldOfElementAt(SharedFunctionInfo::kSharedCodeIndex); | |
2261 RecordSlot(code_map, slot, *slot); | |
2262 } | |
2263 } | |
2264 | |
2265 // Trim the optimized code map if entries have been removed. | |
2266 if (new_length < old_length) { | |
2267 shared->TrimOptimizedCodeMap(old_length - new_length); | |
2268 } | |
2269 } | |
2270 } | |
2271 | |
2272 | |
2273 void MarkCompactCollector::ProcessWeakReferences() { | 2200 void MarkCompactCollector::ProcessWeakReferences() { |
2274 // This should be done before processing weak cells because it checks | 2201 // This should be done before processing weak cells because it checks |
2275 // mark bits of maps in weak cells. | 2202 // mark bits of maps in weak cells. |
2276 DependentCode* dependent_code_list = DependentCodeListFromNonLiveMaps(); | 2203 DependentCode* dependent_code_list = DependentCodeListFromNonLiveMaps(); |
2277 | 2204 |
2278 // Process weak cells before MarkCodeForDeoptimization and | 2205 // Process weak cells before MarkCodeForDeoptimization and |
2279 // ClearNonLiveReferences so that weak cells in dependent code arrays are | 2206 // ClearNonLiveReferences so that weak cells in dependent code arrays are |
2280 // cleared or contain only live code objects. | 2207 // cleared or contain only live code objects. |
2281 ProcessAndClearWeakCells(); | 2208 ProcessAndClearWeakCells(); |
2282 | 2209 |
(...skipping 1874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4157 MarkBit mark_bit = Marking::MarkBitFrom(host); | 4084 MarkBit mark_bit = Marking::MarkBitFrom(host); |
4158 if (Marking::IsBlack(mark_bit)) { | 4085 if (Marking::IsBlack(mark_bit)) { |
4159 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); | 4086 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); |
4160 RecordRelocSlot(&rinfo, target); | 4087 RecordRelocSlot(&rinfo, target); |
4161 } | 4088 } |
4162 } | 4089 } |
4163 } | 4090 } |
4164 | 4091 |
4165 } // namespace internal | 4092 } // namespace internal |
4166 } // namespace v8 | 4093 } // namespace v8 |
OLD | NEW |