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_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
6 #define VM_OBJECT_H_ | 6 #define VM_OBJECT_H_ |
7 | 7 |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/utils.h" | 10 #include "platform/utils.h" |
11 #include "vm/bitmap.h" | 11 #include "vm/bitmap.h" |
12 #include "vm/dart.h" | 12 #include "vm/dart.h" |
13 #include "vm/globals.h" | 13 #include "vm/globals.h" |
14 #include "vm/handles.h" | 14 #include "vm/handles.h" |
15 #include "vm/heap.h" | 15 #include "vm/heap.h" |
16 #include "vm/isolate.h" | 16 #include "vm/isolate.h" |
17 #include "vm/os.h" | 17 #include "vm/os.h" |
18 #include "vm/raw_object.h" | 18 #include "vm/raw_object.h" |
19 #include "vm/scanner.h" | 19 #include "vm/scanner.h" |
20 | 20 |
21 namespace dart { | 21 namespace dart { |
22 | 22 |
23 // Forward declarations. | 23 // Forward declarations. |
24 #define DEFINE_FORWARD_DECLARATION(clazz) \ | 24 #define DEFINE_FORWARD_DECLARATION(clazz) \ |
25 class clazz; | 25 class clazz; |
26 CLASS_LIST(DEFINE_FORWARD_DECLARATION) | 26 CLASS_LIST(DEFINE_FORWARD_DECLARATION) |
27 #undef DEFINE_FORWARD_DECLARATION | 27 #undef DEFINE_FORWARD_DECLARATION |
28 class Api; | 28 class Api; |
29 class Assembler; | 29 class Assembler; |
30 class Closure; | |
30 class Code; | 31 class Code; |
31 class LocalScope; | 32 class LocalScope; |
32 class Symbols; | 33 class Symbols; |
33 | 34 |
34 #define OBJECT_IMPLEMENTATION(object, super) \ | 35 #define OBJECT_IMPLEMENTATION(object, super) \ |
35 public: /* NOLINT */ \ | 36 public: /* NOLINT */ \ |
36 Raw##object* raw() const { return reinterpret_cast<Raw##object*>(raw_); } \ | 37 Raw##object* raw() const { return reinterpret_cast<Raw##object*>(raw_); } \ |
37 void operator=(Raw##object* value) { \ | 38 void operator=(Raw##object* value) { \ |
38 initializeHandle(this, value); \ | 39 initializeHandle(this, value); \ |
39 } \ | 40 } \ |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 static RawClass* context_scope_class_; // Class of ContextScope vm object. | 415 static RawClass* context_scope_class_; // Class of ContextScope vm object. |
415 static RawClass* icdata_class_; // Class of ICData. | 416 static RawClass* icdata_class_; // Class of ICData. |
416 static RawClass* subtypetestcache_class_; // Class of SubtypeTestCache. | 417 static RawClass* subtypetestcache_class_; // Class of SubtypeTestCache. |
417 static RawClass* api_error_class_; // Class of ApiError. | 418 static RawClass* api_error_class_; // Class of ApiError. |
418 static RawClass* language_error_class_; // Class of LanguageError. | 419 static RawClass* language_error_class_; // Class of LanguageError. |
419 static RawClass* unhandled_exception_class_; // Class of UnhandledException. | 420 static RawClass* unhandled_exception_class_; // Class of UnhandledException. |
420 static RawClass* unwind_error_class_; // Class of UnwindError. | 421 static RawClass* unwind_error_class_; // Class of UnwindError. |
421 | 422 |
422 friend void ClassTable::Register(const Class& cls); | 423 friend void ClassTable::Register(const Class& cls); |
423 friend void RawObject::Validate(Isolate* isolate) const; | 424 friend void RawObject::Validate(Isolate* isolate) const; |
425 friend class Closure; | |
424 friend class SnapshotReader; | 426 friend class SnapshotReader; |
425 | 427 |
426 // Disallow allocation. | 428 // Disallow allocation. |
427 void* operator new(size_t size); | 429 void* operator new(size_t size); |
428 // Disallow copy constructor. | 430 // Disallow copy constructor. |
429 DISALLOW_COPY_AND_ASSIGN(Object); | 431 DISALLOW_COPY_AND_ASSIGN(Object); |
430 }; | 432 }; |
431 | 433 |
432 | 434 |
433 class Class : public Object { | 435 class Class : public Object { |
(...skipping 2564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2998 } | 3000 } |
2999 | 3001 |
3000 intptr_t GetNativeField(int index) const { | 3002 intptr_t GetNativeField(int index) const { |
3001 return *NativeFieldAddr(index); | 3003 return *NativeFieldAddr(index); |
3002 } | 3004 } |
3003 | 3005 |
3004 void SetNativeField(int index, intptr_t value) const { | 3006 void SetNativeField(int index, intptr_t value) const { |
3005 *NativeFieldAddr(index) = value; | 3007 *NativeFieldAddr(index) = value; |
3006 } | 3008 } |
3007 | 3009 |
3010 // Returns true if the instance is a closure object. | |
3011 bool IsClosure() const; | |
3012 | |
3008 static intptr_t InstanceSize() { | 3013 static intptr_t InstanceSize() { |
3009 return RoundedAllocationSize(sizeof(RawInstance)); | 3014 return RoundedAllocationSize(sizeof(RawInstance)); |
3010 } | 3015 } |
3011 | 3016 |
3012 static RawInstance* New(const Class& cls, Heap::Space space = Heap::kNew); | 3017 static RawInstance* New(const Class& cls, Heap::Space space = Heap::kNew); |
3013 | 3018 |
3014 private: | 3019 private: |
3015 RawObject** FieldAddrAtOffset(intptr_t offset) const { | 3020 RawObject** FieldAddrAtOffset(intptr_t offset) const { |
3016 ASSERT(IsValidFieldOffset(offset)); | 3021 ASSERT(IsValidFieldOffset(offset)); |
3017 return reinterpret_cast<RawObject**>(raw_value() - kHeapObjectTag + offset); | 3022 return reinterpret_cast<RawObject**>(raw_value() - kHeapObjectTag + offset); |
3018 } | 3023 } |
3019 RawObject** FieldAddr(const Field& field) const { | 3024 RawObject** FieldAddr(const Field& field) const { |
3020 return FieldAddrAtOffset(field.Offset()); | 3025 return FieldAddrAtOffset(field.Offset()); |
3021 } | 3026 } |
3022 intptr_t* NativeFieldAddr(int index) const { | 3027 intptr_t* NativeFieldAddr(int index) const { |
3023 ASSERT(IsValidNativeIndex(index)); | 3028 ASSERT(IsValidNativeIndex(index)); |
3024 return reinterpret_cast<intptr_t*>((raw_value() - kHeapObjectTag) | 3029 return reinterpret_cast<intptr_t*>((raw_value() - kHeapObjectTag) |
3025 + (index * kWordSize) | 3030 + (index * kWordSize) |
3026 + sizeof(RawObject)); | 3031 + sizeof(RawObject)); |
3027 } | 3032 } |
3028 void SetFieldAtOffset(intptr_t offset, const Object& value) const { | 3033 void SetFieldAtOffset(intptr_t offset, const Object& value) const { |
3029 StorePointer(FieldAddrAtOffset(offset), value.raw()); | 3034 StorePointer(FieldAddrAtOffset(offset), value.raw()); |
3030 } | 3035 } |
3031 bool IsValidFieldOffset(int offset) const; | 3036 bool IsValidFieldOffset(int offset) const; |
3032 | 3037 |
3033 // TODO(iposva): Determine if this gets in the way of Smi. | 3038 // TODO(iposva): Determine if this gets in the way of Smi. |
3034 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); | 3039 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); |
3035 friend class Class; | 3040 friend class Class; |
3041 friend class Closure; | |
3036 }; | 3042 }; |
3037 | 3043 |
3038 | 3044 |
3039 // AbstractType is an abstract superclass. | 3045 // AbstractType is an abstract superclass. |
3040 // Subclasses of AbstractType are Type and TypeParameter. | 3046 // Subclasses of AbstractType are Type and TypeParameter. |
3041 class AbstractType : public Instance { | 3047 class AbstractType : public Instance { |
3042 public: | 3048 public: |
3043 virtual bool IsFinalized() const; | 3049 virtual bool IsFinalized() const; |
3044 virtual bool IsBeingFinalized() const; | 3050 virtual bool IsBeingFinalized() const; |
3045 virtual bool IsMalformed() const; | 3051 virtual bool IsMalformed() const; |
(...skipping 2398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5444 | 5450 |
5445 // DartFunction represents the abstract Dart class 'Function'. | 5451 // DartFunction represents the abstract Dart class 'Function'. |
5446 class DartFunction : public Instance { | 5452 class DartFunction : public Instance { |
5447 private: | 5453 private: |
5448 HEAP_OBJECT_IMPLEMENTATION(DartFunction, Instance); | 5454 HEAP_OBJECT_IMPLEMENTATION(DartFunction, Instance); |
5449 friend class Class; | 5455 friend class Class; |
5450 friend class Instance; | 5456 friend class Instance; |
5451 }; | 5457 }; |
5452 | 5458 |
5453 | 5459 |
5454 class Closure : public Instance { | 5460 class Closure : public AllStatic { |
5455 public: | 5461 public: |
5456 RawFunction* function() const { return raw_ptr()->function_; } | 5462 static RawFunction* function(const Instance& closure) { |
5463 return *FunctionAddr(closure); | |
Ivan Posva
2012/10/11 04:04:22
ASSERT(closure.IsClosure());
siva
2012/10/11 17:45:58
Done.
| |
5464 } | |
5457 static intptr_t function_offset() { | 5465 static intptr_t function_offset() { |
5458 return OFFSET_OF(RawClosure, function_); | 5466 return static_cast<intptr_t>(kFunctionOffset * kWordSize); |
5459 } | 5467 } |
5460 | 5468 |
5461 RawContext* context() const { return raw_ptr()->context_; } | 5469 static RawContext* context(const Instance& closure) { |
5462 static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); } | 5470 return *ContextAddr(closure); |
Ivan Posva
2012/10/11 04:04:22
ditto: ASSERT
siva
2012/10/11 17:45:58
Done.
| |
5471 } | |
5472 static intptr_t context_offset() { | |
5473 return static_cast<intptr_t>(kContextOffset * kWordSize); | |
5474 } | |
5463 | 5475 |
5464 virtual RawAbstractTypeArguments* GetTypeArguments() const { | 5476 static RawAbstractTypeArguments* GetTypeArguments(const Instance& closure) { |
5465 return raw_ptr()->type_arguments_; | 5477 return *TypeArgumentsAddr(closure); |
5466 } | 5478 } |
5467 virtual void SetTypeArguments(const AbstractTypeArguments& value) const { | 5479 static void SetTypeArguments(const Instance& closure, |
5468 StorePointer(&raw_ptr()->type_arguments_, value.raw()); | 5480 const AbstractTypeArguments& value) { |
5481 closure.StorePointer(TypeArgumentsAddr(closure), value.raw()); | |
5469 } | 5482 } |
5470 static intptr_t type_arguments_offset() { | 5483 static intptr_t type_arguments_offset() { |
5471 return OFFSET_OF(RawClosure, type_arguments_); | 5484 return static_cast<intptr_t>(kTypeArgumentsOffset * kWordSize); |
5472 } | 5485 } |
5473 | 5486 |
5474 // TODO(iposva): Remove smrck support once mapping to arbitrary is available. | |
5475 RawInteger* smrck() const { return raw_ptr()->smrck_; } | |
5476 void set_smrck(const Integer& smrck) const { | |
5477 StorePointer(&raw_ptr()->smrck_, smrck.raw()); | |
5478 } | |
5479 static intptr_t smrck_offset() { return OFFSET_OF(RawClosure, smrck_); } | |
5480 | |
5481 static intptr_t InstanceSize() { | 5487 static intptr_t InstanceSize() { |
5482 return RoundedAllocationSize(sizeof(RawClosure)); | 5488 intptr_t size = sizeof(RawInstance) + (kNumFields * kWordSize); |
5489 ASSERT(size == Object::RoundedAllocationSize(size)); | |
5490 return size; | |
5483 } | 5491 } |
5484 | 5492 |
5485 static RawClosure* New(const Function& function, | 5493 static RawInstance* New(const Function& function, |
5486 const Context& context, | 5494 const Context& context, |
5487 Heap::Space space = Heap::kNew); | 5495 Heap::Space space = Heap::kNew); |
5488 | 5496 |
5489 private: | 5497 private: |
5490 void set_function(const Function& value) const; | 5498 static const int kTypeArgumentsOffset = 1; |
5491 void set_context(const Context& value) const; | 5499 static const int kFunctionOffset = 2; |
5500 static const int kContextOffset = 3; | |
5501 static const int kNumFields = 3; | |
5492 | 5502 |
5493 HEAP_OBJECT_IMPLEMENTATION(Closure, Instance); | 5503 static RawAbstractTypeArguments** TypeArgumentsAddr(const Instance& obj) { |
5504 return reinterpret_cast<RawAbstractTypeArguments**>( | |
Ivan Posva
2012/10/11 04:04:22
Actually the ASSERTs might make more sense here.
siva
2012/10/11 17:45:58
Done.
| |
5505 reinterpret_cast<intptr_t>(obj.raw_ptr()) + type_arguments_offset()); | |
5506 } | |
5507 static RawFunction** FunctionAddr(const Instance& obj) { | |
5508 return reinterpret_cast<RawFunction**>( | |
5509 reinterpret_cast<intptr_t>(obj.raw_ptr()) + function_offset()); | |
5510 } | |
5511 static RawContext** ContextAddr(const Instance& obj) { | |
5512 return reinterpret_cast<RawContext**>( | |
5513 reinterpret_cast<intptr_t>(obj.raw_ptr()) + context_offset()); | |
5514 } | |
5515 static void set_function(const Instance& closure, | |
5516 const Function& value) { | |
5517 closure.StorePointer(FunctionAddr(closure), value.raw()); | |
5518 } | |
5519 static void set_context(const Instance& closure, | |
5520 const Context& value) { | |
5521 closure.StorePointer(ContextAddr(closure), value.raw()); | |
5522 } | |
5523 | |
5494 friend class Class; | 5524 friend class Class; |
5495 }; | 5525 }; |
5496 | 5526 |
5497 | 5527 |
5498 // Internal stacktrace object used in exceptions for printing stack traces. | 5528 // Internal stacktrace object used in exceptions for printing stack traces. |
5499 class Stacktrace : public Instance { | 5529 class Stacktrace : public Instance { |
5500 public: | 5530 public: |
5501 intptr_t Length() const; | 5531 intptr_t Length() const; |
5502 RawFunction* FunctionAtFrame(intptr_t frame_index) const; | 5532 RawFunction* FunctionAtFrame(intptr_t frame_index) const; |
5503 RawCode* CodeAtFrame(intptr_t frame_index) const; | 5533 RawCode* CodeAtFrame(intptr_t frame_index) const; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5674 } | 5704 } |
5675 #endif | 5705 #endif |
5676 intptr_t cid = raw_->GetClassId(); | 5706 intptr_t cid = raw_->GetClassId(); |
5677 if (cid < kNumPredefinedCids) { | 5707 if (cid < kNumPredefinedCids) { |
5678 #if defined(DEBUG) | 5708 #if defined(DEBUG) |
5679 ASSERT(builtin_vtables_[cid] == | 5709 ASSERT(builtin_vtables_[cid] == |
5680 isolate->class_table()->At(cid)->ptr()->handle_vtable_); | 5710 isolate->class_table()->At(cid)->ptr()->handle_vtable_); |
5681 #endif | 5711 #endif |
5682 set_vtable(builtin_vtables_[cid]); | 5712 set_vtable(builtin_vtables_[cid]); |
5683 } else { | 5713 } else { |
5684 #if !defined(DEBUG) | 5714 set_vtable(builtin_vtables_[kInstanceCid]); |
5685 Isolate* isolate = Isolate::Current(); | |
5686 #endif | |
5687 RawClass* raw_class = isolate->class_table()->At(cid); | |
5688 set_vtable(raw_class->ptr()->handle_vtable_); | |
5689 } | 5715 } |
5690 } | 5716 } |
5691 | 5717 |
5692 | 5718 |
5693 bool Function::HasCode() const { | 5719 bool Function::HasCode() const { |
5694 return raw_ptr()->code_ != Code::null(); | 5720 return raw_ptr()->code_ != Code::null(); |
5695 } | 5721 } |
5696 | 5722 |
5697 | 5723 |
5698 intptr_t Field::Offset() const { | 5724 intptr_t Field::Offset() const { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5737 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5763 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
5738 return false; | 5764 return false; |
5739 } | 5765 } |
5740 } | 5766 } |
5741 return true; | 5767 return true; |
5742 } | 5768 } |
5743 | 5769 |
5744 } // namespace dart | 5770 } // namespace dart |
5745 | 5771 |
5746 #endif // VM_OBJECT_H_ | 5772 #endif // VM_OBJECT_H_ |
OLD | NEW |