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

Side by Side Diff: vm/object.cc

Issue 9701010: First step towards implementing stack map descriptions for the optimizing compiler. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 9 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 | « vm/object.h ('k') | 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 "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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 72 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
73 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 73 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
74 RawClass* Object::literal_token_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 74 RawClass* Object::literal_token_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
75 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 75 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
76 RawClass* Object::script_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 76 RawClass* Object::script_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
77 RawClass* Object::library_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 77 RawClass* Object::library_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
78 RawClass* Object::library_prefix_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 78 RawClass* Object::library_prefix_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
79 RawClass* Object::code_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 79 RawClass* Object::code_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
80 RawClass* Object::instructions_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 80 RawClass* Object::instructions_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
81 RawClass* Object::pc_descriptors_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 81 RawClass* Object::pc_descriptors_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
82 RawClass* Object::stackmap_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
82 RawClass* Object::var_descriptors_class_ = 83 RawClass* Object::var_descriptors_class_ =
83 reinterpret_cast<RawClass*>(RAW_NULL); 84 reinterpret_cast<RawClass*>(RAW_NULL);
84 RawClass* Object::exception_handlers_class_ = 85 RawClass* Object::exception_handlers_class_ =
85 reinterpret_cast<RawClass*>(RAW_NULL); 86 reinterpret_cast<RawClass*>(RAW_NULL);
86 RawClass* Object::context_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 87 RawClass* Object::context_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
87 RawClass* Object::context_scope_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 88 RawClass* Object::context_scope_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
88 RawClass* Object::icdata_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 89 RawClass* Object::icdata_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
89 RawClass* Object::api_error_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 90 RawClass* Object::api_error_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
90 RawClass* Object::language_error_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 91 RawClass* Object::language_error_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
91 RawClass* Object::unhandled_exception_class_ = 92 RawClass* Object::unhandled_exception_class_ =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } else if (raw_class == library_class()) { 131 } else if (raw_class == library_class()) {
131 return kLibraryClass; 132 return kLibraryClass;
132 } else if (raw_class == library_prefix_class()) { 133 } else if (raw_class == library_prefix_class()) {
133 return kLibraryPrefixClass; 134 return kLibraryPrefixClass;
134 } else if (raw_class == code_class()) { 135 } else if (raw_class == code_class()) {
135 return kCodeClass; 136 return kCodeClass;
136 } else if (raw_class == instructions_class()) { 137 } else if (raw_class == instructions_class()) {
137 return kInstructionsClass; 138 return kInstructionsClass;
138 } else if (raw_class == pc_descriptors_class()) { 139 } else if (raw_class == pc_descriptors_class()) {
139 return kPcDescriptorsClass; 140 return kPcDescriptorsClass;
141 } else if (raw_class == stackmap_class()) {
142 return kStackmapClass;
140 } else if (raw_class == var_descriptors_class()) { 143 } else if (raw_class == var_descriptors_class()) {
141 return kLocalVarDescriptorsClass; 144 return kLocalVarDescriptorsClass;
142 } else if (raw_class == exception_handlers_class()) { 145 } else if (raw_class == exception_handlers_class()) {
143 return kExceptionHandlersClass; 146 return kExceptionHandlersClass;
144 } else if (raw_class == context_class()) { 147 } else if (raw_class == context_class()) {
145 return kContextClass; 148 return kContextClass;
146 } else if (raw_class == context_scope_class()) { 149 } else if (raw_class == context_scope_class()) {
147 return kContextScopeClass; 150 return kContextScopeClass;
148 } else if (raw_class == icdata_class()) { 151 } else if (raw_class == icdata_class()) {
149 return kICDataClass; 152 return kICDataClass;
(...skipping 27 matching lines...) Expand all
177 case kFunctionClass: return function_class(); 180 case kFunctionClass: return function_class();
178 case kFieldClass: return field_class(); 181 case kFieldClass: return field_class();
179 case kLiteralTokenClass: return literal_token_class(); 182 case kLiteralTokenClass: return literal_token_class();
180 case kTokenStreamClass: return token_stream_class(); 183 case kTokenStreamClass: return token_stream_class();
181 case kScriptClass: return script_class(); 184 case kScriptClass: return script_class();
182 case kLibraryClass: return library_class(); 185 case kLibraryClass: return library_class();
183 case kLibraryPrefixClass: return library_prefix_class(); 186 case kLibraryPrefixClass: return library_prefix_class();
184 case kCodeClass: return code_class(); 187 case kCodeClass: return code_class();
185 case kInstructionsClass: return instructions_class(); 188 case kInstructionsClass: return instructions_class();
186 case kPcDescriptorsClass: return pc_descriptors_class(); 189 case kPcDescriptorsClass: return pc_descriptors_class();
190 case kStackmapClass: return stackmap_class();
187 case kLocalVarDescriptorsClass: return var_descriptors_class(); 191 case kLocalVarDescriptorsClass: return var_descriptors_class();
188 case kExceptionHandlersClass: return exception_handlers_class(); 192 case kExceptionHandlersClass: return exception_handlers_class();
189 case kContextClass: return context_class(); 193 case kContextClass: return context_class();
190 case kContextScopeClass: return context_scope_class(); 194 case kContextScopeClass: return context_scope_class();
191 case kICDataClass: return icdata_class(); 195 case kICDataClass: return icdata_class();
192 case kApiErrorClass: return api_error_class(); 196 case kApiErrorClass: return api_error_class();
193 case kLanguageErrorClass: return language_error_class(); 197 case kLanguageErrorClass: return language_error_class();
194 case kUnhandledExceptionClass: return unhandled_exception_class(); 198 case kUnhandledExceptionClass: return unhandled_exception_class();
195 case kUnwindErrorClass: return unwind_error_class(); 199 case kUnwindErrorClass: return unwind_error_class();
196 default: break; 200 default: break;
(...skipping 18 matching lines...) Expand all
215 case kInstantiatedTypeArgumentsClass: return "InstantiatedTypeArguments"; 219 case kInstantiatedTypeArgumentsClass: return "InstantiatedTypeArguments";
216 case kFunctionClass: return "Function"; 220 case kFunctionClass: return "Function";
217 case kFieldClass: return "Field"; 221 case kFieldClass: return "Field";
218 case kTokenStreamClass: return "TokenStream"; 222 case kTokenStreamClass: return "TokenStream";
219 case kScriptClass: return "Script"; 223 case kScriptClass: return "Script";
220 case kLibraryClass: return "Library"; 224 case kLibraryClass: return "Library";
221 case kLibraryPrefixClass: return "LibraryPrefix"; 225 case kLibraryPrefixClass: return "LibraryPrefix";
222 case kCodeClass: return "Code"; 226 case kCodeClass: return "Code";
223 case kInstructionsClass: return "Instructions"; 227 case kInstructionsClass: return "Instructions";
224 case kPcDescriptorsClass: return "PcDescriptors"; 228 case kPcDescriptorsClass: return "PcDescriptors";
229 case kStackmapClass: return "Stackmap";
225 case kLocalVarDescriptorsClass: return "LocalVarDescriptors"; 230 case kLocalVarDescriptorsClass: return "LocalVarDescriptors";
226 case kExceptionHandlersClass: return "ExceptionHandlers"; 231 case kExceptionHandlersClass: return "ExceptionHandlers";
227 case kContextClass: return "Context"; 232 case kContextClass: return "Context";
228 case kContextScopeClass: return "ContextScope"; 233 case kContextScopeClass: return "ContextScope";
229 case kICDataClass: return "ICData"; 234 case kICDataClass: return "ICData";
230 case kApiErrorClass: return "ApiError"; 235 case kApiErrorClass: return "ApiError";
231 case kLanguageErrorClass: return "LanguageError"; 236 case kLanguageErrorClass: return "LanguageError";
232 case kUnhandledExceptionClass: return "UnhandledException"; 237 case kUnhandledExceptionClass: return "UnhandledException";
233 case kUnwindErrorClass: return "UnwindError"; 238 case kUnwindErrorClass: return "UnwindError";
234 default: break; 239 default: break;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 363
359 cls = Class::New<Code>(); 364 cls = Class::New<Code>();
360 code_class_ = cls.raw(); 365 code_class_ = cls.raw();
361 366
362 cls = Class::New<Instructions>(); 367 cls = Class::New<Instructions>();
363 instructions_class_ = cls.raw(); 368 instructions_class_ = cls.raw();
364 369
365 cls = Class::New<PcDescriptors>(); 370 cls = Class::New<PcDescriptors>();
366 pc_descriptors_class_ = cls.raw(); 371 pc_descriptors_class_ = cls.raw();
367 372
373 cls = Class::New<Stackmap>();
374 stackmap_class_ = cls.raw();
375
368 cls = Class::New<LocalVarDescriptors>(); 376 cls = Class::New<LocalVarDescriptors>();
369 var_descriptors_class_ = cls.raw(); 377 var_descriptors_class_ = cls.raw();
370 378
371 cls = Class::New<ExceptionHandlers>(); 379 cls = Class::New<ExceptionHandlers>();
372 exception_handlers_class_ = cls.raw(); 380 exception_handlers_class_ = cls.raw();
373 381
374 cls = Class::New<Context>(); 382 cls = Class::New<Context>();
375 context_class_ = cls.raw(); 383 context_class_ = cls.raw();
376 384
377 cls = Class::New<ContextScope>(); 385 cls = Class::New<ContextScope>();
(...skipping 4995 matching lines...) Expand 10 before | Expand all | Expand 10 after
5373 ASSERT(NodeId(k) != node_id); 5381 ASSERT(NodeId(k) != node_id);
5374 } 5382 }
5375 ASSERT(pc != PC(k)); 5383 ASSERT(pc != PC(k));
5376 } 5384 }
5377 } 5385 }
5378 } 5386 }
5379 #endif // DEBUG 5387 #endif // DEBUG
5380 } 5388 }
5381 5389
5382 5390
5391 // Return the bit offset of the highest bit set.
5392 intptr_t Stackmap::Maximum() const {
5393 intptr_t bound = SizeInBits();
5394 for (intptr_t i = (bound - 1); i >= 0; i--) {
5395 if (IsObject(i)) return i;
5396 }
5397 return kNoMaximum;
5398 }
5399
5400
5401 // Return the bit offset of the lowest bit set.
5402 intptr_t Stackmap::Minimum() const {
5403 intptr_t bound = SizeInBits();
5404 for (intptr_t i = 0; i < bound; i++) {
5405 if (IsObject(i)) return i;
5406 }
5407 return kNoMinimum;
5408 }
5409
5410
5411 bool Stackmap::GetBit(intptr_t bit_offset) const {
5412 ASSERT(InRange(bit_offset));
5413 int byte_offset = bit_offset >> kBitsPerByteLog2;
5414 int bit_remainder = bit_offset & (kBitsPerByte - 1);
5415 uint8_t byte_mask = 1U << bit_remainder;
5416 uint8_t byte = raw_ptr()->data_[byte_offset];
5417 return (byte & byte_mask);
5418 }
5419
5420
5421 void Stackmap::SetBit(intptr_t bit_offset, bool value) const {
5422 ASSERT(InRange(bit_offset));
5423 int byte_offset = bit_offset >> kBitsPerByteLog2;
5424 int bit_remainder = bit_offset & (kBitsPerByte - 1);
5425 uint8_t byte_mask = 1U << bit_remainder;
5426 uint8_t* byte_addr = &(raw_ptr()->data_[byte_offset]);
5427 if (value) {
5428 *byte_addr |= byte_mask;
5429 } else {
5430 *byte_addr &= ~byte_mask;
5431 }
5432 }
5433
5434
5435 RawStackmap* Stackmap::New(uword pc, const Code& code, BitmapBuilder* bmap) {
5436 const Class& cls = Class::Handle(Object::stackmap_class());
5437 ASSERT(!cls.IsNull());
5438 ASSERT(bmap != NULL);
5439 Stackmap& result = Stackmap::Handle();
5440 intptr_t size = bmap->SizeInBytes();
5441 {
5442 // Stackmap data objects are associated with a code object, allocate them
5443 // in old generation.
5444 RawObject* raw =
5445 Object::Allocate(cls, Stackmap::InstanceSize(size), Heap::kOld);
5446 NoGCScope no_gc;
5447 result ^= raw;
5448 result.set_bitmap_size_in_bytes(size);
5449 }
5450 result.set_pc(pc);
5451 result.set_code(code);
5452 intptr_t bound = bmap->SizeInBits();
5453 for (intptr_t i = 0; i < bound; i++) {
5454 result.SetBit(i, bmap->Get(i));
5455 }
5456 return result.raw();
5457 }
5458
5459
5460 void Stackmap::set_bitmap_size_in_bytes(intptr_t value) const {
5461 // This is only safe because we create a new Smi, which does not cause
5462 // heap allocation.
5463 raw_ptr()->bitmap_size_in_bytes_ = Smi::New(value);
5464 }
5465
5466
5467 void Stackmap::set_pc(uword value) const {
5468 raw_ptr()->pc_ = value;
5469 }
5470
5471
5472 void Stackmap::set_code(const Code& code) const {
5473 StorePointer(&raw_ptr()->code_, code.raw());
5474 }
5475
5476
5477 const char* Stackmap::ToCString() const {
5478 if (IsNull()) {
5479 return "{null}";
5480 } else {
5481 intptr_t index = OS::SNPrint(NULL, 0, "0x%lx { ", pc());
5482 intptr_t alloc_size = index + ((Maximum() + 1) * 2) + 2; // "{ 1 0 .... }".
5483 Isolate* isolate = Isolate::Current();
5484 char* chars = reinterpret_cast<char*>(
5485 isolate->current_zone()->Allocate(alloc_size));
5486 index = OS::SNPrint(chars, alloc_size, "0x%lx { ", pc());
5487 for (intptr_t i = 0; i <= Maximum(); i++) {
5488 index += OS::SNPrint((chars + index),
5489 (alloc_size - index),
5490 "%d ",
5491 IsObject(i) ? 1 : 0);
5492 }
5493 OS::SNPrint((chars + index), (alloc_size - index), "}");
5494 return chars;
5495 }
5496 }
5497
5498
5383 RawString* LocalVarDescriptors::GetName(intptr_t var_index) const { 5499 RawString* LocalVarDescriptors::GetName(intptr_t var_index) const {
5384 ASSERT(var_index < Length()); 5500 ASSERT(var_index < Length());
5385 const Array& names = Array::Handle(raw_ptr()->names_); 5501 const Array& names = Array::Handle(raw_ptr()->names_);
5386 ASSERT(Length() == names.Length()); 5502 ASSERT(Length() == names.Length());
5387 const String& name = String::CheckedHandle(names.At(var_index)); 5503 const String& name = String::CheckedHandle(names.At(var_index));
5388 return name.raw(); 5504 return name.raw();
5389 } 5505 }
5390 5506
5391 5507
5392 void LocalVarDescriptors::GetScopeInfo( 5508 void LocalVarDescriptors::GetScopeInfo(
(...skipping 3393 matching lines...) Expand 10 before | Expand all | Expand 10 after
8786 const String& str = String::Handle(pattern()); 8902 const String& str = String::Handle(pattern());
8787 const char* format = "JSRegExp: pattern=%s flags=%s"; 8903 const char* format = "JSRegExp: pattern=%s flags=%s";
8788 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 8904 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
8789 char* chars = reinterpret_cast<char*>( 8905 char* chars = reinterpret_cast<char*>(
8790 Isolate::Current()->current_zone()->Allocate(len + 1)); 8906 Isolate::Current()->current_zone()->Allocate(len + 1));
8791 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 8907 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
8792 return chars; 8908 return chars;
8793 } 8909 }
8794 8910
8795 } // namespace dart 8911 } // namespace dart
OLDNEW
« no previous file with comments | « vm/object.h ('k') | vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698