Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(983)

Side by Side Diff: runtime/vm/stub_code.cc

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/stub_code.h ('k') | runtime/vm/stub_code_arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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) \ 23 #define STUB_CODE_DECLARE(name) StubEntry* StubCode::name##_entry_ = NULL;
24 StubEntry* StubCode::name##_entry_ = NULL;
25 VM_STUB_CODE_LIST(STUB_CODE_DECLARE); 24 VM_STUB_CODE_LIST(STUB_CODE_DECLARE);
26 #undef STUB_CODE_DECLARE 25 #undef STUB_CODE_DECLARE
27 26
28 27
29 StubEntry::StubEntry(const Code& code) 28 StubEntry::StubEntry(const Code& code)
30 : code_(code.raw()), 29 : code_(code.raw()),
31 entry_point_(code.UncheckedEntryPoint()), 30 entry_point_(code.UncheckedEntryPoint()),
32 checked_entry_point_(code.CheckedEntryPoint()), 31 checked_entry_point_(code.CheckedEntryPoint()),
33 size_(code.Size()), 32 size_(code.Size()),
34 label_(code.UncheckedEntryPoint()) { 33 label_(code.UncheckedEntryPoint()) {}
35 }
36 34
37 35
38 // Visit all object pointers. 36 // Visit all object pointers.
39 void StubEntry::VisitObjectPointers(ObjectPointerVisitor* visitor) { 37 void StubEntry::VisitObjectPointers(ObjectPointerVisitor* visitor) {
40 ASSERT(visitor != NULL); 38 ASSERT(visitor != NULL);
41 visitor->VisitPointer(reinterpret_cast<RawObject**>(&code_)); 39 visitor->VisitPointer(reinterpret_cast<RawObject**>(&code_));
42 } 40 }
43 41
44 42
45 #define STUB_CODE_GENERATE(name) \ 43 #define STUB_CODE_GENERATE(name) \
46 code ^= Generate("_stub_"#name, StubCode::Generate##name##Stub); \ 44 code ^= Generate("_stub_" #name, StubCode::Generate##name##Stub); \
47 name##_entry_ = new StubEntry(code); 45 name##_entry_ = new StubEntry(code);
48 46
49 47
50 void StubCode::InitOnce() { 48 void StubCode::InitOnce() {
51 #if !defined(DART_PRECOMPILED_RUNTIME) 49 #if !defined(DART_PRECOMPILED_RUNTIME)
52 // Generate all the stubs. 50 // Generate all the stubs.
53 Code& code = Code::Handle(); 51 Code& code = Code::Handle();
54 VM_STUB_CODE_LIST(STUB_CODE_GENERATE); 52 VM_STUB_CODE_LIST(STUB_CODE_GENERATE);
55 #else 53 #else
56 UNREACHABLE(); 54 UNREACHABLE();
57 #endif // DART_PRECOMPILED_RUNTIME 55 #endif // DART_PRECOMPILED_RUNTIME
58 } 56 }
59 57
60 58
61 #undef STUB_CODE_GENERATE 59 #undef STUB_CODE_GENERATE
62 60
63 61
64 void StubCode::Push(Serializer* serializer) { 62 void StubCode::Push(Serializer* serializer) {
65 #define WRITE_STUB(name) \ 63 #define WRITE_STUB(name) serializer->Push(StubCode::name##_entry()->code());
66 serializer->Push(StubCode::name##_entry()->code());
67 VM_STUB_CODE_LIST(WRITE_STUB); 64 VM_STUB_CODE_LIST(WRITE_STUB);
68 #undef WRITE_STUB 65 #undef WRITE_STUB
69 } 66 }
70 67
71 68
72 void StubCode::WriteRef(Serializer* serializer) { 69 void StubCode::WriteRef(Serializer* serializer) {
73 #define WRITE_STUB(name) \ 70 #define WRITE_STUB(name) serializer->WriteRef(StubCode::name##_entry()->code());
74 serializer->WriteRef(StubCode::name##_entry()->code());
75 VM_STUB_CODE_LIST(WRITE_STUB); 71 VM_STUB_CODE_LIST(WRITE_STUB);
76 #undef WRITE_STUB 72 #undef WRITE_STUB
77 } 73 }
78 74
79 75
80 void StubCode::ReadRef(Deserializer* deserializer) { 76 void StubCode::ReadRef(Deserializer* deserializer) {
81 Code& code = Code::Handle(); 77 Code& code = Code::Handle();
82 #define READ_STUB(name) \ 78 #define READ_STUB(name) \
83 code ^= deserializer->ReadRef(); \ 79 code ^= deserializer->ReadRef(); \
84 name##_entry_ = new StubEntry(code); 80 name##_entry_ = new StubEntry(code);
85 VM_STUB_CODE_LIST(READ_STUB); 81 VM_STUB_CODE_LIST(READ_STUB);
86 #undef READ_STUB 82 #undef READ_STUB
87 } 83 }
88 84
89 85
90 86 void StubCode::Init(Isolate* isolate) {}
91 void StubCode::Init(Isolate* isolate) { }
92 87
93 88
94 void StubCode::VisitObjectPointers(ObjectPointerVisitor* visitor) { 89 void StubCode::VisitObjectPointers(ObjectPointerVisitor* visitor) {}
95 }
96 90
97 91
98 bool StubCode::HasBeenInitialized() { 92 bool StubCode::HasBeenInitialized() {
99 #if !defined(TARGET_ARCH_DBC) 93 #if !defined(TARGET_ARCH_DBC)
100 // Use JumpToExceptionHandler and InvokeDart as canaries. 94 // Use JumpToExceptionHandler and InvokeDart as canaries.
101 const StubEntry* entry_1 = StubCode::JumpToExceptionHandler_entry(); 95 const StubEntry* entry_1 = StubCode::JumpToExceptionHandler_entry();
102 const StubEntry* entry_2 = StubCode::InvokeDartCode_entry(); 96 const StubEntry* entry_2 = StubCode::InvokeDartCode_entry();
103 return (entry_1 != NULL) && (entry_2 != NULL); 97 return (entry_1 != NULL) && (entry_2 != NULL);
104 #else 98 #else
105 return true; 99 return true;
(...skipping 22 matching lines...) Expand all
128 uword size = StubCode::JumpToExceptionHandlerSize(); 122 uword size = StubCode::JumpToExceptionHandlerSize();
129 return (pc >= entry) && (pc < (entry + size)); 123 return (pc >= entry) && (pc < (entry + size));
130 #else 124 #else
131 // This stub does not exist on DBC. 125 // This stub does not exist on DBC.
132 return false; 126 return false;
133 #endif 127 #endif
134 } 128 }
135 129
136 130
137 RawCode* StubCode::GetAllocationStubForClass(const Class& cls) { 131 RawCode* StubCode::GetAllocationStubForClass(const Class& cls) {
138 // These stubs are not used by DBC. 132 // These stubs are not used by DBC.
139 #if !defined(TARGET_ARCH_DBC) 133 #if !defined(TARGET_ARCH_DBC)
140 Thread* thread = Thread::Current(); 134 Thread* thread = Thread::Current();
141 Zone* zone = thread->zone(); 135 Zone* zone = thread->zone();
142 const Error& error = Error::Handle(zone, cls.EnsureIsFinalized(thread)); 136 const Error& error = Error::Handle(zone, cls.EnsureIsFinalized(thread));
143 ASSERT(error.IsNull()); 137 ASSERT(error.IsNull());
144 if (cls.id() == kArrayCid) { 138 if (cls.id() == kArrayCid) {
145 return AllocateArray_entry()->code(); 139 return AllocateArray_entry()->code();
146 } 140 }
147 Code& stub = Code::Handle(zone, cls.allocation_stub()); 141 Code& stub = Code::Handle(zone, cls.allocation_stub());
148 if (stub.IsNull()) { 142 if (stub.IsNull()) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 192 }
199 return stub.raw(); 193 return stub.raw();
200 #endif // !DBC 194 #endif // !DBC
201 UNIMPLEMENTED(); 195 UNIMPLEMENTED();
202 return Code::null(); 196 return Code::null();
203 } 197 }
204 198
205 199
206 const StubEntry* StubCode::UnoptimizedStaticCallEntry( 200 const StubEntry* StubCode::UnoptimizedStaticCallEntry(
207 intptr_t num_args_tested) { 201 intptr_t num_args_tested) {
208 // These stubs are not used by DBC. 202 // These stubs are not used by DBC.
209 #if !defined(TARGET_ARCH_DBC) 203 #if !defined(TARGET_ARCH_DBC)
210 switch (num_args_tested) { 204 switch (num_args_tested) {
211 case 0: 205 case 0:
212 return ZeroArgsUnoptimizedStaticCall_entry(); 206 return ZeroArgsUnoptimizedStaticCall_entry();
213 case 1: 207 case 1:
214 return OneArgUnoptimizedStaticCall_entry(); 208 return OneArgUnoptimizedStaticCall_entry();
215 case 2: 209 case 2:
216 return TwoArgsUnoptimizedStaticCall_entry(); 210 return TwoArgsUnoptimizedStaticCall_entry();
217 default: 211 default:
218 UNIMPLEMENTED(); 212 UNIMPLEMENTED();
219 return NULL; 213 return NULL;
220 } 214 }
221 #else 215 #else
222 return NULL; 216 return NULL;
223 #endif 217 #endif
224 } 218 }
225 219
226 220
227 RawCode* StubCode::Generate(const char* name, 221 RawCode* StubCode::Generate(const char* name,
228 void (*GenerateStub)(Assembler* assembler)) { 222 void (*GenerateStub)(Assembler* assembler)) {
229 Assembler assembler; 223 Assembler assembler;
230 GenerateStub(&assembler); 224 GenerateStub(&assembler);
231 const Code& code = Code::Handle( 225 const Code& code =
232 Code::FinalizeCode(name, &assembler, false /* optimized */)); 226 Code::Handle(Code::FinalizeCode(name, &assembler, false /* optimized */));
233 #ifndef PRODUCT 227 #ifndef PRODUCT
234 if (FLAG_support_disassembler && FLAG_disassemble_stubs) { 228 if (FLAG_support_disassembler && FLAG_disassemble_stubs) {
235 LogBlock lb; 229 LogBlock lb;
236 THR_Print("Code for stub '%s': {\n", name); 230 THR_Print("Code for stub '%s': {\n", name);
237 DisassembleToStdout formatter; 231 DisassembleToStdout formatter;
238 code.Disassemble(&formatter); 232 code.Disassemble(&formatter);
239 THR_Print("}\n"); 233 THR_Print("}\n");
240 const ObjectPool& object_pool = ObjectPool::Handle(code.object_pool()); 234 const ObjectPool& object_pool = ObjectPool::Handle(code.object_pool());
241 object_pool.DebugPrint(); 235 object_pool.DebugPrint();
242 } 236 }
243 #endif // !PRODUCT 237 #endif // !PRODUCT
244 return code.raw(); 238 return code.raw();
245 } 239 }
246 240
247 241
248 const char* StubCode::NameOfStub(uword entry_point) { 242 const char* StubCode::NameOfStub(uword entry_point) {
249 #define VM_STUB_CODE_TESTER(name) \ 243 #define VM_STUB_CODE_TESTER(name) \
250 if ((name##_entry() != NULL) && \ 244 if ((name##_entry() != NULL) && \
251 (entry_point == name##_entry()->EntryPoint())) { \ 245 (entry_point == name##_entry()->EntryPoint())) { \
252 return ""#name; \ 246 return "" #name; \
253 } 247 }
254 VM_STUB_CODE_LIST(VM_STUB_CODE_TESTER); 248 VM_STUB_CODE_LIST(VM_STUB_CODE_TESTER);
255 #undef VM_STUB_CODE_TESTER 249 #undef VM_STUB_CODE_TESTER
256 return NULL; 250 return NULL;
257 } 251 }
258 252
259 } // namespace dart 253 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/stub_code.h ('k') | runtime/vm/stub_code_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698