| OLD | NEW |
| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 | 54 |
| 55 class ScopedLoggerInitializer { | 55 class ScopedLoggerInitializer { |
| 56 public: | 56 public: |
| 57 ScopedLoggerInitializer() | 57 ScopedLoggerInitializer() |
| 58 : saved_log_(i::FLAG_log), | 58 : saved_log_(i::FLAG_log), |
| 59 saved_prof_(i::FLAG_prof), | 59 saved_prof_(i::FLAG_prof), |
| 60 temp_file_(NULL), | 60 temp_file_(NULL), |
| 61 // Need to run this prior to creating the scope. | 61 // Need to run this prior to creating the scope. |
| 62 trick_to_run_init_flags_(init_flags_()), | 62 trick_to_run_init_flags_(init_flags_()), |
| 63 scope_(v8::Isolate::GetCurrent()), | 63 scope_(CcTest::isolate()), |
| 64 env_(v8::Context::New(v8::Isolate::GetCurrent())), | 64 env_(v8::Context::New(CcTest::isolate())), |
| 65 logger_(i::Isolate::Current()->logger()) { | 65 logger_(CcTest::i_isolate()->logger()) { |
| 66 env_->Enter(); | 66 env_->Enter(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 ~ScopedLoggerInitializer() { | 69 ~ScopedLoggerInitializer() { |
| 70 env_->Exit(); | 70 env_->Exit(); |
| 71 logger_->TearDown(); | 71 logger_->TearDown(); |
| 72 if (temp_file_ != NULL) fclose(temp_file_); | 72 if (temp_file_ != NULL) fclose(temp_file_); |
| 73 i::FLAG_prof = saved_prof_; | 73 i::FLAG_prof = saved_prof_; |
| 74 i::FLAG_log = saved_log_; | 74 i::FLAG_log = saved_log_; |
| 75 } | 75 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 int v8_thread_id_; | 162 int v8_thread_id_; |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 | 165 |
| 166 class LoopingJsThread : public LoopingThread { | 166 class LoopingJsThread : public LoopingThread { |
| 167 public: | 167 public: |
| 168 explicit LoopingJsThread(v8::internal::Isolate* isolate) | 168 explicit LoopingJsThread(v8::internal::Isolate* isolate) |
| 169 : LoopingThread(isolate) { } | 169 : LoopingThread(isolate) { } |
| 170 void RunLoop() { | 170 void RunLoop() { |
| 171 v8::Locker locker; | 171 v8::Locker locker; |
| 172 CHECK(i::Isolate::Current() != NULL); | 172 CHECK(CcTest::i_isolate() != NULL); |
| 173 CHECK_GT(i::Isolate::Current()->thread_manager()->CurrentId(), 0); | 173 CHECK_GT(CcTest::i_isolate()->thread_manager()->CurrentId(), 0); |
| 174 SetV8ThreadId(); | 174 SetV8ThreadId(); |
| 175 while (IsRunning()) { | 175 while (IsRunning()) { |
| 176 v8::HandleScope scope; | 176 v8::HandleScope scope; |
| 177 v8::Persistent<v8::Context> context = v8::Context::New(); | 177 v8::Persistent<v8::Context> context = v8::Context::New(); |
| 178 CHECK(!context.IsEmpty()); | 178 CHECK(!context.IsEmpty()); |
| 179 { | 179 { |
| 180 v8::Context::Scope context_scope(context); | 180 v8::Context::Scope context_scope(context); |
| 181 SignalRunning(); | 181 SignalRunning(); |
| 182 CompileRun( | 182 CompileRun( |
| 183 "var j; for (var i=0; i<10000; ++i) { j = Math.sin(i); }"); | 183 "var j; for (var i=0; i<10000; ++i) { j = Math.sin(i); }"); |
| 184 } | 184 } |
| 185 context.Dispose(); | 185 context.Dispose(); |
| 186 i::OS::Sleep(1); | 186 i::OS::Sleep(1); |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 }; | 189 }; |
| 190 | 190 |
| 191 | 191 |
| 192 class LoopingNonJsThread : public LoopingThread { | 192 class LoopingNonJsThread : public LoopingThread { |
| 193 public: | 193 public: |
| 194 explicit LoopingNonJsThread(v8::internal::Isolate* isolate) | 194 explicit LoopingNonJsThread(v8::internal::Isolate* isolate) |
| 195 : LoopingThread(isolate) { } | 195 : LoopingThread(isolate) { } |
| 196 void RunLoop() { | 196 void RunLoop() { |
| 197 v8::Locker locker; | 197 v8::Locker locker; |
| 198 v8::Unlocker unlocker; | 198 v8::Unlocker unlocker; |
| 199 // Now thread has V8's id, but will not run VM code. | 199 // Now thread has V8's id, but will not run VM code. |
| 200 CHECK(i::Isolate::Current() != NULL); | 200 CHECK(CcTest::i_isolate() != NULL); |
| 201 CHECK_GT(i::Isolate::Current()->thread_manager()->CurrentId(), 0); | 201 CHECK_GT(CcTest::i_isolate()->thread_manager()->CurrentId(), 0); |
| 202 double i = 10; | 202 double i = 10; |
| 203 SignalRunning(); | 203 SignalRunning(); |
| 204 while (IsRunning()) { | 204 while (IsRunning()) { |
| 205 i = sin(i); | 205 i = sin(i); |
| 206 i::OS::Sleep(1); | 206 i::OS::Sleep(1); |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 }; | 209 }; |
| 210 | 210 |
| 211 | 211 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 236 bool was_sample_stack_called_; | 236 bool was_sample_stack_called_; |
| 237 }; | 237 }; |
| 238 | 238 |
| 239 | 239 |
| 240 } // namespace | 240 } // namespace |
| 241 | 241 |
| 242 TEST(ProfMultipleThreads) { | 242 TEST(ProfMultipleThreads) { |
| 243 TestSampler* sampler = NULL; | 243 TestSampler* sampler = NULL; |
| 244 { | 244 { |
| 245 v8::Locker locker; | 245 v8::Locker locker; |
| 246 sampler = new TestSampler(v8::internal::Isolate::Current()); | 246 sampler = new TestSampler(CcTest::i_isolate()); |
| 247 sampler->Start(); | 247 sampler->Start(); |
| 248 CHECK(sampler->IsActive()); | 248 CHECK(sampler->IsActive()); |
| 249 } | 249 } |
| 250 | 250 |
| 251 LoopingJsThread jsThread(v8::internal::Isolate::Current()); | 251 LoopingJsThread jsThread(CcTest::i_isolate()); |
| 252 jsThread.Start(); | 252 jsThread.Start(); |
| 253 LoopingNonJsThread nonJsThread(v8::internal::Isolate::Current()); | 253 LoopingNonJsThread nonJsThread(CcTest::i_isolate()); |
| 254 nonJsThread.Start(); | 254 nonJsThread.Start(); |
| 255 | 255 |
| 256 CHECK(!sampler->WasSampleStackCalled()); | 256 CHECK(!sampler->WasSampleStackCalled()); |
| 257 jsThread.WaitForRunning(); | 257 jsThread.WaitForRunning(); |
| 258 jsThread.SendSigProf(); | 258 jsThread.SendSigProf(); |
| 259 CHECK(sampler->WaitForTick()); | 259 CHECK(sampler->WaitForTick()); |
| 260 CHECK(sampler->WasSampleStackCalled()); | 260 CHECK(sampler->WasSampleStackCalled()); |
| 261 sampler->Reset(); | 261 sampler->Reset(); |
| 262 CHECK(!sampler->WasSampleStackCalled()); | 262 CHECK(!sampler->WasSampleStackCalled()); |
| 263 nonJsThread.WaitForRunning(); | 263 nonJsThread.WaitForRunning(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 292 virtual ~SimpleExternalString() {} | 292 virtual ~SimpleExternalString() {} |
| 293 virtual size_t length() const { return utf_source_.length(); } | 293 virtual size_t length() const { return utf_source_.length(); } |
| 294 virtual const uint16_t* data() const { return utf_source_.start(); } | 294 virtual const uint16_t* data() const { return utf_source_.start(); } |
| 295 private: | 295 private: |
| 296 i::ScopedVector<uint16_t> utf_source_; | 296 i::ScopedVector<uint16_t> utf_source_; |
| 297 }; | 297 }; |
| 298 | 298 |
| 299 } // namespace | 299 } // namespace |
| 300 | 300 |
| 301 TEST(Issue23768) { | 301 TEST(Issue23768) { |
| 302 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 302 v8::HandleScope scope(CcTest::isolate()); |
| 303 v8::Handle<v8::Context> env = v8::Context::New(v8::Isolate::GetCurrent()); | 303 v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate()); |
| 304 env->Enter(); | 304 env->Enter(); |
| 305 | 305 |
| 306 SimpleExternalString source_ext_str("(function ext() {})();"); | 306 SimpleExternalString source_ext_str("(function ext() {})();"); |
| 307 v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str); | 307 v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str); |
| 308 // Script needs to have a name in order to trigger InitLineEnds execution. | 308 // Script needs to have a name in order to trigger InitLineEnds execution. |
| 309 v8::Handle<v8::String> origin = v8::String::New("issue-23768-test"); | 309 v8::Handle<v8::String> origin = v8::String::New("issue-23768-test"); |
| 310 v8::Handle<v8::Script> evil_script = v8::Script::Compile(source, origin); | 310 v8::Handle<v8::Script> evil_script = v8::Script::Compile(source, origin); |
| 311 CHECK(!evil_script.IsEmpty()); | 311 CHECK(!evil_script.IsEmpty()); |
| 312 CHECK(!evil_script->Run().IsEmpty()); | 312 CHECK(!evil_script->Run().IsEmpty()); |
| 313 i::Handle<i::ExternalTwoByteString> i_source( | 313 i::Handle<i::ExternalTwoByteString> i_source( |
| 314 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); | 314 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); |
| 315 // This situation can happen if source was an external string disposed | 315 // This situation can happen if source was an external string disposed |
| 316 // by its owner. | 316 // by its owner. |
| 317 i_source->set_resource(NULL); | 317 i_source->set_resource(NULL); |
| 318 | 318 |
| 319 // Must not crash. | 319 // Must not crash. |
| 320 i::Isolate::Current()->logger()->LogCompiledFunctions(); | 320 CcTest::i_isolate()->logger()->LogCompiledFunctions(); |
| 321 } | 321 } |
| 322 | 322 |
| 323 | 323 |
| 324 static void ObjMethod1(const v8::FunctionCallbackInfo<v8::Value>& args) { | 324 static void ObjMethod1(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 325 } | 325 } |
| 326 | 326 |
| 327 | 327 |
| 328 TEST(LogCallbacks) { | 328 UNINITIALIZED_TEST(LogCallbacks) { |
| 329 ScopedLoggerInitializer initialize_logger; | 329 ScopedLoggerInitializer initialize_logger; |
| 330 Logger* logger = initialize_logger.logger(); | 330 Logger* logger = initialize_logger.logger(); |
| 331 | 331 |
| 332 v8::Local<v8::FunctionTemplate> obj = | 332 v8::Local<v8::FunctionTemplate> obj = |
| 333 v8::Local<v8::FunctionTemplate>::New(v8::Isolate::GetCurrent(), | 333 v8::Local<v8::FunctionTemplate>::New(CcTest::isolate(), |
| 334 v8::FunctionTemplate::New()); | 334 v8::FunctionTemplate::New()); |
| 335 obj->SetClassName(v8_str("Obj")); | 335 obj->SetClassName(v8_str("Obj")); |
| 336 v8::Handle<v8::ObjectTemplate> proto = obj->PrototypeTemplate(); | 336 v8::Handle<v8::ObjectTemplate> proto = obj->PrototypeTemplate(); |
| 337 v8::Local<v8::Signature> signature = v8::Signature::New(obj); | 337 v8::Local<v8::Signature> signature = v8::Signature::New(obj); |
| 338 proto->Set(v8_str("method1"), | 338 proto->Set(v8_str("method1"), |
| 339 v8::FunctionTemplate::New(ObjMethod1, | 339 v8::FunctionTemplate::New(ObjMethod1, |
| 340 v8::Handle<v8::Value>(), | 340 v8::Handle<v8::Value>(), |
| 341 signature), | 341 signature), |
| 342 static_cast<v8::PropertyAttribute>(v8::DontDelete)); | 342 static_cast<v8::PropertyAttribute>(v8::DontDelete)); |
| 343 | 343 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 367 static void Prop1Setter(v8::Local<v8::String> property, | 367 static void Prop1Setter(v8::Local<v8::String> property, |
| 368 v8::Local<v8::Value> value, | 368 v8::Local<v8::Value> value, |
| 369 const v8::PropertyCallbackInfo<void>& info) { | 369 const v8::PropertyCallbackInfo<void>& info) { |
| 370 } | 370 } |
| 371 | 371 |
| 372 static void Prop2Getter(v8::Local<v8::String> property, | 372 static void Prop2Getter(v8::Local<v8::String> property, |
| 373 const v8::PropertyCallbackInfo<v8::Value>& info) { | 373 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 374 } | 374 } |
| 375 | 375 |
| 376 | 376 |
| 377 TEST(LogAccessorCallbacks) { | 377 UNINITIALIZED_TEST(LogAccessorCallbacks) { |
| 378 ScopedLoggerInitializer initialize_logger; | 378 ScopedLoggerInitializer initialize_logger; |
| 379 Logger* logger = initialize_logger.logger(); | 379 Logger* logger = initialize_logger.logger(); |
| 380 | 380 |
| 381 v8::Local<v8::FunctionTemplate> obj = | 381 v8::Local<v8::FunctionTemplate> obj = |
| 382 v8::Local<v8::FunctionTemplate>::New(v8::Isolate::GetCurrent(), | 382 v8::Local<v8::FunctionTemplate>::New(CcTest::isolate(), |
| 383 v8::FunctionTemplate::New()); | 383 v8::FunctionTemplate::New()); |
| 384 obj->SetClassName(v8_str("Obj")); | 384 obj->SetClassName(v8_str("Obj")); |
| 385 v8::Handle<v8::ObjectTemplate> inst = obj->InstanceTemplate(); | 385 v8::Handle<v8::ObjectTemplate> inst = obj->InstanceTemplate(); |
| 386 inst->SetAccessor(v8_str("prop1"), Prop1Getter, Prop1Setter); | 386 inst->SetAccessor(v8_str("prop1"), Prop1Getter, Prop1Setter); |
| 387 inst->SetAccessor(v8_str("prop2"), Prop2Getter); | 387 inst->SetAccessor(v8_str("prop2"), Prop2Getter); |
| 388 | 388 |
| 389 logger->LogAccessorCallbacks(); | 389 logger->LogAccessorCallbacks(); |
| 390 | 390 |
| 391 bool exists = false; | 391 bool exists = false; |
| 392 i::Vector<const char> log( | 392 i::Vector<const char> log( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 414 CHECK_NE(NULL, | 414 CHECK_NE(NULL, |
| 415 StrNStr(log.start(), prop2_getter_record.start(), log.length())); | 415 StrNStr(log.start(), prop2_getter_record.start(), log.length())); |
| 416 } | 416 } |
| 417 | 417 |
| 418 | 418 |
| 419 typedef i::NativesCollection<i::TEST> TestSources; | 419 typedef i::NativesCollection<i::TEST> TestSources; |
| 420 | 420 |
| 421 | 421 |
| 422 // Test that logging of code create / move events is equivalent to traversal of | 422 // Test that logging of code create / move events is equivalent to traversal of |
| 423 // a resulting heap. | 423 // a resulting heap. |
| 424 TEST(EquivalenceOfLoggingAndTraversal) { | 424 UNINITIALIZED_TEST(EquivalenceOfLoggingAndTraversal) { |
| 425 // This test needs to be run on a "clean" V8 to ensure that snapshot log | 425 // This test needs to be run on a "clean" V8 to ensure that snapshot log |
| 426 // is loaded. This is always true when running using tools/test.py because | 426 // is loaded. This is always true when running using tools/test.py because |
| 427 // it launches a new cctest instance for every test. To be sure that launching | 427 // it launches a new cctest instance for every test. To be sure that launching |
| 428 // cctest manually also works, please be sure that no tests below | 428 // cctest manually also works, please be sure that no tests below |
| 429 // are using V8. | 429 // are using V8. |
| 430 | 430 |
| 431 // Start with profiling to capture all code events from the beginning. | 431 // Start with profiling to capture all code events from the beginning. |
| 432 ScopedLoggerInitializer initialize_logger; | 432 ScopedLoggerInitializer initialize_logger; |
| 433 Logger* logger = initialize_logger.logger(); | 433 Logger* logger = initialize_logger.logger(); |
| 434 | 434 |
| 435 // Compile and run a function that creates other functions. | 435 // Compile and run a function that creates other functions. |
| 436 CompileRun( | 436 CompileRun( |
| 437 "(function f(obj) {\n" | 437 "(function f(obj) {\n" |
| 438 " obj.test =\n" | 438 " obj.test =\n" |
| 439 " (function a(j) { return function b() { return j; } })(100);\n" | 439 " (function a(j) { return function b() { return j; } })(100);\n" |
| 440 "})(this);"); | 440 "})(this);"); |
| 441 logger->StopProfiler(); | 441 logger->StopProfiler(); |
| 442 HEAP->CollectAllGarbage(i::Heap::kMakeHeapIterableMask); | 442 CcTest::heap()->CollectAllGarbage(i::Heap::kMakeHeapIterableMask); |
| 443 logger->StringEvent("test-logging-done", ""); | 443 logger->StringEvent("test-logging-done", ""); |
| 444 | 444 |
| 445 // Iterate heap to find compiled functions, will write to log. | 445 // Iterate heap to find compiled functions, will write to log. |
| 446 logger->LogCompiledFunctions(); | 446 logger->LogCompiledFunctions(); |
| 447 logger->StringEvent("test-traversal-done", ""); | 447 logger->StringEvent("test-traversal-done", ""); |
| 448 | 448 |
| 449 bool exists = false; | 449 bool exists = false; |
| 450 i::Vector<const char> log( | 450 i::Vector<const char> log( |
| 451 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true)); | 451 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true)); |
| 452 CHECK(exists); | 452 CHECK(exists); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 474 v8::Local<v8::String> s = result->ToString(); | 474 v8::Local<v8::String> s = result->ToString(); |
| 475 i::ScopedVector<char> data(s->Utf8Length() + 1); | 475 i::ScopedVector<char> data(s->Utf8Length() + 1); |
| 476 CHECK_NE(NULL, data.start()); | 476 CHECK_NE(NULL, data.start()); |
| 477 s->WriteUtf8(data.start()); | 477 s->WriteUtf8(data.start()); |
| 478 printf("%s\n", data.start()); | 478 printf("%s\n", data.start()); |
| 479 // Make sure that our output is written prior crash due to CHECK failure. | 479 // Make sure that our output is written prior crash due to CHECK failure. |
| 480 fflush(stdout); | 480 fflush(stdout); |
| 481 CHECK(false); | 481 CHECK(false); |
| 482 } | 482 } |
| 483 } | 483 } |
| OLD | NEW |