| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 StackZone stack_zone(thread); | 122 StackZone stack_zone(thread); |
| 123 HANDLESCOPE(thread); | 123 HANDLESCOPE(thread); |
| 124 Zone* zone = thread->zone(); | 124 Zone* zone = thread->zone(); |
| 125 EXPECT_EQ(zone, stack_zone.GetZone()); | 125 EXPECT_EQ(zone, stack_zone.GetZone()); |
| 126 ZoneGrowableArray<bool>* a0 = new(zone) ZoneGrowableArray<bool>(zone, 1); | 126 ZoneGrowableArray<bool>* a0 = new(zone) ZoneGrowableArray<bool>(zone, 1); |
| 127 GrowableArray<bool> a1(zone, 1); | 127 GrowableArray<bool> a1(zone, 1); |
| 128 for (intptr_t i = 0; i < 100000; ++i) { | 128 for (intptr_t i = 0; i < 100000; ++i) { |
| 129 a0->Add(true); | 129 a0->Add(true); |
| 130 a1.Add(true); | 130 a1.Add(true); |
| 131 } | 131 } |
| 132 // Check that we can create handles (but not yet allocate heap objects). | 132 // Check that we can create handles and allocate in old space. |
| 133 String& str = String::Handle(zone, foo_.raw()); | 133 String& str = String::Handle(zone, String::New("old", Heap::kOld)); |
| 134 EXPECT(str.Equals("foo")); | 134 EXPECT(str.Equals("old")); |
| 135 |
| 135 const intptr_t unique_smi = id_ + 928327281; | 136 const intptr_t unique_smi = id_ + 928327281; |
| 136 Smi& smi = Smi::Handle(zone, Smi::New(unique_smi)); | 137 Smi& smi = Smi::Handle(zone, Smi::New(unique_smi)); |
| 137 EXPECT(smi.Value() == unique_smi); | 138 EXPECT(smi.Value() == unique_smi); |
| 138 ObjectCounter counter(isolate_, &smi); | 139 ObjectCounter counter(isolate_, &smi); |
| 139 // Ensure that our particular zone is visited. | 140 // Ensure that our particular zone is visited. |
| 140 // TODO(koda): Remove "->thread_registry()" after updating stack walker. | 141 // TODO(koda): Remove "->thread_registry()" after updating stack walker. |
| 141 isolate_->thread_registry()->VisitObjectPointers(&counter); | 142 isolate_->thread_registry()->VisitObjectPointers(&counter); |
| 142 EXPECT_EQ(1, counter.count()); | 143 EXPECT_EQ(1, counter.count()); |
| 144 |
| 145 char* unique_chars = zone->PrintToString("unique_str_%" Pd, id_); |
| 146 String& unique_str = String::Handle(zone); |
| 147 { |
| 148 // String::New may create additional handles in the topmost scope that |
| 149 // we don't want to count, so wrap this in its own scope. |
| 150 HANDLESCOPE(thread); |
| 151 unique_str = String::New(unique_chars, Heap::kOld); |
| 152 } |
| 153 EXPECT(unique_str.Equals(unique_chars)); |
| 154 ObjectCounter str_counter(isolate_, &unique_str); |
| 155 // Ensure that our particular zone is visited. |
| 156 // TODO(koda): Remove "->thread_registry()" after updating stack walker. |
| 157 isolate_->thread_registry()->VisitObjectPointers(&str_counter); |
| 158 // We should visit the string object exactly once. |
| 159 EXPECT_EQ(1, str_counter.count()); |
| 143 } | 160 } |
| 144 Thread::ExitIsolateAsHelper(); | 161 Thread::ExitIsolateAsHelper(); |
| 145 { | 162 { |
| 146 MonitorLocker ml(monitor_); | 163 MonitorLocker ml(monitor_); |
| 147 *done_ = true; | 164 *done_ = true; |
| 148 ml.Notify(); | 165 ml.Notify(); |
| 149 } | 166 } |
| 150 } | 167 } |
| 151 | 168 |
| 152 private: | 169 private: |
| 153 Isolate* isolate_; | 170 Isolate* isolate_; |
| 154 const String& foo_; | 171 const String& foo_; |
| 155 Monitor* monitor_; | 172 Monitor* monitor_; |
| 156 bool* done_; | 173 bool* done_; |
| 157 intptr_t id_; | 174 intptr_t id_; |
| 158 }; | 175 }; |
| 159 | 176 |
| 160 | 177 |
| 161 TEST_CASE(ManyTasksWithZones) { | 178 TEST_CASE(ManyTasksWithZones) { |
| 162 const int kTaskCount = 100; | 179 const int kTaskCount = 100; |
| 163 Monitor sync[kTaskCount]; | 180 Monitor sync[kTaskCount]; |
| 164 bool done[kTaskCount]; | 181 bool done[kTaskCount]; |
| 165 Isolate* isolate = Thread::Current()->isolate(); | 182 Isolate* isolate = Thread::Current()->isolate(); |
| 166 String& foo = String::Handle(String::New("foo")); | 183 String& foo = String::Handle(String::New("foo")); |
| 167 | 184 EXPECT(isolate->heap()->GrowthControlState()); |
| 185 isolate->heap()->DisableGrowthControl(); |
| 168 for (int i = 0; i < kTaskCount; i++) { | 186 for (int i = 0; i < kTaskCount; i++) { |
| 169 done[i] = false; | 187 done[i] = false; |
| 170 Dart::thread_pool()->Run( | 188 Dart::thread_pool()->Run( |
| 171 new TaskWithZoneAllocation(isolate, foo, &sync[i], &done[i], i)); | 189 new TaskWithZoneAllocation(isolate, foo, &sync[i], &done[i], i)); |
| 172 } | 190 } |
| 173 for (int i = 0; i < kTaskCount; i++) { | 191 for (int i = 0; i < kTaskCount; i++) { |
| 174 // Check that main mutator thread can still freely use its own zone. | 192 // Check that main mutator thread can still freely use its own zone. |
| 175 String& bar = String::Handle(String::New("bar")); | 193 String& bar = String::Handle(String::New("bar")); |
| 176 if (i % 10 == 0) { | 194 if (i % 10 == 0) { |
| 177 // Mutator thread is free to independently move in/out/between isolates. | 195 // Mutator thread is free to independently move in/out/between isolates. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 Thread::ExitIsolate(); | 236 Thread::ExitIsolate(); |
| 219 Thread::EnterIsolate(orig); | 237 Thread::EnterIsolate(orig); |
| 220 // Original zone should be preserved. | 238 // Original zone should be preserved. |
| 221 EXPECT_EQ(orig_zone, Thread::Current()->zone()); | 239 EXPECT_EQ(orig_zone, Thread::Current()->zone()); |
| 222 EXPECT_STREQ("foo", orig_str); | 240 EXPECT_STREQ("foo", orig_str); |
| 223 delete isos[0]; | 241 delete isos[0]; |
| 224 delete isos[1]; | 242 delete isos[1]; |
| 225 } | 243 } |
| 226 | 244 |
| 227 } // namespace dart | 245 } // namespace dart |
| OLD | NEW |