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

Unified 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 side-by-side diff with in-line comments
Download patch
« vm/object.h ('K') | « vm/object.h ('k') | vm/object_store.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vm/object.cc
===================================================================
--- vm/object.cc (revision 10450)
+++ vm/object.cc (working copy)
@@ -59,6 +59,7 @@
#endif
#define RAW_NULL kHeapObjectTag
RawObject* Object::null_ = reinterpret_cast<RawInstance*>(RAW_NULL);
+RawArray* Object::empty_array_ = reinterpret_cast<RawArray*>(RAW_NULL);
RawInstance* Object::sentinel_ = reinterpret_cast<RawInstance*>(RAW_NULL);
RawInstance* Object::transition_sentinel_ =
reinterpret_cast<RawInstance*>(RAW_NULL);
@@ -185,47 +186,6 @@
}
-// TODO(asiva): Get rid of this function once we have predefined names for
-// the shared classes and set that up in the name field.
-const char* Object::GetSingletonClassName(intptr_t class_id) {
- switch (class_id) {
- case kClassCid: return "Class";
- case kNullCid: return "Null";
- case kDynamicCid: return "Dynamic";
- case kVoidCid: return "void";
- case kUnresolvedClassCid: return "UnresolvedClass";
- case kTypeCid: return "Type";
- case kTypeParameterCid: return "TypeParameter";
- case kTypeArgumentsCid: return "TypeArguments";
- case kInstantiatedTypeArgumentsCid: return "InstantiatedTypeArguments";
- case kFunctionCid: return "Function";
- case kFieldCid: return "Field";
- case kLiteralTokenCid: return "LiteralToken";
- case kTokenStreamCid: return "TokenStream";
- case kScriptCid: return "Script";
- case kLibraryCid: return "Library";
- case kLibraryPrefixCid: return "LibraryPrefix";
- case kCodeCid: return "Code";
- case kInstructionsCid: return "Instructions";
- case kPcDescriptorsCid: return "PcDescriptors";
- case kStackmapCid: return "Stackmap";
- case kLocalVarDescriptorsCid: return "LocalVarDescriptors";
- case kExceptionHandlersCid: return "ExceptionHandlers";
- case kContextCid: return "Context";
- case kContextScopeCid: return "ContextScope";
- case kICDataCid: return "ICData";
- case kSubtypeTestCacheCid: return "SubtypeTestCache";
- case kApiErrorCid: return "ApiError";
- case kLanguageErrorCid: return "LanguageError";
- case kUnhandledExceptionCid: return "UnhandledException";
- case kUnwindErrorCid: return "UnwindError";
- default: break;
- }
- UNREACHABLE();
- return NULL;
-}
-
-
void Object::InitOnce() {
// TODO(iposva): NoGCScope needs to be added here.
ASSERT(class_class() == null_);
@@ -239,7 +199,7 @@
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
- // Allocate and initialize the null instance, except its class_ field.
+ // Allocate and initialize the null instance.
// 'null_' must be the first object allocated as it is used in allocation to
// clear the object.
{
@@ -251,7 +211,7 @@
// Initialize object_store empty array to null_ in order to be able to check
// if the empty array was allocated (RAW_NULL is not available).
- isolate->object_store()->set_empty_array(Array::Handle());
+ empty_array_ = Array::null();
Class& cls = Class::Handle();
@@ -303,14 +263,6 @@
transition_sentinel_ = transition_sentinel.raw();
}
- // The interface "Dynamic" is not a VM internal class. It is the type class of
- // the "unknown type". For efficiency, we allocate it in the VM isolate.
- // Therefore, it cannot have a heap allocated name (the name is hard coded,
- // see GetSingletonClassName) and its array fields cannot be set to the empty
- // array, but remain null.
- //
- // TODO(turnidge): Once the empty array is allocated in the vm
- // isolate, use it here.
cls = Class::New<Instance>(kDynamicCid);
cls.set_is_finalized();
cls.set_is_interface();
@@ -411,9 +363,60 @@
isolate->object_store()->set_array_class(cls);
cls = Class::New<OneByteString>();
isolate->object_store()->set_one_byte_string_class(cls);
+
+ // Allocate and initialize the empty_array instance.
+ {
+ uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld);
+ empty_array_ = reinterpret_cast<RawArray*>(address + kHeapObjectTag);
+ InitializeObject(address, kArrayCid, Array::InstanceSize(0));
+ empty_array_->ptr()->length_ = Smi::New(0);
+ }
}
+#define SET_CLASS_NAME(class_name, name) \
+ cls = class_name##_class(); \
+ str = Symbols::name(); \
+ cls.set_name(str); \
+
+void Object::RegisterSingletonClassNames() {
+ Class& cls = Class::Handle();
+ String& str = String::Handle();
+
+ SET_CLASS_NAME(class, Class);
+ SET_CLASS_NAME(null, Null);
+ SET_CLASS_NAME(dynamic, Dynamic);
+ SET_CLASS_NAME(void, Void);
+ SET_CLASS_NAME(unresolved_class, UnresolvedClass);
+ SET_CLASS_NAME(type, Type);
+ SET_CLASS_NAME(type_parameter, TypeParameter);
+ SET_CLASS_NAME(type_arguments, TypeArguments);
+ SET_CLASS_NAME(instantiated_type_arguments, InstantiatedTypeArguments);
+ SET_CLASS_NAME(function, Function);
+ SET_CLASS_NAME(field, Field);
+ SET_CLASS_NAME(literal_token, LiteralToken);
+ SET_CLASS_NAME(token_stream, TokenStream);
+ SET_CLASS_NAME(script, Script);
+ SET_CLASS_NAME(library, LibraryClass);
+ SET_CLASS_NAME(library_prefix, LibraryPrefix);
+ SET_CLASS_NAME(code, Code);
+ SET_CLASS_NAME(instructions, Instructions);
+ SET_CLASS_NAME(pc_descriptors, PcDescriptors);
+ SET_CLASS_NAME(stackmap, Stackmap);
+ SET_CLASS_NAME(var_descriptors, LocalVarDescriptors);
+ SET_CLASS_NAME(exception_handlers, ExceptionHandlers);
+ SET_CLASS_NAME(deopt_info, DeoptInfo);
+ SET_CLASS_NAME(context, Context);
+ SET_CLASS_NAME(context_scope, ContextScope);
+ SET_CLASS_NAME(icdata, ICData);
+ SET_CLASS_NAME(subtypetestcache, SubtypeTestCache);
+ SET_CLASS_NAME(api_error, ApiError);
+ SET_CLASS_NAME(language_error, LanguageError);
+ SET_CLASS_NAME(unhandled_exception, UnhandledException);
+ SET_CLASS_NAME(unwind_error, UnwindError);
+}
+
+
RawClass* Object::CreateAndRegisterInterface(const char* cname,
const Script& script,
const Library& lib) {
@@ -468,14 +471,6 @@
// declared in RawArray.
cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset());
- Array& empty_array = Array::Handle();
- empty_array = Array::New(0, Heap::kOld);
- object_store->set_empty_array(empty_array);
-
- // Re-initialize fields of the array class now that the empty array
- // has been created.
- cls.InitEmptyFields();
-
// Set up the growable object array class (Has to be done after the array
// class is setup as one of its field is an array object).
cls = Class::New<GrowableObjectArray>();
@@ -835,10 +830,6 @@
cls = Class::New<Array>();
object_store->set_array_class(cls);
- Array& empty_array = Array::Handle();
- empty_array = Array::New(0);
- object_store->set_empty_array(empty_array);
-
cls = Class::New<ImmutableArray>();
object_store->set_immutable_array_class(cls);
@@ -1037,11 +1028,8 @@
RawString* Class::Name() const {
- if (raw_ptr()->name_ != String::null()) {
- return raw_ptr()->name_;
- }
- ASSERT(class_class() != Class::null()); // class_class_ should be set up.
- return Symbols::New(GetSingletonClassName(raw_ptr()->id_));
+ ASSERT(raw_ptr()->name_ != String::null());
+ return raw_ptr()->name_;
}
@@ -1186,23 +1174,25 @@
// Initialize class fields of type Array with empty array.
void Class::InitEmptyFields() {
- const Array& empty_array = Array::Handle(Array::Empty());
- if (empty_array.IsNull()) {
+ if (Object::empty_array() == Array::null()) {
// The empty array has not been initialized yet.
return;
}
- StorePointer(&raw_ptr()->interfaces_, empty_array.raw());
- // TODO(srdjan): Make functions_cache growable and start with a smaller size.
- Array& fcache =
- Array::Handle(Array::New(FunctionsCache::kNumEntries * 32, Heap::kOld));
- StorePointer(&raw_ptr()->functions_cache_, fcache.raw());
- StorePointer(&raw_ptr()->constants_, empty_array.raw());
- StorePointer(&raw_ptr()->canonical_types_, empty_array.raw());
- StorePointer(&raw_ptr()->functions_, empty_array.raw());
- StorePointer(&raw_ptr()->fields_, empty_array.raw());
+ StorePointer(&raw_ptr()->interfaces_, Object::empty_array());
+ StorePointer(&raw_ptr()->constants_, Object::empty_array());
+ StorePointer(&raw_ptr()->canonical_types_, Object::empty_array());
+ StorePointer(&raw_ptr()->functions_, Object::empty_array());
+ StorePointer(&raw_ptr()->fields_, Object::empty_array());
}
+void Class::InitFunctionsCache() const {
+ // TODO(srdjan): Make functions_cache growable and start with smaller size.
+ StorePointer(&raw_ptr()->functions_cache_,
+ Array::New(FunctionsCache::kNumEntries * 32, Heap::kOld));
+}
+
+
bool Class::HasInstanceFields() const {
const Array& field_array = Array::Handle(fields());
Field& field = Field::Handle();
@@ -9913,7 +9903,7 @@
RawArray* Array::Empty() {
- return Isolate::Current()->object_store()->empty_array();
+ return Object::empty_array();
}
« vm/object.h ('K') | « vm/object.h ('k') | vm/object_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698