Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 4414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4425 "}" | 4425 "}" |
| 4426 "gc();" | 4426 "gc();" |
| 4427 "4"; | 4427 "4"; |
| 4428 v8::Handle<Value> result = CompileRun(code); | 4428 v8::Handle<Value> result = CompileRun(code); |
| 4429 CHECK_EQ(4.0, result->NumberValue()); | 4429 CHECK_EQ(4.0, result->NumberValue()); |
| 4430 delete whammy; | 4430 delete whammy; |
| 4431 context.Dispose(); | 4431 context.Dispose(); |
| 4432 } | 4432 } |
| 4433 | 4433 |
| 4434 | 4434 |
| 4435 static bool in_scavenge = false; | 4435 static void DisposeAndSetFlag(v8::Persistent<v8::Value> obj, void* data) { |
| 4436 static int last = -1; | |
| 4437 | |
| 4438 static void ForceScavenge(v8::Persistent<v8::Value> obj, void* data) { | |
| 4439 CHECK_EQ(-1, last); | |
| 4440 last = 0; | |
| 4441 obj.Dispose(); | 4436 obj.Dispose(); |
| 4442 obj.Clear(); | 4437 obj.Clear(); |
| 4443 in_scavenge = true; | |
| 4444 HEAP->PerformScavenge(); | |
| 4445 in_scavenge = false; | |
| 4446 *(reinterpret_cast<bool*>(data)) = true; | 4438 *(reinterpret_cast<bool*>(data)) = true; |
| 4447 } | 4439 } |
| 4448 | 4440 |
| 4449 static void CheckIsNotInvokedInScavenge(v8::Persistent<v8::Value> obj, | |
| 4450 void* data) { | |
| 4451 CHECK_EQ(0, last); | |
| 4452 last = 1; | |
| 4453 *(reinterpret_cast<bool*>(data)) = in_scavenge; | |
| 4454 obj.Dispose(); | |
| 4455 obj.Clear(); | |
| 4456 } | |
| 4457 | 4441 |
| 4458 THREADED_TEST(NoWeakRefCallbacksInScavenge) { | 4442 THREADED_TEST(IndependentWeakHandle) { |
| 4459 // Test verifies that scavenge cannot invoke WeakReferenceCallbacks. | |
| 4460 // Calling callbacks from scavenges is unsafe as objects held by those | |
| 4461 // handlers might have become strongly reachable, but scavenge doesn't | |
| 4462 // check that. | |
| 4463 v8::Persistent<Context> context = Context::New(); | 4443 v8::Persistent<Context> context = Context::New(); |
| 4464 Context::Scope context_scope(context); | 4444 Context::Scope context_scope(context); |
| 4465 | 4445 |
| 4466 v8::Persistent<v8::Object> object_a; | 4446 v8::Persistent<v8::Object> object_a; |
| 4467 v8::Persistent<v8::Object> object_b; | |
| 4468 | 4447 |
| 4469 { | 4448 { |
| 4470 v8::HandleScope handle_scope; | 4449 v8::HandleScope handle_scope; |
| 4471 object_b = v8::Persistent<v8::Object>::New(v8::Object::New()); | |
| 4472 object_a = v8::Persistent<v8::Object>::New(v8::Object::New()); | 4450 object_a = v8::Persistent<v8::Object>::New(v8::Object::New()); |
| 4473 } | 4451 } |
| 4474 | 4452 |
| 4475 bool object_a_disposed = false; | 4453 bool object_a_disposed = false; |
| 4476 object_a.MakeWeak(&object_a_disposed, &ForceScavenge); | 4454 object_a.MakeWeak(&object_a_disposed, &DisposeAndSetFlag); |
| 4477 bool released_in_scavenge = false; | 4455 object_a.MarkIndependent(); |
| 4478 object_b.MakeWeak(&released_in_scavenge, &CheckIsNotInvokedInScavenge); | 4456 HEAP->PerformScavenge(); |
| 4457 CHECK(object_a_disposed); | |
| 4458 } | |
| 4479 | 4459 |
| 4480 while (!object_a_disposed) { | 4460 |
| 4481 HEAP->CollectAllGarbage(false); | 4461 static void InvokeScavenge() { |
| 4462 HEAP->PerformScavenge(); | |
| 4463 } | |
| 4464 | |
| 4465 | |
| 4466 static void InvokeMarkSweep() { | |
| 4467 HEAP->CollectAllGarbage(false); | |
| 4468 } | |
| 4469 | |
| 4470 | |
| 4471 static void ForceScavenge(v8::Persistent<v8::Value> obj, void* data) { | |
| 4472 obj.Dispose(); | |
|
antonm
2011/05/16 15:20:44
this slightly worries me. Currently we use data
Vyacheslav Egorov (Chromium)
2011/05/16 15:29:44
Sorry, I am not following. Could you elaborate you
antonm
2011/05/16 15:48:24
Sorry, I was wrong in my assumption.
On 2011/05/1
| |
| 4473 obj.Clear(); | |
| 4474 *(reinterpret_cast<bool*>(data)) = true; | |
| 4475 InvokeScavenge(); | |
| 4476 } | |
| 4477 | |
| 4478 | |
| 4479 static void ForceMarkSweep(v8::Persistent<v8::Value> obj, void* data) { | |
| 4480 obj.Dispose(); | |
| 4481 obj.Clear(); | |
| 4482 *(reinterpret_cast<bool*>(data)) = true; | |
| 4483 InvokeMarkSweep(); | |
| 4484 } | |
| 4485 | |
| 4486 | |
| 4487 THREADED_TEST(GCFromWeakCallbacks) { | |
| 4488 v8::Persistent<Context> context = Context::New(); | |
| 4489 Context::Scope context_scope(context); | |
| 4490 | |
| 4491 static const int kNumberOfGCTypes = 2; | |
| 4492 v8::WeakReferenceCallback gc_forcing_callback[kNumberOfGCTypes] = | |
| 4493 {&ForceScavenge, &ForceMarkSweep}; | |
| 4494 | |
| 4495 typedef void (*GCInvoker)(); | |
| 4496 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; | |
| 4497 | |
| 4498 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { | |
| 4499 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) { | |
| 4500 v8::Persistent<v8::Object> object; | |
| 4501 { | |
| 4502 v8::HandleScope handle_scope; | |
| 4503 object = v8::Persistent<v8::Object>::New(v8::Object::New()); | |
| 4504 } | |
| 4505 bool disposed = false; | |
| 4506 object.MakeWeak(&disposed, gc_forcing_callback[inner_gc]); | |
| 4507 object.MarkIndependent(); | |
| 4508 invoke_gc[outer_gc](); | |
| 4509 CHECK(disposed); | |
| 4510 } | |
| 4482 } | 4511 } |
| 4483 CHECK(!released_in_scavenge); | |
| 4484 } | 4512 } |
| 4485 | 4513 |
| 4486 | 4514 |
| 4515 | |
| 4487 v8::Handle<Function> args_fun; | 4516 v8::Handle<Function> args_fun; |
| 4488 | 4517 |
| 4489 | 4518 |
| 4490 static v8::Handle<Value> ArgumentsTestCallback(const v8::Arguments& args) { | 4519 static v8::Handle<Value> ArgumentsTestCallback(const v8::Arguments& args) { |
| 4491 ApiTestFuzzer::Fuzz(); | 4520 ApiTestFuzzer::Fuzz(); |
| 4492 CHECK_EQ(args_fun, args.Callee()); | 4521 CHECK_EQ(args_fun, args.Callee()); |
| 4493 CHECK_EQ(3, args.Length()); | 4522 CHECK_EQ(3, args.Length()); |
| 4494 CHECK_EQ(v8::Integer::New(1), args[0]); | 4523 CHECK_EQ(v8::Integer::New(1), args[0]); |
| 4495 CHECK_EQ(v8::Integer::New(2), args[1]); | 4524 CHECK_EQ(v8::Integer::New(2), args[1]); |
| 4496 CHECK_EQ(v8::Integer::New(3), args[2]); | 4525 CHECK_EQ(v8::Integer::New(3), args[2]); |
| (...skipping 9949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14446 | 14475 |
| 14447 THREADED_TEST(CallAPIFunctionOnNonObject) { | 14476 THREADED_TEST(CallAPIFunctionOnNonObject) { |
| 14448 v8::HandleScope scope; | 14477 v8::HandleScope scope; |
| 14449 LocalContext context; | 14478 LocalContext context; |
| 14450 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); | 14479 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); |
| 14451 Handle<Function> function = templ->GetFunction(); | 14480 Handle<Function> function = templ->GetFunction(); |
| 14452 context->Global()->Set(v8_str("f"), function); | 14481 context->Global()->Set(v8_str("f"), function); |
| 14453 TryCatch try_catch; | 14482 TryCatch try_catch; |
| 14454 CompileRun("f.call(2)"); | 14483 CompileRun("f.call(2)"); |
| 14455 } | 14484 } |
| OLD | NEW |