Chromium Code Reviews| 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 "platform/globals.h" | 8 #include "platform/globals.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/disassembler.h" | 10 #include "vm/disassembler.h" |
| 11 #include "vm/flags.h" | 11 #include "vm/flags.h" |
| 12 #include "vm/object_store.h" | 12 #include "vm/object_store.h" |
| 13 #include "vm/safepoint.h" | 13 #include "vm/safepoint.h" |
| 14 #include "vm/snapshot.h" | 14 #include "vm/snapshot.h" |
| 15 #include "vm/virtual_memory.h" | 15 #include "vm/virtual_memory.h" |
| 16 #include "vm/visitor.h" | 16 #include "vm/visitor.h" |
| 17 #include "vm/clustered_snapshot.h" | 17 #include "vm/clustered_snapshot.h" |
| 18 | 18 |
| 19 namespace dart { | 19 namespace dart { |
| 20 | 20 |
| 21 DEFINE_FLAG(bool, disassemble_stubs, false, "Disassemble generated stubs."); | 21 DEFINE_FLAG(bool, disassemble_stubs, false, "Disassemble generated stubs."); |
| 22 | 22 |
| 23 #define STUB_CODE_DECLARE(name) StubEntry* StubCode::name##_entry_ = NULL; | 23 StubEntry* StubCode::entries_[kNumStubEntries] = { |
|
Florian Schneider
2016/12/16 22:43:50
StubEntry* const?
rmacnak
2016/12/16 23:42:40
The entries are initialized later.
| |
| 24 VM_STUB_CODE_LIST(STUB_CODE_DECLARE); | 24 #define STUB_CODE_DECLARE(name) NULL, |
| 25 VM_STUB_CODE_LIST(STUB_CODE_DECLARE) | |
| 25 #undef STUB_CODE_DECLARE | 26 #undef STUB_CODE_DECLARE |
| 27 }; | |
| 26 | 28 |
| 27 | 29 |
| 28 StubEntry::StubEntry(const Code& code) | 30 StubEntry::StubEntry(const Code& code) |
| 29 : code_(code.raw()), | 31 : code_(code.raw()), |
| 30 entry_point_(code.UncheckedEntryPoint()), | 32 entry_point_(code.UncheckedEntryPoint()), |
| 31 checked_entry_point_(code.CheckedEntryPoint()), | 33 checked_entry_point_(code.CheckedEntryPoint()), |
| 32 size_(code.Size()), | 34 size_(code.Size()), |
| 33 label_(code.UncheckedEntryPoint()) {} | 35 label_(code.UncheckedEntryPoint()) {} |
| 34 | 36 |
| 35 | 37 |
| 36 // Visit all object pointers. | 38 // Visit all object pointers. |
| 37 void StubEntry::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 39 void StubEntry::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 38 ASSERT(visitor != NULL); | 40 ASSERT(visitor != NULL); |
| 39 visitor->VisitPointer(reinterpret_cast<RawObject**>(&code_)); | 41 visitor->VisitPointer(reinterpret_cast<RawObject**>(&code_)); |
| 40 } | 42 } |
| 41 | 43 |
| 42 | 44 |
| 43 #define STUB_CODE_GENERATE(name) \ | 45 #define STUB_CODE_GENERATE(name) \ |
| 44 code ^= Generate("_stub_" #name, StubCode::Generate##name##Stub); \ | 46 code ^= Generate("_stub_" #name, StubCode::Generate##name##Stub); \ |
| 45 name##_entry_ = new StubEntry(code); | 47 entries_[k##name##Index] = new StubEntry(code); |
| 46 | 48 |
| 47 | 49 |
| 48 void StubCode::InitOnce() { | 50 void StubCode::InitOnce() { |
| 49 #if !defined(DART_PRECOMPILED_RUNTIME) | 51 #if defined(DART_PRECOMPILED_RUNTIME) |
| 52 // Stubs will be loaded from the snapshot. | |
| 53 UNREACHABLE(); | |
| 54 #else | |
| 50 // Generate all the stubs. | 55 // Generate all the stubs. |
| 51 Code& code = Code::Handle(); | 56 Code& code = Code::Handle(); |
| 52 VM_STUB_CODE_LIST(STUB_CODE_GENERATE); | 57 VM_STUB_CODE_LIST(STUB_CODE_GENERATE); |
| 53 #else | |
| 54 UNREACHABLE(); | |
| 55 #endif // DART_PRECOMPILED_RUNTIME | 58 #endif // DART_PRECOMPILED_RUNTIME |
| 56 } | 59 } |
| 57 | 60 |
| 58 | 61 |
| 59 #undef STUB_CODE_GENERATE | 62 #undef STUB_CODE_GENERATE |
| 60 | 63 |
| 61 | 64 |
| 62 void StubCode::Push(Serializer* serializer) { | |
| 63 #define WRITE_STUB(name) serializer->Push(StubCode::name##_entry()->code()); | |
| 64 VM_STUB_CODE_LIST(WRITE_STUB); | |
| 65 #undef WRITE_STUB | |
| 66 } | |
| 67 | |
| 68 | |
| 69 void StubCode::WriteRef(Serializer* serializer) { | |
| 70 #define WRITE_STUB(name) serializer->WriteRef(StubCode::name##_entry()->code()); | |
| 71 VM_STUB_CODE_LIST(WRITE_STUB); | |
| 72 #undef WRITE_STUB | |
| 73 } | |
| 74 | |
| 75 | |
| 76 void StubCode::ReadRef(Deserializer* deserializer) { | |
| 77 Code& code = Code::Handle(); | |
| 78 #define READ_STUB(name) \ | |
| 79 code ^= deserializer->ReadRef(); \ | |
| 80 name##_entry_ = new StubEntry(code); | |
| 81 VM_STUB_CODE_LIST(READ_STUB); | |
| 82 #undef READ_STUB | |
| 83 } | |
| 84 | |
| 85 | |
| 86 void StubCode::Init(Isolate* isolate) {} | 65 void StubCode::Init(Isolate* isolate) {} |
| 87 | 66 |
| 88 | 67 |
| 89 void StubCode::VisitObjectPointers(ObjectPointerVisitor* visitor) {} | 68 void StubCode::VisitObjectPointers(ObjectPointerVisitor* visitor) {} |
| 90 | 69 |
| 91 | 70 |
| 92 bool StubCode::HasBeenInitialized() { | 71 bool StubCode::HasBeenInitialized() { |
| 93 #if !defined(TARGET_ARCH_DBC) | 72 #if !defined(TARGET_ARCH_DBC) |
| 94 // Use JumpToHandler and InvokeDart as canaries. | 73 // Use JumpToHandler and InvokeDart as canaries. |
| 95 const StubEntry* entry_1 = StubCode::JumpToFrame_entry(); | 74 const StubEntry* entry_1 = StubCode::JumpToFrame_entry(); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 if ((name##_entry() != NULL) && \ | 223 if ((name##_entry() != NULL) && \ |
| 245 (entry_point == name##_entry()->EntryPoint())) { \ | 224 (entry_point == name##_entry()->EntryPoint())) { \ |
| 246 return "" #name; \ | 225 return "" #name; \ |
| 247 } | 226 } |
| 248 VM_STUB_CODE_LIST(VM_STUB_CODE_TESTER); | 227 VM_STUB_CODE_LIST(VM_STUB_CODE_TESTER); |
| 249 #undef VM_STUB_CODE_TESTER | 228 #undef VM_STUB_CODE_TESTER |
| 250 return NULL; | 229 return NULL; |
| 251 } | 230 } |
| 252 | 231 |
| 253 } // namespace dart | 232 } // namespace dart |
| OLD | NEW |