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