Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: test/cctest/test-threads.cc

Issue 1780001: Clean JS function results cache on each major GC. (Closed)
Patch Set: Reoworking the test Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 v8::Handle<v8::Script> script = v8::Script::Compile( 43 v8::Handle<v8::Script> script = v8::Script::Compile(
44 v8::String::New("var count = 0; var obj = new Object(); count++;\n")); 44 v8::String::New("var count = 0; var obj = new Object(); count++;\n"));
45 45
46 script->Run(); 46 script->Run();
47 47
48 v8::Locker::StopPreemption(); 48 v8::Locker::StopPreemption();
49 v8::internal::OS::Sleep(500); // Make sure the timer fires. 49 v8::internal::OS::Sleep(500); // Make sure the timer fires.
50 50
51 script->Run(); 51 script->Run();
52 } 52 }
53
54
55 enum Turn {
56 FILL_CACHE,
57 CLEAN_CACHE,
58 SECOND_TIME_FILL_CACHE,
59 DONE
60 };
61
62 static Turn turn = FILL_CACHE;
63
64
65 class ThreadA: public v8::internal::Thread {
66 public:
67 void Run() {
68 v8::Locker locker;
69 v8::HandleScope scope;
70 v8::Context::Scope context_scope(v8::Context::New());
71
72 CHECK_EQ(FILL_CACHE, turn);
73
74 // Fill String.search cache.
75 v8::Handle<v8::Script> script = v8::Script::Compile(
76 v8::String::New(
77 "for (var i = 0; i < 3; i++) {"
78 " var result = \"a\".search(\"a\");"
79 " if (result != 0) throw \"result: \" + result + \" @\" + i;"
80 "};"
81 "true"));
82 CHECK(script->Run()->IsTrue());
83
84 turn = CLEAN_CACHE;
85 do {
86 {
87 v8::Unlocker unlocker;
88 Thread::YieldCPU();
89 }
90 } while (turn != SECOND_TIME_FILL_CACHE);
91
92 // Rerun the script.
93 CHECK(script->Run()->IsTrue());
94
95 turn = DONE;
96 }
97 };
98
99
100 class ThreadB: public v8::internal::Thread {
101 public:
102 void Run() {
103 do {
104 {
105 v8::Locker locker;
106 if (turn == CLEAN_CACHE) {
107 v8::HandleScope scope;
108 v8::Context::Scope context_scope(v8::Context::New());
109
110 // Clear the caches by forcing major GC.
111 v8::internal::Heap::CollectAllGarbage(false);
112 turn = SECOND_TIME_FILL_CACHE;
113 break;
114 }
115 }
116
117 Thread::YieldCPU();
118 } while (true);
119 }
120 };
121
122
123 TEST(JSFunctionResultCachesInTwoThreads) {
124 v8::V8::Initialize();
125
126 ThreadA threadA;
127 ThreadB threadB;
128
129 threadA.Start();
130 threadB.Start();
131
132 threadA.Join();
133 threadB.Join();
134
135 CHECK_EQ(DONE, turn);
136 }
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698