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

Side by Side Diff: src/crankshaft-thread.h

Issue 10417010: Run Crankshaft on a separate thread. (Closed) Base URL: https://chromiumcodereview.appspot.com/10387157
Patch Set: Created 8 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 // Flags: --allow-natives-syntax 28 #ifndef CRANKSHAFT_THREAD_H_
danno 2012/05/22 10:32:19 crankshaft -> concurrent_compiler
29 #define CRANKSHAFT_THREAD_H_
29 30
30 // An exception thrown in a function optimized by on-stack replacement (OSR) 31 #include "v8.h"
31 // should be able to construct a receiver from all optimized stack frames. 32 #include "atomicops.h"
33 #include "isolate.h"
34 #include "objects.h"
35 #include "platform.h"
36 #include "unbound-queue.h"
32 37
33 function A() { } 38 namespace v8 {
34 A.prototype.f = function() { } 39 namespace internal {
35 40
36 function B() { } 41 class CrankshaftThread {
danno 2012/05/22 10:32:19 This isn't a thread, is it? Perhaps ConcurrentComp
42 public:
43 static void StartThread();
44 static void StopThread();
danno 2012/05/22 10:32:19 The above methods should be on the isolate, it see
45 static void AddJob(i::Isolate *isolate, i::Handle<JSFunction> function);
danno 2012/05/22 10:32:19 How about QueueFunctionToCompile instead of AddJob
37 46
38 var o = new A(); 47 private:
48 struct WorkElement {
danno 2012/05/22 10:32:19 Perhaps "PendingCompilation" is more descriptive?
49 i::Handle<JSFunction> function;
50 i::Isolate* isolate;
51 bool dummy;
danno 2012/05/22 10:32:19 Instead of having the explicit dummy field, why no
52 WorkElement() : isolate(NULL), dummy(false) { }
53 };
54 typedef UnboundQueue<WorkElement> WorkQueue;
danno 2012/05/22 10:32:19 CompilationQueue
39 55
40 // This function throws if o does not have an f property, and should not be 56 class WorkerThread : public Thread {
danno 2012/05/22 10:32:19 CompilerThread
41 // inlined. 57 public:
42 function g() { try { return o.f(); } finally { }} 58 explicit WorkerThread(const Options &o) : Thread(o), stop_loop_(false) {
59 queue_semaphore_ = OS::CreateSemaphore(0);
danno 2012/05/22 10:32:19 Where does this get disposed?
60 loop_lock_ = OS::CreateMutex();
61 queue_lock_ = OS::CreateMutex();
danno 2012/05/22 10:32:19 Where to loop_lock_ and queue_lock_ get disposed?
sanjoy 2012/05/22 11:38:55 They don't. Will fix this in the next iteration.
62 #ifdef DEBUG
63 functions_compiled_ = 0;
64 #endif
65 }
43 66
44 // Optimization status (see runtime.cc): 67 void Run();
45 // 1 - yes, 2 - no, 3 - always, 4 - never. 68 void StopThread();
69 void AddElement(const WorkElement &);
danno 2012/05/22 10:32:19 QueuePendingCompilation
46 70
47 // This function should be optimized via OSR. 71 private:
48 function h() { 72 WorkQueue work_queue_;
danno 2012/05/22 10:32:19 compilation_queue_
49 var optstatus = %GetOptimizationStatus(h); 73 Semaphore* queue_semaphore_;
50 if (optstatus == 4) { 74 Mutex* loop_lock_, *queue_lock_;
51 // Optimizations are globally disabled; just run once. 75 volatile AtomicWord stop_loop_, isolate_;
52 g();
53 } else {
54 // Run for a bit as long as h is unoptimized.
55 while (%GetOptimizationStatus(h) == 2) {
56 for (var j = 0; j < 100; j++) g();
57 }
58 g();
59 }
60 }
61 76
62 h(); 77 #ifdef DEBUG
63 o = new B(); 78 int functions_compiled_;
64 assertThrows("h()"); 79 #endif
80
81 friend class CrankshaftThread;
82 };
83
84 static WorkerThread *worker_instance_;
85
86 DISALLOW_IMPLICIT_CONSTRUCTORS(CrankshaftThread);
87 };
danno 2012/05/22 10:32:19 nit: add line break
88 } }
89
90 #endif // CRANKSHAFT_THREAD_H_
91
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698