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

Side by Side Diff: vm/object.cc

Issue 10827249: - Register canonical names for internal VM classes and get rid of the method GetSingletonClassName (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 4 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 | « vm/object.h ('k') | vm/object_store.h » ('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 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 cpp_vtable Object::builtin_vtables_[kNumPredefinedCids] = { 0 }; 52 cpp_vtable Object::builtin_vtables_[kNumPredefinedCids] = { 0 };
53 cpp_vtable Smi::handle_vtable_ = 0; 53 cpp_vtable Smi::handle_vtable_ = 0;
54 54
55 // These are initialized to a value that will force a illegal memory access if 55 // These are initialized to a value that will force a illegal memory access if
56 // they are being used. 56 // they are being used.
57 #if defined(RAW_NULL) 57 #if defined(RAW_NULL)
58 #error RAW_NULL should not be defined. 58 #error RAW_NULL should not be defined.
59 #endif 59 #endif
60 #define RAW_NULL kHeapObjectTag 60 #define RAW_NULL kHeapObjectTag
61 RawObject* Object::null_ = reinterpret_cast<RawInstance*>(RAW_NULL); 61 RawObject* Object::null_ = reinterpret_cast<RawInstance*>(RAW_NULL);
62 RawArray* Object::empty_array_ = reinterpret_cast<RawArray*>(RAW_NULL);
62 RawInstance* Object::sentinel_ = reinterpret_cast<RawInstance*>(RAW_NULL); 63 RawInstance* Object::sentinel_ = reinterpret_cast<RawInstance*>(RAW_NULL);
63 RawInstance* Object::transition_sentinel_ = 64 RawInstance* Object::transition_sentinel_ =
64 reinterpret_cast<RawInstance*>(RAW_NULL); 65 reinterpret_cast<RawInstance*>(RAW_NULL);
65 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 66 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
66 RawClass* Object::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 67 RawClass* Object::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
67 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 68 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
68 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 69 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
69 RawClass* Object::unresolved_class_class_ = 70 RawClass* Object::unresolved_class_class_ =
70 reinterpret_cast<RawClass*>(RAW_NULL); 71 reinterpret_cast<RawClass*>(RAW_NULL);
71 RawClass* Object::type_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 72 RawClass* Object::type_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 if (is_setter) { 179 if (is_setter) {
179 // Setters need to end with '='. 180 // Setters need to end with '='.
180 const String& suffix = String::Handle(Symbols::Equals()); 181 const String& suffix = String::Handle(Symbols::Equals());
181 return String::Concat(result, suffix); 182 return String::Concat(result, suffix);
182 } 183 }
183 184
184 return result.raw(); 185 return result.raw();
185 } 186 }
186 187
187 188
188 // TODO(asiva): Get rid of this function once we have predefined names for
189 // the shared classes and set that up in the name field.
190 const char* Object::GetSingletonClassName(intptr_t class_id) {
191 switch (class_id) {
192 case kClassCid: return "Class";
193 case kNullCid: return "Null";
194 case kDynamicCid: return "Dynamic";
195 case kVoidCid: return "void";
196 case kUnresolvedClassCid: return "UnresolvedClass";
197 case kTypeCid: return "Type";
198 case kTypeParameterCid: return "TypeParameter";
199 case kTypeArgumentsCid: return "TypeArguments";
200 case kInstantiatedTypeArgumentsCid: return "InstantiatedTypeArguments";
201 case kFunctionCid: return "Function";
202 case kFieldCid: return "Field";
203 case kLiteralTokenCid: return "LiteralToken";
204 case kTokenStreamCid: return "TokenStream";
205 case kScriptCid: return "Script";
206 case kLibraryCid: return "Library";
207 case kLibraryPrefixCid: return "LibraryPrefix";
208 case kCodeCid: return "Code";
209 case kInstructionsCid: return "Instructions";
210 case kPcDescriptorsCid: return "PcDescriptors";
211 case kStackmapCid: return "Stackmap";
212 case kLocalVarDescriptorsCid: return "LocalVarDescriptors";
213 case kExceptionHandlersCid: return "ExceptionHandlers";
214 case kContextCid: return "Context";
215 case kContextScopeCid: return "ContextScope";
216 case kICDataCid: return "ICData";
217 case kSubtypeTestCacheCid: return "SubtypeTestCache";
218 case kApiErrorCid: return "ApiError";
219 case kLanguageErrorCid: return "LanguageError";
220 case kUnhandledExceptionCid: return "UnhandledException";
221 case kUnwindErrorCid: return "UnwindError";
222 default: break;
223 }
224 UNREACHABLE();
225 return NULL;
226 }
227
228
229 void Object::InitOnce() { 189 void Object::InitOnce() {
230 // TODO(iposva): NoGCScope needs to be added here. 190 // TODO(iposva): NoGCScope needs to be added here.
231 ASSERT(class_class() == null_); 191 ASSERT(class_class() == null_);
232 // Initialize the static vtable values. 192 // Initialize the static vtable values.
233 { 193 {
234 Object fake_object; 194 Object fake_object;
235 Smi fake_smi; 195 Smi fake_smi;
236 Object::handle_vtable_ = fake_object.vtable(); 196 Object::handle_vtable_ = fake_object.vtable();
237 Smi::handle_vtable_ = fake_smi.vtable(); 197 Smi::handle_vtable_ = fake_smi.vtable();
238 } 198 }
239 199
240 Isolate* isolate = Isolate::Current(); 200 Isolate* isolate = Isolate::Current();
241 Heap* heap = isolate->heap(); 201 Heap* heap = isolate->heap();
242 // Allocate and initialize the null instance, except its class_ field. 202 // Allocate and initialize the null instance.
243 // 'null_' must be the first object allocated as it is used in allocation to 203 // 'null_' must be the first object allocated as it is used in allocation to
244 // clear the object. 204 // clear the object.
245 { 205 {
246 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld); 206 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld);
247 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag); 207 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag);
248 // The call below is using 'null_' to initialize itself. 208 // The call below is using 'null_' to initialize itself.
249 InitializeObject(address, kNullCid, Instance::InstanceSize()); 209 InitializeObject(address, kNullCid, Instance::InstanceSize());
250 } 210 }
251 211
252 // Initialize object_store empty array to null_ in order to be able to check 212 // Initialize object_store empty array to null_ in order to be able to check
253 // if the empty array was allocated (RAW_NULL is not available). 213 // if the empty array was allocated (RAW_NULL is not available).
254 isolate->object_store()->set_empty_array(Array::Handle()); 214 empty_array_ = Array::null();
255 215
256 Class& cls = Class::Handle(); 216 Class& cls = Class::Handle();
257 217
258 // Allocate and initialize the class class. 218 // Allocate and initialize the class class.
259 { 219 {
260 intptr_t size = Class::InstanceSize(); 220 intptr_t size = Class::InstanceSize();
261 uword address = heap->Allocate(size, Heap::kOld); 221 uword address = heap->Allocate(size, Heap::kOld);
262 class_class_ = reinterpret_cast<RawClass*>(address + kHeapObjectTag); 222 class_class_ = reinterpret_cast<RawClass*>(address + kHeapObjectTag);
263 InitializeObject(address, Class::kClassId, size); 223 InitializeObject(address, Class::kClassId, size);
264 224
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 sentinel ^= 256 sentinel ^=
297 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); 257 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld);
298 sentinel_ = sentinel.raw(); 258 sentinel_ = sentinel.raw();
299 259
300 Instance& transition_sentinel = Instance::Handle(); 260 Instance& transition_sentinel = Instance::Handle();
301 transition_sentinel ^= 261 transition_sentinel ^=
302 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); 262 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld);
303 transition_sentinel_ = transition_sentinel.raw(); 263 transition_sentinel_ = transition_sentinel.raw();
304 } 264 }
305 265
306 // The interface "Dynamic" is not a VM internal class. It is the type class of
307 // the "unknown type". For efficiency, we allocate it in the VM isolate.
308 // Therefore, it cannot have a heap allocated name (the name is hard coded,
309 // see GetSingletonClassName) and its array fields cannot be set to the empty
310 // array, but remain null.
311 //
312 // TODO(turnidge): Once the empty array is allocated in the vm
313 // isolate, use it here.
314 cls = Class::New<Instance>(kDynamicCid); 266 cls = Class::New<Instance>(kDynamicCid);
315 cls.set_is_finalized(); 267 cls.set_is_finalized();
316 cls.set_is_interface(); 268 cls.set_is_interface();
317 dynamic_class_ = cls.raw(); 269 dynamic_class_ = cls.raw();
318 270
319 // Allocate the remaining VM internal classes. 271 // Allocate the remaining VM internal classes.
320 cls = Class::New<UnresolvedClass>(); 272 cls = Class::New<UnresolvedClass>();
321 unresolved_class_class_ = cls.raw(); 273 unresolved_class_class_ = cls.raw();
322 274
323 cls = Class::New<Instance>(kVoidCid); 275 cls = Class::New<Instance>(kVoidCid);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 356
405 ASSERT(class_class() != null_); 357 ASSERT(class_class() != null_);
406 358
407 // Pre-allocate the Array and OneByteString class in the vm isolate so that 359 // Pre-allocate the Array and OneByteString class in the vm isolate so that
408 // we can create a symbol table and populate it with some frequently used 360 // we can create a symbol table and populate it with some frequently used
409 // strings as symbols. 361 // strings as symbols.
410 cls = Class::New<Array>(); 362 cls = Class::New<Array>();
411 isolate->object_store()->set_array_class(cls); 363 isolate->object_store()->set_array_class(cls);
412 cls = Class::New<OneByteString>(); 364 cls = Class::New<OneByteString>();
413 isolate->object_store()->set_one_byte_string_class(cls); 365 isolate->object_store()->set_one_byte_string_class(cls);
366
367 // Allocate and initialize the empty_array instance.
368 {
369 uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld);
370 empty_array_ = reinterpret_cast<RawArray*>(address + kHeapObjectTag);
371 InitializeObject(address, kArrayCid, Array::InstanceSize(0));
372 empty_array_->ptr()->length_ = Smi::New(0);
373 }
374 }
375
376
377 #define SET_CLASS_NAME(class_name, name) \
378 cls = class_name##_class(); \
379 str = Symbols::name(); \
380 cls.set_name(str); \
381
382 void Object::RegisterSingletonClassNames() {
383 Class& cls = Class::Handle();
384 String& str = String::Handle();
385
386 SET_CLASS_NAME(class, Class);
387 SET_CLASS_NAME(null, Null);
388 SET_CLASS_NAME(dynamic, Dynamic);
389 SET_CLASS_NAME(void, Void);
390 SET_CLASS_NAME(unresolved_class, UnresolvedClass);
391 SET_CLASS_NAME(type, Type);
392 SET_CLASS_NAME(type_parameter, TypeParameter);
393 SET_CLASS_NAME(type_arguments, TypeArguments);
394 SET_CLASS_NAME(instantiated_type_arguments, InstantiatedTypeArguments);
395 SET_CLASS_NAME(function, Function);
396 SET_CLASS_NAME(field, Field);
397 SET_CLASS_NAME(literal_token, LiteralToken);
398 SET_CLASS_NAME(token_stream, TokenStream);
399 SET_CLASS_NAME(script, Script);
400 SET_CLASS_NAME(library, LibraryClass);
401 SET_CLASS_NAME(library_prefix, LibraryPrefix);
402 SET_CLASS_NAME(code, Code);
403 SET_CLASS_NAME(instructions, Instructions);
404 SET_CLASS_NAME(pc_descriptors, PcDescriptors);
405 SET_CLASS_NAME(stackmap, Stackmap);
406 SET_CLASS_NAME(var_descriptors, LocalVarDescriptors);
407 SET_CLASS_NAME(exception_handlers, ExceptionHandlers);
408 SET_CLASS_NAME(deopt_info, DeoptInfo);
409 SET_CLASS_NAME(context, Context);
410 SET_CLASS_NAME(context_scope, ContextScope);
411 SET_CLASS_NAME(icdata, ICData);
412 SET_CLASS_NAME(subtypetestcache, SubtypeTestCache);
413 SET_CLASS_NAME(api_error, ApiError);
414 SET_CLASS_NAME(language_error, LanguageError);
415 SET_CLASS_NAME(unhandled_exception, UnhandledException);
416 SET_CLASS_NAME(unwind_error, UnwindError);
414 } 417 }
415 418
416 419
417 RawClass* Object::CreateAndRegisterInterface(const char* cname, 420 RawClass* Object::CreateAndRegisterInterface(const char* cname,
418 const Script& script, 421 const Script& script,
419 const Library& lib) { 422 const Library& lib) {
420 const String& name = String::Handle(Symbols::New(cname)); 423 const String& name = String::Handle(Symbols::New(cname));
421 const Class& cls = Class::Handle( 424 const Class& cls = Class::Handle(
422 Class::NewInterface(name, script, Scanner::kDummyTokenIndex)); 425 Class::NewInterface(name, script, Scanner::kDummyTokenIndex));
423 lib.AddClass(cls); 426 lib.AddClass(cls);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 // initialize array class first. 464 // initialize array class first.
462 cls = Class::New<Array>(); 465 cls = Class::New<Array>();
463 object_store->set_array_class(cls); 466 object_store->set_array_class(cls);
464 467
465 // Array and ImmutableArray are the only VM classes that are parameterized. 468 // Array and ImmutableArray are the only VM classes that are parameterized.
466 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we 469 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we
467 // need to set the offset of their type_arguments_ field, which is explicitly 470 // need to set the offset of their type_arguments_ field, which is explicitly
468 // declared in RawArray. 471 // declared in RawArray.
469 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset()); 472 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset());
470 473
471 Array& empty_array = Array::Handle();
472 empty_array = Array::New(0, Heap::kOld);
473 object_store->set_empty_array(empty_array);
474
475 // Re-initialize fields of the array class now that the empty array
476 // has been created.
477 cls.InitEmptyFields();
478
479 // Set up the growable object array class (Has to be done after the array 474 // Set up the growable object array class (Has to be done after the array
480 // class is setup as one of its field is an array object). 475 // class is setup as one of its field is an array object).
481 cls = Class::New<GrowableObjectArray>(); 476 cls = Class::New<GrowableObjectArray>();
482 object_store->set_growable_object_array_class(cls); 477 object_store->set_growable_object_array_class(cls);
483 cls.set_type_arguments_instance_field_offset( 478 cls.set_type_arguments_instance_field_offset(
484 GrowableObjectArray::type_arguments_offset()); 479 GrowableObjectArray::type_arguments_offset());
485 480
486 // canonical_type_arguments_ are NULL terminated. 481 // canonical_type_arguments_ are NULL terminated.
487 array = Array::New(4); 482 array = Array::New(4);
488 object_store->set_canonical_type_arguments(array); 483 object_store->set_canonical_type_arguments(array);
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 ObjectStore* object_store = isolate->object_store(); 823 ObjectStore* object_store = isolate->object_store();
829 824
830 Class& cls = Class::Handle(); 825 Class& cls = Class::Handle();
831 826
832 // Set up empty classes in the object store, these will get 827 // Set up empty classes in the object store, these will get
833 // initialized correctly when we read from the snapshot. 828 // initialized correctly when we read from the snapshot.
834 // This is done to allow bootstrapping of reading classes from the snapshot. 829 // This is done to allow bootstrapping of reading classes from the snapshot.
835 cls = Class::New<Array>(); 830 cls = Class::New<Array>();
836 object_store->set_array_class(cls); 831 object_store->set_array_class(cls);
837 832
838 Array& empty_array = Array::Handle();
839 empty_array = Array::New(0);
840 object_store->set_empty_array(empty_array);
841
842 cls = Class::New<ImmutableArray>(); 833 cls = Class::New<ImmutableArray>();
843 object_store->set_immutable_array_class(cls); 834 object_store->set_immutable_array_class(cls);
844 835
845 cls = Class::New<GrowableObjectArray>(); 836 cls = Class::New<GrowableObjectArray>();
846 object_store->set_growable_object_array_class(cls); 837 object_store->set_growable_object_array_class(cls);
847 838
848 cls = Class::New<Int8Array>(); 839 cls = Class::New<Int8Array>();
849 object_store->set_int8_array_class(cls); 840 object_store->set_int8_array_class(cls);
850 841
851 cls = Class::New<Uint8Array>(); 842 cls = Class::New<Uint8Array>();
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 memmove(raw_obj->ptr(), src.raw()->ptr(), size); 1021 memmove(raw_obj->ptr(), src.raw()->ptr(), size);
1031 if (space == Heap::kOld) { 1022 if (space == Heap::kOld) {
1032 StoreBufferObjectPointerVisitor visitor(Isolate::Current()); 1023 StoreBufferObjectPointerVisitor visitor(Isolate::Current());
1033 raw_obj->VisitPointers(&visitor); 1024 raw_obj->VisitPointers(&visitor);
1034 } 1025 }
1035 return raw_obj; 1026 return raw_obj;
1036 } 1027 }
1037 1028
1038 1029
1039 RawString* Class::Name() const { 1030 RawString* Class::Name() const {
1040 if (raw_ptr()->name_ != String::null()) { 1031 ASSERT(raw_ptr()->name_ != String::null());
1041 return raw_ptr()->name_; 1032 return raw_ptr()->name_;
1042 }
1043 ASSERT(class_class() != Class::null()); // class_class_ should be set up.
1044 return Symbols::New(GetSingletonClassName(raw_ptr()->id_));
1045 } 1033 }
1046 1034
1047 1035
1048 RawString* Class::UserVisibleName() const { 1036 RawString* Class::UserVisibleName() const {
1049 if (FLAG_show_internal_names) { 1037 if (FLAG_show_internal_names) {
1050 return Name(); 1038 return Name();
1051 } 1039 }
1052 switch (id()) { 1040 switch (id()) {
1053 case kIntegerCid: 1041 case kIntegerCid:
1054 case kSmiCid: 1042 case kSmiCid:
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 result.raw_ptr()->num_native_fields_ = 0; 1167 result.raw_ptr()->num_native_fields_ = 0;
1180 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; 1168 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex;
1181 result.InitEmptyFields(); 1169 result.InitEmptyFields();
1182 Isolate::Current()->class_table()->Register(result); 1170 Isolate::Current()->class_table()->Register(result);
1183 return result.raw(); 1171 return result.raw();
1184 } 1172 }
1185 1173
1186 1174
1187 // Initialize class fields of type Array with empty array. 1175 // Initialize class fields of type Array with empty array.
1188 void Class::InitEmptyFields() { 1176 void Class::InitEmptyFields() {
1189 const Array& empty_array = Array::Handle(Array::Empty()); 1177 if (Object::empty_array() == Array::null()) {
1190 if (empty_array.IsNull()) {
1191 // The empty array has not been initialized yet. 1178 // The empty array has not been initialized yet.
1192 return; 1179 return;
1193 } 1180 }
1194 StorePointer(&raw_ptr()->interfaces_, empty_array.raw()); 1181 StorePointer(&raw_ptr()->interfaces_, Object::empty_array());
1195 // TODO(srdjan): Make functions_cache growable and start with a smaller size. 1182 StorePointer(&raw_ptr()->constants_, Object::empty_array());
1196 Array& fcache = 1183 StorePointer(&raw_ptr()->canonical_types_, Object::empty_array());
1197 Array::Handle(Array::New(FunctionsCache::kNumEntries * 32, Heap::kOld)); 1184 StorePointer(&raw_ptr()->functions_, Object::empty_array());
1198 StorePointer(&raw_ptr()->functions_cache_, fcache.raw()); 1185 StorePointer(&raw_ptr()->fields_, Object::empty_array());
1199 StorePointer(&raw_ptr()->constants_, empty_array.raw()); 1186 }
1200 StorePointer(&raw_ptr()->canonical_types_, empty_array.raw()); 1187
1201 StorePointer(&raw_ptr()->functions_, empty_array.raw()); 1188
1202 StorePointer(&raw_ptr()->fields_, empty_array.raw()); 1189 void Class::InitFunctionsCache() const {
1190 // TODO(srdjan): Make functions_cache growable and start with smaller size.
1191 StorePointer(&raw_ptr()->functions_cache_,
1192 Array::New(FunctionsCache::kNumEntries * 32, Heap::kOld));
1203 } 1193 }
1204 1194
1205 1195
1206 bool Class::HasInstanceFields() const { 1196 bool Class::HasInstanceFields() const {
1207 const Array& field_array = Array::Handle(fields()); 1197 const Array& field_array = Array::Handle(fields());
1208 Field& field = Field::Handle(); 1198 Field& field = Field::Handle();
1209 for (intptr_t i = 0; i < field_array.Length(); ++i) { 1199 for (intptr_t i = 0; i < field_array.Length(); ++i) {
1210 field ^= field_array.At(i); 1200 field ^= field_array.At(i);
1211 if (!field.is_static()) { 1201 if (!field.is_static()) {
1212 return true; 1202 return true;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 // way as the owner class of its non-static signature function. 1547 // way as the owner class of its non-static signature function.
1558 // It is not type parameterized if its signature function is static. 1548 // It is not type parameterized if its signature function is static.
1559 if (!signature_function.is_static() && 1549 if (!signature_function.is_static() &&
1560 (owner_class.NumTypeParameters() > 0) && 1550 (owner_class.NumTypeParameters() > 0) &&
1561 !signature_function.HasInstantiatedSignature()) { 1551 !signature_function.HasInstantiatedSignature()) {
1562 type_parameters = owner_class.type_parameters(); 1552 type_parameters = owner_class.type_parameters();
1563 } 1553 }
1564 const intptr_t token_pos = signature_function.token_pos(); 1554 const intptr_t token_pos = signature_function.token_pos();
1565 Class& result = Class::Handle(New<Closure>(name, script, token_pos)); 1555 Class& result = Class::Handle(New<Closure>(name, script, token_pos));
1566 const Type& super_type = Type::Handle(Type::ObjectType()); 1556 const Type& super_type = Type::Handle(Type::ObjectType());
1557 const Array& empty_array = Array::Handle(Object::empty_array());
1567 ASSERT(!super_type.IsNull()); 1558 ASSERT(!super_type.IsNull());
1568 result.set_super_type(super_type); 1559 result.set_super_type(super_type);
1569 result.set_signature_function(signature_function); 1560 result.set_signature_function(signature_function);
1570 result.set_type_parameters(type_parameters); 1561 result.set_type_parameters(type_parameters);
1571 result.SetFields(Array::Handle(Array::Empty())); 1562 result.SetFields(empty_array);
1572 result.SetFunctions(Array::Handle(Array::Empty())); 1563 result.SetFunctions(empty_array);
1573 result.set_type_arguments_instance_field_offset( 1564 result.set_type_arguments_instance_field_offset(
1574 Closure::type_arguments_offset()); 1565 Closure::type_arguments_offset());
1575 // Implements interface "Function". 1566 // Implements interface "Function".
1576 const Type& function_interface = Type::Handle(Type::FunctionInterface()); 1567 const Type& function_interface = Type::Handle(Type::FunctionInterface());
1577 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); 1568 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld));
1578 interfaces.SetAt(0, function_interface); 1569 interfaces.SetAt(0, function_interface);
1579 result.set_interfaces(interfaces); 1570 result.set_interfaces(interfaces);
1580 // Unless the signature function already has a signature class, create a 1571 // Unless the signature function already has a signature class, create a
1581 // canonical signature class by having the signature function point back to 1572 // canonical signature class by having the signature function point back to
1582 // the signature class. 1573 // the signature class.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 UNREACHABLE(); 1607 UNREACHABLE();
1617 return Class::null(); 1608 return Class::null();
1618 } 1609 }
1619 1610
1620 1611
1621 RawClass* Class::NewNativeWrapper(Library* library, 1612 RawClass* Class::NewNativeWrapper(Library* library,
1622 const String& name, 1613 const String& name,
1623 int field_count) { 1614 int field_count) {
1624 Class& cls = Class::Handle(library->LookupClass(name)); 1615 Class& cls = Class::Handle(library->LookupClass(name));
1625 if (cls.IsNull()) { 1616 if (cls.IsNull()) {
1617 const Array& empty_array = Array::Handle(Object::empty_array());
1626 cls = New<Instance>(name, Script::Handle(), Scanner::kDummyTokenIndex); 1618 cls = New<Instance>(name, Script::Handle(), Scanner::kDummyTokenIndex);
1627 cls.SetFields(Array::Handle(Array::Empty())); 1619 cls.SetFields(empty_array);
1628 cls.SetFunctions(Array::Handle(Array::Empty())); 1620 cls.SetFunctions(empty_array);
1629 // Set super class to Object. 1621 // Set super class to Object.
1630 cls.set_super_type(Type::Handle(Type::ObjectType())); 1622 cls.set_super_type(Type::Handle(Type::ObjectType()));
1631 // Compute instance size. 1623 // Compute instance size.
1632 intptr_t instance_size = (field_count * kWordSize) + sizeof(RawObject); 1624 intptr_t instance_size = (field_count * kWordSize) + sizeof(RawObject);
1633 cls.set_instance_size(RoundedAllocationSize(instance_size)); 1625 cls.set_instance_size(RoundedAllocationSize(instance_size));
1634 cls.set_next_field_offset(instance_size); 1626 cls.set_next_field_offset(instance_size);
1635 cls.set_num_native_fields(field_count); 1627 cls.set_num_native_fields(field_count);
1636 cls.set_is_finalized(); 1628 cls.set_is_finalized();
1637 library->AddClass(cls); 1629 library->AddClass(cls);
1638 return cls.raw(); 1630 return cls.raw();
(...skipping 2376 matching lines...) Expand 10 before | Expand all | Expand 10 after
4015 RawFunction::Kind kind, 4007 RawFunction::Kind kind,
4016 bool is_static, 4008 bool is_static,
4017 bool is_const, 4009 bool is_const,
4018 bool is_abstract, 4010 bool is_abstract,
4019 bool is_external, 4011 bool is_external,
4020 const Class& owner, 4012 const Class& owner,
4021 intptr_t token_pos) { 4013 intptr_t token_pos) {
4022 ASSERT(name.IsOneByteString()); 4014 ASSERT(name.IsOneByteString());
4023 ASSERT(!owner.IsNull()); 4015 ASSERT(!owner.IsNull());
4024 const Function& result = Function::Handle(Function::New()); 4016 const Function& result = Function::Handle(Function::New());
4025 result.set_parameter_types(Array::Handle(Array::Empty())); 4017 const Array& empty_array = Array::Handle(Object::empty_array());
4026 result.set_parameter_names(Array::Handle(Array::Empty())); 4018 result.set_parameter_types(empty_array);
4019 result.set_parameter_names(empty_array);
4027 result.set_name(name); 4020 result.set_name(name);
4028 result.set_kind(kind); 4021 result.set_kind(kind);
4029 result.set_is_static(is_static); 4022 result.set_is_static(is_static);
4030 result.set_is_const(is_const); 4023 result.set_is_const(is_const);
4031 result.set_is_abstract(is_abstract); 4024 result.set_is_abstract(is_abstract);
4032 result.set_is_external(is_external); 4025 result.set_is_external(is_external);
4033 result.set_owner(owner); 4026 result.set_owner(owner);
4034 result.set_token_pos(token_pos); 4027 result.set_token_pos(token_pos);
4035 result.set_end_token_pos(token_pos); 4028 result.set_end_token_pos(token_pos);
4036 result.set_num_fixed_parameters(0); 4029 result.set_num_fixed_parameters(0);
(...skipping 2000 matching lines...) Expand 10 before | Expand all | Expand 10 after
6037 return reinterpret_cast<RawLibrary*>(raw); 6030 return reinterpret_cast<RawLibrary*>(raw);
6038 } 6031 }
6039 6032
6040 6033
6041 RawLibrary* Library::NewLibraryHelper(const String& url, 6034 RawLibrary* Library::NewLibraryHelper(const String& url,
6042 bool import_core_lib) { 6035 bool import_core_lib) {
6043 const Library& result = Library::Handle(Library::New()); 6036 const Library& result = Library::Handle(Library::New());
6044 result.StorePointer(&result.raw_ptr()->name_, url.raw()); 6037 result.StorePointer(&result.raw_ptr()->name_, url.raw());
6045 result.StorePointer(&result.raw_ptr()->url_, url.raw()); 6038 result.StorePointer(&result.raw_ptr()->url_, url.raw());
6046 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result); 6039 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result);
6047 result.raw_ptr()->dictionary_ = Array::Empty(); 6040 result.raw_ptr()->dictionary_ = Object::empty_array();
6048 result.raw_ptr()->anonymous_classes_ = Array::Empty(); 6041 result.raw_ptr()->anonymous_classes_ = Object::empty_array();
6049 result.raw_ptr()->num_anonymous_ = 0; 6042 result.raw_ptr()->num_anonymous_ = 0;
6050 result.raw_ptr()->imports_ = Array::Empty(); 6043 result.raw_ptr()->imports_ = Object::empty_array();
6051 result.raw_ptr()->loaded_scripts_ = Array::null(); 6044 result.raw_ptr()->loaded_scripts_ = Array::null();
6052 result.set_native_entry_resolver(NULL); 6045 result.set_native_entry_resolver(NULL);
6053 result.raw_ptr()->corelib_imported_ = true; 6046 result.raw_ptr()->corelib_imported_ = true;
6054 result.set_debuggable(false); 6047 result.set_debuggable(false);
6055 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; 6048 result.raw_ptr()->load_state_ = RawLibrary::kAllocated;
6056 result.raw_ptr()->index_ = -1; 6049 result.raw_ptr()->index_ = -1;
6057 result.InitClassDictionary(); 6050 result.InitClassDictionary();
6058 result.InitImportList(); 6051 result.InitImportList();
6059 result.InitImportedIntoList(); 6052 result.InitImportedIntoList();
6060 if (import_core_lib) { 6053 if (import_core_lib) {
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after
7007 } 7000 }
7008 7001
7009 7002
7010 Code::Comments& Code::Comments::New(intptr_t count) { 7003 Code::Comments& Code::Comments::New(intptr_t count) {
7011 Comments* comments; 7004 Comments* comments;
7012 if (count < 0 || count > (kIntptrMax / kNumberOfEntries)) { 7005 if (count < 0 || count > (kIntptrMax / kNumberOfEntries)) {
7013 // This should be caught before we reach here. 7006 // This should be caught before we reach here.
7014 FATAL1("Fatal error in Code::Comments::New: invalid count %ld\n", count); 7007 FATAL1("Fatal error in Code::Comments::New: invalid count %ld\n", count);
7015 } 7008 }
7016 if (count == 0) { 7009 if (count == 0) {
7017 comments = new Comments(Array::Empty()); 7010 comments = new Comments(Object::empty_array());
7018 } else { 7011 } else {
7019 comments = new Comments(Array::New(count * kNumberOfEntries)); 7012 comments = new Comments(Array::New(count * kNumberOfEntries));
7020 } 7013 }
7021 return *comments; 7014 return *comments;
7022 } 7015 }
7023 7016
7024 7017
7025 intptr_t Code::Comments::Length() const { 7018 intptr_t Code::Comments::Length() const {
7026 if (comments_.IsNull()) { 7019 if (comments_.IsNull()) {
7027 return 0; 7020 return 0;
(...skipping 2945 matching lines...) Expand 10 before | Expand all | Expand 10 after
9973 ASSERT(new_length != len); // Unnecessary copying of array. 9966 ASSERT(new_length != len); // Unnecessary copying of array.
9974 Object& obj = Object::Handle(); 9967 Object& obj = Object::Handle();
9975 for (int i = 0; i < len; i++) { 9968 for (int i = 0; i < len; i++) {
9976 obj = source.At(i); 9969 obj = source.At(i);
9977 result.SetAt(i, obj); 9970 result.SetAt(i, obj);
9978 } 9971 }
9979 return result.raw(); 9972 return result.raw();
9980 } 9973 }
9981 9974
9982 9975
9983 RawArray* Array::Empty() {
9984 return Isolate::Current()->object_store()->empty_array();
9985 }
9986
9987
9988 RawArray* Array::MakeArray(const GrowableObjectArray& growable_array) { 9976 RawArray* Array::MakeArray(const GrowableObjectArray& growable_array) {
9989 intptr_t used_len = growable_array.Length(); 9977 intptr_t used_len = growable_array.Length();
9990 intptr_t capacity_len = growable_array.Capacity(); 9978 intptr_t capacity_len = growable_array.Capacity();
9991 Isolate* isolate = Isolate::Current(); 9979 Isolate* isolate = Isolate::Current();
9992 const Array& array = Array::Handle(isolate, growable_array.data()); 9980 const Array& array = Array::Handle(isolate, growable_array.data());
9993 const Array& new_array = Array::Handle(isolate, Array::Empty()); 9981 const Array& new_array = Array::Handle(isolate, Object::empty_array());
9994 intptr_t capacity_size = Array::InstanceSize(capacity_len); 9982 intptr_t capacity_size = Array::InstanceSize(capacity_len);
9995 intptr_t used_size = Array::InstanceSize(used_len); 9983 intptr_t used_size = Array::InstanceSize(used_len);
9996 NoGCScope no_gc; 9984 NoGCScope no_gc;
9997 9985
9998 // Update the size in the header field and length of the array object. 9986 // Update the size in the header field and length of the array object.
9999 uword tags = array.raw_ptr()->tags_; 9987 uword tags = array.raw_ptr()->tags_;
10000 ASSERT(kArrayCid == RawObject::ClassIdTag::decode(tags)); 9988 ASSERT(kArrayCid == RawObject::ClassIdTag::decode(tags));
10001 tags = RawObject::SizeTag::update(used_size, tags); 9989 tags = RawObject::SizeTag::update(used_size, tags);
10002 array.raw_ptr()->tags_ = tags; 9990 array.raw_ptr()->tags_ = tags;
10003 array.SetLength(used_len); 9991 array.SetLength(used_len);
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
11053 const char* JSRegExp::ToCString() const { 11041 const char* JSRegExp::ToCString() const {
11054 const String& str = String::Handle(pattern()); 11042 const String& str = String::Handle(pattern());
11055 const char* format = "JSRegExp: pattern=%s flags=%s"; 11043 const char* format = "JSRegExp: pattern=%s flags=%s";
11056 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 11044 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
11057 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); 11045 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
11058 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 11046 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
11059 return chars; 11047 return chars;
11060 } 11048 }
11061 11049
11062 } // namespace dart 11050 } // namespace dart
OLDNEW
« no previous file with comments | « vm/object.h ('k') | vm/object_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698