| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 11 matching lines...) Expand all Loading... |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "api.h" | 30 #include "api.h" |
| 31 #include "bootstrapper.h" | 31 #include "bootstrapper.h" |
| 32 #include "compiler.h" |
| 32 #include "debug.h" | 33 #include "debug.h" |
| 33 #include "execution.h" | 34 #include "execution.h" |
| 34 #include "messages.h" | 35 #include "messages.h" |
| 35 #include "platform.h" | 36 #include "platform.h" |
| 36 #include "simulator.h" | 37 #include "simulator.h" |
| 37 #include "string-stream.h" | 38 #include "string-stream.h" |
| 38 #include "vm-state-inl.h" | 39 #include "vm-state-inl.h" |
| 39 | 40 |
| 41 |
| 40 // TODO(isolates): move to isolate.cc. This stuff is kept here to | 42 // TODO(isolates): move to isolate.cc. This stuff is kept here to |
| 41 // simplify merging. | 43 // simplify merging. |
| 42 | 44 |
| 43 namespace v8 { | 45 namespace v8 { |
| 44 namespace internal { | 46 namespace internal { |
| 45 | 47 |
| 46 v8::TryCatch* ThreadLocalTop::TryCatchHandler() { | 48 v8::TryCatch* ThreadLocalTop::TryCatchHandler() { |
| 47 return TRY_CATCH_FROM_ADDRESS(try_catch_handler_address()); | 49 return TRY_CATCH_FROM_ADDRESS(try_catch_handler_address()); |
| 48 } | 50 } |
| 49 | 51 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 84 |
| 83 | 85 |
| 84 char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) { | 86 char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) { |
| 85 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage); | 87 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage); |
| 86 Iterate(v, thread); | 88 Iterate(v, thread); |
| 87 return thread_storage + sizeof(ThreadLocalTop); | 89 return thread_storage + sizeof(ThreadLocalTop); |
| 88 } | 90 } |
| 89 | 91 |
| 90 | 92 |
| 91 void Isolate::IterateThread(ThreadVisitor* v) { | 93 void Isolate::IterateThread(ThreadVisitor* v) { |
| 92 v->VisitThread(thread_local_top()); | 94 v->VisitThread(this, thread_local_top()); |
| 93 } | 95 } |
| 94 | 96 |
| 95 | 97 |
| 96 void Isolate::IterateThread(ThreadVisitor* v, char* t) { | 98 void Isolate::IterateThread(ThreadVisitor* v, char* t) { |
| 97 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(t); | 99 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(t); |
| 98 v->VisitThread(thread); | 100 v->VisitThread(this, thread); |
| 99 } | 101 } |
| 100 | 102 |
| 101 | 103 |
| 102 void Isolate::Iterate(ObjectVisitor* v, ThreadLocalTop* thread) { | 104 void Isolate::Iterate(ObjectVisitor* v, ThreadLocalTop* thread) { |
| 103 // Visit the roots from the top for a given thread. | 105 // Visit the roots from the top for a given thread. |
| 104 Object* pending; | 106 Object* pending; |
| 105 // The pending exception can sometimes be a failure. We can't show | 107 // The pending exception can sometimes be a failure. We can't show |
| 106 // that to the GC, which only understands objects. | 108 // that to the GC, which only understands objects. |
| 107 if (thread->pending_exception_->ToObject(&pending)) { | 109 if (thread->pending_exception_->ToObject(&pending)) { |
| 108 v->VisitPointer(&pending); | 110 v->VisitPointer(&pending); |
| 109 thread->pending_exception_ = pending; // In case GC updated it. | 111 thread->pending_exception_ = pending; // In case GC updated it. |
| 110 } | 112 } |
| 111 v->VisitPointer(&(thread->pending_message_obj_)); | 113 v->VisitPointer(&(thread->pending_message_obj_)); |
| 112 v->VisitPointer(BitCast<Object**>(&(thread->pending_message_script_))); | 114 v->VisitPointer(BitCast<Object**>(&(thread->pending_message_script_))); |
| 113 v->VisitPointer(BitCast<Object**>(&(thread->context_))); | 115 v->VisitPointer(BitCast<Object**>(&(thread->context_))); |
| 114 Object* scheduled; | 116 Object* scheduled; |
| 115 if (thread->scheduled_exception_->ToObject(&scheduled)) { | 117 if (thread->scheduled_exception_->ToObject(&scheduled)) { |
| 116 v->VisitPointer(&scheduled); | 118 v->VisitPointer(&scheduled); |
| 117 thread->scheduled_exception_ = scheduled; | 119 thread->scheduled_exception_ = scheduled; |
| 118 } | 120 } |
| 119 | 121 |
| 120 for (v8::TryCatch* block = thread->TryCatchHandler(); | 122 for (v8::TryCatch* block = thread->TryCatchHandler(); |
| 121 block != NULL; | 123 block != NULL; |
| 122 block = TRY_CATCH_FROM_ADDRESS(block->next_)) { | 124 block = TRY_CATCH_FROM_ADDRESS(block->next_)) { |
| 123 v->VisitPointer(BitCast<Object**>(&(block->exception_))); | 125 v->VisitPointer(BitCast<Object**>(&(block->exception_))); |
| 124 v->VisitPointer(BitCast<Object**>(&(block->message_))); | 126 v->VisitPointer(BitCast<Object**>(&(block->message_))); |
| 125 } | 127 } |
| 126 | 128 |
| 127 // Iterate over pointers on native execution stack. | 129 // Iterate over pointers on native execution stack. |
| 128 for (StackFrameIterator it(thread); !it.done(); it.Advance()) { | 130 for (StackFrameIterator it(this, thread); !it.done(); it.Advance()) { |
| 129 it.frame()->Iterate(v); | 131 it.frame()->Iterate(v); |
| 130 } | 132 } |
| 131 } | 133 } |
| 132 | 134 |
| 133 | 135 |
| 134 void Isolate::Iterate(ObjectVisitor* v) { | 136 void Isolate::Iterate(ObjectVisitor* v) { |
| 135 ThreadLocalTop* current_t = thread_local_top(); | 137 ThreadLocalTop* current_t = thread_local_top(); |
| 136 Iterate(v, current_t); | 138 Iterate(v, current_t); |
| 137 } | 139 } |
| 138 | 140 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 Handle<String> script_key = factory()->LookupAsciiSymbol("scriptName"); | 199 Handle<String> script_key = factory()->LookupAsciiSymbol("scriptName"); |
| 198 Handle<String> name_or_source_url_key = | 200 Handle<String> name_or_source_url_key = |
| 199 factory()->LookupAsciiSymbol("nameOrSourceURL"); | 201 factory()->LookupAsciiSymbol("nameOrSourceURL"); |
| 200 Handle<String> script_name_or_source_url_key = | 202 Handle<String> script_name_or_source_url_key = |
| 201 factory()->LookupAsciiSymbol("scriptNameOrSourceURL"); | 203 factory()->LookupAsciiSymbol("scriptNameOrSourceURL"); |
| 202 Handle<String> function_key = factory()->LookupAsciiSymbol("functionName"); | 204 Handle<String> function_key = factory()->LookupAsciiSymbol("functionName"); |
| 203 Handle<String> eval_key = factory()->LookupAsciiSymbol("isEval"); | 205 Handle<String> eval_key = factory()->LookupAsciiSymbol("isEval"); |
| 204 Handle<String> constructor_key = | 206 Handle<String> constructor_key = |
| 205 factory()->LookupAsciiSymbol("isConstructor"); | 207 factory()->LookupAsciiSymbol("isConstructor"); |
| 206 | 208 |
| 207 StackTraceFrameIterator it; | 209 StackTraceFrameIterator it(this); |
| 208 int frames_seen = 0; | 210 int frames_seen = 0; |
| 209 while (!it.done() && (frames_seen < limit)) { | 211 while (!it.done() && (frames_seen < limit)) { |
| 210 JavaScriptFrame* frame = it.frame(); | 212 JavaScriptFrame* frame = it.frame(); |
| 211 | 213 // Set initial size to the maximum inlining level + 1 for the outermost |
| 212 List<FrameSummary> frames(3); // Max 2 levels of inlining. | 214 // function. |
| 215 List<FrameSummary> frames(Compiler::kMaxInliningLevels + 1); |
| 213 frame->Summarize(&frames); | 216 frame->Summarize(&frames); |
| 214 for (int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) { | 217 for (int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) { |
| 215 // Create a JSObject to hold the information for the StackFrame. | 218 // Create a JSObject to hold the information for the StackFrame. |
| 216 Handle<JSObject> stackFrame = factory()->NewJSObject(object_function()); | 219 Handle<JSObject> stackFrame = factory()->NewJSObject(object_function()); |
| 217 | 220 |
| 218 Handle<JSFunction> fun = frames[i].function(); | 221 Handle<JSFunction> fun = frames[i].function(); |
| 219 Handle<Script> script(Script::cast(fun->shared()->script())); | 222 Handle<Script> script(Script::cast(fun->shared()->script())); |
| 220 | 223 |
| 221 if (options & StackTrace::kLineNumber) { | 224 if (options & StackTrace::kLineNumber) { |
| 222 int script_line_offset = script->line_offset()->value(); | 225 int script_line_offset = script->line_offset()->value(); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 | 580 |
| 578 Failure* Isolate::PromoteScheduledException() { | 581 Failure* Isolate::PromoteScheduledException() { |
| 579 MaybeObject* thrown = scheduled_exception(); | 582 MaybeObject* thrown = scheduled_exception(); |
| 580 clear_scheduled_exception(); | 583 clear_scheduled_exception(); |
| 581 // Re-throw the exception to avoid getting repeated error reporting. | 584 // Re-throw the exception to avoid getting repeated error reporting. |
| 582 return ReThrow(thrown); | 585 return ReThrow(thrown); |
| 583 } | 586 } |
| 584 | 587 |
| 585 | 588 |
| 586 void Isolate::PrintCurrentStackTrace(FILE* out) { | 589 void Isolate::PrintCurrentStackTrace(FILE* out) { |
| 587 StackTraceFrameIterator it; | 590 StackTraceFrameIterator it(this); |
| 588 while (!it.done()) { | 591 while (!it.done()) { |
| 589 HandleScope scope; | 592 HandleScope scope; |
| 590 // Find code position if recorded in relocation info. | 593 // Find code position if recorded in relocation info. |
| 591 JavaScriptFrame* frame = it.frame(); | 594 JavaScriptFrame* frame = it.frame(); |
| 592 int pos = frame->LookupCode(this)->SourcePosition(frame->pc()); | 595 int pos = frame->LookupCode()->SourcePosition(frame->pc()); |
| 593 Handle<Object> pos_obj(Smi::FromInt(pos)); | 596 Handle<Object> pos_obj(Smi::FromInt(pos)); |
| 594 // Fetch function and receiver. | 597 // Fetch function and receiver. |
| 595 Handle<JSFunction> fun(JSFunction::cast(frame->function())); | 598 Handle<JSFunction> fun(JSFunction::cast(frame->function())); |
| 596 Handle<Object> recv(frame->receiver()); | 599 Handle<Object> recv(frame->receiver()); |
| 597 // Advance to the next JavaScript frame and determine if the | 600 // Advance to the next JavaScript frame and determine if the |
| 598 // current frame is the top-level frame. | 601 // current frame is the top-level frame. |
| 599 it.Advance(); | 602 it.Advance(); |
| 600 Handle<Object> is_top_level = it.done() | 603 Handle<Object> is_top_level = it.done() |
| 601 ? factory()->true_value() | 604 ? factory()->true_value() |
| 602 : factory()->false_value(); | 605 : factory()->false_value(); |
| 603 // Generate and print stack trace line. | 606 // Generate and print stack trace line. |
| 604 Handle<String> line = | 607 Handle<String> line = |
| 605 Execution::GetStackTraceLine(recv, fun, pos_obj, is_top_level); | 608 Execution::GetStackTraceLine(recv, fun, pos_obj, is_top_level); |
| 606 if (line->length() > 0) { | 609 if (line->length() > 0) { |
| 607 line->PrintOn(out); | 610 line->PrintOn(out); |
| 608 fprintf(out, "\n"); | 611 fprintf(out, "\n"); |
| 609 } | 612 } |
| 610 } | 613 } |
| 611 } | 614 } |
| 612 | 615 |
| 613 | 616 |
| 614 void Isolate::ComputeLocation(MessageLocation* target) { | 617 void Isolate::ComputeLocation(MessageLocation* target) { |
| 615 *target = MessageLocation(Handle<Script>(heap_.empty_script()), -1, -1); | 618 *target = MessageLocation(Handle<Script>(heap_.empty_script()), -1, -1); |
| 616 StackTraceFrameIterator it; | 619 StackTraceFrameIterator it(this); |
| 617 if (!it.done()) { | 620 if (!it.done()) { |
| 618 JavaScriptFrame* frame = it.frame(); | 621 JavaScriptFrame* frame = it.frame(); |
| 619 JSFunction* fun = JSFunction::cast(frame->function()); | 622 JSFunction* fun = JSFunction::cast(frame->function()); |
| 620 Object* script = fun->shared()->script(); | 623 Object* script = fun->shared()->script(); |
| 621 if (script->IsScript() && | 624 if (script->IsScript() && |
| 622 !(Script::cast(script)->source()->IsUndefined())) { | 625 !(Script::cast(script)->source()->IsUndefined())) { |
| 623 int pos = frame->LookupCode(this)->SourcePosition(frame->pc()); | 626 int pos = frame->LookupCode()->SourcePosition(frame->pc()); |
| 624 // Compute the location from the function and the reloc info. | 627 // Compute the location from the function and the reloc info. |
| 625 Handle<Script> casted_script(Script::cast(script)); | 628 Handle<Script> casted_script(Script::cast(script)); |
| 626 *target = MessageLocation(casted_script, pos, pos + 1); | 629 *target = MessageLocation(casted_script, pos, pos + 1); |
| 627 } | 630 } |
| 628 } | 631 } |
| 629 } | 632 } |
| 630 | 633 |
| 631 | 634 |
| 632 bool Isolate::ShouldReportException(bool* can_be_caught_externally, | 635 bool Isolate::ShouldReportException(bool* can_be_caught_externally, |
| 633 bool catchable_by_javascript) { | 636 bool catchable_by_javascript) { |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 thread_local_top()->simulator_ = Simulator::current(this); | 974 thread_local_top()->simulator_ = Simulator::current(this); |
| 972 #endif | 975 #endif |
| 973 #endif | 976 #endif |
| 974 if (RuntimeProfiler::IsEnabled() && current_vm_state() == JS) { | 977 if (RuntimeProfiler::IsEnabled() && current_vm_state() == JS) { |
| 975 RuntimeProfiler::IsolateEnteredJS(this); | 978 RuntimeProfiler::IsolateEnteredJS(this); |
| 976 } | 979 } |
| 977 return from + sizeof(ThreadLocalTop); | 980 return from + sizeof(ThreadLocalTop); |
| 978 } | 981 } |
| 979 | 982 |
| 980 } } // namespace v8::internal | 983 } } // namespace v8::internal |
| OLD | NEW |