Reland 24052 - Require V8 to be explicitly initialized before an Isolate is created
authorjochen@chromium.org <jochen@chromium.org>
Fri, 19 Sep 2014 08:01:35 +0000 (08:01 +0000)
committerjochen@chromium.org <jochen@chromium.org>
Fri, 19 Sep 2014 08:01:35 +0000 (08:01 +0000)
> We also initialize the Isolate on creation.
>
> This should allow for getting rid of the last remaining default isolate
> traces. Also, it'll speed up several isolate related operations that no
> longer require locks.
>
> Embedders that relied on v8::Isolate to return an uninitialized Isolate
> (so they can set ResourceConstraints for example, or set flags that
> modify the way the isolate is created) should either do the setup before
> creating the isolate, or use the recently added CreateParams to pass e.g.
> ResourceConstraints.
>
> BUG=none
> LOG=y
> R=svenpanne@chromium.org
>
> Review URL: https://codereview.chromium.org/469783002

BUG=none
LOG=y
TBR=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/583153002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

37 files changed:
include/v8.h
samples/lineprocessor.cc
samples/process.cc
samples/shell.cc
src/api.cc
src/base/utils/random-number-generator.cc
src/base/utils/random-number-generator.h
src/bootstrapper.cc
src/d8.cc
src/isolate.cc
src/isolate.h
src/mksnapshot.cc
src/snapshot-common.cc
src/snapshot-external.cc
src/snapshot.h
src/v8.cc
src/v8.h
test/cctest/cctest.cc
test/cctest/cctest.h
test/cctest/test-api.cc
test/cctest/test-ast.cc
test/cctest/test-dataflow.cc
test/cctest/test-debug.cc
test/cctest/test-deoptimization.cc
test/cctest/test-heap.cc
test/cctest/test-liveedit.cc
test/cctest/test-log.cc
test/cctest/test-macro-assembler-arm.cc
test/cctest/test-macro-assembler-ia32.cc
test/cctest/test-macro-assembler-x64.cc
test/cctest/test-macro-assembler-x87.cc
test/cctest/test-random-number-generator.cc
test/cctest/test-regexp.cc
test/cctest/test-serialize.cc
test/cctest/test-spaces.cc
tools/lexer-shell.cc
tools/parser-shell.cc

index e4c7087..26d8710 100644 (file)
@@ -4344,13 +4344,12 @@ typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
 
 
 /**
- * Isolate represents an isolated instance of the V8 engine.  V8
- * isolates have completely separate states.  Objects from one isolate
- * must not be used in other isolates.  When V8 is initialized a
- * default isolate is implicitly created and entered.  The embedder
- * can create additional isolates and use them in parallel in multiple
- * threads.  An isolate can be entered by at most one thread at any
- * given time.  The Locker/Unlocker API must be used to synchronize.
+ * Isolate represents an isolated instance of the V8 engine.  V8 isolates have
+ * completely separate states.  Objects from one isolate must not be used in
+ * other isolates.  The embedder can create multiple isolates and use them in
+ * parallel in multiple threads.  An isolate can be entered by at most one
+ * thread at any given time.  The Locker/Unlocker API must be used to
+ * synchronize.
  */
 class V8_EXPORT Isolate {
  public:
@@ -4358,7 +4357,10 @@ class V8_EXPORT Isolate {
    * Initial configuration parameters for a new Isolate.
    */
   struct CreateParams {
-    CreateParams() : entry_hook(NULL), code_event_handler(NULL) {}
+    CreateParams()
+        : entry_hook(NULL),
+          code_event_handler(NULL),
+          enable_serializer(false) {}
 
     /**
      * The optional entry_hook allows the host application to provide the
@@ -4379,6 +4381,11 @@ class V8_EXPORT Isolate {
      * ResourceConstraints to use for the new Isolate.
      */
     ResourceConstraints constraints;
+
+    /**
+     * This flag currently renders the Isolate unusable.
+     */
+    bool enable_serializer;
   };
 
 
@@ -4489,6 +4496,8 @@ class V8_EXPORT Isolate {
    *
    * When an isolate is no longer used its resources should be freed
    * by calling Dispose().  Using the delete operator is not allowed.
+   *
+   * V8::Initialize() must have run prior to this.
    */
   static Isolate* New(const CreateParams& params = CreateParams());
 
@@ -5102,9 +5111,8 @@ class V8_EXPORT V8 {
   static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback);
 
   /**
-   * Initializes from snapshot if possible. Otherwise, attempts to
-   * initialize from scratch.  This function is called implicitly if
-   * you use the API without calling it first.
+   * Initializes V8. This function needs to be called before the first Isolate
+   * is created. It always returns true.
    */
   static bool Initialize();
 
index 9b627f3..69bfab4 100644 (file)
@@ -257,6 +257,7 @@ int main(int argc, char* argv[]) {
   v8::V8::InitializeICU();
   v8::Platform* platform = v8::platform::CreateDefaultPlatform();
   v8::V8::InitializePlatform(platform);
+  v8::V8::Initialize();
   int result = RunMain(argc, argv);
   v8::V8::Dispose();
   v8::V8::ShutdownPlatform();
index 4db7eeb..e5c9b7a 100644 (file)
@@ -648,6 +648,7 @@ int main(int argc, char* argv[]) {
   v8::V8::InitializeICU();
   v8::Platform* platform = v8::platform::CreateDefaultPlatform();
   v8::V8::InitializePlatform(platform);
+  v8::V8::Initialize();
   map<string, string> options;
   string file;
   ParseOptions(argc, argv, &options, &file);
index ef61426..b66e8f7 100644 (file)
@@ -83,6 +83,7 @@ int main(int argc, char* argv[]) {
   v8::V8::InitializeICU();
   v8::Platform* platform = v8::platform::CreateDefaultPlatform();
   v8::V8::InitializePlatform(platform);
+  v8::V8::Initialize();
   v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
   ShellArrayBufferAllocator array_buffer_allocator;
   v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
index 3c042d7..107c7e8 100644 (file)
@@ -202,29 +202,6 @@ static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) {
 }
 
 
-// --- S t a t i c s ---
-
-
-static bool InitializeHelper(i::Isolate* isolate) {
-  // If the isolate has a function entry hook, it needs to re-build all its
-  // code stubs with entry hooks embedded, so let's deserialize a snapshot.
-  if (isolate == NULL || isolate->function_entry_hook() == NULL) {
-    if (i::Snapshot::Initialize())
-      return true;
-  }
-  return i::V8::Initialize(NULL);
-}
-
-
-static inline bool EnsureInitializedForIsolate(i::Isolate* isolate,
-                                               const char* location) {
-  return (isolate != NULL && isolate->IsInitialized()) ||
-      Utils::ApiCheck(InitializeHelper(isolate),
-                      location,
-                      "Error initializing V8");
-}
-
-
 StartupDataDecompressor::StartupDataDecompressor()
     : raw_data(i::NewArray<char*>(V8::GetCompressedStartupDataCount())) {
   for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) {
@@ -746,7 +723,6 @@ void Context::SetAlignedPointerInEmbedderData(int index, void* value) {
 // NeanderObject constructor.  When you add one to the site calling the
 // constructor you should check that you ensured the VM was not dead first.
 NeanderObject::NeanderObject(v8::internal::Isolate* isolate, int size) {
-  EnsureInitializedForIsolate(isolate, "v8::Nowhere");
   ENTER_V8(isolate);
   value_ = isolate->factory()->NewNeanderObject();
   i::Handle<i::FixedArray> elements = isolate->factory()->NewFixedArray(size);
@@ -939,7 +915,6 @@ Local<FunctionTemplate> FunctionTemplate::New(
     v8::Handle<Signature> signature,
     int length) {
   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
-  EnsureInitializedForIsolate(i_isolate, "v8::FunctionTemplate::New()");
   LOG_API(i_isolate, "FunctionTemplate::New");
   ENTER_V8(i_isolate);
   return FunctionTemplateNew(
@@ -951,7 +926,6 @@ Local<Signature> Signature::New(Isolate* isolate,
                                 Handle<FunctionTemplate> receiver, int argc,
                                 Handle<FunctionTemplate> argv[]) {
   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
-  EnsureInitializedForIsolate(i_isolate, "v8::Signature::New()");
   LOG_API(i_isolate, "Signature::New");
   ENTER_V8(i_isolate);
   i::Handle<i::Struct> struct_obj =
@@ -1102,7 +1076,6 @@ Local<TypeSwitch> TypeSwitch::New(Handle<FunctionTemplate> type) {
 
 Local<TypeSwitch> TypeSwitch::New(int argc, Handle<FunctionTemplate> types[]) {
   i::Isolate* isolate = i::Isolate::Current();
-  EnsureInitializedForIsolate(isolate, "v8::TypeSwitch::New()");
   LOG_API(isolate, "TypeSwitch::New");
   ENTER_V8(isolate);
   i::Handle<i::FixedArray> vector = isolate->factory()->NewFixedArray(argc);
@@ -1283,7 +1256,6 @@ Local<ObjectTemplate> ObjectTemplate::New() {
 Local<ObjectTemplate> ObjectTemplate::New(
     i::Isolate* isolate,
     v8::Handle<FunctionTemplate> constructor) {
-  EnsureInitializedForIsolate(isolate, "v8::ObjectTemplate::New()");
   LOG_API(isolate, "ObjectTemplate::New");
   ENTER_V8(isolate);
   i::Handle<i::Struct> struct_obj =
@@ -2400,7 +2372,6 @@ bool StackFrame::IsConstructor() const {
 Local<Value> JSON::Parse(Local<String> json_string) {
   i::Handle<i::String> string = Utils::OpenHandle(*json_string);
   i::Isolate* isolate = string->GetIsolate();
-  EnsureInitializedForIsolate(isolate, "v8::JSON::Parse");
   ENTER_V8(isolate);
   i::HandleScope scope(isolate);
   i::Handle<i::String> source = i::String::Flatten(string);
@@ -4891,7 +4862,6 @@ int String::Write(uint16_t* buffer,
 
 bool v8::String::IsExternal() const {
   i::Handle<i::String> str = Utils::OpenHandle(this);
-  EnsureInitializedForIsolate(str->GetIsolate(), "v8::String::IsExternal()");
   return i::StringShape(*str).IsExternalTwoByte();
 }
 
@@ -5080,11 +5050,8 @@ void v8::V8::ShutdownPlatform() {
 
 
 bool v8::V8::Initialize() {
-  i::Isolate* isolate = i::Isolate::UncheckedCurrent();
-  if (isolate != NULL && isolate->IsInitialized()) {
-    return true;
-  }
-  return InitializeHelper(isolate);
+  i::V8::Initialize();
+  return true;
 }
 
 
@@ -5279,7 +5246,6 @@ Local<Context> v8::Context::New(
     v8::Handle<ObjectTemplate> global_template,
     v8::Handle<Value> global_object) {
   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
-  EnsureInitializedForIsolate(isolate, "v8::Context::New()");
   LOG_API(isolate, "Context::New");
   ON_BAILOUT(isolate, "v8::Context::New()", return Local<Context>());
   i::HandleScope scope(isolate);
@@ -5410,7 +5376,6 @@ bool FunctionTemplate::HasInstance(v8::Handle<v8::Value> value) {
 Local<External> v8::External::New(Isolate* isolate, void* value) {
   STATIC_ASSERT(sizeof(value) == sizeof(i::Address));
   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
-  EnsureInitializedForIsolate(i_isolate, "v8::External::New()");
   LOG_API(i_isolate, "External::New");
   ENTER_V8(i_isolate);
   i::Handle<i::JSObject> external = i_isolate->factory()->NewExternal(value);
@@ -5485,7 +5450,6 @@ inline Local<String> NewString(Isolate* v8_isolate,
                                String::NewStringType type,
                                int length) {
   i::Isolate* isolate = reinterpret_cast<internal::Isolate*>(v8_isolate);
-  EnsureInitializedForIsolate(isolate, location);
   LOG_API(isolate, env);
   if (length == 0 && type != String::kUndetectableString) {
     return String::Empty(v8_isolate);
@@ -5548,7 +5512,6 @@ Local<String> String::NewFromTwoByte(Isolate* isolate,
 Local<String> v8::String::Concat(Handle<String> left, Handle<String> right) {
   i::Handle<i::String> left_string = Utils::OpenHandle(*left);
   i::Isolate* isolate = left_string->GetIsolate();
-  EnsureInitializedForIsolate(isolate, "v8::String::New()");
   LOG_API(isolate, "String::New(char)");
   ENTER_V8(isolate);
   i::Handle<i::String> right_string = Utils::OpenHandle(*right);
@@ -5581,7 +5544,6 @@ Local<String> v8::String::NewExternal(
     Isolate* isolate,
     v8::String::ExternalStringResource* resource) {
   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
-  EnsureInitializedForIsolate(i_isolate, "v8::String::NewExternal()");
   LOG_API(i_isolate, "String::NewExternal");
   ENTER_V8(i_isolate);
   CHECK(resource && resource->data());
@@ -5620,7 +5582,6 @@ bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
 Local<String> v8::String::NewExternal(
     Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) {
   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
-  EnsureInitializedForIsolate(i_isolate, "v8::String::NewExternal()");
   LOG_API(i_isolate, "String::NewExternal");
   ENTER_V8(i_isolate);
   CHECK(resource && resource->data());
@@ -5673,7 +5634,6 @@ bool v8::String::CanMakeExternal() {
 
 Local<v8::Object> v8::Object::New(Isolate* isolate) {
   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
-  EnsureInitializedForIsolate(i_isolate, "v8::Object::New()");
   LOG_API(i_isolate, "Object::New");
   ENTER_V8(i_isolate);
   i::Handle<i::JSObject> obj =
@@ -5684,7 +5644,6 @@ Local<v8::Object> v8::Object::New(Isolate* isolate) {
 
 Local<v8::Value> v8::NumberObject::New(Isolate* isolate, double value) {
   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
-  EnsureInitializedForIsolate(i_isolate, "v8::NumberObject::New()");
   LOG_API(i_isolate, "NumberObject::New");
   ENTER_V8(i_isolate);
   i::Handle<i::Object> number = i_isolate->factory()->NewNumber(value);
@@ -5705,7 +5664,6 @@ double v8::NumberObject::ValueOf() const {
 
 Local<v8::Value> v8::BooleanObject::New(bool value) {
   i::Isolate* isolate = i::Isolate::Current();
-  EnsureInitializedForIsolate(isolate, "v8::BooleanObject::New()");
   LOG_API(isolate, "BooleanObject::New");
   ENTER_V8(isolate);
   i::Handle<i::Object> boolean(value
@@ -5730,7 +5688,6 @@ bool v8::BooleanObject::ValueOf() const {
 Local<v8::Value> v8::StringObject::New(Handle<String> value) {
   i::Handle<i::String> string = Utils::OpenHandle(*value);
   i::Isolate* isolate = string->GetIsolate();
-  EnsureInitializedForIsolate(isolate, "v8::StringObject::New()");
   LOG_API(isolate, "StringObject::New");
   ENTER_V8(isolate);
   i::Handle<i::Object> obj =
@@ -5751,7 +5708,6 @@ Local<v8::String> v8::StringObject::ValueOf() const {
 
 Local<v8::Value> v8::SymbolObject::New(Isolate* isolate, Handle<Symbol> value) {
   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
-  EnsureInitializedForIsolate(i_isolate, "v8::SymbolObject::New()");
   LOG_API(i_isolate, "SymbolObject::New");
   ENTER_V8(i_isolate);
   i::Handle<i::Object> obj = i::Object::ToObject(
@@ -5772,7 +5728,6 @@ Local<v8::Symbol> v8::SymbolObject::ValueOf() const {
 
 Local<v8::Value> v8::Date::New(Isolate* isolate, double time) {
   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
-  EnsureInitializedForIsolate(i_isolate, "v8::Date::New()");
   LOG_API(i_isolate, "Date::New");
   if (std::isnan(time)) {
     // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
@@ -5838,7 +5793,6 @@ static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) {
 Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern,
                                   Flags flags) {
   i::Isolate* isolate = Utils::OpenHandle(*pattern)->GetIsolate();
-  EnsureInitializedForIsolate(isolate, "v8::RegExp::New()");
   LOG_API(isolate, "RegExp::New");
   ENTER_V8(isolate);
   EXCEPTION_PREAMBLE(isolate);
@@ -5875,7 +5829,6 @@ v8::RegExp::Flags v8::RegExp::GetFlags() const {
 
 Local<v8::Array> v8::Array::New(Isolate* isolate, int length) {
   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
-  EnsureInitializedForIsolate(i_isolate, "v8::Array::New()");
   LOG_API(i_isolate, "Array::New");
   ENTER_V8(i_isolate);
   int real_length = length > 0 ? length : 0;
@@ -6095,7 +6048,6 @@ size_t v8::ArrayBuffer::ByteLength() const {
 
 Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, size_t byte_length) {
   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
-  EnsureInitializedForIsolate(i_isolate, "v8::ArrayBuffer::New(size_t)");
   LOG_API(i_isolate, "v8::ArrayBuffer::New(size_t)");
   ENTER_V8(i_isolate);
   i::Handle<i::JSArrayBuffer> obj =
@@ -6108,7 +6060,6 @@ Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, size_t byte_length) {
 Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, void* data,
                                         size_t byte_length) {
   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
-  EnsureInitializedForIsolate(i_isolate, "v8::ArrayBuffer::New(void*, size_t)");
   LOG_API(i_isolate, "v8::ArrayBuffer::New(void*, size_t)");
   ENTER_V8(i_isolate);
   i::Handle<i::JSArrayBuffer> obj =
@@ -6211,8 +6162,6 @@ i::Handle<i::JSTypedArray> NewTypedArray(
   Local<Type##Array> Type##Array::New(Handle<ArrayBuffer> array_buffer,      \
                                     size_t byte_offset, size_t length) {     \
     i::Isolate* isolate = Utils::OpenHandle(*array_buffer)->GetIsolate();    \
-    EnsureInitializedForIsolate(isolate,                                     \
-        "v8::" #Type "Array::New(Handle<ArrayBuffer>, size_t, size_t)");     \
     LOG_API(isolate,                                                         \
         "v8::" #Type "Array::New(Handle<ArrayBuffer>, size_t, size_t)");     \
     ENTER_V8(isolate);                                                       \
@@ -6236,8 +6185,6 @@ Local<DataView> DataView::New(Handle<ArrayBuffer> array_buffer,
                               size_t byte_offset, size_t byte_length) {
   i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer);
   i::Isolate* isolate = buffer->GetIsolate();
-  EnsureInitializedForIsolate(
-      isolate, "v8::DataView::New(void*, size_t, size_t)");
   LOG_API(isolate, "v8::DataView::New(void*, size_t, size_t)");
   ENTER_V8(isolate);
   i::Handle<i::JSDataView> obj = isolate->factory()->NewJSDataView();
@@ -6249,7 +6196,6 @@ Local<DataView> DataView::New(Handle<ArrayBuffer> array_buffer,
 
 Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) {
   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
-  EnsureInitializedForIsolate(i_isolate, "v8::Symbol::New()");
   LOG_API(i_isolate, "Symbol::New()");
   ENTER_V8(i_isolate);
   i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol();
@@ -6314,7 +6260,6 @@ Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) {
 
 Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) {
   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
-  EnsureInitializedForIsolate(i_isolate, "v8::Private::New()");
   LOG_API(i_isolate, "Private::New()");
   ENTER_V8(i_isolate);
   i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol();
@@ -6386,7 +6331,6 @@ Local<Integer> v8::Integer::NewFromUnsigned(Isolate* isolate, uint32_t value) {
 
 bool V8::AddMessageListener(MessageCallback that, Handle<Value> data) {
   i::Isolate* isolate = i::Isolate::Current();
-  EnsureInitializedForIsolate(isolate, "v8::V8::AddMessageListener()");
   ON_BAILOUT(isolate, "v8::V8::AddMessageListener()", return false);
   ENTER_V8(isolate);
   i::HandleScope scope(isolate);
@@ -6402,7 +6346,6 @@ bool V8::AddMessageListener(MessageCallback that, Handle<Value> data) {
 
 void V8::RemoveMessageListeners(MessageCallback that) {
   i::Isolate* isolate = i::Isolate::Current();
-  EnsureInitializedForIsolate(isolate, "v8::V8::RemoveMessageListener()");
   ON_BAILOUT(isolate, "v8::V8::RemoveMessageListeners()", return);
   ENTER_V8(isolate);
   i::HandleScope scope(isolate);
@@ -6675,6 +6618,16 @@ Isolate* Isolate::New(const Isolate::CreateParams& params) {
   }
   SetResourceConstraints(v8_isolate,
                          const_cast<ResourceConstraints*>(&params.constraints));
+  if (params.enable_serializer) {
+    isolate->enable_serializer();
+  }
+  // TODO(jochen): Once we got rid of Isolate::Current(), we can remove this.
+  Isolate::Scope isolate_scope(v8_isolate);
+  if (params.entry_hook || !i::Snapshot::Initialize(isolate)) {
+    // If the isolate has a function entry hook, it needs to re-build all its
+    // code stubs with entry hooks embedded, so don't deserialize a snapshot.
+    isolate->Init(NULL);
+  }
   return v8_isolate;
 }
 
@@ -6977,7 +6930,6 @@ DEFINE_ERROR(Error)
 
 bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) {
   i::Isolate* isolate = i::Isolate::Current();
-  EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener()");
   ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false);
   ENTER_V8(isolate);
   i::HandleScope scope(isolate);
@@ -7016,7 +6968,6 @@ void Debug::DebugBreakForCommand(Isolate* isolate, ClientData* data) {
 
 void Debug::SetMessageHandler(v8::Debug::MessageHandler handler) {
   i::Isolate* isolate = i::Isolate::Current();
-  EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler");
   ENTER_V8(isolate);
   isolate->debug()->SetMessageHandler(handler);
 }
@@ -7090,7 +7041,6 @@ void Debug::ProcessDebugMessages() {
 
 Local<Context> Debug::GetDebugContext() {
   i::Isolate* isolate = i::Isolate::Current();
-  EnsureInitializedForIsolate(isolate, "v8::Debug::GetDebugContext()");
   ENTER_V8(isolate);
   return Utils::ToLocal(i::Isolate::Current()->debug()->GetDebugContext());
 }
index be79811..9454936 100644 (file)
@@ -125,6 +125,7 @@ int RandomNumberGenerator::Next(int bits) {
 
 
 void RandomNumberGenerator::SetSeed(int64_t seed) {
+  initial_seed_ = seed;
   seed_ = (seed ^ kMultiplier) & kMask;
 }
 
index a9107a6..479423d 100644 (file)
@@ -74,6 +74,8 @@ class RandomNumberGenerator FINAL {
   // Override the current ssed.
   void SetSeed(int64_t seed);
 
+  int64_t initial_seed() const { return initial_seed_; }
+
  private:
   static const int64_t kMultiplier = V8_2PART_UINT64_C(0x5, deece66d);
   static const int64_t kAddend = 0xb;
@@ -81,6 +83,7 @@ class RandomNumberGenerator FINAL {
 
   int Next(int bits) WARN_UNUSED_RESULT;
 
+  int64_t initial_seed_;
   int64_t seed_;
 };
 
index af4acc3..9e564a8 100644 (file)
@@ -2609,9 +2609,6 @@ Genesis::Genesis(Isolate* isolate,
       active_(isolate->bootstrapper()) {
   NoTrackDoubleFieldsForSerializerScope disable_scope(isolate);
   result_ = Handle<Context>::null();
-  // If V8 cannot be initialized, just return.
-  if (!V8::Initialize(NULL)) return;
-
   // Before creating the roots we must save the context and restore it
   // on all function exits.
   SaveContext saved_context(isolate);
index c1d66b4..9db7744 100644 (file)
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -1619,6 +1619,7 @@ int Shell::Main(int argc, char* argv[]) {
   v8::V8::InitializeICU(options.icu_data_file);
   v8::Platform* platform = v8::platform::CreateDefaultPlatform();
   v8::V8::InitializePlatform(platform);
+  v8::V8::Initialize();
 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
   StartupDataHandler startup_data(options.natives_blob, options.snapshot_blob);
 #endif
index 66733cb..e960445 100644 (file)
@@ -48,7 +48,6 @@ int ThreadId::AllocateThreadId() {
 
 
 int ThreadId::GetCurrentThreadId() {
-  Isolate::EnsureInitialized();
   int thread_id = base::Thread::GetThreadLocalInt(Isolate::thread_id_key_);
   if (thread_id == 0) {
     thread_id = AllocateThreadId();
@@ -114,17 +113,16 @@ base::Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_;
 #ifdef DEBUG
 base::Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key;
 #endif  // DEBUG
-base::LazyMutex Isolate::process_wide_mutex_ = LAZY_MUTEX_INITIALIZER;
+base::LazyMutex Isolate::thread_data_table_mutex_ = LAZY_MUTEX_INITIALIZER;
 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL;
 base::Atomic32 Isolate::isolate_counter_ = 0;
 
 Isolate::PerIsolateThreadData*
     Isolate::FindOrAllocatePerThreadDataForThisThread() {
-  EnsureInitialized();
   ThreadId thread_id = ThreadId::Current();
   PerIsolateThreadData* per_thread = NULL;
   {
-    base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
+    base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer());
     per_thread = thread_data_table_->Lookup(this, thread_id);
     if (per_thread == NULL) {
       per_thread = new PerIsolateThreadData(this, thread_id);
@@ -144,28 +142,26 @@ Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() {
 
 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread(
     ThreadId thread_id) {
-  EnsureInitialized();
   PerIsolateThreadData* per_thread = NULL;
   {
-    base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
+    base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer());
     per_thread = thread_data_table_->Lookup(this, thread_id);
   }
   return per_thread;
 }
 
 
-void Isolate::EnsureInitialized() {
-  base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
-  if (thread_data_table_ == NULL) {
-    isolate_key_ = base::Thread::CreateThreadLocalKey();
-    thread_id_key_ = base::Thread::CreateThreadLocalKey();
-    per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey();
+void Isolate::InitializeOncePerProcess() {
+  base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer());
+  CHECK(thread_data_table_ == NULL);
+  isolate_key_ = base::Thread::CreateThreadLocalKey();
+  thread_id_key_ = base::Thread::CreateThreadLocalKey();
+  per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey();
 #ifdef DEBUG
-    PerThreadAssertScopeBase::thread_local_key =
-        base::Thread::CreateThreadLocalKey();
+  PerThreadAssertScopeBase::thread_local_key =
+      base::Thread::CreateThreadLocalKey();
 #endif  // DEBUG
-    thread_data_table_ = new Isolate::ThreadDataTable();
-  }
+  thread_data_table_ = new Isolate::ThreadDataTable();
 }
 
 
@@ -1521,6 +1517,10 @@ Isolate::Isolate()
       stress_deopt_count_(0),
       next_optimization_id_(0),
       use_counter_callback_(NULL) {
+  {
+    base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer());
+    CHECK(thread_data_table_);
+  }
   id_ = base::NoBarrier_AtomicIncrement(&isolate_counter_, 1);
   TRACE_ISOLATE(constructor);
 
@@ -1571,7 +1571,7 @@ void Isolate::TearDown() {
   Deinit();
 
   {
-    base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
+    base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer());
     thread_data_table_->RemoveAllThreads(this);
   }
 
@@ -1676,7 +1676,6 @@ void Isolate::PushToPartialSnapshotCache(Object* obj) {
 
 void Isolate::SetIsolateThreadLocals(Isolate* isolate,
                                      PerIsolateThreadData* data) {
-  EnsureInitialized();
   base::Thread::SetThreadLocal(isolate_key_, isolate);
   base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data);
 }
index 28a45da..24d4b08 100644 (file)
@@ -466,17 +466,17 @@ class Isolate {
     kIsolateAddressCount
   };
 
+  static void InitializeOncePerProcess();
+
   // Returns the PerIsolateThreadData for the current thread (or NULL if one is
   // not currently set).
   static PerIsolateThreadData* CurrentPerIsolateThreadData() {
-    EnsureInitialized();
     return reinterpret_cast<PerIsolateThreadData*>(
         base::Thread::GetThreadLocal(per_isolate_thread_data_key_));
   }
 
   // Returns the isolate inside which the current thread is running.
   INLINE(static Isolate* Current()) {
-    EnsureInitialized();
     Isolate* isolate = reinterpret_cast<Isolate*>(
         base::Thread::GetExistingThreadLocal(isolate_key_));
     DCHECK(isolate != NULL);
@@ -484,7 +484,6 @@ class Isolate {
   }
 
   INLINE(static Isolate* UncheckedCurrent()) {
-    EnsureInitialized();
     return reinterpret_cast<Isolate*>(
         base::Thread::GetThreadLocal(isolate_key_));
   }
@@ -529,13 +528,11 @@ class Isolate {
   // Used internally for V8 threads that do not execute JavaScript but still
   // are part of the domain of an isolate (like the context switcher).
   static base::Thread::LocalStorageKey isolate_key() {
-    EnsureInitialized();
     return isolate_key_;
   }
 
   // Returns the key used to store process-wide thread IDs.
   static base::Thread::LocalStorageKey thread_id_key() {
-    EnsureInitialized();
     return thread_id_key_;
   }
 
@@ -1110,9 +1107,9 @@ class Isolate {
   void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback);
   void CountUsage(v8::Isolate::UseCounterFeature feature);
 
- private:
-  static void EnsureInitialized();
+  static Isolate* NewForTesting() { return new Isolate(); }
 
+ private:
   Isolate();
 
   friend struct GlobalState;
@@ -1171,8 +1168,7 @@ class Isolate {
     DISALLOW_COPY_AND_ASSIGN(EntryStackItem);
   };
 
-  // This mutex protects highest_thread_id_ and thread_data_table_.
-  static base::LazyMutex process_wide_mutex_;
+  static base::LazyMutex thread_data_table_mutex_;
 
   static base::Thread::LocalStorageKey per_isolate_thread_data_key_;
   static base::Thread::LocalStorageKey isolate_key_;
index 71a78a9..b4a4018 100644 (file)
@@ -303,11 +303,6 @@ void DumpException(Handle<Message> message) {
 
 
 int main(int argc, char** argv) {
-  V8::InitializeICU();
-  v8::Platform* platform = v8::platform::CreateDefaultPlatform();
-  v8::V8::InitializePlatform(platform);
-  i::CpuFeatures::Probe(true);
-
   // By default, log code create information in the snapshot.
   i::FLAG_log_code = true;
 
@@ -319,6 +314,13 @@ int main(int argc, char** argv) {
     i::FlagList::PrintHelp();
     return !i::FLAG_help;
   }
+
+  i::CpuFeatures::Probe(true);
+  V8::InitializeICU();
+  v8::Platform* platform = v8::platform::CreateDefaultPlatform();
+  v8::V8::InitializePlatform(platform);
+  v8::V8::Initialize();
+
 #ifdef COMPRESS_STARTUP_DATA_BZ2
   BZip2Decompressor natives_decompressor;
   int bz2_result = natives_decompressor.Decompress();
@@ -329,10 +331,11 @@ int main(int argc, char** argv) {
 #endif
   i::FLAG_logfile_per_isolate = false;
 
-  Isolate* isolate = v8::Isolate::New();
+  Isolate::CreateParams params;
+  params.enable_serializer = true;
+  Isolate* isolate = v8::Isolate::New(params);
   { Isolate::Scope isolate_scope(isolate);
     i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
-    internal_isolate->enable_serializer();
 
     Persistent<Context> context;
     {
index 25193b2..a2d5213 100644 (file)
@@ -26,7 +26,7 @@ void Snapshot::ReserveSpaceForLinkedInSnapshot(Deserializer* deserializer) {
 }
 
 
-bool Snapshot::Initialize() {
+bool Snapshot::Initialize(Isolate* isolate) {
   if (size_ > 0) {
     base::ElapsedTimer timer;
     if (FLAG_profile_deserialization) {
@@ -35,7 +35,7 @@ bool Snapshot::Initialize() {
     SnapshotByteSource source(raw_data_, raw_size_);
     Deserializer deserializer(&source);
     ReserveSpaceForLinkedInSnapshot(&deserializer);
-    bool success = V8::Initialize(&deserializer);
+    bool success = isolate->Init(&deserializer);
     if (FLAG_profile_deserialization) {
       double ms = timer.Elapsed().InMillisecondsF();
       PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms);
index 38b7cf4..ee1a8f4 100644 (file)
@@ -46,7 +46,7 @@ bool Snapshot::HaveASnapshotToStartFrom() {
 }
 
 
-bool Snapshot::Initialize() {
+bool Snapshot::Initialize(Isolate* isolate) {
   if (!HaveASnapshotToStartFrom())
     return false;
 
@@ -66,7 +66,7 @@ bool Snapshot::Initialize() {
   deserializer.set_reservation(CELL_SPACE, snapshot_impl_->cell_space_used);
   deserializer.set_reservation(PROPERTY_CELL_SPACE,
                                snapshot_impl_->property_cell_space_used);
-  bool success = V8::Initialize(&deserializer);
+  bool success = isolate->Init(&deserializer);
   if (FLAG_profile_deserialization) {
     double ms = timer.Elapsed().InMillisecondsF();
     PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms);
index b785cf5..3d752a7 100644 (file)
@@ -12,9 +12,9 @@ namespace internal {
 
 class Snapshot {
  public:
-  // Initialize the VM from the internal snapshot. Returns false if no snapshot
-  // could be found.
-  static bool Initialize();
+  // Initialize the Isolate from the internal snapshot. Returns false if no
+  // snapshot could be found.
+  static bool Initialize(Isolate* isolate);
 
   static bool HaveASnapshotToStartFrom();
 
index d4f59a1..62c3da4 100644 (file)
--- a/src/v8.cc
+++ b/src/v8.cc
@@ -33,14 +33,9 @@ v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL;
 v8::Platform* V8::platform_ = NULL;
 
 
-bool V8::Initialize(Deserializer* des) {
+bool V8::Initialize() {
   InitializeOncePerProcess();
-  Isolate* isolate = Isolate::UncheckedCurrent();
-  if (isolate == NULL) return true;
-  if (isolate->IsDead()) return false;
-  if (isolate->IsInitialized()) return true;
-
-  return isolate->Init(des);
+  return true;
 }
 
 
@@ -79,6 +74,8 @@ void V8::InitializeOncePerProcessImpl() {
 
   base::OS::Initialize(FLAG_random_seed, FLAG_hard_abort, FLAG_gc_fake_mmap);
 
+  Isolate::InitializeOncePerProcess();
+
   Sampler::SetUp();
   CpuFeatures::Probe(false);
   init_memcopy_functions();
index 8ae75fb..13c33e1 100644 (file)
--- a/src/v8.h
+++ b/src/v8.h
 namespace v8 {
 namespace internal {
 
-class Deserializer;
-
 class V8 : public AllStatic {
  public:
   // Global actions.
 
-  // If Initialize is called with des == NULL, the initial state is
-  // created from scratch. If a non-null Deserializer is given, the
-  // initial state is created by reading the deserialized data into an
-  // empty heap.
-  static bool Initialize(Deserializer* des);
+  static bool Initialize();
   static void TearDown();
 
   // Report process out of memory. Implementation found in api.cc.
index 3eb189f..f03710a 100644 (file)
@@ -164,8 +164,8 @@ int main(int argc, char* argv[]) {
   v8::V8::InitializeICU();
   v8::Platform* platform = v8::platform::CreateDefaultPlatform();
   v8::V8::InitializePlatform(platform);
-
   v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
+  v8::V8::Initialize();
 
   CcTestArrayBufferAllocator array_buffer_allocator;
   v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
@@ -182,10 +182,6 @@ int main(int argc, char* argv[]) {
   for (int i = 1; i < argc; i++) {
     char* arg = argv[i];
     if (strcmp(arg, "--list") == 0) {
-      // TODO(svenpanne) Serializer::enabled() and Serializer::code_address_map_
-      // are fundamentally broken, so we can't unconditionally initialize and
-      // dispose V8.
-      v8::V8::Initialize();
       PrintTestList(CcTest::last());
       print_run_count = false;
 
index 2ab973c..6d27074 100644 (file)
   static void Test##Name()
 #endif
 
+#ifndef UNINITIALIZED_DEPENDENT_TEST
+#define UNINITIALIZED_DEPENDENT_TEST(Name, Dep)                                \
+  static void Test##Name();                                                    \
+  CcTest register_test_##Name(Test##Name, __FILE__, #Name, #Dep, true, false); \
+  static void Test##Name()
+#endif
+
 #ifndef DISABLED_TEST
 #define DISABLED_TEST(Name)                                                    \
   static void Test##Name();                                                    \
index d065ada..51ad973 100644 (file)
@@ -19486,31 +19486,26 @@ static int CalcFibonacci(v8::Isolate* isolate, int limit) {
 
 class IsolateThread : public v8::base::Thread {
  public:
-  IsolateThread(v8::Isolate* isolate, int fib_limit)
-      : Thread(Options("IsolateThread")),
-        isolate_(isolate),
-        fib_limit_(fib_limit),
-        result_(0) {}
+  explicit IsolateThread(int fib_limit)
+      : Thread(Options("IsolateThread")), fib_limit_(fib_limit), result_(0) {}
 
   void Run() {
-    result_ = CalcFibonacci(isolate_, fib_limit_);
+    v8::Isolate* isolate = v8::Isolate::New();
+    result_ = CalcFibonacci(isolate, fib_limit_);
+    isolate->Dispose();
   }
 
   int result() { return result_; }
 
  private:
-  v8::Isolate* isolate_;
   int fib_limit_;
   int result_;
 };
 
 
 TEST(MultipleIsolatesOnIndividualThreads) {
-  v8::Isolate* isolate1 = v8::Isolate::New();
-  v8::Isolate* isolate2 = v8::Isolate::New();
-
-  IsolateThread thread1(isolate1, 21);
-  IsolateThread thread2(isolate2, 12);
+  IsolateThread thread1(21);
+  IsolateThread thread2(12);
 
   // Compute some fibonacci numbers on 3 threads in 3 isolates.
   thread1.Start();
@@ -19528,9 +19523,6 @@ TEST(MultipleIsolatesOnIndividualThreads) {
   CHECK_EQ(result2, 144);
   CHECK_EQ(result1, thread1.result());
   CHECK_EQ(result2, thread2.result());
-
-  isolate1->Dispose();
-  isolate2->Dispose();
 }
 
 
index da090c6..24819df 100644 (file)
@@ -35,7 +35,6 @@
 using namespace v8::internal;
 
 TEST(List) {
-  v8::internal::V8::Initialize(NULL);
   List<AstNode*>* list = new List<AstNode*>(0);
   CHECK_EQ(0, list->length());
 
index fc1a7fa..43d950d 100644 (file)
@@ -35,7 +35,6 @@
 using namespace v8::internal;
 
 TEST(BitVector) {
-  v8::internal::V8::Initialize(NULL);
   Zone zone(CcTest::i_isolate());
   {
     BitVector v(15, &zone);
index 0adcc0a..69c10c2 100644 (file)
@@ -73,16 +73,23 @@ using ::v8::internal::StrLength;
 class DebugLocalContext {
  public:
   inline DebugLocalContext(
+      v8::Isolate* isolate, v8::ExtensionConfiguration* extensions = 0,
+      v8::Handle<v8::ObjectTemplate> global_template =
+          v8::Handle<v8::ObjectTemplate>(),
+      v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>())
+      : scope_(isolate),
+        context_(v8::Context::New(isolate, extensions, global_template,
+                                  global_object)) {
+    context_->Enter();
+  }
+  inline DebugLocalContext(
       v8::ExtensionConfiguration* extensions = 0,
       v8::Handle<v8::ObjectTemplate> global_template =
           v8::Handle<v8::ObjectTemplate>(),
       v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>())
       : scope_(CcTest::isolate()),
-        context_(
-          v8::Context::New(CcTest::isolate(),
-                           extensions,
-                           global_template,
-                           global_object)) {
+        context_(v8::Context::New(CcTest::isolate(), extensions,
+                                  global_template, global_object)) {
     context_->Enter();
   }
   inline ~DebugLocalContext() {
@@ -137,8 +144,7 @@ static v8::Local<v8::Function> CompileFunction(v8::Isolate* isolate,
                                                const char* source,
                                                const char* function_name) {
   v8::Script::Compile(v8::String::NewFromUtf8(isolate, source))->Run();
-  v8::Local<v8::Object> global =
-      CcTest::isolate()->GetCurrentContext()->Global();
+  v8::Local<v8::Object> global = isolate->GetCurrentContext()->Global();
   return v8::Local<v8::Function>::Cast(
       global->Get(v8::String::NewFromUtf8(isolate, function_name)));
 }
@@ -5155,12 +5161,20 @@ class V8Thread : public v8::base::Thread {
  public:
   V8Thread() : Thread(Options("V8Thread")) {}
   void Run();
+  v8::Isolate* isolate() { return isolate_; }
+
+ private:
+  v8::Isolate* isolate_;
 };
 
 class DebuggerThread : public v8::base::Thread {
  public:
-  DebuggerThread() : Thread(Options("DebuggerThread")) {}
+  explicit DebuggerThread(v8::Isolate* isolate)
+      : Thread(Options("DebuggerThread")), isolate_(isolate) {}
   void Run();
+
+ private:
+  v8::Isolate* isolate_;
 };
 
 
@@ -5203,22 +5217,25 @@ void V8Thread::Run() {
       "\n"
       "foo();\n";
 
-  v8::Isolate* isolate = CcTest::isolate();
-  v8::Isolate::Scope isolate_scope(isolate);
-  DebugLocalContext env;
-  v8::HandleScope scope(env->GetIsolate());
-  v8::Debug::SetMessageHandler(&ThreadedMessageHandler);
-  v8::Handle<v8::ObjectTemplate> global_template =
-      v8::ObjectTemplate::New(env->GetIsolate());
-  global_template->Set(
-      v8::String::NewFromUtf8(env->GetIsolate(), "ThreadedAtBarrier1"),
-      v8::FunctionTemplate::New(isolate, ThreadedAtBarrier1));
-  v8::Handle<v8::Context> context = v8::Context::New(isolate,
-                                                     NULL,
-                                                     global_template);
-  v8::Context::Scope context_scope(context);
-
-  CompileRun(source);
+  isolate_ = v8::Isolate::New();
+  threaded_debugging_barriers.barrier_3.Wait();
+  {
+    v8::Isolate::Scope isolate_scope(isolate_);
+    DebugLocalContext env(isolate_);
+    v8::HandleScope scope(isolate_);
+    v8::Debug::SetMessageHandler(&ThreadedMessageHandler);
+    v8::Handle<v8::ObjectTemplate> global_template =
+        v8::ObjectTemplate::New(env->GetIsolate());
+    global_template->Set(
+        v8::String::NewFromUtf8(env->GetIsolate(), "ThreadedAtBarrier1"),
+        v8::FunctionTemplate::New(isolate_, ThreadedAtBarrier1));
+    v8::Handle<v8::Context> context =
+        v8::Context::New(isolate_, NULL, global_template);
+    v8::Context::Scope context_scope(context);
+
+    CompileRun(source);
+  }
+  isolate_->Dispose();
 }
 
 
@@ -5234,21 +5251,21 @@ void DebuggerThread::Run() {
       "\"type\":\"request\","
       "\"command\":\"continue\"}";
 
-  v8::Isolate* isolate = CcTest::isolate();
   threaded_debugging_barriers.barrier_1.Wait();
-  v8::Debug::DebugBreak(isolate);
+  v8::Debug::DebugBreak(isolate_);
   threaded_debugging_barriers.barrier_2.Wait();
-  v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_1, buffer));
-  v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_2, buffer));
+  v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_1, buffer));
+  v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_2, buffer));
 }
 
 
 TEST(ThreadedDebugging) {
-  DebuggerThread debugger_thread;
   V8Thread v8_thread;
 
   // Create a V8 environment
   v8_thread.Start();
+  threaded_debugging_barriers.barrier_3.Wait();
+  DebuggerThread debugger_thread(v8_thread.isolate());
   debugger_thread.Start();
 
   v8_thread.Join();
@@ -5267,17 +5284,24 @@ class BreakpointsV8Thread : public v8::base::Thread {
  public:
   BreakpointsV8Thread() : Thread(Options("BreakpointsV8Thread")) {}
   void Run();
+
+  v8::Isolate* isolate() { return isolate_; }
+
+ private:
+  v8::Isolate* isolate_;
 };
 
 class BreakpointsDebuggerThread : public v8::base::Thread {
  public:
-  explicit BreakpointsDebuggerThread(bool global_evaluate)
+  BreakpointsDebuggerThread(bool global_evaluate, v8::Isolate* isolate)
       : Thread(Options("BreakpointsDebuggerThread")),
-        global_evaluate_(global_evaluate) {}
+        global_evaluate_(global_evaluate),
+        isolate_(isolate) {}
   void Run();
 
  private:
   bool global_evaluate_;
+  v8::Isolate* isolate_;
 };
 
 
@@ -5322,16 +5346,20 @@ void BreakpointsV8Thread::Run() {
   const char* source_2 = "cat(17);\n"
     "cat(19);\n";
 
-  v8::Isolate* isolate = CcTest::isolate();
-  v8::Isolate::Scope isolate_scope(isolate);
-  DebugLocalContext env;
-  v8::HandleScope scope(isolate);
-  v8::Debug::SetMessageHandler(&BreakpointsMessageHandler);
-
-  CompileRun(source_1);
-  breakpoints_barriers->barrier_1.Wait();
-  breakpoints_barriers->barrier_2.Wait();
-  CompileRun(source_2);
+  isolate_ = v8::Isolate::New();
+  breakpoints_barriers->barrier_3.Wait();
+  {
+    v8::Isolate::Scope isolate_scope(isolate_);
+    DebugLocalContext env(isolate_);
+    v8::HandleScope scope(isolate_);
+    v8::Debug::SetMessageHandler(&BreakpointsMessageHandler);
+
+    CompileRun(source_1);
+    breakpoints_barriers->barrier_1.Wait();
+    breakpoints_barriers->barrier_2.Wait();
+    CompileRun(source_2);
+  }
+  isolate_->Dispose();
 }
 
 
@@ -5397,14 +5425,12 @@ void BreakpointsDebuggerThread::Run() {
       "\"command\":\"continue\"}";
 
 
-  v8::Isolate* isolate = CcTest::isolate();
-  v8::Isolate::Scope isolate_scope(isolate);
   // v8 thread initializes, runs source_1
   breakpoints_barriers->barrier_1.Wait();
   // 1:Set breakpoint in cat() (will get id 1).
-  v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_1, buffer));
+  v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_1, buffer));
   // 2:Set breakpoint in dog() (will get id 2).
-  v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_2, buffer));
+  v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_2, buffer));
   breakpoints_barriers->barrier_2.Wait();
   // V8 thread starts compiling source_2.
   // Automatic break happens, to run queued commands
@@ -5416,43 +5442,42 @@ void BreakpointsDebuggerThread::Run() {
   // Must have hit breakpoint #1.
   CHECK_EQ(1, break_event_breakpoint_id);
   // 4:Evaluate dog() (which has a breakpoint).
-  v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_3, buffer));
+  v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_3, buffer));
   // V8 thread hits breakpoint in dog().
   breakpoints_barriers->semaphore_1.Wait();  // wait for break event
   // Must have hit breakpoint #2.
   CHECK_EQ(2, break_event_breakpoint_id);
   // 5:Evaluate (x + 1).
-  v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_4, buffer));
+  v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_4, buffer));
   // Evaluate (x + 1) finishes.
   breakpoints_barriers->semaphore_1.Wait();
   // Must have result 108.
   CHECK_EQ(108, evaluate_int_result);
   // 6:Continue evaluation of dog().
-  v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_5, buffer));
+  v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_5, buffer));
   // Evaluate dog() finishes.
   breakpoints_barriers->semaphore_1.Wait();
   // Must have result 107.
   CHECK_EQ(107, evaluate_int_result);
   // 7:Continue evaluation of source_2, finish cat(17), hit breakpoint
   // in cat(19).
-  v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_6, buffer));
+  v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_6, buffer));
   // Message callback gets break event.
   breakpoints_barriers->semaphore_1.Wait();  // wait for break event
   // Must have hit breakpoint #1.
   CHECK_EQ(1, break_event_breakpoint_id);
   // 8: Evaluate dog() with breaks disabled.
-  v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_7, buffer));
+  v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_7, buffer));
   // Evaluate dog() finishes.
   breakpoints_barriers->semaphore_1.Wait();
   // Must have result 116.
   CHECK_EQ(116, evaluate_int_result);
   // 9: Continue evaluation of source2, reach end.
-  v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_8, buffer));
+  v8::Debug::SendCommand(isolate_, buffer, AsciiToUtf16(command_8, buffer));
 }
 
 
 void TestRecursiveBreakpointsGeneric(bool global_evaluate) {
-  BreakpointsDebuggerThread breakpoints_debugger_thread(global_evaluate);
   BreakpointsV8Thread breakpoints_v8_thread;
 
   // Create a V8 environment
@@ -5460,6 +5485,9 @@ void TestRecursiveBreakpointsGeneric(bool global_evaluate) {
   breakpoints_barriers = &stack_allocated_breakpoints_barriers;
 
   breakpoints_v8_thread.Start();
+  breakpoints_barriers->barrier_3.Wait();
+  BreakpointsDebuggerThread breakpoints_debugger_thread(
+      global_evaluate, breakpoints_v8_thread.isolate());
   breakpoints_debugger_thread.Start();
 
   breakpoints_v8_thread.Join();
index 262ffc1..a201ccd 100644 (file)
@@ -98,8 +98,8 @@ class AllowNativesSyntaxNoInlining {
 
 // Abort any ongoing incremental marking to make sure that all weak global
 // handle callbacks are processed.
-static void NonIncrementalGC() {
-  CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
+static void NonIncrementalGC(i::Isolate* isolate) {
+  isolate->heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
 }
 
 
@@ -127,7 +127,7 @@ TEST(DeoptimizeSimple) {
         "function f() { g(); };"
         "f();");
   }
-  NonIncrementalGC();
+  NonIncrementalGC(CcTest::i_isolate());
 
   CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
   CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
@@ -143,7 +143,7 @@ TEST(DeoptimizeSimple) {
         "function f(x) { if (x) { g(); } else { return } };"
         "f(true);");
   }
-  NonIncrementalGC();
+  NonIncrementalGC(CcTest::i_isolate());
 
   CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
   CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
@@ -167,7 +167,7 @@ TEST(DeoptimizeSimpleWithArguments) {
         "function f(x, y, z) { g(1,x); y+z; };"
         "f(1, \"2\", false);");
   }
-  NonIncrementalGC();
+  NonIncrementalGC(CcTest::i_isolate());
 
   CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
   CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
@@ -184,7 +184,7 @@ TEST(DeoptimizeSimpleWithArguments) {
         "function f(x, y, z) { if (x) { g(x, y); } else { return y + z; } };"
         "f(true, 1, \"2\");");
   }
-  NonIncrementalGC();
+  NonIncrementalGC(CcTest::i_isolate());
 
   CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
   CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
@@ -209,7 +209,7 @@ TEST(DeoptimizeSimpleNested) {
         "function g(z) { count++; %DeoptimizeFunction(f); return z;}"
         "function f(x,y,z) { return h(x, y, g(z)); };"
         "result = f(1, 2, 3);");
-    NonIncrementalGC();
+    NonIncrementalGC(CcTest::i_isolate());
 
     CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
     CHECK_EQ(6, env->Global()->Get(v8_str("result"))->Int32Value());
@@ -235,7 +235,7 @@ TEST(DeoptimizeRecursive) {
         "function f(x) { calls++; if (x > 0) { f(x - 1); } else { g(); } };"
         "f(10);");
   }
-  NonIncrementalGC();
+  NonIncrementalGC(CcTest::i_isolate());
 
   CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
   CHECK_EQ(11, env->Global()->Get(v8_str("calls"))->Int32Value());
@@ -268,7 +268,7 @@ TEST(DeoptimizeMultiple) {
         "function f1(x) { return f2(x + 1, x + 1) + x; };"
         "result = f1(1);");
   }
-  NonIncrementalGC();
+  NonIncrementalGC(CcTest::i_isolate());
 
   CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
   CHECK_EQ(14, env->Global()->Get(v8_str("result"))->Int32Value());
@@ -290,7 +290,7 @@ TEST(DeoptimizeConstructor) {
         "function f() {  g(); };"
         "result = new f() instanceof f;");
   }
-  NonIncrementalGC();
+  NonIncrementalGC(CcTest::i_isolate());
 
   CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
   CHECK(env->Global()->Get(v8_str("result"))->IsTrue());
@@ -307,7 +307,7 @@ TEST(DeoptimizeConstructor) {
         "result = new f(1, 2);"
         "result = result.x + result.y;");
   }
-  NonIncrementalGC();
+  NonIncrementalGC(CcTest::i_isolate());
 
   CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
   CHECK_EQ(3, env->Global()->Get(v8_str("result"))->Int32Value());
@@ -337,7 +337,7 @@ TEST(DeoptimizeConstructorMultiple) {
         "function f1(x) { this.result = new f2(x + 1, x + 1).result + x; };"
         "result = new f1(1).result;");
   }
-  NonIncrementalGC();
+  NonIncrementalGC(CcTest::i_isolate());
 
   CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
   CHECK_EQ(14, env->Global()->Get(v8_str("result"))->Int32Value());
@@ -345,51 +345,61 @@ TEST(DeoptimizeConstructorMultiple) {
 }
 
 
-TEST(DeoptimizeBinaryOperationADDString) {
+UNINITIALIZED_TEST(DeoptimizeBinaryOperationADDString) {
   i::FLAG_turbo_deoptimization = true;
   i::FLAG_concurrent_recompilation = false;
   AllowNativesSyntaxNoInlining options;
-  LocalContext env;
-  v8::HandleScope scope(env->GetIsolate());
-
-  const char* f_source = "function f(x, y) { return x + y; };";
-
+  v8::Isolate* isolate = v8::Isolate::New();
+  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+  isolate->Enter();
   {
-    // Compile function f and collect to type feedback to insert binary op stub
-    // call in the optimized code.
-    i::FLAG_prepare_always_opt = true;
-    CompileRun("var count = 0;"
-               "var result = 0;"
-               "var deopt = false;"
-               "function X() { };"
-               "X.prototype.toString = function () {"
-               "  if (deopt) { count++; %DeoptimizeFunction(f); } return 'an X'"
-               "};");
-    CompileRun(f_source);
-    CompileRun("for (var i = 0; i < 5; i++) {"
-               "  f('a+', new X());"
-               "};");
-
-    // Compile an optimized version of f.
-    i::FLAG_always_opt = true;
-    CompileRun(f_source);
-    CompileRun("f('a+', new X());");
-    CHECK(!CcTest::i_isolate()->use_crankshaft() ||
-          GetJSFunction(env->Global(), "f")->IsOptimized());
-
-    // Call f and force deoptimization while processing the binary operation.
-    CompileRun("deopt = true;"
-               "var result = f('a+', new X());");
-  }
-  NonIncrementalGC();
+    LocalContext env(isolate);
+    v8::HandleScope scope(env->GetIsolate());
+
+    const char* f_source = "function f(x, y) { return x + y; };";
+
+    {
+      // Compile function f and collect to type feedback to insert binary op
+      // stub call in the optimized code.
+      i::FLAG_prepare_always_opt = true;
+      CompileRun(
+          "var count = 0;"
+          "var result = 0;"
+          "var deopt = false;"
+          "function X() { };"
+          "X.prototype.toString = function () {"
+          "  if (deopt) { count++; %DeoptimizeFunction(f); } return 'an X'"
+          "};");
+      CompileRun(f_source);
+      CompileRun(
+          "for (var i = 0; i < 5; i++) {"
+          "  f('a+', new X());"
+          "};");
+
+      // Compile an optimized version of f.
+      i::FLAG_always_opt = true;
+      CompileRun(f_source);
+      CompileRun("f('a+', new X());");
+      CHECK(!i_isolate->use_crankshaft() ||
+            GetJSFunction(env->Global(), "f")->IsOptimized());
+
+      // Call f and force deoptimization while processing the binary operation.
+      CompileRun(
+          "deopt = true;"
+          "var result = f('a+', new X());");
+    }
+    NonIncrementalGC(i_isolate);
 
-  CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
-  CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
-  v8::Handle<v8::Value> result = env->Global()->Get(v8_str("result"));
-  CHECK(result->IsString());
-  v8::String::Utf8Value utf8(result);
-  CHECK_EQ("a+an X", *utf8);
-  CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
+    CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
+    CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+    v8::Handle<v8::Value> result = env->Global()->Get(v8_str("result"));
+    CHECK(result->IsString());
+    v8::String::Utf8Value utf8(result);
+    CHECK_EQ("a+an X", *utf8);
+    CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
+  }
+  isolate->Exit();
+  isolate->Dispose();
 }
 
 
@@ -406,6 +416,7 @@ static void CompileConstructorWithDeoptimizingValueOf() {
 
 static void TestDeoptimizeBinaryOpHelper(LocalContext* env,
                                          const char* binary_op) {
+  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>((*env)->GetIsolate());
   EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> f_source_buffer;
   SNPrintF(f_source_buffer,
            "function f(x, y) { return x %s y; };",
@@ -426,290 +437,355 @@ static void TestDeoptimizeBinaryOpHelper(LocalContext* env,
   i::FLAG_always_opt = true;
   CompileRun(f_source);
   CompileRun("f(7, new X());");
-  CHECK(!CcTest::i_isolate()->use_crankshaft() ||
+  CHECK(!i_isolate->use_crankshaft() ||
         GetJSFunction((*env)->Global(), "f")->IsOptimized());
 
   // Call f and force deoptimization while processing the binary operation.
   CompileRun("deopt = true;"
              "var result = f(7, new X());");
-  NonIncrementalGC();
+  NonIncrementalGC(i_isolate);
   CHECK(!GetJSFunction((*env)->Global(), "f")->IsOptimized());
 }
 
 
-TEST(DeoptimizeBinaryOperationADD) {
+UNINITIALIZED_TEST(DeoptimizeBinaryOperationADD) {
   i::FLAG_turbo_deoptimization = true;
   i::FLAG_concurrent_recompilation = false;
-  LocalContext env;
-  v8::HandleScope scope(env->GetIsolate());
+  v8::Isolate* isolate = v8::Isolate::New();
+  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+  isolate->Enter();
+  {
+    LocalContext env(isolate);
+    v8::HandleScope scope(env->GetIsolate());
 
-  TestDeoptimizeBinaryOpHelper(&env, "+");
+    TestDeoptimizeBinaryOpHelper(&env, "+");
 
-  CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
-  CHECK_EQ(15, env->Global()->Get(v8_str("result"))->Int32Value());
-  CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
+    CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+    CHECK_EQ(15, env->Global()->Get(v8_str("result"))->Int32Value());
+    CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
+  }
+  isolate->Exit();
+  isolate->Dispose();
 }
 
 
-TEST(DeoptimizeBinaryOperationSUB) {
+UNINITIALIZED_TEST(DeoptimizeBinaryOperationSUB) {
   i::FLAG_turbo_deoptimization = true;
   i::FLAG_concurrent_recompilation = false;
-  LocalContext env;
-  v8::HandleScope scope(env->GetIsolate());
+  v8::Isolate* isolate = v8::Isolate::New();
+  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+  isolate->Enter();
+  {
+    LocalContext env(isolate);
+    v8::HandleScope scope(env->GetIsolate());
 
-  TestDeoptimizeBinaryOpHelper(&env, "-");
+    TestDeoptimizeBinaryOpHelper(&env, "-");
 
-  CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
-  CHECK_EQ(-1, env->Global()->Get(v8_str("result"))->Int32Value());
-  CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
+    CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+    CHECK_EQ(-1, env->Global()->Get(v8_str("result"))->Int32Value());
+    CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
+  }
+  isolate->Exit();
+  isolate->Dispose();
 }
 
 
-TEST(DeoptimizeBinaryOperationMUL) {
+UNINITIALIZED_TEST(DeoptimizeBinaryOperationMUL) {
   i::FLAG_turbo_deoptimization = true;
   i::FLAG_concurrent_recompilation = false;
-  LocalContext env;
-  v8::HandleScope scope(env->GetIsolate());
+  v8::Isolate* isolate = v8::Isolate::New();
+  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+  isolate->Enter();
+  {
+    LocalContext env(isolate);
+    v8::HandleScope scope(env->GetIsolate());
 
-  TestDeoptimizeBinaryOpHelper(&env, "*");
+    TestDeoptimizeBinaryOpHelper(&env, "*");
 
-  CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
-  CHECK_EQ(56, env->Global()->Get(v8_str("result"))->Int32Value());
-  CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
+    CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+    CHECK_EQ(56, env->Global()->Get(v8_str("result"))->Int32Value());
+    CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
+  }
+  isolate->Exit();
+  isolate->Dispose();
 }
 
 
-TEST(DeoptimizeBinaryOperationDIV) {
+UNINITIALIZED_TEST(DeoptimizeBinaryOperationDIV) {
   i::FLAG_turbo_deoptimization = true;
   i::FLAG_concurrent_recompilation = false;
-  LocalContext env;
-  v8::HandleScope scope(env->GetIsolate());
+  v8::Isolate* isolate = v8::Isolate::New();
+  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+  isolate->Enter();
+  {
+    LocalContext env(isolate);
+    v8::HandleScope scope(env->GetIsolate());
 
-  TestDeoptimizeBinaryOpHelper(&env, "/");
+    TestDeoptimizeBinaryOpHelper(&env, "/");
 
-  CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
-  CHECK_EQ(0, env->Global()->Get(v8_str("result"))->Int32Value());
-  CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
+    CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+    CHECK_EQ(0, env->Global()->Get(v8_str("result"))->Int32Value());
+    CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
+  }
+  isolate->Exit();
+  isolate->Dispose();
 }
 
 
-TEST(DeoptimizeBinaryOperationMOD) {
+UNINITIALIZED_TEST(DeoptimizeBinaryOperationMOD) {
   i::FLAG_turbo_deoptimization = true;
   i::FLAG_concurrent_recompilation = false;
-  LocalContext env;
-  v8::HandleScope scope(env->GetIsolate());
+  v8::Isolate* isolate = v8::Isolate::New();
+  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+  isolate->Enter();
+  {
+    LocalContext env(isolate);
+    v8::HandleScope scope(env->GetIsolate());
 
-  TestDeoptimizeBinaryOpHelper(&env, "%");
+    TestDeoptimizeBinaryOpHelper(&env, "%");
 
-  CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
-  CHECK_EQ(7, env->Global()->Get(v8_str("result"))->Int32Value());
-  CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
+    CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+    CHECK_EQ(7, env->Global()->Get(v8_str("result"))->Int32Value());
+    CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
+  }
+  isolate->Exit();
+  isolate->Dispose();
 }
 
 
-TEST(DeoptimizeCompare) {
+UNINITIALIZED_TEST(DeoptimizeCompare) {
   i::FLAG_turbo_deoptimization = true;
   i::FLAG_concurrent_recompilation = false;
-  LocalContext env;
-  v8::HandleScope scope(env->GetIsolate());
-
-  const char* f_source = "function f(x, y) { return x < y; };";
-
+  v8::Isolate* isolate = v8::Isolate::New();
+  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+  isolate->Enter();
   {
-    AllowNativesSyntaxNoInlining options;
-    // Compile function f and collect to type feedback to insert compare ic
-    // call in the optimized code.
-    i::FLAG_prepare_always_opt = true;
-    CompileRun("var count = 0;"
-               "var result = 0;"
-               "var deopt = false;"
-               "function X() { };"
-               "X.prototype.toString = function () {"
-               "  if (deopt) { count++; %DeoptimizeFunction(f); } return 'b'"
-               "};");
-    CompileRun(f_source);
-    CompileRun("for (var i = 0; i < 5; i++) {"
-               "  f('a', new X());"
-               "};");
-
-    // Compile an optimized version of f.
-    i::FLAG_always_opt = true;
-    CompileRun(f_source);
-    CompileRun("f('a', new X());");
-    CHECK(!CcTest::i_isolate()->use_crankshaft() ||
-          GetJSFunction(env->Global(), "f")->IsOptimized());
-
-    // Call f and force deoptimization while processing the comparison.
-    CompileRun("deopt = true;"
-               "var result = f('a', new X());");
-  }
-  NonIncrementalGC();
+    LocalContext env(isolate);
+    v8::HandleScope scope(env->GetIsolate());
+
+    const char* f_source = "function f(x, y) { return x < y; };";
+
+    {
+      AllowNativesSyntaxNoInlining options;
+      // Compile function f and collect to type feedback to insert compare ic
+      // call in the optimized code.
+      i::FLAG_prepare_always_opt = true;
+      CompileRun(
+          "var count = 0;"
+          "var result = 0;"
+          "var deopt = false;"
+          "function X() { };"
+          "X.prototype.toString = function () {"
+          "  if (deopt) { count++; %DeoptimizeFunction(f); } return 'b'"
+          "};");
+      CompileRun(f_source);
+      CompileRun(
+          "for (var i = 0; i < 5; i++) {"
+          "  f('a', new X());"
+          "};");
+
+      // Compile an optimized version of f.
+      i::FLAG_always_opt = true;
+      CompileRun(f_source);
+      CompileRun("f('a', new X());");
+      CHECK(!i_isolate->use_crankshaft() ||
+            GetJSFunction(env->Global(), "f")->IsOptimized());
+
+      // Call f and force deoptimization while processing the comparison.
+      CompileRun(
+          "deopt = true;"
+          "var result = f('a', new X());");
+    }
+    NonIncrementalGC(i_isolate);
 
-  CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
-  CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
-  CHECK_EQ(true, env->Global()->Get(v8_str("result"))->BooleanValue());
-  CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(CcTest::i_isolate()));
+    CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized());
+    CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+    CHECK_EQ(true, env->Global()->Get(v8_str("result"))->BooleanValue());
+    CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(i_isolate));
+  }
+  isolate->Exit();
+  isolate->Dispose();
 }
 
 
-TEST(DeoptimizeLoadICStoreIC) {
+UNINITIALIZED_TEST(DeoptimizeLoadICStoreIC) {
   i::FLAG_turbo_deoptimization = true;
   i::FLAG_concurrent_recompilation = false;
-  LocalContext env;
-  v8::HandleScope scope(env->GetIsolate());
-
-  // Functions to generate load/store/keyed load/keyed store IC calls.
-  const char* f1_source = "function f1(x) { return x.y; };";
-  const char* g1_source = "function g1(x) { x.y = 1; };";
-  const char* f2_source = "function f2(x, y) { return x[y]; };";
-  const char* g2_source = "function g2(x, y) { x[y] = 1; };";
-
+  v8::Isolate* isolate = v8::Isolate::New();
+  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+  isolate->Enter();
   {
-    AllowNativesSyntaxNoInlining options;
-    // Compile functions and collect to type feedback to insert ic
-    // calls in the optimized code.
-    i::FLAG_prepare_always_opt = true;
-    CompileRun("var count = 0;"
-               "var result = 0;"
-               "var deopt = false;"
-               "function X() { };"
-               "X.prototype.__defineGetter__('y', function () {"
-               "  if (deopt) { count++; %DeoptimizeFunction(f1); };"
-               "  return 13;"
-               "});"
-               "X.prototype.__defineSetter__('y', function () {"
-               "  if (deopt) { count++; %DeoptimizeFunction(g1); };"
-               "});"
-               "X.prototype.__defineGetter__('z', function () {"
-               "  if (deopt) { count++; %DeoptimizeFunction(f2); };"
-               "  return 13;"
-               "});"
-               "X.prototype.__defineSetter__('z', function () {"
-               "  if (deopt) { count++; %DeoptimizeFunction(g2); };"
-               "});");
-    CompileRun(f1_source);
-    CompileRun(g1_source);
-    CompileRun(f2_source);
-    CompileRun(g2_source);
-    CompileRun("for (var i = 0; i < 5; i++) {"
-               "  f1(new X());"
-               "  g1(new X());"
-               "  f2(new X(), 'z');"
-               "  g2(new X(), 'z');"
-               "};");
-
-    // Compile an optimized version of the functions.
-    i::FLAG_always_opt = true;
-    CompileRun(f1_source);
-    CompileRun(g1_source);
-    CompileRun(f2_source);
-    CompileRun(g2_source);
-    CompileRun("f1(new X());");
-    CompileRun("g1(new X());");
-    CompileRun("f2(new X(), 'z');");
-    CompileRun("g2(new X(), 'z');");
-    if (CcTest::i_isolate()->use_crankshaft()) {
-      CHECK(GetJSFunction(env->Global(), "f1")->IsOptimized());
-      CHECK(GetJSFunction(env->Global(), "g1")->IsOptimized());
-      CHECK(GetJSFunction(env->Global(), "f2")->IsOptimized());
-      CHECK(GetJSFunction(env->Global(), "g2")->IsOptimized());
+    LocalContext env(isolate);
+    v8::HandleScope scope(env->GetIsolate());
+
+    // Functions to generate load/store/keyed load/keyed store IC calls.
+    const char* f1_source = "function f1(x) { return x.y; };";
+    const char* g1_source = "function g1(x) { x.y = 1; };";
+    const char* f2_source = "function f2(x, y) { return x[y]; };";
+    const char* g2_source = "function g2(x, y) { x[y] = 1; };";
+
+    {
+      AllowNativesSyntaxNoInlining options;
+      // Compile functions and collect to type feedback to insert ic
+      // calls in the optimized code.
+      i::FLAG_prepare_always_opt = true;
+      CompileRun(
+          "var count = 0;"
+          "var result = 0;"
+          "var deopt = false;"
+          "function X() { };"
+          "X.prototype.__defineGetter__('y', function () {"
+          "  if (deopt) { count++; %DeoptimizeFunction(f1); };"
+          "  return 13;"
+          "});"
+          "X.prototype.__defineSetter__('y', function () {"
+          "  if (deopt) { count++; %DeoptimizeFunction(g1); };"
+          "});"
+          "X.prototype.__defineGetter__('z', function () {"
+          "  if (deopt) { count++; %DeoptimizeFunction(f2); };"
+          "  return 13;"
+          "});"
+          "X.prototype.__defineSetter__('z', function () {"
+          "  if (deopt) { count++; %DeoptimizeFunction(g2); };"
+          "});");
+      CompileRun(f1_source);
+      CompileRun(g1_source);
+      CompileRun(f2_source);
+      CompileRun(g2_source);
+      CompileRun(
+          "for (var i = 0; i < 5; i++) {"
+          "  f1(new X());"
+          "  g1(new X());"
+          "  f2(new X(), 'z');"
+          "  g2(new X(), 'z');"
+          "};");
+
+      // Compile an optimized version of the functions.
+      i::FLAG_always_opt = true;
+      CompileRun(f1_source);
+      CompileRun(g1_source);
+      CompileRun(f2_source);
+      CompileRun(g2_source);
+      CompileRun("f1(new X());");
+      CompileRun("g1(new X());");
+      CompileRun("f2(new X(), 'z');");
+      CompileRun("g2(new X(), 'z');");
+      if (i_isolate->use_crankshaft()) {
+        CHECK(GetJSFunction(env->Global(), "f1")->IsOptimized());
+        CHECK(GetJSFunction(env->Global(), "g1")->IsOptimized());
+        CHECK(GetJSFunction(env->Global(), "f2")->IsOptimized());
+        CHECK(GetJSFunction(env->Global(), "g2")->IsOptimized());
+      }
+
+      // Call functions and force deoptimization while processing the ics.
+      CompileRun(
+          "deopt = true;"
+          "var result = f1(new X());"
+          "g1(new X());"
+          "f2(new X(), 'z');"
+          "g2(new X(), 'z');");
     }
-
-    // Call functions and force deoptimization while processing the ics.
-    CompileRun("deopt = true;"
-               "var result = f1(new X());"
-               "g1(new X());"
-               "f2(new X(), 'z');"
-               "g2(new X(), 'z');");
+    NonIncrementalGC(i_isolate);
+
+    CHECK(!GetJSFunction(env->Global(), "f1")->IsOptimized());
+    CHECK(!GetJSFunction(env->Global(), "g1")->IsOptimized());
+    CHECK(!GetJSFunction(env->Global(), "f2")->IsOptimized());
+    CHECK(!GetJSFunction(env->Global(), "g2")->IsOptimized());
+    CHECK_EQ(4, env->Global()->Get(v8_str("count"))->Int32Value());
+    CHECK_EQ(13, env->Global()->Get(v8_str("result"))->Int32Value());
   }
-  NonIncrementalGC();
-
-  CHECK(!GetJSFunction(env->Global(), "f1")->IsOptimized());
-  CHECK(!GetJSFunction(env->Global(), "g1")->IsOptimized());
-  CHECK(!GetJSFunction(env->Global(), "f2")->IsOptimized());
-  CHECK(!GetJSFunction(env->Global(), "g2")->IsOptimized());
-  CHECK_EQ(4, env->Global()->Get(v8_str("count"))->Int32Value());
-  CHECK_EQ(13, env->Global()->Get(v8_str("result"))->Int32Value());
+  isolate->Exit();
+  isolate->Dispose();
 }
 
 
-TEST(DeoptimizeLoadICStoreICNested) {
+UNINITIALIZED_TEST(DeoptimizeLoadICStoreICNested) {
   i::FLAG_turbo_deoptimization = true;
   i::FLAG_concurrent_recompilation = false;
-  LocalContext env;
-  v8::HandleScope scope(env->GetIsolate());
-
-  // Functions to generate load/store/keyed load/keyed store IC calls.
-  const char* f1_source = "function f1(x) { return x.y; };";
-  const char* g1_source = "function g1(x) { x.y = 1; };";
-  const char* f2_source = "function f2(x, y) { return x[y]; };";
-  const char* g2_source = "function g2(x, y) { x[y] = 1; };";
-
+  v8::Isolate* isolate = v8::Isolate::New();
+  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+  isolate->Enter();
   {
-    AllowNativesSyntaxNoInlining options;
-    // Compile functions and collect to type feedback to insert ic
-    // calls in the optimized code.
-    i::FLAG_prepare_always_opt = true;
-    CompileRun("var count = 0;"
-               "var result = 0;"
-               "var deopt = false;"
-               "function X() { };"
-               "X.prototype.__defineGetter__('y', function () {"
-               "  g1(this);"
-               "  return 13;"
-               "});"
-               "X.prototype.__defineSetter__('y', function () {"
-               "  f2(this, 'z');"
-               "});"
-               "X.prototype.__defineGetter__('z', function () {"
-               "  g2(this, 'z');"
-               "});"
-               "X.prototype.__defineSetter__('z', function () {"
-               "  if (deopt) {"
-               "    count++;"
-               "    %DeoptimizeFunction(f1);"
-               "    %DeoptimizeFunction(g1);"
-               "    %DeoptimizeFunction(f2);"
-               "    %DeoptimizeFunction(g2); };"
-               "});");
-    CompileRun(f1_source);
-    CompileRun(g1_source);
-    CompileRun(f2_source);
-    CompileRun(g2_source);
-    CompileRun("for (var i = 0; i < 5; i++) {"
-               "  f1(new X());"
-               "  g1(new X());"
-               "  f2(new X(), 'z');"
-               "  g2(new X(), 'z');"
-               "};");
-
-    // Compile an optimized version of the functions.
-    i::FLAG_always_opt = true;
-    CompileRun(f1_source);
-    CompileRun(g1_source);
-    CompileRun(f2_source);
-    CompileRun(g2_source);
-    CompileRun("f1(new X());");
-    CompileRun("g1(new X());");
-    CompileRun("f2(new X(), 'z');");
-    CompileRun("g2(new X(), 'z');");
-    if (CcTest::i_isolate()->use_crankshaft()) {
-      CHECK(GetJSFunction(env->Global(), "f1")->IsOptimized());
-      CHECK(GetJSFunction(env->Global(), "g1")->IsOptimized());
-      CHECK(GetJSFunction(env->Global(), "f2")->IsOptimized());
-      CHECK(GetJSFunction(env->Global(), "g2")->IsOptimized());
+    LocalContext env(isolate);
+    v8::HandleScope scope(env->GetIsolate());
+
+    // Functions to generate load/store/keyed load/keyed store IC calls.
+    const char* f1_source = "function f1(x) { return x.y; };";
+    const char* g1_source = "function g1(x) { x.y = 1; };";
+    const char* f2_source = "function f2(x, y) { return x[y]; };";
+    const char* g2_source = "function g2(x, y) { x[y] = 1; };";
+
+    {
+      AllowNativesSyntaxNoInlining options;
+      // Compile functions and collect to type feedback to insert ic
+      // calls in the optimized code.
+      i::FLAG_prepare_always_opt = true;
+      CompileRun(
+          "var count = 0;"
+          "var result = 0;"
+          "var deopt = false;"
+          "function X() { };"
+          "X.prototype.__defineGetter__('y', function () {"
+          "  g1(this);"
+          "  return 13;"
+          "});"
+          "X.prototype.__defineSetter__('y', function () {"
+          "  f2(this, 'z');"
+          "});"
+          "X.prototype.__defineGetter__('z', function () {"
+          "  g2(this, 'z');"
+          "});"
+          "X.prototype.__defineSetter__('z', function () {"
+          "  if (deopt) {"
+          "    count++;"
+          "    %DeoptimizeFunction(f1);"
+          "    %DeoptimizeFunction(g1);"
+          "    %DeoptimizeFunction(f2);"
+          "    %DeoptimizeFunction(g2); };"
+          "});");
+      CompileRun(f1_source);
+      CompileRun(g1_source);
+      CompileRun(f2_source);
+      CompileRun(g2_source);
+      CompileRun(
+          "for (var i = 0; i < 5; i++) {"
+          "  f1(new X());"
+          "  g1(new X());"
+          "  f2(new X(), 'z');"
+          "  g2(new X(), 'z');"
+          "};");
+
+      // Compile an optimized version of the functions.
+      i::FLAG_always_opt = true;
+      CompileRun(f1_source);
+      CompileRun(g1_source);
+      CompileRun(f2_source);
+      CompileRun(g2_source);
+      CompileRun("f1(new X());");
+      CompileRun("g1(new X());");
+      CompileRun("f2(new X(), 'z');");
+      CompileRun("g2(new X(), 'z');");
+      if (i_isolate->use_crankshaft()) {
+        CHECK(GetJSFunction(env->Global(), "f1")->IsOptimized());
+        CHECK(GetJSFunction(env->Global(), "g1")->IsOptimized());
+        CHECK(GetJSFunction(env->Global(), "f2")->IsOptimized());
+        CHECK(GetJSFunction(env->Global(), "g2")->IsOptimized());
+      }
+
+      // Call functions and force deoptimization while processing the ics.
+      CompileRun(
+          "deopt = true;"
+          "var result = f1(new X());");
     }
+    NonIncrementalGC(i_isolate);
 
-    // Call functions and force deoptimization while processing the ics.
-    CompileRun("deopt = true;"
-               "var result = f1(new X());");
+    CHECK(!GetJSFunction(env->Global(), "f1")->IsOptimized());
+    CHECK(!GetJSFunction(env->Global(), "g1")->IsOptimized());
+    CHECK(!GetJSFunction(env->Global(), "f2")->IsOptimized());
+    CHECK(!GetJSFunction(env->Global(), "g2")->IsOptimized());
+    CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
+    CHECK_EQ(13, env->Global()->Get(v8_str("result"))->Int32Value());
   }
-  NonIncrementalGC();
-
-  CHECK(!GetJSFunction(env->Global(), "f1")->IsOptimized());
-  CHECK(!GetJSFunction(env->Global(), "g1")->IsOptimized());
-  CHECK(!GetJSFunction(env->Global(), "f2")->IsOptimized());
-  CHECK(!GetJSFunction(env->Global(), "g2")->IsOptimized());
-  CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value());
-  CHECK_EQ(13, env->Global()->Get(v8_str("result"))->Int32Value());
+  isolate->Exit();
+  isolate->Dispose();
 }
index aca4b9d..fcee9f4 100644 (file)
@@ -1052,53 +1052,61 @@ TEST(Regression39128) {
 }
 
 
-TEST(TestCodeFlushing) {
+UNINITIALIZED_TEST(TestCodeFlushing) {
   // If we do not flush code this test is invalid.
   if (!FLAG_flush_code) return;
   i::FLAG_allow_natives_syntax = true;
   i::FLAG_optimize_for_size = false;
-  CcTest::InitializeVM();
-  Isolate* isolate = CcTest::i_isolate();
-  Factory* factory = isolate->factory();
-  v8::HandleScope scope(CcTest::isolate());
-  const char* source = "function foo() {"
-                       "  var x = 42;"
-                       "  var y = 42;"
-                       "  var z = x + y;"
-                       "};"
-                       "foo()";
-  Handle<String> foo_name = factory->InternalizeUtf8String("foo");
+  v8::Isolate* isolate = v8::Isolate::New();
+  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+  isolate->Enter();
+  Factory* factory = i_isolate->factory();
+  {
+    v8::HandleScope scope(isolate);
+    v8::Context::New(isolate)->Enter();
+    const char* source =
+        "function foo() {"
+        "  var x = 42;"
+        "  var y = 42;"
+        "  var z = x + y;"
+        "};"
+        "foo()";
+    Handle<String> foo_name = factory->InternalizeUtf8String("foo");
+
+    // This compile will add the code to the compilation cache.
+    {
+      v8::HandleScope scope(isolate);
+      CompileRun(source);
+    }
 
-  // This compile will add the code to the compilation cache.
-  { v8::HandleScope scope(CcTest::isolate());
-    CompileRun(source);
-  }
+    // Check function is compiled.
+    Handle<Object> func_value = Object::GetProperty(i_isolate->global_object(),
+                                                    foo_name).ToHandleChecked();
+    CHECK(func_value->IsJSFunction());
+    Handle<JSFunction> function = Handle<JSFunction>::cast(func_value);
+    CHECK(function->shared()->is_compiled());
 
-  // Check function is compiled.
-  Handle<Object> func_value = Object::GetProperty(
-      CcTest::i_isolate()->global_object(), foo_name).ToHandleChecked();
-  CHECK(func_value->IsJSFunction());
-  Handle<JSFunction> function = Handle<JSFunction>::cast(func_value);
-  CHECK(function->shared()->is_compiled());
+    // The code will survive at least two GCs.
+    i_isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
+    i_isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
+    CHECK(function->shared()->is_compiled());
 
-  // The code will survive at least two GCs.
-  CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
-  CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
-  CHECK(function->shared()->is_compiled());
+    // Simulate several GCs that use full marking.
+    const int kAgingThreshold = 6;
+    for (int i = 0; i < kAgingThreshold; i++) {
+      i_isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
+    }
 
-  // Simulate several GCs that use full marking.
-  const int kAgingThreshold = 6;
-  for (int i = 0; i < kAgingThreshold; i++) {
-    CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
+    // foo should no longer be in the compilation cache
+    CHECK(!function->shared()->is_compiled() || function->IsOptimized());
+    CHECK(!function->is_compiled() || function->IsOptimized());
+    // Call foo to get it recompiled.
+    CompileRun("foo()");
+    CHECK(function->shared()->is_compiled());
+    CHECK(function->is_compiled());
   }
-
-  // foo should no longer be in the compilation cache
-  CHECK(!function->shared()->is_compiled() || function->IsOptimized());
-  CHECK(!function->is_compiled() || function->IsOptimized());
-  // Call foo to get it recompiled.
-  CompileRun("foo()");
-  CHECK(function->shared()->is_compiled());
-  CHECK(function->is_compiled());
+  isolate->Exit();
+  isolate->Dispose();
 }
 
 
@@ -3297,26 +3305,28 @@ class SourceResource : public v8::String::ExternalOneByteStringResource {
 };
 
 
-void ReleaseStackTraceDataTest(const char* source, const char* accessor) {
+void ReleaseStackTraceDataTest(v8::Isolate* isolate, const char* source,
+                               const char* accessor) {
   // Test that the data retained by the Error.stack accessor is released
   // after the first time the accessor is fired.  We use external string
   // to check whether the data is being released since the external string
   // resource's callback is fired when the external string is GC'ed.
-  v8::HandleScope scope(CcTest::isolate());
+  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+  v8::HandleScope scope(isolate);
   SourceResource* resource = new SourceResource(i::StrDup(source));
   {
-    v8::HandleScope scope(CcTest::isolate());
+    v8::HandleScope scope(isolate);
     v8::Handle<v8::String> source_string =
-        v8::String::NewExternal(CcTest::isolate(), resource);
-    CcTest::heap()->CollectAllAvailableGarbage();
+        v8::String::NewExternal(isolate, resource);
+    i_isolate->heap()->CollectAllAvailableGarbage();
     v8::Script::Compile(source_string)->Run();
     CHECK(!resource->IsDisposed());
   }
-  // CcTest::heap()->CollectAllAvailableGarbage();
+  // i_isolate->heap()->CollectAllAvailableGarbage();
   CHECK(!resource->IsDisposed());
 
   CompileRun(accessor);
-  CcTest::heap()->CollectAllAvailableGarbage();
+  i_isolate->heap()->CollectAllAvailableGarbage();
 
   // External source has been released.
   CHECK(resource->IsDisposed());
@@ -3324,7 +3334,7 @@ void ReleaseStackTraceDataTest(const char* source, const char* accessor) {
 }
 
 
-TEST(ReleaseStackTraceData) {
+UNINITIALIZED_TEST(ReleaseStackTraceData) {
   if (i::FLAG_always_opt) {
     // TODO(ulan): Remove this once the memory leak via code_next_link is fixed.
     // See: https://codereview.chromium.org/181833004/
@@ -3332,46 +3342,51 @@ TEST(ReleaseStackTraceData) {
   }
   FLAG_use_ic = false;  // ICs retain objects.
   FLAG_concurrent_recompilation = false;
-  CcTest::InitializeVM();
-  static const char* source1 = "var error = null;            "
-  /* Normal Error */           "try {                        "
-                               "  throw new Error();         "
-                               "} catch (e) {                "
-                               "  error = e;                 "
-                               "}                            ";
-  static const char* source2 = "var error = null;            "
-  /* Stack overflow */         "try {                        "
-                               "  (function f() { f(); })(); "
-                               "} catch (e) {                "
-                               "  error = e;                 "
-                               "}                            ";
-  static const char* source3 = "var error = null;            "
-  /* Normal Error */           "try {                        "
-  /* as prototype */           "  throw new Error();         "
-                               "} catch (e) {                "
-                               "  error = {};                "
-                               "  error.__proto__ = e;       "
-                               "}                            ";
-  static const char* source4 = "var error = null;            "
-  /* Stack overflow */         "try {                        "
-  /* as prototype   */         "  (function f() { f(); })(); "
-                               "} catch (e) {                "
-                               "  error = {};                "
-                               "  error.__proto__ = e;       "
-                               "}                            ";
-  static const char* getter = "error.stack";
-  static const char* setter = "error.stack = 0";
-
-  ReleaseStackTraceDataTest(source1, setter);
-  ReleaseStackTraceDataTest(source2, setter);
-  // We do not test source3 and source4 with setter, since the setter is
-  // supposed to (untypically) write to the receiver, not the holder.  This is
-  // to emulate the behavior of a data property.
-
-  ReleaseStackTraceDataTest(source1, getter);
-  ReleaseStackTraceDataTest(source2, getter);
-  ReleaseStackTraceDataTest(source3, getter);
-  ReleaseStackTraceDataTest(source4, getter);
+  v8::Isolate* isolate = v8::Isolate::New();
+  {
+    v8::Isolate::Scope isolate_scope(isolate);
+    v8::HandleScope handle_scope(isolate);
+    v8::Context::New(isolate)->Enter();
+    static const char* source1 = "var error = null;            "
+    /* Normal Error */           "try {                        "
+                                 "  throw new Error();         "
+                                 "} catch (e) {                "
+                                 "  error = e;                 "
+                                 "}                            ";
+    static const char* source2 = "var error = null;            "
+    /* Stack overflow */         "try {                        "
+                                 "  (function f() { f(); })(); "
+                                 "} catch (e) {                "
+                                 "  error = e;                 "
+                                 "}                            ";
+    static const char* source3 = "var error = null;            "
+    /* Normal Error */           "try {                        "
+    /* as prototype */           "  throw new Error();         "
+                                 "} catch (e) {                "
+                                 "  error = {};                "
+                                 "  error.__proto__ = e;       "
+                                 "}                            ";
+    static const char* source4 = "var error = null;            "
+    /* Stack overflow */         "try {                        "
+    /* as prototype   */         "  (function f() { f(); })(); "
+                                 "} catch (e) {                "
+                                 "  error = {};                "
+                                 "  error.__proto__ = e;       "
+                                 "}                            ";
+    static const char* getter = "error.stack";
+    static const char* setter = "error.stack = 0";
+
+    ReleaseStackTraceDataTest(isolate, source1, setter);
+    ReleaseStackTraceDataTest(isolate, source2, setter);
+    // We do not test source3 and source4 with setter, since the setter is
+    // supposed to (untypically) write to the receiver, not the holder.  This is
+    // to emulate the behavior of a data property.
+
+    ReleaseStackTraceDataTest(isolate, source1, getter);
+    ReleaseStackTraceDataTest(isolate, source2, getter);
+    ReleaseStackTraceDataTest(isolate, source3, getter);
+    ReleaseStackTraceDataTest(isolate, source4, getter);
+  }
 }
 
 
@@ -4349,78 +4364,84 @@ TEST(ArrayShiftSweeping) {
 }
 
 
-TEST(PromotionQueue) {
+UNINITIALIZED_TEST(PromotionQueue) {
   i::FLAG_expose_gc = true;
   i::FLAG_max_semi_space_size = 2;
-  CcTest::InitializeVM();
-  v8::HandleScope scope(CcTest::isolate());
-  Isolate* isolate = CcTest::i_isolate();
-  Heap* heap = isolate->heap();
-  NewSpace* new_space = heap->new_space();
-
-  // In this test we will try to overwrite the promotion queue which is at the
-  // end of to-space. To actually make that possible, we need at least two
-  // semi-space pages and take advantage of fragementation.
-  // (1) Grow semi-space to two pages.
-  // (2) Create a few small long living objects and call the scavenger to
-  // move them to the other semi-space.
-  // (3) Create a huge object, i.e., remainder of first semi-space page and
-  // create another huge object which should be of maximum allocatable memory
-  // size of the second semi-space page.
-  // (4) Call the scavenger again.
-  // What will happen is: the scavenger will promote the objects created in (2)
-  // and will create promotion queue entries at the end of the second
-  // semi-space page during the next scavenge when it promotes the objects to
-  // the old generation. The first allocation of (3) will fill up the first
-  // semi-space page. The second allocation in (3) will not fit into the first
-  // semi-space page, but it will overwrite the promotion queue which are in
-  // the second semi-space page. If the right guards are in place, the promotion
-  // queue will be evacuated in that case.
-
-  // Grow the semi-space to two pages to make semi-space copy overwrite the
-  // promotion queue, which will be at the end of the second page.
-  intptr_t old_capacity = new_space->TotalCapacity();
-  new_space->Grow();
-  CHECK(new_space->IsAtMaximumCapacity());
-  CHECK(2 * old_capacity == new_space->TotalCapacity());
-
-  // Call the scavenger two times to get an empty new space
-  heap->CollectGarbage(NEW_SPACE);
-  heap->CollectGarbage(NEW_SPACE);
-
-  // First create a few objects which will survive a scavenge, and will get
-  // promoted to the old generation later on. These objects will create
-  // promotion queue entries at the end of the second semi-space page.
-  const int number_handles = 12;
-  Handle<FixedArray> handles[number_handles];
-  for (int i = 0; i < number_handles; i++) {
-    handles[i] = isolate->factory()->NewFixedArray(1, NOT_TENURED);
+  v8::Isolate* isolate = v8::Isolate::New();
+  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+  {
+    v8::Isolate::Scope isolate_scope(isolate);
+    v8::HandleScope handle_scope(isolate);
+    v8::Context::New(isolate)->Enter();
+    Heap* heap = i_isolate->heap();
+    NewSpace* new_space = heap->new_space();
+
+    // In this test we will try to overwrite the promotion queue which is at the
+    // end of to-space. To actually make that possible, we need at least two
+    // semi-space pages and take advantage of fragementation.
+    // (1) Grow semi-space to two pages.
+    // (2) Create a few small long living objects and call the scavenger to
+    // move them to the other semi-space.
+    // (3) Create a huge object, i.e., remainder of first semi-space page and
+    // create another huge object which should be of maximum allocatable memory
+    // size of the second semi-space page.
+    // (4) Call the scavenger again.
+    // What will happen is: the scavenger will promote the objects created in
+    // (2) and will create promotion queue entries at the end of the second
+    // semi-space page during the next scavenge when it promotes the objects to
+    // the old generation. The first allocation of (3) will fill up the first
+    // semi-space page. The second allocation in (3) will not fit into the
+    // first semi-space page, but it will overwrite the promotion queue which
+    // are in the second semi-space page. If the right guards are in place, the
+    // promotion queue will be evacuated in that case.
+
+    // Grow the semi-space to two pages to make semi-space copy overwrite the
+    // promotion queue, which will be at the end of the second page.
+    intptr_t old_capacity = new_space->TotalCapacity();
+    new_space->Grow();
+    CHECK(new_space->IsAtMaximumCapacity());
+    CHECK(2 * old_capacity == new_space->TotalCapacity());
+
+    // Call the scavenger two times to get an empty new space
+    heap->CollectGarbage(NEW_SPACE);
+    heap->CollectGarbage(NEW_SPACE);
+
+    // First create a few objects which will survive a scavenge, and will get
+    // promoted to the old generation later on. These objects will create
+    // promotion queue entries at the end of the second semi-space page.
+    const int number_handles = 12;
+    Handle<FixedArray> handles[number_handles];
+    for (int i = 0; i < number_handles; i++) {
+      handles[i] = i_isolate->factory()->NewFixedArray(1, NOT_TENURED);
+    }
+    heap->CollectGarbage(NEW_SPACE);
+
+    // Create the first huge object which will exactly fit the first semi-space
+    // page.
+    int new_linear_size =
+        static_cast<int>(*heap->new_space()->allocation_limit_address() -
+                         *heap->new_space()->allocation_top_address());
+    int length = new_linear_size / kPointerSize - FixedArray::kHeaderSize;
+    Handle<FixedArray> first =
+        i_isolate->factory()->NewFixedArray(length, NOT_TENURED);
+    CHECK(heap->InNewSpace(*first));
+
+    // Create the second huge object of maximum allocatable second semi-space
+    // page size.
+    new_linear_size =
+        static_cast<int>(*heap->new_space()->allocation_limit_address() -
+                         *heap->new_space()->allocation_top_address());
+    length = Page::kMaxRegularHeapObjectSize / kPointerSize -
+             FixedArray::kHeaderSize;
+    Handle<FixedArray> second =
+        i_isolate->factory()->NewFixedArray(length, NOT_TENURED);
+    CHECK(heap->InNewSpace(*second));
+
+    // This scavenge will corrupt memory if the promotion queue is not
+    // evacuated.
+    heap->CollectGarbage(NEW_SPACE);
   }
-  heap->CollectGarbage(NEW_SPACE);
-
-  // Create the first huge object which will exactly fit the first semi-space
-  // page.
-  int new_linear_size = static_cast<int>(
-      *heap->new_space()->allocation_limit_address() -
-          *heap->new_space()->allocation_top_address());
-  int length = new_linear_size / kPointerSize - FixedArray::kHeaderSize;
-  Handle<FixedArray> first =
-    isolate->factory()->NewFixedArray(length, NOT_TENURED);
-  CHECK(heap->InNewSpace(*first));
-
-  // Create the second huge object of maximum allocatable second semi-space
-  // page size.
-  new_linear_size = static_cast<int>(
-      *heap->new_space()->allocation_limit_address() -
-          *heap->new_space()->allocation_top_address());
-  length = Page::kMaxRegularHeapObjectSize / kPointerSize -
-      FixedArray::kHeaderSize;
-  Handle<FixedArray> second =
-      isolate->factory()->NewFixedArray(length, NOT_TENURED);
-  CHECK(heap->InNewSpace(*second));
-
-  // This scavenge will corrupt memory if the promotion queue is not evacuated.
-  heap->CollectGarbage(NEW_SPACE);
+  isolate->Dispose();
 }
 
 
index f5c2274..6a5f0b2 100644 (file)
@@ -158,7 +158,6 @@ void CompareStrings(const char* s1, const char* s2,
 // --- T h e   A c t u a l   T e s t s
 
 TEST(LiveEditDiffer) {
-  v8::internal::V8::Initialize(NULL);
   CompareStrings("zz1zzz12zz123zzz", "zzzzzzzzzz", 6);
   CompareStrings("zz1zzz12zz123zzz", "zz0zzz0zz0zzz", 9);
   CompareStrings("123456789", "987654321", 16);
index d72e6f0..482f89f 100644 (file)
@@ -61,9 +61,11 @@ class ScopedLoggerInitializer {
         temp_file_(NULL),
         // Need to run this prior to creating the scope.
         trick_to_run_init_flags_(init_flags_()),
-        scope_(CcTest::isolate()),
-        env_(v8::Context::New(CcTest::isolate())),
-        logger_(CcTest::i_isolate()->logger()) {
+        isolate_(v8::Isolate::New()),
+        isolate_scope_(isolate_),
+        scope_(isolate_),
+        env_(v8::Context::New(isolate_)),
+        logger_(reinterpret_cast<i::Isolate*>(isolate_)->logger()) {
     env_->Enter();
   }
 
@@ -77,6 +79,8 @@ class ScopedLoggerInitializer {
 
   v8::Handle<v8::Context>& env() { return env_; }
 
+  v8::Isolate* isolate() { return isolate_; }
+
   Logger* logger() { return logger_; }
 
   FILE* StopLoggingGetTempFile() {
@@ -100,6 +104,8 @@ class ScopedLoggerInitializer {
   const bool saved_prof_;
   FILE* temp_file_;
   const bool trick_to_run_init_flags_;
+  v8::Isolate* isolate_;
+  v8::Isolate::Scope isolate_scope_;
   v8::HandleScope scope_;
   v8::Handle<v8::Context> env_;
   Logger* logger_;
@@ -330,41 +336,41 @@ static void ObjMethod1(const v8::FunctionCallbackInfo<v8::Value>& args) {
 
 
 TEST(LogCallbacks) {
-  v8::Isolate* isolate = CcTest::isolate();
-  ScopedLoggerInitializer initialize_logger;
-  Logger* logger = initialize_logger.logger();
-
-  v8::Local<v8::FunctionTemplate> obj =
-      v8::Local<v8::FunctionTemplate>::New(isolate,
-                                           v8::FunctionTemplate::New(isolate));
-  obj->SetClassName(v8_str("Obj"));
-  v8::Handle<v8::ObjectTemplate> proto = obj->PrototypeTemplate();
-  v8::Local<v8::Signature> signature =
-      v8::Signature::New(isolate, obj);
-  proto->Set(v8_str("method1"),
-             v8::FunctionTemplate::New(isolate,
-                                       ObjMethod1,
-                                       v8::Handle<v8::Value>(),
-                                       signature),
-             static_cast<v8::PropertyAttribute>(v8::DontDelete));
-
-  initialize_logger.env()->Global()->Set(v8_str("Obj"), obj->GetFunction());
-  CompileRun("Obj.prototype.method1.toString();");
-
-  logger->LogCompiledFunctions();
-
-  bool exists = false;
-  i::Vector<const char> log(
-      i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true));
-  CHECK(exists);
-
-  i::EmbeddedVector<char, 100> ref_data;
-  i::SNPrintF(ref_data,
-              "code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"method1\"",
-              reinterpret_cast<intptr_t>(ObjMethod1));
-
-  CHECK_NE(NULL, StrNStr(log.start(), ref_data.start(), log.length()));
-  log.Dispose();
+  v8::Isolate* isolate;
+  {
+    ScopedLoggerInitializer initialize_logger;
+    isolate = initialize_logger.isolate();
+    Logger* logger = initialize_logger.logger();
+
+    v8::Local<v8::FunctionTemplate> obj = v8::Local<v8::FunctionTemplate>::New(
+        isolate, v8::FunctionTemplate::New(isolate));
+    obj->SetClassName(v8_str("Obj"));
+    v8::Handle<v8::ObjectTemplate> proto = obj->PrototypeTemplate();
+    v8::Local<v8::Signature> signature = v8::Signature::New(isolate, obj);
+    proto->Set(v8_str("method1"),
+               v8::FunctionTemplate::New(isolate, ObjMethod1,
+                                         v8::Handle<v8::Value>(), signature),
+               static_cast<v8::PropertyAttribute>(v8::DontDelete));
+
+    initialize_logger.env()->Global()->Set(v8_str("Obj"), obj->GetFunction());
+    CompileRun("Obj.prototype.method1.toString();");
+
+    logger->LogCompiledFunctions();
+
+    bool exists = false;
+    i::Vector<const char> log(
+        i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true));
+    CHECK(exists);
+
+    i::EmbeddedVector<char, 100> ref_data;
+    i::SNPrintF(ref_data,
+                "code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"method1\"",
+                reinterpret_cast<intptr_t>(ObjMethod1));
+
+    CHECK_NE(NULL, StrNStr(log.start(), ref_data.start(), log.length()));
+    log.Dispose();
+  }
+  isolate->Dispose();
 }
 
 
@@ -383,46 +389,49 @@ static void Prop2Getter(v8::Local<v8::String> property,
 
 
 TEST(LogAccessorCallbacks) {
-  v8::Isolate* isolate = CcTest::isolate();
-  ScopedLoggerInitializer initialize_logger;
-  Logger* logger = initialize_logger.logger();
-
-  v8::Local<v8::FunctionTemplate> obj =
-      v8::Local<v8::FunctionTemplate>::New(isolate,
-                                           v8::FunctionTemplate::New(isolate));
-  obj->SetClassName(v8_str("Obj"));
-  v8::Handle<v8::ObjectTemplate> inst = obj->InstanceTemplate();
-  inst->SetAccessor(v8_str("prop1"), Prop1Getter, Prop1Setter);
-  inst->SetAccessor(v8_str("prop2"), Prop2Getter);
-
-  logger->LogAccessorCallbacks();
-
-  bool exists = false;
-  i::Vector<const char> log(
-      i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true));
-  CHECK(exists);
-
-  EmbeddedVector<char, 100> prop1_getter_record;
-  i::SNPrintF(prop1_getter_record,
-              "code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"get prop1\"",
-              reinterpret_cast<intptr_t>(Prop1Getter));
-  CHECK_NE(NULL,
-           StrNStr(log.start(), prop1_getter_record.start(), log.length()));
-
-  EmbeddedVector<char, 100> prop1_setter_record;
-  i::SNPrintF(prop1_setter_record,
-              "code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"set prop1\"",
-              reinterpret_cast<intptr_t>(Prop1Setter));
-  CHECK_NE(NULL,
-           StrNStr(log.start(), prop1_setter_record.start(), log.length()));
-
-  EmbeddedVector<char, 100> prop2_getter_record;
-  i::SNPrintF(prop2_getter_record,
-              "code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"get prop2\"",
-              reinterpret_cast<intptr_t>(Prop2Getter));
-  CHECK_NE(NULL,
-           StrNStr(log.start(), prop2_getter_record.start(), log.length()));
-  log.Dispose();
+  v8::Isolate* isolate;
+  {
+    ScopedLoggerInitializer initialize_logger;
+    isolate = initialize_logger.isolate();
+    Logger* logger = initialize_logger.logger();
+
+    v8::Local<v8::FunctionTemplate> obj = v8::Local<v8::FunctionTemplate>::New(
+        isolate, v8::FunctionTemplate::New(isolate));
+    obj->SetClassName(v8_str("Obj"));
+    v8::Handle<v8::ObjectTemplate> inst = obj->InstanceTemplate();
+    inst->SetAccessor(v8_str("prop1"), Prop1Getter, Prop1Setter);
+    inst->SetAccessor(v8_str("prop2"), Prop2Getter);
+
+    logger->LogAccessorCallbacks();
+
+    bool exists = false;
+    i::Vector<const char> log(
+        i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true));
+    CHECK(exists);
+
+    EmbeddedVector<char, 100> prop1_getter_record;
+    i::SNPrintF(prop1_getter_record,
+                "code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"get prop1\"",
+                reinterpret_cast<intptr_t>(Prop1Getter));
+    CHECK_NE(NULL,
+             StrNStr(log.start(), prop1_getter_record.start(), log.length()));
+
+    EmbeddedVector<char, 100> prop1_setter_record;
+    i::SNPrintF(prop1_setter_record,
+                "code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"set prop1\"",
+                reinterpret_cast<intptr_t>(Prop1Setter));
+    CHECK_NE(NULL,
+             StrNStr(log.start(), prop1_setter_record.start(), log.length()));
+
+    EmbeddedVector<char, 100> prop2_getter_record;
+    i::SNPrintF(prop2_getter_record,
+                "code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"get prop2\"",
+                reinterpret_cast<intptr_t>(Prop2Getter));
+    CHECK_NE(NULL,
+             StrNStr(log.start(), prop2_getter_record.start(), log.length()));
+    log.Dispose();
+  }
+  isolate->Dispose();
 }
 
 
@@ -439,57 +448,63 @@ TEST(EquivalenceOfLoggingAndTraversal) {
   // are using V8.
 
   // Start with profiling to capture all code events from the beginning.
-  ScopedLoggerInitializer initialize_logger;
-  Logger* logger = initialize_logger.logger();
-
-  // Compile and run a function that creates other functions.
-  CompileRun(
-      "(function f(obj) {\n"
-      "  obj.test =\n"
-      "    (function a(j) { return function b() { return j; } })(100);\n"
-      "})(this);");
-  logger->StopProfiler();
-  CcTest::heap()->CollectAllGarbage(i::Heap::kMakeHeapIterableMask);
-  logger->StringEvent("test-logging-done", "");
-
-  // Iterate heap to find compiled functions, will write to log.
-  logger->LogCompiledFunctions();
-  logger->StringEvent("test-traversal-done", "");
-
-  bool exists = false;
-  i::Vector<const char> log(
-      i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true));
-  CHECK(exists);
-  v8::Handle<v8::String> log_str = v8::String::NewFromUtf8(
-      CcTest::isolate(), log.start(), v8::String::kNormalString, log.length());
-  initialize_logger.env()->Global()->Set(v8_str("_log"), log_str);
-
-  i::Vector<const unsigned char> source = TestSources::GetScriptsSource();
-  v8::Handle<v8::String> source_str = v8::String::NewFromUtf8(
-      CcTest::isolate(), reinterpret_cast<const char*>(source.start()),
-      v8::String::kNormalString, source.length());
-  v8::TryCatch try_catch;
-  v8::Handle<v8::Script> script = CompileWithOrigin(source_str, "");
-  if (script.IsEmpty()) {
-    v8::String::Utf8Value exception(try_catch.Exception());
-    printf("compile: %s\n", *exception);
-    CHECK(false);
-  }
-  v8::Handle<v8::Value> result = script->Run();
-  if (result.IsEmpty()) {
-    v8::String::Utf8Value exception(try_catch.Exception());
-    printf("run: %s\n", *exception);
-    CHECK(false);
-  }
-  // The result either be a "true" literal or problem description.
-  if (!result->IsTrue()) {
-    v8::Local<v8::String> s = result->ToString();
-    i::ScopedVector<char> data(s->Utf8Length() + 1);
-    CHECK_NE(NULL, data.start());
-    s->WriteUtf8(data.start());
-    printf("%s\n", data.start());
-    // Make sure that our output is written prior crash due to CHECK failure.
-    fflush(stdout);
-    CHECK(false);
+  v8::Isolate* isolate;
+  {
+    ScopedLoggerInitializer initialize_logger;
+    isolate = initialize_logger.isolate();
+    Logger* logger = initialize_logger.logger();
+
+    // Compile and run a function that creates other functions.
+    CompileRun(
+        "(function f(obj) {\n"
+        "  obj.test =\n"
+        "    (function a(j) { return function b() { return j; } })(100);\n"
+        "})(this);");
+    logger->StopProfiler();
+    reinterpret_cast<i::Isolate*>(isolate)->heap()->CollectAllGarbage(
+        i::Heap::kMakeHeapIterableMask);
+    logger->StringEvent("test-logging-done", "");
+
+    // Iterate heap to find compiled functions, will write to log.
+    logger->LogCompiledFunctions();
+    logger->StringEvent("test-traversal-done", "");
+
+    bool exists = false;
+    i::Vector<const char> log(
+        i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true));
+    CHECK(exists);
+    v8::Handle<v8::String> log_str = v8::String::NewFromUtf8(
+        isolate, log.start(), v8::String::kNormalString, log.length());
+    initialize_logger.env()->Global()->Set(v8_str("_log"), log_str);
+
+    i::Vector<const unsigned char> source = TestSources::GetScriptsSource();
+    v8::Handle<v8::String> source_str = v8::String::NewFromUtf8(
+        isolate, reinterpret_cast<const char*>(source.start()),
+        v8::String::kNormalString, source.length());
+    v8::TryCatch try_catch;
+    v8::Handle<v8::Script> script = CompileWithOrigin(source_str, "");
+    if (script.IsEmpty()) {
+      v8::String::Utf8Value exception(try_catch.Exception());
+      printf("compile: %s\n", *exception);
+      CHECK(false);
+    }
+    v8::Handle<v8::Value> result = script->Run();
+    if (result.IsEmpty()) {
+      v8::String::Utf8Value exception(try_catch.Exception());
+      printf("run: %s\n", *exception);
+      CHECK(false);
+    }
+    // The result either be a "true" literal or problem description.
+    if (!result->IsTrue()) {
+      v8::Local<v8::String> s = result->ToString();
+      i::ScopedVector<char> data(s->Utf8Length() + 1);
+      CHECK_NE(NULL, data.start());
+      s->WriteUtf8(data.start());
+      printf("%s\n", data.start());
+      // Make sure that our output is written prior crash due to CHECK failure.
+      fflush(stdout);
+      CHECK(false);
+    }
   }
+  isolate->Dispose();
 }
index 2cfad0d..3ca0266 100644 (file)
@@ -137,8 +137,6 @@ typedef int (*F5)(void*, void*, void*, void*, void*);
 
 
 TEST(LoadAndStoreWithRepresentation) {
-  v8::internal::V8::Initialize(NULL);
-
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
index 4d37579..b2b8c94 100644 (file)
@@ -50,8 +50,6 @@ typedef F0Type* F0;
 
 
 TEST(LoadAndStoreWithRepresentation) {
-  v8::internal::V8::Initialize(NULL);
-
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
index 2c0e918..7f20a8d 100644 (file)
@@ -153,7 +153,6 @@ static void TestMoveSmi(MacroAssembler* masm, Label* exit, int id, Smi* value) {
 
 // Test that we can move a Smi value literally into a register.
 TEST(SmiMove) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -239,7 +238,6 @@ void TestSmiCompare(MacroAssembler* masm, Label* exit, int id, int x, int y) {
 
 // Test that we can compare smis for equality (and more).
 TEST(SmiCompare) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -288,7 +286,6 @@ TEST(SmiCompare) {
 
 
 TEST(Integer32ToSmi) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -415,7 +412,6 @@ void TestI64PlusConstantToSmi(MacroAssembler* masm,
 
 
 TEST(Integer64PlusConstantToSmi) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -458,7 +454,6 @@ TEST(Integer64PlusConstantToSmi) {
 
 
 TEST(SmiCheck) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -704,7 +699,6 @@ void TestSmiNeg(MacroAssembler* masm, Label* exit, int id, int x) {
 
 
 TEST(SmiNeg) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -918,7 +912,6 @@ static void SmiAddOverflowTest(MacroAssembler* masm,
 
 
 TEST(SmiAdd) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -1137,7 +1130,6 @@ static void SmiSubOverflowTest(MacroAssembler* masm,
 
 
 TEST(SmiSub) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -1226,7 +1218,6 @@ void TestSmiMul(MacroAssembler* masm, Label* exit, int id, int x, int y) {
 
 
 TEST(SmiMul) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -1330,7 +1321,6 @@ void TestSmiDiv(MacroAssembler* masm, Label* exit, int id, int x, int y) {
 
 
 TEST(SmiDiv) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -1438,7 +1428,6 @@ void TestSmiMod(MacroAssembler* masm, Label* exit, int id, int x, int y) {
 
 
 TEST(SmiMod) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -1533,7 +1522,6 @@ void TestSmiIndex(MacroAssembler* masm, Label* exit, int id, int x) {
 
 
 TEST(SmiIndex) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -1600,7 +1588,6 @@ void TestSelectNonSmi(MacroAssembler* masm, Label* exit, int id, int x, int y) {
 
 
 TEST(SmiSelectNonSmi) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -1677,7 +1664,6 @@ void TestSmiAnd(MacroAssembler* masm, Label* exit, int id, int x, int y) {
 
 
 TEST(SmiAnd) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -1756,7 +1742,6 @@ void TestSmiOr(MacroAssembler* masm, Label* exit, int id, int x, int y) {
 
 
 TEST(SmiOr) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -1837,7 +1822,6 @@ void TestSmiXor(MacroAssembler* masm, Label* exit, int id, int x, int y) {
 
 
 TEST(SmiXor) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -1902,7 +1886,6 @@ void TestSmiNot(MacroAssembler* masm, Label* exit, int id, int x) {
 
 
 TEST(SmiNot) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -1996,7 +1979,6 @@ void TestSmiShiftLeft(MacroAssembler* masm, Label* exit, int id, int x) {
 
 
 TEST(SmiShiftLeft) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -2100,7 +2082,6 @@ void TestSmiShiftLogicalRight(MacroAssembler* masm,
 
 
 TEST(SmiShiftLogicalRight) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -2167,7 +2148,6 @@ void TestSmiShiftArithmeticRight(MacroAssembler* masm,
 
 
 TEST(SmiShiftArithmeticRight) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -2229,7 +2209,6 @@ void TestPositiveSmiPowerUp(MacroAssembler* masm, Label* exit, int id, int x) {
 
 
 TEST(PositiveSmiTimesPowerOfTwoToInteger64) {
-  i::V8::Initialize(NULL);
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
@@ -2267,7 +2246,6 @@ TEST(PositiveSmiTimesPowerOfTwoToInteger64) {
 
 
 TEST(OperandOffset) {
-  i::V8::Initialize(NULL);
   uint32_t data[256];
   for (uint32_t i = 0; i < 256; i++) { data[i] = i * 0x01010101; }
 
@@ -2621,8 +2599,6 @@ TEST(OperandOffset) {
 
 
 TEST(LoadAndStoreWithRepresentation) {
-  v8::internal::V8::Initialize(NULL);
-
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
index 9aa40c0..0b057d8 100644 (file)
@@ -50,8 +50,6 @@ typedef F0Type* F0;
 
 
 TEST(LoadAndStoreWithRepresentation) {
-  v8::internal::V8::Initialize(NULL);
-
   // Allocate an executable page of memory.
   size_t actual_size;
   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
index d2e67c7..04b5882 100644 (file)
 using namespace v8::internal;
 
 
-static const int kMaxRuns = 12345;
-static const int kRandomSeeds[] = {
-  -1, 1, 42, 100, 1234567890, 987654321
-};
+static const int64_t kRandomSeeds[] = {-1, 1, 42, 100, 1234567890, 987654321};
 
 
 TEST(RandomSeedFlagIsUsed) {
   for (unsigned n = 0; n < arraysize(kRandomSeeds); ++n) {
-    FLAG_random_seed = kRandomSeeds[n];
+    FLAG_random_seed = static_cast<int>(kRandomSeeds[n]);
     v8::Isolate* i = v8::Isolate::New();
-    v8::base::RandomNumberGenerator& rng1 =
+    v8::base::RandomNumberGenerator& rng =
         *reinterpret_cast<Isolate*>(i)->random_number_generator();
-    v8::base::RandomNumberGenerator rng2(kRandomSeeds[n]);
-    for (int k = 1; k <= kMaxRuns; ++k) {
-      int64_t i1, i2;
-      rng1.NextBytes(&i1, sizeof(i1));
-      rng2.NextBytes(&i2, sizeof(i2));
-      CHECK_EQ(i2, i1);
-      CHECK_EQ(rng2.NextInt(), rng1.NextInt());
-      CHECK_EQ(rng2.NextInt(k), rng1.NextInt(k));
-      CHECK_EQ(rng2.NextDouble(), rng1.NextDouble());
-    }
+    CHECK_EQ(kRandomSeeds[n], rng.initial_seed());
     i->Dispose();
   }
 }
index d1c2ea1..9d1d52e 100644 (file)
@@ -85,7 +85,6 @@ using namespace v8::internal;
 
 
 static bool CheckParse(const char* input) {
-  V8::Initialize(NULL);
   v8::HandleScope scope(CcTest::isolate());
   Zone zone(CcTest::i_isolate());
   FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
@@ -96,7 +95,6 @@ static bool CheckParse(const char* input) {
 
 
 static void CheckParseEq(const char* input, const char* expected) {
-  V8::Initialize(NULL);
   v8::HandleScope scope(CcTest::isolate());
   Zone zone(CcTest::i_isolate());
   FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
@@ -112,7 +110,6 @@ static void CheckParseEq(const char* input, const char* expected) {
 
 
 static bool CheckSimple(const char* input) {
-  V8::Initialize(NULL);
   v8::HandleScope scope(CcTest::isolate());
   Zone zone(CcTest::i_isolate());
   FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
@@ -131,7 +128,6 @@ struct MinMaxPair {
 
 
 static MinMaxPair CheckMinMaxMatch(const char* input) {
-  V8::Initialize(NULL);
   v8::HandleScope scope(CcTest::isolate());
   Zone zone(CcTest::i_isolate());
   FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
@@ -156,8 +152,6 @@ static MinMaxPair CheckMinMaxMatch(const char* input) {
   }
 
 TEST(Parser) {
-  V8::Initialize(NULL);
-
   CHECK_PARSE_ERROR("?");
 
   CheckParseEq("abc", "'abc'");
@@ -407,7 +401,6 @@ TEST(ParserRegression) {
 
 static void ExpectError(const char* input,
                         const char* expected) {
-  V8::Initialize(NULL);
   v8::HandleScope scope(CcTest::isolate());
   Zone zone(CcTest::i_isolate());
   FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
@@ -494,7 +487,6 @@ static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) {
 
 
 TEST(CharacterClassEscapes) {
-  v8::internal::V8::Initialize(NULL);
   TestCharacterClassEscapes('.', IsRegExpNewline);
   TestCharacterClassEscapes('d', IsDigit);
   TestCharacterClassEscapes('D', NotDigit);
@@ -507,7 +499,6 @@ TEST(CharacterClassEscapes) {
 
 static RegExpNode* Compile(const char* input, bool multiline, bool is_one_byte,
                            Zone* zone) {
-  V8::Initialize(NULL);
   Isolate* isolate = CcTest::i_isolate();
   FlatStringReader reader(isolate, CStrVector(input));
   RegExpCompileData compile_data;
@@ -564,7 +555,6 @@ static unsigned PseudoRandom(int i, int j) {
 
 
 TEST(SplayTreeSimple) {
-  v8::internal::V8::Initialize(NULL);
   static const unsigned kLimit = 1000;
   Zone zone(CcTest::i_isolate());
   ZoneSplayTree<TestConfig> tree(&zone);
@@ -617,7 +607,6 @@ TEST(SplayTreeSimple) {
 
 
 TEST(DispatchTableConstruction) {
-  v8::internal::V8::Initialize(NULL);
   // Initialize test data.
   static const int kLimit = 1000;
   static const int kRangeCount = 8;
@@ -1362,7 +1351,6 @@ TEST(MacroAssemblerNativeLotsOfRegisters) {
 #else  // V8_INTERPRETED_REGEXP
 
 TEST(MacroAssembler) {
-  V8::Initialize(NULL);
   byte codes[1024];
   Zone zone(CcTest::i_isolate());
   RegExpMacroAssemblerIrregexp m(Vector<byte>(codes, 1024), &zone);
@@ -1428,7 +1416,6 @@ TEST(MacroAssembler) {
 
 
 TEST(AddInverseToTable) {
-  v8::internal::V8::Initialize(NULL);
   static const int kLimit = 1000;
   static const int kRangeCount = 16;
   for (int t = 0; t < 10; t++) {
@@ -1588,7 +1575,6 @@ static void TestSimpleRangeCaseIndependence(CharacterRange input,
 
 
 TEST(CharacterRangeCaseIndependence) {
-  v8::internal::V8::Initialize(NULL);
   TestSimpleRangeCaseIndependence(CharacterRange::Singleton('a'),
                                   CharacterRange::Singleton('A'));
   TestSimpleRangeCaseIndependence(CharacterRange::Singleton('z'),
@@ -1630,7 +1616,6 @@ static bool InClass(uc16 c, ZoneList<CharacterRange>* ranges) {
 
 
 TEST(CharClassDifference) {
-  v8::internal::V8::Initialize(NULL);
   Zone zone(CcTest::i_isolate());
   ZoneList<CharacterRange>* base =
       new(&zone) ZoneList<CharacterRange>(1, &zone);
@@ -1658,7 +1643,6 @@ TEST(CharClassDifference) {
 
 
 TEST(CanonicalizeCharacterSets) {
-  v8::internal::V8::Initialize(NULL);
   Zone zone(CcTest::i_isolate());
   ZoneList<CharacterRange>* list =
       new(&zone) ZoneList<CharacterRange>(4, &zone);
@@ -1720,7 +1704,6 @@ TEST(CanonicalizeCharacterSets) {
 
 
 TEST(CharacterRangeMerge) {
-  v8::internal::V8::Initialize(NULL);
   Zone zone(CcTest::i_isolate());
   ZoneList<CharacterRange> l1(4, &zone);
   ZoneList<CharacterRange> l2(4, &zone);
@@ -1808,6 +1791,5 @@ TEST(CharacterRangeMerge) {
 
 
 TEST(Graph) {
-  V8::Initialize(NULL);
   Execute("\\b\\w+\\b", false, true, true);
 }
index 5431e0b..94b400e 100644 (file)
 
 using namespace v8::internal;
 
-static const unsigned kCounters = 256;
-static int local_counters[kCounters];
-static const char* local_counter_names[kCounters];
-
-
-static unsigned CounterHash(const char* s) {
-  unsigned hash = 0;
-  while (*++s) {
-    hash |= hash << 5;
-    hash += *s;
-  }
-  return hash;
-}
-
-
-// Callback receiver to track counters in test.
-static int* counter_function(const char* name) {
-  unsigned hash = CounterHash(name) % kCounters;
-  unsigned original_hash = hash;
-  USE(original_hash);
-  while (true) {
-    if (local_counter_names[hash] == name) {
-      return &local_counters[hash];
-    }
-    if (local_counter_names[hash] == 0) {
-      local_counter_names[hash] = name;
-      return &local_counters[hash];
-    }
-    if (strcmp(local_counter_names[hash], name) == 0) {
-      return &local_counters[hash];
-    }
-    hash = (hash + 1) % kCounters;
-    DCHECK(hash != original_hash);  // Hash table has been filled up.
-  }
-}
-
 
 template <class T>
 static Address AddressOf(T id) {
@@ -101,7 +65,6 @@ static int make_code(TypeCode type, int id) {
 
 TEST(ExternalReferenceEncoder) {
   Isolate* isolate = CcTest::i_isolate();
-  isolate->stats_table()->SetCounterFunction(counter_function);
   v8::V8::Initialize();
 
   ExternalReferenceEncoder encoder(isolate);
@@ -109,10 +72,6 @@ TEST(ExternalReferenceEncoder) {
            Encode(encoder, Builtins::kArrayCode));
   CHECK_EQ(make_code(v8::internal::RUNTIME_FUNCTION, Runtime::kAbort),
            Encode(encoder, Runtime::kAbort));
-  ExternalReference total_compile_size =
-      ExternalReference(isolate->counters()->total_compile_size());
-  CHECK_EQ(make_code(STATS_COUNTER, Counters::k_total_compile_size),
-           encoder.Encode(total_compile_size.address()));
   ExternalReference stack_limit_address =
       ExternalReference::address_of_stack_limit(isolate);
   CHECK_EQ(make_code(UNCLASSIFIED, 2),
@@ -136,7 +95,6 @@ TEST(ExternalReferenceEncoder) {
 
 TEST(ExternalReferenceDecoder) {
   Isolate* isolate = CcTest::i_isolate();
-  isolate->stats_table()->SetCounterFunction(counter_function);
   v8::V8::Initialize();
 
   ExternalReferenceDecoder decoder(isolate);
@@ -145,12 +103,6 @@ TEST(ExternalReferenceDecoder) {
   CHECK_EQ(AddressOf(Runtime::kAbort),
            decoder.Decode(make_code(v8::internal::RUNTIME_FUNCTION,
                                     Runtime::kAbort)));
-  ExternalReference total_compile_size =
-      ExternalReference(isolate->counters()->total_compile_size());
-  CHECK_EQ(total_compile_size.address(),
-           decoder.Decode(
-               make_code(STATS_COUNTER,
-                         Counters::k_total_compile_size)));
   CHECK_EQ(ExternalReference::address_of_stack_limit(isolate).address(),
            decoder.Decode(make_code(UNCLASSIFIED, 2)));
   CHECK_EQ(ExternalReference::address_of_real_stack_limit(isolate).address(),
@@ -242,40 +194,42 @@ static bool WriteToFile(Isolate* isolate, const char* snapshot_file) {
 }
 
 
-static void Serialize() {
+static void Serialize(v8::Isolate* isolate) {
   // We have to create one context.  One reason for this is so that the builtins
   // can be loaded from v8natives.js and their addresses can be processed.  This
   // will clear the pending fixups array, which would otherwise contain GC roots
   // that would confuse the serialization/deserialization process.
-  v8::Isolate* isolate = CcTest::isolate();
+  v8::Isolate::Scope isolate_scope(isolate);
   {
     v8::HandleScope scope(isolate);
     v8::Context::New(isolate);
   }
 
-  Isolate* internal_isolate = CcTest::i_isolate();
+  Isolate* internal_isolate = reinterpret_cast<Isolate*>(isolate);
   internal_isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, "serialize");
   WriteToFile(internal_isolate, FLAG_testing_serialization_file);
 }
 
 
 // Test that the whole heap can be serialized.
-TEST(Serialize) {
+UNINITIALIZED_TEST(Serialize) {
   if (!Snapshot::HaveASnapshotToStartFrom()) {
-    CcTest::i_isolate()->enable_serializer();
-    v8::V8::Initialize();
-    Serialize();
+    v8::Isolate::CreateParams params;
+    params.enable_serializer = true;
+    v8::Isolate* isolate = v8::Isolate::New(params);
+    Serialize(isolate);
   }
 }
 
 
 // Test that heap serialization is non-destructive.
-TEST(SerializeTwice) {
+UNINITIALIZED_TEST(SerializeTwice) {
   if (!Snapshot::HaveASnapshotToStartFrom()) {
-    CcTest::i_isolate()->enable_serializer();
-    v8::V8::Initialize();
-    Serialize();
-    Serialize();
+    v8::Isolate::CreateParams params;
+    params.enable_serializer = true;
+    v8::Isolate* isolate = v8::Isolate::New(params);
+    Serialize(isolate);
+    Serialize(isolate);
   }
 }
 
@@ -319,330 +273,370 @@ static void ReserveSpaceForSnapshot(Deserializer* deserializer,
 }
 
 
-bool InitializeFromFile(const char* snapshot_file) {
+v8::Isolate* InitializeFromFile(const char* snapshot_file) {
   int len;
   byte* str = ReadBytes(snapshot_file, &len);
-  if (!str) return false;
-  bool success;
+  if (!str) return NULL;
+  v8::Isolate* v8_isolate = NULL;
   {
     SnapshotByteSource source(str, len);
     Deserializer deserializer(&source);
     ReserveSpaceForSnapshot(&deserializer, snapshot_file);
-    success = V8::Initialize(&deserializer);
+    Isolate* isolate = Isolate::NewForTesting();
+    v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
+    v8::Isolate::Scope isolate_scope(v8_isolate);
+    isolate->Init(&deserializer);
   }
   DeleteArray(str);
-  return success;
+  return v8_isolate;
 }
 
 
-static void Deserialize() {
-  CHECK(InitializeFromFile(FLAG_testing_serialization_file));
+static v8::Isolate* Deserialize() {
+  v8::Isolate* isolate = InitializeFromFile(FLAG_testing_serialization_file);
+  CHECK(isolate);
+  return isolate;
 }
 
 
-static void SanityCheck() {
-  Isolate* isolate = CcTest::i_isolate();
-  v8::HandleScope scope(CcTest::isolate());
+static void SanityCheck(v8::Isolate* v8_isolate) {
+  Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
+  v8::HandleScope scope(v8_isolate);
 #ifdef VERIFY_HEAP
-  CcTest::heap()->Verify();
+  isolate->heap()->Verify();
 #endif
   CHECK(isolate->global_object()->IsJSObject());
   CHECK(isolate->native_context()->IsContext());
-  CHECK(CcTest::heap()->string_table()->IsStringTable());
+  CHECK(isolate->heap()->string_table()->IsStringTable());
   isolate->factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("Empty"));
 }
 
 
-DEPENDENT_TEST(Deserialize, Serialize) {
+UNINITIALIZED_DEPENDENT_TEST(Deserialize, Serialize) {
   // The serialize-deserialize tests only work if the VM is built without
   // serialization.  That doesn't matter.  We don't need to be able to
   // serialize a snapshot in a VM that is booted from a snapshot.
   if (!Snapshot::HaveASnapshotToStartFrom()) {
-    v8::Isolate* isolate = CcTest::isolate();
-    v8::HandleScope scope(isolate);
-    Deserialize();
+    v8::Isolate* isolate = Deserialize();
+    {
+      v8::HandleScope handle_scope(isolate);
+      v8::Isolate::Scope isolate_scope(isolate);
 
-    v8::Local<v8::Context> env = v8::Context::New(isolate);
-    env->Enter();
+      v8::Local<v8::Context> env = v8::Context::New(isolate);
+      env->Enter();
 
-    SanityCheck();
+      SanityCheck(isolate);
+    }
+    isolate->Dispose();
   }
 }
 
 
-DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) {
+UNINITIALIZED_DEPENDENT_TEST(DeserializeFromSecondSerialization,
+                             SerializeTwice) {
   if (!Snapshot::HaveASnapshotToStartFrom()) {
-    v8::Isolate* isolate = CcTest::isolate();
-    v8::HandleScope scope(isolate);
-    Deserialize();
+    v8::Isolate* isolate = Deserialize();
+    {
+      v8::Isolate::Scope isolate_scope(isolate);
+      v8::HandleScope handle_scope(isolate);
 
-    v8::Local<v8::Context> env = v8::Context::New(isolate);
-    env->Enter();
+      v8::Local<v8::Context> env = v8::Context::New(isolate);
+      env->Enter();
 
-    SanityCheck();
+      SanityCheck(isolate);
+    }
+    isolate->Dispose();
   }
 }
 
 
-DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) {
+UNINITIALIZED_DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) {
   if (!Snapshot::HaveASnapshotToStartFrom()) {
-    v8::Isolate* isolate = CcTest::isolate();
-    v8::HandleScope scope(isolate);
-    Deserialize();
+    v8::Isolate* isolate = Deserialize();
+    {
+      v8::Isolate::Scope isolate_scope(isolate);
+      v8::HandleScope handle_scope(isolate);
+
 
-    v8::Local<v8::Context> env = v8::Context::New(isolate);
-    env->Enter();
+      v8::Local<v8::Context> env = v8::Context::New(isolate);
+      env->Enter();
 
-    const char* c_source = "\"1234\".length";
-    v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, c_source);
-    v8::Local<v8::Script> script = v8::Script::Compile(source);
-    CHECK_EQ(4, script->Run()->Int32Value());
+      const char* c_source = "\"1234\".length";
+      v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, c_source);
+      v8::Local<v8::Script> script = v8::Script::Compile(source);
+      CHECK_EQ(4, script->Run()->Int32Value());
+    }
+    isolate->Dispose();
   }
 }
 
 
-DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2,
-               SerializeTwice) {
+UNINITIALIZED_DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2,
+                             SerializeTwice) {
   if (!Snapshot::HaveASnapshotToStartFrom()) {
-    v8::Isolate* isolate = CcTest::isolate();
-    v8::HandleScope scope(isolate);
-    Deserialize();
+    v8::Isolate* isolate = Deserialize();
+    {
+      v8::Isolate::Scope isolate_scope(isolate);
+      v8::HandleScope handle_scope(isolate);
 
-    v8::Local<v8::Context> env = v8::Context::New(isolate);
-    env->Enter();
+      v8::Local<v8::Context> env = v8::Context::New(isolate);
+      env->Enter();
 
-    const char* c_source = "\"1234\".length";
-    v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, c_source);
-    v8::Local<v8::Script> script = v8::Script::Compile(source);
-    CHECK_EQ(4, script->Run()->Int32Value());
+      const char* c_source = "\"1234\".length";
+      v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, c_source);
+      v8::Local<v8::Script> script = v8::Script::Compile(source);
+      CHECK_EQ(4, script->Run()->Int32Value());
+    }
+    isolate->Dispose();
   }
 }
 
 
-TEST(PartialSerialization) {
+UNINITIALIZED_TEST(PartialSerialization) {
   if (!Snapshot::HaveASnapshotToStartFrom()) {
-    Isolate* isolate = CcTest::i_isolate();
-    CcTest::i_isolate()->enable_serializer();
-    v8::V8::Initialize();
-    v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
-    Heap* heap = isolate->heap();
-
-    v8::Persistent<v8::Context> env;
-    {
-      HandleScope scope(isolate);
-      env.Reset(v8_isolate, v8::Context::New(v8_isolate));
-    }
-    DCHECK(!env.IsEmpty());
+    v8::Isolate::CreateParams params;
+    params.enable_serializer = true;
+    v8::Isolate* v8_isolate = v8::Isolate::New(params);
+    Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
+    v8_isolate->Enter();
     {
-      v8::HandleScope handle_scope(v8_isolate);
-      v8::Local<v8::Context>::New(v8_isolate, env)->Enter();
-    }
-    // Make sure all builtin scripts are cached.
-    { HandleScope scope(isolate);
-      for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
-        isolate->bootstrapper()->NativesSourceLookup(i);
-      }
-    }
-    heap->CollectAllGarbage(Heap::kNoGCFlags);
-    heap->CollectAllGarbage(Heap::kNoGCFlags);
+      Heap* heap = isolate->heap();
 
-    Object* raw_foo;
-    {
-      v8::HandleScope handle_scope(v8_isolate);
-      v8::Local<v8::String> foo = v8::String::NewFromUtf8(v8_isolate, "foo");
-      DCHECK(!foo.IsEmpty());
-      raw_foo = *(v8::Utils::OpenHandle(*foo));
-    }
+      v8::Persistent<v8::Context> env;
+      {
+        HandleScope scope(isolate);
+        env.Reset(v8_isolate, v8::Context::New(v8_isolate));
+      }
+      DCHECK(!env.IsEmpty());
+      {
+        v8::HandleScope handle_scope(v8_isolate);
+        v8::Local<v8::Context>::New(v8_isolate, env)->Enter();
+      }
+      // Make sure all builtin scripts are cached.
+      {
+        HandleScope scope(isolate);
+        for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
+          isolate->bootstrapper()->NativesSourceLookup(i);
+        }
+      }
+      heap->CollectAllGarbage(Heap::kNoGCFlags);
+      heap->CollectAllGarbage(Heap::kNoGCFlags);
+
+      Object* raw_foo;
+      {
+        v8::HandleScope handle_scope(v8_isolate);
+        v8::Local<v8::String> foo = v8::String::NewFromUtf8(v8_isolate, "foo");
+        DCHECK(!foo.IsEmpty());
+        raw_foo = *(v8::Utils::OpenHandle(*foo));
+      }
 
-    int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
-    Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
-    SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
+      int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
+      Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
+      SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
 
-    {
-      v8::HandleScope handle_scope(v8_isolate);
-      v8::Local<v8::Context>::New(v8_isolate, env)->Exit();
+      {
+        v8::HandleScope handle_scope(v8_isolate);
+        v8::Local<v8::Context>::New(v8_isolate, env)->Exit();
+      }
+      env.Reset();
+
+      FileByteSink startup_sink(startup_name.start());
+      StartupSerializer startup_serializer(isolate, &startup_sink);
+      startup_serializer.SerializeStrongReferences();
+
+      FileByteSink partial_sink(FLAG_testing_serialization_file);
+      PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink);
+      p_ser.Serialize(&raw_foo);
+      startup_serializer.SerializeWeakReferences();
+
+      partial_sink.WriteSpaceUsed(
+          p_ser.CurrentAllocationAddress(NEW_SPACE),
+          p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE),
+          p_ser.CurrentAllocationAddress(OLD_DATA_SPACE),
+          p_ser.CurrentAllocationAddress(CODE_SPACE),
+          p_ser.CurrentAllocationAddress(MAP_SPACE),
+          p_ser.CurrentAllocationAddress(CELL_SPACE),
+          p_ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE));
+
+      startup_sink.WriteSpaceUsed(
+          startup_serializer.CurrentAllocationAddress(NEW_SPACE),
+          startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE),
+          startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE),
+          startup_serializer.CurrentAllocationAddress(CODE_SPACE),
+          startup_serializer.CurrentAllocationAddress(MAP_SPACE),
+          startup_serializer.CurrentAllocationAddress(CELL_SPACE),
+          startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE));
+      startup_name.Dispose();
     }
-    env.Reset();
-
-    FileByteSink startup_sink(startup_name.start());
-    StartupSerializer startup_serializer(isolate, &startup_sink);
-    startup_serializer.SerializeStrongReferences();
-
-    FileByteSink partial_sink(FLAG_testing_serialization_file);
-    PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink);
-    p_ser.Serialize(&raw_foo);
-    startup_serializer.SerializeWeakReferences();
-
-    partial_sink.WriteSpaceUsed(
-        p_ser.CurrentAllocationAddress(NEW_SPACE),
-        p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE),
-        p_ser.CurrentAllocationAddress(OLD_DATA_SPACE),
-        p_ser.CurrentAllocationAddress(CODE_SPACE),
-        p_ser.CurrentAllocationAddress(MAP_SPACE),
-        p_ser.CurrentAllocationAddress(CELL_SPACE),
-        p_ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE));
-
-    startup_sink.WriteSpaceUsed(
-        startup_serializer.CurrentAllocationAddress(NEW_SPACE),
-        startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE),
-        startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE),
-        startup_serializer.CurrentAllocationAddress(CODE_SPACE),
-        startup_serializer.CurrentAllocationAddress(MAP_SPACE),
-        startup_serializer.CurrentAllocationAddress(CELL_SPACE),
-        startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE));
-    startup_name.Dispose();
+    v8_isolate->Exit();
+    v8_isolate->Dispose();
   }
 }
 
 
-DEPENDENT_TEST(PartialDeserialization, PartialSerialization) {
+UNINITIALIZED_DEPENDENT_TEST(PartialDeserialization, PartialSerialization) {
   if (!Snapshot::HaveASnapshotToStartFrom()) {
     int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
     Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
     SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
 
-    CHECK(InitializeFromFile(startup_name.start()));
+    v8::Isolate* v8_isolate = InitializeFromFile(startup_name.start());
+    CHECK(v8_isolate);
     startup_name.Dispose();
-
-    const char* file_name = FLAG_testing_serialization_file;
-
-    int snapshot_size = 0;
-    byte* snapshot = ReadBytes(file_name, &snapshot_size);
-
-    Isolate* isolate = CcTest::i_isolate();
-    Object* root;
     {
-      SnapshotByteSource source(snapshot, snapshot_size);
-      Deserializer deserializer(&source);
-      ReserveSpaceForSnapshot(&deserializer, file_name);
-      deserializer.DeserializePartial(isolate, &root);
-      CHECK(root->IsString());
-    }
-    HandleScope handle_scope(isolate);
-    Handle<Object> root_handle(root, isolate);
+      v8::Isolate::Scope isolate_scope(v8_isolate);
 
+      const char* file_name = FLAG_testing_serialization_file;
 
-    Object* root2;
-    {
-      SnapshotByteSource source(snapshot, snapshot_size);
-      Deserializer deserializer(&source);
-      ReserveSpaceForSnapshot(&deserializer, file_name);
-      deserializer.DeserializePartial(isolate, &root2);
-      CHECK(root2->IsString());
-      CHECK(*root_handle == root2);
+      int snapshot_size = 0;
+      byte* snapshot = ReadBytes(file_name, &snapshot_size);
+
+      Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
+      Object* root;
+      {
+        SnapshotByteSource source(snapshot, snapshot_size);
+        Deserializer deserializer(&source);
+        ReserveSpaceForSnapshot(&deserializer, file_name);
+        deserializer.DeserializePartial(isolate, &root);
+        CHECK(root->IsString());
+      }
+      HandleScope handle_scope(isolate);
+      Handle<Object> root_handle(root, isolate);
+
+
+      Object* root2;
+      {
+        SnapshotByteSource source(snapshot, snapshot_size);
+        Deserializer deserializer(&source);
+        ReserveSpaceForSnapshot(&deserializer, file_name);
+        deserializer.DeserializePartial(isolate, &root2);
+        CHECK(root2->IsString());
+        CHECK(*root_handle == root2);
+      }
     }
+    v8_isolate->Dispose();
   }
 }
 
 
-TEST(ContextSerialization) {
+UNINITIALIZED_TEST(ContextSerialization) {
   if (!Snapshot::HaveASnapshotToStartFrom()) {
-    Isolate* isolate = CcTest::i_isolate();
-    CcTest::i_isolate()->enable_serializer();
-    v8::V8::Initialize();
-    v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
+    v8::Isolate::CreateParams params;
+    params.enable_serializer = true;
+    v8::Isolate* v8_isolate = v8::Isolate::New(params);
+    Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
     Heap* heap = isolate->heap();
-
-    v8::Persistent<v8::Context> env;
     {
-      HandleScope scope(isolate);
-      env.Reset(v8_isolate, v8::Context::New(v8_isolate));
-    }
-    DCHECK(!env.IsEmpty());
-    {
-      v8::HandleScope handle_scope(v8_isolate);
-      v8::Local<v8::Context>::New(v8_isolate, env)->Enter();
-    }
-    // Make sure all builtin scripts are cached.
-    { HandleScope scope(isolate);
-      for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
-        isolate->bootstrapper()->NativesSourceLookup(i);
+      v8::Isolate::Scope isolate_scope(v8_isolate);
+
+      v8::Persistent<v8::Context> env;
+      {
+        HandleScope scope(isolate);
+        env.Reset(v8_isolate, v8::Context::New(v8_isolate));
       }
-    }
-    // If we don't do this then we end up with a stray root pointing at the
-    // context even after we have disposed of env.
-    heap->CollectAllGarbage(Heap::kNoGCFlags);
+      DCHECK(!env.IsEmpty());
+      {
+        v8::HandleScope handle_scope(v8_isolate);
+        v8::Local<v8::Context>::New(v8_isolate, env)->Enter();
+      }
+      // Make sure all builtin scripts are cached.
+      {
+        HandleScope scope(isolate);
+        for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
+          isolate->bootstrapper()->NativesSourceLookup(i);
+        }
+      }
+      // If we don't do this then we end up with a stray root pointing at the
+      // context even after we have disposed of env.
+      heap->CollectAllGarbage(Heap::kNoGCFlags);
 
-    int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
-    Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
-    SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
+      int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
+      Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
+      SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
 
-    {
-      v8::HandleScope handle_scope(v8_isolate);
-      v8::Local<v8::Context>::New(v8_isolate, env)->Exit();
-    }
+      {
+        v8::HandleScope handle_scope(v8_isolate);
+        v8::Local<v8::Context>::New(v8_isolate, env)->Exit();
+      }
 
-    i::Object* raw_context = *v8::Utils::OpenPersistent(env);
-
-    env.Reset();
-
-    FileByteSink startup_sink(startup_name.start());
-    StartupSerializer startup_serializer(isolate, &startup_sink);
-    startup_serializer.SerializeStrongReferences();
-
-    FileByteSink partial_sink(FLAG_testing_serialization_file);
-    PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink);
-    p_ser.Serialize(&raw_context);
-    startup_serializer.SerializeWeakReferences();
-
-    partial_sink.WriteSpaceUsed(
-        p_ser.CurrentAllocationAddress(NEW_SPACE),
-        p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE),
-        p_ser.CurrentAllocationAddress(OLD_DATA_SPACE),
-        p_ser.CurrentAllocationAddress(CODE_SPACE),
-        p_ser.CurrentAllocationAddress(MAP_SPACE),
-        p_ser.CurrentAllocationAddress(CELL_SPACE),
-        p_ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE));
-
-    startup_sink.WriteSpaceUsed(
-        startup_serializer.CurrentAllocationAddress(NEW_SPACE),
-        startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE),
-        startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE),
-        startup_serializer.CurrentAllocationAddress(CODE_SPACE),
-        startup_serializer.CurrentAllocationAddress(MAP_SPACE),
-        startup_serializer.CurrentAllocationAddress(CELL_SPACE),
-        startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE));
-    startup_name.Dispose();
+      i::Object* raw_context = *v8::Utils::OpenPersistent(env);
+
+      env.Reset();
+
+      FileByteSink startup_sink(startup_name.start());
+      StartupSerializer startup_serializer(isolate, &startup_sink);
+      startup_serializer.SerializeStrongReferences();
+
+      FileByteSink partial_sink(FLAG_testing_serialization_file);
+      PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink);
+      p_ser.Serialize(&raw_context);
+      startup_serializer.SerializeWeakReferences();
+
+      partial_sink.WriteSpaceUsed(
+          p_ser.CurrentAllocationAddress(NEW_SPACE),
+          p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE),
+          p_ser.CurrentAllocationAddress(OLD_DATA_SPACE),
+          p_ser.CurrentAllocationAddress(CODE_SPACE),
+          p_ser.CurrentAllocationAddress(MAP_SPACE),
+          p_ser.CurrentAllocationAddress(CELL_SPACE),
+          p_ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE));
+
+      startup_sink.WriteSpaceUsed(
+          startup_serializer.CurrentAllocationAddress(NEW_SPACE),
+          startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE),
+          startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE),
+          startup_serializer.CurrentAllocationAddress(CODE_SPACE),
+          startup_serializer.CurrentAllocationAddress(MAP_SPACE),
+          startup_serializer.CurrentAllocationAddress(CELL_SPACE),
+          startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE));
+      startup_name.Dispose();
+    }
+    v8_isolate->Dispose();
   }
 }
 
 
-DEPENDENT_TEST(ContextDeserialization, ContextSerialization) {
+UNINITIALIZED_DEPENDENT_TEST(ContextDeserialization, ContextSerialization) {
   if (!Snapshot::HaveASnapshotToStartFrom()) {
     int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
     Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
     SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
 
-    CHECK(InitializeFromFile(startup_name.start()));
+    v8::Isolate* v8_isolate = InitializeFromFile(startup_name.start());
+    CHECK(v8_isolate);
     startup_name.Dispose();
-
-    const char* file_name = FLAG_testing_serialization_file;
-
-    int snapshot_size = 0;
-    byte* snapshot = ReadBytes(file_name, &snapshot_size);
-
-    Isolate* isolate = CcTest::i_isolate();
-    Object* root;
     {
-      SnapshotByteSource source(snapshot, snapshot_size);
-      Deserializer deserializer(&source);
-      ReserveSpaceForSnapshot(&deserializer, file_name);
-      deserializer.DeserializePartial(isolate, &root);
-      CHECK(root->IsContext());
-    }
-    HandleScope handle_scope(isolate);
-    Handle<Object> root_handle(root, isolate);
+      v8::Isolate::Scope isolate_scope(v8_isolate);
 
+      const char* file_name = FLAG_testing_serialization_file;
 
-    Object* root2;
-    {
-      SnapshotByteSource source(snapshot, snapshot_size);
-      Deserializer deserializer(&source);
-      ReserveSpaceForSnapshot(&deserializer, file_name);
-      deserializer.DeserializePartial(isolate, &root2);
-      CHECK(root2->IsContext());
-      CHECK(*root_handle != root2);
+      int snapshot_size = 0;
+      byte* snapshot = ReadBytes(file_name, &snapshot_size);
+
+      Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
+      Object* root;
+      {
+        SnapshotByteSource source(snapshot, snapshot_size);
+        Deserializer deserializer(&source);
+        ReserveSpaceForSnapshot(&deserializer, file_name);
+        deserializer.DeserializePartial(isolate, &root);
+        CHECK(root->IsContext());
+      }
+      HandleScope handle_scope(isolate);
+      Handle<Object> root_handle(root, isolate);
+
+
+      Object* root2;
+      {
+        SnapshotByteSource source(snapshot, snapshot_size);
+        Deserializer deserializer(&source);
+        ReserveSpaceForSnapshot(&deserializer, file_name);
+        deserializer.DeserializePartial(isolate, &root2);
+        CHECK(root2->IsContext());
+        CHECK(*root_handle != root2);
+      }
     }
+    v8_isolate->Dispose();
   }
 }
 
@@ -799,7 +793,6 @@ TEST(SerializeToplevelIsolates) {
   v8::ScriptCompiler::CachedData* cache;
 
   v8::Isolate* isolate1 = v8::Isolate::New();
-  v8::Isolate* isolate2 = v8::Isolate::New();
   {
     v8::Isolate::Scope iscope(isolate1);
     v8::HandleScope scope(isolate1);
@@ -823,6 +816,7 @@ TEST(SerializeToplevelIsolates) {
   }
   isolate1->Dispose();
 
+  v8::Isolate* isolate2 = v8::Isolate::New();
   {
     v8::Isolate::Scope iscope(isolate2);
     v8::HandleScope scope(isolate2);
index 27ebc76..d09c128 100644 (file)
@@ -205,9 +205,7 @@ static void VerifyMemoryChunk(Isolate* isolate,
 
 TEST(Regress3540) {
   Isolate* isolate = CcTest::i_isolate();
-  isolate->InitializeLoggingAndCounters();
   Heap* heap = isolate->heap();
-  CHECK(heap->ConfigureHeapDefault());
   MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
   CHECK(
       memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize()));
@@ -241,9 +239,7 @@ static unsigned int Pseudorandom() {
 
 TEST(MemoryChunk) {
   Isolate* isolate = CcTest::i_isolate();
-  isolate->InitializeLoggingAndCounters();
   Heap* heap = isolate->heap();
-  CHECK(heap->ConfigureHeapDefault());
 
   size_t reserve_area_size = 1 * MB;
   size_t initial_commit_area_size, second_commit_area_size;
@@ -297,9 +293,7 @@ TEST(MemoryChunk) {
 
 TEST(MemoryAllocator) {
   Isolate* isolate = CcTest::i_isolate();
-  isolate->InitializeLoggingAndCounters();
   Heap* heap = isolate->heap();
-  CHECK(isolate->heap()->ConfigureHeapDefault());
 
   MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
   CHECK(memory_allocator->SetUp(heap->MaxReserved(),
@@ -346,9 +340,7 @@ TEST(MemoryAllocator) {
 
 TEST(NewSpace) {
   Isolate* isolate = CcTest::i_isolate();
-  isolate->InitializeLoggingAndCounters();
   Heap* heap = isolate->heap();
-  CHECK(heap->ConfigureHeapDefault());
   MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
   CHECK(memory_allocator->SetUp(heap->MaxReserved(),
                                 heap->MaxExecutableSize()));
@@ -374,9 +366,7 @@ TEST(NewSpace) {
 
 TEST(OldSpace) {
   Isolate* isolate = CcTest::i_isolate();
-  isolate->InitializeLoggingAndCounters();
   Heap* heap = isolate->heap();
-  CHECK(heap->ConfigureHeapDefault());
   MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
   CHECK(memory_allocator->SetUp(heap->MaxReserved(),
                                 heap->MaxExecutableSize()));
index cbd3524..f8ddc02 100644 (file)
@@ -180,10 +180,11 @@ v8::base::TimeDelta ProcessFile(
 
 
 int main(int argc, char* argv[]) {
+  v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
   v8::V8::InitializeICU();
   v8::Platform* platform = v8::platform::CreateDefaultPlatform();
   v8::V8::InitializePlatform(platform);
-  v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
+  v8::V8::Initialize();
   Encoding encoding = LATIN1;
   bool print_tokens = false;
   std::vector<std::string> fnames;
index ce18e38..2cafc83 100644 (file)
@@ -123,10 +123,11 @@ std::pair<v8::base::TimeDelta, v8::base::TimeDelta> RunBaselineParser(
 
 
 int main(int argc, char* argv[]) {
+  v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
   v8::V8::InitializeICU();
   v8::Platform* platform = v8::platform::CreateDefaultPlatform();
   v8::V8::InitializePlatform(platform);
-  v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
+  v8::V8::Initialize();
   Encoding encoding = LATIN1;
   std::vector<std::string> fnames;
   std::string benchmark;