OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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/dart_api_state.h" | 5 #include "vm/dart_api_state.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/heap.h" | 9 #include "vm/heap.h" |
10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
11 #include "vm/lockers.h" | 11 #include "vm/lockers.h" |
12 #include "vm/thread.h" | 12 #include "vm/thread.h" |
13 #include "vm/timeline.h" | 13 #include "vm/timeline.h" |
14 | 14 |
15 namespace dart { | 15 namespace dart { |
16 | 16 |
17 intptr_t ApiNativeScope::current_memory_usage_ = 0; | 17 intptr_t ApiNativeScope::current_memory_usage_ = 0; |
18 | 18 |
19 BackgroundFinalizer::BackgroundFinalizer(Isolate* isolate, | |
20 FinalizationQueue* queue) | |
21 : isolate_(isolate), queue_(queue) { | |
22 ASSERT(FLAG_background_finalization); | |
23 PageSpace* old_space = isolate->heap()->old_space(); | |
24 MonitorLocker ml(old_space->tasks_lock()); | |
25 old_space->set_tasks(old_space->tasks() + 1); | |
26 } | |
27 | |
28 | |
29 void BackgroundFinalizer::Run() { | |
30 bool result = Thread::EnterIsolateAsHelper(isolate_, Thread::kFinalizerTask); | |
31 ASSERT(result); | |
32 | |
33 { | |
34 Thread* thread = Thread::Current(); | |
35 TIMELINE_FUNCTION_GC_DURATION(thread, "BackgroundFinalization"); | |
36 TransitionVMToNative transition(thread); | |
37 for (intptr_t i = 0; i < queue_->length(); i++) { | |
38 FinalizablePersistentHandle* handle = (*queue_)[i]; | |
39 FinalizablePersistentHandle::Finalize(isolate_, handle); | |
40 } | |
41 delete queue_; | |
42 } | |
43 | |
44 // Exit isolate cleanly *before* notifying it, to avoid shutdown race. | |
45 Thread::ExitIsolateAsHelper(); | |
46 | |
47 { | |
48 PageSpace* old_space = isolate_->heap()->old_space(); | |
49 MonitorLocker ml(old_space->tasks_lock()); | |
50 old_space->set_tasks(old_space->tasks() - 1); | |
51 ml.NotifyAll(); | |
52 } | |
53 } | |
54 | |
55 } // namespace dart | 19 } // namespace dart |
OLD | NEW |