| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 CLEAN_CACHE, | 57 CLEAN_CACHE, |
| 58 SECOND_TIME_FILL_CACHE, | 58 SECOND_TIME_FILL_CACHE, |
| 59 DONE | 59 DONE |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 static Turn turn = FILL_CACHE; | 62 static Turn turn = FILL_CACHE; |
| 63 | 63 |
| 64 | 64 |
| 65 class ThreadA: public v8::internal::Thread { | 65 class ThreadA: public v8::internal::Thread { |
| 66 public: | 66 public: |
| 67 explicit ThreadA(i::Isolate* isolate) : Thread(isolate) { } | 67 explicit ThreadA(i::Isolate* isolate) : Thread(isolate, "ThreadA") { } |
| 68 void Run() { | 68 void Run() { |
| 69 v8::Locker locker; | 69 v8::Locker locker; |
| 70 v8::HandleScope scope; | 70 v8::HandleScope scope; |
| 71 v8::Context::Scope context_scope(v8::Context::New()); | 71 v8::Context::Scope context_scope(v8::Context::New()); |
| 72 | 72 |
| 73 CHECK_EQ(FILL_CACHE, turn); | 73 CHECK_EQ(FILL_CACHE, turn); |
| 74 | 74 |
| 75 // Fill String.search cache. | 75 // Fill String.search cache. |
| 76 v8::Handle<v8::Script> script = v8::Script::Compile( | 76 v8::Handle<v8::Script> script = v8::Script::Compile( |
| 77 v8::String::New( | 77 v8::String::New( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 93 // Rerun the script. | 93 // Rerun the script. |
| 94 CHECK(script->Run()->IsTrue()); | 94 CHECK(script->Run()->IsTrue()); |
| 95 | 95 |
| 96 turn = DONE; | 96 turn = DONE; |
| 97 } | 97 } |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 | 100 |
| 101 class ThreadB: public v8::internal::Thread { | 101 class ThreadB: public v8::internal::Thread { |
| 102 public: | 102 public: |
| 103 explicit ThreadB(i::Isolate* isolate) : Thread(isolate) { } | 103 explicit ThreadB(i::Isolate* isolate) : Thread(isolate, "ThreadB") { } |
| 104 void Run() { | 104 void Run() { |
| 105 do { | 105 do { |
| 106 { | 106 { |
| 107 v8::Locker locker; | 107 v8::Locker locker; |
| 108 if (turn == CLEAN_CACHE) { | 108 if (turn == CLEAN_CACHE) { |
| 109 v8::HandleScope scope; | 109 v8::HandleScope scope; |
| 110 v8::Context::Scope context_scope(v8::Context::New()); | 110 v8::Context::Scope context_scope(v8::Context::New()); |
| 111 | 111 |
| 112 // Clear the caches by forcing major GC. | 112 // Clear the caches by forcing major GC. |
| 113 HEAP->CollectAllGarbage(false); | 113 HEAP->CollectAllGarbage(false); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 129 ThreadB threadB(i::Isolate::Current()); | 129 ThreadB threadB(i::Isolate::Current()); |
| 130 | 130 |
| 131 threadA.Start(); | 131 threadA.Start(); |
| 132 threadB.Start(); | 132 threadB.Start(); |
| 133 | 133 |
| 134 threadA.Join(); | 134 threadA.Join(); |
| 135 threadB.Join(); | 135 threadB.Join(); |
| 136 | 136 |
| 137 CHECK_EQ(DONE, turn); | 137 CHECK_EQ(DONE, turn); |
| 138 } | 138 } |
| OLD | NEW |