Speed up CalledAsConstructor.

Changed CalledAsConstructor to process the raw runtime stack directly,
rather than using a StackFrameIterator.  Using an interator turns out
to be quite expensive and the vast majority of the work done is not
relevant to deciding if we've been called as a constructor.

This speeds up getElementById by ~13%.

Review URL: http://codereview.chromium.org/160325

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2578 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 0d2c8158
...@@ -87,18 +87,34 @@ static inline Object* __builtin_arg__(int n, int argc, Object** argv) { ...@@ -87,18 +87,34 @@ static inline Object* __builtin_arg__(int n, int argc, Object** argv) {
} }
// TODO(1238487): Get rid of this function that determines if the
// builtin is called as a constructor. This may be a somewhat slow
// operation due to the stack frame iteration.
static inline bool CalledAsConstructor() { static inline bool CalledAsConstructor() {
#ifdef DEBUG
// Calculate the result using a full stack frame iterator and check
// that the state of the stack is as we assume it to be in the
// code below.
StackFrameIterator it; StackFrameIterator it;
ASSERT(it.frame()->is_exit()); ASSERT(it.frame()->is_exit());
it.Advance(); it.Advance();
StackFrame* frame = it.frame(); StackFrame* frame = it.frame();
return frame->is_construct(); bool reference_result = frame->is_construct();
#endif
Address fp = Top::c_entry_fp(Top::GetCurrentThread());
// Because we know fp points to an exit frame we can use the relevant
// part of ExitFrame::ComputeCallerState directly.
const int kCallerOffset = ExitFrameConstants::kCallerFPOffset;
Address caller_fp = Memory::Address_at(fp + kCallerOffset);
// This inlines the part of StackFrame::ComputeType that grabs the
// type of the current frame. Note that StackFrame::ComputeType
// has been specialized for each architecture so if any one of them
// changes this code has to be changed as well.
const int kMarkerOffset = StandardFrameConstants::kMarkerOffset;
const Smi* kConstructMarker = Smi::FromInt(StackFrame::CONSTRUCT);
Object* marker = Memory::Object_at(caller_fp + kMarkerOffset);
bool result = (marker == kConstructMarker);
ASSERT_EQ(result, reference_result);
return result;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment