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 4510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4521 | 4521 |
4522 bool Function::HasBreakpoint() const { | 4522 bool Function::HasBreakpoint() const { |
4523 return Isolate::Current()->debugger()->HasBreakpoint(*this); | 4523 return Isolate::Current()->debugger()->HasBreakpoint(*this); |
4524 } | 4524 } |
4525 | 4525 |
4526 | 4526 |
4527 void Function::SetCode(const Code& value) const { | 4527 void Function::SetCode(const Code& value) const { |
4528 StorePointer(&raw_ptr()->code_, value.raw()); | 4528 StorePointer(&raw_ptr()->code_, value.raw()); |
4529 ASSERT(Function::Handle(value.function()).IsNull() || | 4529 ASSERT(Function::Handle(value.function()).IsNull() || |
4530 (value.function() == this->raw())); | 4530 (value.function() == this->raw())); |
4531 value.set_function(*this); | 4531 value.set_owner_function(*this); |
Ivan Posva
2014/02/28 21:46:35
I still think this should be called set_owner.
Cutch
2014/02/28 22:47:05
Done.
| |
4532 } | 4532 } |
4533 | 4533 |
4534 | 4534 |
4535 void Function::SwitchToUnoptimizedCode() const { | 4535 void Function::SwitchToUnoptimizedCode() const { |
4536 ASSERT(HasOptimizedCode()); | 4536 ASSERT(HasOptimizedCode()); |
4537 | 4537 |
4538 const Code& current_code = Code::Handle(CurrentCode()); | 4538 const Code& current_code = Code::Handle(CurrentCode()); |
4539 | 4539 |
4540 // Optimized code object might have been actually fully produced by the | 4540 // Optimized code object might have been actually fully produced by the |
4541 // intrinsifier in this case nothing has to be done. In fact an attempt to | 4541 // intrinsifier in this case nothing has to be done. In fact an attempt to |
(...skipping 5709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10251 } | 10251 } |
10252 } | 10252 } |
10253 | 10253 |
10254 | 10254 |
10255 // Check if object matches find condition. | 10255 // Check if object matches find condition. |
10256 bool Code::FindRawCodeVisitor::FindObject(RawObject* obj) const { | 10256 bool Code::FindRawCodeVisitor::FindObject(RawObject* obj) const { |
10257 return RawInstructions::ContainsPC(obj, pc_); | 10257 return RawInstructions::ContainsPC(obj, pc_); |
10258 } | 10258 } |
10259 | 10259 |
10260 | 10260 |
10261 RawCode* Code::LookupCode(uword pc) { | 10261 RawCode* Code::LookupCodeInIsolate(Isolate* isolate, uword pc) { |
10262 Isolate* isolate = Isolate::Current(); | 10262 ASSERT((isolate == Isolate::Current()) || (isolate == Dart::vm_isolate())); |
10263 NoGCScope no_gc; | 10263 NoGCScope no_gc; |
10264 FindRawCodeVisitor visitor(pc); | 10264 FindRawCodeVisitor visitor(pc); |
10265 RawInstructions* instr; | 10265 RawInstructions* instr; |
10266 if (isolate->heap() == NULL) { | 10266 if (isolate->heap() == NULL) { |
10267 return Code::null(); | 10267 return Code::null(); |
10268 } | 10268 } |
10269 instr = isolate->heap()->FindObjectInCodeSpace(&visitor); | 10269 instr = isolate->heap()->FindObjectInCodeSpace(&visitor); |
10270 if (instr != Instructions::null()) { | 10270 if (instr != Instructions::null()) { |
10271 return instr->ptr()->code_; | 10271 return instr->ptr()->code_; |
10272 } | 10272 } |
10273 return Code::null(); | 10273 return Code::null(); |
10274 } | 10274 } |
10275 | 10275 |
10276 | 10276 |
10277 RawCode* Code::LookupCode(uword pc) { | |
10278 return LookupCodeInIsolate(Isolate::Current(), pc); | |
10279 } | |
10280 | |
10281 | |
10282 RawCode* Code::LookupCodeInVmIsolate(uword pc) { | |
10283 return LookupCodeInIsolate(Dart::vm_isolate(), pc); | |
10284 } | |
10285 | |
10286 | |
10277 intptr_t Code::GetTokenIndexOfPC(uword pc) const { | 10287 intptr_t Code::GetTokenIndexOfPC(uword pc) const { |
10278 intptr_t token_pos = -1; | 10288 intptr_t token_pos = -1; |
10279 const PcDescriptors& descriptors = PcDescriptors::Handle(pc_descriptors()); | 10289 const PcDescriptors& descriptors = PcDescriptors::Handle(pc_descriptors()); |
10280 for (intptr_t i = 0; i < descriptors.Length(); i++) { | 10290 for (intptr_t i = 0; i < descriptors.Length(); i++) { |
10281 if (descriptors.PC(i) == pc) { | 10291 if (descriptors.PC(i) == pc) { |
10282 token_pos = descriptors.TokenPos(i); | 10292 token_pos = descriptors.TokenPos(i); |
10283 break; | 10293 break; |
10284 } | 10294 } |
10285 } | 10295 } |
10286 return token_pos; | 10296 return token_pos; |
(...skipping 28 matching lines...) Expand all Loading... | |
10315 | 10325 |
10316 const char* Code::ToCString() const { | 10326 const char* Code::ToCString() const { |
10317 const char* kFormat = "Code entry:%p"; | 10327 const char* kFormat = "Code entry:%p"; |
10318 intptr_t len = OS::SNPrint(NULL, 0, kFormat, EntryPoint()) + 1; | 10328 intptr_t len = OS::SNPrint(NULL, 0, kFormat, EntryPoint()) + 1; |
10319 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 10329 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
10320 OS::SNPrint(chars, len, kFormat, EntryPoint()); | 10330 OS::SNPrint(chars, len, kFormat, EntryPoint()); |
10321 return chars; | 10331 return chars; |
10322 } | 10332 } |
10323 | 10333 |
10324 | 10334 |
10335 RawString* Code::Name() const { | |
Ivan Posva
2014/02/28 21:46:35
If we stored the Class object instead of the cid a
Cutch
2014/02/28 22:47:05
Done.
| |
10336 if (OwnerIsStub()) { | |
10337 // Regular stub. | |
10338 const char* name = StubCode::NameOfStub(EntryPoint()); | |
10339 ASSERT(name != NULL); | |
10340 return String::New(name); | |
10341 } else if (OwnerIsAllocationStub()) { | |
10342 // Allocation stub. | |
10343 Isolate* isolate = Isolate::Current(); | |
10344 ClassTable* class_table = isolate->class_table(); | |
10345 intptr_t cid = Smi::Value(allocation_stub_class_id()); | |
10346 Class& cls = Class::Handle(); | |
10347 cls ^= class_table->At(cid); | |
10348 ASSERT(!cls.IsNull()); | |
10349 String& cls_name = String::Handle(cls.Name()); | |
10350 ASSERT(!cls_name.IsNull()); | |
10351 return String::Concat(Symbols::AllocationStubFor(), cls_name); | |
10352 } else { | |
10353 ASSERT(OwnerIsFunction()); | |
10354 // Dart function. | |
10355 Function& func = Function::Handle(); | |
10356 func ^= function(); | |
10357 ASSERT(!func.IsNull()); | |
10358 return func.name(); | |
10359 } | |
10360 } | |
10361 | |
10362 | |
10363 RawString* Code::UserName() const { | |
10364 if (OwnerIsStub()) { | |
10365 // Regular stub. | |
10366 const char* name = StubCode::NameOfStub(EntryPoint()); | |
10367 ASSERT(name != NULL); | |
10368 return String::New(name); | |
10369 } else if (OwnerIsAllocationStub()) { | |
10370 // Allocation stub. | |
10371 Isolate* isolate = Isolate::Current(); | |
10372 ClassTable* class_table = isolate->class_table(); | |
10373 intptr_t cid = Smi::Value(allocation_stub_class_id()); | |
10374 Class& cls = Class::Handle(); | |
10375 cls ^= class_table->At(cid); | |
10376 ASSERT(!cls.IsNull()); | |
10377 String& cls_name = String::Handle(cls.UserVisibleName()); | |
10378 ASSERT(!cls_name.IsNull()); | |
10379 return String::Concat(Symbols::AllocationStubFor(), cls_name); | |
10380 } else { | |
10381 ASSERT(OwnerIsFunction()); | |
10382 // Dart function. | |
10383 Function& func = Function::Handle(); | |
10384 func ^= function(); | |
10385 ASSERT(!func.IsNull()); | |
10386 return func.QualifiedUserVisibleName(); | |
10387 } | |
10388 } | |
10389 | |
10325 void Code::PrintToJSONStream(JSONStream* stream, bool ref) const { | 10390 void Code::PrintToJSONStream(JSONStream* stream, bool ref) const { |
10326 JSONObject jsobj(stream); | 10391 JSONObject jsobj(stream); |
10327 jsobj.AddProperty("type", JSONType(ref)); | 10392 jsobj.AddProperty("type", JSONType(ref)); |
10328 jsobj.AddPropertyF("id", "code/%" Px "", EntryPoint()); | 10393 jsobj.AddPropertyF("id", "code/%" Px "", EntryPoint()); |
10329 jsobj.AddPropertyF("start", "%" Px "", EntryPoint()); | 10394 jsobj.AddPropertyF("start", "%" Px "", EntryPoint()); |
10330 jsobj.AddPropertyF("end", "%" Px "", EntryPoint() + Size()); | 10395 jsobj.AddPropertyF("end", "%" Px "", EntryPoint() + Size()); |
10331 Function& func = Function::Handle(); | 10396 jsobj.AddProperty("is_optimized", is_optimized()); |
10332 func ^= function(); | 10397 jsobj.AddProperty("is_alive", is_alive()); |
10333 ASSERT(!func.IsNull()); | 10398 const String& name = String::Handle(Name()); |
10334 String& name = String::Handle(); | 10399 const String& user_name = String::Handle(UserName()); |
10335 ASSERT(!func.IsNull()); | 10400 const char* name_prefix = is_optimized() ? "*" : ""; |
10336 name ^= func.name(); | 10401 jsobj.AddPropertyF("name", "%s%s", name_prefix, name.ToCString()); |
10337 const char* internal_function_name = name.ToCString(); | 10402 jsobj.AddPropertyF("user_name", "%s%s", name_prefix, user_name.ToCString()); |
10338 jsobj.AddPropertyF("name", "%s%s", is_optimized() ? "*" : "", | |
10339 internal_function_name); | |
10340 name ^= func.QualifiedUserVisibleName(); | |
10341 const char* function_name = name.ToCString(); | |
10342 jsobj.AddPropertyF("user_name", "%s%s", is_optimized() ? "*" : "", | |
10343 function_name); | |
10344 if (ref) { | 10403 if (ref) { |
10345 return; | 10404 return; |
10346 } | 10405 } |
10347 jsobj.AddProperty("is_optimized", is_optimized()); | |
10348 jsobj.AddProperty("is_alive", is_alive()); | |
10349 jsobj.AddProperty("function", Object::Handle(function())); | |
10350 JSONArray jsarr(&jsobj, "disassembly"); | 10406 JSONArray jsarr(&jsobj, "disassembly"); |
10351 if (is_alive()) { | 10407 if (is_alive()) { |
10352 // Only disassemble alive code objects. | 10408 // Only disassemble alive code objects. |
10353 DisassembleToJSONStream formatter(jsarr); | 10409 DisassembleToJSONStream formatter(jsarr); |
10354 Disassemble(&formatter); | 10410 Disassemble(&formatter); |
10355 } | 10411 } |
10356 } | 10412 } |
10357 | 10413 |
10358 | 10414 |
10359 uword Code::GetPatchCodePc() const { | 10415 uword Code::GetPatchCodePc() const { |
(...skipping 7066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17426 return "_MirrorReference"; | 17482 return "_MirrorReference"; |
17427 } | 17483 } |
17428 | 17484 |
17429 | 17485 |
17430 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 17486 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
17431 Instance::PrintToJSONStream(stream, ref); | 17487 Instance::PrintToJSONStream(stream, ref); |
17432 } | 17488 } |
17433 | 17489 |
17434 | 17490 |
17435 } // namespace dart | 17491 } // namespace dart |
OLD | NEW |