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

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

Issue 1247783002: Make array allocation stub shared between isolates. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 months 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
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"
(...skipping 20 matching lines...) Expand all
31 } 31 }
32 32
33 33
34 // Visit all object pointers. 34 // Visit all object pointers.
35 void StubEntry::VisitObjectPointers(ObjectPointerVisitor* visitor) { 35 void StubEntry::VisitObjectPointers(ObjectPointerVisitor* visitor) {
36 ASSERT(visitor != NULL); 36 ASSERT(visitor != NULL);
37 visitor->VisitPointer(reinterpret_cast<RawObject**>(&code_)); 37 visitor->VisitPointer(reinterpret_cast<RawObject**>(&code_));
38 } 38 }
39 39
40 40
41 StubCode::~StubCode() {
42 #define STUB_CODE_DELETER(name) \
43 delete name##_entry_;
44 STUB_CODE_LIST(STUB_CODE_DELETER);
45 #undef STUB_CODE_DELETER
46 }
47
48
49 #define STUB_CODE_GENERATE(name) \ 41 #define STUB_CODE_GENERATE(name) \
50 code ^= Generate("_stub_"#name, StubCode::Generate##name##Stub); \ 42 code ^= Generate("_stub_"#name, StubCode::Generate##name##Stub); \
51 name##_entry_ = new StubEntry(code); 43 name##_entry_ = new StubEntry(code);
52 44
53 45
54 void StubCode::InitOnce() { 46 void StubCode::InitOnce() {
55 // Generate all the stubs. 47 // Generate all the stubs.
56 Code& code = Code::Handle(); 48 Code& code = Code::Handle();
57 VM_STUB_CODE_LIST(STUB_CODE_GENERATE); 49 VM_STUB_CODE_LIST(STUB_CODE_GENERATE);
58 } 50 }
59 51
60 52
61 void StubCode::GenerateStubsFor(Isolate* init) {
62 // Generate all the other stubs.
63 Code& code = Code::Handle();
64 STUB_CODE_LIST(STUB_CODE_GENERATE);
65 }
66
67 #undef STUB_CODE_GENERATE 53 #undef STUB_CODE_GENERATE
68 54
69 55
70 void StubCode::Init(Isolate* isolate) { 56 void StubCode::Init(Isolate* isolate) { }
71 StubCode* stubs = new StubCode(isolate);
72 isolate->set_stub_code(stubs);
73 isolate->stub_code()->GenerateStubsFor(isolate);
74 }
75 57
76 58
77 void StubCode::VisitObjectPointers(ObjectPointerVisitor* visitor) { 59 void StubCode::VisitObjectPointers(ObjectPointerVisitor* visitor) {
78 // The current isolate is needed as part of the macro.
79 Isolate* isolate = Isolate::Current();
80 StubCode* stubs = isolate->stub_code();
81 if (stubs == NULL) return;
82 StubEntry* entry;
83 #define STUB_CODE_VISIT_OBJECT_POINTER(name) \
84 entry = stubs->name##_entry(); \
85 if (entry != NULL) { \
86 entry->VisitObjectPointers(visitor); \
87 }
88
89 STUB_CODE_LIST(STUB_CODE_VISIT_OBJECT_POINTER);
90 #undef STUB_CODE_VISIT_OBJECT_POINTER
91 } 60 }
92 61
93 62
94 bool StubCode::InInvocationStub(uword pc) { 63 bool StubCode::InInvocationStub(uword pc) {
95 return InInvocationStubForIsolate(Isolate::Current(), pc); 64 uword entry = StubCode::InvokeDartCodeEntryPoint();
96 } 65 uword size = StubCode::InvokeDartCodeSize();
97
98
99 bool StubCode::InInvocationStubForIsolate(Isolate* isolate, uword pc) {
100 StubCode* stub_code = isolate->stub_code();
101 uword entry = stub_code->InvokeDartCodeEntryPoint();
102 uword size = stub_code->InvokeDartCodeSize();
103 return (pc >= entry) && (pc < (entry + size)); 66 return (pc >= entry) && (pc < (entry + size));
104 } 67 }
105 68
106 69
107 bool StubCode::InJumpToExceptionHandlerStub(uword pc) { 70 bool StubCode::InJumpToExceptionHandlerStub(uword pc) {
108 uword entry = StubCode::JumpToExceptionHandlerEntryPoint(); 71 uword entry = StubCode::JumpToExceptionHandlerEntryPoint();
109 uword size = StubCode::JumpToExceptionHandlerSize(); 72 uword size = StubCode::JumpToExceptionHandlerSize();
110 return (pc >= entry) && (pc < (entry + size)); 73 return (pc >= entry) && (pc < (entry + size));
111 } 74 }
112 75
113 76
114 RawCode* StubCode::GetAllocateArrayStub() {
115 const Class& array_cls = Class::Handle(isolate_,
116 isolate_->object_store()->array_class());
117 return GetAllocationStubForClass(array_cls);
118 }
119
120
121 RawCode* StubCode::GetAllocationStubForClass(const Class& cls) { 77 RawCode* StubCode::GetAllocationStubForClass(const Class& cls) {
122 Isolate* isolate = Isolate::Current(); 78 Isolate* isolate = Isolate::Current();
123 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate)); 79 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate));
124 ASSERT(error.IsNull()); 80 ASSERT(error.IsNull());
81 if (cls.id() == kArrayCid) {
82 return AllocateArray_entry()->code();
83 }
125 Code& stub = Code::Handle(isolate, cls.allocation_stub()); 84 Code& stub = Code::Handle(isolate, cls.allocation_stub());
126 if (stub.IsNull()) { 85 if (stub.IsNull()) {
127 Assembler assembler; 86 Assembler assembler;
128 const char* name = cls.ToCString(); 87 const char* name = cls.ToCString();
129 uword patch_code_offset = 0; 88 uword patch_code_offset = 0;
130 uword entry_patch_offset = 0; 89 uword entry_patch_offset = 0;
131 if (cls.id() == kArrayCid) { 90 StubCode::GenerateAllocationStubForClass(
132 StubCode::GeneratePatchableAllocateArrayStub( 91 &assembler, cls, &entry_patch_offset, &patch_code_offset);
133 &assembler, &entry_patch_offset, &patch_code_offset);
134 } else {
135 StubCode::GenerateAllocationStubForClass(
136 &assembler, cls, &entry_patch_offset, &patch_code_offset);
137 }
138 stub ^= Code::FinalizeCode(name, &assembler); 92 stub ^= Code::FinalizeCode(name, &assembler);
139 stub.set_owner(cls); 93 stub.set_owner(cls);
140 cls.set_allocation_stub(stub); 94 cls.set_allocation_stub(stub);
141 if (FLAG_disassemble_stubs) { 95 if (FLAG_disassemble_stubs) {
142 LogBlock lb(Isolate::Current()); 96 LogBlock lb(Isolate::Current());
143 ISL_Print("Code for allocation stub '%s': {\n", name); 97 ISL_Print("Code for allocation stub '%s': {\n", name);
144 DisassembleToStdout formatter; 98 DisassembleToStdout formatter;
145 stub.Disassemble(&formatter); 99 stub.Disassemble(&formatter);
146 ISL_Print("}\n"); 100 ISL_Print("}\n");
147 const ObjectPool& object_pool = ObjectPool::Handle( 101 const ObjectPool& object_pool = ObjectPool::Handle(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 return code.raw(); 142 return code.raw();
189 } 143 }
190 144
191 145
192 const char* StubCode::NameOfStub(uword entry_point) { 146 const char* StubCode::NameOfStub(uword entry_point) {
193 #define VM_STUB_CODE_TESTER(name) \ 147 #define VM_STUB_CODE_TESTER(name) \
194 if ((name##_entry() != NULL) && (entry_point == name##EntryPoint())) { \ 148 if ((name##_entry() != NULL) && (entry_point == name##EntryPoint())) { \
195 return ""#name; \ 149 return ""#name; \
196 } 150 }
197 VM_STUB_CODE_LIST(VM_STUB_CODE_TESTER); 151 VM_STUB_CODE_LIST(VM_STUB_CODE_TESTER);
198
199 #define STUB_CODE_TESTER(name) \
200 if ((isolate->stub_code()->name##_entry() != NULL) && \
201 (entry_point == isolate->stub_code()->name##EntryPoint())) { \
202 return ""#name; \
203 }
204 Isolate* isolate = Isolate::Current();
205 if ((isolate != NULL) && (isolate->stub_code() != NULL)) {
206 STUB_CODE_LIST(STUB_CODE_TESTER);
207 }
208 #undef VM_STUB_CODE_TESTER 152 #undef VM_STUB_CODE_TESTER
209 #undef STUB_CODE_TESTER
210 return NULL; 153 return NULL;
211 } 154 }
212 155
213 } // namespace dart 156 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698