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 { | |
srdjan
2015/06/09 21:49:47
Add a brief comment above.
Florian Schneider
2015/06/10 08:26:17
Done.
| |
3507 public: | |
3508 enum EntryType { | |
3509 kTaggedObject, | |
3510 kImmediate, | |
3511 }; | |
3512 | |
3513 struct Entry { | |
3514 Entry() : raw_value_(), type_() { } | |
3515 explicit Entry(const Object* obj) : obj_(obj), type_(kTaggedObject) { } | |
3516 Entry(uword value, EntryType info) : raw_value_(value), type_(info) { } | |
3517 union { | |
3518 const Object* obj_; | |
3519 uword raw_value_; | |
3520 }; | |
3521 EntryType type_; | |
3522 }; | |
3523 | |
3524 intptr_t Length() const { | |
3525 return raw_ptr()->length_; | |
3526 } | |
3527 void SetLength(intptr_t value) const { | |
3528 StoreNonPointer(&raw_ptr()->length_, value); | |
3529 } | |
3530 | |
3531 RawTypedData* info_array() const { | |
3532 return raw_ptr()->info_array_; | |
3533 } | |
3534 | |
3535 void set_info_array(const TypedData& info_array) const; | |
3536 | |
3537 static intptr_t length_offset() { return OFFSET_OF(RawObjectPool, length_); } | |
3538 static intptr_t data_offset() { | |
3539 return OFFSET_OF_RETURNED_VALUE(RawObjectPool, data); | |
3540 } | |
3541 static intptr_t element_offset(intptr_t index) { | |
3542 return OFFSET_OF_RETURNED_VALUE(RawObjectPool, data) | |
3543 + kBytesPerElement * index; | |
3544 } | |
3545 | |
3546 EntryType InfoAt(intptr_t index) const; | |
3547 void SetInfoAt(intptr_t index, EntryType info) const; | |
3548 | |
3549 RawObject* ObjectAt(intptr_t index) const { | |
3550 ASSERT(InfoAt(index) == kTaggedObject); | |
3551 return EntryAddr(index)->raw_obj_; | |
3552 } | |
3553 void SetObjectAt(intptr_t index, const Object& obj) const { | |
3554 ASSERT(InfoAt(index) == kTaggedObject); | |
3555 StorePointer(&EntryAddr(index)->raw_obj_, obj.raw()); | |
3556 } | |
3557 | |
3558 uword RawValueAt(intptr_t index) const { | |
3559 ASSERT(InfoAt(index) != kTaggedObject); | |
3560 return EntryAddr(index)->raw_value_; | |
3561 } | |
3562 void SetRawValueAt(intptr_t index, uword raw_value) const { | |
3563 ASSERT(InfoAt(index) != kTaggedObject); | |
3564 StoreNonPointer(&EntryAddr(index)->raw_value_, raw_value); | |
3565 } | |
3566 | |
3567 static intptr_t InstanceSize() { | |
3568 ASSERT(sizeof(RawObjectPool) == | |
3569 OFFSET_OF_RETURNED_VALUE(RawObjectPool, data)); | |
3570 return 0; | |
3571 } | |
3572 | |
3573 static const intptr_t kBytesPerElement = sizeof(RawObjectPool::Entry); | |
3574 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | |
3575 | |
3576 static intptr_t InstanceSize(intptr_t len) { | |
3577 // Ensure that variable length data is not adding to the object length. | |
3578 ASSERT(sizeof(RawObjectPool) == (sizeof(RawObject) + (2 * kWordSize))); | |
3579 ASSERT(0 <= len && len <= kMaxElements); | |
3580 return RoundedAllocationSize( | |
3581 sizeof(RawObjectPool) + (len * kBytesPerElement)); | |
3582 } | |
3583 | |
3584 static RawObjectPool* New(intptr_t len); | |
3585 | |
3586 static intptr_t IndexFromOffset(intptr_t offset) { | |
3587 return (offset + kHeapObjectTag - data_offset()) / kBytesPerElement; | |
3588 } | |
3589 | |
3590 void DebugPrint() const; | |
3591 | |
3592 private: | |
3593 RawObjectPool::Entry const* EntryAddr(intptr_t index) const { | |
3594 ASSERT((index >= 0) && (index < Length())); | |
3595 return &raw_ptr()->data()[index]; | |
3596 } | |
3597 | |
3598 FINAL_HEAP_OBJECT_IMPLEMENTATION(ObjectPool, Object); | |
3599 friend class Class; | |
3600 friend class Object; | |
3601 friend class RawObjectPool; | |
3602 }; | |
3603 | |
3604 | |
3498 class Instructions : public Object { | 3605 class Instructions : public Object { |
3499 public: | 3606 public: |
3500 intptr_t size() const { return raw_ptr()->size_; } // Excludes HeaderSize(). | 3607 intptr_t size() const { return raw_ptr()->size_; } // Excludes HeaderSize(). |
3501 RawCode* code() const { return raw_ptr()->code_; } | 3608 RawCode* code() const { return raw_ptr()->code_; } |
3502 static intptr_t code_offset() { | 3609 static intptr_t code_offset() { |
3503 return OFFSET_OF(RawInstructions, code_); | 3610 return OFFSET_OF(RawInstructions, code_); |
3504 } | 3611 } |
3505 RawArray* object_pool() const { return raw_ptr()->object_pool_; } | 3612 RawObjectPool* object_pool() const { return raw_ptr()->object_pool_; } |
3506 static intptr_t object_pool_offset() { | 3613 static intptr_t object_pool_offset() { |
3507 return OFFSET_OF(RawInstructions, object_pool_); | 3614 return OFFSET_OF(RawInstructions, object_pool_); |
3508 } | 3615 } |
3509 | 3616 |
3510 uword EntryPoint() const { | 3617 uword EntryPoint() const { |
3511 return reinterpret_cast<uword>(raw_ptr()) + HeaderSize(); | 3618 return reinterpret_cast<uword>(raw_ptr()) + HeaderSize(); |
3512 } | 3619 } |
3513 | 3620 |
3514 static const intptr_t kMaxElements = (kMaxInt32 - | 3621 static const intptr_t kMaxElements = (kMaxInt32 - |
3515 (sizeof(RawInstructions) + | 3622 (sizeof(RawInstructions) + |
(...skipping 24 matching lines...) Expand all Loading... | |
3540 entry_point - HeaderSize() + kHeapObjectTag); | 3647 entry_point - HeaderSize() + kHeapObjectTag); |
3541 } | 3648 } |
3542 | 3649 |
3543 private: | 3650 private: |
3544 void set_size(intptr_t size) const { | 3651 void set_size(intptr_t size) const { |
3545 StoreNonPointer(&raw_ptr()->size_, size); | 3652 StoreNonPointer(&raw_ptr()->size_, size); |
3546 } | 3653 } |
3547 void set_code(RawCode* code) const { | 3654 void set_code(RawCode* code) const { |
3548 StorePointer(&raw_ptr()->code_, code); | 3655 StorePointer(&raw_ptr()->code_, code); |
3549 } | 3656 } |
3550 void set_object_pool(RawArray* object_pool) const { | 3657 void set_object_pool(RawObjectPool* object_pool) const { |
3551 StorePointer(&raw_ptr()->object_pool_, object_pool); | 3658 StorePointer(&raw_ptr()->object_pool_, object_pool); |
3552 } | 3659 } |
3553 | 3660 |
3554 // New is a private method as RawInstruction and RawCode objects should | 3661 // New is a private method as RawInstruction and RawCode objects should |
3555 // only be created using the Code::FinalizeCode method. This method creates | 3662 // only be created using the Code::FinalizeCode method. This method creates |
3556 // the RawInstruction and RawCode objects, sets up the pointer offsets | 3663 // the RawInstruction and RawCode objects, sets up the pointer offsets |
3557 // and links the two in a GC safe manner. | 3664 // and links the two in a GC safe manner. |
3558 static RawInstructions* New(intptr_t size); | 3665 static RawInstructions* New(intptr_t size); |
3559 | 3666 |
3560 FINAL_HEAP_OBJECT_IMPLEMENTATION(Instructions, Object); | 3667 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; | 3999 void set_is_alive(bool value) const; |
3893 | 4000 |
3894 uword EntryPoint() const { | 4001 uword EntryPoint() const { |
3895 const Instructions& instr = Instructions::Handle(instructions()); | 4002 const Instructions& instr = Instructions::Handle(instructions()); |
3896 return instr.EntryPoint(); | 4003 return instr.EntryPoint(); |
3897 } | 4004 } |
3898 intptr_t Size() const { | 4005 intptr_t Size() const { |
3899 const Instructions& instr = Instructions::Handle(instructions()); | 4006 const Instructions& instr = Instructions::Handle(instructions()); |
3900 return instr.size(); | 4007 return instr.size(); |
3901 } | 4008 } |
3902 RawArray* ObjectPool() const { | 4009 RawObjectPool* GetObjectPool() const { |
3903 const Instructions& instr = Instructions::Handle(instructions()); | 4010 const Instructions& instr = Instructions::Handle(instructions()); |
3904 return instr.object_pool(); | 4011 return instr.object_pool(); |
3905 } | 4012 } |
3906 bool ContainsInstructionAt(uword addr) const { | 4013 bool ContainsInstructionAt(uword addr) const { |
3907 const Instructions& instr = Instructions::Handle(instructions()); | 4014 const Instructions& instr = Instructions::Handle(instructions()); |
3908 const uword offset = addr - instr.EntryPoint(); | 4015 const uword offset = addr - instr.EntryPoint(); |
3909 return offset < static_cast<uword>(instr.size()); | 4016 return offset < static_cast<uword>(instr.size()); |
3910 } | 4017 } |
3911 | 4018 |
3912 // Returns true if there is a debugger breakpoint set in this code object. | 4019 // 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 | 7961 |
7855 | 7962 |
7856 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 7963 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
7857 intptr_t index) { | 7964 intptr_t index) { |
7858 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 7965 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
7859 } | 7966 } |
7860 | 7967 |
7861 } // namespace dart | 7968 } // namespace dart |
7862 | 7969 |
7863 #endif // VM_OBJECT_H_ | 7970 #endif // VM_OBJECT_H_ |
OLD | NEW |