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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: src/crankshaft-thread.h
diff --git a/test/mjsunit/regress/regress-1118.js b/src/crankshaft-thread.h
similarity index 51%
copy from test/mjsunit/regress/regress-1118.js
copy to src/crankshaft-thread.h
index 7e0461db4d5da3c33a6c692ae50927e50a131903..1ed80b7e33fadefa22cfe76dde89e5a9571e2fd2 100644
--- a/test/mjsunit/regress/regress-1118.js
+++ b/src/crankshaft-thread.h
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -25,40 +25,67 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Flags: --allow-natives-syntax
+#ifndef CRANKSHAFT_THREAD_H_
danno 2012/05/22 10:32:19 crankshaft -> concurrent_compiler
+#define CRANKSHAFT_THREAD_H_
-// An exception thrown in a function optimized by on-stack replacement (OSR)
-// should be able to construct a receiver from all optimized stack frames.
+#include "v8.h"
+#include "atomicops.h"
+#include "isolate.h"
+#include "objects.h"
+#include "platform.h"
+#include "unbound-queue.h"
-function A() { }
-A.prototype.f = function() { }
+namespace v8 {
+namespace internal {
-function B() { }
+class CrankshaftThread {
danno 2012/05/22 10:32:19 This isn't a thread, is it? Perhaps ConcurrentComp
+ public:
+ static void StartThread();
+ static void StopThread();
danno 2012/05/22 10:32:19 The above methods should be on the isolate, it see
+ static void AddJob(i::Isolate *isolate, i::Handle<JSFunction> function);
danno 2012/05/22 10:32:19 How about QueueFunctionToCompile instead of AddJob
-var o = new A();
+ private:
+ struct WorkElement {
danno 2012/05/22 10:32:19 Perhaps "PendingCompilation" is more descriptive?
+ i::Handle<JSFunction> function;
+ i::Isolate* isolate;
+ bool dummy;
danno 2012/05/22 10:32:19 Instead of having the explicit dummy field, why no
+ WorkElement() : isolate(NULL), dummy(false) { }
+ };
+ typedef UnboundQueue<WorkElement> WorkQueue;
danno 2012/05/22 10:32:19 CompilationQueue
-// This function throws if o does not have an f property, and should not be
-// inlined.
-function g() { try { return o.f(); } finally { }}
+ class WorkerThread : public Thread {
danno 2012/05/22 10:32:19 CompilerThread
+ public:
+ explicit WorkerThread(const Options &o) : Thread(o), stop_loop_(false) {
+ queue_semaphore_ = OS::CreateSemaphore(0);
danno 2012/05/22 10:32:19 Where does this get disposed?
+ loop_lock_ = OS::CreateMutex();
+ 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.
+#ifdef DEBUG
+ functions_compiled_ = 0;
+#endif
+ }
-// Optimization status (see runtime.cc):
-// 1 - yes, 2 - no, 3 - always, 4 - never.
+ void Run();
+ void StopThread();
+ void AddElement(const WorkElement &);
danno 2012/05/22 10:32:19 QueuePendingCompilation
-// This function should be optimized via OSR.
-function h() {
- var optstatus = %GetOptimizationStatus(h);
- if (optstatus == 4) {
- // Optimizations are globally disabled; just run once.
- g();
- } else {
- // Run for a bit as long as h is unoptimized.
- while (%GetOptimizationStatus(h) == 2) {
- for (var j = 0; j < 100; j++) g();
- }
- g();
- }
-}
+ private:
+ WorkQueue work_queue_;
danno 2012/05/22 10:32:19 compilation_queue_
+ Semaphore* queue_semaphore_;
+ Mutex* loop_lock_, *queue_lock_;
+ volatile AtomicWord stop_loop_, isolate_;
+
+#ifdef DEBUG
+ int functions_compiled_;
+#endif
+
+ friend class CrankshaftThread;
+ };
+
+ static WorkerThread *worker_instance_;
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(CrankshaftThread);
+};
danno 2012/05/22 10:32:19 nit: add line break
+} }
+
+#endif // CRANKSHAFT_THREAD_H_
-h();
-o = new B();
-assertThrows("h()");

Powered by Google App Engine
This is Rietveld 408576698