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