Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: src/mark-compact.cc

Issue 10837037: Age code to allow reclaiming old unexecuted functions (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review feedback Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/mark-compact.h ('k') | src/objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // ------------------------------------------------------------------------- 55 // -------------------------------------------------------------------------
56 // MarkCompactCollector 56 // MarkCompactCollector
57 57
58 MarkCompactCollector::MarkCompactCollector() : // NOLINT 58 MarkCompactCollector::MarkCompactCollector() : // NOLINT
59 #ifdef DEBUG 59 #ifdef DEBUG
60 state_(IDLE), 60 state_(IDLE),
61 #endif 61 #endif
62 sweep_precisely_(false), 62 sweep_precisely_(false),
63 reduce_memory_footprint_(false), 63 reduce_memory_footprint_(false),
64 abort_incremental_marking_(false), 64 abort_incremental_marking_(false),
65 marking_parity_(ODD_MARKING_PARITY),
65 compacting_(false), 66 compacting_(false),
66 was_marked_incrementally_(false), 67 was_marked_incrementally_(false),
67 tracer_(NULL), 68 tracer_(NULL),
68 migration_slots_buffer_(NULL), 69 migration_slots_buffer_(NULL),
69 heap_(NULL), 70 heap_(NULL),
70 code_flusher_(NULL), 71 code_flusher_(NULL),
71 encountered_weak_maps_(NULL), 72 encountered_weak_maps_(NULL),
72 marker_(this, this) { } 73 marker_(this, this) { }
73 74
74 75
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 if (!FLAG_collect_maps) ReattachInitialMaps(); 392 if (!FLAG_collect_maps) ReattachInitialMaps();
392 393
393 #ifdef DEBUG 394 #ifdef DEBUG
394 if (FLAG_verify_native_context_separation) { 395 if (FLAG_verify_native_context_separation) {
395 VerifyNativeContextSeparation(heap_); 396 VerifyNativeContextSeparation(heap_);
396 } 397 }
397 #endif 398 #endif
398 399
399 Finish(); 400 Finish();
400 401
402 if (marking_parity_ == EVEN_MARKING_PARITY) {
403 marking_parity_ = ODD_MARKING_PARITY;
404 } else {
405 ASSERT(marking_parity_ == ODD_MARKING_PARITY);
406 marking_parity_ = EVEN_MARKING_PARITY;
407 }
408
401 tracer_ = NULL; 409 tracer_ = NULL;
402 } 410 }
403 411
404 412
405 #ifdef DEBUG 413 #ifdef DEBUG
406 void MarkCompactCollector::VerifyMarkbitsAreClean(PagedSpace* space) { 414 void MarkCompactCollector::VerifyMarkbitsAreClean(PagedSpace* space) {
407 PageIterator it(space); 415 PageIterator it(space);
408 416
409 while (it.has_next()) { 417 while (it.has_next()) {
410 Page* p = it.next(); 418 Page* p = it.next();
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 } 1194 }
1187 1195
1188 inline static bool IsCompiled(SharedFunctionInfo* function) { 1196 inline static bool IsCompiled(SharedFunctionInfo* function) {
1189 return function->code() != 1197 return function->code() !=
1190 function->GetIsolate()->builtins()->builtin(Builtins::kLazyCompile); 1198 function->GetIsolate()->builtins()->builtin(Builtins::kLazyCompile);
1191 } 1199 }
1192 1200
1193 inline static bool IsFlushable(Heap* heap, JSFunction* function) { 1201 inline static bool IsFlushable(Heap* heap, JSFunction* function) {
1194 SharedFunctionInfo* shared_info = function->unchecked_shared(); 1202 SharedFunctionInfo* shared_info = function->unchecked_shared();
1195 1203
1196 // Code is either on stack, in compilation cache or referenced 1204 // Old code gets flushed if its shared_info is also flushable
1197 // by optimized version of function. 1205 return function->code()->IsOld() && IsFlushable(heap, shared_info);
Michael Starzinger 2012/10/02 14:58:59 See comment below.
danno 2012/10/25 10:07:23 Done.
1198 MarkBit code_mark = Marking::MarkBitFrom(function->code());
1199 if (code_mark.Get()) {
1200 if (!Marking::MarkBitFrom(shared_info).Get()) {
1201 shared_info->set_code_age(0);
1202 }
1203 return false;
1204 }
1205
1206 // We do not flush code for optimized functions.
1207 if (function->code() != shared_info->code()) {
1208 return false;
1209 }
1210
1211 return IsFlushable(heap, shared_info);
1212 } 1206 }
1213 1207
1214 inline static bool IsFlushable(Heap* heap, SharedFunctionInfo* shared_info) { 1208 inline static bool IsFlushable(Heap* heap, SharedFunctionInfo* shared_info) {
1215 // Code is either on stack, in compilation cache or referenced 1209 // Code that is not old is not flushable.
1216 // by optimized version of function. 1210 if (!shared_info->code()->IsOld()) return false;
Michael Starzinger 2012/10/02 14:58:59 1) We shouldn't remove the check for the marking b
danno 2012/10/25 10:07:23 Done.
1217 MarkBit code_mark =
1218 Marking::MarkBitFrom(shared_info->code());
1219 if (code_mark.Get()) {
1220 return false;
1221 }
1222 1211
1223 // The function must be compiled and have the source code available, 1212 // The function must be compiled and have the source code available,
1224 // to be able to recompile it in case we need the function again. 1213 // to be able to recompile it in case we need the function again.
1225 if (!(shared_info->is_compiled() && HasSourceCode(heap, shared_info))) { 1214 if (!(shared_info->is_compiled() && HasSourceCode(heap, shared_info))) {
1226 return false; 1215 return false;
1227 } 1216 }
1228 1217
1229 // We never flush code for Api functions. 1218 // We never flush code for Api functions.
1230 Object* function_data = shared_info->function_data(); 1219 Object* function_data = shared_info->function_data();
1231 if (function_data->IsFunctionTemplateInfo()) { 1220 if (function_data->IsFunctionTemplateInfo()) {
1232 return false; 1221 return false;
1233 } 1222 }
1234 1223
1235 // Only flush code for functions. 1224 // Only flush code for functions.
1236 if (shared_info->code()->kind() != Code::FUNCTION) { 1225 if (shared_info->code()->kind() != Code::FUNCTION) {
1237 return false; 1226 return false;
1238 } 1227 }
1239 1228
1240 // Function must be lazy compilable. 1229 // Function must be lazy compilable.
1241 if (!shared_info->allows_lazy_compilation()) { 1230 if (!shared_info->allows_lazy_compilation()) {
1242 return false; 1231 return false;
1243 } 1232 }
1244 1233
1245 // If this is a full script wrapped in a function we do no flush the code. 1234 // If this is a full script wrapped in a function we do no flush the code.
1246 if (shared_info->is_toplevel()) { 1235 if (shared_info->is_toplevel()) {
1247 return false; 1236 return false;
1248 } 1237 }
1249 1238
1250 // Age this shared function info.
1251 if (shared_info->code_age() < kCodeAgeThreshold) {
1252 shared_info->set_code_age(shared_info->code_age() + 1);
1253 return false;
1254 }
1255
1256 return true; 1239 return true;
1257 } 1240 }
1258 1241
1259 1242
1260 static bool FlushCodeForFunction(Heap* heap, JSFunction* function) { 1243 static bool FlushCodeForFunction(Heap* heap, JSFunction* function) {
1261 if (!IsFlushable(heap, function)) return false; 1244 if (!IsFlushable(heap, function)) return false;
1262 1245
1263 // This function's code looks flushable. But we have to postpone the 1246 // This function's code looks flushable. But we have to postpone the
1264 // decision until we see all functions that point to the same 1247 // decision until we see all functions that point to the same
1265 // SharedFunctionInfo because some of them might be optimized. 1248 // SharedFunctionInfo because some of them might be optimized.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 // The function must have a valid context and not be a builtin. 1388 // The function must have a valid context and not be a builtin.
1406 bool flush_code_candidate = false; 1389 bool flush_code_candidate = false;
1407 if (IsValidNotBuiltinContext(jsfunction->unchecked_context())) { 1390 if (IsValidNotBuiltinContext(jsfunction->unchecked_context())) {
1408 flush_code_candidate = FlushCodeForFunction(heap, jsfunction); 1391 flush_code_candidate = FlushCodeForFunction(heap, jsfunction);
1409 } 1392 }
1410 1393
1411 if (!flush_code_candidate) { 1394 if (!flush_code_candidate) {
1412 Code* code = jsfunction->shared()->code(); 1395 Code* code = jsfunction->shared()->code();
1413 MarkBit code_mark = Marking::MarkBitFrom(code); 1396 MarkBit code_mark = Marking::MarkBitFrom(code);
1414 collector->MarkObject(code, code_mark); 1397 collector->MarkObject(code, code_mark);
1415
1416 if (jsfunction->code()->kind() == Code::OPTIMIZED_FUNCTION) { 1398 if (jsfunction->code()->kind() == Code::OPTIMIZED_FUNCTION) {
1399 code->MakeYoung();
1417 collector->MarkInlinedFunctionsCode(jsfunction->code()); 1400 collector->MarkInlinedFunctionsCode(jsfunction->code());
1418 } 1401 }
1419 } 1402 }
1420 1403
1421 VisitJSFunctionFields(map, 1404 VisitJSFunctionFields(map,
1422 reinterpret_cast<JSFunction*>(object), 1405 reinterpret_cast<JSFunction*>(object),
1423 flush_code_candidate); 1406 flush_code_candidate);
1424 } 1407 }
1425 1408
1426 1409
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after
2723 rinfo->set_target_object(target); 2706 rinfo->set_target_object(target);
2724 } 2707 }
2725 2708
2726 void VisitCodeTarget(RelocInfo* rinfo) { 2709 void VisitCodeTarget(RelocInfo* rinfo) {
2727 ASSERT(RelocInfo::IsCodeTarget(rinfo->rmode())); 2710 ASSERT(RelocInfo::IsCodeTarget(rinfo->rmode()));
2728 Object* target = Code::GetCodeFromTargetAddress(rinfo->target_address()); 2711 Object* target = Code::GetCodeFromTargetAddress(rinfo->target_address());
2729 VisitPointer(&target); 2712 VisitPointer(&target);
2730 rinfo->set_target_address(Code::cast(target)->instruction_start()); 2713 rinfo->set_target_address(Code::cast(target)->instruction_start());
2731 } 2714 }
2732 2715
2716 void VisitCodeAgeSequence(RelocInfo* rinfo) {
2717 ASSERT(RelocInfo::IsCodeAgeSequence(rinfo->rmode()));
2718 Object* stub = rinfo->code_age_stub();
2719 ASSERT(stub != NULL);
2720 VisitPointer(&stub);
2721 rinfo->set_code_age_stub(Code::cast(stub));
2722 }
2723
2733 void VisitDebugTarget(RelocInfo* rinfo) { 2724 void VisitDebugTarget(RelocInfo* rinfo) {
2734 ASSERT((RelocInfo::IsJSReturn(rinfo->rmode()) && 2725 ASSERT((RelocInfo::IsJSReturn(rinfo->rmode()) &&
2735 rinfo->IsPatchedReturnSequence()) || 2726 rinfo->IsPatchedReturnSequence()) ||
2736 (RelocInfo::IsDebugBreakSlot(rinfo->rmode()) && 2727 (RelocInfo::IsDebugBreakSlot(rinfo->rmode()) &&
2737 rinfo->IsPatchedDebugBreakSlotSequence())); 2728 rinfo->IsPatchedDebugBreakSlotSequence()));
2738 Object* target = Code::GetCodeFromTargetAddress(rinfo->call_address()); 2729 Object* target = Code::GetCodeFromTargetAddress(rinfo->call_address());
2739 VisitPointer(&target); 2730 VisitPointer(&target);
2740 rinfo->set_call_address(Code::cast(target)->instruction_start()); 2731 rinfo->set_call_address(Code::cast(target)->instruction_start());
2741 } 2732 }
2742 2733
(...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after
4145 while (buffer != NULL) { 4136 while (buffer != NULL) {
4146 SlotsBuffer* next_buffer = buffer->next(); 4137 SlotsBuffer* next_buffer = buffer->next();
4147 DeallocateBuffer(buffer); 4138 DeallocateBuffer(buffer);
4148 buffer = next_buffer; 4139 buffer = next_buffer;
4149 } 4140 }
4150 *buffer_address = NULL; 4141 *buffer_address = NULL;
4151 } 4142 }
4152 4143
4153 4144
4154 } } // namespace v8::internal 4145 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/mark-compact.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698