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