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

Side by Side Diff: src/objects.cc

Issue 101853003: Cache optimized code for OSR. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments, fixed a bug. 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 9516 matching lines...) Expand 10 before | Expand all | Expand 10 after
9527 set_code_no_write_barrier( 9527 set_code_no_write_barrier(
9528 GetIsolate()->builtins()->builtin(Builtins::kInOptimizationQueue)); 9528 GetIsolate()->builtins()->builtin(Builtins::kInOptimizationQueue));
9529 // No write barrier required, since the builtin is part of the root set. 9529 // No write barrier required, since the builtin is part of the root set.
9530 } 9530 }
9531 9531
9532 9532
9533 void SharedFunctionInfo::AddToOptimizedCodeMap( 9533 void SharedFunctionInfo::AddToOptimizedCodeMap(
9534 Handle<SharedFunctionInfo> shared, 9534 Handle<SharedFunctionInfo> shared,
9535 Handle<Context> native_context, 9535 Handle<Context> native_context,
9536 Handle<Code> code, 9536 Handle<Code> code,
9537 Handle<FixedArray> literals) { 9537 Handle<FixedArray> literals,
9538 BailoutId osr_ast_id) {
9538 CALL_HEAP_FUNCTION_VOID( 9539 CALL_HEAP_FUNCTION_VOID(
9539 shared->GetIsolate(), 9540 shared->GetIsolate(),
9540 shared->AddToOptimizedCodeMap(*native_context, *code, *literals)); 9541 shared->AddToOptimizedCodeMap(
9542 *native_context, *code, *literals, osr_ast_id));
9541 } 9543 }
9542 9544
9543 9545
9544 MaybeObject* SharedFunctionInfo::AddToOptimizedCodeMap(Context* native_context, 9546 MaybeObject* SharedFunctionInfo::AddToOptimizedCodeMap(Context* native_context,
9545 Code* code, 9547 Code* code,
9546 FixedArray* literals) { 9548 FixedArray* literals,
9549 BailoutId osr_ast_id) {
9547 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); 9550 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION);
9548 ASSERT(native_context->IsNativeContext()); 9551 ASSERT(native_context->IsNativeContext());
9549 STATIC_ASSERT(kEntryLength == 3); 9552 STATIC_ASSERT(kEntryLength == 4);
9550 Heap* heap = GetHeap(); 9553 Heap* heap = GetHeap();
9551 FixedArray* new_code_map; 9554 FixedArray* new_code_map;
9552 Object* value = optimized_code_map(); 9555 Object* value = optimized_code_map();
9556 Smi* osr_ast_id_smi = Smi::FromInt(osr_ast_id.ToInt());
9553 if (value->IsSmi()) { 9557 if (value->IsSmi()) {
9554 // No optimized code map. 9558 // No optimized code map.
9555 ASSERT_EQ(0, Smi::cast(value)->value()); 9559 ASSERT_EQ(0, Smi::cast(value)->value());
9556 // Create 3 entries per context {context, code, literals}. 9560 // Create 3 entries per context {context, code, literals}.
9557 MaybeObject* maybe = heap->AllocateFixedArray(kInitialLength); 9561 MaybeObject* maybe = heap->AllocateFixedArray(kInitialLength);
9558 if (!maybe->To(&new_code_map)) return maybe; 9562 if (!maybe->To(&new_code_map)) return maybe;
9559 new_code_map->set(kEntriesStart + 0, native_context); 9563 new_code_map->set(kEntriesStart + kContextOffset, native_context);
9560 new_code_map->set(kEntriesStart + 1, code); 9564 new_code_map->set(kEntriesStart + kCachedCodeOffset, code);
9561 new_code_map->set(kEntriesStart + 2, literals); 9565 new_code_map->set(kEntriesStart + kLiteralsOffset, literals);
9566 new_code_map->set(kEntriesStart + kOsrAstIdOffset, osr_ast_id_smi);
9562 } else { 9567 } else {
9563 // Copy old map and append one new entry. 9568 // Copy old map and append one new entry.
9564 FixedArray* old_code_map = FixedArray::cast(value); 9569 FixedArray* old_code_map = FixedArray::cast(value);
9565 ASSERT_EQ(-1, SearchOptimizedCodeMap(native_context)); 9570 ASSERT_EQ(-1, SearchOptimizedCodeMap(native_context, osr_ast_id));
9566 int old_length = old_code_map->length(); 9571 int old_length = old_code_map->length();
9567 int new_length = old_length + kEntryLength; 9572 int new_length = old_length + kEntryLength;
9568 MaybeObject* maybe = old_code_map->CopySize(new_length); 9573 MaybeObject* maybe = old_code_map->CopySize(new_length);
9569 if (!maybe->To(&new_code_map)) return maybe; 9574 if (!maybe->To(&new_code_map)) return maybe;
9570 new_code_map->set(old_length + 0, native_context); 9575 new_code_map->set(old_length + kContextOffset, native_context);
9571 new_code_map->set(old_length + 1, code); 9576 new_code_map->set(old_length + kCachedCodeOffset, code);
9572 new_code_map->set(old_length + 2, literals); 9577 new_code_map->set(old_length + kLiteralsOffset, literals);
9578 new_code_map->set(old_length + kOsrAstIdOffset, osr_ast_id_smi);
9573 // Zap the old map for the sake of the heap verifier. 9579 // Zap the old map for the sake of the heap verifier.
9574 if (Heap::ShouldZapGarbage()) { 9580 if (Heap::ShouldZapGarbage()) {
9575 Object** data = old_code_map->data_start(); 9581 Object** data = old_code_map->data_start();
9576 MemsetPointer(data, heap->the_hole_value(), old_length); 9582 MemsetPointer(data, heap->the_hole_value(), old_length);
9577 } 9583 }
9578 } 9584 }
9579 #ifdef DEBUG 9585 #ifdef DEBUG
9580 for (int i = kEntriesStart; i < new_code_map->length(); i += kEntryLength) { 9586 for (int i = kEntriesStart; i < new_code_map->length(); i += kEntryLength) {
9581 ASSERT(new_code_map->get(i)->IsNativeContext()); 9587 ASSERT(new_code_map->get(i + kContextOffset)->IsNativeContext());
9582 ASSERT(new_code_map->get(i + 1)->IsCode()); 9588 ASSERT(new_code_map->get(i + kCachedCodeOffset)->IsCode());
9583 ASSERT(Code::cast(new_code_map->get(i + 1))->kind() == 9589 ASSERT(Code::cast(new_code_map->get(i + kCachedCodeOffset))->kind() ==
9584 Code::OPTIMIZED_FUNCTION); 9590 Code::OPTIMIZED_FUNCTION);
9585 ASSERT(new_code_map->get(i + 2)->IsFixedArray()); 9591 ASSERT(new_code_map->get(i + kLiteralsOffset)->IsFixedArray());
9592 ASSERT(new_code_map->get(i + kOsrAstIdOffset)->IsSmi());
9586 } 9593 }
9587 #endif 9594 #endif
9588 set_optimized_code_map(new_code_map); 9595 set_optimized_code_map(new_code_map);
9589 return new_code_map; 9596 return new_code_map;
9590 } 9597 }
9591 9598
9592 9599
9593 FixedArray* SharedFunctionInfo::GetLiteralsFromOptimizedCodeMap(int index) { 9600 FixedArray* SharedFunctionInfo::GetLiteralsFromOptimizedCodeMap(int index) {
9594 ASSERT(index > kEntriesStart); 9601 ASSERT(index > kEntriesStart);
9595 FixedArray* code_map = FixedArray::cast(optimized_code_map()); 9602 FixedArray* code_map = FixedArray::cast(optimized_code_map());
9596 if (!bound()) { 9603 if (!bound()) {
9597 FixedArray* cached_literals = FixedArray::cast(code_map->get(index + 1)); 9604 FixedArray* cached_literals = FixedArray::cast(code_map->get(index + 1));
9598 ASSERT_NE(NULL, cached_literals); 9605 ASSERT_NE(NULL, cached_literals);
9599 return cached_literals; 9606 return cached_literals;
9600 } 9607 }
9601 return NULL; 9608 return NULL;
9602 } 9609 }
9603 9610
9604 9611
9605
9606 Code* SharedFunctionInfo::GetCodeFromOptimizedCodeMap(int index) { 9612 Code* SharedFunctionInfo::GetCodeFromOptimizedCodeMap(int index) {
9607 ASSERT(index > kEntriesStart); 9613 ASSERT(index > kEntriesStart);
9608 FixedArray* code_map = FixedArray::cast(optimized_code_map()); 9614 FixedArray* code_map = FixedArray::cast(optimized_code_map());
9609 Code* code = Code::cast(code_map->get(index)); 9615 Code* code = Code::cast(code_map->get(index));
9610 ASSERT_NE(NULL, code); 9616 ASSERT_NE(NULL, code);
9611 return code; 9617 return code;
9612 } 9618 }
9613 9619
9614 9620
9615 void SharedFunctionInfo::ClearOptimizedCodeMap() { 9621 void SharedFunctionInfo::ClearOptimizedCodeMap() {
(...skipping 24 matching lines...) Expand all
9640 if (FLAG_trace_opt) { 9646 if (FLAG_trace_opt) {
9641 PrintF("[evicting entry from optimizing code map (%s) for ", reason); 9647 PrintF("[evicting entry from optimizing code map (%s) for ", reason);
9642 ShortPrint(); 9648 ShortPrint();
9643 PrintF("]\n"); 9649 PrintF("]\n");
9644 } 9650 }
9645 removed_entry = true; 9651 removed_entry = true;
9646 break; 9652 break;
9647 } 9653 }
9648 } 9654 }
9649 while (i < (code_map->length() - kEntryLength)) { 9655 while (i < (code_map->length() - kEntryLength)) {
9650 code_map->set(i, code_map->get(i + kEntryLength)); 9656 code_map->set(i + kContextOffset,
9651 code_map->set(i + 1, code_map->get(i + 1 + kEntryLength)); 9657 code_map->get(i + kContextOffset + kEntryLength));
9652 code_map->set(i + 2, code_map->get(i + 2 + kEntryLength)); 9658 code_map->set(i + kCachedCodeOffset,
9659 code_map->get(i + kCachedCodeOffset + kEntryLength));
9660 code_map->set(i + kLiteralsOffset,
9661 code_map->get(i + kLiteralsOffset + kEntryLength));
9662 code_map->set(i + kOsrAstIdOffset,
9663 code_map->get(i + kOsrAstIdOffset + kEntryLength));
9653 i += kEntryLength; 9664 i += kEntryLength;
9654 } 9665 }
9655 if (removed_entry) { 9666 if (removed_entry) {
9656 // Always trim even when array is cleared because of heap verifier. 9667 // Always trim even when array is cleared because of heap verifier.
9657 RightTrimFixedArray<FROM_MUTATOR>(GetHeap(), code_map, kEntryLength); 9668 RightTrimFixedArray<FROM_MUTATOR>(GetHeap(), code_map, kEntryLength);
9658 if (code_map->length() == kEntriesStart) { 9669 if (code_map->length() == kEntriesStart) {
9659 ClearOptimizedCodeMap(); 9670 ClearOptimizedCodeMap();
9660 } 9671 }
9661 } 9672 }
9662 } 9673 }
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
10204 // Resize the initial map and all maps in its transition tree. 10215 // Resize the initial map and all maps in its transition tree.
10205 map->TraverseTransitionTree(&ShrinkInstanceSize, &slack); 10216 map->TraverseTransitionTree(&ShrinkInstanceSize, &slack);
10206 10217
10207 // Give the correct expected_nof_properties to initial maps created later. 10218 // Give the correct expected_nof_properties to initial maps created later.
10208 ASSERT(expected_nof_properties() >= slack); 10219 ASSERT(expected_nof_properties() >= slack);
10209 set_expected_nof_properties(expected_nof_properties() - slack); 10220 set_expected_nof_properties(expected_nof_properties() - slack);
10210 } 10221 }
10211 } 10222 }
10212 10223
10213 10224
10214 int SharedFunctionInfo::SearchOptimizedCodeMap(Context* native_context) { 10225 int SharedFunctionInfo::SearchOptimizedCodeMap(Context* native_context,
10226 BailoutId osr_ast_id) {
10215 ASSERT(native_context->IsNativeContext()); 10227 ASSERT(native_context->IsNativeContext());
10216 if (!FLAG_cache_optimized_code) return -1; 10228 if (!FLAG_cache_optimized_code) return -1;
10217 Object* value = optimized_code_map(); 10229 Object* value = optimized_code_map();
10218 if (!value->IsSmi()) { 10230 if (!value->IsSmi()) {
10219 FixedArray* optimized_code_map = FixedArray::cast(value); 10231 FixedArray* optimized_code_map = FixedArray::cast(value);
10220 int length = optimized_code_map->length(); 10232 int length = optimized_code_map->length();
10233 Smi* osr_ast_id_smi = Smi::FromInt(osr_ast_id.ToInt());
10221 for (int i = kEntriesStart; i < length; i += kEntryLength) { 10234 for (int i = kEntriesStart; i < length; i += kEntryLength) {
10222 if (optimized_code_map->get(i) == native_context) { 10235 if (optimized_code_map->get(i + kContextOffset) == native_context &&
10223 return i + 1; 10236 optimized_code_map->get(i + kOsrAstIdOffset) == osr_ast_id_smi) {
10237 return i + kCachedCodeOffset;
10224 } 10238 }
10225 } 10239 }
10226 if (FLAG_trace_opt) { 10240 if (FLAG_trace_opt) {
10227 PrintF("[didn't find optimized code in optimized code map for "); 10241 PrintF("[didn't find optimized code in optimized code map for ");
10228 ShortPrint(); 10242 ShortPrint();
10229 PrintF("]\n"); 10243 PrintF("]\n");
10230 } 10244 }
10231 } 10245 }
10232 return -1; 10246 return -1;
10233 } 10247 }
(...skipping 6370 matching lines...) Expand 10 before | Expand all | Expand 10 after
16604 #define ERROR_MESSAGES_TEXTS(C, T) T, 16618 #define ERROR_MESSAGES_TEXTS(C, T) T,
16605 static const char* error_messages_[] = { 16619 static const char* error_messages_[] = {
16606 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16620 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16607 }; 16621 };
16608 #undef ERROR_MESSAGES_TEXTS 16622 #undef ERROR_MESSAGES_TEXTS
16609 return error_messages_[reason]; 16623 return error_messages_[reason];
16610 } 16624 }
16611 16625
16612 16626
16613 } } // namespace v8::internal 16627 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698