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

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

Issue 15689012: More cleanup to avoid creation of redundant handles (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 static object& CheckedZoneHandle(RawObject* raw_ptr) { \ 103 static object& CheckedZoneHandle(RawObject* raw_ptr) { \
104 return CheckedZoneHandle(Isolate::Current(), raw_ptr); \ 104 return CheckedZoneHandle(Isolate::Current(), raw_ptr); \
105 } \ 105 } \
106 /* T::Cast cannot be applied to a null Object, because the object vtable */ \ 106 /* T::Cast cannot be applied to a null Object, because the object vtable */ \
107 /* is not setup for type T, although some methods are supposed to work */ \ 107 /* is not setup for type T, although some methods are supposed to work */ \
108 /* with null, for example Instance::Equals(). */ \ 108 /* with null, for example Instance::Equals(). */ \
109 static const object& Cast(const Object& obj) { \ 109 static const object& Cast(const Object& obj) { \
110 ASSERT(obj.Is##object()); \ 110 ASSERT(obj.Is##object()); \
111 return reinterpret_cast<const object&>(obj); \ 111 return reinterpret_cast<const object&>(obj); \
112 } \ 112 } \
113 static Raw##object* RawCast(RawObject* raw) { \
114 ASSERT(Object::Handle(raw).Is##object()); \
hausner 2013/05/31 16:40:25 I always cringe at expensive asserts in very low l
siva 2013/05/31 22:35:48 A handle creation can not lead to garbage collecti
115 return reinterpret_cast<Raw##object*>(raw); \
116 } \
113 static Raw##object* null() { \ 117 static Raw##object* null() { \
114 return reinterpret_cast<Raw##object*>(Object::null()); \ 118 return reinterpret_cast<Raw##object*>(Object::null()); \
115 } \ 119 } \
120 static const object& null_object() { \
121 return reinterpret_cast<const object&>(Object::null_object()); \
122 } \
116 virtual const char* ToCString() const; \ 123 virtual const char* ToCString() const; \
117 static const ClassId kClassId = k##object##Cid; \ 124 static const ClassId kClassId = k##object##Cid; \
118 private: /* NOLINT */ \ 125 private: /* NOLINT */ \
119 /* Initialize the handle based on the raw_ptr in the presence of null. */ \ 126 /* Initialize the handle based on the raw_ptr in the presence of null. */ \
120 static void initializeHandle(object* obj, RawObject* raw_ptr) { \ 127 static void initializeHandle(object* obj, RawObject* raw_ptr) { \
121 if (raw_ptr != Object::null()) { \ 128 if (raw_ptr != Object::null()) { \
122 obj->SetRaw(raw_ptr); \ 129 obj->SetRaw(raw_ptr); \
123 } else { \ 130 } else { \
124 obj->raw_ = Object::null(); \ 131 obj->raw_ = Object::null(); \
125 object fake_object; \ 132 object fake_object; \
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 305
299 static Object& ZoneHandle() { 306 static Object& ZoneHandle() {
300 return ZoneHandle(Isolate::Current(), null_); 307 return ZoneHandle(Isolate::Current(), null_);
301 } 308 }
302 309
303 static Object& ZoneHandle(RawObject* raw_ptr) { 310 static Object& ZoneHandle(RawObject* raw_ptr) {
304 return ZoneHandle(Isolate::Current(), raw_ptr); 311 return ZoneHandle(Isolate::Current(), raw_ptr);
305 } 312 }
306 313
307 static RawObject* null() { return null_; } 314 static RawObject* null() { return null_; }
315 static const Object& null_object() {
316 ASSERT(null_object_ != NULL);
317 return *null_object_;
318 }
308 static const Array& empty_array() { 319 static const Array& empty_array() {
309 ASSERT(empty_array_ != NULL); 320 ASSERT(empty_array_ != NULL);
310 return *empty_array_; 321 return *empty_array_;
311 } 322 }
312 323
313 // The sentinel is a value that cannot be produced by Dart code. 324 // The sentinel is a value that cannot be produced by Dart code.
314 // It can be used to mark special values, for example to distinguish 325 // It can be used to mark special values, for example to distinguish
315 // "uninitialized" fields. 326 // "uninitialized" fields.
316 static const Instance& sentinel() { 327 static const Instance& sentinel() {
317 ASSERT(sentinel_ != NULL); 328 ASSERT(sentinel_ != NULL);
(...skipping 17 matching lines...) Expand all
335 } 346 }
336 347
337 static const Bool& bool_true() { 348 static const Bool& bool_true() {
338 ASSERT(bool_true_ != NULL); 349 ASSERT(bool_true_ != NULL);
339 return *bool_true_; 350 return *bool_true_;
340 } 351 }
341 static const Bool& bool_false() { 352 static const Bool& bool_false() {
342 ASSERT(bool_false_ != NULL); 353 ASSERT(bool_false_ != NULL);
343 return *bool_false_; 354 return *bool_false_;
344 } 355 }
356
357 static const Smi& sentinel_smi() {
358 ASSERT(sentinel_smi_ != NULL);
359 return *sentinel_smi_;
360 }
345 static const LanguageError& snapshot_writer_error() { 361 static const LanguageError& snapshot_writer_error() {
346 ASSERT(snapshot_writer_error_ != NULL); 362 ASSERT(snapshot_writer_error_ != NULL);
347 return *snapshot_writer_error_; 363 return *snapshot_writer_error_;
348 } 364 }
349 365
350 static RawClass* class_class() { return class_class_; } 366 static RawClass* class_class() { return class_class_; }
351 static RawClass* null_class() { return null_class_; } 367 static RawClass* null_class() { return null_class_; }
352 static RawClass* dynamic_class() { return dynamic_class_; } 368 static RawClass* dynamic_class() { return dynamic_class_; }
353 static RawClass* void_class() { return void_class_; } 369 static RawClass* void_class() { return void_class_; }
354 static RawClass* unresolved_class_class() { return unresolved_class_class_; } 370 static RawClass* unresolved_class_class() { return unresolved_class_class_; }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 static RawClass* icdata_class_; // Class of ICData. 542 static RawClass* icdata_class_; // Class of ICData.
527 static RawClass* megamorphic_cache_class_; // Class of MegamorphiCache. 543 static RawClass* megamorphic_cache_class_; // Class of MegamorphiCache.
528 static RawClass* subtypetestcache_class_; // Class of SubtypeTestCache. 544 static RawClass* subtypetestcache_class_; // Class of SubtypeTestCache.
529 static RawClass* api_error_class_; // Class of ApiError. 545 static RawClass* api_error_class_; // Class of ApiError.
530 static RawClass* language_error_class_; // Class of LanguageError. 546 static RawClass* language_error_class_; // Class of LanguageError.
531 static RawClass* unhandled_exception_class_; // Class of UnhandledException. 547 static RawClass* unhandled_exception_class_; // Class of UnhandledException.
532 static RawClass* unwind_error_class_; // Class of UnwindError. 548 static RawClass* unwind_error_class_; // Class of UnwindError.
533 549
534 // The static values below are read-only handle pointers for singleton 550 // The static values below are read-only handle pointers for singleton
535 // objects that are shared between the different isolates. 551 // objects that are shared between the different isolates.
552 static Object* null_object_;
536 static Array* empty_array_; 553 static Array* empty_array_;
537 static Instance* sentinel_; 554 static Instance* sentinel_;
538 static Instance* transition_sentinel_; 555 static Instance* transition_sentinel_;
539 static Instance* unknown_constant_; 556 static Instance* unknown_constant_;
540 static Instance* non_constant_; 557 static Instance* non_constant_;
541 static Bool* bool_true_; 558 static Bool* bool_true_;
542 static Bool* bool_false_; 559 static Bool* bool_false_;
560 static Smi* sentinel_smi_;
hausner 2013/05/31 16:40:25 I would name this Smi illegal_cid or something sim
siva 2013/05/31 22:35:48 Renamed it smi_illegal_cid_ On 2013/05/31 16:40:2
543 static LanguageError* snapshot_writer_error_; 561 static LanguageError* snapshot_writer_error_;
544 562
545 friend void ClassTable::Register(const Class& cls); 563 friend void ClassTable::Register(const Class& cls);
546 friend void RawObject::Validate(Isolate* isolate) const; 564 friend void RawObject::Validate(Isolate* isolate) const;
547 friend class Closure; 565 friend class Closure;
548 friend class SnapshotReader; 566 friend class SnapshotReader;
549 friend class OneByteString; 567 friend class OneByteString;
550 friend class TwoByteString; 568 friend class TwoByteString;
551 friend class ExternalOneByteString; 569 friend class ExternalOneByteString;
552 friend class ExternalTwoByteString; 570 friend class ExternalTwoByteString;
(...skipping 2691 matching lines...) Expand 10 before | Expand all | Expand 10 after
3244 void set_deopt_id(intptr_t value) const; 3262 void set_deopt_id(intptr_t value) const;
3245 void set_num_args_tested(intptr_t value) const; 3263 void set_num_args_tested(intptr_t value) const;
3246 void set_ic_data(const Array& value) const; 3264 void set_ic_data(const Array& value) const;
3247 3265
3248 #if defined(DEBUG) 3266 #if defined(DEBUG)
3249 // Used in asserts to verify that a check is not added twice. 3267 // Used in asserts to verify that a check is not added twice.
3250 bool HasCheck(const GrowableArray<intptr_t>& cids) const; 3268 bool HasCheck(const GrowableArray<intptr_t>& cids) const;
3251 #endif // DEBUG 3269 #endif // DEBUG
3252 3270
3253 intptr_t TestEntryLength() const; 3271 intptr_t TestEntryLength() const;
3254 void WriteSentinel() const; 3272 void WriteSentinel(const Array& data) const;
3255 3273
3256 FINAL_HEAP_OBJECT_IMPLEMENTATION(ICData, Object); 3274 FINAL_HEAP_OBJECT_IMPLEMENTATION(ICData, Object);
3257 friend class Class; 3275 friend class Class;
3258 }; 3276 };
3259 3277
3260 3278
3261 class MegamorphicCache : public Object { 3279 class MegamorphicCache : public Object {
3262 public: 3280 public:
3263 static const int kInitialCapacity = 16; 3281 static const int kInitialCapacity = 16;
3264 static const double kLoadFactor; 3282 static const double kLoadFactor;
(...skipping 2557 matching lines...) Expand 10 before | Expand all | Expand 10 after
5822 5840
5823 5841
5824 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 5842 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
5825 intptr_t index) { 5843 intptr_t index) {
5826 return array.At((index * kEntryLength) + kTargetFunctionIndex); 5844 return array.At((index * kEntryLength) + kTargetFunctionIndex);
5827 } 5845 }
5828 5846
5829 } // namespace dart 5847 } // namespace dart
5830 5848
5831 #endif // VM_OBJECT_H_ 5849 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698