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: src/compiler.cc

Issue 871253005: Use weak cells in dependent code. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address comments Created 5 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 | « include/v8.h ('k') | src/heap/heap.h » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 8
9 #include "src/ast-numbering.h" 9 #include "src/ast-numbering.h"
10 #include "src/ast-this-access-visitor.h" 10 #include "src/ast-this-access-visitor.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 // Check that no dependent maps have been added or added dependent maps have 214 // Check that no dependent maps have been added or added dependent maps have
215 // been rolled back or committed. 215 // been rolled back or committed.
216 for (int i = 0; i < DependentCode::kGroupCount; i++) { 216 for (int i = 0; i < DependentCode::kGroupCount; i++) {
217 DCHECK(!dependencies_[i]); 217 DCHECK(!dependencies_[i]);
218 } 218 }
219 #endif // DEBUG 219 #endif // DEBUG
220 } 220 }
221 221
222 222
223 void CompilationInfo::CommitDependencies(Handle<Code> code) { 223 void CompilationInfo::CommitDependencies(Handle<Code> code) {
224 bool has_dependencies = false;
225 for (int i = 0; i < DependentCode::kGroupCount; i++) {
226 has_dependencies |=
227 dependencies_[i] != NULL && dependencies_[i]->length() > 0;
228 }
229 // Avoid creating a weak cell for code with no dependencies.
230 if (!has_dependencies) return;
231
232 AllowDeferredHandleDereference get_object_wrapper;
233 Handle<WeakCell> cell = Code::WeakCellFor(code);
224 for (int i = 0; i < DependentCode::kGroupCount; i++) { 234 for (int i = 0; i < DependentCode::kGroupCount; i++) {
225 ZoneList<Handle<HeapObject> >* group_objects = dependencies_[i]; 235 ZoneList<Handle<HeapObject> >* group_objects = dependencies_[i];
226 if (group_objects == NULL) continue; 236 if (group_objects == NULL) continue;
227 DCHECK(!object_wrapper_.is_null()); 237 DCHECK(!object_wrapper_.is_null());
228 for (int j = 0; j < group_objects->length(); j++) { 238 for (int j = 0; j < group_objects->length(); j++) {
229 DependentCode::DependencyGroup group = 239 DependentCode::DependencyGroup group =
230 static_cast<DependentCode::DependencyGroup>(i); 240 static_cast<DependentCode::DependencyGroup>(i);
231 DependentCode* dependent_code = 241 DependentCode* dependent_code =
232 DependentCode::ForObject(group_objects->at(j), group); 242 DependentCode::ForObject(group_objects->at(j), group);
233 dependent_code->UpdateToFinishedCode(group, this, *code); 243 dependent_code->UpdateToFinishedCode(group, *object_wrapper(), *cell);
234 } 244 }
235 dependencies_[i] = NULL; // Zone-allocated, no need to delete. 245 dependencies_[i] = NULL; // Zone-allocated, no need to delete.
236 } 246 }
237 } 247 }
238 248
239 249
240 void CompilationInfo::RollbackDependencies() { 250 void CompilationInfo::RollbackDependencies() {
251 AllowDeferredHandleDereference get_object_wrapper;
241 // Unregister from all dependent maps if not yet committed. 252 // Unregister from all dependent maps if not yet committed.
242 for (int i = 0; i < DependentCode::kGroupCount; i++) { 253 for (int i = 0; i < DependentCode::kGroupCount; i++) {
243 ZoneList<Handle<HeapObject> >* group_objects = dependencies_[i]; 254 ZoneList<Handle<HeapObject> >* group_objects = dependencies_[i];
244 if (group_objects == NULL) continue; 255 if (group_objects == NULL) continue;
245 for (int j = 0; j < group_objects->length(); j++) { 256 for (int j = 0; j < group_objects->length(); j++) {
246 DependentCode::DependencyGroup group = 257 DependentCode::DependencyGroup group =
247 static_cast<DependentCode::DependencyGroup>(i); 258 static_cast<DependentCode::DependencyGroup>(i);
248 DependentCode* dependent_code = 259 DependentCode* dependent_code =
249 DependentCode::ForObject(group_objects->at(j), group); 260 DependentCode::ForObject(group_objects->at(j), group);
250 dependent_code->RemoveCompilationInfo(group, this); 261 dependent_code->RemoveCompilationInfo(group, *object_wrapper());
251 } 262 }
252 dependencies_[i] = NULL; // Zone-allocated, no need to delete. 263 dependencies_[i] = NULL; // Zone-allocated, no need to delete.
253 } 264 }
254 } 265 }
255 266
256 267
257 int CompilationInfo::num_parameters() const { 268 int CompilationInfo::num_parameters() const {
258 if (IsStub()) { 269 if (IsStub()) {
259 DCHECK(parameter_count_ > 0); 270 DCHECK(parameter_count_ > 0);
260 return parameter_count_; 271 return parameter_count_;
(...skipping 1324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 } 1596 }
1586 1597
1587 1598
1588 #if DEBUG 1599 #if DEBUG
1589 void CompilationInfo::PrintAstForTesting() { 1600 void CompilationInfo::PrintAstForTesting() {
1590 PrintF("--- Source from AST ---\n%s\n", 1601 PrintF("--- Source from AST ---\n%s\n",
1591 PrettyPrinter(isolate(), zone()).PrintProgram(function())); 1602 PrettyPrinter(isolate(), zone()).PrintProgram(function()));
1592 } 1603 }
1593 #endif 1604 #endif
1594 } } // namespace v8::internal 1605 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/heap/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698