| OLD | NEW |
| 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 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 uword old_tags; | 935 uword old_tags; |
| 936 // TODO(iposva): Investigate whether CompareAndSwapWord is necessary. | 936 // TODO(iposva): Investigate whether CompareAndSwapWord is necessary. |
| 937 do { | 937 do { |
| 938 old_tags = tags; | 938 old_tags = tags; |
| 939 tags = AtomicOperations::CompareAndSwapWord( | 939 tags = AtomicOperations::CompareAndSwapWord( |
| 940 &raw->ptr()->tags_, old_tags, new_tags); | 940 &raw->ptr()->tags_, old_tags, new_tags); |
| 941 } while (tags != old_tags); | 941 } while (tags != old_tags); |
| 942 | 942 |
| 943 intptr_t leftover_len = (leftover_size - TypedData::InstanceSize(0)); | 943 intptr_t leftover_len = (leftover_size - TypedData::InstanceSize(0)); |
| 944 ASSERT(TypedData::InstanceSize(leftover_len) == leftover_size); | 944 ASSERT(TypedData::InstanceSize(leftover_len) == leftover_size); |
| 945 raw->ptr()->length_ = Smi::New(leftover_len); | 945 raw->StoreSmi(&(raw->ptr()->length_), Smi::New(leftover_len)); |
| 946 } else { | 946 } else { |
| 947 // Update the leftover space as a basic object. | 947 // Update the leftover space as a basic object. |
| 948 ASSERT(leftover_size == Object::InstanceSize()); | 948 ASSERT(leftover_size == Object::InstanceSize()); |
| 949 RawObject* raw = reinterpret_cast<RawObject*>(RawObject::FromAddr(addr)); | 949 RawObject* raw = reinterpret_cast<RawObject*>(RawObject::FromAddr(addr)); |
| 950 uword new_tags = RawObject::ClassIdTag::update(kInstanceCid, 0); | 950 uword new_tags = RawObject::ClassIdTag::update(kInstanceCid, 0); |
| 951 new_tags = RawObject::SizeTag::update(leftover_size, new_tags); | 951 new_tags = RawObject::SizeTag::update(leftover_size, new_tags); |
| 952 uword tags = raw->ptr()->tags_; | 952 uword tags = raw->ptr()->tags_; |
| 953 uword old_tags; | 953 uword old_tags; |
| 954 // TODO(iposva): Investigate whether CompareAndSwapWord is necessary. | 954 // TODO(iposva): Investigate whether CompareAndSwapWord is necessary. |
| 955 do { | 955 do { |
| (...skipping 11184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12140 const ZoneGrowableArray<intptr_t>& pointer_offsets = | 12140 const ZoneGrowableArray<intptr_t>& pointer_offsets = |
| 12141 assembler->GetPointerOffsets(); | 12141 assembler->GetPointerOffsets(); |
| 12142 ASSERT(pointer_offsets.length() == pointer_offset_count); | 12142 ASSERT(pointer_offsets.length() == pointer_offset_count); |
| 12143 ASSERT(code.pointer_offsets_length() == pointer_offsets.length()); | 12143 ASSERT(code.pointer_offsets_length() == pointer_offsets.length()); |
| 12144 | 12144 |
| 12145 // Set pointer offsets list in Code object and resolve all handles in | 12145 // Set pointer offsets list in Code object and resolve all handles in |
| 12146 // the instruction stream to raw objects. | 12146 // the instruction stream to raw objects. |
| 12147 for (intptr_t i = 0; i < pointer_offsets.length(); i++) { | 12147 for (intptr_t i = 0; i < pointer_offsets.length(); i++) { |
| 12148 intptr_t offset_in_instrs = pointer_offsets[i]; | 12148 intptr_t offset_in_instrs = pointer_offsets[i]; |
| 12149 code.SetPointerOffsetAt(i, offset_in_instrs); | 12149 code.SetPointerOffsetAt(i, offset_in_instrs); |
| 12150 const Object* object = region.Load<const Object*>(offset_in_instrs); | 12150 uword addr = region.start() + offset_in_instrs; |
| 12151 region.Store<RawObject*>(offset_in_instrs, object->raw()); | 12151 const Object* object = *reinterpret_cast<Object**>(addr); |
| 12152 instrs.raw()->StorePointer(reinterpret_cast<RawObject**>(addr), |
| 12153 object->raw()); |
| 12152 } | 12154 } |
| 12153 | 12155 |
| 12154 // Hook up Code and Instructions objects. | 12156 // Hook up Code and Instructions objects. |
| 12155 instrs.set_code(code.raw()); | 12157 instrs.set_code(code.raw()); |
| 12156 code.set_instructions(instrs.raw()); | 12158 code.set_instructions(instrs.raw()); |
| 12157 code.set_is_alive(true); | 12159 code.set_is_alive(true); |
| 12158 | 12160 |
| 12159 // Set object pool in Instructions object. | 12161 // Set object pool in Instructions object. |
| 12160 const GrowableObjectArray& object_pool = assembler->object_pool(); | 12162 const GrowableObjectArray& object_pool = assembler->object_pool(); |
| 12161 if (object_pool.IsNull()) { | 12163 if (object_pool.IsNull()) { |
| (...skipping 6000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18162 if (len < 0 || len > kMaxElements) { | 18164 if (len < 0 || len > kMaxElements) { |
| 18163 // This should be caught before we reach here. | 18165 // This should be caught before we reach here. |
| 18164 FATAL1("Fatal error in OneByteString::New: invalid len %" Pd "\n", len); | 18166 FATAL1("Fatal error in OneByteString::New: invalid len %" Pd "\n", len); |
| 18165 } | 18167 } |
| 18166 { | 18168 { |
| 18167 RawObject* raw = Object::Allocate(OneByteString::kClassId, | 18169 RawObject* raw = Object::Allocate(OneByteString::kClassId, |
| 18168 OneByteString::InstanceSize(len), | 18170 OneByteString::InstanceSize(len), |
| 18169 space); | 18171 space); |
| 18170 NoGCScope no_gc; | 18172 NoGCScope no_gc; |
| 18171 RawOneByteString* result = reinterpret_cast<RawOneByteString*>(raw); | 18173 RawOneByteString* result = reinterpret_cast<RawOneByteString*>(raw); |
| 18172 result->ptr()->length_ = Smi::New(len); | 18174 result->StoreSmi(&(result->ptr()->length_), Smi::New(len)); |
| 18173 result->ptr()->hash_ = 0; | 18175 result->StoreSmi(&(result->ptr()->hash_), Smi::New(0)); |
| 18174 return result; | 18176 return result; |
| 18175 } | 18177 } |
| 18176 } | 18178 } |
| 18177 | 18179 |
| 18178 | 18180 |
| 18179 RawOneByteString* OneByteString::New(const uint8_t* characters, | 18181 RawOneByteString* OneByteString::New(const uint8_t* characters, |
| 18180 intptr_t len, | 18182 intptr_t len, |
| 18181 Heap::Space space) { | 18183 Heap::Space space) { |
| 18182 const String& result = String::Handle(OneByteString::New(len, space)); | 18184 const String& result = String::Handle(OneByteString::New(len, space)); |
| 18183 if (len > 0) { | 18185 if (len > 0) { |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18700 if ((len < 0) || (len > Array::kMaxElements)) { | 18702 if ((len < 0) || (len > Array::kMaxElements)) { |
| 18701 // This should be caught before we reach here. | 18703 // This should be caught before we reach here. |
| 18702 FATAL1("Fatal error in Array::New: invalid len %" Pd "\n", len); | 18704 FATAL1("Fatal error in Array::New: invalid len %" Pd "\n", len); |
| 18703 } | 18705 } |
| 18704 { | 18706 { |
| 18705 RawArray* raw = reinterpret_cast<RawArray*>( | 18707 RawArray* raw = reinterpret_cast<RawArray*>( |
| 18706 Object::Allocate(class_id, | 18708 Object::Allocate(class_id, |
| 18707 Array::InstanceSize(len), | 18709 Array::InstanceSize(len), |
| 18708 space)); | 18710 space)); |
| 18709 NoGCScope no_gc; | 18711 NoGCScope no_gc; |
| 18710 raw->ptr()->length_ = Smi::New(len); | 18712 raw->StoreSmi(&(raw->ptr()->length_), Smi::New(len)); |
| 18711 return raw; | 18713 return raw; |
| 18712 } | 18714 } |
| 18713 } | 18715 } |
| 18714 | 18716 |
| 18715 | 18717 |
| 18716 RawArray* Array::Slice(intptr_t start, | 18718 RawArray* Array::Slice(intptr_t start, |
| 18717 intptr_t count, | 18719 intptr_t count, |
| 18718 bool with_type_argument) const { | 18720 bool with_type_argument) const { |
| 18719 // TODO(vegorov) introduce an array allocation method that fills newly | 18721 // TODO(vegorov) introduce an array allocation method that fills newly |
| 18720 // allocated array with values from the given source array instead of | 18722 // allocated array with values from the given source array instead of |
| (...skipping 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20314 return tag_label.ToCString(); | 20316 return tag_label.ToCString(); |
| 20315 } | 20317 } |
| 20316 | 20318 |
| 20317 | 20319 |
| 20318 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20320 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 20319 Instance::PrintJSONImpl(stream, ref); | 20321 Instance::PrintJSONImpl(stream, ref); |
| 20320 } | 20322 } |
| 20321 | 20323 |
| 20322 | 20324 |
| 20323 } // namespace dart | 20325 } // namespace dart |
| OLD | NEW |