| 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 "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/isolate.h" | 6 #include "vm/isolate.h" |
| 7 #include "vm/lockers.h" | 7 #include "vm/lockers.h" |
| 8 #include "vm/unit_test.h" | 8 #include "vm/unit_test.h" |
| 9 #include "vm/profiler.h" | 9 #include "vm/profiler.h" |
| 10 #include "vm/thread_pool.h" | 10 #include "vm/thread_pool.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 102 |
| 103 private: | 103 private: |
| 104 const Object* obj_; | 104 const Object* obj_; |
| 105 intptr_t count_; | 105 intptr_t count_; |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 | 108 |
| 109 class TaskWithZoneAllocation : public ThreadPool::Task { | 109 class TaskWithZoneAllocation : public ThreadPool::Task { |
| 110 public: | 110 public: |
| 111 TaskWithZoneAllocation(Isolate* isolate, | 111 TaskWithZoneAllocation(Isolate* isolate, |
| 112 const String& foo, | |
| 113 Monitor* monitor, | 112 Monitor* monitor, |
| 114 bool* done, | 113 bool* done, |
| 115 intptr_t id) | 114 intptr_t id) |
| 116 : isolate_(isolate), foo_(foo), monitor_(monitor), done_(done), id_(id) {} | 115 : isolate_(isolate), monitor_(monitor), done_(done), id_(id) {} |
| 117 virtual void Run() { | 116 virtual void Run() { |
| 118 Thread::EnterIsolateAsHelper(isolate_); | 117 Thread::EnterIsolateAsHelper(isolate_); |
| 119 { | 118 { |
| 120 Thread* thread = Thread::Current(); | 119 Thread* thread = Thread::Current(); |
| 121 // Create a zone (which is also a stack resource) and exercise it a bit. | 120 // Create a zone (which is also a stack resource) and exercise it a bit. |
| 122 StackZone stack_zone(thread); | 121 StackZone stack_zone(thread); |
| 123 HANDLESCOPE(thread); | 122 HANDLESCOPE(thread); |
| 124 Zone* zone = thread->zone(); | 123 Zone* zone = thread->zone(); |
| 125 EXPECT_EQ(zone, stack_zone.GetZone()); | 124 EXPECT_EQ(zone, stack_zone.GetZone()); |
| 126 ZoneGrowableArray<bool>* a0 = new(zone) ZoneGrowableArray<bool>(zone, 1); | 125 ZoneGrowableArray<bool>* a0 = new(zone) ZoneGrowableArray<bool>(zone, 1); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 Thread::ExitIsolateAsHelper(); | 160 Thread::ExitIsolateAsHelper(); |
| 162 { | 161 { |
| 163 MonitorLocker ml(monitor_); | 162 MonitorLocker ml(monitor_); |
| 164 *done_ = true; | 163 *done_ = true; |
| 165 ml.Notify(); | 164 ml.Notify(); |
| 166 } | 165 } |
| 167 } | 166 } |
| 168 | 167 |
| 169 private: | 168 private: |
| 170 Isolate* isolate_; | 169 Isolate* isolate_; |
| 171 const String& foo_; | |
| 172 Monitor* monitor_; | 170 Monitor* monitor_; |
| 173 bool* done_; | 171 bool* done_; |
| 174 intptr_t id_; | 172 intptr_t id_; |
| 175 }; | 173 }; |
| 176 | 174 |
| 177 | 175 |
| 178 TEST_CASE(ManyTasksWithZones) { | 176 TEST_CASE(ManyTasksWithZones) { |
| 179 const int kTaskCount = 100; | 177 const int kTaskCount = 100; |
| 180 Monitor sync[kTaskCount]; | 178 Monitor sync[kTaskCount]; |
| 181 bool done[kTaskCount]; | 179 bool done[kTaskCount]; |
| 182 Isolate* isolate = Thread::Current()->isolate(); | 180 Isolate* isolate = Thread::Current()->isolate(); |
| 183 String& foo = String::Handle(String::New("foo")); | |
| 184 EXPECT(isolate->heap()->GrowthControlState()); | 181 EXPECT(isolate->heap()->GrowthControlState()); |
| 185 isolate->heap()->DisableGrowthControl(); | 182 isolate->heap()->DisableGrowthControl(); |
| 186 for (int i = 0; i < kTaskCount; i++) { | 183 for (int i = 0; i < kTaskCount; i++) { |
| 187 done[i] = false; | 184 done[i] = false; |
| 188 Dart::thread_pool()->Run( | 185 Dart::thread_pool()->Run( |
| 189 new TaskWithZoneAllocation(isolate, foo, &sync[i], &done[i], i)); | 186 new TaskWithZoneAllocation(isolate, &sync[i], &done[i], i)); |
| 190 } | 187 } |
| 191 for (int i = 0; i < kTaskCount; i++) { | 188 for (int i = 0; i < kTaskCount; i++) { |
| 192 // Check that main mutator thread can still freely use its own zone. | 189 // Check that main mutator thread can still freely use its own zone. |
| 193 String& bar = String::Handle(String::New("bar")); | 190 String& bar = String::Handle(String::New("bar")); |
| 194 if (i % 10 == 0) { | 191 if (i % 10 == 0) { |
| 195 // Mutator thread is free to independently move in/out/between isolates. | 192 // Mutator thread is free to independently move in/out/between isolates. |
| 196 Thread::ExitIsolate(); | 193 Thread::ExitIsolate(); |
| 197 } | 194 } |
| 198 MonitorLocker ml(&sync[i]); | 195 MonitorLocker ml(&sync[i]); |
| 199 while (!done[i]) { | 196 while (!done[i]) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 Thread::ExitIsolate(); | 233 Thread::ExitIsolate(); |
| 237 Thread::EnterIsolate(orig); | 234 Thread::EnterIsolate(orig); |
| 238 // Original zone should be preserved. | 235 // Original zone should be preserved. |
| 239 EXPECT_EQ(orig_zone, Thread::Current()->zone()); | 236 EXPECT_EQ(orig_zone, Thread::Current()->zone()); |
| 240 EXPECT_STREQ("foo", orig_str); | 237 EXPECT_STREQ("foo", orig_str); |
| 241 delete isos[0]; | 238 delete isos[0]; |
| 242 delete isos[1]; | 239 delete isos[1]; |
| 243 } | 240 } |
| 244 | 241 |
| 245 } // namespace dart | 242 } // namespace dart |
| OLD | NEW |