| 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/globals.h" | 5 #include "platform/globals.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 #include "vm/heap.h" | 10 #include "vm/heap.h" |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // so we allow slightly more than expected. | 229 // so we allow slightly more than expected. |
| 230 static const intptr_t kTolerance = 10 * kWordSize; | 230 static const intptr_t kTolerance = 10 * kWordSize; |
| 231 EXPECT_LE(expected_size, after - before); | 231 EXPECT_LE(expected_size, after - before); |
| 232 EXPECT_GT(expected_size + kTolerance, after - before); | 232 EXPECT_GT(expected_size + kTolerance, after - before); |
| 233 Dart_ExitScope(); | 233 Dart_ExitScope(); |
| 234 } | 234 } |
| 235 | 235 |
| 236 | 236 |
| 237 class FindOnly : public FindObjectVisitor { | 237 class FindOnly : public FindObjectVisitor { |
| 238 public: | 238 public: |
| 239 FindOnly(Isolate* isolate, RawObject* target) | 239 explicit FindOnly(RawObject* target) : target_(target) { |
| 240 : FindObjectVisitor(isolate), target_(target) { | |
| 241 #if defined(DEBUG) | 240 #if defined(DEBUG) |
| 242 EXPECT_GT(Thread::Current()->no_safepoint_scope_depth(), 0); | 241 EXPECT_GT(Thread::Current()->no_safepoint_scope_depth(), 0); |
| 243 #endif | 242 #endif |
| 244 } | 243 } |
| 245 virtual ~FindOnly() { } | 244 virtual ~FindOnly() { } |
| 246 | 245 |
| 247 virtual bool FindObject(RawObject* obj) const { | 246 virtual bool FindObject(RawObject* obj) const { |
| 248 return obj == target_; | 247 return obj == target_; |
| 249 } | 248 } |
| 250 private: | 249 private: |
| 251 RawObject* target_; | 250 RawObject* target_; |
| 252 }; | 251 }; |
| 253 | 252 |
| 254 | 253 |
| 255 class FindNothing : public FindObjectVisitor { | 254 class FindNothing : public FindObjectVisitor { |
| 256 public: | 255 public: |
| 257 FindNothing() : FindObjectVisitor(Isolate::Current()) { } | 256 FindNothing() { } |
| 258 virtual ~FindNothing() { } | 257 virtual ~FindNothing() { } |
| 259 virtual bool FindObject(RawObject* obj) const { return false; } | 258 virtual bool FindObject(RawObject* obj) const { return false; } |
| 260 }; | 259 }; |
| 261 | 260 |
| 262 | 261 |
| 263 TEST_CASE(FindObject) { | 262 TEST_CASE(FindObject) { |
| 264 Isolate* isolate = Isolate::Current(); | 263 Isolate* isolate = Isolate::Current(); |
| 265 Heap* heap = isolate->heap(); | 264 Heap* heap = isolate->heap(); |
| 266 Heap::Space spaces[2] = {Heap::kOld, Heap::kNew}; | 265 Heap::Space spaces[2] = {Heap::kOld, Heap::kNew}; |
| 267 for (size_t space = 0; space < ARRAY_SIZE(spaces); ++space) { | 266 for (size_t space = 0; space < ARRAY_SIZE(spaces); ++space) { |
| 268 const String& obj = String::Handle(String::New("x", spaces[space])); | 267 const String& obj = String::Handle(String::New("x", spaces[space])); |
| 269 { | 268 { |
| 270 NoSafepointScope no_safepoint; | 269 NoSafepointScope no_safepoint; |
| 271 FindOnly find_only(isolate, obj.raw()); | 270 FindOnly find_only(obj.raw()); |
| 272 EXPECT(obj.raw() == heap->FindObject(&find_only)); | 271 EXPECT(obj.raw() == heap->FindObject(&find_only)); |
| 273 } | 272 } |
| 274 } | 273 } |
| 275 { | 274 { |
| 276 NoSafepointScope no_safepoint; | 275 NoSafepointScope no_safepoint; |
| 277 FindNothing find_nothing; | 276 FindNothing find_nothing; |
| 278 EXPECT(Object::null() == heap->FindObject(&find_nothing)); | 277 EXPECT(Object::null() == heap->FindObject(&find_nothing)); |
| 279 } | 278 } |
| 280 } | 279 } |
| 281 | 280 |
| 282 | 281 |
| 283 TEST_CASE(IterateReadOnly) { | 282 TEST_CASE(IterateReadOnly) { |
| 284 const String& obj = String::Handle(String::New("x", Heap::kOld)); | 283 const String& obj = String::Handle(String::New("x", Heap::kOld)); |
| 285 Heap* heap = Thread::Current()->isolate()->heap(); | 284 Heap* heap = Thread::Current()->isolate()->heap(); |
| 286 EXPECT(heap->Contains(RawObject::ToAddr(obj.raw()))); | 285 EXPECT(heap->Contains(RawObject::ToAddr(obj.raw()))); |
| 287 heap->WriteProtect(true, true /* include_code_pages */); | 286 heap->WriteProtect(true, true /* include_code_pages */); |
| 288 EXPECT(heap->Contains(RawObject::ToAddr(obj.raw()))); | 287 EXPECT(heap->Contains(RawObject::ToAddr(obj.raw()))); |
| 289 heap->WriteProtect(false, true /* include_code_pages */); | 288 heap->WriteProtect(false, true /* include_code_pages */); |
| 290 EXPECT(heap->Contains(RawObject::ToAddr(obj.raw()))); | 289 EXPECT(heap->Contains(RawObject::ToAddr(obj.raw()))); |
| 291 } | 290 } |
| 292 | 291 |
| 293 } // namespace dart. | 292 } // namespace dart. |
| OLD | NEW |