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" |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 406 |
407 static const Array& empty_array() { | 407 static const Array& empty_array() { |
408 ASSERT(empty_array_ != NULL); | 408 ASSERT(empty_array_ != NULL); |
409 return *empty_array_; | 409 return *empty_array_; |
410 } | 410 } |
411 static const Array& zero_array() { | 411 static const Array& zero_array() { |
412 ASSERT(zero_array_ != NULL); | 412 ASSERT(zero_array_ != NULL); |
413 return *zero_array_; | 413 return *zero_array_; |
414 } | 414 } |
415 | 415 |
| 416 static const ObjectPool& empty_object_pool() { |
| 417 ASSERT(empty_object_pool_ != NULL); |
| 418 return *empty_object_pool_; |
| 419 } |
| 420 |
416 static const PcDescriptors& empty_descriptors() { | 421 static const PcDescriptors& empty_descriptors() { |
417 ASSERT(empty_descriptors_ != NULL); | 422 ASSERT(empty_descriptors_ != NULL); |
418 return *empty_descriptors_; | 423 return *empty_descriptors_; |
419 } | 424 } |
420 | 425 |
421 static const LocalVarDescriptors& empty_var_descriptors() { | 426 static const LocalVarDescriptors& empty_var_descriptors() { |
422 ASSERT(empty_var_descriptors_ != NULL); | 427 ASSERT(empty_var_descriptors_ != NULL); |
423 return *empty_var_descriptors_; | 428 return *empty_var_descriptors_; |
424 } | 429 } |
425 | 430 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 static RawClass* closure_data_class() { return closure_data_class_; } | 508 static RawClass* closure_data_class() { return closure_data_class_; } |
504 static RawClass* redirection_data_class() { return redirection_data_class_; } | 509 static RawClass* redirection_data_class() { return redirection_data_class_; } |
505 static RawClass* field_class() { return field_class_; } | 510 static RawClass* field_class() { return field_class_; } |
506 static RawClass* literal_token_class() { return literal_token_class_; } | 511 static RawClass* literal_token_class() { return literal_token_class_; } |
507 static RawClass* token_stream_class() { return token_stream_class_; } | 512 static RawClass* token_stream_class() { return token_stream_class_; } |
508 static RawClass* script_class() { return script_class_; } | 513 static RawClass* script_class() { return script_class_; } |
509 static RawClass* library_class() { return library_class_; } | 514 static RawClass* library_class() { return library_class_; } |
510 static RawClass* namespace_class() { return namespace_class_; } | 515 static RawClass* namespace_class() { return namespace_class_; } |
511 static RawClass* code_class() { return code_class_; } | 516 static RawClass* code_class() { return code_class_; } |
512 static RawClass* instructions_class() { return instructions_class_; } | 517 static RawClass* instructions_class() { return instructions_class_; } |
| 518 static RawClass* object_pool_class() { return object_pool_class_; } |
513 static RawClass* pc_descriptors_class() { return pc_descriptors_class_; } | 519 static RawClass* pc_descriptors_class() { return pc_descriptors_class_; } |
514 static RawClass* stackmap_class() { return stackmap_class_; } | 520 static RawClass* stackmap_class() { return stackmap_class_; } |
515 static RawClass* var_descriptors_class() { return var_descriptors_class_; } | 521 static RawClass* var_descriptors_class() { return var_descriptors_class_; } |
516 static RawClass* exception_handlers_class() { | 522 static RawClass* exception_handlers_class() { |
517 return exception_handlers_class_; | 523 return exception_handlers_class_; |
518 } | 524 } |
519 static RawClass* deopt_info_class() { return deopt_info_class_; } | 525 static RawClass* deopt_info_class() { return deopt_info_class_; } |
520 static RawClass* context_class() { return context_class_; } | 526 static RawClass* context_class() { return context_class_; } |
521 static RawClass* context_scope_class() { return context_scope_class_; } | 527 static RawClass* context_scope_class() { return context_scope_class_; } |
522 static RawClass* api_error_class() { return api_error_class_; } | 528 static RawClass* api_error_class() { return api_error_class_; } |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 static RawClass* closure_data_class_; // Class of ClosureData vm obj. | 767 static RawClass* closure_data_class_; // Class of ClosureData vm obj. |
762 static RawClass* redirection_data_class_; // Class of RedirectionData vm obj. | 768 static RawClass* redirection_data_class_; // Class of RedirectionData vm obj. |
763 static RawClass* field_class_; // Class of the Field vm object. | 769 static RawClass* field_class_; // Class of the Field vm object. |
764 static RawClass* literal_token_class_; // Class of LiteralToken vm object. | 770 static RawClass* literal_token_class_; // Class of LiteralToken vm object. |
765 static RawClass* token_stream_class_; // Class of the TokenStream vm object. | 771 static RawClass* token_stream_class_; // Class of the TokenStream vm object. |
766 static RawClass* script_class_; // Class of the Script vm object. | 772 static RawClass* script_class_; // Class of the Script vm object. |
767 static RawClass* library_class_; // Class of the Library vm object. | 773 static RawClass* library_class_; // Class of the Library vm object. |
768 static RawClass* namespace_class_; // Class of Namespace vm object. | 774 static RawClass* namespace_class_; // Class of Namespace vm object. |
769 static RawClass* code_class_; // Class of the Code vm object. | 775 static RawClass* code_class_; // Class of the Code vm object. |
770 static RawClass* instructions_class_; // Class of the Instructions vm object. | 776 static RawClass* instructions_class_; // Class of the Instructions vm object. |
| 777 static RawClass* object_pool_class_; // Class of the ObjectPool vm object. |
771 static RawClass* pc_descriptors_class_; // Class of PcDescriptors vm object. | 778 static RawClass* pc_descriptors_class_; // Class of PcDescriptors vm object. |
772 static RawClass* stackmap_class_; // Class of Stackmap vm object. | 779 static RawClass* stackmap_class_; // Class of Stackmap vm object. |
773 static RawClass* var_descriptors_class_; // Class of LocalVarDescriptors. | 780 static RawClass* var_descriptors_class_; // Class of LocalVarDescriptors. |
774 static RawClass* exception_handlers_class_; // Class of ExceptionHandlers. | 781 static RawClass* exception_handlers_class_; // Class of ExceptionHandlers. |
775 static RawClass* deopt_info_class_; // Class of DeoptInfo. | 782 static RawClass* deopt_info_class_; // Class of DeoptInfo. |
776 static RawClass* context_class_; // Class of the Context vm object. | 783 static RawClass* context_class_; // Class of the Context vm object. |
777 static RawClass* context_scope_class_; // Class of ContextScope vm object. | 784 static RawClass* context_scope_class_; // Class of ContextScope vm object. |
778 static RawClass* icdata_class_; // Class of ICData. | 785 static RawClass* icdata_class_; // Class of ICData. |
779 static RawClass* megamorphic_cache_class_; // Class of MegamorphiCache. | 786 static RawClass* megamorphic_cache_class_; // Class of MegamorphiCache. |
780 static RawClass* subtypetestcache_class_; // Class of SubtypeTestCache. | 787 static RawClass* subtypetestcache_class_; // Class of SubtypeTestCache. |
781 static RawClass* api_error_class_; // Class of ApiError. | 788 static RawClass* api_error_class_; // Class of ApiError. |
782 static RawClass* language_error_class_; // Class of LanguageError. | 789 static RawClass* language_error_class_; // Class of LanguageError. |
783 static RawClass* unhandled_exception_class_; // Class of UnhandledException. | 790 static RawClass* unhandled_exception_class_; // Class of UnhandledException. |
784 static RawClass* unwind_error_class_; // Class of UnwindError. | 791 static RawClass* unwind_error_class_; // Class of UnwindError. |
785 | 792 |
786 // The static values below are read-only handle pointers for singleton | 793 // The static values below are read-only handle pointers for singleton |
787 // objects that are shared between the different isolates. | 794 // objects that are shared between the different isolates. |
788 static Object* null_object_; | 795 static Object* null_object_; |
789 static Array* null_array_; | 796 static Array* null_array_; |
790 static String* null_string_; | 797 static String* null_string_; |
791 static Instance* null_instance_; | 798 static Instance* null_instance_; |
792 static TypeArguments* null_type_arguments_; | 799 static TypeArguments* null_type_arguments_; |
793 static Array* empty_array_; | 800 static Array* empty_array_; |
794 static Array* zero_array_; | 801 static Array* zero_array_; |
| 802 static ObjectPool* empty_object_pool_; |
795 static PcDescriptors* empty_descriptors_; | 803 static PcDescriptors* empty_descriptors_; |
796 static LocalVarDescriptors* empty_var_descriptors_; | 804 static LocalVarDescriptors* empty_var_descriptors_; |
797 static ExceptionHandlers* empty_exception_handlers_; | 805 static ExceptionHandlers* empty_exception_handlers_; |
798 static Array* extractor_parameter_types_; | 806 static Array* extractor_parameter_types_; |
799 static Array* extractor_parameter_names_; | 807 static Array* extractor_parameter_names_; |
800 static Instance* sentinel_; | 808 static Instance* sentinel_; |
801 static Instance* transition_sentinel_; | 809 static Instance* transition_sentinel_; |
802 static Instance* unknown_constant_; | 810 static Instance* unknown_constant_; |
803 static Instance* non_constant_; | 811 static Instance* non_constant_; |
804 static Bool* bool_true_; | 812 static Bool* bool_true_; |
(...skipping 2683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3488 static RawNamespace* New(); | 3496 static RawNamespace* New(); |
3489 | 3497 |
3490 RawField* metadata_field() const { return raw_ptr()->metadata_field_; } | 3498 RawField* metadata_field() const { return raw_ptr()->metadata_field_; } |
3491 void set_metadata_field(const Field& value) const; | 3499 void set_metadata_field(const Field& value) const; |
3492 | 3500 |
3493 FINAL_HEAP_OBJECT_IMPLEMENTATION(Namespace, Object); | 3501 FINAL_HEAP_OBJECT_IMPLEMENTATION(Namespace, Object); |
3494 friend class Class; | 3502 friend class Class; |
3495 }; | 3503 }; |
3496 | 3504 |
3497 | 3505 |
| 3506 class ObjectPool : public Object { |
| 3507 public: |
| 3508 enum EntryType { |
| 3509 kTaggedObject, |
| 3510 kImmediate, |
| 3511 kExternalLabel, |
| 3512 }; |
| 3513 |
| 3514 struct Entry { |
| 3515 Entry() : raw_value_(), type_() { } |
| 3516 explicit Entry(const Object* obj) : obj_(obj), type_(kTaggedObject) { } |
| 3517 Entry(uword value, EntryType info) : raw_value_(value), type_(info) { } |
| 3518 union { |
| 3519 const Object* obj_; |
| 3520 uword raw_value_; |
| 3521 }; |
| 3522 EntryType type_; |
| 3523 }; |
| 3524 |
| 3525 intptr_t Length() const { |
| 3526 return raw_ptr()->length_; |
| 3527 } |
| 3528 void SetLength(intptr_t value) const { |
| 3529 StoreNonPointer(&raw_ptr()->length_, value); |
| 3530 } |
| 3531 |
| 3532 RawTypedData* info_array() const { |
| 3533 return raw_ptr()->info_array_; |
| 3534 } |
| 3535 |
| 3536 void set_info_array(const TypedData& info_array) const; |
| 3537 |
| 3538 static intptr_t length_offset() { return OFFSET_OF(RawObjectPool, length_); } |
| 3539 static intptr_t data_offset() { |
| 3540 return OFFSET_OF_RETURNED_VALUE(RawObjectPool, data); |
| 3541 } |
| 3542 static intptr_t element_offset(intptr_t index) { |
| 3543 return OFFSET_OF_RETURNED_VALUE(RawObjectPool, data) |
| 3544 + kBytesPerElement * index; |
| 3545 } |
| 3546 |
| 3547 EntryType InfoAt(intptr_t index) const; |
| 3548 void SetInfoAt(intptr_t index, EntryType info) const; |
| 3549 |
| 3550 RawObject* ObjectAt(intptr_t index) const { |
| 3551 ASSERT(InfoAt(index) == kTaggedObject); |
| 3552 return EntryAddr(index)->raw_obj_; |
| 3553 } |
| 3554 void SetObjectAt(intptr_t index, const Object& obj) const { |
| 3555 ASSERT(InfoAt(index) == kTaggedObject); |
| 3556 StorePointer(&EntryAddr(index)->raw_obj_, obj.raw()); |
| 3557 } |
| 3558 |
| 3559 uword RawValueAt(intptr_t index) const { |
| 3560 ASSERT(InfoAt(index) != kTaggedObject); |
| 3561 return EntryAddr(index)->raw_value_; |
| 3562 } |
| 3563 void SetRawValueAt(intptr_t index, uword raw_value) const { |
| 3564 ASSERT(InfoAt(index) != kTaggedObject); |
| 3565 StoreNonPointer(&EntryAddr(index)->raw_value_, raw_value); |
| 3566 } |
| 3567 |
| 3568 static intptr_t InstanceSize() { |
| 3569 ASSERT(sizeof(RawObjectPool) == |
| 3570 OFFSET_OF_RETURNED_VALUE(RawObjectPool, data)); |
| 3571 return 0; |
| 3572 } |
| 3573 |
| 3574 static const intptr_t kBytesPerElement = sizeof(RawObjectPool::Entry); |
| 3575 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 3576 |
| 3577 static intptr_t InstanceSize(intptr_t len) { |
| 3578 // Ensure that variable length data is not adding to the object length. |
| 3579 ASSERT(sizeof(RawObjectPool) == (sizeof(RawObject) + (2 * kWordSize))); |
| 3580 ASSERT(0 <= len && len <= kMaxElements); |
| 3581 return RoundedAllocationSize( |
| 3582 sizeof(RawObjectPool) + (len * kBytesPerElement)); |
| 3583 } |
| 3584 |
| 3585 static RawObjectPool* New(intptr_t len); |
| 3586 |
| 3587 static intptr_t IndexFromOffset(intptr_t offset) { |
| 3588 return (offset + kHeapObjectTag - data_offset()) / kBytesPerElement; |
| 3589 } |
| 3590 |
| 3591 void DebugPrint() const; |
| 3592 |
| 3593 private: |
| 3594 RawObjectPool::Entry const* EntryAddr(intptr_t index) const { |
| 3595 ASSERT((index >= 0) && (index < Length())); |
| 3596 return &raw_ptr()->data()[index]; |
| 3597 } |
| 3598 |
| 3599 FINAL_HEAP_OBJECT_IMPLEMENTATION(ObjectPool, Object); |
| 3600 friend class Class; |
| 3601 friend class Object; |
| 3602 friend class RawObjectPool; |
| 3603 }; |
| 3604 |
| 3605 |
3498 class Instructions : public Object { | 3606 class Instructions : public Object { |
3499 public: | 3607 public: |
3500 intptr_t size() const { return raw_ptr()->size_; } // Excludes HeaderSize(). | 3608 intptr_t size() const { return raw_ptr()->size_; } // Excludes HeaderSize(). |
3501 RawCode* code() const { return raw_ptr()->code_; } | 3609 RawCode* code() const { return raw_ptr()->code_; } |
3502 static intptr_t code_offset() { | 3610 static intptr_t code_offset() { |
3503 return OFFSET_OF(RawInstructions, code_); | 3611 return OFFSET_OF(RawInstructions, code_); |
3504 } | 3612 } |
3505 RawArray* object_pool() const { return raw_ptr()->object_pool_; } | 3613 RawObjectPool* object_pool() const { return raw_ptr()->object_pool_; } |
3506 static intptr_t object_pool_offset() { | 3614 static intptr_t object_pool_offset() { |
3507 return OFFSET_OF(RawInstructions, object_pool_); | 3615 return OFFSET_OF(RawInstructions, object_pool_); |
3508 } | 3616 } |
3509 | 3617 |
3510 uword EntryPoint() const { | 3618 uword EntryPoint() const { |
3511 return reinterpret_cast<uword>(raw_ptr()) + HeaderSize(); | 3619 return reinterpret_cast<uword>(raw_ptr()) + HeaderSize(); |
3512 } | 3620 } |
3513 | 3621 |
3514 static const intptr_t kMaxElements = (kMaxInt32 - | 3622 static const intptr_t kMaxElements = (kMaxInt32 - |
3515 (sizeof(RawInstructions) + | 3623 (sizeof(RawInstructions) + |
(...skipping 24 matching lines...) Expand all Loading... |
3540 entry_point - HeaderSize() + kHeapObjectTag); | 3648 entry_point - HeaderSize() + kHeapObjectTag); |
3541 } | 3649 } |
3542 | 3650 |
3543 private: | 3651 private: |
3544 void set_size(intptr_t size) const { | 3652 void set_size(intptr_t size) const { |
3545 StoreNonPointer(&raw_ptr()->size_, size); | 3653 StoreNonPointer(&raw_ptr()->size_, size); |
3546 } | 3654 } |
3547 void set_code(RawCode* code) const { | 3655 void set_code(RawCode* code) const { |
3548 StorePointer(&raw_ptr()->code_, code); | 3656 StorePointer(&raw_ptr()->code_, code); |
3549 } | 3657 } |
3550 void set_object_pool(RawArray* object_pool) const { | 3658 void set_object_pool(RawObjectPool* object_pool) const { |
3551 StorePointer(&raw_ptr()->object_pool_, object_pool); | 3659 StorePointer(&raw_ptr()->object_pool_, object_pool); |
3552 } | 3660 } |
3553 | 3661 |
3554 // New is a private method as RawInstruction and RawCode objects should | 3662 // New is a private method as RawInstruction and RawCode objects should |
3555 // only be created using the Code::FinalizeCode method. This method creates | 3663 // only be created using the Code::FinalizeCode method. This method creates |
3556 // the RawInstruction and RawCode objects, sets up the pointer offsets | 3664 // the RawInstruction and RawCode objects, sets up the pointer offsets |
3557 // and links the two in a GC safe manner. | 3665 // and links the two in a GC safe manner. |
3558 static RawInstructions* New(intptr_t size); | 3666 static RawInstructions* New(intptr_t size); |
3559 | 3667 |
3560 FINAL_HEAP_OBJECT_IMPLEMENTATION(Instructions, Object); | 3668 FINAL_HEAP_OBJECT_IMPLEMENTATION(Instructions, Object); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3892 void set_is_alive(bool value) const; | 4000 void set_is_alive(bool value) const; |
3893 | 4001 |
3894 uword EntryPoint() const { | 4002 uword EntryPoint() const { |
3895 const Instructions& instr = Instructions::Handle(instructions()); | 4003 const Instructions& instr = Instructions::Handle(instructions()); |
3896 return instr.EntryPoint(); | 4004 return instr.EntryPoint(); |
3897 } | 4005 } |
3898 intptr_t Size() const { | 4006 intptr_t Size() const { |
3899 const Instructions& instr = Instructions::Handle(instructions()); | 4007 const Instructions& instr = Instructions::Handle(instructions()); |
3900 return instr.size(); | 4008 return instr.size(); |
3901 } | 4009 } |
3902 RawArray* ObjectPool() const { | 4010 RawObjectPool* GetObjectPool() const { |
3903 const Instructions& instr = Instructions::Handle(instructions()); | 4011 const Instructions& instr = Instructions::Handle(instructions()); |
3904 return instr.object_pool(); | 4012 return instr.object_pool(); |
3905 } | 4013 } |
3906 bool ContainsInstructionAt(uword addr) const { | 4014 bool ContainsInstructionAt(uword addr) const { |
3907 const Instructions& instr = Instructions::Handle(instructions()); | 4015 const Instructions& instr = Instructions::Handle(instructions()); |
3908 const uword offset = addr - instr.EntryPoint(); | 4016 const uword offset = addr - instr.EntryPoint(); |
3909 return offset < static_cast<uword>(instr.size()); | 4017 return offset < static_cast<uword>(instr.size()); |
3910 } | 4018 } |
3911 | 4019 |
3912 // Returns true if there is a debugger breakpoint set in this code object. | 4020 // Returns true if there is a debugger breakpoint set in this code object. |
(...skipping 3941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7854 | 7962 |
7855 | 7963 |
7856 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 7964 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
7857 intptr_t index) { | 7965 intptr_t index) { |
7858 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 7966 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
7859 } | 7967 } |
7860 | 7968 |
7861 } // namespace dart | 7969 } // namespace dart |
7862 | 7970 |
7863 #endif // VM_OBJECT_H_ | 7971 #endif // VM_OBJECT_H_ |
OLD | NEW |