| 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/clustered_snapshot.h" | 10 #include "vm/clustered_snapshot.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 checked_entry_point_(code.CheckedEntryPoint()), | 32 checked_entry_point_(code.CheckedEntryPoint()), |
| 33 size_(code.Size()), | 33 size_(code.Size()), |
| 34 label_(code.UncheckedEntryPoint()) {} | 34 label_(code.UncheckedEntryPoint()) {} |
| 35 | 35 |
| 36 // Visit all object pointers. | 36 // Visit all object pointers. |
| 37 void StubEntry::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 37 void StubEntry::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 38 ASSERT(visitor != NULL); | 38 ASSERT(visitor != NULL); |
| 39 visitor->VisitPointer(reinterpret_cast<RawObject**>(&code_)); | 39 visitor->VisitPointer(reinterpret_cast<RawObject**>(&code_)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 #if defined(DART_PRECOMPILED_RUNTIME) |
| 43 void StubCode::InitOnce() { |
| 44 // Stubs will be loaded from the snapshot. |
| 45 UNREACHABLE(); |
| 46 } |
| 47 #else |
| 48 |
| 42 #define STUB_CODE_GENERATE(name) \ | 49 #define STUB_CODE_GENERATE(name) \ |
| 43 code ^= Generate("_stub_" #name, StubCode::Generate##name##Stub); \ | 50 code ^= Generate("_stub_" #name, StubCode::Generate##name##Stub); \ |
| 44 entries_[k##name##Index] = new StubEntry(code); | 51 entries_[k##name##Index] = new StubEntry(code); |
| 45 | 52 |
| 46 void StubCode::InitOnce() { | 53 void StubCode::InitOnce() { |
| 47 #if defined(DART_PRECOMPILED_RUNTIME) | |
| 48 // Stubs will be loaded from the snapshot. | |
| 49 UNREACHABLE(); | |
| 50 #else | |
| 51 // Generate all the stubs. | 54 // Generate all the stubs. |
| 52 Code& code = Code::Handle(); | 55 Code& code = Code::Handle(); |
| 53 VM_STUB_CODE_LIST(STUB_CODE_GENERATE); | 56 VM_STUB_CODE_LIST(STUB_CODE_GENERATE); |
| 54 #endif // DART_PRECOMPILED_RUNTIME | |
| 55 } | 57 } |
| 56 | 58 |
| 57 #undef STUB_CODE_GENERATE | 59 #undef STUB_CODE_GENERATE |
| 58 | 60 |
| 61 RawCode* StubCode::Generate(const char* name, |
| 62 void (*GenerateStub)(Assembler* assembler)) { |
| 63 Assembler assembler; |
| 64 GenerateStub(&assembler); |
| 65 const Code& code = |
| 66 Code::Handle(Code::FinalizeCode(name, &assembler, false /* optimized */)); |
| 67 #ifndef PRODUCT |
| 68 if (FLAG_support_disassembler && FLAG_disassemble_stubs) { |
| 69 LogBlock lb; |
| 70 THR_Print("Code for stub '%s': {\n", name); |
| 71 DisassembleToStdout formatter; |
| 72 code.Disassemble(&formatter); |
| 73 THR_Print("}\n"); |
| 74 const ObjectPool& object_pool = ObjectPool::Handle(code.object_pool()); |
| 75 object_pool.DebugPrint(); |
| 76 } |
| 77 #endif // !PRODUCT |
| 78 return code.raw(); |
| 79 } |
| 80 #endif // defined(DART_PRECOMPILED_RUNTIME) |
| 81 |
| 59 void StubCode::Init(Isolate* isolate) {} | 82 void StubCode::Init(Isolate* isolate) {} |
| 60 | 83 |
| 61 void StubCode::VisitObjectPointers(ObjectPointerVisitor* visitor) {} | 84 void StubCode::VisitObjectPointers(ObjectPointerVisitor* visitor) {} |
| 62 | 85 |
| 63 bool StubCode::HasBeenInitialized() { | 86 bool StubCode::HasBeenInitialized() { |
| 64 #if !defined(TARGET_ARCH_DBC) | 87 #if !defined(TARGET_ARCH_DBC) |
| 65 // Use JumpToHandler and InvokeDart as canaries. | 88 // Use JumpToHandler and InvokeDart as canaries. |
| 66 const StubEntry* entry_1 = StubCode::JumpToFrame_entry(); | 89 const StubEntry* entry_1 = StubCode::JumpToFrame_entry(); |
| 67 const StubEntry* entry_2 = StubCode::InvokeDartCode_entry(); | 90 const StubEntry* entry_2 = StubCode::InvokeDartCode_entry(); |
| 68 return (entry_1 != NULL) && (entry_2 != NULL); | 91 return (entry_1 != NULL) && (entry_2 != NULL); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 // These stubs are not used by DBC. | 123 // These stubs are not used by DBC. |
| 101 #if !defined(TARGET_ARCH_DBC) | 124 #if !defined(TARGET_ARCH_DBC) |
| 102 Thread* thread = Thread::Current(); | 125 Thread* thread = Thread::Current(); |
| 103 Zone* zone = thread->zone(); | 126 Zone* zone = thread->zone(); |
| 104 const Error& error = Error::Handle(zone, cls.EnsureIsFinalized(thread)); | 127 const Error& error = Error::Handle(zone, cls.EnsureIsFinalized(thread)); |
| 105 ASSERT(error.IsNull()); | 128 ASSERT(error.IsNull()); |
| 106 if (cls.id() == kArrayCid) { | 129 if (cls.id() == kArrayCid) { |
| 107 return AllocateArray_entry()->code(); | 130 return AllocateArray_entry()->code(); |
| 108 } | 131 } |
| 109 Code& stub = Code::Handle(zone, cls.allocation_stub()); | 132 Code& stub = Code::Handle(zone, cls.allocation_stub()); |
| 133 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 110 if (stub.IsNull()) { | 134 if (stub.IsNull()) { |
| 111 Assembler assembler; | 135 Assembler assembler; |
| 112 const char* name = cls.ToCString(); | 136 const char* name = cls.ToCString(); |
| 113 StubCode::GenerateAllocationStubForClass(&assembler, cls); | 137 StubCode::GenerateAllocationStubForClass(&assembler, cls); |
| 114 | 138 |
| 115 if (thread->IsMutatorThread()) { | 139 if (thread->IsMutatorThread()) { |
| 116 stub ^= Code::FinalizeCode(name, &assembler, false /* optimized */); | 140 stub ^= Code::FinalizeCode(name, &assembler, false /* optimized */); |
| 117 // Check if background compilation thread has not already added the stub. | 141 // Check if background compilation thread has not already added the stub. |
| 118 if (cls.allocation_stub() == Code::null()) { | 142 if (cls.allocation_stub() == Code::null()) { |
| 119 stub.set_owner(cls); | 143 stub.set_owner(cls); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 LogBlock lb; | 175 LogBlock lb; |
| 152 THR_Print("Code for allocation stub '%s': {\n", name); | 176 THR_Print("Code for allocation stub '%s': {\n", name); |
| 153 DisassembleToStdout formatter; | 177 DisassembleToStdout formatter; |
| 154 stub.Disassemble(&formatter); | 178 stub.Disassemble(&formatter); |
| 155 THR_Print("}\n"); | 179 THR_Print("}\n"); |
| 156 const ObjectPool& object_pool = ObjectPool::Handle(stub.object_pool()); | 180 const ObjectPool& object_pool = ObjectPool::Handle(stub.object_pool()); |
| 157 object_pool.DebugPrint(); | 181 object_pool.DebugPrint(); |
| 158 } | 182 } |
| 159 #endif // !PRODUCT | 183 #endif // !PRODUCT |
| 160 } | 184 } |
| 185 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| 161 return stub.raw(); | 186 return stub.raw(); |
| 162 #endif // !DBC | 187 #endif // !DBC |
| 163 UNIMPLEMENTED(); | 188 UNIMPLEMENTED(); |
| 164 return Code::null(); | 189 return Code::null(); |
| 165 } | 190 } |
| 166 | 191 |
| 167 const StubEntry* StubCode::UnoptimizedStaticCallEntry( | 192 const StubEntry* StubCode::UnoptimizedStaticCallEntry( |
| 168 intptr_t num_args_tested) { | 193 intptr_t num_args_tested) { |
| 169 // These stubs are not used by DBC. | 194 // These stubs are not used by DBC. |
| 170 #if !defined(TARGET_ARCH_DBC) | 195 #if !defined(TARGET_ARCH_DBC) |
| 171 switch (num_args_tested) { | 196 switch (num_args_tested) { |
| 172 case 0: | 197 case 0: |
| 173 return ZeroArgsUnoptimizedStaticCall_entry(); | 198 return ZeroArgsUnoptimizedStaticCall_entry(); |
| 174 case 1: | 199 case 1: |
| 175 return OneArgUnoptimizedStaticCall_entry(); | 200 return OneArgUnoptimizedStaticCall_entry(); |
| 176 case 2: | 201 case 2: |
| 177 return TwoArgsUnoptimizedStaticCall_entry(); | 202 return TwoArgsUnoptimizedStaticCall_entry(); |
| 178 default: | 203 default: |
| 179 UNIMPLEMENTED(); | 204 UNIMPLEMENTED(); |
| 180 return NULL; | 205 return NULL; |
| 181 } | 206 } |
| 182 #else | 207 #else |
| 183 return NULL; | 208 return NULL; |
| 184 #endif | 209 #endif |
| 185 } | 210 } |
| 186 | 211 |
| 187 RawCode* StubCode::Generate(const char* name, | |
| 188 void (*GenerateStub)(Assembler* assembler)) { | |
| 189 Assembler assembler; | |
| 190 GenerateStub(&assembler); | |
| 191 const Code& code = | |
| 192 Code::Handle(Code::FinalizeCode(name, &assembler, false /* optimized */)); | |
| 193 #ifndef PRODUCT | |
| 194 if (FLAG_support_disassembler && FLAG_disassemble_stubs) { | |
| 195 LogBlock lb; | |
| 196 THR_Print("Code for stub '%s': {\n", name); | |
| 197 DisassembleToStdout formatter; | |
| 198 code.Disassemble(&formatter); | |
| 199 THR_Print("}\n"); | |
| 200 const ObjectPool& object_pool = ObjectPool::Handle(code.object_pool()); | |
| 201 object_pool.DebugPrint(); | |
| 202 } | |
| 203 #endif // !PRODUCT | |
| 204 return code.raw(); | |
| 205 } | |
| 206 | |
| 207 const char* StubCode::NameOfStub(uword entry_point) { | 212 const char* StubCode::NameOfStub(uword entry_point) { |
| 208 #define VM_STUB_CODE_TESTER(name) \ | 213 #define VM_STUB_CODE_TESTER(name) \ |
| 209 if ((name##_entry() != NULL) && \ | 214 if ((name##_entry() != NULL) && \ |
| 210 (entry_point == name##_entry()->EntryPoint())) { \ | 215 (entry_point == name##_entry()->EntryPoint())) { \ |
| 211 return "" #name; \ | 216 return "" #name; \ |
| 212 } | 217 } |
| 213 VM_STUB_CODE_LIST(VM_STUB_CODE_TESTER); | 218 VM_STUB_CODE_LIST(VM_STUB_CODE_TESTER); |
| 214 #undef VM_STUB_CODE_TESTER | 219 #undef VM_STUB_CODE_TESTER |
| 215 return NULL; | 220 return NULL; |
| 216 } | 221 } |
| 217 | 222 |
| 218 } // namespace dart | 223 } // namespace dart |
| OLD | NEW |