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

Side by Side Diff: src/isolate.cc

Issue 1712003003: Add WasmFrame, backtraces reflect wasm's presence (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 // Functions defined in native scripts are not visible unless directly 331 // Functions defined in native scripts are not visible unless directly
332 // exposed, in which case the native flag is set. 332 // exposed, in which case the native flag is set.
333 // The --builtins-in-stack-traces command line flag allows including 333 // The --builtins-in-stack-traces command line flag allows including
334 // internal call sites in the stack trace for debugging purposes. 334 // internal call sites in the stack trace for debugging purposes.
335 if (!FLAG_builtins_in_stack_traces && fun->shared()->IsBuiltin()) { 335 if (!FLAG_builtins_in_stack_traces && fun->shared()->IsBuiltin()) {
336 return fun->shared()->native(); 336 return fun->shared()->native();
337 } 337 }
338 return true; 338 return true;
339 } 339 }
340 340
341 static Handle<FixedArray> maybeGrow(Isolate* isolate, Handle<FixedArray> e,
342 int cur_position, int new_size) {
343 if (new_size > e->length()) {
344 int new_capacity = JSObject::NewElementsCapacity(e->length());
345 Handle<FixedArray> new_e =
titzer 2016/02/19 10:50:30 I guess it's ok to spell out new_elements here, si
JF 2016/02/19 16:53:58 Done.
346 isolate->factory()->NewFixedArrayWithHoles(new_capacity);
347 for (int i = 0; i < cur_position; i++) {
348 new_e->set(i, e->get(i));
349 }
350 e = new_e;
351 }
352 DCHECK(new_size <= e->length());
353 return e;
354 }
341 355
342 Handle<Object> Isolate::CaptureSimpleStackTrace(Handle<JSObject> error_object, 356 Handle<Object> Isolate::CaptureSimpleStackTrace(Handle<JSObject> error_object,
343 Handle<Object> caller) { 357 Handle<Object> caller) {
344 // Get stack trace limit. 358 // Get stack trace limit.
345 Handle<JSObject> error = error_function(); 359 Handle<JSObject> error = error_function();
346 Handle<String> stackTraceLimit = 360 Handle<String> stackTraceLimit =
347 factory()->InternalizeUtf8String("stackTraceLimit"); 361 factory()->InternalizeUtf8String("stackTraceLimit");
348 DCHECK(!stackTraceLimit.is_null()); 362 DCHECK(!stackTraceLimit.is_null());
349 Handle<Object> stack_trace_limit = 363 Handle<Object> stack_trace_limit =
350 JSReceiver::GetDataProperty(error, stackTraceLimit); 364 JSReceiver::GetDataProperty(error, stackTraceLimit);
351 if (!stack_trace_limit->IsNumber()) return factory()->undefined_value(); 365 if (!stack_trace_limit->IsNumber()) return factory()->undefined_value();
352 int limit = FastD2IChecked(stack_trace_limit->Number()); 366 int limit = FastD2IChecked(stack_trace_limit->Number());
353 limit = Max(limit, 0); // Ensure that limit is not negative. 367 limit = Max(limit, 0); // Ensure that limit is not negative.
354 368
355 int initial_size = Min(limit, 10); 369 int initial_size = Min(limit, 10);
356 Handle<FixedArray> elements = 370 Handle<FixedArray> elements =
357 factory()->NewFixedArrayWithHoles(initial_size * 4 + 1); 371 factory()->NewFixedArrayWithHoles(initial_size * 4 + 1);
358 372
359 // If the caller parameter is a function we skip frames until we're 373 // If the caller parameter is a function we skip frames until we're
360 // under it before starting to collect. 374 // under it before starting to collect.
361 bool seen_caller = !caller->IsJSFunction(); 375 bool seen_caller = !caller->IsJSFunction();
362 // First element is reserved to store the number of sloppy frames. 376 // First element is reserved to store the number of sloppy frames.
363 int cursor = 1; 377 int cursor = 1;
364 int frames_seen = 0; 378 int frames_seen = 0;
365 int sloppy_frames = 0; 379 int sloppy_frames = 0;
366 bool encountered_strict_function = false; 380 bool encountered_strict_function = false;
367 for (JavaScriptFrameIterator iter(this); 381 for (VisibleFrameIterator iter(this); !iter.done() && frames_seen < limit;
368 !iter.done() && frames_seen < limit;
369 iter.Advance()) { 382 iter.Advance()) {
370 JavaScriptFrame* frame = iter.frame(); 383 VisibleFrame* frame = iter.frame();
371 // Set initial size to the maximum inlining level + 1 for the outermost 384
372 // function. 385 switch (frame->type()) {
373 List<FrameSummary> frames(FLAG_max_inlining_levels + 1); 386 case StackFrame::JAVA_SCRIPT:
374 frame->Summarize(&frames); 387 case StackFrame::OPTIMIZED:
375 for (int i = frames.length() - 1; i >= 0; i--) { 388 case StackFrame::INTERPRETED: {
376 Handle<JSFunction> fun = frames[i].function(); 389 // Set initial size to the maximum inlining level + 1 for the outermost
377 Handle<Object> recv = frames[i].receiver(); 390 // function.
378 // Filter out internal frames that we do not want to show. 391 List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
379 if (!IsVisibleInStackTrace(*fun, *caller, *recv, &seen_caller)) continue; 392 frame->Summarize(&frames);
380 // Filter out frames from other security contexts. 393 for (int i = frames.length() - 1; i >= 0; i--) {
381 if (!this->context()->HasSameSecurityTokenAs(fun->context())) continue; 394 Handle<JSFunction> fun = frames[i].function();
382 if (cursor + 4 > elements->length()) { 395 Handle<Object> recv = frames[i].receiver();
383 int new_capacity = JSObject::NewElementsCapacity(elements->length()); 396 // Filter out internal frames that we do not want to show.
384 Handle<FixedArray> new_elements = 397 if (!IsVisibleInStackTrace(*fun, *caller, *recv, &seen_caller))
385 factory()->NewFixedArrayWithHoles(new_capacity); 398 continue;
386 for (int i = 0; i < cursor; i++) { 399 // Filter out frames from other security contexts.
387 new_elements->set(i, elements->get(i)); 400 if (!this->context()->HasSameSecurityTokenAs(fun->context()))
401 continue;
402 elements = maybeGrow(this, elements, cursor, cursor + 4);
403
404 Handle<AbstractCode> abstract_code = frames[i].abstract_code();
405
406 Handle<Smi> offset(Smi::FromInt(frames[i].code_offset()), this);
407 // The stack trace API should not expose receivers and function
408 // objects on frames deeper than the top-most one with a strict mode
409 // function. The number of sloppy frames is stored as first element in
410 // the result array.
411 if (!encountered_strict_function) {
412 if (is_strict(fun->shared()->language_mode())) {
413 encountered_strict_function = true;
414 } else {
415 sloppy_frames++;
416 }
417 }
418 elements->set(cursor++, *recv);
419 elements->set(cursor++, *fun);
420 elements->set(cursor++, *abstract_code);
421 elements->set(cursor++, *offset);
422 frames_seen++;
388 } 423 }
389 elements = new_elements; 424 } break;
390 }
391 DCHECK(cursor + 4 <= elements->length());
392 425
393 Handle<AbstractCode> abstract_code = frames[i].abstract_code(); 426 case StackFrame::WASM: {
427 elements = maybeGrow(this, elements, cursor, cursor + 4);
428 elements->set(cursor++, *caller);
titzer 2016/02/19 10:50:30 I'm not sure it's OK to put in the caller as the r
JF 2016/02/19 16:53:58 I wasn't sure about that :-) I left as-is for now,
titzer 2016/02/19 17:00:41 Please make it undefined; it will explode more rea
JF 2016/02/19 20:57:42 Ah I had misunderstood what you meant by "undefine
429 elements->set(cursor++,
430 *factory()->NewFunction(
431 factory()->NewStringFromAsciiChecked("<WASM>")));
432 elements->set(cursor++, Internals::IntToSmi(0));
433 elements->set(cursor++, Internals::IntToSmi(0));
434 frames_seen++;
435 } break;
394 436
395 Handle<Smi> offset(Smi::FromInt(frames[i].code_offset()), this); 437 default:
396 // The stack trace API should not expose receivers and function 438 DCHECK(false && "unknown frame type");
titzer 2016/02/19 10:50:30 We usually just use UNREACHABLE();
JF 2016/02/19 16:53:58 Done.
397 // objects on frames deeper than the top-most one with a strict
398 // mode function. The number of sloppy frames is stored as
399 // first element in the result array.
400 if (!encountered_strict_function) {
401 if (is_strict(fun->shared()->language_mode())) {
402 encountered_strict_function = true;
403 } else {
404 sloppy_frames++;
405 }
406 }
407 elements->set(cursor++, *recv);
408 elements->set(cursor++, *fun);
409 elements->set(cursor++, *abstract_code);
410 elements->set(cursor++, *offset);
411 frames_seen++;
412 } 439 }
413 } 440 }
414 elements->set(0, Smi::FromInt(sloppy_frames)); 441 elements->set(0, Smi::FromInt(sloppy_frames));
415 elements->Shrink(cursor); 442 elements->Shrink(cursor);
416 Handle<JSArray> result = factory()->NewJSArrayWithElements(elements); 443 Handle<JSArray> result = factory()->NewJSArrayWithElements(elements);
417 result->set_length(Smi::FromInt(cursor)); 444 result->set_length(Smi::FromInt(cursor));
418 // TODO(yangguo): Queue this structured stack trace for preprocessing on GC. 445 // TODO(yangguo): Queue this structured stack trace for preprocessing on GC.
419 return result; 446 return result;
420 } 447 }
421 448
(...skipping 2435 matching lines...) Expand 10 before | Expand all | Expand 10 after
2857 // Then check whether this scope intercepts. 2884 // Then check whether this scope intercepts.
2858 if ((flag & intercept_mask_)) { 2885 if ((flag & intercept_mask_)) {
2859 intercepted_flags_ |= flag; 2886 intercepted_flags_ |= flag;
2860 return true; 2887 return true;
2861 } 2888 }
2862 return false; 2889 return false;
2863 } 2890 }
2864 2891
2865 } // namespace internal 2892 } // namespace internal
2866 } // namespace v8 2893 } // namespace v8
OLDNEW
« no previous file with comments | « src/frames-inl.h ('k') | src/objects.h » ('j') | test/mjsunit/wasm/stack.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698