| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 #include "bootstrapper.h" | 30 #include "bootstrapper.h" |
| 31 #include "code-stubs.h" | 31 #include "code-stubs.h" |
| 32 #include "factory.h" | 32 #include "factory.h" |
| 33 #include "macro-assembler.h" | 33 #include "macro-assembler.h" |
| 34 | 34 |
| 35 namespace v8 { | 35 namespace v8 { |
| 36 namespace internal { | 36 namespace internal { |
| 37 | 37 |
| 38 Handle<Code> CodeStub::GetCode() { | 38 Handle<Code> CodeStub::GetCode() { |
| 39 uint32_t key = GetKey(); | 39 bool custom_cache = has_custom_cache(); |
| 40 int index = Heap::code_stubs()->FindEntry(key); | 40 |
| 41 if (index == NumberDictionary::kNotFound) { | 41 int index = 0; |
| 42 HandleScope scope; | 42 uint32_t key = 0; |
| 43 if (custom_cache) { |
| 44 Code* cached; |
| 45 if (GetCustomCache(&cached)) { |
| 46 return Handle<Code>(cached); |
| 47 } else { |
| 48 index = NumberDictionary::kNotFound; |
| 49 } |
| 50 } else { |
| 51 key = GetKey(); |
| 52 index = Heap::code_stubs()->FindEntry(key); |
| 53 if (index != NumberDictionary::kNotFound) |
| 54 return Handle<Code>(Code::cast(Heap::code_stubs()->ValueAt(index))); |
| 55 } |
| 56 |
| 57 Code* result; |
| 58 { |
| 59 v8::HandleScope scope; |
| 43 | 60 |
| 44 // Update the static counter each time a new code stub is generated. | 61 // Update the static counter each time a new code stub is generated. |
| 45 Counters::code_stubs.Increment(); | 62 Counters::code_stubs.Increment(); |
| 46 | 63 |
| 47 // Generate the new code. | 64 // Generate the new code. |
| 48 MacroAssembler masm(NULL, 256); | 65 MacroAssembler masm(NULL, 256); |
| 49 | 66 |
| 50 // Nested stubs are not allowed for leafs. | 67 // Nested stubs are not allowed for leafs. |
| 51 masm.set_allow_stub_calls(AllowsStubCalls()); | 68 masm.set_allow_stub_calls(AllowsStubCalls()); |
| 52 | 69 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 72 #ifdef ENABLE_DISASSEMBLER | 89 #ifdef ENABLE_DISASSEMBLER |
| 73 if (FLAG_print_code_stubs) { | 90 if (FLAG_print_code_stubs) { |
| 74 #ifdef DEBUG | 91 #ifdef DEBUG |
| 75 Print(); | 92 Print(); |
| 76 #endif | 93 #endif |
| 77 code->Disassemble(GetName()); | 94 code->Disassemble(GetName()); |
| 78 PrintF("\n"); | 95 PrintF("\n"); |
| 79 } | 96 } |
| 80 #endif | 97 #endif |
| 81 | 98 |
| 82 // Update the dictionary and the root in Heap. | 99 if (custom_cache) { |
| 83 Handle<NumberDictionary> dict = | 100 SetCustomCache(*code); |
| 84 Factory::DictionaryAtNumberPut( | 101 } else { |
| 85 Handle<NumberDictionary>(Heap::code_stubs()), | 102 // Update the dictionary and the root in Heap. |
| 86 key, | 103 Handle<NumberDictionary> dict = |
| 87 code); | 104 Factory::DictionaryAtNumberPut( |
| 88 Heap::public_set_code_stubs(*dict); | 105 Handle<NumberDictionary>(Heap::code_stubs()), |
| 89 index = Heap::code_stubs()->FindEntry(key); | 106 key, |
| 107 code); |
| 108 Heap::public_set_code_stubs(*dict); |
| 109 } |
| 110 result = *code; |
| 90 } | 111 } |
| 91 ASSERT(index != NumberDictionary::kNotFound); | |
| 92 | 112 |
| 93 return Handle<Code>(Code::cast(Heap::code_stubs()->ValueAt(index))); | 113 return Handle<Code>(result); |
| 94 } | 114 } |
| 95 | 115 |
| 96 | 116 |
| 97 const char* CodeStub::MajorName(CodeStub::Major major_key) { | 117 const char* CodeStub::MajorName(CodeStub::Major major_key) { |
| 98 switch (major_key) { | 118 switch (major_key) { |
| 99 #define DEF_CASE(name) case name: return #name; | 119 #define DEF_CASE(name) case name: return #name; |
| 100 CODE_STUB_LIST_ALL(DEF_CASE) | 120 CODE_STUB_LIST_ALL(DEF_CASE) |
| 101 #undef DEF_CASE | 121 #undef DEF_CASE |
| 102 default: | 122 default: |
| 103 UNREACHABLE(); | 123 UNREACHABLE(); |
| 104 return NULL; | 124 return NULL; |
| 105 } | 125 } |
| 106 } | 126 } |
| 107 | 127 |
| 108 | 128 |
| 109 } } // namespace v8::internal | 129 } } // namespace v8::internal |
| OLD | NEW |