Project: v8 Issues People Development process History Sign in
New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.
Starred by 39 users
Status: Fixed
Owner:
Email to this user bounced
Closed: Apr 2011
HW: ----
OS: ----
Priority: ----
Type: ----



Sign in to add a comment
Several V8 instances in a process
Reported by maxim.mo...@gmail.com, Nov 13 2009 Back to list
Currently there is no way to have several V8 instances in process, this
fact severely limits usage of embedded V8 in server environment.
 
V8 engine can be bound to particular thread for the needed processing thus there is
no need to change most of the code.
Static data can be collected like this:

#include "utils.h"
#include "platform.h"

namespace disasm {
  class DisassemblerData;
}

namespace v8 {
namespace internal {
class ThreadManager;
class V8;
class StackGuard;
class Top;
class GlobalHandles;
class Heap;
class ContextSlotCache;
class KeyedLookupCache;
class DescriptorLookupCache;
class TranscendentalCaches;
class CompilationCache;
class Counters;
class StubCache;
class MarkCompactCollector;
class HandleScopeImplementer;
class Logger;
class Bootstrapper;
class Builtins;
class RelocatableData;
class RegExpStack;
class Scanner;
class Compiler;
class StorageData;
class ZoneData;
class ApiData;
class CodeGeneratorData;
class ObjectsData;
class RuntimeData;
class StatsTableData;
class ExecutionData;
class AssemblerData;
class ExternalReferenceTable;
#ifdef ENABLE_DEBUGGER_SUPPORT
class Debug;
class DebuggerAgent;
#endif
}

class V8Context {
public:
  internal::ThreadManager& thread_manager_;
  internal::V8& v8_;
  internal::Top& top_;
  internal::GlobalHandles& global_handles_;
  internal::Heap& heap_;
  internal::StackGuard& stack_guard_;
  internal::ContextSlotCache& context_slot_cache_;
  internal::DescriptorLookupCache& descriptor_lookup_cache_;
  internal::KeyedLookupCache& keyed_lookup_cache_;
  internal::TranscendentalCaches& transcendental_caches_;
  internal::CompilationCache& compilation_cache_;
  internal::Counters& counters_;
  internal::MarkCompactCollector& mark_compact_collector_;
  internal::StubCache& stub_cache_;
  internal::HandleScopeImplementer& handle_scope_implementer_;
  internal::Logger& logger_;
  internal::Bootstrapper& bootstrapper_;
  internal::Builtins& builtins_;
  internal::RelocatableData& relocatable_data_;
  internal::RegExpStack& reg_exp_stack_;
  internal::Scanner& scanner_;
  internal::Compiler& compiler_;
  internal::StorageData& storage_data_;
  internal::ZoneData& zone_data_;

  internal::ApiData& api_data;
  internal::ObjectsData* objects_data;
  internal::CodeGeneratorData& code_generator_data_;
  internal::RuntimeData* runtime_data_;
  internal::ExecutionData* execution_data_;
  internal::StatsTableData& stats_table_data_;
  internal::ExternalReferenceTable* external_reference_table_;

  #ifdef ENABLE_DEBUGGER_SUPPORT
  internal::Debug& debug_;
  internal::DebuggerAgent* debugger_agent_;
  #endif

  //#ifdef ENABLE_DISASSEMBLER
  disasm::DisassemblerData* disassembler_data_;
  //#endif
  
  internal::AssemblerData* assembler_data_;

  V8Context();
  ~V8Context();
private:
  DISALLOW_COPY_AND_ASSIGN(V8Context);
};

#ifndef V8_SINGLE_THREADED
extern internal::Thread::LocalStorageKey default_context;

inline V8Context* v8_context() {
  return reinterpret_cast<V8Context*>(internal::Thread::GetThreadLocal(default_context));
}
#else
extern V8Context* default_context;

inline V8Context* v8_context() {
  return default_context;
}
#endif

}

---------------
prototype patch for i386 attached

Most of static invokations for top level internal classes like 
Heap::PerformScavenge() 
become 
v8_context()->heap_.PerformScavenge();
-------
prototype patch for i386 + updated tests attached



v8mt_with_tests.patch
1.1 MB View Download
Wow, this is the most ambitious patch I've ever seen!

I'm having some trouble getting it patched in though.  The patch says it's against 
3237 but I get conflicts when I try to patch it into that revision on bleeding_edge.  
Would you consider updating the patch to be against the latest bleeding_edge and 
uploading it to our code review server (see 
http://www.chromium.org/developers/contributing-code).

Also, do you have any performance measurements?  How does this affect the v8 
benchmarks for instance?
I attached archieved complete sources (v8mt.rar) of the prototype for anybody
interested to play with. One needs to define SEVERAL_V8_IN_PROCESS in include/v8.h,
please see sample win32 program V8M.cpp. 
The changes are quite massive and it takes some time for rebasing :) I will post
smaller patches for the easier review and incremental process.
As to performance, I've put all benchmark js files into one (benchmarks/test.js ) and
run it five times.
Original v8 RELEASE (scons mode=release library=static snapshot=on) version yields
following results:
All benchmark done for 54 seconds:
Richards: 1136
DeltaBlue: 1198
Crypto: 776
RayTrace: 1865
EarleyBoyer: 2319
RegExp: 389
Splay: 1514
Score: 1152

Richards: 1130
DeltaBlue: 1232
Crypto: 787
RayTrace: 1822
EarleyBoyer: 2413
RegExp: 384
Splay: 1498
Score: 1157

Richards: 1185
DeltaBlue: 1225
Crypto: 793
RayTrace: 1858
EarleyBoyer: 2411
RegExp: 380
Splay: 1445
Score: 1160

Richards: 1142
DeltaBlue: 1216
Crypto: 767
RayTrace: 1823
EarleyBoyer: 2296
RegExp: 372
Splay: 1450
Score: 1134

Richards: 1142
DeltaBlue: 1208
Crypto: 763
RayTrace: 1831
EarleyBoyer: 2392
RegExp: 380
Splay: 1525
Score: 1150
----
Attached RELEASE version without several v8 instances in process:
Benchmark done for 55 seconds
Richards: 1155
DeltaBlue: 1180
Crypto: 768
RayTrace: 1847
EarleyBoyer: 2276
RegExp: 229
Splay: 1467
Score: 1057

Richards: 1142
DeltaBlue: 1196
Crypto: 769
RayTrace: 1804
EarleyBoyer: 2289
RegExp: 229
Splay: 1501
Score: 1059

Richards: 1140
DeltaBlue: 1199
Crypto: 772
RayTrace: 1790
EarleyBoyer: 2294
RegExp: 233
Splay: 1421
Score: 1053

Richards: 1161
DeltaBlue: 1241
Crypto: 778
RayTrace: 1841
EarleyBoyer: 2364
RegExp: 232
Splay: 1501
Score: 1079

Richards: 1166
DeltaBlue: 1212
Crypto: 780
RayTrace: 1822
EarleyBoyer: 2299
RegExp: 232
Splay: 1501
Score: 1070

-------------- 
Attached RELEASE version with several v8 instances in process and one thread:
Benchmark done for 59 seconds
Richards: 1171
DeltaBlue: 1200
Crypto: 787
RayTrace: 1697
EarleyBoyer: 1975
RegExp: 214
Splay: 2064
Score: 1073

Richards: 1165
DeltaBlue: 1163
Crypto: 788
RayTrace: 1807
EarleyBoyer: 2048
RegExp: 215
Splay: 1120
Score: 993

Richards: 1171
DeltaBlue: 1216
Crypto: 788
RayTrace: 1804
EarleyBoyer: 2075
RegExp: 216
Splay: 1131
Score: 1004

Richards: 1161
DeltaBlue: 1187
Crypto: 791
RayTrace: 1811
EarleyBoyer: 2073
RegExp: 216
Splay: 1147
Score: 1002

Richards: 1162
DeltaBlue: 1199
Crypto: 785
RayTrace: 1813
EarleyBoyer: 2050
RegExp: 216
Splay: 1168
Score: 1003

Attached RELEASE version with several v8 instances in process and two threads (CPU
has two cores):
Benchmark done for 59 seconds
Richards: 1187
DeltaBlue: 1228
Crypto: 802
RayTrace: 1770
EarleyBoyer: 2030
RegExp: 220
Splay: 1134
Score: 1007

Richards: 1200
DeltaBlue: 1239
Crypto: 802
RayTrace: 1856
EarleyBoyer: 2064
RegExp: 220
Splay: 1095
Score: 1014

Richards: 1193
DeltaBlue: 1218
Crypto: 800
RayTrace: 1860
EarleyBoyer: 2005
RegExp: 220
Splay: 1145
Score: 1013

Richards: 1194
DeltaBlue: 1235
Crypto: 802
RayTrace: 1862
EarleyBoyer: 2003
RegExp: 217
Splay: 1159
Score: 1015

Richards: 1197
DeltaBlue: 1239
Crypto: 803
RayTrace: 1865
EarleyBoyer: 2022
RegExp: 221
Splay: 1160
Score: 1020

Richards: 1140
DeltaBlue: 1146
Crypto: 757
RayTrace: 1610
EarleyBoyer: 1907
RegExp: 207
Splay: 1980
Score: 1031

Richards: 1107
DeltaBlue: 1126
Crypto: 764
RayTrace: 1694
EarleyBoyer: 1973
RegExp: 208
Splay: 1044
Score: 948

Richards: 1106
DeltaBlue: 1150
Crypto: 754
RayTrace: 1720
EarleyBoyer: 1953
RegExp: 204
Splay: 1044
Score: 948

Richards: 1126
DeltaBlue: 1153
Crypto: 759
RayTrace: 1712
EarleyBoyer: 1985
RegExp: 206
Splay: 1046
Score: 955

Richards: 1130
DeltaBlue: 1159
Crypto: 762
RayTrace: 1751
EarleyBoyer: 1985
RegExp: 204
Splay: 1058
Score: 960

V8M.cpp
2.2 KB View Download
archieved sources file now contain cctest files
v8mt.rar
2.4 MB Download
gcl is unable to upload patch with "Connection refused"
----- gcl changelist description
First patch for allowing several V8 instances in process:
- Introduced V8ContextProvider and V8ContextBinder classes to public api (include\v8.h),
first class is defined only if SEVERAL_V8_IN_PROCESS macro is defined
- Created v8::internal::V8Context class to hold the data of separate objects of v8
instance

- Created v8_context() inline function to return V8Context for accessing the data, 
in case SEVERAL_V8_IN_PROCESS not defined the function just returns global pointer
otherwise
the data is retrieved from thread local variable
- Moved static data of v8::internal::V8, static flag from v8::Locker, static callback
pointer 
 exception_behavior from api.cc into v8::internal::V8Data as instance variables

- Moved static data of v8::internal::ThreadManager, v8::internal::ContextSwitcher,
v8::internal::ThreadState,
static Thread::LocalStorageKey variables into v8::internal::ThreadManagerData
- Wrapped dtoa calls in conversions.cc with locking when SEVERAL_V8_IN_PROCESS

- Moved static data of v8::internal::Heap into v8::internal::HeapData as instance
variables.
- MarkObjectVisitor and UnmarkObjectVisitor allocated on stack instead of static
variables.
- static void MarkObjectRecursively(Object** p); becomes member of
v8::internal::MarkObjectVisitor
- static void UnmarkObjectRecursively(Object** p); becomes member of
v8::internal::UnmarkObjectVisitor
- Moved static data of heap.cc into v8::internal::PrivateHeapData as instance variables.
- static void MarkRootObjectRecursively(Object** root); moved to
v8::internal::PrivateHeapData

- static data and types of v8::internal::TranscendentalCache moved to
v8::internal::TranscendentalCacheData as 
instance variables / types.
- static data and types of v8::internal::DescriptorLookupCache moved to
v8::internal::DescriptorLookupCacheData 
as instance variables / types.
- static data and types of v8::internal::KeyedLookupCacheData moved to
v8::internal::KeyedLookupCacheDataData as 
instance variables / types

- static data of v8::internal::Zone, v8::internal::ZoneScope, v8::internal::Zone, 
  v8::internal::AssertNoZoneAllocation, v8::internal::Segment moved to
v8:internal::ZoneData

BUG= 510 
TEST=When SEVERAL_V8_IN_PROCESS is not defined (default) all tests should pass

Uploaded several_v8_in_process_1.patch for code review
http://codereview.chromium.org/435003
Current sources snapshot of http://codereview.chromium.org/435003
v8embeddable.rar
3.3 MB Download
Sources available in V8 sources fork at git://github.com/nicity/Embeddable-V8.git
V8 project SVN now has Isolates branch
(http://v8.googlecode.com/svn/branches/experimental/isolates/). This branch contains
some initial extraction of V8 statics into separate class v8::internal::Isolate which
is the same as v8::internal::V8Context from suggested patch. In other words, if that
branch succeeds we will be able to get V8 multithreaded.
What is the status of the isolates branch? Just curious when it might be ready for use.
I have some use cases for it I would like to explore.
It works (at least on linux), but it's not well tested yet and the performance is worse than on bleeding_edge. We're working on fixing these issues.
Is there still work done on this issue?
Comment 15 by ager@chromium.org, Jan 11 2011
Yes, progress can be tracked on the isolates branch. Currently a merge of V8 version 3.0 is in progress. Once that is done the work is getting close to completion and after extensive testing we hope to be able to land this on the main development branch.
Isolates branch was merged into bleeding_edge 
http://code.google.com/p/v8/source/detail?r=7271
We expect next V8 version will allow several V8 instances (aka Isolates) in process!!!
Per http://code.google.com/p/v8/source/detail?spec=svn7392&r=7322 Isolates are in Trunk, the issue can be closed
Comment 18 Deleted
Owner: vitalyr@chromium.org
Status: Fixed
Isolates are now merged to trunk. There's still some ongoing work to fully support lockers+isolates, but we can close this issue.
Sign in to add a comment