 Chromium Code Reviews
 Chromium Code Reviews Issue 1712003003:
  Add WasmFrame, backtraces reflect wasm's presence  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master
    
  
    Issue 1712003003:
  Add WasmFrame, backtraces reflect wasm's presence  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master| OLD | NEW | 
|---|---|
| 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 Loading... | |
| 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, | |
| 
Michael Starzinger
2016/02/19 21:15:27
nit: Function name is not following V8 style.
 
JF
2016/02/19 21:43:51
Done.
 | |
| 342 Handle<FixedArray> elements, | |
| 343 int cur_position, int new_size) { | |
| 344 if (new_size > elements->length()) { | |
| 345 int new_capacity = JSObject::NewElementsCapacity(elements->length()); | |
| 346 Handle<FixedArray> new_elements = | |
| 347 isolate->factory()->NewFixedArrayWithHoles(new_capacity); | |
| 348 for (int i = 0; i < cur_position; i++) { | |
| 349 new_elements->set(i, elements->get(i)); | |
| 350 } | |
| 351 elements = new_elements; | |
| 352 } | |
| 353 DCHECK(new_size <= elements->length()); | |
| 354 return elements; | |
| 355 } | |
| 341 | 356 | 
| 342 Handle<Object> Isolate::CaptureSimpleStackTrace(Handle<JSObject> error_object, | 357 Handle<Object> Isolate::CaptureSimpleStackTrace(Handle<JSObject> error_object, | 
| 343 Handle<Object> caller) { | 358 Handle<Object> caller) { | 
| 344 // Get stack trace limit. | 359 // Get stack trace limit. | 
| 345 Handle<JSObject> error = error_function(); | 360 Handle<JSObject> error = error_function(); | 
| 346 Handle<String> stackTraceLimit = | 361 Handle<String> stackTraceLimit = | 
| 347 factory()->InternalizeUtf8String("stackTraceLimit"); | 362 factory()->InternalizeUtf8String("stackTraceLimit"); | 
| 348 DCHECK(!stackTraceLimit.is_null()); | 363 DCHECK(!stackTraceLimit.is_null()); | 
| 349 Handle<Object> stack_trace_limit = | 364 Handle<Object> stack_trace_limit = | 
| 350 JSReceiver::GetDataProperty(error, stackTraceLimit); | 365 JSReceiver::GetDataProperty(error, stackTraceLimit); | 
| 351 if (!stack_trace_limit->IsNumber()) return factory()->undefined_value(); | 366 if (!stack_trace_limit->IsNumber()) return factory()->undefined_value(); | 
| 352 int limit = FastD2IChecked(stack_trace_limit->Number()); | 367 int limit = FastD2IChecked(stack_trace_limit->Number()); | 
| 353 limit = Max(limit, 0); // Ensure that limit is not negative. | 368 limit = Max(limit, 0); // Ensure that limit is not negative. | 
| 354 | 369 | 
| 355 int initial_size = Min(limit, 10); | 370 int initial_size = Min(limit, 10); | 
| 356 Handle<FixedArray> elements = | 371 Handle<FixedArray> elements = | 
| 357 factory()->NewFixedArrayWithHoles(initial_size * 4 + 1); | 372 factory()->NewFixedArrayWithHoles(initial_size * 4 + 1); | 
| 358 | 373 | 
| 359 // If the caller parameter is a function we skip frames until we're | 374 // If the caller parameter is a function we skip frames until we're | 
| 360 // under it before starting to collect. | 375 // under it before starting to collect. | 
| 361 bool seen_caller = !caller->IsJSFunction(); | 376 bool seen_caller = !caller->IsJSFunction(); | 
| 362 // First element is reserved to store the number of sloppy frames. | 377 // First element is reserved to store the number of sloppy frames. | 
| 363 int cursor = 1; | 378 int cursor = 1; | 
| 364 int frames_seen = 0; | 379 int frames_seen = 0; | 
| 365 int sloppy_frames = 0; | 380 int sloppy_frames = 0; | 
| 366 bool encountered_strict_function = false; | 381 bool encountered_strict_function = false; | 
| 367 for (JavaScriptFrameIterator iter(this); | 382 for (VisibleFrameIterator iter(this); !iter.done() && frames_seen < limit; | 
| 368 !iter.done() && frames_seen < limit; | |
| 369 iter.Advance()) { | 383 iter.Advance()) { | 
| 370 JavaScriptFrame* frame = iter.frame(); | 384 VisibleFrame* frame = iter.frame(); | 
| 371 // Set initial size to the maximum inlining level + 1 for the outermost | 385 | 
| 372 // function. | 386 switch (frame->type()) { | 
| 373 List<FrameSummary> frames(FLAG_max_inlining_levels + 1); | 387 case StackFrame::JAVA_SCRIPT: | 
| 374 frame->Summarize(&frames); | 388 case StackFrame::OPTIMIZED: | 
| 375 for (int i = frames.length() - 1; i >= 0; i--) { | 389 case StackFrame::INTERPRETED: { | 
| 376 Handle<JSFunction> fun = frames[i].function(); | 390 // Set initial size to the maximum inlining level + 1 for the outermost | 
| 377 Handle<Object> recv = frames[i].receiver(); | 391 // function. | 
| 378 // Filter out internal frames that we do not want to show. | 392 List<FrameSummary> frames(FLAG_max_inlining_levels + 1); | 
| 379 if (!IsVisibleInStackTrace(*fun, *caller, *recv, &seen_caller)) continue; | 393 frame->Summarize(&frames); | 
| 380 // Filter out frames from other security contexts. | 394 for (int i = frames.length() - 1; i >= 0; i--) { | 
| 381 if (!this->context()->HasSameSecurityTokenAs(fun->context())) continue; | 395 Handle<JSFunction> fun = frames[i].function(); | 
| 382 if (cursor + 4 > elements->length()) { | 396 Handle<Object> recv = frames[i].receiver(); | 
| 383 int new_capacity = JSObject::NewElementsCapacity(elements->length()); | 397 // Filter out internal frames that we do not want to show. | 
| 384 Handle<FixedArray> new_elements = | 398 if (!IsVisibleInStackTrace(*fun, *caller, *recv, &seen_caller)) | 
| 385 factory()->NewFixedArrayWithHoles(new_capacity); | 399 continue; | 
| 
Michael Starzinger
2016/02/19 21:15:27
nit: Please put curly braces around body if condit
 
JF
2016/02/19 21:43:51
Done. Auto-format doesn't auto-curl :-(
 | |
| 386 for (int i = 0; i < cursor; i++) { | 400 // Filter out frames from other security contexts. | 
| 387 new_elements->set(i, elements->get(i)); | 401 if (!this->context()->HasSameSecurityTokenAs(fun->context())) | 
| 402 continue; | |
| 
Michael Starzinger
2016/02/19 21:15:27
nit: Please put curly braces around body if condit
 
JF
2016/02/19 21:43:51
Done.
 | |
| 403 elements = maybeGrow(this, elements, cursor, cursor + 4); | |
| 404 | |
| 405 Handle<AbstractCode> abstract_code = frames[i].abstract_code(); | |
| 406 | |
| 407 Handle<Smi> offset(Smi::FromInt(frames[i].code_offset()), this); | |
| 408 // The stack trace API should not expose receivers and function | |
| 409 // objects on frames deeper than the top-most one with a strict mode | |
| 410 // function. The number of sloppy frames is stored as first element in | |
| 411 // the result array. | |
| 412 if (!encountered_strict_function) { | |
| 413 if (is_strict(fun->shared()->language_mode())) { | |
| 414 encountered_strict_function = true; | |
| 415 } else { | |
| 416 sloppy_frames++; | |
| 417 } | |
| 418 } | |
| 419 elements->set(cursor++, *factory()->undefined_value()); | |
| 
Michael Starzinger
2016/02/19 21:15:27
I don't think it is OK to pass undefined as the re
 
JF
2016/02/19 21:43:51
What would be OK instead?
 
Michael Starzinger
2016/02/19 21:55:23
The "recv" value, as it was before. I am on referr
 
titzer
2016/02/21 09:01:54
In a previous comment I had advised passing "undef
 
JF
2016/02/22 18:29:40
Oh right, sorry about that! Too much look-alike co
 | |
| 420 elements->set(cursor++, *fun); | |
| 421 elements->set(cursor++, *abstract_code); | |
| 422 elements->set(cursor++, *offset); | |
| 423 frames_seen++; | |
| 388 } | 424 } | 
| 389 elements = new_elements; | 425 } break; | 
| 390 } | |
| 391 DCHECK(cursor + 4 <= elements->length()); | |
| 392 | 426 | 
| 393 Handle<AbstractCode> abstract_code = frames[i].abstract_code(); | 427 case StackFrame::WASM: { | 
| 428 elements = maybeGrow(this, elements, cursor, cursor + 4); | |
| 429 elements->set(cursor++, *caller); // TODO(jfb) Pass module object. | |
| 430 elements->set(cursor++, | |
| 431 *factory()->NewFunction( | |
| 432 factory()->NewStringFromAsciiChecked("<WASM>"))); | |
| 433 elements->set(cursor++, Internals::IntToSmi(0)); | |
| 434 elements->set(cursor++, Internals::IntToSmi(0)); | |
| 435 frames_seen++; | |
| 436 } break; | |
| 394 | 437 | 
| 395 Handle<Smi> offset(Smi::FromInt(frames[i].code_offset()), this); | 438 default: | 
| 396 // The stack trace API should not expose receivers and function | 439 UNREACHABLE(); | 
| 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 } | 440 } | 
| 413 } | 441 } | 
| 414 elements->set(0, Smi::FromInt(sloppy_frames)); | 442 elements->set(0, Smi::FromInt(sloppy_frames)); | 
| 415 elements->Shrink(cursor); | 443 elements->Shrink(cursor); | 
| 416 Handle<JSArray> result = factory()->NewJSArrayWithElements(elements); | 444 Handle<JSArray> result = factory()->NewJSArrayWithElements(elements); | 
| 417 result->set_length(Smi::FromInt(cursor)); | 445 result->set_length(Smi::FromInt(cursor)); | 
| 418 // TODO(yangguo): Queue this structured stack trace for preprocessing on GC. | 446 // TODO(yangguo): Queue this structured stack trace for preprocessing on GC. | 
| 419 return result; | 447 return result; | 
| 420 } | 448 } | 
| 421 | 449 | 
| (...skipping 2435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2857 // Then check whether this scope intercepts. | 2885 // Then check whether this scope intercepts. | 
| 2858 if ((flag & intercept_mask_)) { | 2886 if ((flag & intercept_mask_)) { | 
| 2859 intercepted_flags_ |= flag; | 2887 intercepted_flags_ |= flag; | 
| 2860 return true; | 2888 return true; | 
| 2861 } | 2889 } | 
| 2862 return false; | 2890 return false; | 
| 2863 } | 2891 } | 
| 2864 | 2892 | 
| 2865 } // namespace internal | 2893 } // namespace internal | 
| 2866 } // namespace v8 | 2894 } // namespace v8 | 
| OLD | NEW |