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

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

Issue 16336021: Create specific null read only handles for the frequently used types (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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) { \ 113 static Raw##object* RawCast(RawObject* raw) { \
114 ASSERT(Object::Handle(raw).Is##object()); \ 114 ASSERT(Object::Handle(raw).Is##object()); \
115 return reinterpret_cast<Raw##object*>(raw); \ 115 return reinterpret_cast<Raw##object*>(raw); \
116 } \ 116 } \
117 static Raw##object* null() { \ 117 static Raw##object* null() { \
118 return reinterpret_cast<Raw##object*>(Object::null()); \ 118 return reinterpret_cast<Raw##object*>(Object::null()); \
119 } \ 119 } \
120 static const object& null_object() { \
121 return reinterpret_cast<const object&>(Object::null_object()); \
122 } \
123 virtual const char* ToCString() const; \ 120 virtual const char* ToCString() const; \
124 static const ClassId kClassId = k##object##Cid; \ 121 static const ClassId kClassId = k##object##Cid; \
125 private: /* NOLINT */ \ 122 private: /* NOLINT */ \
126 /* Initialize the handle based on the raw_ptr in the presence of null. */ \ 123 /* Initialize the handle based on the raw_ptr in the presence of null. */ \
127 static void initializeHandle(object* obj, RawObject* raw_ptr) { \ 124 static void initializeHandle(object* obj, RawObject* raw_ptr) { \
128 if (raw_ptr != Object::null()) { \ 125 if (raw_ptr != Object::null()) { \
129 obj->SetRaw(raw_ptr); \ 126 obj->SetRaw(raw_ptr); \
130 } else { \ 127 } else { \
131 obj->raw_ = Object::null(); \ 128 obj->raw_ = Object::null(); \
132 object fake_object; \ 129 object fake_object; \
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 273
277 bool IsNotTemporaryScopedHandle() const; 274 bool IsNotTemporaryScopedHandle() const;
278 275
279 static RawObject* Clone(const Object& src, Heap::Space space = Heap::kNew); 276 static RawObject* Clone(const Object& src, Heap::Space space = Heap::kNew);
280 277
281 static Object& Handle(Isolate* isolate, RawObject* raw_ptr) { 278 static Object& Handle(Isolate* isolate, RawObject* raw_ptr) {
282 Object* obj = reinterpret_cast<Object*>(VMHandles::AllocateHandle(isolate)); 279 Object* obj = reinterpret_cast<Object*>(VMHandles::AllocateHandle(isolate));
283 initializeHandle(obj, raw_ptr); 280 initializeHandle(obj, raw_ptr);
284 return *obj; 281 return *obj;
285 } 282 }
283 static Object* ReadOnlyHandle() {
284 Object* obj = reinterpret_cast<Object*>(
285 Dart::AllocateReadOnlyHandle());
286 initializeHandle(obj, Object::null());
287 return obj;
288 }
286 289
287 static Object& Handle() { 290 static Object& Handle() {
288 return Handle(Isolate::Current(), null_); 291 return Handle(Isolate::Current(), null_);
289 } 292 }
290 293
291 static Object& Handle(Isolate* isolate) { 294 static Object& Handle(Isolate* isolate) {
292 return Handle(isolate, null_); 295 return Handle(isolate, null_);
293 } 296 }
294 297
295 static Object& Handle(RawObject* raw_ptr) { 298 static Object& Handle(RawObject* raw_ptr) {
(...skipping 13 matching lines...) Expand all
309 312
310 static Object& ZoneHandle(RawObject* raw_ptr) { 313 static Object& ZoneHandle(RawObject* raw_ptr) {
311 return ZoneHandle(Isolate::Current(), raw_ptr); 314 return ZoneHandle(Isolate::Current(), raw_ptr);
312 } 315 }
313 316
314 static RawObject* null() { return null_; } 317 static RawObject* null() { return null_; }
315 static const Object& null_object() { 318 static const Object& null_object() {
316 ASSERT(null_object_ != NULL); 319 ASSERT(null_object_ != NULL);
317 return *null_object_; 320 return *null_object_;
318 } 321 }
322 static const Array& null_array() {
323 ASSERT(null_array_ != NULL);
324 return *null_array_;
325 }
326 static const String& null_string() {
327 ASSERT(null_string_ != NULL);
328 return *null_string_;
329 }
330 static const Instance& null_instance() {
331 ASSERT(null_instance_ != NULL);
332 return *null_instance_;
333 }
334 static const AbstractTypeArguments& null_abstract_type_arguments() {
335 ASSERT(null_abstract_type_arguments_ != NULL);
336 return *null_abstract_type_arguments_;
337 }
319 static const Array& empty_array() { 338 static const Array& empty_array() {
320 ASSERT(empty_array_ != NULL); 339 ASSERT(empty_array_ != NULL);
321 return *empty_array_; 340 return *empty_array_;
322 } 341 }
323 342
324 // The sentinel is a value that cannot be produced by Dart code. 343 // The sentinel is a value that cannot be produced by Dart code.
325 // It can be used to mark special values, for example to distinguish 344 // It can be used to mark special values, for example to distinguish
326 // "uninitialized" fields. 345 // "uninitialized" fields.
327 static const Instance& sentinel() { 346 static const Instance& sentinel() {
328 ASSERT(sentinel_ != NULL); 347 ASSERT(sentinel_ != NULL);
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 static RawClass* megamorphic_cache_class_; // Class of MegamorphiCache. 562 static RawClass* megamorphic_cache_class_; // Class of MegamorphiCache.
544 static RawClass* subtypetestcache_class_; // Class of SubtypeTestCache. 563 static RawClass* subtypetestcache_class_; // Class of SubtypeTestCache.
545 static RawClass* api_error_class_; // Class of ApiError. 564 static RawClass* api_error_class_; // Class of ApiError.
546 static RawClass* language_error_class_; // Class of LanguageError. 565 static RawClass* language_error_class_; // Class of LanguageError.
547 static RawClass* unhandled_exception_class_; // Class of UnhandledException. 566 static RawClass* unhandled_exception_class_; // Class of UnhandledException.
548 static RawClass* unwind_error_class_; // Class of UnwindError. 567 static RawClass* unwind_error_class_; // Class of UnwindError.
549 568
550 // The static values below are read-only handle pointers for singleton 569 // The static values below are read-only handle pointers for singleton
551 // objects that are shared between the different isolates. 570 // objects that are shared between the different isolates.
552 static Object* null_object_; 571 static Object* null_object_;
572 static Array* null_array_;
573 static String* null_string_;
574 static Instance* null_instance_;
575 static AbstractTypeArguments* null_abstract_type_arguments_;
553 static Array* empty_array_; 576 static Array* empty_array_;
554 static Instance* sentinel_; 577 static Instance* sentinel_;
555 static Instance* transition_sentinel_; 578 static Instance* transition_sentinel_;
556 static Instance* unknown_constant_; 579 static Instance* unknown_constant_;
557 static Instance* non_constant_; 580 static Instance* non_constant_;
558 static Bool* bool_true_; 581 static Bool* bool_true_;
559 static Bool* bool_false_; 582 static Bool* bool_false_;
560 static Smi* smi_illegal_cid_; 583 static Smi* smi_illegal_cid_;
561 static LanguageError* snapshot_writer_error_; 584 static LanguageError* snapshot_writer_error_;
562 585
(...skipping 5277 matching lines...) Expand 10 before | Expand all | Expand 10 after
5840 5863
5841 5864
5842 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 5865 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
5843 intptr_t index) { 5866 intptr_t index) {
5844 return array.At((index * kEntryLength) + kTargetFunctionIndex); 5867 return array.At((index * kEntryLength) + kTargetFunctionIndex);
5845 } 5868 }
5846 5869
5847 } // namespace dart 5870 } // namespace dart
5848 5871
5849 #endif // VM_OBJECT_H_ 5872 #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