| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/stub_code.h" | 5 #include "vm/stub_code.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/disassembler.h" | 9 #include "vm/disassembler.h" |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| 11 #include "vm/symbols.h" |
| 11 #include "vm/virtual_memory.h" | 12 #include "vm/virtual_memory.h" |
| 12 #include "vm/visitor.h" | 13 #include "vm/visitor.h" |
| 13 | 14 |
| 14 namespace dart { | 15 namespace dart { |
| 15 | 16 |
| 16 DEFINE_FLAG(bool, disassemble_stubs, false, "Disassemble generated stubs."); | 17 DEFINE_FLAG(bool, disassemble_stubs, false, "Disassemble generated stubs."); |
| 17 | 18 |
| 18 #define STUB_CODE_DECLARE(name) \ | 19 #define STUB_CODE_DECLARE(name) \ |
| 19 StubEntry* StubCode::name##_entry_ = NULL; | 20 StubEntry* StubCode::name##_entry_ = NULL; |
| 20 VM_STUB_CODE_LIST(STUB_CODE_DECLARE); | 21 VM_STUB_CODE_LIST(STUB_CODE_DECLARE); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 if (FLAG_disassemble_stubs) { | 148 if (FLAG_disassemble_stubs) { |
| 148 OS::Print("Code for stub '%s': {\n", name); | 149 OS::Print("Code for stub '%s': {\n", name); |
| 149 Disassembler::Disassemble(code.EntryPoint(), | 150 Disassembler::Disassemble(code.EntryPoint(), |
| 150 code.EntryPoint() + assembler.CodeSize()); | 151 code.EntryPoint() + assembler.CodeSize()); |
| 151 OS::Print("}\n"); | 152 OS::Print("}\n"); |
| 152 } | 153 } |
| 153 return code.raw(); | 154 return code.raw(); |
| 154 } | 155 } |
| 155 | 156 |
| 156 | 157 |
| 158 static const char* CreateMethodExtractorName(const Function& closure_function) { |
| 159 const char* kFormat = "[MethodExtractor:%s]"; |
| 160 const char* function_name = |
| 161 String::Handle(closure_function.name()).ToCString(); |
| 162 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name) + 1; |
| 163 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 164 OS::SNPrint(chars, len, kFormat, function_name); |
| 165 return chars; |
| 166 } |
| 167 |
| 168 |
| 169 RawFunction* StubCode::GetMethodExtractor(const Function& closure_function) { |
| 170 Function& extractor = Function::Handle(closure_function.method_extractor()); |
| 171 if (extractor.IsNull()) { |
| 172 Assembler assembler; |
| 173 |
| 174 const char* name = CreateMethodExtractorName(closure_function); |
| 175 |
| 176 StubCode::GenerateMethodExtractor(&assembler, closure_function); |
| 177 const Code& code = Code::Handle(Code::FinalizeCode(name, &assembler)); |
| 178 if (FLAG_disassemble_stubs) { |
| 179 OS::Print("Code for stub '%s': {\n", name); |
| 180 Disassembler::Disassemble(code.EntryPoint(), |
| 181 code.EntryPoint() + assembler.CodeSize()); |
| 182 OS::Print("}\n"); |
| 183 } |
| 184 |
| 185 const Class& cls = |
| 186 Class::Handle(Type::Handle(Type::Function()).type_class()); |
| 187 extractor ^= Function::New(String::Handle(Symbols::New(name)), |
| 188 RawFunction::kMethodExtractor, |
| 189 false, // Not static. |
| 190 false, // Not const. |
| 191 false, // Not abstract. |
| 192 false, // Not external. |
| 193 cls, |
| 194 0); // No token position. |
| 195 extractor.SetCode(code); |
| 196 extractor.set_extracted_method_closure(closure_function); |
| 197 } |
| 198 return extractor.raw(); |
| 199 } |
| 200 |
| 201 |
| 157 const char* StubCode::NameOfStub(uword entry_point) { | 202 const char* StubCode::NameOfStub(uword entry_point) { |
| 158 #define STUB_CODE_TESTER(name) \ | 203 #define STUB_CODE_TESTER(name) \ |
| 159 if ((name##_entry() != NULL) && (entry_point == name##EntryPoint())) { \ | 204 if ((name##_entry() != NULL) && (entry_point == name##EntryPoint())) { \ |
| 160 return ""#name; \ | 205 return ""#name; \ |
| 161 } | 206 } |
| 162 | 207 |
| 163 VM_STUB_CODE_LIST(STUB_CODE_TESTER); | 208 VM_STUB_CODE_LIST(STUB_CODE_TESTER); |
| 164 Isolate* isolate = Isolate::Current(); | 209 Isolate* isolate = Isolate::Current(); |
| 165 if ((isolate != NULL) && (isolate->stub_code() != NULL)) { | 210 if ((isolate != NULL) && (isolate->stub_code() != NULL)) { |
| 166 STUB_CODE_LIST(STUB_CODE_TESTER); | 211 STUB_CODE_LIST(STUB_CODE_TESTER); |
| 167 } | 212 } |
| 168 #undef STUB_CODE_TESTER | 213 #undef STUB_CODE_TESTER |
| 169 return NULL; | 214 return NULL; |
| 170 } | 215 } |
| 171 | 216 |
| 172 } // namespace dart | 217 } // namespace dart |
| OLD | NEW |