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

Side by Side Diff: test/cctest/test-log-stack-tracer.cc

Issue 6614010: [Isolates] Merge 6700:7030 from bleeding_edge to isolates. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: '' Created 9 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-log.cc ('k') | test/cctest/test-mark-compact.cc » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 15 matching lines...) Expand all
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 // Tests of profiler-related functions from log.h 28 // Tests of profiler-related functions from log.h
29 29
30 #ifdef ENABLE_LOGGING_AND_PROFILING 30 #ifdef ENABLE_LOGGING_AND_PROFILING
31 31
32 #include <stdlib.h> 32 #include <stdlib.h>
33 33
34 #include "v8.h" 34 #include "v8.h"
35 35
36 #include "api.h"
36 #include "codegen.h" 37 #include "codegen.h"
37 #include "log.h" 38 #include "log.h"
38 #include "isolate.h" 39 #include "isolate.h"
39 #include "cctest.h" 40 #include "cctest.h"
40 #include "disassembler.h" 41 #include "disassembler.h"
41 #include "register-allocator-inl.h" 42 #include "register-allocator-inl.h"
42 #include "vm-state-inl.h" 43 #include "vm-state-inl.h"
43 44
44 using v8::Function; 45 using v8::Function;
45 using v8::Local; 46 using v8::Local;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 v8::HandleScope scope; 195 v8::HandleScope scope;
195 const char* extensions[] = { "v8/trace" }; 196 const char* extensions[] = { "v8/trace" };
196 v8::ExtensionConfiguration config(1, extensions); 197 v8::ExtensionConfiguration config(1, extensions);
197 env = v8::Context::New(&config); 198 env = v8::Context::New(&config);
198 } 199 }
199 v8::HandleScope scope; 200 v8::HandleScope scope;
200 env->Enter(); 201 env->Enter();
201 } 202 }
202 203
203 204
204 static void CheckJSFunctionAtAddress(const char* func_name, Address addr) { 205 static bool IsAddressWithinFuncCode(JSFunction* function, Address addr) {
205 CHECK(HEAP->Contains(addr)); 206 i::Code* code = function->code();
206 i::Object* obj = i::HeapObject::FromAddress(addr); 207 return code->contains(addr);
207 CHECK(obj->IsJSFunction()); 208 }
208 CHECK(JSFunction::cast(obj)->shared()->name()->IsString()); 209
209 i::SmartPointer<char> found_name = 210 static bool IsAddressWithinFuncCode(const char* func_name, Address addr) {
210 i::String::cast( 211 v8::Local<v8::Value> func = env->Global()->Get(v8_str(func_name));
211 JSFunction::cast( 212 CHECK(func->IsFunction());
212 obj)->shared()->name())->ToCString(); 213 JSFunction* js_func = JSFunction::cast(*v8::Utils::OpenHandle(*func));
213 CHECK_EQ(func_name, *found_name); 214 return IsAddressWithinFuncCode(js_func, addr);
214 } 215 }
215 216
216 217
217 // This C++ function is called as a constructor, to grab the frame pointer 218 // This C++ function is called as a constructor, to grab the frame pointer
218 // from the calling function. When this function runs, the stack contains 219 // from the calling function. When this function runs, the stack contains
219 // a C_Entry frame and a Construct frame above the calling function's frame. 220 // a C_Entry frame and a Construct frame above the calling function's frame.
220 static v8::Handle<Value> construct_call(const v8::Arguments& args) { 221 static v8::Handle<Value> construct_call(const v8::Arguments& args) {
221 i::StackFrameIterator frame_iterator; 222 i::StackFrameIterator frame_iterator;
222 CHECK(frame_iterator.frame()->is_exit()); 223 CHECK(frame_iterator.frame()->is_exit());
223 frame_iterator.Advance(); 224 frame_iterator.Advance();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 // StackTracer::Trace 304 // StackTracer::Trace
304 305
305 // The VM state tracking keeps track of external callbacks and puts 306 // The VM state tracking keeps track of external callbacks and puts
306 // them at the top of the sample stack. 307 // them at the top of the sample stack.
307 int base = 0; 308 int base = 0;
308 CHECK(sample.stack[0] == FUNCTION_ADDR(TraceExtension::Trace)); 309 CHECK(sample.stack[0] == FUNCTION_ADDR(TraceExtension::Trace));
309 base++; 310 base++;
310 311
311 // Stack tracing will start from the first JS function, i.e. "JSFuncDoTrace" 312 // Stack tracing will start from the first JS function, i.e. "JSFuncDoTrace"
312 CHECK_GT(sample.frames_count, base + 1); 313 CHECK_GT(sample.frames_count, base + 1);
313 CheckJSFunctionAtAddress("JSFuncDoTrace", sample.stack[base + 0]); 314 CHECK(IsAddressWithinFuncCode("JSFuncDoTrace", sample.stack[base + 0]));
314 CheckJSFunctionAtAddress("JSTrace", sample.stack[base + 1]); 315 CHECK(IsAddressWithinFuncCode("JSTrace", sample.stack[base + 1]));
315 } 316 }
316 317
317 318
318 // This test verifies that stack tracing works when called during 319 // This test verifies that stack tracing works when called during
319 // execution of JS code. However, as calling StackTracer requires 320 // execution of JS code. However, as calling StackTracer requires
320 // entering native code, we can only emulate pure JS by erasing 321 // entering native code, we can only emulate pure JS by erasing
321 // Isolate::c_entry_fp value. In this case, StackTracer uses passed frame 322 // Isolate::c_entry_fp value. In this case, StackTracer uses passed frame
322 // pointer value as a starting point for stack walking. 323 // pointer value as a starting point for stack walking.
323 TEST(PureJSStackTrace) { 324 TEST(PureJSStackTrace) {
324 // This test does not pass with inlining enabled since inlined functions 325 // This test does not pass with inlining enabled since inlined functions
(...skipping 20 matching lines...) Expand all
345 CHECK(!result.IsEmpty()); 346 CHECK(!result.IsEmpty());
346 // When stack tracer is invoked, the stack should look as follows: 347 // When stack tracer is invoked, the stack should look as follows:
347 // script [JS] 348 // script [JS]
348 // OuterJSTrace() [JS] 349 // OuterJSTrace() [JS]
349 // JSTrace() [JS] 350 // JSTrace() [JS]
350 // JSFuncDoTrace() [JS] 351 // JSFuncDoTrace() [JS]
351 // js_trace(EBP) [native (extension)] 352 // js_trace(EBP) [native (extension)]
352 // DoTraceHideCEntryFPAddress(EBP) [native] 353 // DoTraceHideCEntryFPAddress(EBP) [native]
353 // StackTracer::Trace 354 // StackTracer::Trace
354 // 355 //
355 // The last JS function called. It is only visible through
356 // sample.function, as its return address is above captured EBP value.
357 CheckJSFunctionAtAddress("JSFuncDoTrace", sample.function);
358 356
359 // The VM state tracking keeps track of external callbacks and puts 357 // The VM state tracking keeps track of external callbacks and puts
360 // them at the top of the sample stack. 358 // them at the top of the sample stack.
361 int base = 0; 359 int base = 0;
362 CHECK(sample.stack[0] == FUNCTION_ADDR(TraceExtension::JSTrace)); 360 CHECK(sample.stack[0] == FUNCTION_ADDR(TraceExtension::JSTrace));
363 base++; 361 base++;
364 362
365 // Stack sampling will start from the caller of JSFuncDoTrace, i.e. "JSTrace" 363 // Stack sampling will start from the caller of JSFuncDoTrace, i.e. "JSTrace"
366 CHECK_GT(sample.frames_count, base + 1); 364 CHECK_GT(sample.frames_count, base + 1);
367 CheckJSFunctionAtAddress("JSTrace", sample.stack[base + 0]); 365 CHECK(IsAddressWithinFuncCode("JSTrace", sample.stack[base + 0]));
368 CheckJSFunctionAtAddress("OuterJSTrace", sample.stack[base + 1]); 366 CHECK(IsAddressWithinFuncCode("OuterJSTrace", sample.stack[base + 1]));
369 } 367 }
370 368
371 369
372 static void CFuncDoTrace(byte dummy_parameter) { 370 static void CFuncDoTrace(byte dummy_parameter) {
373 Address fp; 371 Address fp;
374 #ifdef __GNUC__ 372 #ifdef __GNUC__
375 fp = reinterpret_cast<Address>(__builtin_frame_address(0)); 373 fp = reinterpret_cast<Address>(__builtin_frame_address(0));
376 #elif defined _MSC_VER 374 #elif defined _MSC_VER
377 // Approximate a frame pointer address. We compile without base pointers, 375 // Approximate a frame pointer address. We compile without base pointers,
378 // so we can't trust ebp/rbp. 376 // so we can't trust ebp/rbp.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 CHECK_EQ(0, GetJsEntrySp()); 409 CHECK_EQ(0, GetJsEntrySp());
412 CompileRun("a = 1; b = a + 1;"); 410 CompileRun("a = 1; b = a + 1;");
413 CHECK_EQ(0, GetJsEntrySp()); 411 CHECK_EQ(0, GetJsEntrySp());
414 CompileRun("js_entry_sp();"); 412 CompileRun("js_entry_sp();");
415 CHECK_EQ(0, GetJsEntrySp()); 413 CHECK_EQ(0, GetJsEntrySp());
416 CompileRun("js_entry_sp_level2();"); 414 CompileRun("js_entry_sp_level2();");
417 CHECK_EQ(0, GetJsEntrySp()); 415 CHECK_EQ(0, GetJsEntrySp());
418 } 416 }
419 417
420 #endif // ENABLE_LOGGING_AND_PROFILING 418 #endif // ENABLE_LOGGING_AND_PROFILING
OLDNEW
« no previous file with comments | « test/cctest/test-log.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698