Commit e8bf3142 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Introduces a light version of D8 that links against shared library.

Review URL: http://codereview.chromium.org/7351017

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8657 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d4779286
...@@ -773,6 +773,13 @@ PREPARSER_FLAGS = { ...@@ -773,6 +773,13 @@ PREPARSER_FLAGS = {
D8_FLAGS = { D8_FLAGS = {
'all': {
'library:shared': {
'CPPDEFINES': ['V8_SHARED'],
'LIBS': ['v8'],
'LIBPATH': ['.']
},
},
'gcc': { 'gcc': {
'all': { 'all': {
'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'], 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
...@@ -1370,7 +1377,11 @@ def BuildSpecific(env, mode, env_overrides, tools): ...@@ -1370,7 +1377,11 @@ def BuildSpecific(env, mode, env_overrides, tools):
d8_env = Environment(tools=tools) d8_env = Environment(tools=tools)
d8_env.Replace(**context.flags['d8']) d8_env.Replace(**context.flags['d8'])
context.ApplyEnvOverrides(d8_env) context.ApplyEnvOverrides(d8_env)
shell = d8_env.Program('d8' + suffix, object_files + shell_files) if context.options['library'] == 'static':
shell = d8_env.Program('d8' + suffix, object_files + shell_files)
else:
shell = d8_env.Program('d8' + suffix, shell_files)
d8_env.Depends(shell, library)
context.d8_targets.append(shell) context.d8_targets.append(shell)
for sample in context.samples: for sample in context.samples:
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
'type': 'none', 'type': 'none',
'dependencies': [ 'dependencies': [
'../samples/samples.gyp:*', '../samples/samples.gyp:*',
'../src/d8.gyp:*', '../src/d8.gyp:d8',
], ],
'conditions': [ 'conditions': [
[ 'component!="shared_library"', { [ 'component!="shared_library"', {
......
...@@ -243,7 +243,14 @@ PREPARSER_SOURCES = { ...@@ -243,7 +243,14 @@ PREPARSER_SOURCES = {
} }
D8_FILES = { D8_LIGHT_FILES = {
'all': [
'd8.cc'
]
}
D8_FULL_FILES = {
'all': [ 'all': [
'd8.cc', 'd8-debug.cc' 'd8.cc', 'd8-debug.cc'
], ],
...@@ -323,11 +330,15 @@ def ConfigureObjectFiles(): ...@@ -323,11 +330,15 @@ def ConfigureObjectFiles():
# Build the standard platform-independent source files. # Build the standard platform-independent source files.
source_files = context.GetRelevantSources(SOURCES) source_files = context.GetRelevantSources(SOURCES)
d8_files = context.GetRelevantSources(D8_FILES)
d8_js = env.JS2C('d8-js.cc', 'd8.js', **{'TYPE': 'D8', 'COMPRESSION': 'off'}) d8_js = env.JS2C('d8-js.cc', 'd8.js', **{'TYPE': 'D8', 'COMPRESSION': 'off'})
d8_js_obj = context.ConfigureObject(env, d8_js, CPPPATH=['.']) d8_js_obj = context.ConfigureObject(env, d8_js, CPPPATH=['.'])
d8_objs = [context.ConfigureObject(env, [d8_files]), d8_js_obj] if context.options['library'] == 'shared':
d8_files = context.GetRelevantSources(D8_LIGHT_FILES)
d8_objs = []
else:
d8_files = context.GetRelevantSources(D8_FULL_FILES)
d8_objs = [d8_js_obj]
d8_objs.append(context.ConfigureObject(env, [d8_files]))
# Combine the JavaScript library files into a single C++ file and # Combine the JavaScript library files into a single C++ file and
# compile it. # compile it.
......
This diff is collapsed.
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
'target_name': 'd8', 'target_name': 'd8',
'type': 'executable', 'type': 'executable',
'dependencies': [ 'dependencies': [
'd8_js2c#host',
'../tools/gyp/v8.gyp:v8', '../tools/gyp/v8.gyp:v8',
], ],
'include_dirs+': [ 'include_dirs+': [
...@@ -42,15 +41,24 @@ ...@@ -42,15 +41,24 @@
], ],
'sources': [ 'sources': [
'd8.cc', 'd8.cc',
'd8-debug.cc',
'<(SHARED_INTERMEDIATE_DIR)/d8-js.cc',
], ],
'conditions': [ 'conditions': [
[ 'OS=="linux" or OS=="mac" or OS=="freebsd" or OS=="openbsd" or OS=="solaris"', { [ 'component!="shared_library"', {
'sources': [ 'd8-posix.cc', ] 'dependencies': [ 'd8_js2c#host', ],
}], 'sources': [ 'd8-debug.cc', '<(SHARED_INTERMEDIATE_DIR)/d8-js.cc', ],
[ 'OS=="win"', { 'conditions': [
'sources': [ 'd8-windows.cc', ] [ 'console=="readline"', {
'libraries': [ '-lreadline', ],
'sources': [ 'd8-readline.cc' ],
}],
[ '(OS=="linux" or OS=="mac" or OS=="freebsd" \
or OS=="openbsd" or OS=="solaris")', {
'sources': [ 'd8-posix.cc', ]
}],
[ 'OS=="win"', {
'sources': [ 'd8-windows.cc', ]
}],
],
}], }],
], ],
}, },
......
...@@ -28,16 +28,23 @@ ...@@ -28,16 +28,23 @@
#ifndef V8_D8_H_ #ifndef V8_D8_H_
#define V8_D8_H_ #define V8_D8_H_
#include "allocation.h"
#ifndef USING_V8_SHARED
#include "v8.h" #include "v8.h"
#include "allocation.h"
#include "hashmap.h" #include "hashmap.h"
#else
#include "../include/v8.h"
#endif // USING_V8_SHARED
namespace v8 { namespace v8 {
#ifndef USING_V8_SHARED
namespace i = v8::internal; namespace i = v8::internal;
#endif // USING_V8_SHARED
#ifndef USING_V8_SHARED
// A single counter in a counter collection. // A single counter in a counter collection.
class Counter { class Counter {
public: public:
...@@ -110,17 +117,20 @@ class CounterMap { ...@@ -110,17 +117,20 @@ class CounterMap {
static bool Match(void* key1, void* key2); static bool Match(void* key1, void* key2);
i::HashMap hash_map_; i::HashMap hash_map_;
}; };
#endif // USING_V8_SHARED
class SourceGroup { class SourceGroup {
public: public:
SourceGroup() SourceGroup() :
: next_semaphore_(v8::internal::OS::CreateSemaphore(0)), #ifndef USING_V8_SHARED
done_semaphore_(v8::internal::OS::CreateSemaphore(0)), next_semaphore_(v8::internal::OS::CreateSemaphore(0)),
thread_(NULL), done_semaphore_(v8::internal::OS::CreateSemaphore(0)),
argv_(NULL), thread_(NULL),
begin_offset_(0), #endif // USING_V8_SHARED
end_offset_(0) { } argv_(NULL),
begin_offset_(0),
end_offset_(0) { }
void Begin(char** argv, int offset) { void Begin(char** argv, int offset) {
argv_ = const_cast<const char**>(argv); argv_ = const_cast<const char**>(argv);
...@@ -131,6 +141,7 @@ class SourceGroup { ...@@ -131,6 +141,7 @@ class SourceGroup {
void Execute(); void Execute();
#ifndef USING_V8_SHARED
void StartExecuteInThread(); void StartExecuteInThread();
void WaitForThread(); void WaitForThread();
...@@ -154,6 +165,7 @@ class SourceGroup { ...@@ -154,6 +165,7 @@ class SourceGroup {
i::Semaphore* next_semaphore_; i::Semaphore* next_semaphore_;
i::Semaphore* done_semaphore_; i::Semaphore* done_semaphore_;
i::Thread* thread_; i::Thread* thread_;
#endif // USING_V8_SHARED
void ExitShell(int exit_code); void ExitShell(int exit_code);
Handle<String> ReadFile(const char* name); Handle<String> ReadFile(const char* name);
...@@ -166,34 +178,41 @@ class SourceGroup { ...@@ -166,34 +178,41 @@ class SourceGroup {
class ShellOptions { class ShellOptions {
public: public:
ShellOptions() ShellOptions() :
: script_executed(false), #ifndef USING_V8_SHARED
last_run(true), use_preemption(true),
stress_opt(false), preemption_interval(10),
stress_deopt(false), parallel_files(NULL),
interactive_shell(false), #endif // USING_V8_SHARED
test_shell(false), script_executed(false),
use_preemption(true), last_run(true),
preemption_interval(10), stress_opt(false),
num_isolates(1), stress_deopt(false),
isolate_sources(NULL), interactive_shell(false),
parallel_files(NULL) { } test_shell(false),
num_isolates(1),
isolate_sources(NULL) { }
#ifndef USING_V8_SHARED
bool use_preemption;
int preemption_interval;
i::List< i::Vector<const char> >* parallel_files;
#endif // USING_V8_SHARED
bool script_executed; bool script_executed;
bool last_run; bool last_run;
bool stress_opt; bool stress_opt;
bool stress_deopt; bool stress_deopt;
bool interactive_shell; bool interactive_shell;
bool test_shell; bool test_shell;
bool use_preemption;
int preemption_interval;
int num_isolates; int num_isolates;
SourceGroup* isolate_sources; SourceGroup* isolate_sources;
i::List< i::Vector<const char> >* parallel_files;
}; };
#ifdef USING_V8_SHARED
class Shell: public i::AllStatic { class Shell {
#else
class Shell : public i::AllStatic {
#endif // USING_V8_SHARED
public: public:
static bool ExecuteString(Handle<String> source, static bool ExecuteString(Handle<String> source,
Handle<Value> name, Handle<Value> name,
...@@ -201,6 +220,14 @@ class Shell: public i::AllStatic { ...@@ -201,6 +220,14 @@ class Shell: public i::AllStatic {
bool report_exceptions); bool report_exceptions);
static const char* ToCString(const v8::String::Utf8Value& value); static const char* ToCString(const v8::String::Utf8Value& value);
static void ReportException(TryCatch* try_catch); static void ReportException(TryCatch* try_catch);
static Handle<String> ReadFile(const char* name);
static Persistent<Context> CreateEvaluationContext();
static int RunMain(int argc, char* argv[]);
static int Main(int argc, char* argv[]);
#ifndef USING_V8_SHARED
static Handle<Array> GetCompletions(Handle<String> text,
Handle<String> full);
static void OnExit(); static void OnExit();
static int* LookupCounter(const char* name); static int* LookupCounter(const char* name);
static void* CreateHistogram(const char* name, static void* CreateHistogram(const char* name,
...@@ -209,18 +236,8 @@ class Shell: public i::AllStatic { ...@@ -209,18 +236,8 @@ class Shell: public i::AllStatic {
size_t buckets); size_t buckets);
static void AddHistogramSample(void* histogram, int sample); static void AddHistogramSample(void* histogram, int sample);
static void MapCounters(const char* name); static void MapCounters(const char* name);
static Handle<String> ReadFile(const char* name); #endif // USING_V8_SHARED
static void Initialize();
static Persistent<Context> CreateEvaluationContext();
static void InstallUtilityScript();
static void RunShell();
static bool SetOptions(int argc, char* argv[]);
static int RunScript(char* filename);
static int RunMain(int argc, char* argv[]);
static int Main(int argc, char* argv[]);
static Handle<ObjectTemplate> CreateGlobalTemplate();
static Handle<Array> GetCompletions(Handle<String> text,
Handle<String> full);
#ifdef ENABLE_DEBUGGER_SUPPORT #ifdef ENABLE_DEBUGGER_SUPPORT
static Handle<Object> DebugMessageDetails(Handle<String> message); static Handle<Object> DebugMessageDetails(Handle<String> message);
static Handle<Value> DebugCommandToJSONRequest(Handle<String> command); static Handle<Value> DebugCommandToJSONRequest(Handle<String> command);
...@@ -283,15 +300,16 @@ class Shell: public i::AllStatic { ...@@ -283,15 +300,16 @@ class Shell: public i::AllStatic {
static Handle<Value> RemoveDirectory(const Arguments& args); static Handle<Value> RemoveDirectory(const Arguments& args);
static void AddOSMethods(Handle<ObjectTemplate> os_template); static void AddOSMethods(Handle<ObjectTemplate> os_template);
#ifndef USING_V8_SHARED
static const char* kHistoryFileName; static const char* kHistoryFileName;
#endif // USING_V8_SHARED
static const char* kPrompt; static const char* kPrompt;
static ShellOptions options; static ShellOptions options;
private: private:
static Persistent<Context> utility_context_;
static Persistent<Context> evaluation_context_; static Persistent<Context> evaluation_context_;
#ifndef USING_V8_SHARED
static Persistent<Context> utility_context_;
static CounterMap* counter_map_; static CounterMap* counter_map_;
// We statically allocate a set of local counters to be used if we // 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 // don't want to store the stats in a memory-mapped file
...@@ -299,7 +317,14 @@ class Shell: public i::AllStatic { ...@@ -299,7 +317,14 @@ class Shell: public i::AllStatic {
static CounterCollection* counters_; static CounterCollection* counters_;
static i::OS::MemoryMappedFile* counters_file_; static i::OS::MemoryMappedFile* counters_file_;
static i::Mutex* context_mutex_; static i::Mutex* context_mutex_;
static Counter* GetCounter(const char* name, bool is_histogram); static Counter* GetCounter(const char* name, bool is_histogram);
static void InstallUtilityScript();
#endif // USING_V8_SHARED
static void Initialize();
static void RunShell();
static bool SetOptions(int argc, char* argv[]);
static Handle<ObjectTemplate> CreateGlobalTemplate();
static Handle<Value> CreateExternalArray(const Arguments& args, static Handle<Value> CreateExternalArray(const Arguments& args,
ExternalArrayType type, ExternalArrayType type,
size_t element_size); size_t element_size);
...@@ -307,6 +332,7 @@ class Shell: public i::AllStatic { ...@@ -307,6 +332,7 @@ class Shell: public i::AllStatic {
}; };
#ifndef USING_V8_SHARED
class LineEditor { class LineEditor {
public: public:
enum Type { DUMB = 0, READLINE = 1 }; enum Type { DUMB = 0, READLINE = 1 };
...@@ -326,6 +352,7 @@ class LineEditor { ...@@ -326,6 +352,7 @@ class LineEditor {
LineEditor* next_; LineEditor* next_;
static LineEditor* first_; static LineEditor* first_;
}; };
#endif // USING_V8_SHARED
} // namespace v8 } // namespace v8
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment