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

Side by Side Diff: src/frames.cc

Issue 9401019: Support for return-address rewriting profilers. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Supply return address resolution function through an API. Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 23 matching lines...) Expand all
34 #include "mark-compact.h" 34 #include "mark-compact.h"
35 #include "safepoint-table.h" 35 #include "safepoint-table.h"
36 #include "scopeinfo.h" 36 #include "scopeinfo.h"
37 #include "string-stream.h" 37 #include "string-stream.h"
38 38
39 #include "allocation-inl.h" 39 #include "allocation-inl.h"
40 40
41 namespace v8 { 41 namespace v8 {
42 namespace internal { 42 namespace internal {
43 43
44
45 ReturnAddressLocationResolver return_address_location_resolver = NULL;
Vyacheslav Egorov (Chromium) 2012/02/24 10:34:02 declare it static
Sigurður Ásgeirsson 2012/02/24 14:46:04 Done.
46
47
48 // Resolves pc_address through the resolution address function if one is set.
49 Address* ResolveReturnAddressLocation(Address* pc_address) {
Vyacheslav Egorov (Chromium) 2012/02/24 10:34:02 declare it static
Sigurður Ásgeirsson 2012/02/24 14:46:04 Done. Does this warrant "static inline" or are the
Vyacheslav Egorov (Chromium) 2012/02/24 14:48:21 Yes, I think there is no harm declaring it inline
Sigurður Ásgeirsson 2012/02/24 14:59:40 Done.
50 if (return_address_location_resolver == NULL) {
51 return pc_address;
52 } else {
53 return reinterpret_cast<Address*>(
54 return_address_location_resolver(
55 reinterpret_cast<uintptr_t>(pc_address)));
56 }
57 }
58
59
44 // Iterator that supports traversing the stack handlers of a 60 // Iterator that supports traversing the stack handlers of a
45 // particular frame. Needs to know the top of the handler chain. 61 // particular frame. Needs to know the top of the handler chain.
46 class StackHandlerIterator BASE_EMBEDDED { 62 class StackHandlerIterator BASE_EMBEDDED {
47 public: 63 public:
48 StackHandlerIterator(const StackFrame* frame, StackHandler* handler) 64 StackHandlerIterator(const StackFrame* frame, StackHandler* handler)
49 : limit_(frame->fp()), handler_(handler) { 65 : limit_(frame->fp()), handler_(handler) {
50 // Make sure the handler has already been unwound to this frame. 66 // Make sure the handler has already been unwound to this frame.
51 ASSERT(frame->sp() <= handler->address()); 67 ASSERT(frame->sp() <= handler->address());
52 } 68 }
53 69
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 StackFrame::Type type; 164 StackFrame::Type type;
149 if (thread_ != NULL) { 165 if (thread_ != NULL) {
150 type = ExitFrame::GetStateForFramePointer( 166 type = ExitFrame::GetStateForFramePointer(
151 Isolate::c_entry_fp(thread_), &state); 167 Isolate::c_entry_fp(thread_), &state);
152 handler_ = StackHandler::FromAddress( 168 handler_ = StackHandler::FromAddress(
153 Isolate::handler(thread_)); 169 Isolate::handler(thread_));
154 } else { 170 } else {
155 ASSERT(fp_ != NULL); 171 ASSERT(fp_ != NULL);
156 state.fp = fp_; 172 state.fp = fp_;
157 state.sp = sp_; 173 state.sp = sp_;
158 state.pc_address = 174 state.pc_address = ResolveReturnAddressLocation(
159 reinterpret_cast<Address*>(StandardFrame::ComputePCAddress(fp_)); 175 reinterpret_cast<Address*>(StandardFrame::ComputePCAddress(fp_)));
160 type = StackFrame::ComputeType(isolate(), &state); 176 type = StackFrame::ComputeType(isolate(), &state);
161 } 177 }
162 if (SingletonFor(type) == NULL) return; 178 if (SingletonFor(type) == NULL) return;
163 frame_ = SingletonFor(type, &state); 179 frame_ = SingletonFor(type, &state);
164 } 180 }
165 181
166 182
167 StackFrame* StackFrameIterator::SingletonFor(StackFrame::Type type, 183 StackFrame* StackFrameIterator::SingletonFor(StackFrame::Type type,
168 StackFrame::State* state) { 184 StackFrame::State* state) {
169 if (type == StackFrame::NONE) return NULL; 185 if (type == StackFrame::NONE) return NULL;
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 ASSERT(GcSafeCodeContains(holder, pc)); 421 ASSERT(GcSafeCodeContains(holder, pc));
406 unsigned pc_offset = static_cast<unsigned>(pc - holder->instruction_start()); 422 unsigned pc_offset = static_cast<unsigned>(pc - holder->instruction_start());
407 Object* code = holder; 423 Object* code = holder;
408 v->VisitPointer(&code); 424 v->VisitPointer(&code);
409 if (code != holder) { 425 if (code != holder) {
410 holder = reinterpret_cast<Code*>(code); 426 holder = reinterpret_cast<Code*>(code);
411 pc = holder->instruction_start() + pc_offset; 427 pc = holder->instruction_start() + pc_offset;
412 *pc_address = pc; 428 *pc_address = pc;
413 } 429 }
414 } 430 }
415 431
Vyacheslav Egorov (Chromium) 2012/02/24 10:34:02 add empty line
Sigurður Ásgeirsson 2012/02/24 14:46:04 Done.
432 void StackFrame::SetReturnAddressLocationResolver(
433 ReturnAddressLocationResolver resolver) {
434 return_address_location_resolver = resolver;
Vyacheslav Egorov (Chromium) 2012/02/24 10:34:02 assert that we don't have any other resolver insta
Sigurður Ásgeirsson 2012/02/24 14:46:04 Done.
435 }
436
416 437
417 StackFrame::Type StackFrame::ComputeType(Isolate* isolate, State* state) { 438 StackFrame::Type StackFrame::ComputeType(Isolate* isolate, State* state) {
418 ASSERT(state->fp != NULL); 439 ASSERT(state->fp != NULL);
419 if (StandardFrame::IsArgumentsAdaptorFrame(state->fp)) { 440 if (StandardFrame::IsArgumentsAdaptorFrame(state->fp)) {
420 return ARGUMENTS_ADAPTOR; 441 return ARGUMENTS_ADAPTOR;
421 } 442 }
422 // The marker and function offsets overlap. If the marker isn't a 443 // The marker and function offsets overlap. If the marker isn't a
423 // smi then the frame is a JavaScript frame -- and the marker is 444 // smi then the frame is a JavaScript frame -- and the marker is
424 // really the function. 445 // really the function.
425 const int offset = StandardFrameConstants::kMarkerOffset; 446 const int offset = StandardFrameConstants::kMarkerOffset;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 502
482 Code* ExitFrame::unchecked_code() const { 503 Code* ExitFrame::unchecked_code() const {
483 return reinterpret_cast<Code*>(code_slot()); 504 return reinterpret_cast<Code*>(code_slot());
484 } 505 }
485 506
486 507
487 void ExitFrame::ComputeCallerState(State* state) const { 508 void ExitFrame::ComputeCallerState(State* state) const {
488 // Set up the caller state. 509 // Set up the caller state.
489 state->sp = caller_sp(); 510 state->sp = caller_sp();
490 state->fp = Memory::Address_at(fp() + ExitFrameConstants::kCallerFPOffset); 511 state->fp = Memory::Address_at(fp() + ExitFrameConstants::kCallerFPOffset);
491 state->pc_address 512 state->pc_address = ResolveReturnAddressLocation(
492 = reinterpret_cast<Address*>(fp() + ExitFrameConstants::kCallerPCOffset); 513 reinterpret_cast<Address*>(fp() + ExitFrameConstants::kCallerPCOffset));
493 } 514 }
494 515
495 516
496 void ExitFrame::SetCallerFp(Address caller_fp) { 517 void ExitFrame::SetCallerFp(Address caller_fp) {
497 Memory::Address_at(fp() + ExitFrameConstants::kCallerFPOffset) = caller_fp; 518 Memory::Address_at(fp() + ExitFrameConstants::kCallerFPOffset) = caller_fp;
498 } 519 }
499 520
500 521
501 void ExitFrame::Iterate(ObjectVisitor* v) const { 522 void ExitFrame::Iterate(ObjectVisitor* v) const {
502 // The arguments are traversed as part of the expression stack of 523 // The arguments are traversed as part of the expression stack of
(...skipping 13 matching lines...) Expand all
516 Address sp = ComputeStackPointer(fp); 537 Address sp = ComputeStackPointer(fp);
517 FillState(fp, sp, state); 538 FillState(fp, sp, state);
518 ASSERT(*state->pc_address != NULL); 539 ASSERT(*state->pc_address != NULL);
519 return EXIT; 540 return EXIT;
520 } 541 }
521 542
522 543
523 void ExitFrame::FillState(Address fp, Address sp, State* state) { 544 void ExitFrame::FillState(Address fp, Address sp, State* state) {
524 state->sp = sp; 545 state->sp = sp;
525 state->fp = fp; 546 state->fp = fp;
526 state->pc_address = reinterpret_cast<Address*>(sp - 1 * kPointerSize); 547 state->pc_address = ResolveReturnAddressLocation(
548 reinterpret_cast<Address*>(sp - 1 * kPointerSize));
527 } 549 }
528 550
529 551
530 Address StandardFrame::GetExpressionAddress(int n) const { 552 Address StandardFrame::GetExpressionAddress(int n) const {
531 const int offset = StandardFrameConstants::kExpressionsOffset; 553 const int offset = StandardFrameConstants::kExpressionsOffset;
532 return fp() + offset - n * kPointerSize; 554 return fp() + offset - n * kPointerSize;
533 } 555 }
534 556
535 557
536 Object* StandardFrame::GetExpression(Address fp, int index) { 558 Object* StandardFrame::GetExpression(Address fp, int index) {
(...skipping 14 matching lines...) Expand all
551 Address limit = sp(); 573 Address limit = sp();
552 ASSERT(base >= limit); // stack grows downwards 574 ASSERT(base >= limit); // stack grows downwards
553 // Include register-allocated locals in number of expressions. 575 // Include register-allocated locals in number of expressions.
554 return static_cast<int>((base - limit) / kPointerSize); 576 return static_cast<int>((base - limit) / kPointerSize);
555 } 577 }
556 578
557 579
558 void StandardFrame::ComputeCallerState(State* state) const { 580 void StandardFrame::ComputeCallerState(State* state) const {
559 state->sp = caller_sp(); 581 state->sp = caller_sp();
560 state->fp = caller_fp(); 582 state->fp = caller_fp();
561 state->pc_address = reinterpret_cast<Address*>(ComputePCAddress(fp())); 583 state->pc_address = ResolveReturnAddressLocation(
584 reinterpret_cast<Address*>(ComputePCAddress(fp())));
562 } 585 }
563 586
564 587
565 void StandardFrame::SetCallerFp(Address caller_fp) { 588 void StandardFrame::SetCallerFp(Address caller_fp) {
566 Memory::Address_at(fp() + StandardFrameConstants::kCallerFPOffset) = 589 Memory::Address_at(fp() + StandardFrameConstants::kCallerFPOffset) =
567 caller_fp; 590 caller_fp;
568 } 591 }
569 592
570 593
571 bool StandardFrame::IsExpressionInsideHandler(int n) const { 594 bool StandardFrame::IsExpressionInsideHandler(int n) const {
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 ZoneList<StackFrame*> list(10); 1413 ZoneList<StackFrame*> list(10);
1391 for (StackFrameIterator it; !it.done(); it.Advance()) { 1414 for (StackFrameIterator it; !it.done(); it.Advance()) {
1392 StackFrame* frame = AllocateFrameCopy(it.frame()); 1415 StackFrame* frame = AllocateFrameCopy(it.frame());
1393 list.Add(frame); 1416 list.Add(frame);
1394 } 1417 }
1395 return list.ToVector(); 1418 return list.ToVector();
1396 } 1419 }
1397 1420
1398 1421
1399 } } // namespace v8::internal 1422 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698