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

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

Issue 13483017: Unify the way cctest initalizes the VM for each test case. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed presubmit errors. Created 7 years, 8 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-heap.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 using v8::internal::byte; 49 using v8::internal::byte;
50 using v8::internal::Address; 50 using v8::internal::Address;
51 using v8::internal::Handle; 51 using v8::internal::Handle;
52 using v8::internal::Isolate; 52 using v8::internal::Isolate;
53 using v8::internal::JSFunction; 53 using v8::internal::JSFunction;
54 using v8::internal::StackTracer; 54 using v8::internal::StackTracer;
55 using v8::internal::TickSample; 55 using v8::internal::TickSample;
56 56
57 57
58 static v8::Persistent<v8::Context> env;
59
60
61 static struct { 58 static struct {
62 TickSample* sample; 59 TickSample* sample;
63 } trace_env = { NULL }; 60 } trace_env = { NULL };
64 61
65 62
66 static void InitTraceEnv(TickSample* sample) { 63 static void InitTraceEnv(TickSample* sample) {
67 trace_env.sample = sample; 64 trace_env.sample = sample;
68 } 65 }
69 66
70 67
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 CompileRun("js_entry_sp();"); 175 CompileRun("js_entry_sp();");
179 CHECK_EQ(js_entry_sp, GetJsEntrySp()); 176 CHECK_EQ(js_entry_sp, GetJsEntrySp());
180 return v8::Undefined(); 177 return v8::Undefined();
181 } 178 }
182 179
183 180
184 static TraceExtension kTraceExtension; 181 static TraceExtension kTraceExtension;
185 v8::DeclareExtension kTraceExtensionDeclaration(&kTraceExtension); 182 v8::DeclareExtension kTraceExtensionDeclaration(&kTraceExtension);
186 183
187 184
188 static void InitializeVM() {
189 if (env.IsEmpty()) {
190 const char* extensions[] = { "v8/trace" };
191 v8::ExtensionConfiguration config(1, extensions);
192 env = v8::Context::New(&config);
193 }
194 env->Enter();
195 }
196
197
198 static bool IsAddressWithinFuncCode(JSFunction* function, Address addr) { 185 static bool IsAddressWithinFuncCode(JSFunction* function, Address addr) {
199 i::Code* code = function->code(); 186 i::Code* code = function->code();
200 return code->contains(addr); 187 return code->contains(addr);
201 } 188 }
202 189
203 static bool IsAddressWithinFuncCode(const char* func_name, Address addr) { 190 static bool IsAddressWithinFuncCode(const char* func_name, Address addr) {
204 v8::Local<v8::Value> func = env->Global()->Get(v8_str(func_name)); 191 v8::Local<v8::Value> func = CcTest::env()->Global()->Get(v8_str(func_name));
205 CHECK(func->IsFunction()); 192 CHECK(func->IsFunction());
206 JSFunction* js_func = JSFunction::cast(*v8::Utils::OpenHandle(*func)); 193 JSFunction* js_func = JSFunction::cast(*v8::Utils::OpenHandle(*func));
207 return IsAddressWithinFuncCode(js_func, addr); 194 return IsAddressWithinFuncCode(js_func, addr);
208 } 195 }
209 196
210 197
211 // This C++ function is called as a constructor, to grab the frame pointer 198 // This C++ function is called as a constructor, to grab the frame pointer
212 // from the calling function. When this function runs, the stack contains 199 // from the calling function. When this function runs, the stack contains
213 // a C_Entry frame and a Construct frame above the calling function's frame. 200 // a C_Entry frame and a Construct frame above the calling function's frame.
214 static v8::Handle<Value> construct_call(const v8::Arguments& args) { 201 static v8::Handle<Value> construct_call(const v8::Arguments& args) {
(...skipping 21 matching lines...) Expand all
236 return args.This(); 223 return args.This();
237 } 224 }
238 225
239 226
240 // Use the API to create a JSFunction object that calls the above C++ function. 227 // Use the API to create a JSFunction object that calls the above C++ function.
241 void CreateFramePointerGrabberConstructor(const char* constructor_name) { 228 void CreateFramePointerGrabberConstructor(const char* constructor_name) {
242 Local<v8::FunctionTemplate> constructor_template = 229 Local<v8::FunctionTemplate> constructor_template =
243 v8::FunctionTemplate::New(construct_call); 230 v8::FunctionTemplate::New(construct_call);
244 constructor_template->SetClassName(v8_str("FPGrabber")); 231 constructor_template->SetClassName(v8_str("FPGrabber"));
245 Local<Function> fun = constructor_template->GetFunction(); 232 Local<Function> fun = constructor_template->GetFunction();
246 env->Global()->Set(v8_str(constructor_name), fun); 233 CcTest::env()->Global()->Set(v8_str(constructor_name), fun);
247 } 234 }
248 235
249 236
250 // Creates a global function named 'func_name' that calls the tracing 237 // Creates a global function named 'func_name' that calls the tracing
251 // function 'trace_func_name' with an actual EBP register value, 238 // function 'trace_func_name' with an actual EBP register value,
252 // encoded as one or two Smis. 239 // encoded as one or two Smis.
253 static void CreateTraceCallerFunction(const char* func_name, 240 static void CreateTraceCallerFunction(const char* func_name,
254 const char* trace_func_name) { 241 const char* trace_func_name) {
255 i::EmbeddedVector<char, 256> trace_call_buf; 242 i::EmbeddedVector<char, 256> trace_call_buf;
256 i::OS::SNPrintF(trace_call_buf, 243 i::OS::SNPrintF(trace_call_buf,
(...skipping 16 matching lines...) Expand all
273 // execution of a native function called from JS code. In this case, 260 // execution of a native function called from JS code. In this case,
274 // StackTracer uses Isolate::c_entry_fp as a starting point for stack 261 // StackTracer uses Isolate::c_entry_fp as a starting point for stack
275 // walking. 262 // walking.
276 TEST(CFromJSStackTrace) { 263 TEST(CFromJSStackTrace) {
277 // BUG(1303) Inlining of JSFuncDoTrace() in JSTrace below breaks this test. 264 // BUG(1303) Inlining of JSFuncDoTrace() in JSTrace below breaks this test.
278 i::FLAG_use_inlining = false; 265 i::FLAG_use_inlining = false;
279 266
280 TickSample sample; 267 TickSample sample;
281 InitTraceEnv(&sample); 268 InitTraceEnv(&sample);
282 269
283 InitializeVM(); 270 CcTest::InitializeVM(TRACE_EXTENSION);
284 v8::HandleScope scope(env->GetIsolate()); 271 v8::HandleScope scope(CcTest::isolate());
285 // Create global function JSFuncDoTrace which calls 272 // Create global function JSFuncDoTrace which calls
286 // extension function trace() with the current frame pointer value. 273 // extension function trace() with the current frame pointer value.
287 CreateTraceCallerFunction("JSFuncDoTrace", "trace"); 274 CreateTraceCallerFunction("JSFuncDoTrace", "trace");
288 Local<Value> result = CompileRun( 275 Local<Value> result = CompileRun(
289 "function JSTrace() {" 276 "function JSTrace() {"
290 " JSFuncDoTrace();" 277 " JSFuncDoTrace();"
291 "};\n" 278 "};\n"
292 "JSTrace();\n" 279 "JSTrace();\n"
293 "true;"); 280 "true;");
294 CHECK(!result.IsEmpty()); 281 CHECK(!result.IsEmpty());
(...skipping 23 matching lines...) Expand all
318 // Isolate::c_entry_fp value. In this case, StackTracer uses passed frame 305 // Isolate::c_entry_fp value. In this case, StackTracer uses passed frame
319 // pointer value as a starting point for stack walking. 306 // pointer value as a starting point for stack walking.
320 TEST(PureJSStackTrace) { 307 TEST(PureJSStackTrace) {
321 // This test does not pass with inlining enabled since inlined functions 308 // This test does not pass with inlining enabled since inlined functions
322 // don't appear in the stack trace. 309 // don't appear in the stack trace.
323 i::FLAG_use_inlining = false; 310 i::FLAG_use_inlining = false;
324 311
325 TickSample sample; 312 TickSample sample;
326 InitTraceEnv(&sample); 313 InitTraceEnv(&sample);
327 314
328 InitializeVM(); 315 CcTest::InitializeVM(TRACE_EXTENSION);
329 v8::HandleScope scope(env->GetIsolate()); 316 v8::HandleScope scope(CcTest::isolate());
330 // Create global function JSFuncDoTrace which calls 317 // Create global function JSFuncDoTrace which calls
331 // extension function js_trace() with the current frame pointer value. 318 // extension function js_trace() with the current frame pointer value.
332 CreateTraceCallerFunction("JSFuncDoTrace", "js_trace"); 319 CreateTraceCallerFunction("JSFuncDoTrace", "js_trace");
333 Local<Value> result = CompileRun( 320 Local<Value> result = CompileRun(
334 "function JSTrace() {" 321 "function JSTrace() {"
335 " JSFuncDoTrace();" 322 " JSFuncDoTrace();"
336 "};\n" 323 "};\n"
337 "function OuterJSTrace() {" 324 "function OuterJSTrace() {"
338 " JSTrace();" 325 " JSTrace();"
339 "};\n" 326 "};\n"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 372 }
386 } 373 }
387 374
388 375
389 // This test verifies that stack tracing doesn't crash when called on 376 // This test verifies that stack tracing doesn't crash when called on
390 // pure native code. StackTracer only unrolls JS code, so we can't 377 // pure native code. StackTracer only unrolls JS code, so we can't
391 // get any meaningful info here. 378 // get any meaningful info here.
392 TEST(PureCStackTrace) { 379 TEST(PureCStackTrace) {
393 TickSample sample; 380 TickSample sample;
394 InitTraceEnv(&sample); 381 InitTraceEnv(&sample);
395 InitializeVM(); 382 CcTest::InitializeVM(TRACE_EXTENSION);
396 // Check that sampler doesn't crash 383 // Check that sampler doesn't crash
397 CHECK_EQ(10, CFunc(10)); 384 CHECK_EQ(10, CFunc(10));
398 } 385 }
399 386
400 387
401 TEST(JsEntrySp) { 388 TEST(JsEntrySp) {
402 InitializeVM(); 389 CcTest::InitializeVM(TRACE_EXTENSION);
403 v8::HandleScope scope(env->GetIsolate()); 390 v8::HandleScope scope(CcTest::isolate());
404 CHECK_EQ(0, GetJsEntrySp()); 391 CHECK_EQ(0, GetJsEntrySp());
405 CompileRun("a = 1; b = a + 1;"); 392 CompileRun("a = 1; b = a + 1;");
406 CHECK_EQ(0, GetJsEntrySp()); 393 CHECK_EQ(0, GetJsEntrySp());
407 CompileRun("js_entry_sp();"); 394 CompileRun("js_entry_sp();");
408 CHECK_EQ(0, GetJsEntrySp()); 395 CHECK_EQ(0, GetJsEntrySp());
409 CompileRun("js_entry_sp_level2();"); 396 CompileRun("js_entry_sp_level2();");
410 CHECK_EQ(0, GetJsEntrySp()); 397 CHECK_EQ(0, GetJsEntrySp());
411 } 398 }
OLDNEW
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698