| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 CLEAN_CACHE, | 58 CLEAN_CACHE, |
| 59 SECOND_TIME_FILL_CACHE, | 59 SECOND_TIME_FILL_CACHE, |
| 60 DONE | 60 DONE |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 static Turn turn = FILL_CACHE; | 63 static Turn turn = FILL_CACHE; |
| 64 | 64 |
| 65 | 65 |
| 66 class ThreadA: public v8::internal::Thread { | 66 class ThreadA: public v8::internal::Thread { |
| 67 public: | 67 public: |
| 68 explicit ThreadA(i::Isolate* isolate) : Thread(isolate, "ThreadA") { } | 68 ThreadA() : Thread("ThreadA") { } |
| 69 void Run() { | 69 void Run() { |
| 70 v8::Locker locker; | 70 v8::Locker locker; |
| 71 v8::HandleScope scope; | 71 v8::HandleScope scope; |
| 72 v8::Context::Scope context_scope(v8::Context::New()); | 72 v8::Context::Scope context_scope(v8::Context::New()); |
| 73 | 73 |
| 74 CHECK_EQ(FILL_CACHE, turn); | 74 CHECK_EQ(FILL_CACHE, turn); |
| 75 | 75 |
| 76 // Fill String.search cache. | 76 // Fill String.search cache. |
| 77 v8::Handle<v8::Script> script = v8::Script::Compile( | 77 v8::Handle<v8::Script> script = v8::Script::Compile( |
| 78 v8::String::New( | 78 v8::String::New( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 94 // Rerun the script. | 94 // Rerun the script. |
| 95 CHECK(script->Run()->IsTrue()); | 95 CHECK(script->Run()->IsTrue()); |
| 96 | 96 |
| 97 turn = DONE; | 97 turn = DONE; |
| 98 } | 98 } |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 | 101 |
| 102 class ThreadB: public v8::internal::Thread { | 102 class ThreadB: public v8::internal::Thread { |
| 103 public: | 103 public: |
| 104 explicit ThreadB(i::Isolate* isolate) : Thread(isolate, "ThreadB") { } | 104 ThreadB() : Thread("ThreadB") { } |
| 105 void Run() { | 105 void Run() { |
| 106 do { | 106 do { |
| 107 { | 107 { |
| 108 v8::Locker locker; | 108 v8::Locker locker; |
| 109 if (turn == CLEAN_CACHE) { | 109 if (turn == CLEAN_CACHE) { |
| 110 v8::HandleScope scope; | 110 v8::HandleScope scope; |
| 111 v8::Context::Scope context_scope(v8::Context::New()); | 111 v8::Context::Scope context_scope(v8::Context::New()); |
| 112 | 112 |
| 113 // Clear the caches by forcing major GC. | 113 // Clear the caches by forcing major GC. |
| 114 HEAP->CollectAllGarbage(false); | 114 HEAP->CollectAllGarbage(false); |
| 115 turn = SECOND_TIME_FILL_CACHE; | 115 turn = SECOND_TIME_FILL_CACHE; |
| 116 break; | 116 break; |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 Thread::YieldCPU(); | 120 Thread::YieldCPU(); |
| 121 } while (true); | 121 } while (true); |
| 122 } | 122 } |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 | 125 |
| 126 TEST(JSFunctionResultCachesInTwoThreads) { | 126 TEST(JSFunctionResultCachesInTwoThreads) { |
| 127 v8::V8::Initialize(); | 127 v8::V8::Initialize(); |
| 128 | 128 |
| 129 ThreadA threadA(i::Isolate::Current()); | 129 ThreadA threadA; |
| 130 ThreadB threadB(i::Isolate::Current()); | 130 ThreadB threadB; |
| 131 | 131 |
| 132 threadA.Start(); | 132 threadA.Start(); |
| 133 threadB.Start(); | 133 threadB.Start(); |
| 134 | 134 |
| 135 threadA.Join(); | 135 threadA.Join(); |
| 136 threadB.Join(); | 136 threadB.Join(); |
| 137 | 137 |
| 138 CHECK_EQ(DONE, turn); | 138 CHECK_EQ(DONE, turn); |
| 139 } | 139 } |
| 140 | 140 |
| 141 class ThreadIdValidationThread : public v8::internal::Thread { | 141 class ThreadIdValidationThread : public v8::internal::Thread { |
| 142 public: | 142 public: |
| 143 ThreadIdValidationThread(i::Thread* thread_to_start, | 143 ThreadIdValidationThread(i::Thread* thread_to_start, |
| 144 i::List<i::ThreadId>* refs, | 144 i::List<i::ThreadId>* refs, |
| 145 unsigned int thread_no, | 145 unsigned int thread_no, |
| 146 i::Semaphore* semaphore) | 146 i::Semaphore* semaphore) |
| 147 : Thread(NULL, "ThreadRefValidationThread"), | 147 : Thread("ThreadRefValidationThread"), |
| 148 refs_(refs), thread_no_(thread_no), thread_to_start_(thread_to_start), | 148 refs_(refs), thread_no_(thread_no), thread_to_start_(thread_to_start), |
| 149 semaphore_(semaphore) { | 149 semaphore_(semaphore) { |
| 150 } | 150 } |
| 151 | 151 |
| 152 void Run() { | 152 void Run() { |
| 153 i::ThreadId thread_id = i::ThreadId::Current(); | 153 i::ThreadId thread_id = i::ThreadId::Current(); |
| 154 for (int i = 0; i < thread_no_; i++) { | 154 for (int i = 0; i < thread_no_; i++) { |
| 155 CHECK(!(*refs_)[i].Equals(thread_id)); | 155 CHECK(!(*refs_)[i].Equals(thread_id)); |
| 156 } | 156 } |
| 157 CHECK(thread_id.IsValid()); | 157 CHECK(thread_id.IsValid()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 182 refs.Add(i::ThreadId::Invalid()); | 182 refs.Add(i::ThreadId::Invalid()); |
| 183 } | 183 } |
| 184 prev->Start(); | 184 prev->Start(); |
| 185 for (int i = 0; i < kNThreads; i++) { | 185 for (int i = 0; i < kNThreads; i++) { |
| 186 semaphore->Wait(); | 186 semaphore->Wait(); |
| 187 } | 187 } |
| 188 for (int i = 0; i < kNThreads; i++) { | 188 for (int i = 0; i < kNThreads; i++) { |
| 189 delete threads[i]; | 189 delete threads[i]; |
| 190 } | 190 } |
| 191 } | 191 } |
| OLD | NEW |