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

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

Issue 1634863002: Introduce CodeSourceMap object to hold pc -> token position mappings (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/raw_object.h » ('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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 134 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
135 RawClass* Object::literal_token_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 135 RawClass* Object::literal_token_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
136 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 136 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
137 RawClass* Object::script_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 137 RawClass* Object::script_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
138 RawClass* Object::library_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 138 RawClass* Object::library_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
139 RawClass* Object::namespace_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 139 RawClass* Object::namespace_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
140 RawClass* Object::code_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 140 RawClass* Object::code_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
141 RawClass* Object::instructions_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 141 RawClass* Object::instructions_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
142 RawClass* Object::object_pool_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 142 RawClass* Object::object_pool_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
143 RawClass* Object::pc_descriptors_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 143 RawClass* Object::pc_descriptors_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
144 RawClass* Object::code_source_map_class_ =
145 reinterpret_cast<RawClass*>(RAW_NULL);
144 RawClass* Object::stackmap_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 146 RawClass* Object::stackmap_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
145 RawClass* Object::var_descriptors_class_ = 147 RawClass* Object::var_descriptors_class_ =
146 reinterpret_cast<RawClass*>(RAW_NULL); 148 reinterpret_cast<RawClass*>(RAW_NULL);
147 RawClass* Object::exception_handlers_class_ = 149 RawClass* Object::exception_handlers_class_ =
148 reinterpret_cast<RawClass*>(RAW_NULL); 150 reinterpret_cast<RawClass*>(RAW_NULL);
149 RawClass* Object::context_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 151 RawClass* Object::context_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
150 RawClass* Object::context_scope_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 152 RawClass* Object::context_scope_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
151 RawClass* Object::icdata_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 153 RawClass* Object::icdata_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
152 RawClass* Object::megamorphic_cache_class_ = 154 RawClass* Object::megamorphic_cache_class_ =
153 reinterpret_cast<RawClass*>(RAW_NULL); 155 reinterpret_cast<RawClass*>(RAW_NULL);
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 608
607 cls = Class::New<Instructions>(); 609 cls = Class::New<Instructions>();
608 instructions_class_ = cls.raw(); 610 instructions_class_ = cls.raw();
609 611
610 cls = Class::New<ObjectPool>(); 612 cls = Class::New<ObjectPool>();
611 object_pool_class_ = cls.raw(); 613 object_pool_class_ = cls.raw();
612 614
613 cls = Class::New<PcDescriptors>(); 615 cls = Class::New<PcDescriptors>();
614 pc_descriptors_class_ = cls.raw(); 616 pc_descriptors_class_ = cls.raw();
615 617
618 cls = Class::New<CodeSourceMap>();
619 code_source_map_class_ = cls.raw();
620
616 cls = Class::New<Stackmap>(); 621 cls = Class::New<Stackmap>();
617 stackmap_class_ = cls.raw(); 622 stackmap_class_ = cls.raw();
618 623
619 cls = Class::New<LocalVarDescriptors>(); 624 cls = Class::New<LocalVarDescriptors>();
620 var_descriptors_class_ = cls.raw(); 625 var_descriptors_class_ = cls.raw();
621 626
622 cls = Class::New<ExceptionHandlers>(); 627 cls = Class::New<ExceptionHandlers>();
623 exception_handlers_class_ = cls.raw(); 628 exception_handlers_class_ = cls.raw();
624 629
625 cls = Class::New<Context>(); 630 cls = Class::New<Context>();
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 SET_CLASS_NAME(redirection_data, RedirectionData); 943 SET_CLASS_NAME(redirection_data, RedirectionData);
939 SET_CLASS_NAME(field, Field); 944 SET_CLASS_NAME(field, Field);
940 SET_CLASS_NAME(literal_token, LiteralToken); 945 SET_CLASS_NAME(literal_token, LiteralToken);
941 SET_CLASS_NAME(token_stream, TokenStream); 946 SET_CLASS_NAME(token_stream, TokenStream);
942 SET_CLASS_NAME(script, Script); 947 SET_CLASS_NAME(script, Script);
943 SET_CLASS_NAME(library, LibraryClass); 948 SET_CLASS_NAME(library, LibraryClass);
944 SET_CLASS_NAME(namespace, Namespace); 949 SET_CLASS_NAME(namespace, Namespace);
945 SET_CLASS_NAME(code, Code); 950 SET_CLASS_NAME(code, Code);
946 SET_CLASS_NAME(instructions, Instructions); 951 SET_CLASS_NAME(instructions, Instructions);
947 SET_CLASS_NAME(object_pool, ObjectPool); 952 SET_CLASS_NAME(object_pool, ObjectPool);
953 SET_CLASS_NAME(code_source_map, CodeSourceMap);
948 SET_CLASS_NAME(pc_descriptors, PcDescriptors); 954 SET_CLASS_NAME(pc_descriptors, PcDescriptors);
949 SET_CLASS_NAME(stackmap, Stackmap); 955 SET_CLASS_NAME(stackmap, Stackmap);
950 SET_CLASS_NAME(var_descriptors, LocalVarDescriptors); 956 SET_CLASS_NAME(var_descriptors, LocalVarDescriptors);
951 SET_CLASS_NAME(exception_handlers, ExceptionHandlers); 957 SET_CLASS_NAME(exception_handlers, ExceptionHandlers);
952 SET_CLASS_NAME(context, Context); 958 SET_CLASS_NAME(context, Context);
953 SET_CLASS_NAME(context_scope, ContextScope); 959 SET_CLASS_NAME(context_scope, ContextScope);
954 SET_CLASS_NAME(icdata, ICData); 960 SET_CLASS_NAME(icdata, ICData);
955 SET_CLASS_NAME(megamorphic_cache, MegamorphicCache); 961 SET_CLASS_NAME(megamorphic_cache, MegamorphicCache);
956 SET_CLASS_NAME(subtypetestcache, SubtypeTestCache); 962 SET_CLASS_NAME(subtypetestcache, SubtypeTestCache);
957 SET_CLASS_NAME(api_error, ApiError); 963 SET_CLASS_NAME(api_error, ApiError);
(...skipping 2285 matching lines...) Expand 10 before | Expand all | Expand 10 after
3243 case kLibraryPrefixCid: 3249 case kLibraryPrefixCid:
3244 return Symbols::LibraryPrefix().raw(); 3250 return Symbols::LibraryPrefix().raw();
3245 case kNamespaceCid: 3251 case kNamespaceCid:
3246 return Symbols::Namespace().raw(); 3252 return Symbols::Namespace().raw();
3247 case kCodeCid: 3253 case kCodeCid:
3248 return Symbols::Code().raw(); 3254 return Symbols::Code().raw();
3249 case kInstructionsCid: 3255 case kInstructionsCid:
3250 return Symbols::Instructions().raw(); 3256 return Symbols::Instructions().raw();
3251 case kObjectPoolCid: 3257 case kObjectPoolCid:
3252 return Symbols::ObjectPool().raw(); 3258 return Symbols::ObjectPool().raw();
3259 case kCodeSourceMapCid:
3260 return Symbols::CodeSourceMap().raw();
3253 case kPcDescriptorsCid: 3261 case kPcDescriptorsCid:
3254 return Symbols::PcDescriptors().raw(); 3262 return Symbols::PcDescriptors().raw();
3255 case kStackmapCid: 3263 case kStackmapCid:
3256 return Symbols::Stackmap().raw(); 3264 return Symbols::Stackmap().raw();
3257 case kLocalVarDescriptorsCid: 3265 case kLocalVarDescriptorsCid:
3258 return Symbols::LocalVarDescriptors().raw(); 3266 return Symbols::LocalVarDescriptors().raw();
3259 case kExceptionHandlersCid: 3267 case kExceptionHandlersCid:
3260 return Symbols::ExceptionHandlers().raw(); 3268 return Symbols::ExceptionHandlers().raw();
3261 case kContextCid: 3269 case kContextCid:
3262 return Symbols::Context().raw(); 3270 return Symbols::Context().raw();
(...skipping 7888 matching lines...) Expand 10 before | Expand all | Expand 10 after
11151 void Instructions::PrintJSONImpl(JSONStream* stream, bool ref) const { 11159 void Instructions::PrintJSONImpl(JSONStream* stream, bool ref) const {
11152 JSONObject jsobj(stream); 11160 JSONObject jsobj(stream);
11153 AddCommonObjectProperties(&jsobj, "Object", ref); 11161 AddCommonObjectProperties(&jsobj, "Object", ref);
11154 jsobj.AddServiceId(*this); 11162 jsobj.AddServiceId(*this);
11155 if (ref) { 11163 if (ref) {
11156 return; 11164 return;
11157 } 11165 }
11158 } 11166 }
11159 11167
11160 11168
11161 // Encode integer in SLEB128 format. 11169 // Encode integer |value| in SLEB128 format and store into |data|.
11162 void PcDescriptors::EncodeInteger(GrowableArray<uint8_t>* data, 11170 static void EncodeSLEB128(GrowableArray<uint8_t>* data,
11163 intptr_t value) { 11171 intptr_t value) {
11164 bool is_last_part = false; 11172 bool is_last_part = false;
11165 while (!is_last_part) { 11173 while (!is_last_part) {
11166 uint8_t part = value & 0x7f; 11174 uint8_t part = value & 0x7f;
11167 value >>= 7; 11175 value >>= 7;
11168 if ((value == 0 && (part & 0x40) == 0) || 11176 if ((value == 0 && (part & 0x40) == 0) ||
11169 (value == static_cast<intptr_t>(-1) && (part & 0x40) != 0)) { 11177 (value == static_cast<intptr_t>(-1) && (part & 0x40) != 0)) {
11170 is_last_part = true; 11178 is_last_part = true;
11171 } else { 11179 } else {
11172 part |= 0x80; 11180 part |= 0x80;
11173 } 11181 }
11174 data->Add(part); 11182 data->Add(part);
11175 } 11183 }
11176 } 11184 }
11177 11185
11178 11186
11179 // Decode SLEB128 encoded integer. Update byte_index to the next integer. 11187 // Decode integer in SLEB128 format from |data| and update |byte_index|.
11180 intptr_t PcDescriptors::DecodeInteger(intptr_t* byte_index) const { 11188 static intptr_t DecodeSLEB128(const uint8_t* data,
11181 NoSafepointScope no_safepoint; 11189 const intptr_t data_length,
11182 const uint8_t* data = raw_ptr()->data(); 11190 intptr_t* byte_index) {
11183 ASSERT(*byte_index < Length()); 11191 ASSERT(*byte_index < data_length);
11184 uword shift = 0; 11192 uword shift = 0;
11185 intptr_t value = 0; 11193 intptr_t value = 0;
11186 uint8_t part = 0; 11194 uint8_t part = 0;
11187 do { 11195 do {
11188 part = data[(*byte_index)++]; 11196 part = data[(*byte_index)++];
11189 value |= static_cast<intptr_t>(part & 0x7f) << shift; 11197 value |= static_cast<intptr_t>(part & 0x7f) << shift;
11190 shift += 7; 11198 shift += 7;
11191 } while ((part & 0x80) != 0); 11199 } while ((part & 0x80) != 0);
11192 11200
11193 if ((shift < (sizeof(value) * 8)) && ((part & 0x40) != 0)) { 11201 if ((shift < (sizeof(value) * 8)) && ((part & 0x40) != 0)) {
11194 value |= static_cast<intptr_t>(-1) << shift; 11202 value |= static_cast<intptr_t>(-1) << shift;
11195 } 11203 }
11196 return value; 11204 return value;
11197 } 11205 }
11198 11206
11199 11207
11208 // Encode integer in SLEB128 format.
11209 void PcDescriptors::EncodeInteger(GrowableArray<uint8_t>* data,
11210 intptr_t value) {
11211 return EncodeSLEB128(data, value);
11212 }
11213
11214
11215 // Decode SLEB128 encoded integer. Update byte_index to the next integer.
11216 intptr_t PcDescriptors::DecodeInteger(intptr_t* byte_index) const {
11217 NoSafepointScope no_safepoint;
11218 const uint8_t* data = raw_ptr()->data();
11219 return DecodeSLEB128(data, Length(), byte_index);
11220 }
11221
11222
11200 RawObjectPool* ObjectPool::New(intptr_t len) { 11223 RawObjectPool* ObjectPool::New(intptr_t len) {
11201 ASSERT(Object::object_pool_class() != Class::null()); 11224 ASSERT(Object::object_pool_class() != Class::null());
11202 if (len < 0 || len > kMaxElements) { 11225 if (len < 0 || len > kMaxElements) {
11203 // This should be caught before we reach here. 11226 // This should be caught before we reach here.
11204 FATAL1("Fatal error in ObjectPool::New: invalid length %" Pd "\n", len); 11227 FATAL1("Fatal error in ObjectPool::New: invalid length %" Pd "\n", len);
11205 } 11228 }
11206 ObjectPool& result = ObjectPool::Handle(); 11229 ObjectPool& result = ObjectPool::Handle();
11207 { 11230 {
11208 uword size = ObjectPool::InstanceSize(len); 11231 uword size = ObjectPool::InstanceSize(len);
11209 RawObject* raw = Object::Allocate(ObjectPool::kClassId, 11232 RawObject* raw = Object::Allocate(ObjectPool::kClassId,
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
11488 deopt_ids->Add(iter.DeoptId()); 11511 deopt_ids->Add(iter.DeoptId());
11489 } else { 11512 } else {
11490 ASSERT(!iccall_ids->Contains(iter.DeoptId())); 11513 ASSERT(!iccall_ids->Contains(iter.DeoptId()));
11491 iccall_ids->Add(iter.DeoptId()); 11514 iccall_ids->Add(iter.DeoptId());
11492 } 11515 }
11493 } 11516 }
11494 #endif // DEBUG 11517 #endif // DEBUG
11495 } 11518 }
11496 11519
11497 11520
11521 intptr_t CodeSourceMap::Length() const {
11522 return raw_ptr()->length_;
11523 }
11524
11525
11526 void CodeSourceMap::SetLength(intptr_t value) const {
11527 StoreNonPointer(&raw_ptr()->length_, value);
11528 }
11529
11530
11531 void CodeSourceMap::CopyData(GrowableArray<uint8_t>* delta_encoded_data) {
11532 NoSafepointScope no_safepoint;
11533 uint8_t* data = UnsafeMutableNonPointer(&raw_ptr()->data()[0]);
11534 for (intptr_t i = 0; i < delta_encoded_data->length(); ++i) {
11535 data[i] = (*delta_encoded_data)[i];
11536 }
11537 }
11538
11539
11540 RawCodeSourceMap* CodeSourceMap::New(GrowableArray<uint8_t>* data) {
11541 ASSERT(Object::code_source_map_class() != Class::null());
11542 Thread* thread = Thread::Current();
11543 CodeSourceMap& result = CodeSourceMap::Handle(thread->zone());
11544 {
11545 uword size = CodeSourceMap::InstanceSize(data->length());
11546 RawObject* raw = Object::Allocate(CodeSourceMap::kClassId,
11547 size,
11548 Heap::kOld);
11549 NoSafepointScope no_safepoint;
11550 result ^= raw;
11551 result.SetLength(data->length());
11552 result.CopyData(data);
11553 }
11554 return result.raw();
11555 }
11556
11557
11558 RawCodeSourceMap* CodeSourceMap::New(intptr_t length) {
11559 ASSERT(Object::code_source_map_class() != Class::null());
11560 Thread* thread = Thread::Current();
11561 CodeSourceMap& result = CodeSourceMap::Handle(thread->zone());
11562 {
11563 uword size = CodeSourceMap::InstanceSize(length);
11564 RawObject* raw = Object::Allocate(CodeSourceMap::kClassId,
11565 size,
11566 Heap::kOld);
11567 NoSafepointScope no_safepoint;
11568 result ^= raw;
11569 result.SetLength(length);
11570 }
11571 return result.raw();
11572 }
11573
11574
11575 void CodeSourceMap::PrintJSONImpl(JSONStream* stream, bool ref) const {
11576 Object::PrintJSONImpl(stream, ref);
11577 }
11578
11579
11580 const char* CodeSourceMap::ToCString() const {
11581 // "*" in a printf format specifier tells it to read the field width from
11582 // the printf argument list.
11583 #define FORMAT "%#-*" Px "\t%" Pd "\n"
11584 if (Length() == 0) {
11585 return "empty CodeSourceMap\n";
11586 }
11587 // 4 bits per hex digit.
11588 const int addr_width = kBitsPerWord / 4;
11589 // First compute the buffer size required.
11590 intptr_t len = 1; // Trailing '\0'.
11591 {
11592 Iterator iter(*this);
11593 while (iter.MoveNext()) {
11594 len += OS::SNPrint(NULL, 0, FORMAT, addr_width,
11595 iter.PcOffset(),
11596 iter.TokenPos());
11597 }
11598 }
11599 // Allocate the buffer.
11600 char* buffer = Thread::Current()->zone()->Alloc<char>(len);
11601 // Layout the fields in the buffer.
11602 intptr_t index = 0;
11603 Iterator iter(*this);
11604 while (iter.MoveNext()) {
11605 index += OS::SNPrint((buffer + index), (len - index), FORMAT, addr_width,
11606 iter.PcOffset(),
11607 iter.TokenPos());
11608 }
11609 return buffer;
11610 #undef FORMAT
11611 }
11612
11613
11614 // Encode integer in SLEB128 format.
11615 void CodeSourceMap::EncodeInteger(GrowableArray<uint8_t>* data,
11616 intptr_t value) {
11617 return EncodeSLEB128(data, value);
11618 }
11619
11620
11621 // Decode SLEB128 encoded integer. Update byte_index to the next integer.
11622 intptr_t CodeSourceMap::DecodeInteger(intptr_t* byte_index) const {
11623 NoSafepointScope no_safepoint;
11624 const uint8_t* data = raw_ptr()->data();
11625 return DecodeSLEB128(data, Length(), byte_index);
11626 }
11627
11628
11498 bool Stackmap::GetBit(intptr_t bit_index) const { 11629 bool Stackmap::GetBit(intptr_t bit_index) const {
11499 ASSERT(InRange(bit_index)); 11630 ASSERT(InRange(bit_index));
11500 int byte_index = bit_index >> kBitsPerByteLog2; 11631 int byte_index = bit_index >> kBitsPerByteLog2;
11501 int bit_remainder = bit_index & (kBitsPerByte - 1); 11632 int bit_remainder = bit_index & (kBitsPerByte - 1);
11502 uint8_t byte_mask = 1U << bit_remainder; 11633 uint8_t byte_mask = 1U << bit_remainder;
11503 uint8_t byte = raw_ptr()->data()[byte_index]; 11634 uint8_t byte = raw_ptr()->data()[byte_index];
11504 return (byte & byte_mask); 11635 return (byte & byte_mask);
11505 } 11636 }
11506 11637
11507 11638
(...skipping 11198 matching lines...) Expand 10 before | Expand all | Expand 10 after
22706 return tag_label.ToCString(); 22837 return tag_label.ToCString();
22707 } 22838 }
22708 22839
22709 22840
22710 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 22841 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
22711 Instance::PrintJSONImpl(stream, ref); 22842 Instance::PrintJSONImpl(stream, ref);
22712 } 22843 }
22713 22844
22714 22845
22715 } // namespace dart 22846 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698