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

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

Issue 1116633002: Pass ArrayBuffer::Allocator via Isolate::CreateParams (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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 | « test/cctest/test-lockers.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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "test/cctest/cctest.h" 47 #include "test/cctest/cctest.h"
48 48
49 using v8::internal::Address; 49 using v8::internal::Address;
50 using v8::internal::EmbeddedVector; 50 using v8::internal::EmbeddedVector;
51 using v8::internal::Logger; 51 using v8::internal::Logger;
52 using v8::internal::StrLength; 52 using v8::internal::StrLength;
53 53
54 namespace { 54 namespace {
55 55
56 56
57 #define SETUP_FLAGS() \
58 bool saved_log = i::FLAG_log; \
59 bool saved_prof = i::FLAG_prof; \
60 i::FLAG_log = true; \
61 i::FLAG_prof = true; \
62 i::FLAG_logfile = i::Log::kLogToTemporaryFile; \
63 i::FLAG_logfile_per_isolate = false
64
65
57 class ScopedLoggerInitializer { 66 class ScopedLoggerInitializer {
58 public: 67 public:
59 ScopedLoggerInitializer() 68 ScopedLoggerInitializer(bool saved_log, bool saved_prof, v8::Isolate* isolate)
60 : saved_log_(i::FLAG_log), 69 : saved_log_(saved_log),
61 saved_prof_(i::FLAG_prof), 70 saved_prof_(saved_prof),
62 temp_file_(NULL), 71 temp_file_(NULL),
63 // Need to run this prior to creating the scope. 72 isolate_(isolate),
64 trick_to_run_init_flags_(init_flags_()), 73 isolate_scope_(isolate),
65 isolate_(v8::Isolate::New()), 74 scope_(isolate),
66 isolate_scope_(isolate_), 75 env_(v8::Context::New(isolate)),
67 scope_(isolate_), 76 logger_(reinterpret_cast<i::Isolate*>(isolate)->logger()) {
68 env_(v8::Context::New(isolate_)),
69 logger_(reinterpret_cast<i::Isolate*>(isolate_)->logger()) {
70 env_->Enter(); 77 env_->Enter();
71 } 78 }
72 79
73 ~ScopedLoggerInitializer() { 80 ~ScopedLoggerInitializer() {
74 env_->Exit(); 81 env_->Exit();
75 logger_->TearDown(); 82 logger_->TearDown();
76 if (temp_file_ != NULL) fclose(temp_file_); 83 if (temp_file_ != NULL) fclose(temp_file_);
77 i::FLAG_prof = saved_prof_; 84 i::FLAG_prof = saved_prof_;
78 i::FLAG_log = saved_log_; 85 i::FLAG_log = saved_log_;
79 } 86 }
80 87
81 v8::Handle<v8::Context>& env() { return env_; } 88 v8::Handle<v8::Context>& env() { return env_; }
82 89
83 v8::Isolate* isolate() { return isolate_; } 90 v8::Isolate* isolate() { return isolate_; }
84 91
85 Logger* logger() { return logger_; } 92 Logger* logger() { return logger_; }
86 93
87 FILE* StopLoggingGetTempFile() { 94 FILE* StopLoggingGetTempFile() {
88 temp_file_ = logger_->TearDown(); 95 temp_file_ = logger_->TearDown();
89 CHECK(temp_file_); 96 CHECK(temp_file_);
90 fflush(temp_file_); 97 fflush(temp_file_);
91 rewind(temp_file_); 98 rewind(temp_file_);
92 return temp_file_; 99 return temp_file_;
93 } 100 }
94 101
95 private: 102 private:
96 static bool init_flags_() {
97 i::FLAG_log = true;
98 i::FLAG_prof = true;
99 i::FLAG_logfile = i::Log::kLogToTemporaryFile;
100 i::FLAG_logfile_per_isolate = false;
101 return false;
102 }
103
104 const bool saved_log_; 103 const bool saved_log_;
105 const bool saved_prof_; 104 const bool saved_prof_;
106 FILE* temp_file_; 105 FILE* temp_file_;
107 const bool trick_to_run_init_flags_;
108 v8::Isolate* isolate_; 106 v8::Isolate* isolate_;
109 v8::Isolate::Scope isolate_scope_; 107 v8::Isolate::Scope isolate_scope_;
110 v8::HandleScope scope_; 108 v8::HandleScope scope_;
111 v8::Handle<v8::Context> env_; 109 v8::Handle<v8::Context> env_;
112 Logger* logger_; 110 Logger* logger_;
113 111
114 DISALLOW_COPY_AND_ASSIGN(ScopedLoggerInitializer); 112 DISALLOW_COPY_AND_ASSIGN(ScopedLoggerInitializer);
115 }; 113 };
116 114
117 } // namespace 115 } // namespace
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // Must not crash. 328 // Must not crash.
331 CcTest::i_isolate()->logger()->LogCompiledFunctions(); 329 CcTest::i_isolate()->logger()->LogCompiledFunctions();
332 } 330 }
333 331
334 332
335 static void ObjMethod1(const v8::FunctionCallbackInfo<v8::Value>& args) { 333 static void ObjMethod1(const v8::FunctionCallbackInfo<v8::Value>& args) {
336 } 334 }
337 335
338 336
339 TEST(LogCallbacks) { 337 TEST(LogCallbacks) {
340 v8::Isolate* isolate; 338 SETUP_FLAGS();
339 v8::Isolate::CreateParams create_params;
340 create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
341 v8::Isolate* isolate = v8::Isolate::New(create_params);
341 { 342 {
342 ScopedLoggerInitializer initialize_logger; 343 ScopedLoggerInitializer initialize_logger(saved_log, saved_prof, isolate);
343 isolate = initialize_logger.isolate();
344 Logger* logger = initialize_logger.logger(); 344 Logger* logger = initialize_logger.logger();
345 345
346 v8::Local<v8::FunctionTemplate> obj = v8::Local<v8::FunctionTemplate>::New( 346 v8::Local<v8::FunctionTemplate> obj = v8::Local<v8::FunctionTemplate>::New(
347 isolate, v8::FunctionTemplate::New(isolate)); 347 isolate, v8::FunctionTemplate::New(isolate));
348 obj->SetClassName(v8_str("Obj")); 348 obj->SetClassName(v8_str("Obj"));
349 v8::Handle<v8::ObjectTemplate> proto = obj->PrototypeTemplate(); 349 v8::Handle<v8::ObjectTemplate> proto = obj->PrototypeTemplate();
350 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, obj); 350 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, obj);
351 proto->Set(v8_str("method1"), 351 proto->Set(v8_str("method1"),
352 v8::FunctionTemplate::New(isolate, ObjMethod1, 352 v8::FunctionTemplate::New(isolate, ObjMethod1,
353 v8::Handle<v8::Value>(), signature), 353 v8::Handle<v8::Value>(), signature),
(...skipping 29 matching lines...) Expand all
383 v8::Local<v8::Value> value, 383 v8::Local<v8::Value> value,
384 const v8::PropertyCallbackInfo<void>& info) { 384 const v8::PropertyCallbackInfo<void>& info) {
385 } 385 }
386 386
387 static void Prop2Getter(v8::Local<v8::String> property, 387 static void Prop2Getter(v8::Local<v8::String> property,
388 const v8::PropertyCallbackInfo<v8::Value>& info) { 388 const v8::PropertyCallbackInfo<v8::Value>& info) {
389 } 389 }
390 390
391 391
392 TEST(LogAccessorCallbacks) { 392 TEST(LogAccessorCallbacks) {
393 v8::Isolate* isolate; 393 SETUP_FLAGS();
394 v8::Isolate::CreateParams create_params;
395 create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
396 v8::Isolate* isolate = v8::Isolate::New(create_params);
394 { 397 {
395 ScopedLoggerInitializer initialize_logger; 398 ScopedLoggerInitializer initialize_logger(saved_log, saved_prof, isolate);
396 isolate = initialize_logger.isolate();
397 Logger* logger = initialize_logger.logger(); 399 Logger* logger = initialize_logger.logger();
398 400
399 v8::Local<v8::FunctionTemplate> obj = v8::Local<v8::FunctionTemplate>::New( 401 v8::Local<v8::FunctionTemplate> obj = v8::Local<v8::FunctionTemplate>::New(
400 isolate, v8::FunctionTemplate::New(isolate)); 402 isolate, v8::FunctionTemplate::New(isolate));
401 obj->SetClassName(v8_str("Obj")); 403 obj->SetClassName(v8_str("Obj"));
402 v8::Handle<v8::ObjectTemplate> inst = obj->InstanceTemplate(); 404 v8::Handle<v8::ObjectTemplate> inst = obj->InstanceTemplate();
403 inst->SetAccessor(v8_str("prop1"), Prop1Getter, Prop1Setter); 405 inst->SetAccessor(v8_str("prop1"), Prop1Getter, Prop1Setter);
404 inst->SetAccessor(v8_str("prop2"), Prop2Getter); 406 inst->SetAccessor(v8_str("prop2"), Prop2Getter);
405 407
406 logger->LogAccessorCallbacks(); 408 logger->LogAccessorCallbacks();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 // Test that logging of code create / move events is equivalent to traversal of 441 // Test that logging of code create / move events is equivalent to traversal of
440 // a resulting heap. 442 // a resulting heap.
441 TEST(EquivalenceOfLoggingAndTraversal) { 443 TEST(EquivalenceOfLoggingAndTraversal) {
442 // This test needs to be run on a "clean" V8 to ensure that snapshot log 444 // This test needs to be run on a "clean" V8 to ensure that snapshot log
443 // is loaded. This is always true when running using tools/test.py because 445 // is loaded. This is always true when running using tools/test.py because
444 // it launches a new cctest instance for every test. To be sure that launching 446 // it launches a new cctest instance for every test. To be sure that launching
445 // cctest manually also works, please be sure that no tests below 447 // cctest manually also works, please be sure that no tests below
446 // are using V8. 448 // are using V8.
447 449
448 // Start with profiling to capture all code events from the beginning. 450 // Start with profiling to capture all code events from the beginning.
449 v8::Isolate* isolate; 451 SETUP_FLAGS();
452 v8::Isolate::CreateParams create_params;
453 create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
454 v8::Isolate* isolate = v8::Isolate::New(create_params);
450 { 455 {
451 ScopedLoggerInitializer initialize_logger; 456 ScopedLoggerInitializer initialize_logger(saved_log, saved_prof, isolate);
452 isolate = initialize_logger.isolate();
453 Logger* logger = initialize_logger.logger(); 457 Logger* logger = initialize_logger.logger();
454 458
455 // Compile and run a function that creates other functions. 459 // Compile and run a function that creates other functions.
456 CompileRun( 460 CompileRun(
457 "(function f(obj) {\n" 461 "(function f(obj) {\n"
458 " obj.test =\n" 462 " obj.test =\n"
459 " (function a(j) { return function b() { return j; } })(100);\n" 463 " (function a(j) { return function b() { return j; } })(100);\n"
460 "})(this);"); 464 "})(this);");
461 logger->StopProfiler(); 465 logger->StopProfiler();
462 reinterpret_cast<i::Isolate*>(isolate)->heap()->CollectAllGarbage( 466 reinterpret_cast<i::Isolate*>(isolate)->heap()->CollectAllGarbage(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // Make sure that our output is written prior crash due to CHECK failure. 505 // Make sure that our output is written prior crash due to CHECK failure.
502 fflush(stdout); 506 fflush(stdout);
503 CHECK(false); 507 CHECK(false);
504 } 508 }
505 } 509 }
506 isolate->Dispose(); 510 isolate->Dispose();
507 } 511 }
508 512
509 513
510 TEST(LogVersion) { 514 TEST(LogVersion) {
511 v8::Isolate* isolate; 515 SETUP_FLAGS();
516 v8::Isolate::CreateParams create_params;
517 create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
518 v8::Isolate* isolate = v8::Isolate::New(create_params);
512 { 519 {
513 ScopedLoggerInitializer initialize_logger; 520 ScopedLoggerInitializer initialize_logger(saved_log, saved_prof, isolate);
514 isolate = initialize_logger.isolate();
515 bool exists = false; 521 bool exists = false;
516 i::Vector<const char> log( 522 i::Vector<const char> log(
517 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true)); 523 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true));
518 CHECK(exists); 524 CHECK(exists);
519 i::EmbeddedVector<char, 100> ref_data; 525 i::EmbeddedVector<char, 100> ref_data;
520 i::SNPrintF(ref_data, "v8-version,%d,%d,%d,%d,%d", i::Version::GetMajor(), 526 i::SNPrintF(ref_data, "v8-version,%d,%d,%d,%d,%d", i::Version::GetMajor(),
521 i::Version::GetMinor(), i::Version::GetBuild(), 527 i::Version::GetMinor(), i::Version::GetBuild(),
522 i::Version::GetPatch(), i::Version::IsCandidate()); 528 i::Version::GetPatch(), i::Version::IsCandidate());
523 CHECK(StrNStr(log.start(), ref_data.start(), log.length())); 529 CHECK(StrNStr(log.start(), ref_data.start(), log.length()));
524 log.Dispose(); 530 log.Dispose();
525 } 531 }
526 isolate->Dispose(); 532 isolate->Dispose();
527 } 533 }
OLDNEW
« no previous file with comments | « test/cctest/test-lockers.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698