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

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

Issue 16163010: More cleanup based on profile information. (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/object.h ('k') | runtime/vm/symbols.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 #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/cpu.h" 10 #include "vm/cpu.h"
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 Object fake_object; 314 Object fake_object;
315 Smi fake_smi; 315 Smi fake_smi;
316 Object::handle_vtable_ = fake_object.vtable(); 316 Object::handle_vtable_ = fake_object.vtable();
317 Smi::handle_vtable_ = fake_smi.vtable(); 317 Smi::handle_vtable_ = fake_smi.vtable();
318 } 318 }
319 319
320 Isolate* isolate = Isolate::Current(); 320 Isolate* isolate = Isolate::Current();
321 Heap* heap = isolate->heap(); 321 Heap* heap = isolate->heap();
322 322
323 // Allocate the read only object handles here. 323 // Allocate the read only object handles here.
324 empty_array_ = Array::ReadOnlyHandle(isolate); 324 empty_array_ = Array::ReadOnlyHandle();
325 sentinel_ = Instance::ReadOnlyHandle(isolate); 325 sentinel_ = Instance::ReadOnlyHandle();
326 transition_sentinel_ = Instance::ReadOnlyHandle(isolate); 326 transition_sentinel_ = Instance::ReadOnlyHandle();
327 unknown_constant_ = Instance::ReadOnlyHandle(isolate); 327 unknown_constant_ = Instance::ReadOnlyHandle();
328 non_constant_ = Instance::ReadOnlyHandle(isolate); 328 non_constant_ = Instance::ReadOnlyHandle();
329 bool_true_ = Bool::ReadOnlyHandle(isolate); 329 bool_true_ = Bool::ReadOnlyHandle();
330 bool_false_ = Bool::ReadOnlyHandle(isolate); 330 bool_false_ = Bool::ReadOnlyHandle();
331 snapshot_writer_error_ = LanguageError::ReadOnlyHandle(isolate); 331 snapshot_writer_error_ = LanguageError::ReadOnlyHandle();
332 332
333 // Allocate and initialize the null instance. 333 // Allocate and initialize the null instance.
334 // 'null_' must be the first object allocated as it is used in allocation to 334 // 'null_' must be the first object allocated as it is used in allocation to
335 // clear the object. 335 // clear the object.
336 { 336 {
337 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld); 337 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld);
338 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag); 338 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag);
339 // The call below is using 'null_' to initialize itself. 339 // The call below is using 'null_' to initialize itself.
340 InitializeObject(address, kNullCid, Instance::InstanceSize()); 340 InitializeObject(address, kNullCid, Instance::InstanceSize());
341 } 341 }
(...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 } 1570 }
1571 const TypeArguments& type_params = TypeArguments::Handle(type_parameters()); 1571 const TypeArguments& type_params = TypeArguments::Handle(type_parameters());
1572 return type_params.Length(); 1572 return type_params.Length();
1573 } 1573 }
1574 1574
1575 1575
1576 intptr_t Class::NumTypeArguments() const { 1576 intptr_t Class::NumTypeArguments() const {
1577 // To work properly, this call requires the super class of this class to be 1577 // To work properly, this call requires the super class of this class to be
1578 // resolved, which is checked by the SuperClass() call. 1578 // resolved, which is checked by the SuperClass() call.
1579 Class& cls = Class::Handle(raw()); 1579 Class& cls = Class::Handle(raw());
1580 if (IsSignatureClass()) { 1580 intptr_t num_type_args = 0;
1581 const Function& signature_fun = Function::Handle(signature_function()); 1581
1582 if (!signature_fun.is_static() && 1582 do {
1583 !signature_fun.HasInstantiatedSignature()) { 1583 if (cls.IsSignatureClass()) {
1584 cls = signature_fun.Owner(); 1584 const Function& signature_fun =
1585 Function::Handle(cls.signature_function());
1586 if (!signature_fun.is_static() &&
1587 !signature_fun.HasInstantiatedSignature()) {
1588 cls = signature_fun.Owner();
1589 }
1585 } 1590 }
1586 } 1591 num_type_args += cls.NumTypeParameters();
1587 intptr_t num_type_args = NumTypeParameters(); 1592 // Object is its own super class during bootstrap.
1588 cls = cls.SuperClass(); 1593 if (cls.SuperClass() == Class::null() || cls.SuperClass() == cls.raw()) {
1589 // Object is its own super class during bootstrap. 1594 break;
1590 if (!cls.IsNull() && (cls.raw() != raw())) { 1595 }
1591 num_type_args += cls.NumTypeArguments(); 1596 cls = cls.SuperClass();
1592 } 1597 } while (true);
1593 return num_type_args; 1598 return num_type_args;
1594 } 1599 }
1595 1600
1596 1601
1597 bool Class::HasTypeArguments() const { 1602 bool Class::HasTypeArguments() const {
1598 if (!IsSignatureClass() && (is_type_finalized() || is_prefinalized())) { 1603 if (!IsSignatureClass() && (is_type_finalized() || is_prefinalized())) {
1599 // More efficient than calling NumTypeArguments(). 1604 // More efficient than calling NumTypeArguments().
1600 return type_arguments_field_offset() != kNoTypeArguments; 1605 return type_arguments_field_offset() != kNoTypeArguments;
1601 } else { 1606 } else {
1602 // No need to check NumTypeArguments() if class has type parameters. 1607 // No need to check NumTypeArguments() if class has type parameters.
(...skipping 3680 matching lines...) Expand 10 before | Expand all | Expand 10 after
5283 iterator.Advance(); 5288 iterator.Advance();
5284 kind = iterator.CurrentTokenKind(); 5289 kind = iterator.CurrentTokenKind();
5285 index += 1; 5290 index += 1;
5286 } 5291 }
5287 return iterator.CurrentPosition(); 5292 return iterator.CurrentPosition();
5288 } 5293 }
5289 5294
5290 5295
5291 RawTokenStream* TokenStream::New() { 5296 RawTokenStream* TokenStream::New() {
5292 ASSERT(Object::token_stream_class() != Class::null()); 5297 ASSERT(Object::token_stream_class() != Class::null());
5293 TokenStream& result = TokenStream::Handle(); 5298 RawObject* raw = Object::Allocate(TokenStream::kClassId,
5294 { 5299 TokenStream::InstanceSize(),
5295 RawObject* raw = Object::Allocate(TokenStream::kClassId, 5300 Heap::kOld);
5296 TokenStream::InstanceSize(), 5301 return reinterpret_cast<RawTokenStream*>(raw);
5297 Heap::kOld);
5298 NoGCScope no_gc;
5299 result ^= raw;
5300 }
5301 return result.raw();
5302 } 5302 }
5303 5303
5304 5304
5305 RawTokenStream* TokenStream::New(intptr_t len) { 5305 RawTokenStream* TokenStream::New(intptr_t len) {
5306 if (len < 0 || len > kMaxElements) { 5306 if (len < 0 || len > kMaxElements) {
5307 // This should be caught before we reach here. 5307 // This should be caught before we reach here.
5308 FATAL1("Fatal error in TokenStream::New: invalid len %"Pd"\n", len); 5308 FATAL1("Fatal error in TokenStream::New: invalid len %"Pd"\n", len);
5309 } 5309 }
5310 uint8_t* data = reinterpret_cast<uint8_t*>(::malloc(len)); 5310 uint8_t* data = reinterpret_cast<uint8_t*>(::malloc(len));
5311 ASSERT(data != NULL); 5311 ASSERT(data != NULL);
(...skipping 3910 matching lines...) Expand 10 before | Expand all | Expand 10 after
9222 } while (!cls.IsNull()); 9222 } while (!cls.IsNull());
9223 return false; 9223 return false;
9224 } 9224 }
9225 9225
9226 9226
9227 RawInstance* Instance::New(const Class& cls, Heap::Space space) { 9227 RawInstance* Instance::New(const Class& cls, Heap::Space space) {
9228 Isolate* isolate = Isolate::Current(); 9228 Isolate* isolate = Isolate::Current();
9229 if (cls.EnsureIsFinalized(isolate) != Error::null()) { 9229 if (cls.EnsureIsFinalized(isolate) != Error::null()) {
9230 return Instance::null(); 9230 return Instance::null();
9231 } 9231 }
9232 Instance& result = Instance::Handle(isolate); 9232 intptr_t instance_size = cls.instance_size();
9233 { 9233 ASSERT(instance_size > 0);
9234 intptr_t instance_size = cls.instance_size(); 9234 RawObject* raw = Object::Allocate(cls.id(), instance_size, space);
9235 ASSERT(instance_size > 0); 9235 return reinterpret_cast<RawInstance*>(raw);
9236 RawObject* raw = Object::Allocate(cls.id(), instance_size, space);
9237 NoGCScope no_gc;
9238 result ^= raw;
9239 }
9240 return result.raw();
9241 } 9236 }
9242 9237
9243 9238
9244 bool Instance::IsValidFieldOffset(int offset) const { 9239 bool Instance::IsValidFieldOffset(int offset) const {
9245 const Class& cls = Class::Handle(clazz()); 9240 const Class& cls = Class::Handle(clazz());
9246 return (offset >= 0 && offset <= (cls.instance_size() - kWordSize)); 9241 return (offset >= 0 && offset <= (cls.instance_size() - kWordSize));
9247 } 9242 }
9248 9243
9249 9244
9250 const char* Instance::ToCString() const { 9245 const char* Instance::ToCString() const {
(...skipping 4057 matching lines...) Expand 10 before | Expand all | Expand 10 after
13308 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 13303 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
13309 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); 13304 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
13310 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 13305 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
13311 return chars; 13306 return chars;
13312 } 13307 }
13313 13308
13314 13309
13315 RawWeakProperty* WeakProperty::New(Heap::Space space) { 13310 RawWeakProperty* WeakProperty::New(Heap::Space space) {
13316 ASSERT(Isolate::Current()->object_store()->weak_property_class() 13311 ASSERT(Isolate::Current()->object_store()->weak_property_class()
13317 != Class::null()); 13312 != Class::null());
13318 WeakProperty& result = WeakProperty::Handle(); 13313 RawObject* raw = Object::Allocate(WeakProperty::kClassId,
13319 { 13314 WeakProperty::InstanceSize(),
13320 RawObject* raw = Object::Allocate(WeakProperty::kClassId, 13315 space);
13321 WeakProperty::InstanceSize(), 13316 return reinterpret_cast<RawWeakProperty*>(raw);
13322 space);
13323 NoGCScope no_gc;
13324 result ^= raw;
13325 }
13326 return result.raw();
13327 } 13317 }
13328 13318
13329 13319
13330 const char* WeakProperty::ToCString() const { 13320 const char* WeakProperty::ToCString() const {
13331 return "_WeakProperty"; 13321 return "_WeakProperty";
13332 } 13322 }
13333 13323
13334 } // namespace dart 13324 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/symbols.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698