| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 13346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13357 break; | 13357 break; |
| 13358 | 13358 |
| 13359 default: | 13359 default: |
| 13360 // Impossible event. | 13360 // Impossible event. |
| 13361 CHECK(false); | 13361 CHECK(false); |
| 13362 break; | 13362 break; |
| 13363 } | 13363 } |
| 13364 } | 13364 } |
| 13365 | 13365 |
| 13366 | 13366 |
| 13367 TEST(SetJitCodeEventHandler) { | 13367 UNINITIALIZED_TEST(SetJitCodeEventHandler) { |
| 13368 i::FLAG_stress_compaction = true; | 13368 i::FLAG_stress_compaction = true; |
| 13369 i::FLAG_incremental_marking = false; | 13369 i::FLAG_incremental_marking = false; |
| 13370 const char* script = | 13370 const char* script = |
| 13371 "function bar() {" | 13371 "function bar() {" |
| 13372 " var sum = 0;" | 13372 " var sum = 0;" |
| 13373 " for (i = 0; i < 100; ++i)" | 13373 " for (i = 0; i < 100; ++i)" |
| 13374 " sum = foo(i);" | 13374 " sum = foo(i);" |
| 13375 " return sum;" | 13375 " return sum;" |
| 13376 "}" | 13376 "}" |
| 13377 "function foo(i) { return i * i; };" | 13377 "function foo(i) { return i * i; };" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 13393 | 13393 |
| 13394 saw_bar = 0; | 13394 saw_bar = 0; |
| 13395 move_events = 0; | 13395 move_events = 0; |
| 13396 | 13396 |
| 13397 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler); | 13397 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler); |
| 13398 | 13398 |
| 13399 // Generate new code objects sparsely distributed across several | 13399 // Generate new code objects sparsely distributed across several |
| 13400 // different fragmented code-space pages. | 13400 // different fragmented code-space pages. |
| 13401 const int kIterations = 10; | 13401 const int kIterations = 10; |
| 13402 for (int i = 0; i < kIterations; ++i) { | 13402 for (int i = 0; i < kIterations; ++i) { |
| 13403 LocalContext env; | 13403 LocalContext env(isolate); |
| 13404 i::AlwaysAllocateScope always_allocate; | 13404 i::AlwaysAllocateScope always_allocate; |
| 13405 SimulateFullSpace(heap->code_space()); | 13405 SimulateFullSpace(heap->code_space()); |
| 13406 CompileRun(script); | 13406 CompileRun(script); |
| 13407 | 13407 |
| 13408 // Keep a strong reference to the code object in the handle scope. | 13408 // Keep a strong reference to the code object in the handle scope. |
| 13409 i::Handle<i::Code> bar_code(i::Handle<i::JSFunction>::cast( | 13409 i::Handle<i::Code> bar_code(i::Handle<i::JSFunction>::cast( |
| 13410 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar"))))->code()); | 13410 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar"))))->code()); |
| 13411 i::Handle<i::Code> foo_code(i::Handle<i::JSFunction>::cast( | 13411 i::Handle<i::Code> foo_code(i::Handle<i::JSFunction>::cast( |
| 13412 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo"))))->code()); | 13412 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo"))))->code()); |
| 13413 | 13413 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 13431 isolate->Dispose(); | 13431 isolate->Dispose(); |
| 13432 | 13432 |
| 13433 // Do this in a new isolate. | 13433 // Do this in a new isolate. |
| 13434 isolate = v8::Isolate::New(); | 13434 isolate = v8::Isolate::New(); |
| 13435 isolate->Enter(); | 13435 isolate->Enter(); |
| 13436 | 13436 |
| 13437 // Verify that we get callbacks for existing code objects when we | 13437 // Verify that we get callbacks for existing code objects when we |
| 13438 // request enumeration of existing code. | 13438 // request enumeration of existing code. |
| 13439 { | 13439 { |
| 13440 v8::HandleScope scope(isolate); | 13440 v8::HandleScope scope(isolate); |
| 13441 LocalContext env; | 13441 LocalContext env(isolate); |
| 13442 CompileRun(script); | 13442 CompileRun(script); |
| 13443 | 13443 |
| 13444 // Now get code through initial iteration. | 13444 // Now get code through initial iteration. |
| 13445 i::HashMap code(MatchPointers); | 13445 i::HashMap code(MatchPointers); |
| 13446 code_map = &code; | 13446 code_map = &code; |
| 13447 | 13447 |
| 13448 i::HashMap lineinfo(MatchPointers); | 13448 i::HashMap lineinfo(MatchPointers); |
| 13449 jitcode_line_info = &lineinfo; | 13449 jitcode_line_info = &lineinfo; |
| 13450 | 13450 |
| 13451 V8::SetJitCodeEventHandler(v8::kJitCodeEventEnumExisting, event_handler); | 13451 V8::SetJitCodeEventHandler(v8::kJitCodeEventEnumExisting, event_handler); |
| (...skipping 4762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18214 CHECK_EQ(last_location, NULL); | 18214 CHECK_EQ(last_location, NULL); |
| 18215 CHECK_EQ(last_message, NULL); | 18215 CHECK_EQ(last_message, NULL); |
| 18216 } | 18216 } |
| 18217 | 18217 |
| 18218 | 18218 |
| 18219 UNINITIALIZED_TEST(DisposeIsolateWhenInUse) { | 18219 UNINITIALIZED_TEST(DisposeIsolateWhenInUse) { |
| 18220 v8::Isolate* isolate = v8::Isolate::New(); | 18220 v8::Isolate* isolate = v8::Isolate::New(); |
| 18221 CHECK(isolate); | 18221 CHECK(isolate); |
| 18222 isolate->Enter(); | 18222 isolate->Enter(); |
| 18223 v8::HandleScope scope(isolate); | 18223 v8::HandleScope scope(isolate); |
| 18224 LocalContext context; | 18224 LocalContext context(isolate); |
| 18225 // Run something in this isolate. | 18225 // Run something in this isolate. |
| 18226 ExpectTrue("true"); | 18226 ExpectTrue("true"); |
| 18227 v8::V8::SetFatalErrorHandler(StoringErrorCallback); | 18227 v8::V8::SetFatalErrorHandler(StoringErrorCallback); |
| 18228 last_location = last_message = NULL; | 18228 last_location = last_message = NULL; |
| 18229 // Still entered, should fail. | 18229 // Still entered, should fail. |
| 18230 isolate->Dispose(); | 18230 isolate->Dispose(); |
| 18231 CHECK_NE(last_location, NULL); | 18231 CHECK_NE(last_location, NULL); |
| 18232 CHECK_NE(last_message, NULL); | 18232 CHECK_NE(last_message, NULL); |
| 18233 } | 18233 } |
| 18234 | 18234 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18354 v8::Local<v8::Context>::New(CcTest::isolate(), context_default); | 18354 v8::Local<v8::Context>::New(CcTest::isolate(), context_default); |
| 18355 v8::Context::Scope context_scope(context); | 18355 v8::Context::Scope context_scope(context); |
| 18356 ExpectTrue("function f() { return isDefaultIsolate; }; f()"); | 18356 ExpectTrue("function f() { return isDefaultIsolate; }; f()"); |
| 18357 } | 18357 } |
| 18358 } | 18358 } |
| 18359 | 18359 |
| 18360 | 18360 |
| 18361 static int CalcFibonacci(v8::Isolate* isolate, int limit) { | 18361 static int CalcFibonacci(v8::Isolate* isolate, int limit) { |
| 18362 v8::Isolate::Scope isolate_scope(isolate); | 18362 v8::Isolate::Scope isolate_scope(isolate); |
| 18363 v8::HandleScope scope(isolate); | 18363 v8::HandleScope scope(isolate); |
| 18364 LocalContext context; | 18364 LocalContext context(isolate); |
| 18365 i::ScopedVector<char> code(1024); | 18365 i::ScopedVector<char> code(1024); |
| 18366 i::OS::SNPrintF(code, "function fib(n) {" | 18366 i::OS::SNPrintF(code, "function fib(n) {" |
| 18367 " if (n <= 2) return 1;" | 18367 " if (n <= 2) return 1;" |
| 18368 " return fib(n-1) + fib(n-2);" | 18368 " return fib(n-1) + fib(n-2);" |
| 18369 "}" | 18369 "}" |
| 18370 "fib(%d)", limit); | 18370 "fib(%d)", limit); |
| 18371 Local<Value> value = CompileRun(code.start()); | 18371 Local<Value> value = CompileRun(code.start()); |
| 18372 CHECK(value->IsNumber()); | 18372 CHECK(value->IsNumber()); |
| 18373 return static_cast<int>(value->NumberValue()); | 18373 return static_cast<int>(value->NumberValue()); |
| 18374 } | 18374 } |
| (...skipping 2218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20593 Local<Object> data2 = v8::Object::New(); | 20593 Local<Object> data2 = v8::Object::New(); |
| 20594 function_new_expected_env = data2; | 20594 function_new_expected_env = data2; |
| 20595 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); | 20595 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); |
| 20596 CHECK(!func2->IsNull()); | 20596 CHECK(!func2->IsNull()); |
| 20597 CHECK_NE(func, func2); | 20597 CHECK_NE(func, func2); |
| 20598 env->Global()->Set(v8_str("func2"), func2); | 20598 env->Global()->Set(v8_str("func2"), func2); |
| 20599 Local<Value> result2 = CompileRun("func2();"); | 20599 Local<Value> result2 = CompileRun("func2();"); |
| 20600 CHECK_EQ(v8::Integer::New(17, isolate), result2); | 20600 CHECK_EQ(v8::Integer::New(17, isolate), result2); |
| 20601 } | 20601 } |
| 20602 | 20602 |
| OLD | NEW |