| 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/pages.h" | 5 #include "vm/pages.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/compiler_stats.h" | 8 #include "vm/compiler_stats.h" |
| 9 #include "vm/gc_marker.h" | 9 #include "vm/gc_marker.h" |
| 10 #include "vm/gc_sweeper.h" | 10 #include "vm/gc_sweeper.h" |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 page = page->next(); | 377 page = page->next(); |
| 378 } | 378 } |
| 379 page = large_pages_; | 379 page = large_pages_; |
| 380 while (page != NULL) { | 380 while (page != NULL) { |
| 381 page->WriteProtect(read_only); | 381 page->WriteProtect(read_only); |
| 382 page = page->next(); | 382 page = page->next(); |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 | 385 |
| 386 | 386 |
| 387 | |
| 388 class CodeDetacherVisitor : public ObjectVisitor { | 387 class CodeDetacherVisitor : public ObjectVisitor { |
| 389 public: | 388 public: |
| 390 explicit CodeDetacherVisitor(Isolate* isolate) : ObjectVisitor(isolate) { } | 389 explicit CodeDetacherVisitor(Isolate* isolate) : ObjectVisitor(isolate) { } |
| 391 | 390 |
| 392 virtual void VisitObject(RawObject* obj); | 391 virtual void VisitObject(RawObject* obj); |
| 393 | 392 |
| 394 private: | 393 private: |
| 394 static bool MayDetachCode(const Function& fn); |
| 395 DISALLOW_COPY_AND_ASSIGN(CodeDetacherVisitor); | 395 DISALLOW_COPY_AND_ASSIGN(CodeDetacherVisitor); |
| 396 }; | 396 }; |
| 397 | 397 |
| 398 | 398 |
| 399 bool CodeDetacherVisitor::MayDetachCode(const Function& fn) { |
| 400 return fn.HasCode() && // Not already detached. |
| 401 !fn.HasOptimizedCode() && |
| 402 !fn.HasBreakpoint() && |
| 403 (fn.usage_counter() > 0); |
| 404 } |
| 405 |
| 406 |
| 399 void CodeDetacherVisitor::VisitObject(RawObject* raw_obj) { | 407 void CodeDetacherVisitor::VisitObject(RawObject* raw_obj) { |
| 400 Isolate* isolate = Isolate::Current(); | 408 Isolate* isolate = Isolate::Current(); |
| 401 HANDLESCOPE(isolate); | 409 HANDLESCOPE(isolate); |
| 402 const Object& obj = Object::Handle(raw_obj); | 410 const Object& obj = Object::Handle(raw_obj); |
| 403 if (obj.GetClassId() == kFunctionCid) { | 411 if (obj.GetClassId() == kFunctionCid) { |
| 404 const Function& fn = Function::Cast(obj); | 412 const Function& fn = Function::Cast(obj); |
| 405 if (!fn.HasOptimizedCode() && | 413 if (CodeDetacherVisitor::MayDetachCode(fn)) { |
| 406 !fn.HasBreakpoint() && | |
| 407 fn.HasCode() && // Not already detached. | |
| 408 (fn.usage_counter() > 0)) { | |
| 409 fn.set_usage_counter(fn.usage_counter() / 2); | 414 fn.set_usage_counter(fn.usage_counter() / 2); |
| 410 if (fn.usage_counter() == 0) { | 415 if (fn.usage_counter() == 0) { |
| 411 if (FLAG_log_code_drop) { | 416 if (FLAG_log_code_drop) { |
| 412 const String& name = String::Handle(fn.name()); | 417 const String& name = String::Handle(fn.name()); |
| 413 OS::Print("Detaching code for function %s\n", name.ToCString()); | 418 OS::Print("Detaching code for function %s\n", name.ToCString()); |
| 414 } | 419 } |
| 415 fn.DetachCode(); | 420 fn.DetachCode(); |
| 416 } | 421 } |
| 417 } | 422 } |
| 418 } | 423 } |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 return 0; | 655 return 0; |
| 651 } else { | 656 } else { |
| 652 ASSERT(total_time >= gc_time); | 657 ASSERT(total_time >= gc_time); |
| 653 int result= static_cast<int>((static_cast<double>(gc_time) / | 658 int result= static_cast<int>((static_cast<double>(gc_time) / |
| 654 static_cast<double>(total_time)) * 100); | 659 static_cast<double>(total_time)) * 100); |
| 655 return result; | 660 return result; |
| 656 } | 661 } |
| 657 } | 662 } |
| 658 | 663 |
| 659 } // namespace dart | 664 } // namespace dart |
| OLD | NEW |