| 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/handles.h" |
| 5 #include "platform/assert.h" | 6 #include "platform/assert.h" |
| 6 #include "vm/dart_api_state.h" | 7 #include "vm/dart_api_state.h" |
| 7 #include "vm/flags.h" | 8 #include "vm/flags.h" |
| 8 #include "vm/handles.h" | |
| 9 #include "vm/heap.h" | 9 #include "vm/heap.h" |
| 10 #include "vm/object.h" | 10 #include "vm/object.h" |
| 11 #include "vm/unit_test.h" | 11 #include "vm/unit_test.h" |
| 12 #include "vm/zone.h" | 12 #include "vm/zone.h" |
| 13 | 13 |
| 14 namespace dart { | 14 namespace dart { |
| 15 | 15 |
| 16 // Unit test for Zone handle allocation. | 16 // Unit test for Zone handle allocation. |
| 17 TEST_CASE(AllocateZoneHandle) { | 17 TEST_CASE(AllocateZoneHandle) { |
| 18 #if defined(DEBUG) | 18 #if defined(DEBUG) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 30 EXPECT_EQ(kNumHandles + initial_count, VMHandles::ZoneHandleCount()); | 30 EXPECT_EQ(kNumHandles + initial_count, VMHandles::ZoneHandleCount()); |
| 31 // Create some more zone handles. | 31 // Create some more zone handles. |
| 32 for (int i = kNumHandles; i < (2 * kNumHandles); i++) { | 32 for (int i = kNumHandles; i < (2 * kNumHandles); i++) { |
| 33 const Smi& handle = Smi::ZoneHandle(Smi::New(i)); | 33 const Smi& handle = Smi::ZoneHandle(Smi::New(i)); |
| 34 EXPECT(handle.IsSmi()); | 34 EXPECT(handle.IsSmi()); |
| 35 EXPECT_EQ(i, handle.Value()); | 35 EXPECT_EQ(i, handle.Value()); |
| 36 } | 36 } |
| 37 EXPECT_EQ((2 * kNumHandles) + initial_count, VMHandles::ZoneHandleCount()); | 37 EXPECT_EQ((2 * kNumHandles) + initial_count, VMHandles::ZoneHandleCount()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 | |
| 41 // Unit test for Scope handle allocation. | 40 // Unit test for Scope handle allocation. |
| 42 TEST_CASE(AllocateScopeHandle) { | 41 TEST_CASE(AllocateScopeHandle) { |
| 43 #if defined(DEBUG) | 42 #if defined(DEBUG) |
| 44 FLAG_trace_handles = true; | 43 FLAG_trace_handles = true; |
| 45 #endif | 44 #endif |
| 46 int32_t handle_count = VMHandles::ScopedHandleCount(); | 45 int32_t handle_count = VMHandles::ScopedHandleCount(); |
| 47 static const int kNumHandles = 65; | 46 static const int kNumHandles = 65; |
| 48 // Create some scoped handles. | 47 // Create some scoped handles. |
| 49 { | 48 { |
| 50 Thread* thread = Thread::Current(); | 49 Thread* thread = Thread::Current(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 71 const Smi& handle = Smi::Handle(Smi::New(i)); | 70 const Smi& handle = Smi::Handle(Smi::New(i)); |
| 72 EXPECT(handle.IsSmi()); | 71 EXPECT(handle.IsSmi()); |
| 73 EXPECT_EQ(i, handle.Value()); | 72 EXPECT_EQ(i, handle.Value()); |
| 74 } | 73 } |
| 75 EXPECT_EQ((handle_count + (2 * kNumHandles)), | 74 EXPECT_EQ((handle_count + (2 * kNumHandles)), |
| 76 VMHandles::ScopedHandleCount()); | 75 VMHandles::ScopedHandleCount()); |
| 77 } | 76 } |
| 78 EXPECT_EQ(handle_count, VMHandles::ScopedHandleCount()); | 77 EXPECT_EQ(handle_count, VMHandles::ScopedHandleCount()); |
| 79 } | 78 } |
| 80 | 79 |
| 81 | |
| 82 static void NoopCallback(void* isolate_callback_data, | 80 static void NoopCallback(void* isolate_callback_data, |
| 83 Dart_WeakPersistentHandle handle, | 81 Dart_WeakPersistentHandle handle, |
| 84 void* peer) {} | 82 void* peer) {} |
| 85 | 83 |
| 86 | |
| 87 // Unit test for handle validity checks. | 84 // Unit test for handle validity checks. |
| 88 TEST_CASE(CheckHandleValidity) { | 85 TEST_CASE(CheckHandleValidity) { |
| 89 #if defined(DEBUG) | 86 #if defined(DEBUG) |
| 90 FLAG_trace_handles = true; | 87 FLAG_trace_handles = true; |
| 91 #endif | 88 #endif |
| 92 Thread* current = Thread::Current(); | 89 Thread* current = Thread::Current(); |
| 93 Dart_Handle handle = NULL; | 90 Dart_Handle handle = NULL; |
| 94 // Check validity using zone handles. | 91 // Check validity using zone handles. |
| 95 { | 92 { |
| 96 StackZone sz(current); | 93 StackZone sz(current); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 125 EXPECT_NOTNULL(handle); | 122 EXPECT_NOTNULL(handle); |
| 126 EXPECT_VALID(handle); | 123 EXPECT_VALID(handle); |
| 127 | 124 |
| 128 Dart_DeleteWeakPersistentHandle( | 125 Dart_DeleteWeakPersistentHandle( |
| 129 reinterpret_cast<Dart_Isolate>(isolate), | 126 reinterpret_cast<Dart_Isolate>(isolate), |
| 130 reinterpret_cast<Dart_WeakPersistentHandle>(handle)); | 127 reinterpret_cast<Dart_WeakPersistentHandle>(handle)); |
| 131 EXPECT(!Api::IsValid(handle)); | 128 EXPECT(!Api::IsValid(handle)); |
| 132 } | 129 } |
| 133 | 130 |
| 134 } // namespace dart | 131 } // namespace dart |
| OLD | NEW |