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

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

Issue 10786003: Ensure objects emitted in code are allocated in old space. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 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/object_ia32_test.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 "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 Library::InitCoreLibrary(isolate); 510 Library::InitCoreLibrary(isolate);
511 Library& core_lib = Library::Handle(Library::CoreLibrary()); 511 Library& core_lib = Library::Handle(Library::CoreLibrary());
512 ASSERT(!core_lib.IsNull()); 512 ASSERT(!core_lib.IsNull());
513 Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); 513 Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary());
514 ASSERT(!core_impl_lib.IsNull()); 514 ASSERT(!core_impl_lib.IsNull());
515 515
516 const GrowableObjectArray& pending_classes = 516 const GrowableObjectArray& pending_classes =
517 GrowableObjectArray::Handle(GrowableObjectArray::New(Heap::kOld)); 517 GrowableObjectArray::Handle(GrowableObjectArray::New(Heap::kOld));
518 object_store->set_pending_classes(pending_classes); 518 object_store->set_pending_classes(pending_classes);
519 519
520 Context& context = Context::Handle(Context::New(0)); 520 Context& context = Context::Handle(Context::New(0, Heap::kOld));
521 object_store->set_empty_context(context); 521 object_store->set_empty_context(context);
522 522
523 // Now that the symbol table is initialized and that the core dictionary as 523 // Now that the symbol table is initialized and that the core dictionary as
524 // well as the core implementation dictionary have been setup, preallocate 524 // well as the core implementation dictionary have been setup, preallocate
525 // remaining classes and register them by name in the dictionaries. 525 // remaining classes and register them by name in the dictionaries.
526 const Script& impl_script = Script::Handle(Bootstrap::LoadImplScript()); 526 const Script& impl_script = Script::Handle(Bootstrap::LoadImplScript());
527 527
528 cls = Class::New<Smi>(); 528 cls = Class::New<Smi>();
529 object_store->set_smi_class(cls); 529 object_store->set_smi_class(cls);
530 RegisterClass(cls, "Smi", impl_script, core_impl_lib); 530 RegisterClass(cls, "Smi", impl_script, core_impl_lib);
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 UNREACHABLE(); 996 UNREACHABLE();
997 } 997 }
998 NoGCScope no_gc; 998 NoGCScope no_gc;
999 InitializeObject(address, cls.id(), size); 999 InitializeObject(address, cls.id(), size);
1000 RawObject* raw_obj = reinterpret_cast<RawObject*>(address + kHeapObjectTag); 1000 RawObject* raw_obj = reinterpret_cast<RawObject*>(address + kHeapObjectTag);
1001 ASSERT(cls.id() == RawObject::ClassIdTag::decode(raw_obj->ptr()->tags_)); 1001 ASSERT(cls.id() == RawObject::ClassIdTag::decode(raw_obj->ptr()->tags_));
1002 return raw_obj; 1002 return raw_obj;
1003 } 1003 }
1004 1004
1005 1005
1006 class StoreBufferObjectPointerVisitor : public ObjectPointerVisitor {
1007 public:
1008 explicit StoreBufferObjectPointerVisitor(Isolate* isolate) :
1009 ObjectPointerVisitor(isolate) {
1010 }
1011 void VisitPointers(RawObject** first, RawObject** last) {
1012 for (RawObject** curr = first; curr <= last; ++curr) {
1013 if ((*curr)->IsNewObject()) {
1014 uword ptr = reinterpret_cast<uword>(curr);
1015 isolate()->store_buffer()->AddPointer(ptr);
1016 }
1017 }
1018 }
1019
1020 private:
1021 DISALLOW_COPY_AND_ASSIGN(StoreBufferObjectPointerVisitor);
1022 };
1023
1024
1025 RawObject* Object::Clone(const Object& src, Heap::Space space) {
1026 const Class& cls = Class::Handle(src.clazz());
1027 intptr_t size = src.raw()->Size();
1028 RawObject* raw_obj = Object::Allocate(cls, size, space);
1029 NoGCScope no_gc;
1030 memmove(raw_obj->ptr(), src.raw()->ptr(), size);
1031 if (space == Heap::kOld) {
1032 StoreBufferObjectPointerVisitor visitor(Isolate::Current());
1033 raw_obj->VisitPointers(&visitor);
1034 }
1035 return raw_obj;
1036 }
1037
1038
1006 RawString* Class::Name() const { 1039 RawString* Class::Name() const {
1007 if (raw_ptr()->name_ != String::null()) { 1040 if (raw_ptr()->name_ != String::null()) {
1008 return raw_ptr()->name_; 1041 return raw_ptr()->name_;
1009 } 1042 }
1010 ASSERT(class_class() != Class::null()); // class_class_ should be set up. 1043 ASSERT(class_class() != Class::null()); // class_class_ should be set up.
1011 intptr_t index = GetSingletonClassIndex(raw()); 1044 intptr_t index = GetSingletonClassIndex(raw());
1012 return String::NewSymbol(GetSingletonClassName(index)); 1045 return String::NewSymbol(GetSingletonClassName(index));
1013 } 1046 }
1014 1047
1015 1048
(...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after
2754 ASSERT((index == 0) && cls.IsSignatureClass()); 2787 ASSERT((index == 0) && cls.IsSignatureClass());
2755 index++; 2788 index++;
2756 continue; 2789 continue;
2757 } 2790 }
2758 if (this->Equals(type)) { 2791 if (this->Equals(type)) {
2759 return type.raw(); 2792 return type.raw();
2760 } 2793 }
2761 index++; 2794 index++;
2762 } 2795 }
2763 // The type needs to be added to the list. Grow the list if it is full. 2796 // The type needs to be added to the list. Grow the list if it is full.
2764 // TODO(srdjan): Copy type into old space if canonicalized? 2797 // TODO(srdjan): Copy type into old space if canonicalized?
regis 2012/07/13 22:32:16 This TODO can be removed, since you assert below t
cshapiro 2012/07/13 23:17:00 Yes! Done.
2765 if (index == canonical_types_len) { 2798 if (index == canonical_types_len) {
2766 const intptr_t kLengthIncrement = 2; // Raw and parameterized. 2799 const intptr_t kLengthIncrement = 2; // Raw and parameterized.
2767 const intptr_t new_length = canonical_types.Length() + kLengthIncrement; 2800 const intptr_t new_length = canonical_types.Length() + kLengthIncrement;
2768 const Array& new_canonical_types = 2801 const Array& new_canonical_types =
2769 Array::Handle(Array::Grow(canonical_types, new_length, Heap::kOld)); 2802 Array::Handle(Array::Grow(canonical_types, new_length, Heap::kOld));
2770 cls.set_canonical_types(new_canonical_types); 2803 cls.set_canonical_types(new_canonical_types);
2771 new_canonical_types.SetAt(index, *this); 2804 new_canonical_types.SetAt(index, *this);
2772 } else { 2805 } else {
2773 canonical_types.SetAt(index, *this); 2806 canonical_types.SetAt(index, *this);
2774 } 2807 }
2808 ASSERT(IsOld());
2775 SetCanonical(); 2809 SetCanonical();
2776 return this->raw(); 2810 return this->raw();
2777 } 2811 }
2778 2812
2779 2813
2780 void Type::set_type_class(const Object& value) const { 2814 void Type::set_type_class(const Object& value) const {
2781 ASSERT(!value.IsNull() && (value.IsClass() || value.IsUnresolvedClass())); 2815 ASSERT(!value.IsNull() && (value.IsClass() || value.IsUnresolvedClass()));
2782 StorePointer(&raw_ptr()->type_class_, value.raw()); 2816 StorePointer(&raw_ptr()->type_class_, value.raw());
2783 } 2817 }
2784 2818
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
3416 intptr_t index = 0; 3450 intptr_t index = 0;
3417 TypeArguments& other = TypeArguments::Handle(); 3451 TypeArguments& other = TypeArguments::Handle();
3418 other ^= table.At(index); 3452 other ^= table.At(index);
3419 while (!other.IsNull()) { 3453 while (!other.IsNull()) {
3420 if (this->Equals(other)) { 3454 if (this->Equals(other)) {
3421 return other.raw(); 3455 return other.raw();
3422 } 3456 }
3423 other ^= table.At(++index); 3457 other ^= table.At(++index);
3424 } 3458 }
3425 // Not found. Add 'this' to table. 3459 // Not found. Add 'this' to table.
3426 // TODO(srdjan): Copy 'this' into old space if canonicalized? 3460 // TODO(srdjan): Copy 'this' into old space if canonicalized?
regis 2012/07/13 22:32:16 How about this TODO? Either assert that 'this' is
cshapiro 2012/07/13 23:17:00 Done. Both, actually. Running the test with chec
3427 if (index == table.Length() - 1) { 3461 if (index == table.Length() - 1) {
3428 table = Array::Grow(table, table.Length() + 4, Heap::kOld); 3462 table = Array::Grow(table, table.Length() + 4, Heap::kOld);
3429 object_store->set_canonical_type_arguments(table); 3463 object_store->set_canonical_type_arguments(table);
3430 } 3464 }
3431 table.SetAt(index, *this); 3465 table.SetAt(index, *this);
3432 SetCanonical(); 3466 SetCanonical();
3433 return this->raw(); 3467 return this->raw();
3434 } 3468 }
3435 3469
3436 3470
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after
4416 return reinterpret_cast<RawLiteralToken*>(raw); 4450 return reinterpret_cast<RawLiteralToken*>(raw);
4417 } 4451 }
4418 4452
4419 4453
4420 RawLiteralToken* LiteralToken::New(Token::Kind kind, const String& literal) { 4454 RawLiteralToken* LiteralToken::New(Token::Kind kind, const String& literal) {
4421 const LiteralToken& result = LiteralToken::Handle(LiteralToken::New()); 4455 const LiteralToken& result = LiteralToken::Handle(LiteralToken::New());
4422 result.set_kind(kind); 4456 result.set_kind(kind);
4423 result.set_literal(literal); 4457 result.set_literal(literal);
4424 if (kind == Token::kINTEGER) { 4458 if (kind == Token::kINTEGER) {
4425 const Integer& value = Integer::Handle(Integer::New(literal, Heap::kOld)); 4459 const Integer& value = Integer::Handle(Integer::New(literal, Heap::kOld));
4460 ASSERT(value.IsSmi() || value.IsOld());
4426 result.set_value(value); 4461 result.set_value(value);
4427 } else if (kind == Token::kDOUBLE) { 4462 } else if (kind == Token::kDOUBLE) {
4428 const Double& value = Double::Handle(Double::NewCanonical(literal)); 4463 const Double& value = Double::Handle(Double::NewCanonical(literal));
4429 result.set_value(value); 4464 result.set_value(value);
4430 } else { 4465 } else {
4431 ASSERT(Token::NeedsLiteralToken(kind)); 4466 ASSERT(Token::NeedsLiteralToken(kind));
4432 result.set_value(literal); 4467 result.set_value(literal);
4433 } 4468 }
4434 return result.raw(); 4469 return result.raw();
4435 } 4470 }
(...skipping 3105 matching lines...) Expand 10 before | Expand all | Expand 10 after
7541 return false; 7576 return false;
7542 } 7577 }
7543 } 7578 }
7544 } 7579 }
7545 return true; 7580 return true;
7546 } 7581 }
7547 7582
7548 7583
7549 RawInstance* Instance::Canonicalize() const { 7584 RawInstance* Instance::Canonicalize() const {
7550 ASSERT(!IsNull()); 7585 ASSERT(!IsNull());
7551 if (!IsCanonical()) { 7586 if (this->IsCanonical()) {
7552 const Class& cls = Class::Handle(this->clazz()); 7587 return this->raw();
7553 Array& constants = Array::Handle(cls.constants()); 7588 }
7554 const intptr_t constants_len = constants.Length(); 7589 Instance& result = Instance::Handle();
7555 // Linear search to see whether this value is already present in the 7590 const Class& cls = Class::Handle(this->clazz());
7556 // list of canonicalized constants. 7591 Array& constants = Array::Handle(cls.constants());
7557 Instance& norm_value = Instance::Handle(); 7592 const intptr_t constants_len = constants.Length();
7558 intptr_t index = 0; 7593 // Linear search to see whether this value is already present in the
7559 while (index < constants_len) { 7594 // list of canonicalized constants.
7560 norm_value ^= constants.At(index); 7595 intptr_t index = 0;
7561 if (norm_value.IsNull()) { 7596 while (index < constants_len) {
7562 break; 7597 result ^= constants.At(index);
7563 } 7598 if (result.IsNull()) {
7564 if (this->Equals(norm_value)) { 7599 break;
7565 return norm_value.raw();
7566 }
7567 index++;
7568 } 7600 }
7569 // The value needs to be added to the list. Grow the list if 7601 if (this->Equals(result)) {
7570 // it is full. 7602 return result.raw();
7571 // TODO(srdjan): Copy instance into old space if canonicalized? 7603 }
7572 cls.InsertCanonicalConstant(index, *this); 7604 index++;
7573 SetCanonical();
7574 } 7605 }
7575 return this->raw(); 7606 // The value needs to be added to the list. Grow the list if
7607 // it is full.
7608 // TODO(srdjan): Copy instance into old space if canonicalized?
regis 2012/07/13 22:32:16 You can remove this TODO.
cshapiro 2012/07/13 23:17:00 Done.
7609 result ^= this->raw();
7610 if (result.IsNew()) {
7611 // Create a canonical object in old space.
7612 result ^= Object::Clone(result, Heap::kOld);
7613 ASSERT(result.IsOld());
7614 }
7615 cls.InsertCanonicalConstant(index, result);
7616 result.SetCanonical();
7617 return result.raw();
7576 } 7618 }
7577 7619
7578 7620
7579 RawType* Instance::GetType() const { 7621 RawType* Instance::GetType() const {
7580 if (IsNull()) { 7622 if (IsNull()) {
7581 return Type::NullType(); 7623 return Type::NullType();
7582 } 7624 }
7583 const Class& cls = Class::Handle(clazz()); 7625 const Class& cls = Class::Handle(clazz());
7584 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); 7626 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle();
7585 if (cls.HasTypeArguments()) { 7627 if (cls.HasTypeArguments()) {
(...skipping 3157 matching lines...) Expand 10 before | Expand all | Expand 10 after
10743 const String& str = String::Handle(pattern()); 10785 const String& str = String::Handle(pattern());
10744 const char* format = "JSRegExp: pattern=%s flags=%s"; 10786 const char* format = "JSRegExp: pattern=%s flags=%s";
10745 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 10787 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
10746 char* chars = reinterpret_cast<char*>( 10788 char* chars = reinterpret_cast<char*>(
10747 Isolate::Current()->current_zone()->Allocate(len + 1)); 10789 Isolate::Current()->current_zone()->Allocate(len + 1));
10748 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 10790 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
10749 return chars; 10791 return chars;
10750 } 10792 }
10751 10793
10752 } // namespace dart 10794 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_ia32_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698