| 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 "vm/handles.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/dart_api_state.h" | 9 #include "vm/dart_api_state.h" |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| 11 #include "vm/os.h" | 11 #include "vm/os.h" |
| 12 #include "vm/raw_object.h" | 12 #include "vm/raw_object.h" |
| 13 #include "vm/visitor.h" | 13 #include "vm/visitor.h" |
| 14 #include "vm/zone.h" | 14 #include "vm/zone.h" |
| 15 | 15 |
| 16 #include "vm/handles_impl.h" | 16 #include "vm/handles_impl.h" |
| 17 | 17 |
| 18 namespace dart { | 18 namespace dart { |
| 19 | 19 |
| 20 DEFINE_FLAG(bool, verify_handles, false, "Verify handles."); | 20 DEFINE_FLAG(bool, verify_handles, false, "Verify handles."); |
| 21 | 21 |
| 22 | 22 |
| 23 VMHandles::~VMHandles() { | 23 VMHandles::~VMHandles() { |
| 24 if (FLAG_trace_handles) { | 24 if (FLAG_trace_handles) { |
| 25 OS::PrintErr("*** Handle Counts for 0x(%" Px | 25 OS::PrintErr("*** Handle Counts for 0x(%" Px "):Zone = %d,Scoped = %d\n", |
| 26 "):Zone = %d,Scoped = %d\n", | 26 reinterpret_cast<intptr_t>(this), CountZoneHandles(), |
| 27 reinterpret_cast<intptr_t>(this), | 27 CountScopedHandles()); |
| 28 CountZoneHandles(), CountScopedHandles()); | 28 OS::PrintErr("*** Deleting VM handle block 0x%" Px "\n", |
| 29 OS::PrintErr("*** Deleting VM handle block 0x%" Px "\n", | 29 reinterpret_cast<intptr_t>(this)); |
| 30 reinterpret_cast<intptr_t>(this)); | 30 } |
| 31 } | |
| 32 } | 31 } |
| 33 | 32 |
| 34 | 33 |
| 35 void VMHandles::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 34 void VMHandles::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 36 return Handles<kVMHandleSizeInWords, | 35 return Handles<kVMHandleSizeInWords, kVMHandlesPerChunk, |
| 37 kVMHandlesPerChunk, | |
| 38 kOffsetOfRawPtr>::VisitObjectPointers(visitor); | 36 kOffsetOfRawPtr>::VisitObjectPointers(visitor); |
| 39 } | 37 } |
| 40 | 38 |
| 41 | 39 |
| 42 #if defined(DEBUG) | 40 #if defined(DEBUG) |
| 43 static bool IsCurrentApiNativeScope(Zone* zone) { | 41 static bool IsCurrentApiNativeScope(Zone* zone) { |
| 44 ApiNativeScope* scope = ApiNativeScope::Current(); | 42 ApiNativeScope* scope = ApiNativeScope::Current(); |
| 45 return (scope != NULL) && (scope->zone() == zone); | 43 return (scope != NULL) && (scope->zone() == zone); |
| 46 } | 44 } |
| 47 #endif // DEBUG | 45 #endif // DEBUG |
| 48 | 46 |
| 49 | 47 |
| 50 uword VMHandles::AllocateHandle(Zone* zone) { | 48 uword VMHandles::AllocateHandle(Zone* zone) { |
| 51 DEBUG_ASSERT(!IsCurrentApiNativeScope(zone)); | 49 DEBUG_ASSERT(!IsCurrentApiNativeScope(zone)); |
| 52 return Handles<kVMHandleSizeInWords, | 50 return Handles<kVMHandleSizeInWords, kVMHandlesPerChunk, |
| 53 kVMHandlesPerChunk, | |
| 54 kOffsetOfRawPtr>::AllocateHandle(zone); | 51 kOffsetOfRawPtr>::AllocateHandle(zone); |
| 55 } | 52 } |
| 56 | 53 |
| 57 | 54 |
| 58 uword VMHandles::AllocateZoneHandle(Zone* zone) { | 55 uword VMHandles::AllocateZoneHandle(Zone* zone) { |
| 59 DEBUG_ASSERT(!IsCurrentApiNativeScope(zone)); | 56 DEBUG_ASSERT(!IsCurrentApiNativeScope(zone)); |
| 60 return Handles<kVMHandleSizeInWords, | 57 return Handles<kVMHandleSizeInWords, kVMHandlesPerChunk, |
| 61 kVMHandlesPerChunk, | |
| 62 kOffsetOfRawPtr>::AllocateZoneHandle(zone); | 58 kOffsetOfRawPtr>::AllocateZoneHandle(zone); |
| 63 } | 59 } |
| 64 | 60 |
| 65 | 61 |
| 66 bool VMHandles::IsZoneHandle(uword handle) { | 62 bool VMHandles::IsZoneHandle(uword handle) { |
| 67 return Handles<kVMHandleSizeInWords, | 63 return Handles<kVMHandleSizeInWords, kVMHandlesPerChunk, |
| 68 kVMHandlesPerChunk, | 64 kOffsetOfRawPtr>::IsZoneHandle(handle); |
| 69 kOffsetOfRawPtr >::IsZoneHandle(handle); | |
| 70 } | 65 } |
| 71 | 66 |
| 72 | 67 |
| 73 int VMHandles::ScopedHandleCount() { | 68 int VMHandles::ScopedHandleCount() { |
| 74 Thread* thread = Thread::Current(); | 69 Thread* thread = Thread::Current(); |
| 75 ASSERT(thread->zone() != NULL); | 70 ASSERT(thread->zone() != NULL); |
| 76 VMHandles* handles = thread->zone()->handles(); | 71 VMHandles* handles = thread->zone()->handles(); |
| 77 return handles->CountScopedHandles(); | 72 return handles->CountScopedHandles(); |
| 78 } | 73 } |
| 79 | 74 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 thread->IncrementNoHandleScopeDepth(); | 119 thread->IncrementNoHandleScopeDepth(); |
| 125 } | 120 } |
| 126 | 121 |
| 127 | 122 |
| 128 NoHandleScope::~NoHandleScope() { | 123 NoHandleScope::~NoHandleScope() { |
| 129 thread()->DecrementNoHandleScopeDepth(); | 124 thread()->DecrementNoHandleScopeDepth(); |
| 130 } | 125 } |
| 131 #endif // defined(DEBUG) | 126 #endif // defined(DEBUG) |
| 132 | 127 |
| 133 } // namespace dart | 128 } // namespace dart |
| OLD | NEW |