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

Side by Side Diff: src/isolate.cc

Issue 1618343002: [interpreter, debugger] abstraction for source position calculation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: remove bogus assertion Created 4 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
« no previous file with comments | « src/heap/heap.cc ('k') | src/objects.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/isolate.h" 5 #include "src/isolate.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <fstream> // NOLINT(readability/streams) 9 #include <fstream> // NOLINT(readability/streams)
10 #include <sstream> 10 #include <sstream>
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 int new_capacity = JSObject::NewElementsCapacity(elements->length()); 383 int new_capacity = JSObject::NewElementsCapacity(elements->length());
384 Handle<FixedArray> new_elements = 384 Handle<FixedArray> new_elements =
385 factory()->NewFixedArrayWithHoles(new_capacity); 385 factory()->NewFixedArrayWithHoles(new_capacity);
386 for (int i = 0; i < cursor; i++) { 386 for (int i = 0; i < cursor; i++) {
387 new_elements->set(i, elements->get(i)); 387 new_elements->set(i, elements->get(i));
388 } 388 }
389 elements = new_elements; 389 elements = new_elements;
390 } 390 }
391 DCHECK(cursor + 4 <= elements->length()); 391 DCHECK(cursor + 4 <= elements->length());
392 392
393 Handle<Code> code = frames[i].code(); 393 Handle<AbstractCode> abstract_code = frames[i].abstract_code();
394 Handle<Smi> offset(Smi::FromInt(frames[i].offset()), this); 394
395 Handle<Smi> offset(Smi::FromInt(frames[i].code_offset()), this);
395 // The stack trace API should not expose receivers and function 396 // The stack trace API should not expose receivers and function
396 // objects on frames deeper than the top-most one with a strict 397 // objects on frames deeper than the top-most one with a strict
397 // mode function. The number of sloppy frames is stored as 398 // mode function. The number of sloppy frames is stored as
398 // first element in the result array. 399 // first element in the result array.
399 if (!encountered_strict_function) { 400 if (!encountered_strict_function) {
400 if (is_strict(fun->shared()->language_mode())) { 401 if (is_strict(fun->shared()->language_mode())) {
401 encountered_strict_function = true; 402 encountered_strict_function = true;
402 } else { 403 } else {
403 sloppy_frames++; 404 sloppy_frames++;
404 } 405 }
405 } 406 }
406 elements->set(cursor++, *recv); 407 elements->set(cursor++, *recv);
407 elements->set(cursor++, *fun); 408 elements->set(cursor++, *fun);
408 elements->set(cursor++, *code); 409 elements->set(cursor++, *abstract_code);
409 elements->set(cursor++, *offset); 410 elements->set(cursor++, *offset);
410 frames_seen++; 411 frames_seen++;
411 } 412 }
412 } 413 }
413 elements->set(0, Smi::FromInt(sloppy_frames)); 414 elements->set(0, Smi::FromInt(sloppy_frames));
414 elements->Shrink(cursor); 415 elements->Shrink(cursor);
415 Handle<JSArray> result = factory()->NewJSArrayWithElements(elements); 416 Handle<JSArray> result = factory()->NewJSArrayWithElements(elements);
416 result->set_length(Smi::FromInt(cursor)); 417 result->set_length(Smi::FromInt(cursor));
417 // TODO(yangguo): Queue this structured stack trace for preprocessing on GC. 418 // TODO(yangguo): Queue this structured stack trace for preprocessing on GC.
418 return result; 419 return result;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 Handle<String> constructor_key_; 588 Handle<String> constructor_key_;
588 }; 589 };
589 590
590 591
591 int PositionFromStackTrace(Handle<FixedArray> elements, int index) { 592 int PositionFromStackTrace(Handle<FixedArray> elements, int index) {
592 DisallowHeapAllocation no_gc; 593 DisallowHeapAllocation no_gc;
593 Object* maybe_code = elements->get(index + 2); 594 Object* maybe_code = elements->get(index + 2);
594 if (maybe_code->IsSmi()) { 595 if (maybe_code->IsSmi()) {
595 return Smi::cast(maybe_code)->value(); 596 return Smi::cast(maybe_code)->value();
596 } else { 597 } else {
597 Code* code = Code::cast(maybe_code); 598 AbstractCode* abstract_code = AbstractCode::cast(maybe_code);
598 Address pc = code->address() + Smi::cast(elements->get(index + 3))->value(); 599 int code_offset = Smi::cast(elements->get(index + 3))->value();
599 return code->SourcePosition(pc); 600 return abstract_code->SourcePosition(code_offset);
600 } 601 }
601 } 602 }
602 603
603 604
604 Handle<JSArray> Isolate::GetDetailedFromSimpleStackTrace( 605 Handle<JSArray> Isolate::GetDetailedFromSimpleStackTrace(
605 Handle<JSObject> error_object) { 606 Handle<JSObject> error_object) {
606 Handle<Name> key = factory()->stack_trace_symbol(); 607 Handle<Name> key = factory()->stack_trace_symbol();
607 Handle<Object> property = JSReceiver::GetDataProperty(error_object, key); 608 Handle<Object> property = JSReceiver::GetDataProperty(error_object, key);
608 if (!property->IsJSArray()) return Handle<JSArray>(); 609 if (!property->IsJSArray()) return Handle<JSArray>();
609 Handle<JSArray> simple_stack_trace = Handle<JSArray>::cast(property); 610 Handle<JSArray> simple_stack_trace = Handle<JSArray>::cast(property);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 JavaScriptFrame* frame = it.frame(); 655 JavaScriptFrame* frame = it.frame();
655 // Set initial size to the maximum inlining level + 1 for the outermost 656 // Set initial size to the maximum inlining level + 1 for the outermost
656 // function. 657 // function.
657 List<FrameSummary> frames(FLAG_max_inlining_levels + 1); 658 List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
658 frame->Summarize(&frames); 659 frame->Summarize(&frames);
659 for (int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) { 660 for (int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) {
660 Handle<JSFunction> fun = frames[i].function(); 661 Handle<JSFunction> fun = frames[i].function();
661 // Filter frames from other security contexts. 662 // Filter frames from other security contexts.
662 if (!(options & StackTrace::kExposeFramesAcrossSecurityOrigins) && 663 if (!(options & StackTrace::kExposeFramesAcrossSecurityOrigins) &&
663 !this->context()->HasSameSecurityTokenAs(fun->context())) continue; 664 !this->context()->HasSameSecurityTokenAs(fun->context())) continue;
664 int position = frames[i].code()->SourcePosition(frames[i].pc()); 665 int position =
666 frames[i].abstract_code()->SourcePosition(frames[i].code_offset());
665 Handle<JSObject> stack_frame = 667 Handle<JSObject> stack_frame =
666 helper.NewStackFrameObject(fun, position, frames[i].is_constructor()); 668 helper.NewStackFrameObject(fun, position, frames[i].is_constructor());
667 669
668 FixedArray::cast(stack_trace->elements())->set(frames_seen, *stack_frame); 670 FixedArray::cast(stack_trace->elements())->set(frames_seen, *stack_frame);
669 frames_seen++; 671 frames_seen++;
670 } 672 }
671 it.Advance(); 673 it.Advance();
672 } 674 }
673 675
674 stack_trace->set_length(Smi::FromInt(frames_seen)); 676 stack_trace->set_length(Smi::FromInt(frames_seen));
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 return ReThrow(thrown); 1278 return ReThrow(thrown);
1277 } 1279 }
1278 1280
1279 1281
1280 void Isolate::PrintCurrentStackTrace(FILE* out) { 1282 void Isolate::PrintCurrentStackTrace(FILE* out) {
1281 StackTraceFrameIterator it(this); 1283 StackTraceFrameIterator it(this);
1282 while (!it.done()) { 1284 while (!it.done()) {
1283 HandleScope scope(this); 1285 HandleScope scope(this);
1284 // Find code position if recorded in relocation info. 1286 // Find code position if recorded in relocation info.
1285 JavaScriptFrame* frame = it.frame(); 1287 JavaScriptFrame* frame = it.frame();
1286 int pos = frame->LookupCode()->SourcePosition(frame->pc()); 1288 Code* code = frame->LookupCode();
1289 int offset = static_cast<int>(frame->pc() - code->instruction_start());
1290 int pos = frame->LookupCode()->SourcePosition(offset);
1287 Handle<Object> pos_obj(Smi::FromInt(pos), this); 1291 Handle<Object> pos_obj(Smi::FromInt(pos), this);
1288 // Fetch function and receiver. 1292 // Fetch function and receiver.
1289 Handle<JSFunction> fun(frame->function()); 1293 Handle<JSFunction> fun(frame->function());
1290 Handle<Object> recv(frame->receiver(), this); 1294 Handle<Object> recv(frame->receiver(), this);
1291 // Advance to the next JavaScript frame and determine if the 1295 // Advance to the next JavaScript frame and determine if the
1292 // current frame is the top-level frame. 1296 // current frame is the top-level frame.
1293 it.Advance(); 1297 it.Advance();
1294 Handle<Object> is_top_level = factory()->ToBoolean(it.done()); 1298 Handle<Object> is_top_level = factory()->ToBoolean(it.done());
1295 // Generate and print stack trace line. 1299 // Generate and print stack trace line.
1296 Handle<String> line = 1300 Handle<String> line =
(...skipping 14 matching lines...) Expand all
1311 Object* script = fun->shared()->script(); 1315 Object* script = fun->shared()->script();
1312 if (script->IsScript() && 1316 if (script->IsScript() &&
1313 !(Script::cast(script)->source()->IsUndefined())) { 1317 !(Script::cast(script)->source()->IsUndefined())) {
1314 Handle<Script> casted_script(Script::cast(script)); 1318 Handle<Script> casted_script(Script::cast(script));
1315 // Compute the location from the function and the relocation info of the 1319 // Compute the location from the function and the relocation info of the
1316 // baseline code. For optimized code this will use the deoptimization 1320 // baseline code. For optimized code this will use the deoptimization
1317 // information to get canonical location information. 1321 // information to get canonical location information.
1318 List<FrameSummary> frames(FLAG_max_inlining_levels + 1); 1322 List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
1319 it.frame()->Summarize(&frames); 1323 it.frame()->Summarize(&frames);
1320 FrameSummary& summary = frames.last(); 1324 FrameSummary& summary = frames.last();
1321 int pos = summary.code()->SourcePosition(summary.pc()); 1325 int pos = summary.abstract_code()->SourcePosition(summary.code_offset());
1322 *target = MessageLocation(casted_script, pos, pos + 1, handle(fun)); 1326 *target = MessageLocation(casted_script, pos, pos + 1, handle(fun));
1323 return true; 1327 return true;
1324 } 1328 }
1325 } 1329 }
1326 return false; 1330 return false;
1327 } 1331 }
1328 1332
1329 1333
1330 bool Isolate::ComputeLocationFromException(MessageLocation* target, 1334 bool Isolate::ComputeLocationFromException(MessageLocation* target,
1331 Handle<Object> exception) { 1335 Handle<Object> exception) {
(...skipping 1523 matching lines...) Expand 10 before | Expand all | Expand 10 after
2855 // Then check whether this scope intercepts. 2859 // Then check whether this scope intercepts.
2856 if ((flag & intercept_mask_)) { 2860 if ((flag & intercept_mask_)) {
2857 intercepted_flags_ |= flag; 2861 intercepted_flags_ |= flag;
2858 return true; 2862 return true;
2859 } 2863 }
2860 return false; 2864 return false;
2861 } 2865 }
2862 2866
2863 } // namespace internal 2867 } // namespace internal
2864 } // namespace v8 2868 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/heap.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698