Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: runtime/vm/object.h

Issue 1147303002: Support untagged object pool entries. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: rebased Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 400
401 static const Array& empty_array() { 401 static const Array& empty_array() {
402 ASSERT(empty_array_ != NULL); 402 ASSERT(empty_array_ != NULL);
403 return *empty_array_; 403 return *empty_array_;
404 } 404 }
405 static const Array& zero_array() { 405 static const Array& zero_array() {
406 ASSERT(zero_array_ != NULL); 406 ASSERT(zero_array_ != NULL);
407 return *zero_array_; 407 return *zero_array_;
408 } 408 }
409 409
410 static const ObjectPool& empty_object_pool() {
411 ASSERT(empty_object_pool_ != NULL);
412 return *empty_object_pool_;
413 }
414
410 static const PcDescriptors& empty_descriptors() { 415 static const PcDescriptors& empty_descriptors() {
411 ASSERT(empty_descriptors_ != NULL); 416 ASSERT(empty_descriptors_ != NULL);
412 return *empty_descriptors_; 417 return *empty_descriptors_;
413 } 418 }
414 419
415 static const LocalVarDescriptors& empty_var_descriptors() { 420 static const LocalVarDescriptors& empty_var_descriptors() {
416 ASSERT(empty_var_descriptors_ != NULL); 421 ASSERT(empty_var_descriptors_ != NULL);
417 return *empty_var_descriptors_; 422 return *empty_var_descriptors_;
418 } 423 }
419 424
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 static RawClass* function_class() { return function_class_; } 501 static RawClass* function_class() { return function_class_; }
497 static RawClass* closure_data_class() { return closure_data_class_; } 502 static RawClass* closure_data_class() { return closure_data_class_; }
498 static RawClass* redirection_data_class() { return redirection_data_class_; } 503 static RawClass* redirection_data_class() { return redirection_data_class_; }
499 static RawClass* field_class() { return field_class_; } 504 static RawClass* field_class() { return field_class_; }
500 static RawClass* literal_token_class() { return literal_token_class_; } 505 static RawClass* literal_token_class() { return literal_token_class_; }
501 static RawClass* token_stream_class() { return token_stream_class_; } 506 static RawClass* token_stream_class() { return token_stream_class_; }
502 static RawClass* script_class() { return script_class_; } 507 static RawClass* script_class() { return script_class_; }
503 static RawClass* library_class() { return library_class_; } 508 static RawClass* library_class() { return library_class_; }
504 static RawClass* namespace_class() { return namespace_class_; } 509 static RawClass* namespace_class() { return namespace_class_; }
505 static RawClass* code_class() { return code_class_; } 510 static RawClass* code_class() { return code_class_; }
511 static RawClass* object_pool_class() { return object_pool_class_; }
506 static RawClass* instructions_class() { return instructions_class_; } 512 static RawClass* instructions_class() { return instructions_class_; }
507 static RawClass* pc_descriptors_class() { return pc_descriptors_class_; } 513 static RawClass* pc_descriptors_class() { return pc_descriptors_class_; }
508 static RawClass* stackmap_class() { return stackmap_class_; } 514 static RawClass* stackmap_class() { return stackmap_class_; }
509 static RawClass* var_descriptors_class() { return var_descriptors_class_; } 515 static RawClass* var_descriptors_class() { return var_descriptors_class_; }
510 static RawClass* exception_handlers_class() { 516 static RawClass* exception_handlers_class() {
511 return exception_handlers_class_; 517 return exception_handlers_class_;
512 } 518 }
513 static RawClass* deopt_info_class() { return deopt_info_class_; } 519 static RawClass* deopt_info_class() { return deopt_info_class_; }
514 static RawClass* context_class() { return context_class_; } 520 static RawClass* context_class() { return context_class_; }
515 static RawClass* context_scope_class() { return context_scope_class_; } 521 static RawClass* context_scope_class() { return context_scope_class_; }
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 static RawClass* function_class_; // Class of the Function vm object. 756 static RawClass* function_class_; // Class of the Function vm object.
751 static RawClass* closure_data_class_; // Class of ClosureData vm obj. 757 static RawClass* closure_data_class_; // Class of ClosureData vm obj.
752 static RawClass* redirection_data_class_; // Class of RedirectionData vm obj. 758 static RawClass* redirection_data_class_; // Class of RedirectionData vm obj.
753 static RawClass* field_class_; // Class of the Field vm object. 759 static RawClass* field_class_; // Class of the Field vm object.
754 static RawClass* literal_token_class_; // Class of LiteralToken vm object. 760 static RawClass* literal_token_class_; // Class of LiteralToken vm object.
755 static RawClass* token_stream_class_; // Class of the TokenStream vm object. 761 static RawClass* token_stream_class_; // Class of the TokenStream vm object.
756 static RawClass* script_class_; // Class of the Script vm object. 762 static RawClass* script_class_; // Class of the Script vm object.
757 static RawClass* library_class_; // Class of the Library vm object. 763 static RawClass* library_class_; // Class of the Library vm object.
758 static RawClass* namespace_class_; // Class of Namespace vm object. 764 static RawClass* namespace_class_; // Class of Namespace vm object.
759 static RawClass* code_class_; // Class of the Code vm object. 765 static RawClass* code_class_; // Class of the Code vm object.
766 static RawClass* object_pool_class_; // Class of the ObjectPool vm object.
760 static RawClass* instructions_class_; // Class of the Instructions vm object. 767 static RawClass* instructions_class_; // Class of the Instructions vm object.
761 static RawClass* pc_descriptors_class_; // Class of PcDescriptors vm object. 768 static RawClass* pc_descriptors_class_; // Class of PcDescriptors vm object.
762 static RawClass* stackmap_class_; // Class of Stackmap vm object. 769 static RawClass* stackmap_class_; // Class of Stackmap vm object.
763 static RawClass* var_descriptors_class_; // Class of LocalVarDescriptors. 770 static RawClass* var_descriptors_class_; // Class of LocalVarDescriptors.
764 static RawClass* exception_handlers_class_; // Class of ExceptionHandlers. 771 static RawClass* exception_handlers_class_; // Class of ExceptionHandlers.
765 static RawClass* deopt_info_class_; // Class of DeoptInfo. 772 static RawClass* deopt_info_class_; // Class of DeoptInfo.
766 static RawClass* context_class_; // Class of the Context vm object. 773 static RawClass* context_class_; // Class of the Context vm object.
767 static RawClass* context_scope_class_; // Class of ContextScope vm object. 774 static RawClass* context_scope_class_; // Class of ContextScope vm object.
768 static RawClass* icdata_class_; // Class of ICData. 775 static RawClass* icdata_class_; // Class of ICData.
769 static RawClass* megamorphic_cache_class_; // Class of MegamorphiCache. 776 static RawClass* megamorphic_cache_class_; // Class of MegamorphiCache.
770 static RawClass* subtypetestcache_class_; // Class of SubtypeTestCache. 777 static RawClass* subtypetestcache_class_; // Class of SubtypeTestCache.
771 static RawClass* api_error_class_; // Class of ApiError. 778 static RawClass* api_error_class_; // Class of ApiError.
772 static RawClass* language_error_class_; // Class of LanguageError. 779 static RawClass* language_error_class_; // Class of LanguageError.
773 static RawClass* unhandled_exception_class_; // Class of UnhandledException. 780 static RawClass* unhandled_exception_class_; // Class of UnhandledException.
774 static RawClass* unwind_error_class_; // Class of UnwindError. 781 static RawClass* unwind_error_class_; // Class of UnwindError.
775 782
776 // The static values below are read-only handle pointers for singleton 783 // The static values below are read-only handle pointers for singleton
777 // objects that are shared between the different isolates. 784 // objects that are shared between the different isolates.
778 static Object* null_object_; 785 static Object* null_object_;
779 static Array* null_array_; 786 static Array* null_array_;
780 static String* null_string_; 787 static String* null_string_;
781 static Instance* null_instance_; 788 static Instance* null_instance_;
782 static TypeArguments* null_type_arguments_; 789 static TypeArguments* null_type_arguments_;
783 static Array* empty_array_; 790 static Array* empty_array_;
784 static Array* zero_array_; 791 static Array* zero_array_;
792 static ObjectPool* empty_object_pool_;
785 static PcDescriptors* empty_descriptors_; 793 static PcDescriptors* empty_descriptors_;
786 static LocalVarDescriptors* empty_var_descriptors_; 794 static LocalVarDescriptors* empty_var_descriptors_;
787 static ExceptionHandlers* empty_exception_handlers_; 795 static ExceptionHandlers* empty_exception_handlers_;
788 static Array* extractor_parameter_types_; 796 static Array* extractor_parameter_types_;
789 static Array* extractor_parameter_names_; 797 static Array* extractor_parameter_names_;
790 static Instance* sentinel_; 798 static Instance* sentinel_;
791 static Instance* transition_sentinel_; 799 static Instance* transition_sentinel_;
792 static Instance* unknown_constant_; 800 static Instance* unknown_constant_;
793 static Instance* non_constant_; 801 static Instance* non_constant_;
794 static Bool* bool_true_; 802 static Bool* bool_true_;
(...skipping 2370 matching lines...) Expand 10 before | Expand all | Expand 10 after
3165 static RawNamespace* New(); 3173 static RawNamespace* New();
3166 3174
3167 RawField* metadata_field() const { return raw_ptr()->metadata_field_; } 3175 RawField* metadata_field() const { return raw_ptr()->metadata_field_; }
3168 void set_metadata_field(const Field& value) const; 3176 void set_metadata_field(const Field& value) const;
3169 3177
3170 FINAL_HEAP_OBJECT_IMPLEMENTATION(Namespace, Object); 3178 FINAL_HEAP_OBJECT_IMPLEMENTATION(Namespace, Object);
3171 friend class Class; 3179 friend class Class;
3172 }; 3180 };
3173 3181
3174 3182
3183 class ObjectPool : public Object {
3184 public:
3185 struct Entry {
3186 Entry() : raw_value_() { }
3187 explicit Entry(const Object* obj) : obj_(obj) { }
3188 explicit Entry(uword value) : raw_value_(value) { }
3189 union {
3190 const Object* obj_;
3191 uword raw_value_;
3192 };
3193 };
3194
3195 intptr_t Length() const {
3196 return raw_ptr()->length_;
3197 }
3198 void SetLength(intptr_t value) const {
3199 StoreNonPointer(&raw_ptr()->length_, value);
3200 }
3201
3202 intptr_t NumTaggedEntries() const {
3203 return raw_ptr()->num_tagged_entries_;
3204 }
3205
3206 void SetNumTaggedEntries(intptr_t value) {
3207 StoreNonPointer(&raw_ptr()->num_tagged_entries_, value);
3208 }
3209
3210 static intptr_t data_offset() {
3211 return OFFSET_OF_RETURNED_VALUE(RawObjectPool, data);
3212 }
3213 static intptr_t element_offset(intptr_t index) {
3214 return OFFSET_OF_RETURNED_VALUE(RawObjectPool, data)
3215 + kBytesPerElement * index;
3216 }
3217
3218 RawObject* ObjectAt(intptr_t index) const {
3219 return EntryAddr(index)->raw_obj_;
3220 }
3221 void SetObjectAt(intptr_t index, const Object& obj) const {
3222 StorePointer(&EntryAddr(index)->raw_obj_, obj.raw());
3223 }
3224
3225 uword RawValueAt(intptr_t index) const {
3226 return EntryAddr(index)->raw_value_;
3227 }
3228 void SetRawValueAt(intptr_t index, uword raw_value) const {
3229 StoreNonPointer(&EntryAddr(index)->raw_value_, raw_value);
3230 }
3231
3232 void DebugPrint() const;
3233
3234 static intptr_t InstanceSize() {
3235 ASSERT(sizeof(RawObjectPool) ==
3236 OFFSET_OF_RETURNED_VALUE(RawObjectPool, data));
3237 return 0;
3238 }
3239
3240 static const intptr_t kBytesPerElement = sizeof(RawObjectPool::Entry);
3241 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement;
3242
3243 static intptr_t InstanceSize(intptr_t len) {
3244 // Ensure that variable length data is not adding to the object length.
3245 ASSERT(sizeof(RawObjectPool) == (sizeof(RawObject) + (2 * kWordSize)));
3246 ASSERT(0 <= len && len <= kMaxElements);
3247 return RoundedAllocationSize(
3248 sizeof(RawObjectPool) + (len * kBytesPerElement));
3249 }
3250
3251 static RawObjectPool* New(intptr_t len, intptr_t num_tagged_entries);
3252
3253 static intptr_t IndexFromOffset(intptr_t offset) {
3254 return (offset + kHeapObjectTag - data_offset()) / kBytesPerElement;
3255 }
3256
3257 private:
3258 RawObjectPool::Entry const* EntryAddr(intptr_t index) const {
3259 ASSERT((index >= 0) && (index < Length()));
3260 return &raw_ptr()->data()[index];
3261 }
3262
3263 FINAL_HEAP_OBJECT_IMPLEMENTATION(ObjectPool, Object);
3264 friend class Class;
3265 friend class Object;
3266 friend class RawObjectPool;
3267 };
3268
3269
3175 class Instructions : public Object { 3270 class Instructions : public Object {
3176 public: 3271 public:
3177 intptr_t size() const { return raw_ptr()->size_; } // Excludes HeaderSize(). 3272 intptr_t size() const { return raw_ptr()->size_; } // Excludes HeaderSize().
3178 RawCode* code() const { return raw_ptr()->code_; } 3273 RawCode* code() const { return raw_ptr()->code_; }
3179 static intptr_t code_offset() { 3274 static intptr_t code_offset() {
3180 return OFFSET_OF(RawInstructions, code_); 3275 return OFFSET_OF(RawInstructions, code_);
3181 } 3276 }
3182 RawArray* object_pool() const { return raw_ptr()->object_pool_; } 3277 RawObjectPool* object_pool() const { return raw_ptr()->object_pool_; }
3183 static intptr_t object_pool_offset() { 3278 static intptr_t object_pool_offset() {
3184 return OFFSET_OF(RawInstructions, object_pool_); 3279 return OFFSET_OF(RawInstructions, object_pool_);
3185 } 3280 }
3186 3281
3187 uword EntryPoint() const { 3282 uword EntryPoint() const {
3188 return reinterpret_cast<uword>(raw_ptr()) + HeaderSize(); 3283 return reinterpret_cast<uword>(raw_ptr()) + HeaderSize();
3189 } 3284 }
3190 3285
3191 static const intptr_t kMaxElements = (kMaxInt32 - 3286 static const intptr_t kMaxElements = (kMaxInt32 -
3192 (sizeof(RawInstructions) + 3287 (sizeof(RawInstructions) +
(...skipping 24 matching lines...) Expand all
3217 entry_point - HeaderSize() + kHeapObjectTag); 3312 entry_point - HeaderSize() + kHeapObjectTag);
3218 } 3313 }
3219 3314
3220 private: 3315 private:
3221 void set_size(intptr_t size) const { 3316 void set_size(intptr_t size) const {
3222 StoreNonPointer(&raw_ptr()->size_, size); 3317 StoreNonPointer(&raw_ptr()->size_, size);
3223 } 3318 }
3224 void set_code(RawCode* code) const { 3319 void set_code(RawCode* code) const {
3225 StorePointer(&raw_ptr()->code_, code); 3320 StorePointer(&raw_ptr()->code_, code);
3226 } 3321 }
3227 void set_object_pool(RawArray* object_pool) const { 3322 void set_object_pool(RawObjectPool* object_pool) const {
3228 StorePointer(&raw_ptr()->object_pool_, object_pool); 3323 StorePointer(&raw_ptr()->object_pool_, object_pool);
3229 } 3324 }
3230 3325
3231 // New is a private method as RawInstruction and RawCode objects should 3326 // New is a private method as RawInstruction and RawCode objects should
3232 // only be created using the Code::FinalizeCode method. This method creates 3327 // only be created using the Code::FinalizeCode method. This method creates
3233 // the RawInstruction and RawCode objects, sets up the pointer offsets 3328 // the RawInstruction and RawCode objects, sets up the pointer offsets
3234 // and links the two in a GC safe manner. 3329 // and links the two in a GC safe manner.
3235 static RawInstructions* New(intptr_t size); 3330 static RawInstructions* New(intptr_t size);
3236 3331
3237 FINAL_HEAP_OBJECT_IMPLEMENTATION(Instructions, Object); 3332 FINAL_HEAP_OBJECT_IMPLEMENTATION(Instructions, Object);
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
3883 void set_is_alive(bool value) const; 3978 void set_is_alive(bool value) const;
3884 3979
3885 uword EntryPoint() const { 3980 uword EntryPoint() const {
3886 const Instructions& instr = Instructions::Handle(instructions()); 3981 const Instructions& instr = Instructions::Handle(instructions());
3887 return instr.EntryPoint(); 3982 return instr.EntryPoint();
3888 } 3983 }
3889 intptr_t Size() const { 3984 intptr_t Size() const {
3890 const Instructions& instr = Instructions::Handle(instructions()); 3985 const Instructions& instr = Instructions::Handle(instructions());
3891 return instr.size(); 3986 return instr.size();
3892 } 3987 }
3893 RawArray* ObjectPool() const { 3988 RawObjectPool* GetObjectPool() const {
3894 const Instructions& instr = Instructions::Handle(instructions()); 3989 const Instructions& instr = Instructions::Handle(instructions());
3895 return instr.object_pool(); 3990 return instr.object_pool();
3896 } 3991 }
3897 bool ContainsInstructionAt(uword addr) const { 3992 bool ContainsInstructionAt(uword addr) const {
3898 const Instructions& instr = Instructions::Handle(instructions()); 3993 const Instructions& instr = Instructions::Handle(instructions());
3899 const uword offset = addr - instr.EntryPoint(); 3994 const uword offset = addr - instr.EntryPoint();
3900 return offset < static_cast<uword>(instr.size()); 3995 return offset < static_cast<uword>(instr.size());
3901 } 3996 }
3902 3997
3903 // Returns true if there is a debugger breakpoint set in this code object. 3998 // Returns true if there is a debugger breakpoint set in this code object.
(...skipping 3841 matching lines...) Expand 10 before | Expand all | Expand 10 after
7745 7840
7746 7841
7747 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 7842 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
7748 intptr_t index) { 7843 intptr_t index) {
7749 return array.At((index * kEntryLength) + kTargetFunctionIndex); 7844 return array.At((index * kEntryLength) + kTargetFunctionIndex);
7750 } 7845 }
7751 7846
7752 } // namespace dart 7847 } // namespace dart
7753 7848
7754 #endif // VM_OBJECT_H_ 7849 #endif // VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698