2012-01-11 14:42:58 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-10-21 09:12:27 +00:00
|
|
|
|
|
|
|
#ifndef V8_D8_H_
|
|
|
|
#define V8_D8_H_
|
|
|
|
|
2017-02-04 00:43:36 +00:00
|
|
|
#include <iterator>
|
2017-05-10 16:18:55 +00:00
|
|
|
#include <map>
|
2017-01-27 20:15:37 +00:00
|
|
|
#include <memory>
|
2016-09-20 23:38:58 +00:00
|
|
|
#include <string>
|
2017-01-27 20:15:37 +00:00
|
|
|
#include <vector>
|
2016-09-20 23:38:58 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/allocation.h"
|
2016-06-09 17:58:10 +00:00
|
|
|
#include "src/base/hashmap.h"
|
2015-08-12 07:32:36 +00:00
|
|
|
#include "src/base/platform/time.h"
|
2015-06-22 17:12:26 +00:00
|
|
|
#include "src/list.h"
|
2017-01-11 12:18:48 +00:00
|
|
|
#include "src/utils.h"
|
2008-10-21 09:12:27 +00:00
|
|
|
|
2015-07-14 23:04:18 +00:00
|
|
|
#include "src/base/once.h"
|
|
|
|
|
|
|
|
|
2008-10-21 09:12:27 +00:00
|
|
|
namespace v8 {
|
|
|
|
|
|
|
|
|
2008-12-03 09:35:21 +00:00
|
|
|
// A single counter in a counter collection.
|
2008-10-21 09:12:27 +00:00
|
|
|
class Counter {
|
|
|
|
public:
|
2008-12-03 09:35:21 +00:00
|
|
|
static const int kMaxNameSize = 64;
|
2009-04-14 00:30:44 +00:00
|
|
|
int32_t* Bind(const char* name, bool histogram);
|
|
|
|
int32_t* ptr() { return &count_; }
|
|
|
|
int32_t count() { return count_; }
|
|
|
|
int32_t sample_total() { return sample_total_; }
|
|
|
|
bool is_histogram() { return is_histogram_; }
|
|
|
|
void AddSample(int32_t sample);
|
2008-10-21 09:12:27 +00:00
|
|
|
private:
|
2009-04-14 00:30:44 +00:00
|
|
|
int32_t count_;
|
|
|
|
int32_t sample_total_;
|
|
|
|
bool is_histogram_;
|
2008-12-03 09:35:21 +00:00
|
|
|
uint8_t name_[kMaxNameSize];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A set of counters and associated information. An instance of this
|
|
|
|
// class is stored directly in the memory-mapped counters file if
|
|
|
|
// the --map-counters options is used
|
|
|
|
class CounterCollection {
|
|
|
|
public:
|
|
|
|
CounterCollection();
|
|
|
|
Counter* GetNextCounter();
|
|
|
|
private:
|
2012-07-13 12:22:09 +00:00
|
|
|
static const unsigned kMaxCounters = 512;
|
2008-12-03 09:35:21 +00:00
|
|
|
uint32_t magic_number_;
|
|
|
|
uint32_t max_counters_;
|
|
|
|
uint32_t max_name_size_;
|
|
|
|
uint32_t counters_in_use_;
|
|
|
|
Counter counters_[kMaxCounters];
|
2008-10-21 09:12:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-03-24 13:33:54 +00:00
|
|
|
class CounterMap {
|
|
|
|
public:
|
|
|
|
CounterMap(): hash_map_(Match) { }
|
|
|
|
Counter* Lookup(const char* name) {
|
2016-06-09 17:58:10 +00:00
|
|
|
base::HashMap::Entry* answer =
|
2015-04-13 19:01:15 +00:00
|
|
|
hash_map_.Lookup(const_cast<char*>(name), Hash(name));
|
2009-03-24 13:33:54 +00:00
|
|
|
if (!answer) return NULL;
|
|
|
|
return reinterpret_cast<Counter*>(answer->value);
|
|
|
|
}
|
|
|
|
void Set(const char* name, Counter* value) {
|
2016-06-09 17:58:10 +00:00
|
|
|
base::HashMap::Entry* answer =
|
2015-04-13 19:01:15 +00:00
|
|
|
hash_map_.LookupOrInsert(const_cast<char*>(name), Hash(name));
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(answer != NULL);
|
2009-03-24 13:33:54 +00:00
|
|
|
answer->value = value;
|
|
|
|
}
|
|
|
|
class Iterator {
|
|
|
|
public:
|
2009-03-24 14:29:49 +00:00
|
|
|
explicit Iterator(CounterMap* map)
|
|
|
|
: map_(&map->hash_map_), entry_(map_->Start()) { }
|
2009-03-24 13:33:54 +00:00
|
|
|
void Next() { entry_ = map_->Next(entry_); }
|
|
|
|
bool More() { return entry_ != NULL; }
|
|
|
|
const char* CurrentKey() { return static_cast<const char*>(entry_->key); }
|
|
|
|
Counter* CurrentValue() { return static_cast<Counter*>(entry_->value); }
|
|
|
|
private:
|
2016-09-30 16:16:47 +00:00
|
|
|
base::CustomMatcherHashMap* map_;
|
|
|
|
base::CustomMatcherHashMap::Entry* entry_;
|
2009-03-24 13:33:54 +00:00
|
|
|
};
|
2011-06-07 07:17:46 +00:00
|
|
|
|
2009-03-24 13:33:54 +00:00
|
|
|
private:
|
|
|
|
static int Hash(const char* name);
|
|
|
|
static bool Match(void* key1, void* key2);
|
2016-09-30 16:16:47 +00:00
|
|
|
base::CustomMatcherHashMap hash_map_;
|
2009-03-24 13:33:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-07-11 07:38:09 +00:00
|
|
|
class SourceGroup {
|
|
|
|
public:
|
2011-07-14 15:43:40 +00:00
|
|
|
SourceGroup() :
|
2013-09-02 12:26:06 +00:00
|
|
|
next_semaphore_(0),
|
|
|
|
done_semaphore_(0),
|
2011-09-08 22:44:03 +00:00
|
|
|
thread_(NULL),
|
2011-07-14 15:43:40 +00:00
|
|
|
argv_(NULL),
|
|
|
|
begin_offset_(0),
|
2011-09-08 13:51:06 +00:00
|
|
|
end_offset_(0) {}
|
2011-07-11 07:38:09 +00:00
|
|
|
|
2011-09-08 22:44:03 +00:00
|
|
|
~SourceGroup();
|
|
|
|
|
2011-07-11 07:38:09 +00:00
|
|
|
void Begin(char** argv, int offset) {
|
|
|
|
argv_ = const_cast<const char**>(argv);
|
|
|
|
begin_offset_ = offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void End(int offset) { end_offset_ = offset; }
|
|
|
|
|
2012-11-20 14:47:56 +00:00
|
|
|
void Execute(Isolate* isolate);
|
2011-07-11 07:38:09 +00:00
|
|
|
|
|
|
|
void StartExecuteInThread();
|
|
|
|
void WaitForThread();
|
2015-07-30 08:20:35 +00:00
|
|
|
void JoinThread();
|
2011-07-11 07:38:09 +00:00
|
|
|
|
|
|
|
private:
|
2014-06-30 13:25:46 +00:00
|
|
|
class IsolateThread : public base::Thread {
|
2011-07-11 07:38:09 +00:00
|
|
|
public:
|
|
|
|
explicit IsolateThread(SourceGroup* group)
|
2014-06-30 13:25:46 +00:00
|
|
|
: base::Thread(GetThreadOptions()), group_(group) {}
|
2011-07-11 07:38:09 +00:00
|
|
|
|
|
|
|
virtual void Run() {
|
|
|
|
group_->ExecuteInThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SourceGroup* group_;
|
|
|
|
};
|
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
static base::Thread::Options GetThreadOptions();
|
2011-07-11 07:38:09 +00:00
|
|
|
void ExecuteInThread();
|
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
base::Semaphore next_semaphore_;
|
|
|
|
base::Semaphore done_semaphore_;
|
|
|
|
base::Thread* thread_;
|
2011-07-11 07:38:09 +00:00
|
|
|
|
|
|
|
void ExitShell(int exit_code);
|
2015-07-20 07:05:42 +00:00
|
|
|
Local<String> ReadFile(Isolate* isolate, const char* name);
|
2011-07-11 07:38:09 +00:00
|
|
|
|
|
|
|
const char** argv_;
|
|
|
|
int begin_offset_;
|
|
|
|
int end_offset_;
|
|
|
|
};
|
|
|
|
|
2017-02-04 00:43:36 +00:00
|
|
|
// The backing store of an ArrayBuffer or SharedArrayBuffer, after
|
|
|
|
// Externalize() has been called on it.
|
|
|
|
class ExternalizedContents {
|
|
|
|
public:
|
|
|
|
explicit ExternalizedContents(const ArrayBuffer::Contents& contents)
|
|
|
|
: data_(contents.Data()), size_(contents.ByteLength()) {}
|
|
|
|
explicit ExternalizedContents(const SharedArrayBuffer::Contents& contents)
|
|
|
|
: data_(contents.Data()), size_(contents.ByteLength()) {}
|
|
|
|
ExternalizedContents(ExternalizedContents&& other)
|
|
|
|
: data_(other.data_), size_(other.size_) {
|
|
|
|
other.data_ = nullptr;
|
|
|
|
other.size_ = 0;
|
|
|
|
}
|
|
|
|
ExternalizedContents& operator=(ExternalizedContents&& other) {
|
|
|
|
if (this != &other) {
|
|
|
|
data_ = other.data_;
|
|
|
|
size_ = other.size_;
|
|
|
|
other.data_ = nullptr;
|
|
|
|
other.size_ = 0;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
~ExternalizedContents();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void* data_;
|
|
|
|
size_t size_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ExternalizedContents);
|
|
|
|
};
|
2015-06-22 17:12:26 +00:00
|
|
|
|
|
|
|
class SerializationData {
|
|
|
|
public:
|
2017-02-04 00:43:36 +00:00
|
|
|
SerializationData() : size_(0) {}
|
2015-06-22 17:12:26 +00:00
|
|
|
|
2017-01-27 20:15:37 +00:00
|
|
|
uint8_t* data() { return data_.get(); }
|
|
|
|
size_t size() { return size_; }
|
|
|
|
const std::vector<ArrayBuffer::Contents>& array_buffer_contents() {
|
|
|
|
return array_buffer_contents_;
|
2015-06-22 17:12:26 +00:00
|
|
|
}
|
2017-01-27 20:15:37 +00:00
|
|
|
const std::vector<SharedArrayBuffer::Contents>&
|
|
|
|
shared_array_buffer_contents() {
|
|
|
|
return shared_array_buffer_contents_;
|
2015-06-22 17:12:26 +00:00
|
|
|
}
|
|
|
|
|
2017-02-04 00:43:36 +00:00
|
|
|
void AppendExternalizedContentsTo(std::vector<ExternalizedContents>* to) {
|
|
|
|
to->insert(to->end(),
|
|
|
|
std::make_move_iterator(externalized_contents_.begin()),
|
|
|
|
std::make_move_iterator(externalized_contents_.end()));
|
|
|
|
externalized_contents_.clear();
|
|
|
|
}
|
2017-01-27 20:15:37 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct DataDeleter {
|
|
|
|
void operator()(uint8_t* p) const { free(p); }
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unique_ptr<uint8_t, DataDeleter> data_;
|
|
|
|
size_t size_;
|
|
|
|
std::vector<ArrayBuffer::Contents> array_buffer_contents_;
|
|
|
|
std::vector<SharedArrayBuffer::Contents> shared_array_buffer_contents_;
|
2017-02-04 00:43:36 +00:00
|
|
|
std::vector<ExternalizedContents> externalized_contents_;
|
2017-01-27 20:15:37 +00:00
|
|
|
|
2015-06-22 17:12:26 +00:00
|
|
|
private:
|
2017-01-27 20:15:37 +00:00
|
|
|
friend class Serializer;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(SerializationData);
|
2015-06-22 17:12:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SerializationDataQueue {
|
|
|
|
public:
|
2017-01-27 20:15:37 +00:00
|
|
|
void Enqueue(std::unique_ptr<SerializationData> data);
|
|
|
|
bool Dequeue(std::unique_ptr<SerializationData>* data);
|
2015-06-22 17:12:26 +00:00
|
|
|
bool IsEmpty();
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
private:
|
|
|
|
base::Mutex mutex_;
|
2017-01-27 20:15:37 +00:00
|
|
|
std::vector<std::unique_ptr<SerializationData>> data_;
|
2015-06-22 17:12:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Worker {
|
|
|
|
public:
|
|
|
|
Worker();
|
|
|
|
~Worker();
|
|
|
|
|
2015-07-30 08:19:29 +00:00
|
|
|
// Run the given script on this Worker. This function should only be called
|
|
|
|
// once, and should only be called by the thread that created the Worker.
|
|
|
|
void StartExecuteInThread(const char* script);
|
2015-07-13 21:04:55 +00:00
|
|
|
// Post a message to the worker's incoming message queue. The worker will
|
|
|
|
// take ownership of the SerializationData.
|
2015-07-30 08:19:29 +00:00
|
|
|
// This function should only be called by the thread that created the Worker.
|
2017-01-27 20:15:37 +00:00
|
|
|
void PostMessage(std::unique_ptr<SerializationData> data);
|
2015-07-13 21:04:55 +00:00
|
|
|
// Synchronously retrieve messages from the worker's outgoing message queue.
|
|
|
|
// If there is no message in the queue, block until a message is available.
|
|
|
|
// If there are no messages in the queue and the worker is no longer running,
|
|
|
|
// return nullptr.
|
2015-07-30 08:19:29 +00:00
|
|
|
// This function should only be called by the thread that created the Worker.
|
2017-01-27 20:15:37 +00:00
|
|
|
std::unique_ptr<SerializationData> GetMessage();
|
2015-07-13 21:04:55 +00:00
|
|
|
// Terminate the worker's event loop. Messages from the worker that have been
|
|
|
|
// queued can still be read via GetMessage().
|
2015-07-30 08:19:29 +00:00
|
|
|
// This function can be called by any thread.
|
2015-06-22 17:12:26 +00:00
|
|
|
void Terminate();
|
2015-07-13 21:04:55 +00:00
|
|
|
// Terminate and join the thread.
|
2015-07-30 08:19:29 +00:00
|
|
|
// This function can be called by any thread.
|
2015-07-13 21:04:55 +00:00
|
|
|
void WaitForThread();
|
2015-06-22 17:12:26 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
class WorkerThread : public base::Thread {
|
|
|
|
public:
|
|
|
|
explicit WorkerThread(Worker* worker)
|
|
|
|
: base::Thread(base::Thread::Options("WorkerThread")),
|
|
|
|
worker_(worker) {}
|
|
|
|
|
|
|
|
virtual void Run() { worker_->ExecuteInThread(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Worker* worker_;
|
|
|
|
};
|
|
|
|
|
|
|
|
void ExecuteInThread();
|
|
|
|
static void PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
|
|
|
|
base::Semaphore in_semaphore_;
|
|
|
|
base::Semaphore out_semaphore_;
|
|
|
|
SerializationDataQueue in_queue_;
|
|
|
|
SerializationDataQueue out_queue_;
|
|
|
|
base::Thread* thread_;
|
|
|
|
char* script_;
|
2015-07-30 08:19:29 +00:00
|
|
|
base::Atomic32 running_;
|
2015-06-22 17:12:26 +00:00
|
|
|
};
|
|
|
|
|
2011-07-11 07:38:09 +00:00
|
|
|
class ShellOptions {
|
|
|
|
public:
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
ShellOptions()
|
|
|
|
: script_executed(false),
|
|
|
|
send_idle_notification(false),
|
|
|
|
invoke_weak_callbacks(false),
|
2015-04-22 12:24:29 +00:00
|
|
|
omit_quit(false),
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
stress_opt(false),
|
|
|
|
stress_deopt(false),
|
2015-07-30 08:20:35 +00:00
|
|
|
stress_runs(1),
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
interactive_shell(false),
|
|
|
|
test_shell(false),
|
|
|
|
expected_to_throw(false),
|
|
|
|
mock_arraybuffer_allocator(false),
|
2016-10-21 06:37:29 +00:00
|
|
|
enable_inspector(false),
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
num_isolates(1),
|
|
|
|
compile_options(v8::ScriptCompiler::kNoCompileOptions),
|
|
|
|
isolate_sources(NULL),
|
|
|
|
icu_data_file(NULL),
|
|
|
|
natives_blob(NULL),
|
2016-07-27 16:21:09 +00:00
|
|
|
snapshot_blob(NULL),
|
2016-08-10 17:10:51 +00:00
|
|
|
trace_enabled(false),
|
2017-02-15 10:16:44 +00:00
|
|
|
trace_config(NULL),
|
2017-05-05 16:00:27 +00:00
|
|
|
lcov_file(NULL),
|
|
|
|
disable_in_process_stack_traces(false) {}
|
2011-07-14 15:43:40 +00:00
|
|
|
|
2011-09-13 13:16:13 +00:00
|
|
|
~ShellOptions() {
|
|
|
|
delete[] isolate_sources;
|
|
|
|
}
|
2011-09-13 09:31:41 +00:00
|
|
|
|
2014-05-27 07:19:32 +00:00
|
|
|
bool use_interactive_shell() {
|
|
|
|
return (interactive_shell || !script_executed) && !test_shell;
|
|
|
|
}
|
|
|
|
|
2011-07-11 07:38:09 +00:00
|
|
|
bool script_executed;
|
2012-08-20 13:19:52 +00:00
|
|
|
bool send_idle_notification;
|
2014-05-27 15:16:42 +00:00
|
|
|
bool invoke_weak_callbacks;
|
2015-04-22 12:24:29 +00:00
|
|
|
bool omit_quit;
|
2011-07-11 07:38:09 +00:00
|
|
|
bool stress_opt;
|
|
|
|
bool stress_deopt;
|
2015-07-30 08:20:35 +00:00
|
|
|
int stress_runs;
|
2011-07-11 07:38:09 +00:00
|
|
|
bool interactive_shell;
|
|
|
|
bool test_shell;
|
2013-10-04 16:21:23 +00:00
|
|
|
bool expected_to_throw;
|
2013-11-18 14:50:45 +00:00
|
|
|
bool mock_arraybuffer_allocator;
|
2016-10-21 06:37:29 +00:00
|
|
|
bool enable_inspector;
|
2011-07-11 07:38:09 +00:00
|
|
|
int num_isolates;
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
v8::ScriptCompiler::CompileOptions compile_options;
|
2011-07-11 07:38:09 +00:00
|
|
|
SourceGroup* isolate_sources;
|
2014-03-25 12:05:33 +00:00
|
|
|
const char* icu_data_file;
|
2014-06-23 13:52:17 +00:00
|
|
|
const char* natives_blob;
|
|
|
|
const char* snapshot_blob;
|
2016-07-27 16:21:09 +00:00
|
|
|
bool trace_enabled;
|
|
|
|
const char* trace_config;
|
2017-02-15 10:16:44 +00:00
|
|
|
const char* lcov_file;
|
2017-05-05 16:00:27 +00:00
|
|
|
bool disable_in_process_stack_traces;
|
2011-07-11 07:38:09 +00:00
|
|
|
};
|
|
|
|
|
2011-07-14 15:43:40 +00:00
|
|
|
class Shell : public i::AllStatic {
|
2008-10-21 09:12:27 +00:00
|
|
|
public:
|
2015-07-20 07:05:42 +00:00
|
|
|
static MaybeLocal<Script> CompileString(
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
Isolate* isolate, Local<String> source, Local<Value> name,
|
2016-09-16 21:47:14 +00:00
|
|
|
v8::ScriptCompiler::CompileOptions compile_options);
|
2015-07-20 07:05:42 +00:00
|
|
|
static bool ExecuteString(Isolate* isolate, Local<String> source,
|
|
|
|
Local<Value> name, bool print_result,
|
2016-09-20 23:38:58 +00:00
|
|
|
bool report_exceptions);
|
|
|
|
static bool ExecuteModule(Isolate* isolate, const char* file_name);
|
2013-03-15 12:06:53 +00:00
|
|
|
static void ReportException(Isolate* isolate, TryCatch* try_catch);
|
2015-07-20 07:05:42 +00:00
|
|
|
static Local<String> ReadFile(Isolate* isolate, const char* name);
|
2013-05-08 07:45:16 +00:00
|
|
|
static Local<Context> CreateEvaluationContext(Isolate* isolate);
|
2015-07-30 08:20:35 +00:00
|
|
|
static int RunMain(Isolate* isolate, int argc, char* argv[], bool last_run);
|
2011-07-14 15:43:40 +00:00
|
|
|
static int Main(int argc, char* argv[]);
|
2011-09-13 13:16:13 +00:00
|
|
|
static void Exit(int exit_code);
|
2014-11-21 09:53:04 +00:00
|
|
|
static void OnExit(Isolate* isolate);
|
2015-06-03 14:34:50 +00:00
|
|
|
static void CollectGarbage(Isolate* isolate);
|
2015-07-15 12:26:06 +00:00
|
|
|
static void EmptyMessageQueues(Isolate* isolate);
|
2017-05-10 16:18:55 +00:00
|
|
|
static void EnsureEventLoopInitialized(Isolate* isolate);
|
|
|
|
static void CompleteMessageLoop(Isolate* isolate);
|
2011-07-14 15:43:40 +00:00
|
|
|
|
2017-01-27 20:15:37 +00:00
|
|
|
static std::unique_ptr<SerializationData> SerializeValue(
|
|
|
|
Isolate* isolate, Local<Value> value, Local<Value> transfer);
|
|
|
|
static MaybeLocal<Value> DeserializeValue(
|
|
|
|
Isolate* isolate, std::unique_ptr<SerializationData> data);
|
2015-06-22 17:12:26 +00:00
|
|
|
static void CleanupWorkers();
|
2008-12-01 07:40:43 +00:00
|
|
|
static int* LookupCounter(const char* name);
|
2009-04-14 00:30:44 +00:00
|
|
|
static void* CreateHistogram(const char* name,
|
|
|
|
int min,
|
|
|
|
int max,
|
|
|
|
size_t buckets);
|
|
|
|
static void AddHistogramSample(void* histogram, int sample);
|
2014-07-07 07:19:46 +00:00
|
|
|
static void MapCounters(v8::Isolate* isolate, const char* name);
|
2011-07-14 15:43:40 +00:00
|
|
|
|
2014-01-10 12:07:29 +00:00
|
|
|
static void PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2013-10-24 11:59:09 +00:00
|
|
|
|
2013-06-05 12:36:33 +00:00
|
|
|
static void RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void RealmOwner(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2017-02-28 16:38:04 +00:00
|
|
|
static void RealmNavigate(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2016-05-27 18:47:05 +00:00
|
|
|
static void RealmCreateAllowCrossRealmAccess(
|
|
|
|
const v8::FunctionCallbackInfo<v8::Value>& args);
|
2013-06-05 12:36:33 +00:00
|
|
|
static void RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void RealmSwitch(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void RealmSharedGet(Local<String> property,
|
|
|
|
const PropertyCallbackInfo<Value>& info);
|
2013-04-22 11:29:52 +00:00
|
|
|
static void RealmSharedSet(Local<String> property,
|
|
|
|
Local<Value> value,
|
2013-06-05 12:36:33 +00:00
|
|
|
const PropertyCallbackInfo<void>& info);
|
|
|
|
|
|
|
|
static void Print(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2016-10-31 16:39:48 +00:00
|
|
|
static void PrintErr(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2013-06-05 12:36:33 +00:00
|
|
|
static void Write(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2017-05-10 16:18:55 +00:00
|
|
|
static void WaitUntilDone(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void NotifyDone(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2015-07-14 23:04:18 +00:00
|
|
|
static void QuitOnce(v8::FunctionCallbackInfo<v8::Value>* args);
|
2013-06-05 12:36:33 +00:00
|
|
|
static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Version(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Read(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2015-07-20 07:05:42 +00:00
|
|
|
static Local<String> ReadFromStdin(Isolate* isolate);
|
2013-06-05 12:36:33 +00:00
|
|
|
static void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate()));
|
2012-01-17 13:37:09 +00:00
|
|
|
}
|
2013-06-05 12:36:33 +00:00
|
|
|
static void Load(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2015-06-22 17:12:26 +00:00
|
|
|
static void WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void WorkerPostMessage(
|
|
|
|
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void WorkerGetMessage(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void WorkerTerminate(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2009-03-31 06:51:25 +00:00
|
|
|
// The OS object on the global object contains methods for performing
|
|
|
|
// operating system calls:
|
|
|
|
//
|
|
|
|
// os.system("program_name", ["arg1", "arg2", ...], timeout1, timeout2) will
|
|
|
|
// run the command, passing the arguments to the program. The standard output
|
|
|
|
// of the program will be picked up and returned as a multiline string. If
|
2009-03-27 13:50:26 +00:00
|
|
|
// timeout1 is present then it should be a number. -1 indicates no timeout
|
|
|
|
// and a positive number is used as a timeout in milliseconds that limits the
|
|
|
|
// time spent waiting between receiving output characters from the program.
|
|
|
|
// timeout2, if present, should be a number indicating the limit in
|
|
|
|
// milliseconds on the total running time of the program. Exceptions are
|
|
|
|
// thrown on timeouts or other errors or if the exit status of the program
|
|
|
|
// indicates an error.
|
2009-03-31 06:51:25 +00:00
|
|
|
//
|
|
|
|
// os.chdir(dir) changes directory to the given directory. Throws an
|
|
|
|
// exception/ on error.
|
|
|
|
//
|
|
|
|
// os.setenv(variable, value) sets an environment variable. Repeated calls to
|
|
|
|
// this method leak memory due to the API of setenv in the standard C library.
|
2009-03-31 12:45:33 +00:00
|
|
|
//
|
|
|
|
// os.umask(alue) calls the umask system call and returns the old umask.
|
|
|
|
//
|
|
|
|
// os.mkdirp(name, mask) creates a directory. The mask (if present) is anded
|
|
|
|
// with the current umask. Intermediate directories are created if necessary.
|
|
|
|
// An exception is not thrown if the directory already exists. Analogous to
|
|
|
|
// the "mkdir -p" command.
|
2013-06-05 12:36:33 +00:00
|
|
|
static void System(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void ChangeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2017-06-29 21:22:11 +00:00
|
|
|
static Local<Promise> HostImportModuleDynamically(Local<Context> context,
|
|
|
|
Local<String> referrer,
|
|
|
|
Local<String> specifier);
|
2017-04-11 09:33:11 +00:00
|
|
|
|
|
|
|
// Data is of type DynamicImportData*. We use void* here to be able
|
|
|
|
// to conform with MicrotaskCallback interface and enqueue this
|
|
|
|
// function in the microtask queue.
|
|
|
|
static void DoHostImportModuleDynamically(void* data);
|
2013-11-22 12:35:39 +00:00
|
|
|
static void AddOSMethods(v8::Isolate* isolate,
|
2015-07-20 07:05:42 +00:00
|
|
|
Local<ObjectTemplate> os_template);
|
2012-01-17 13:37:09 +00:00
|
|
|
|
2008-10-21 09:12:27 +00:00
|
|
|
static const char* kPrompt;
|
2011-07-11 07:38:09 +00:00
|
|
|
static ShellOptions options;
|
2015-06-22 17:12:26 +00:00
|
|
|
static ArrayBuffer::Allocator* array_buffer_allocator;
|
2011-07-11 07:38:09 +00:00
|
|
|
|
2017-05-10 16:18:55 +00:00
|
|
|
static void SetWaitUntilDone(Isolate* isolate, bool value);
|
|
|
|
static bool IsWaitUntilDone(Isolate* isolate);
|
|
|
|
|
2008-10-21 09:12:27 +00:00
|
|
|
private:
|
2015-07-20 07:05:42 +00:00
|
|
|
static Global<Context> evaluation_context_;
|
2015-07-14 23:04:18 +00:00
|
|
|
static base::OnceType quit_once_;
|
2016-03-31 10:16:43 +00:00
|
|
|
static Global<Function> stringify_function_;
|
2009-03-24 13:33:54 +00:00
|
|
|
static CounterMap* counter_map_;
|
2008-12-03 09:35:21 +00:00
|
|
|
// We statically allocate a set of local counters to be used if we
|
|
|
|
// don't want to store the stats in a memory-mapped file
|
|
|
|
static CounterCollection local_counters_;
|
|
|
|
static CounterCollection* counters_;
|
2014-06-30 13:25:46 +00:00
|
|
|
static base::OS::MemoryMappedFile* counters_file_;
|
2015-07-16 16:40:37 +00:00
|
|
|
static base::LazyMutex context_mutex_;
|
2014-06-30 13:25:46 +00:00
|
|
|
static const base::TimeTicks kInitialTicks;
|
2015-06-25 18:01:11 +00:00
|
|
|
|
2015-07-16 16:40:37 +00:00
|
|
|
static base::LazyMutex workers_mutex_;
|
2015-06-25 18:01:11 +00:00
|
|
|
static bool allow_new_workers_;
|
2015-06-22 17:12:26 +00:00
|
|
|
static i::List<Worker*> workers_;
|
2017-02-04 00:43:36 +00:00
|
|
|
static std::vector<ExternalizedContents> externalized_contents_;
|
2011-07-14 15:43:40 +00:00
|
|
|
|
2016-04-27 11:10:41 +00:00
|
|
|
static void WriteIgnitionDispatchCountersFile(v8::Isolate* isolate);
|
2017-02-15 10:16:44 +00:00
|
|
|
// Append LCOV coverage data to file.
|
|
|
|
static void WriteLcovData(v8::Isolate* isolate, const char* file);
|
2009-04-14 00:30:44 +00:00
|
|
|
static Counter* GetCounter(const char* name, bool is_histogram);
|
2016-03-31 10:16:43 +00:00
|
|
|
static Local<String> Stringify(Isolate* isolate, Local<Value> value);
|
2012-11-20 14:47:56 +00:00
|
|
|
static void Initialize(Isolate* isolate);
|
|
|
|
static void RunShell(Isolate* isolate);
|
2011-07-14 15:43:40 +00:00
|
|
|
static bool SetOptions(int argc, char* argv[]);
|
2015-07-20 07:05:42 +00:00
|
|
|
static Local<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate);
|
2016-05-27 18:47:05 +00:00
|
|
|
static MaybeLocal<Context> CreateRealm(
|
2017-02-28 16:38:04 +00:00
|
|
|
const v8::FunctionCallbackInfo<v8::Value>& args, int index,
|
|
|
|
v8::MaybeLocal<Value> global_object);
|
|
|
|
static void DisposeRealm(const v8::FunctionCallbackInfo<v8::Value>& args,
|
|
|
|
int index);
|
2016-10-11 19:22:03 +00:00
|
|
|
static MaybeLocal<Module> FetchModuleTree(v8::Local<v8::Context> context,
|
|
|
|
const std::string& file_name);
|
2017-05-10 16:18:55 +00:00
|
|
|
// We may have multiple isolates running concurrently, so the access to
|
|
|
|
// the isolate_status_ needs to be concurrency-safe.
|
|
|
|
static base::LazyMutex isolate_status_lock_;
|
|
|
|
static std::map<Isolate*, bool> isolate_status_;
|
2008-10-21 09:12:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
|
|
|
|
#endif // V8_D8_H_
|