nodejs 启动过程2

原创 2013年12月03日 11:59:55

 Isolate::Init

bool Isolate::Init(Deserializer* des) {
  ASSERT(state_ != INITIALIZED);
  ASSERT(Isolate::Current() == this);
  TRACE_ISOLATE(init);


  // The initialization process does not handle memory exhaustion.
  DisallowAllocationFailure disallow_allocation_failure;


  InitializeLoggingAndCounters();


  InitializeDebugger();

// 内存分配器
  memory_allocator_ = new MemoryAllocator(this);
  code_range_ = new CodeRange(this);

// TODO:下面的未分析
  // Safe after setting Heap::isolate_, initializing StackGuard and
  // ensuring that Isolate::Current() == this.
  heap_.SetStackLimits();


#define ASSIGN_ELEMENT(CamelName, hacker_name)                  \
  isolate_addresses_[Isolate::k##CamelName##Address] =          \
      reinterpret_cast<Address>(hacker_name##_address());
  FOR_EACH_ISOLATE_ADDRESS_NAME(ASSIGN_ELEMENT)
#undef C


  string_tracker_ = new StringTracker();
  string_tracker_->isolate_ = this;
  compilation_cache_ = new CompilationCache(this);
  transcendental_cache_ = new TranscendentalCache();
  keyed_lookup_cache_ = new KeyedLookupCache();
  context_slot_cache_ = new ContextSlotCache();
  descriptor_lookup_cache_ = new DescriptorLookupCache();
  unicode_cache_ = new UnicodeCache();
  inner_pointer_to_code_cache_ = new InnerPointerToCodeCache(this);
  write_input_buffer_ = new StringInputBuffer();
  global_handles_ = new GlobalHandles(this);
  bootstrapper_ = new Bootstrapper();
  handle_scope_implementer_ = new HandleScopeImplementer(this);
  stub_cache_ = new StubCache(this, runtime_zone());
  regexp_stack_ = new RegExpStack();
  regexp_stack_->isolate_ = this;
  date_cache_ = new DateCache();


  // Enable logging before setting up the heap
  logger_->SetUp();


  CpuProfiler::SetUp();
  HeapProfiler::SetUp();


  // Initialize other runtime facilities
#if defined(USE_SIMULATOR)
#if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS)
  Simulator::Initialize(this);
#endif
#endif


  { // NOLINT
    // Ensure that the thread has a valid stack guard.  The v8::Locker object
    // will ensure this too, but we don't have to use lockers if we are only
    // using one thread.
    ExecutionAccess lock(this);
    stack_guard_.InitThread(lock);
  }


  // SetUp the object heap.
  const bool create_heap_objects = (des == NULL);
  ASSERT(!heap_.HasBeenSetUp());
  if (!heap_.SetUp(create_heap_objects)) {
    V8::SetFatalError();
    return false;
  }


  if (create_heap_objects) {
    // Terminate the cache array with the sentinel so we can iterate.
    PushToPartialSnapshotCache(heap_.undefined_value());
  }


  InitializeThreadLocal();


  bootstrapper_->Initialize(create_heap_objects);
  builtins_.SetUp(create_heap_objects);


  // Only preallocate on the first initialization.
  if (FLAG_preallocate_message_memory && preallocated_message_space_ == NULL) {
    // Start the thread which will set aside some memory.
    PreallocatedMemoryThreadStart();
    preallocated_message_space_ =
        new NoAllocationStringAllocator(
            preallocated_memory_thread_->data(),
            preallocated_memory_thread_->length());
    PreallocatedStorageInit(preallocated_memory_thread_->length() / 4);
  }


  if (FLAG_preemption) {
    v8::Locker locker;
    v8::Locker::StartPreemption(100);
  }


#ifdef ENABLE_DEBUGGER_SUPPORT
  debug_->SetUp(create_heap_objects);
#endif


  // If we are deserializing, read the state into the now-empty heap.
  if (!create_heap_objects) {
    des->Deserialize();
  }
  stub_cache_->Initialize();


  // Finish initialization of ThreadLocal after deserialization is done.
  clear_pending_exception();
  clear_pending_message();
  clear_scheduled_exception();


  // Deserializing may put strange things in the root array's copy of the
  // stack guard.
  heap_.SetStackLimits();


  // Quiet the heap NaN if needed on target platform.
  if (!create_heap_objects) Assembler::QuietNaN(heap_.nan_value());


  deoptimizer_data_ = new DeoptimizerData;
  runtime_profiler_ = new RuntimeProfiler(this);
  runtime_profiler_->SetUp();


  // If we are deserializing, log non-function code objects and compiled
  // functions found in the snapshot.
  if (create_heap_objects &&
      (FLAG_log_code || FLAG_ll_prof || logger_->is_logging_code_events())) {
    HandleScope scope;
    LOG(this, LogCodeObjects());
    LOG(this, LogCompiledFunctions());
  }


  CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, state_)),
           Internals::kIsolateStateOffset);
  CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, embedder_data_)),
           Internals::kIsolateEmbedderDataOffset);
  CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, heap_.roots_)),
           Internals::kIsolateRootsOffset);


  state_ = INITIALIZED;
  time_millis_at_init_ = OS::TimeCurrentMillis();
  if (FLAG_parallel_recompilation) optimizing_compiler_thread_.Start();
  return true;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

nodejs c++启动过程1

在isolate文件中中: struct StaticInitializer {   StaticInitializer() {     Isolate::EnsureDefaultIsolate()...

NodeJs——(8)http.ServerRequest的过程

(25)http.ServerRequest的过程 ①http.ServerRequest提供了3个事件用于控制请求体传输: 【1】data:当请求体数据到来时,该事件被触发,提供一个参数给回调函...

Nodejs Win8 安装过程

现在才开始着手写点Nodejs 东西.之前都是在ubuntu系统和centos系统下进行编程的,现在来了点兴趣, 搞下windows下的Nodejs 编程开发.主要是为了方便. Don`t sha...

nodejs+mongodb实现curd 登录 注销 分页等功能的实现过程

e page.  */ //取得一个集合中的所有数据并实现分页效果,这里我们还处理session的登录判断等exports.index = function(req, res){ var mo...

微信小程序[全栈]-配置本地Nodejs服务器全过程

总结填坑过程(2017.1.19):电脑系统:Win7 64位。 Web服务器:Nodejs 数据库:MongoDB 这个实例主要是要实现微信小程序的全栈测试。值得研究。 具体的逻辑是:可以实...

NodeJs的学习一:centos中的安装过程

如果你想长期做 node 开发, 或者想快速更新 node 版本, 或者想快速切换 node 版本, 那么在非 Windows(如 osx, linux) 环境下, 请使用 nvm 来安装你的 nod...

NodeJS基础API搭建服务器详细过程记录

前言在习惯了使用express框架,jade模板引擎等现成工具来写代码之后,很多人对于基本的NodeJS API会慢慢生疏。本文将以一个超小型web项目,来详细介绍如何使用NodeJS基础的http,...

Nodejs源码的阅读-事件循环的过程

Nodejs源码的阅读-事件循环的过程   解读基于node V0.2.0   Unknown Watcher 首先在“Nodejs源码的阅读-事件循环的建立”中我们看到有几个初始化但是没有start...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)