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

Side by Side Diff: src/objects.cc

Issue 100613004: Use optimized code map to cache OSR code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: correctly upload stuff Created 7 years 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
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 9525 matching lines...) Expand 10 before | Expand all | Expand 10 after
9536 ASSERT(shared->allows_lazy_compilation_without_context()); 9536 ASSERT(shared->allows_lazy_compilation_without_context());
9537 CompilationInfoWithZone info(shared); 9537 CompilationInfoWithZone info(shared);
9538 return CompileLazyHelper(&info, flag); 9538 return CompileLazyHelper(&info, flag);
9539 } 9539 }
9540 9540
9541 9541
9542 void SharedFunctionInfo::AddToOptimizedCodeMap( 9542 void SharedFunctionInfo::AddToOptimizedCodeMap(
9543 Handle<SharedFunctionInfo> shared, 9543 Handle<SharedFunctionInfo> shared,
9544 Handle<Context> native_context, 9544 Handle<Context> native_context,
9545 Handle<Code> code, 9545 Handle<Code> code,
9546 Handle<FixedArray> literals) { 9546 Handle<FixedArray> literals,
9547 BailoutId osr_ast_id) {
9547 CALL_HEAP_FUNCTION_VOID( 9548 CALL_HEAP_FUNCTION_VOID(
9548 shared->GetIsolate(), 9549 shared->GetIsolate(),
9549 shared->AddToOptimizedCodeMap(*native_context, *code, *literals)); 9550 shared->AddToOptimizedCodeMap(
9551 *native_context, *code, *literals, osr_ast_id));
9550 } 9552 }
9551 9553
9552 9554
9553 MaybeObject* SharedFunctionInfo::AddToOptimizedCodeMap(Context* native_context, 9555 MaybeObject* SharedFunctionInfo::AddToOptimizedCodeMap(Context* native_context,
9554 Code* code, 9556 Code* code,
9555 FixedArray* literals) { 9557 FixedArray* literals,
9558 BailoutId osr_ast_id) {
9556 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); 9559 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION);
9557 ASSERT(native_context->IsNativeContext()); 9560 ASSERT(native_context->IsNativeContext());
9558 STATIC_ASSERT(kEntryLength == 3); 9561 STATIC_ASSERT(kEntryLength == 4);
9559 Heap* heap = GetHeap(); 9562 Heap* heap = GetHeap();
9560 FixedArray* new_code_map; 9563 FixedArray* new_code_map;
9561 Object* value = optimized_code_map(); 9564 Object* value = optimized_code_map();
9565 Smi* osr_smi = Smi::FromInt(osr_ast_id.ToInt());
9562 if (value->IsSmi()) { 9566 if (value->IsSmi()) {
9563 // No optimized code map. 9567 // No optimized code map.
9564 ASSERT_EQ(0, Smi::cast(value)->value()); 9568 ASSERT_EQ(0, Smi::cast(value)->value());
9565 // Create 3 entries per context {context, code, literals}. 9569 // Create 3 entries per context {context, code, literals}.
9566 MaybeObject* maybe = heap->AllocateFixedArray(kInitialLength); 9570 MaybeObject* maybe = heap->AllocateFixedArray(kInitialLength);
9567 if (!maybe->To(&new_code_map)) return maybe; 9571 if (!maybe->To(&new_code_map)) return maybe;
9568 new_code_map->set(kEntriesStart + 0, native_context); 9572 new_code_map->set(kEntriesStart + 0, native_context);
9569 new_code_map->set(kEntriesStart + 1, code); 9573 new_code_map->set(kEntriesStart + 1, code);
9570 new_code_map->set(kEntriesStart + 2, literals); 9574 new_code_map->set(kEntriesStart + 2, literals);
9575 new_code_map->set(kEntriesStart + 3, osr_smi);
9571 } else { 9576 } else {
9572 // Copy old map and append one new entry. 9577 // Copy old map and append one new entry.
9573 FixedArray* old_code_map = FixedArray::cast(value); 9578 FixedArray* old_code_map = FixedArray::cast(value);
9574 ASSERT_EQ(-1, SearchOptimizedCodeMap(native_context)); 9579 ASSERT_EQ(-1, SearchOptimizedCodeMap(native_context, osr_ast_id));
9575 int old_length = old_code_map->length(); 9580 int old_length = old_code_map->length();
9576 int new_length = old_length + kEntryLength; 9581 int new_length = old_length + kEntryLength;
9577 MaybeObject* maybe = old_code_map->CopySize(new_length); 9582 MaybeObject* maybe = old_code_map->CopySize(new_length);
9578 if (!maybe->To(&new_code_map)) return maybe; 9583 if (!maybe->To(&new_code_map)) return maybe;
9579 new_code_map->set(old_length + 0, native_context); 9584 new_code_map->set(old_length + 0, native_context);
9580 new_code_map->set(old_length + 1, code); 9585 new_code_map->set(old_length + 1, code);
9581 new_code_map->set(old_length + 2, literals); 9586 new_code_map->set(old_length + 2, literals);
9587 new_code_map->set(old_length + 3, osr_smi);
9582 // Zap the old map for the sake of the heap verifier. 9588 // Zap the old map for the sake of the heap verifier.
9583 if (Heap::ShouldZapGarbage()) { 9589 if (Heap::ShouldZapGarbage()) {
9584 Object** data = old_code_map->data_start(); 9590 Object** data = old_code_map->data_start();
9585 MemsetPointer(data, heap->the_hole_value(), old_length); 9591 MemsetPointer(data, heap->the_hole_value(), old_length);
9586 } 9592 }
9587 } 9593 }
9588 #ifdef DEBUG 9594 #ifdef DEBUG
9589 for (int i = kEntriesStart; i < new_code_map->length(); i += kEntryLength) { 9595 for (int i = kEntriesStart; i < new_code_map->length(); i += kEntryLength) {
9590 ASSERT(new_code_map->get(i)->IsNativeContext()); 9596 ASSERT(new_code_map->get(i)->IsNativeContext());
9591 ASSERT(new_code_map->get(i + 1)->IsCode()); 9597 ASSERT(new_code_map->get(i + 1)->IsCode());
9592 ASSERT(Code::cast(new_code_map->get(i + 1))->kind() == 9598 ASSERT(Code::cast(new_code_map->get(i + 1))->kind() ==
9593 Code::OPTIMIZED_FUNCTION); 9599 Code::OPTIMIZED_FUNCTION);
9594 ASSERT(new_code_map->get(i + 2)->IsFixedArray()); 9600 ASSERT(new_code_map->get(i + 2)->IsFixedArray());
9601 ASSERT(new_code_map->get(i + 3)->IsSmi());
9595 } 9602 }
9596 #endif 9603 #endif
9597 set_optimized_code_map(new_code_map); 9604 set_optimized_code_map(new_code_map);
9598 return new_code_map; 9605 return new_code_map;
9599 } 9606 }
9600 9607
9601 9608
9602 void SharedFunctionInfo::InstallFromOptimizedCodeMap(JSFunction* function, 9609 void SharedFunctionInfo::InstallFromOptimizedCodeMap(JSFunction* function,
9603 int index) { 9610 int index) {
9604 ASSERT(index > kEntriesStart); 9611 ASSERT(index > kEntriesStart);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
9646 PrintF("]\n"); 9653 PrintF("]\n");
9647 } 9654 }
9648 removed_entry = true; 9655 removed_entry = true;
9649 break; 9656 break;
9650 } 9657 }
9651 } 9658 }
9652 while (i < (code_map->length() - kEntryLength)) { 9659 while (i < (code_map->length() - kEntryLength)) {
9653 code_map->set(i, code_map->get(i + kEntryLength)); 9660 code_map->set(i, code_map->get(i + kEntryLength));
9654 code_map->set(i + 1, code_map->get(i + 1 + kEntryLength)); 9661 code_map->set(i + 1, code_map->get(i + 1 + kEntryLength));
9655 code_map->set(i + 2, code_map->get(i + 2 + kEntryLength)); 9662 code_map->set(i + 2, code_map->get(i + 2 + kEntryLength));
9663 code_map->set(i + 3, code_map->get(i + 3 + kEntryLength));
9656 i += kEntryLength; 9664 i += kEntryLength;
9657 } 9665 }
9658 if (removed_entry) { 9666 if (removed_entry) {
9659 // Always trim even when array is cleared because of heap verifier. 9667 // Always trim even when array is cleared because of heap verifier.
9660 RightTrimFixedArray<FROM_MUTATOR>(GetHeap(), code_map, kEntryLength); 9668 RightTrimFixedArray<FROM_MUTATOR>(GetHeap(), code_map, kEntryLength);
9661 if (code_map->length() == kEntriesStart) { 9669 if (code_map->length() == kEntriesStart) {
9662 ClearOptimizedCodeMap(); 9670 ClearOptimizedCodeMap();
9663 } 9671 }
9664 } 9672 }
9665 } 9673 }
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
10251 // Resize the initial map and all maps in its transition tree. 10259 // Resize the initial map and all maps in its transition tree.
10252 map->TraverseTransitionTree(&ShrinkInstanceSize, &slack); 10260 map->TraverseTransitionTree(&ShrinkInstanceSize, &slack);
10253 10261
10254 // Give the correct expected_nof_properties to initial maps created later. 10262 // Give the correct expected_nof_properties to initial maps created later.
10255 ASSERT(expected_nof_properties() >= slack); 10263 ASSERT(expected_nof_properties() >= slack);
10256 set_expected_nof_properties(expected_nof_properties() - slack); 10264 set_expected_nof_properties(expected_nof_properties() - slack);
10257 } 10265 }
10258 } 10266 }
10259 10267
10260 10268
10261 int SharedFunctionInfo::SearchOptimizedCodeMap(Context* native_context) { 10269 int SharedFunctionInfo::SearchOptimizedCodeMap(Context* native_context,
10270 BailoutId osr_ast_id) {
10262 ASSERT(native_context->IsNativeContext()); 10271 ASSERT(native_context->IsNativeContext());
10263 if (!FLAG_cache_optimized_code) return -1; 10272 if (!FLAG_cache_optimized_code) return -1;
10264 Object* value = optimized_code_map(); 10273 Object* value = optimized_code_map();
10274 Smi* osr_smi = Smi::FromInt(osr_ast_id.ToInt());
10265 if (!value->IsSmi()) { 10275 if (!value->IsSmi()) {
10266 FixedArray* optimized_code_map = FixedArray::cast(value); 10276 FixedArray* optimized_code_map = FixedArray::cast(value);
10267 int length = optimized_code_map->length(); 10277 int length = optimized_code_map->length();
10268 for (int i = kEntriesStart; i < length; i += kEntryLength) { 10278 for (int i = kEntriesStart; i < length; i += kEntryLength) {
10269 if (optimized_code_map->get(i) == native_context) { 10279 if (optimized_code_map->get(i) == native_context &&
10280 optimized_code_map->get(i + 3) == osr_smi) {
10270 return i + 1; 10281 return i + 1;
10271 } 10282 }
10272 } 10283 }
10273 if (FLAG_trace_opt) { 10284 if (FLAG_trace_opt) {
10274 PrintF("[didn't find optimized code in optimized code map for "); 10285 PrintF("[didn't find optimized code in optimized code map for ");
10275 ShortPrint(); 10286 ShortPrint();
10276 PrintF("]\n"); 10287 PrintF("]\n");
10277 } 10288 }
10278 } 10289 }
10279 return -1; 10290 return -1;
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
10686 DisallowHeapAllocation no_gc; 10697 DisallowHeapAllocation no_gc;
10687 ASSERT(kind() == FUNCTION); 10698 ASSERT(kind() == FUNCTION);
10688 BackEdgeTable back_edges(this, &no_gc); 10699 BackEdgeTable back_edges(this, &no_gc);
10689 for (uint32_t i = 0; i < back_edges.length(); i++) { 10700 for (uint32_t i = 0; i < back_edges.length(); i++) {
10690 if (back_edges.pc_offset(i) == pc_offset) return back_edges.ast_id(i); 10701 if (back_edges.pc_offset(i) == pc_offset) return back_edges.ast_id(i);
10691 } 10702 }
10692 return BailoutId::None(); 10703 return BailoutId::None();
10693 } 10704 }
10694 10705
10695 10706
10707 uint32_t Code::TranslateAstIdToPcOffset(BailoutId ast_id) {
10708 DisallowHeapAllocation no_gc;
10709 ASSERT(kind() == FUNCTION);
10710 BackEdgeTable back_edges(this, &no_gc);
10711 for (uint32_t i = 0; i < back_edges.length(); i++) {
10712 if (back_edges.ast_id(i) == ast_id) return back_edges.pc_offset(i);
10713 }
10714 UNREACHABLE();
10715 return 0;
10716 }
10717
10718
10696 void Code::MakeCodeAgeSequenceYoung(byte* sequence, Isolate* isolate) { 10719 void Code::MakeCodeAgeSequenceYoung(byte* sequence, Isolate* isolate) {
10697 PatchPlatformCodeAge(isolate, sequence, kNoAgeCodeAge, NO_MARKING_PARITY); 10720 PatchPlatformCodeAge(isolate, sequence, kNoAgeCodeAge, NO_MARKING_PARITY);
10698 } 10721 }
10699 10722
10700 10723
10701 void Code::MarkCodeAsExecuted(byte* sequence, Isolate* isolate) { 10724 void Code::MarkCodeAsExecuted(byte* sequence, Isolate* isolate) {
10702 PatchPlatformCodeAge(isolate, sequence, kExecutedOnceCodeAge, 10725 PatchPlatformCodeAge(isolate, sequence, kExecutedOnceCodeAge,
10703 NO_MARKING_PARITY); 10726 NO_MARKING_PARITY);
10704 } 10727 }
10705 10728
(...skipping 5945 matching lines...) Expand 10 before | Expand all | Expand 10 after
16651 #define ERROR_MESSAGES_TEXTS(C, T) T, 16674 #define ERROR_MESSAGES_TEXTS(C, T) T,
16652 static const char* error_messages_[] = { 16675 static const char* error_messages_[] = {
16653 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16676 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16654 }; 16677 };
16655 #undef ERROR_MESSAGES_TEXTS 16678 #undef ERROR_MESSAGES_TEXTS
16656 return error_messages_[reason]; 16679 return error_messages_[reason];
16657 } 16680 }
16658 16681
16659 16682
16660 } } // namespace v8::internal 16683 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/optimizing-compiler-thread.h » ('j') | src/runtime.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698