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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
| 28 // TODO(dcarney): remove |
| 29 #define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT |
| 30 #define V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW |
| 31 |
28 #include "v8.h" | 32 #include "v8.h" |
29 | 33 |
30 #include "platform.h" | 34 #include "platform.h" |
31 #include "isolate.h" | 35 #include "isolate.h" |
32 | 36 |
33 #include "cctest.h" | 37 #include "cctest.h" |
34 | 38 |
35 | 39 |
36 TEST(Preemption) { | 40 TEST(Preemption) { |
37 v8::Locker locker(CcTest::default_isolate()); | 41 v8::Isolate* isolate = CcTest::default_isolate(); |
| 42 v8::Locker locker(isolate); |
38 v8::V8::Initialize(); | 43 v8::V8::Initialize(); |
39 v8::HandleScope scope(CcTest::default_isolate()); | 44 v8::HandleScope scope(isolate); |
40 v8::Context::Scope context_scope(v8::Context::New()); | 45 v8::Handle<v8::Context> context = v8::Context::New(isolate); |
| 46 v8::Context::Scope context_scope(context); |
41 | 47 |
42 v8::Locker::StartPreemption(100); | 48 v8::Locker::StartPreemption(100); |
43 | 49 |
44 v8::Handle<v8::Script> script = v8::Script::Compile( | 50 v8::Handle<v8::Script> script = v8::Script::Compile( |
45 v8::String::New("var count = 0; var obj = new Object(); count++;\n")); | 51 v8::String::New("var count = 0; var obj = new Object(); count++;\n")); |
46 | 52 |
47 script->Run(); | 53 script->Run(); |
48 | 54 |
49 v8::Locker::StopPreemption(); | 55 v8::Locker::StopPreemption(); |
50 v8::internal::OS::Sleep(500); // Make sure the timer fires. | 56 v8::internal::OS::Sleep(500); // Make sure the timer fires. |
51 | 57 |
52 script->Run(); | 58 script->Run(); |
53 } | 59 } |
54 | 60 |
55 | 61 |
56 enum Turn { | 62 enum Turn { |
57 FILL_CACHE, | 63 FILL_CACHE, |
58 CLEAN_CACHE, | 64 CLEAN_CACHE, |
59 SECOND_TIME_FILL_CACHE, | 65 SECOND_TIME_FILL_CACHE, |
60 DONE | 66 DONE |
61 }; | 67 }; |
62 | 68 |
63 static Turn turn = FILL_CACHE; | 69 static Turn turn = FILL_CACHE; |
64 | 70 |
65 | 71 |
66 class ThreadA : public v8::internal::Thread { | 72 class ThreadA : public v8::internal::Thread { |
67 public: | 73 public: |
68 ThreadA() : Thread("ThreadA") { } | 74 ThreadA() : Thread("ThreadA") { } |
69 void Run() { | 75 void Run() { |
70 v8::Locker locker(CcTest::default_isolate()); | 76 v8::Isolate* isolate = CcTest::default_isolate(); |
71 v8::HandleScope scope(CcTest::default_isolate()); | 77 v8::Locker locker(isolate); |
72 v8::Context::Scope context_scope(v8::Context::New()); | 78 v8::HandleScope scope(isolate); |
| 79 v8::Handle<v8::Context> context = v8::Context::New(isolate); |
| 80 v8::Context::Scope context_scope(context); |
73 | 81 |
74 CHECK_EQ(FILL_CACHE, turn); | 82 CHECK_EQ(FILL_CACHE, turn); |
75 | 83 |
76 // Fill String.search cache. | 84 // Fill String.search cache. |
77 v8::Handle<v8::Script> script = v8::Script::Compile( | 85 v8::Handle<v8::Script> script = v8::Script::Compile( |
78 v8::String::New( | 86 v8::String::New( |
79 "for (var i = 0; i < 3; i++) {" | 87 "for (var i = 0; i < 3; i++) {" |
80 " var result = \"a\".search(\"a\");" | 88 " var result = \"a\".search(\"a\");" |
81 " if (result != 0) throw \"result: \" + result + \" @\" + i;" | 89 " if (result != 0) throw \"result: \" + result + \" @\" + i;" |
82 "};" | 90 "};" |
(...skipping 15 matching lines...) Expand all Loading... |
98 } | 106 } |
99 }; | 107 }; |
100 | 108 |
101 | 109 |
102 class ThreadB : public v8::internal::Thread { | 110 class ThreadB : public v8::internal::Thread { |
103 public: | 111 public: |
104 ThreadB() : Thread("ThreadB") { } | 112 ThreadB() : Thread("ThreadB") { } |
105 void Run() { | 113 void Run() { |
106 do { | 114 do { |
107 { | 115 { |
108 v8::Locker locker(CcTest::default_isolate()); | 116 v8::Isolate* isolate = CcTest::default_isolate(); |
| 117 v8::Locker locker(isolate); |
109 if (turn == CLEAN_CACHE) { | 118 if (turn == CLEAN_CACHE) { |
110 v8::HandleScope scope(CcTest::default_isolate()); | 119 v8::HandleScope scope(isolate); |
111 v8::Context::Scope context_scope(v8::Context::New()); | 120 v8::Handle<v8::Context> context = v8::Context::New(isolate); |
| 121 v8::Context::Scope context_scope(context); |
112 | 122 |
113 // Clear the caches by forcing major GC. | 123 // Clear the caches by forcing major GC. |
114 HEAP->CollectAllGarbage(v8::internal::Heap::kNoGCFlags); | 124 HEAP->CollectAllGarbage(v8::internal::Heap::kNoGCFlags); |
115 turn = SECOND_TIME_FILL_CACHE; | 125 turn = SECOND_TIME_FILL_CACHE; |
116 break; | 126 break; |
117 } | 127 } |
118 } | 128 } |
119 | 129 |
120 Thread::YieldCPU(); | 130 Thread::YieldCPU(); |
121 } while (true); | 131 } while (true); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 Join(); | 209 Join(); |
200 } | 210 } |
201 }; | 211 }; |
202 | 212 |
203 | 213 |
204 TEST(ThreadJoinSelf) { | 214 TEST(ThreadJoinSelf) { |
205 ThreadC thread; | 215 ThreadC thread; |
206 thread.Start(); | 216 thread.Start(); |
207 thread.Join(); | 217 thread.Join(); |
208 } | 218 } |
OLD | NEW |