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 2145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2156 heap()->isolate()->global_handles()->RemoveImplicitRefGroups(); | 2156 heap()->isolate()->global_handles()->RemoveImplicitRefGroups(); |
2157 } | 2157 } |
2158 | 2158 |
2159 // Flush code from collected candidates. | 2159 // Flush code from collected candidates. |
2160 if (is_code_flushing_enabled()) { | 2160 if (is_code_flushing_enabled()) { |
2161 GCTracer::Scope gc_scope(heap()->tracer(), | 2161 GCTracer::Scope gc_scope(heap()->tracer(), |
2162 GCTracer::Scope::MC_MARK_CODE_FLUSH); | 2162 GCTracer::Scope::MC_MARK_CODE_FLUSH); |
2163 code_flusher_->ProcessCandidates(); | 2163 code_flusher_->ProcessCandidates(); |
2164 } | 2164 } |
2165 | 2165 |
2166 // Process and clear all optimized code maps. | |
2167 if (!FLAG_flush_optimized_code_cache) { | |
2168 GCTracer::Scope gc_scope(heap()->tracer(), | |
2169 GCTracer::Scope::MC_MARK_OPTIMIZED_CODE_MAPS); | |
2170 ProcessAndClearOptimizedCodeMaps(); | |
2171 } | |
2172 | |
2173 if (FLAG_track_gc_object_stats) { | 2166 if (FLAG_track_gc_object_stats) { |
2174 if (FLAG_trace_gc_object_stats) { | 2167 if (FLAG_trace_gc_object_stats) { |
2175 heap()->object_stats_->TraceObjectStats(); | 2168 heap()->object_stats_->TraceObjectStats(); |
2176 } | 2169 } |
2177 heap()->object_stats_->CheckpointObjectStats(); | 2170 heap()->object_stats_->CheckpointObjectStats(); |
2178 } | 2171 } |
2179 } | 2172 } |
2180 | 2173 |
2181 | 2174 |
2182 void MarkCompactCollector::ProcessAndClearOptimizedCodeMaps() { | |
2183 SharedFunctionInfo::Iterator iterator(isolate()); | |
2184 while (SharedFunctionInfo* shared = iterator.Next()) { | |
2185 if (shared->OptimizedCodeMapIsCleared()) continue; | |
2186 | |
2187 // Process context-dependent entries in the optimized code map. | |
2188 FixedArray* code_map = shared->optimized_code_map(); | |
2189 int new_length = SharedFunctionInfo::kEntriesStart; | |
2190 int old_length = code_map->length(); | |
2191 for (int i = SharedFunctionInfo::kEntriesStart; i < old_length; | |
2192 i += SharedFunctionInfo::kEntryLength) { | |
2193 // Each entry contains [ context, code, literals, ast-id ] as fields. | |
2194 STATIC_ASSERT(SharedFunctionInfo::kEntryLength == 4); | |
2195 Context* context = | |
2196 Context::cast(code_map->get(i + SharedFunctionInfo::kContextOffset)); | |
2197 HeapObject* code = HeapObject::cast( | |
2198 code_map->get(i + SharedFunctionInfo::kCachedCodeOffset)); | |
2199 FixedArray* literals = FixedArray::cast( | |
2200 code_map->get(i + SharedFunctionInfo::kLiteralsOffset)); | |
2201 Smi* ast_id = | |
2202 Smi::cast(code_map->get(i + SharedFunctionInfo::kOsrAstIdOffset)); | |
2203 if (Marking::IsWhite(Marking::MarkBitFrom(context))) continue; | |
2204 DCHECK(Marking::IsBlack(Marking::MarkBitFrom(context))); | |
2205 if (Marking::IsWhite(Marking::MarkBitFrom(code))) continue; | |
2206 DCHECK(Marking::IsBlack(Marking::MarkBitFrom(code))); | |
2207 if (Marking::IsWhite(Marking::MarkBitFrom(literals))) continue; | |
2208 DCHECK(Marking::IsBlack(Marking::MarkBitFrom(literals))); | |
2209 // Move every slot in the entry and record slots when needed. | |
2210 code_map->set(new_length + SharedFunctionInfo::kCachedCodeOffset, code); | |
2211 code_map->set(new_length + SharedFunctionInfo::kContextOffset, context); | |
2212 code_map->set(new_length + SharedFunctionInfo::kLiteralsOffset, literals); | |
2213 code_map->set(new_length + SharedFunctionInfo::kOsrAstIdOffset, ast_id); | |
2214 Object** code_slot = code_map->RawFieldOfElementAt( | |
2215 new_length + SharedFunctionInfo::kCachedCodeOffset); | |
2216 RecordSlot(code_map, code_slot, *code_slot); | |
2217 Object** context_slot = code_map->RawFieldOfElementAt( | |
2218 new_length + SharedFunctionInfo::kContextOffset); | |
2219 RecordSlot(code_map, context_slot, *context_slot); | |
2220 Object** literals_slot = code_map->RawFieldOfElementAt( | |
2221 new_length + SharedFunctionInfo::kLiteralsOffset); | |
2222 RecordSlot(code_map, literals_slot, *literals_slot); | |
2223 new_length += SharedFunctionInfo::kEntryLength; | |
2224 } | |
2225 | |
2226 // Process context-independent entry in the optimized code map. | |
2227 Object* shared_object = code_map->get(SharedFunctionInfo::kSharedCodeIndex); | |
2228 if (shared_object->IsCode()) { | |
2229 Code* shared_code = Code::cast(shared_object); | |
2230 if (Marking::IsWhite(Marking::MarkBitFrom(shared_code))) { | |
2231 code_map->set_undefined(SharedFunctionInfo::kSharedCodeIndex); | |
2232 } else { | |
2233 DCHECK(Marking::IsBlack(Marking::MarkBitFrom(shared_code))); | |
2234 Object** slot = | |
2235 code_map->RawFieldOfElementAt(SharedFunctionInfo::kSharedCodeIndex); | |
2236 RecordSlot(code_map, slot, *slot); | |
2237 } | |
2238 } | |
2239 | |
2240 // Trim the optimized code map if entries have been removed. | |
2241 if (new_length < old_length) { | |
2242 shared->TrimOptimizedCodeMap(old_length - new_length); | |
2243 } | |
2244 } | |
2245 } | |
2246 | |
2247 | |
2248 void MarkCompactCollector::ClearNonLiveReferences() { | 2175 void MarkCompactCollector::ClearNonLiveReferences() { |
2249 GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_CLEAR); | 2176 GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_CLEAR); |
2250 | 2177 |
2251 DependentCode* dependent_code_list; | 2178 DependentCode* dependent_code_list; |
2252 Object* non_live_map_list; | 2179 Object* non_live_map_list; |
2253 ClearWeakCells(&non_live_map_list, &dependent_code_list); | 2180 ClearWeakCells(&non_live_map_list, &dependent_code_list); |
2254 | 2181 |
2255 { | 2182 { |
2256 GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_CLEAR_MAP); | 2183 GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_CLEAR_MAP); |
2257 ClearSimpleMapTransitions(non_live_map_list); | 2184 ClearSimpleMapTransitions(non_live_map_list); |
(...skipping 1886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4144 MarkBit mark_bit = Marking::MarkBitFrom(host); | 4071 MarkBit mark_bit = Marking::MarkBitFrom(host); |
4145 if (Marking::IsBlack(mark_bit)) { | 4072 if (Marking::IsBlack(mark_bit)) { |
4146 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); | 4073 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); |
4147 RecordRelocSlot(&rinfo, target); | 4074 RecordRelocSlot(&rinfo, target); |
4148 } | 4075 } |
4149 } | 4076 } |
4150 } | 4077 } |
4151 | 4078 |
4152 } // namespace internal | 4079 } // namespace internal |
4153 } // namespace v8 | 4080 } // namespace v8 |
OLD | NEW |