| 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/become.h" | 10 #include "vm/become.h" |
| (...skipping 11823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11834 false, // is_const | 11834 false, // is_const |
| 11835 owner, token_pos)); | 11835 owner, token_pos)); |
| 11836 field.set_is_reflectable(false); | 11836 field.set_is_reflectable(false); |
| 11837 field.SetFieldType(Object::dynamic_type()); | 11837 field.SetFieldType(Object::dynamic_type()); |
| 11838 field.SetStaticValue(Array::empty_array(), true); | 11838 field.SetStaticValue(Array::empty_array(), true); |
| 11839 set_metadata_field(field); | 11839 set_metadata_field(field); |
| 11840 } | 11840 } |
| 11841 | 11841 |
| 11842 | 11842 |
| 11843 RawObject* Namespace::GetMetadata() const { | 11843 RawObject* Namespace::GetMetadata() const { |
| 11844 #if defined(DART_PRECOMPILED_RUNTIME) |
| 11845 COMPILE_ASSERT(!FLAG_enable_mirrors); |
| 11846 return Object::empty_array().raw(); |
| 11847 #else |
| 11844 Field& field = Field::Handle(metadata_field()); | 11848 Field& field = Field::Handle(metadata_field()); |
| 11845 if (field.IsNull()) { | 11849 if (field.IsNull()) { |
| 11846 // There is no metadata for this object. | 11850 // There is no metadata for this object. |
| 11847 return Object::empty_array().raw(); | 11851 return Object::empty_array().raw(); |
| 11848 } | 11852 } |
| 11849 Object& metadata = Object::Handle(); | 11853 Object& metadata = Object::Handle(); |
| 11850 metadata = field.StaticValue(); | 11854 metadata = field.StaticValue(); |
| 11851 if (field.StaticValue() == Object::empty_array().raw()) { | 11855 if (field.StaticValue() == Object::empty_array().raw()) { |
| 11852 metadata = Parser::ParseMetadata(field); | 11856 metadata = Parser::ParseMetadata(field); |
| 11853 if (metadata.IsArray()) { | 11857 if (metadata.IsArray()) { |
| 11854 ASSERT(Array::Cast(metadata).raw() != Object::empty_array().raw()); | 11858 ASSERT(Array::Cast(metadata).raw() != Object::empty_array().raw()); |
| 11855 field.SetStaticValue(Array::Cast(metadata), true); | 11859 field.SetStaticValue(Array::Cast(metadata), true); |
| 11856 } | 11860 } |
| 11857 } | 11861 } |
| 11858 return metadata.raw(); | 11862 return metadata.raw(); |
| 11863 #endif // defined(DART_PRECOMPILED_RUNTIME) |
| 11859 } | 11864 } |
| 11860 | 11865 |
| 11861 | 11866 |
| 11862 const char* Namespace::ToCString() const { | 11867 const char* Namespace::ToCString() const { |
| 11863 const Library& lib = Library::Handle(library()); | 11868 const Library& lib = Library::Handle(library()); |
| 11864 return OS::SCreate(Thread::Current()->zone(), "Namespace for library '%s'", | 11869 return OS::SCreate(Thread::Current()->zone(), "Namespace for library '%s'", |
| 11865 lib.ToCString()); | 11870 lib.ToCString()); |
| 11866 } | 11871 } |
| 11867 | 11872 |
| 11868 | 11873 |
| (...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12973 num_chars += OS::SNPrint((buffer + num_chars), (len - num_chars), FORMAT2, | 12978 num_chars += OS::SNPrint((buffer + num_chars), (len - num_chars), FORMAT2, |
| 12974 k, type.ToCString()); | 12979 k, type.ToCString()); |
| 12975 } | 12980 } |
| 12976 } | 12981 } |
| 12977 return buffer; | 12982 return buffer; |
| 12978 #undef FORMAT1 | 12983 #undef FORMAT1 |
| 12979 #undef FORMAT2 | 12984 #undef FORMAT2 |
| 12980 } | 12985 } |
| 12981 | 12986 |
| 12982 | 12987 |
| 12983 intptr_t DeoptInfo::FrameSize(const TypedData& packed) { | |
| 12984 NoSafepointScope no_safepoint; | |
| 12985 typedef ReadStream::Raw<sizeof(intptr_t), intptr_t> Reader; | |
| 12986 ReadStream read_stream(reinterpret_cast<uint8_t*>(packed.DataAddr(0)), | |
| 12987 packed.LengthInBytes()); | |
| 12988 return Reader::Read(&read_stream); | |
| 12989 } | |
| 12990 | |
| 12991 | |
| 12992 intptr_t DeoptInfo::NumMaterializations( | |
| 12993 const GrowableArray<DeoptInstr*>& unpacked) { | |
| 12994 intptr_t num = 0; | |
| 12995 while (unpacked[num]->kind() == DeoptInstr::kMaterializeObject) { | |
| 12996 num++; | |
| 12997 } | |
| 12998 return num; | |
| 12999 } | |
| 13000 | |
| 13001 | |
| 13002 void DeoptInfo::UnpackInto(const Array& table, | |
| 13003 const TypedData& packed, | |
| 13004 GrowableArray<DeoptInstr*>* unpacked, | |
| 13005 intptr_t length) { | |
| 13006 NoSafepointScope no_safepoint; | |
| 13007 typedef ReadStream::Raw<sizeof(intptr_t), intptr_t> Reader; | |
| 13008 ReadStream read_stream(reinterpret_cast<uint8_t*>(packed.DataAddr(0)), | |
| 13009 packed.LengthInBytes()); | |
| 13010 const intptr_t frame_size = Reader::Read(&read_stream); // Skip frame size. | |
| 13011 USE(frame_size); | |
| 13012 | |
| 13013 const intptr_t suffix_length = Reader::Read(&read_stream); | |
| 13014 if (suffix_length != 0) { | |
| 13015 ASSERT(suffix_length > 1); | |
| 13016 const intptr_t info_number = Reader::Read(&read_stream); | |
| 13017 | |
| 13018 TypedData& suffix = TypedData::Handle(); | |
| 13019 Smi& offset = Smi::Handle(); | |
| 13020 Smi& reason_and_flags = Smi::Handle(); | |
| 13021 DeoptTable::GetEntry(table, info_number, &offset, &suffix, | |
| 13022 &reason_and_flags); | |
| 13023 UnpackInto(table, suffix, unpacked, suffix_length); | |
| 13024 } | |
| 13025 | |
| 13026 while ((read_stream.PendingBytes() > 0) && (unpacked->length() < length)) { | |
| 13027 const intptr_t instruction = Reader::Read(&read_stream); | |
| 13028 const intptr_t from_index = Reader::Read(&read_stream); | |
| 13029 unpacked->Add(DeoptInstr::Create(instruction, from_index)); | |
| 13030 } | |
| 13031 } | |
| 13032 | |
| 13033 | |
| 13034 void DeoptInfo::Unpack(const Array& table, | |
| 13035 const TypedData& packed, | |
| 13036 GrowableArray<DeoptInstr*>* unpacked) { | |
| 13037 ASSERT(unpacked->is_empty()); | |
| 13038 | |
| 13039 // Pass kMaxInt32 as the length to unpack all instructions from the | |
| 13040 // packed stream. | |
| 13041 UnpackInto(table, packed, unpacked, kMaxInt32); | |
| 13042 | |
| 13043 unpacked->Reverse(); | |
| 13044 } | |
| 13045 | |
| 13046 | |
| 13047 const char* DeoptInfo::ToCString(const Array& deopt_table, | |
| 13048 const TypedData& packed) { | |
| 13049 #define FORMAT "[%s]" | |
| 13050 GrowableArray<DeoptInstr*> deopt_instrs; | |
| 13051 Unpack(deopt_table, packed, &deopt_instrs); | |
| 13052 | |
| 13053 // Compute the buffer size required. | |
| 13054 intptr_t len = 1; // Trailing '\0'. | |
| 13055 for (intptr_t i = 0; i < deopt_instrs.length(); i++) { | |
| 13056 len += OS::SNPrint(NULL, 0, FORMAT, deopt_instrs[i]->ToCString()); | |
| 13057 } | |
| 13058 | |
| 13059 // Allocate the buffer. | |
| 13060 char* buffer = Thread::Current()->zone()->Alloc<char>(len); | |
| 13061 | |
| 13062 // Layout the fields in the buffer. | |
| 13063 intptr_t index = 0; | |
| 13064 for (intptr_t i = 0; i < deopt_instrs.length(); i++) { | |
| 13065 index += OS::SNPrint((buffer + index), (len - index), FORMAT, | |
| 13066 deopt_instrs[i]->ToCString()); | |
| 13067 } | |
| 13068 | |
| 13069 return buffer; | |
| 13070 #undef FORMAT | |
| 13071 } | |
| 13072 | |
| 13073 | |
| 13074 // Returns a bool so it can be asserted. | |
| 13075 bool DeoptInfo::VerifyDecompression(const GrowableArray<DeoptInstr*>& original, | |
| 13076 const Array& deopt_table, | |
| 13077 const TypedData& packed) { | |
| 13078 GrowableArray<DeoptInstr*> unpacked; | |
| 13079 Unpack(deopt_table, packed, &unpacked); | |
| 13080 ASSERT(unpacked.length() == original.length()); | |
| 13081 for (intptr_t i = 0; i < unpacked.length(); ++i) { | |
| 13082 ASSERT(unpacked[i]->Equals(*original[i])); | |
| 13083 } | |
| 13084 return true; | |
| 13085 } | |
| 13086 | |
| 13087 | |
| 13088 void SingleTargetCache::set_target(const Code& value) const { | 12988 void SingleTargetCache::set_target(const Code& value) const { |
| 13089 StorePointer(&raw_ptr()->target_, value.raw()); | 12989 StorePointer(&raw_ptr()->target_, value.raw()); |
| 13090 } | 12990 } |
| 13091 | 12991 |
| 13092 | 12992 |
| 13093 const char* SingleTargetCache::ToCString() const { | 12993 const char* SingleTargetCache::ToCString() const { |
| 13094 return "SingleTargetCache"; | 12994 return "SingleTargetCache"; |
| 13095 } | 12995 } |
| 13096 | 12996 |
| 13097 | 12997 |
| (...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14347 if (!FLAG_support_debugger) { | 14247 if (!FLAG_support_debugger) { |
| 14348 return false; | 14248 return false; |
| 14349 } | 14249 } |
| 14350 return Isolate::Current()->debugger()->HasBreakpoint(*this); | 14250 return Isolate::Current()->debugger()->HasBreakpoint(*this); |
| 14351 } | 14251 } |
| 14352 | 14252 |
| 14353 | 14253 |
| 14354 RawTypedData* Code::GetDeoptInfoAtPc(uword pc, | 14254 RawTypedData* Code::GetDeoptInfoAtPc(uword pc, |
| 14355 ICData::DeoptReasonId* deopt_reason, | 14255 ICData::DeoptReasonId* deopt_reason, |
| 14356 uint32_t* deopt_flags) const { | 14256 uint32_t* deopt_flags) const { |
| 14257 #if defined(DART_PRECOMPILED_RUNTIME) |
| 14258 ASSERT(Dart::vm_snapshot_kind() == Snapshot::kFullAOT); |
| 14259 return TypedData::null(); |
| 14260 #else |
| 14357 ASSERT(is_optimized()); | 14261 ASSERT(is_optimized()); |
| 14358 const Instructions& instrs = Instructions::Handle(instructions()); | 14262 const Instructions& instrs = Instructions::Handle(instructions()); |
| 14359 uword code_entry = instrs.PayloadStart(); | 14263 uword code_entry = instrs.PayloadStart(); |
| 14360 const Array& table = Array::Handle(deopt_info_array()); | 14264 const Array& table = Array::Handle(deopt_info_array()); |
| 14361 if (table.IsNull()) { | 14265 if (table.IsNull()) { |
| 14362 ASSERT(Dart::vm_snapshot_kind() == Snapshot::kFullAOT); | 14266 ASSERT(Dart::vm_snapshot_kind() == Snapshot::kFullAOT); |
| 14363 return TypedData::null(); | 14267 return TypedData::null(); |
| 14364 } | 14268 } |
| 14365 // Linear search for the PC offset matching the target PC. | 14269 // Linear search for the PC offset matching the target PC. |
| 14366 intptr_t length = DeoptTable::GetLength(table); | 14270 intptr_t length = DeoptTable::GetLength(table); |
| 14367 Smi& offset = Smi::Handle(); | 14271 Smi& offset = Smi::Handle(); |
| 14368 Smi& reason_and_flags = Smi::Handle(); | 14272 Smi& reason_and_flags = Smi::Handle(); |
| 14369 TypedData& info = TypedData::Handle(); | 14273 TypedData& info = TypedData::Handle(); |
| 14370 for (intptr_t i = 0; i < length; ++i) { | 14274 for (intptr_t i = 0; i < length; ++i) { |
| 14371 DeoptTable::GetEntry(table, i, &offset, &info, &reason_and_flags); | 14275 DeoptTable::GetEntry(table, i, &offset, &info, &reason_and_flags); |
| 14372 if (pc == (code_entry + offset.Value())) { | 14276 if (pc == (code_entry + offset.Value())) { |
| 14373 ASSERT(!info.IsNull()); | 14277 ASSERT(!info.IsNull()); |
| 14374 *deopt_reason = DeoptTable::ReasonField::decode(reason_and_flags.Value()); | 14278 *deopt_reason = DeoptTable::ReasonField::decode(reason_and_flags.Value()); |
| 14375 *deopt_flags = DeoptTable::FlagsField::decode(reason_and_flags.Value()); | 14279 *deopt_flags = DeoptTable::FlagsField::decode(reason_and_flags.Value()); |
| 14376 return info.raw(); | 14280 return info.raw(); |
| 14377 } | 14281 } |
| 14378 } | 14282 } |
| 14379 *deopt_reason = ICData::kDeoptUnknown; | 14283 *deopt_reason = ICData::kDeoptUnknown; |
| 14380 return TypedData::null(); | 14284 return TypedData::null(); |
| 14285 #endif // defined(DART_PRECOMPILED_RUNTIME) |
| 14381 } | 14286 } |
| 14382 | 14287 |
| 14383 | 14288 |
| 14384 intptr_t Code::BinarySearchInSCallTable(uword pc) const { | 14289 intptr_t Code::BinarySearchInSCallTable(uword pc) const { |
| 14385 #if defined(DART_PRECOMPILED_RUNTIME) | 14290 #if defined(DART_PRECOMPILED_RUNTIME) |
| 14386 UNREACHABLE(); | 14291 UNREACHABLE(); |
| 14387 #else | 14292 #else |
| 14388 NoSafepointScope no_safepoint; | 14293 NoSafepointScope no_safepoint; |
| 14389 const Array& table = Array::Handle(raw_ptr()->static_calls_target_table_); | 14294 const Array& table = Array::Handle(raw_ptr()->static_calls_target_table_); |
| 14390 RawObject* key = reinterpret_cast<RawObject*>(Smi::New(pc - PayloadStart())); | 14295 RawObject* key = reinterpret_cast<RawObject*>(Smi::New(pc - PayloadStart())); |
| (...skipping 9111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 23502 return UserTag::null(); | 23407 return UserTag::null(); |
| 23503 } | 23408 } |
| 23504 | 23409 |
| 23505 | 23410 |
| 23506 const char* UserTag::ToCString() const { | 23411 const char* UserTag::ToCString() const { |
| 23507 const String& tag_label = String::Handle(label()); | 23412 const String& tag_label = String::Handle(label()); |
| 23508 return tag_label.ToCString(); | 23413 return tag_label.ToCString(); |
| 23509 } | 23414 } |
| 23510 | 23415 |
| 23511 } // namespace dart | 23416 } // namespace dart |
| OLD | NEW |