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

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

Issue 1710443003: Fix background compilation: allocate stubs at safepoint (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Comments Created 4 years, 10 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
« no previous file with comments | « runtime/vm/compiler.cc ('k') | runtime/vm/virtual_memory_android.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/snapshot.h" 14 #include "vm/snapshot.h"
14 #include "vm/virtual_memory.h" 15 #include "vm/virtual_memory.h"
15 #include "vm/visitor.h" 16 #include "vm/visitor.h"
16 17
17 namespace dart { 18 namespace dart {
18 19
19 DEFINE_FLAG(bool, disassemble_stubs, false, "Disassemble generated stubs."); 20 DEFINE_FLAG(bool, disassemble_stubs, false, "Disassemble generated stubs.");
20 21
21 #define STUB_CODE_DECLARE(name) \ 22 #define STUB_CODE_DECLARE(name) \
22 StubEntry* StubCode::name##_entry_ = NULL; 23 StubEntry* StubCode::name##_entry_ = NULL;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 const Error& error = Error::Handle(zone, cls.EnsureIsFinalized(thread)); 114 const Error& error = Error::Handle(zone, cls.EnsureIsFinalized(thread));
114 ASSERT(error.IsNull()); 115 ASSERT(error.IsNull());
115 if (cls.id() == kArrayCid) { 116 if (cls.id() == kArrayCid) {
116 return AllocateArray_entry()->code(); 117 return AllocateArray_entry()->code();
117 } 118 }
118 Code& stub = Code::Handle(zone, cls.allocation_stub()); 119 Code& stub = Code::Handle(zone, cls.allocation_stub());
119 if (stub.IsNull()) { 120 if (stub.IsNull()) {
120 Assembler assembler; 121 Assembler assembler;
121 const char* name = cls.ToCString(); 122 const char* name = cls.ToCString();
122 StubCode::GenerateAllocationStubForClass(&assembler, cls); 123 StubCode::GenerateAllocationStubForClass(&assembler, cls);
123 stub ^= Code::FinalizeCode(name, &assembler, false /* optimized */); 124
124 stub.set_owner(cls); 125 if (thread->IsMutatorThread()) {
125 cls.set_allocation_stub(stub); 126 stub ^= Code::FinalizeCode(name, &assembler, false /* optimized */);
127 stub.set_owner(cls);
128 cls.set_allocation_stub(stub);
129 } else {
130 // This part of stub code generation must be at a safepoint.
131 // Stop mutator thread before creating the instruction object and
132 // installing code.
133 // Mutator thread may not run code while we are creating the
134 // instruction object, since the creation of instruction object
135 // changes code page access permissions (makes them temporary not
136 // executable).
137 {
138 SafepointOperationScope safepoint_scope(thread);
139 // Do not Garbage collect during this stage and instead allow the
140 // heap to grow.
141 NoHeapGrowthControlScope no_growth_control;
142 stub ^= Code::FinalizeCode(name, &assembler, false /* optimized */);
143 stub.set_owner(cls);
144 cls.set_allocation_stub(stub);
145 }
146 Isolate* isolate = thread->isolate();
147 if (isolate->heap()->NeedsGarbageCollection()) {
148 isolate->heap()->CollectAllGarbage();
149 }
150 }
126 if (FLAG_support_disassembler && FLAG_disassemble_stubs) { 151 if (FLAG_support_disassembler && FLAG_disassemble_stubs) {
127 LogBlock lb; 152 LogBlock lb;
128 THR_Print("Code for allocation stub '%s': {\n", name); 153 THR_Print("Code for allocation stub '%s': {\n", name);
129 #ifndef PRODUCT 154 #ifndef PRODUCT
130 DisassembleToStdout formatter; 155 DisassembleToStdout formatter;
131 stub.Disassemble(&formatter); 156 stub.Disassemble(&formatter);
132 #endif 157 #endif
133 THR_Print("}\n"); 158 THR_Print("}\n");
134 const ObjectPool& object_pool = ObjectPool::Handle(stub.object_pool()); 159 const ObjectPool& object_pool = ObjectPool::Handle(stub.object_pool());
135 object_pool.DebugPrint(); 160 object_pool.DebugPrint();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 if ((name##_entry() != NULL) && \ 204 if ((name##_entry() != NULL) && \
180 (entry_point == name##_entry()->EntryPoint())) { \ 205 (entry_point == name##_entry()->EntryPoint())) { \
181 return ""#name; \ 206 return ""#name; \
182 } 207 }
183 VM_STUB_CODE_LIST(VM_STUB_CODE_TESTER); 208 VM_STUB_CODE_LIST(VM_STUB_CODE_TESTER);
184 #undef VM_STUB_CODE_TESTER 209 #undef VM_STUB_CODE_TESTER
185 return NULL; 210 return NULL;
186 } 211 }
187 212
188 } // namespace dart 213 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/compiler.cc ('k') | runtime/vm/virtual_memory_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698