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 #ifndef VM_DART_API_STATE_H_ | 5 #ifndef VM_DART_API_STATE_H_ |
6 #define VM_DART_API_STATE_H_ | 6 #define VM_DART_API_STATE_H_ |
7 | 7 |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 | 9 |
10 #include "platform/utils.h" | 10 #include "platform/utils.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 RawObject** raw_addr() { return &raw_; } | 206 RawObject** raw_addr() { return &raw_; } |
207 static intptr_t raw_offset() { | 207 static intptr_t raw_offset() { |
208 return OFFSET_OF(FinalizablePersistentHandle, raw_); | 208 return OFFSET_OF(FinalizablePersistentHandle, raw_); |
209 } | 209 } |
210 void* peer() const { return peer_; } | 210 void* peer() const { return peer_; } |
211 Dart_WeakPersistentHandleFinalizer callback() const { return callback_; } | 211 Dart_WeakPersistentHandleFinalizer callback() const { return callback_; } |
212 Dart_WeakPersistentHandle apiHandle() { | 212 Dart_WeakPersistentHandle apiHandle() { |
213 return reinterpret_cast<Dart_WeakPersistentHandle>(this); | 213 return reinterpret_cast<Dart_WeakPersistentHandle>(this); |
214 } | 214 } |
215 | 215 |
| 216 intptr_t external_size() const { |
| 217 return ExternalSizeBits::decode(external_data_); |
| 218 } |
| 219 |
216 void SetExternalSize(intptr_t size, Isolate* isolate) { | 220 void SetExternalSize(intptr_t size, Isolate* isolate) { |
217 ASSERT(size >= 0); | 221 ASSERT(size >= 0); |
218 set_external_size(Utils::RoundUp(size, kObjectAlignment)); | 222 set_external_size(Utils::RoundUp(size, kObjectAlignment)); |
219 if (SpaceForExternal() == Heap::kNew) { | 223 if (SpaceForExternal() == Heap::kNew) { |
220 SetExternalNewSpaceBit(); | 224 SetExternalNewSpaceBit(); |
221 } | 225 } |
222 isolate->heap()->AllocateExternal(external_size(), SpaceForExternal()); | 226 isolate->heap()->AllocateExternal(external_size(), SpaceForExternal()); |
223 } | 227 } |
224 | 228 |
225 // Called when the referent becomes unreachable. | 229 // Called when the referent becomes unreachable. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 void set_raw(RawObject* raw) { raw_ = raw; } | 302 void set_raw(RawObject* raw) { raw_ = raw; } |
299 void set_raw(const LocalHandle& ref) { raw_ = ref.raw(); } | 303 void set_raw(const LocalHandle& ref) { raw_ = ref.raw(); } |
300 void set_raw(const Object& object) { raw_ = object.raw(); } | 304 void set_raw(const Object& object) { raw_ = object.raw(); } |
301 | 305 |
302 void set_peer(void* peer) { peer_ = peer; } | 306 void set_peer(void* peer) { peer_ = peer; } |
303 | 307 |
304 void set_callback(Dart_WeakPersistentHandleFinalizer callback) { | 308 void set_callback(Dart_WeakPersistentHandleFinalizer callback) { |
305 callback_ = callback; | 309 callback_ = callback; |
306 } | 310 } |
307 | 311 |
308 intptr_t external_size() const { | |
309 return ExternalSizeBits::decode(external_data_); | |
310 } | |
311 | |
312 void set_external_size(intptr_t size) { | 312 void set_external_size(intptr_t size) { |
313 ASSERT(ExternalSizeBits::is_valid(size)); | 313 ASSERT(ExternalSizeBits::is_valid(size)); |
314 external_data_ = ExternalSizeBits::update(size, external_data_); | 314 external_data_ = ExternalSizeBits::update(size, external_data_); |
315 } | 315 } |
316 | 316 |
317 bool IsSetNewSpaceBit() const { | 317 bool IsSetNewSpaceBit() const { |
318 return ExternalNewSpaceBit::decode(external_data_); | 318 return ExternalNewSpaceBit::decode(external_data_); |
319 } | 319 } |
320 | 320 |
321 void SetExternalNewSpaceBit() { | 321 void SetExternalNewSpaceBit() { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 PersistentHandle* free_list() const { return free_list_; } | 438 PersistentHandle* free_list() const { return free_list_; } |
439 void set_free_list(PersistentHandle* value) { free_list_ = value; } | 439 void set_free_list(PersistentHandle* value) { free_list_ = value; } |
440 | 440 |
441 // Visit all object pointers stored in the various handles. | 441 // Visit all object pointers stored in the various handles. |
442 void VisitObjectPointers(ObjectPointerVisitor* visitor) { | 442 void VisitObjectPointers(ObjectPointerVisitor* visitor) { |
443 Handles<kPersistentHandleSizeInWords, | 443 Handles<kPersistentHandleSizeInWords, |
444 kPersistentHandlesPerChunk, | 444 kPersistentHandlesPerChunk, |
445 kOffsetOfRawPtrInPersistentHandle>::VisitObjectPointers(visitor); | 445 kOffsetOfRawPtrInPersistentHandle>::VisitObjectPointers(visitor); |
446 } | 446 } |
447 | 447 |
| 448 // Visit all the handles. |
| 449 void Visit(HandleVisitor* visitor) { |
| 450 Handles<kPersistentHandleSizeInWords, |
| 451 kPersistentHandlesPerChunk, |
| 452 kOffsetOfRawPtrInPersistentHandle>::Visit(visitor); |
| 453 } |
| 454 |
448 // Allocates a persistent handle, these have to be destroyed explicitly | 455 // Allocates a persistent handle, these have to be destroyed explicitly |
449 // by calling FreeHandle. | 456 // by calling FreeHandle. |
450 PersistentHandle* AllocateHandle() { | 457 PersistentHandle* AllocateHandle() { |
451 PersistentHandle* handle; | 458 PersistentHandle* handle; |
452 if (free_list_ != NULL) { | 459 if (free_list_ != NULL) { |
453 handle = free_list_; | 460 handle = free_list_; |
454 free_list_ = handle->Next(); | 461 free_list_ = handle->Next(); |
455 } else { | 462 } else { |
456 handle = reinterpret_cast<PersistentHandle*>(AllocateScopedHandle()); | 463 handle = reinterpret_cast<PersistentHandle*>(AllocateScopedHandle()); |
457 } | 464 } |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 ref->set_peer(peer); | 762 ref->set_peer(peer); |
756 ref->set_callback(callback); | 763 ref->set_callback(callback); |
757 // This may trigger GC, so it must be called last. | 764 // This may trigger GC, so it must be called last. |
758 ref->SetExternalSize(external_size, isolate); | 765 ref->SetExternalSize(external_size, isolate); |
759 return ref; | 766 return ref; |
760 } | 767 } |
761 | 768 |
762 } // namespace dart | 769 } // namespace dart |
763 | 770 |
764 #endif // VM_DART_API_STATE_H_ | 771 #endif // VM_DART_API_STATE_H_ |
OLD | NEW |