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下express 从安装到运行的全过程

安装过程: npm install -gd express  npm install -g express-generator  express -V //查看版本,现在一般都是4.x系列的 exp...

从下载NodeJs开始到引入express模块最全的安装过程以及出现的所有问题

nodejs的安装配置,修改npm的默认全局路径遇到的问题和解决方案,node安装express模块报不是内部指令....

Nodejs 部署到阿里云全过程

转自Nodejs 部署到阿里云全过程 整个部署过程学到了不少东西,记录一下。

nodeJs学习过程之一个图片上传显示的例子

nodeJs学习过程之一个图片上传显示的例子 目标 1. 在浏览器地址栏输入“http://demos/start”,进入欢迎页面,页面有一个文件上传表单; 2. 选择一张图片并提交表单,文...

Nodejs Win8 安装过程

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

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

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

NodeJS制作爬虫全过程(续)

转自:http://www.jb51.net/article/58821.htm (原文更易阅读) 本文是接上篇NodeJS制作爬虫全过程,是最上文的一个补充以及优化,给需要的小伙伴参考下 ...

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

(25)http.ServerRequest的过程 ①http.ServerRequest提供了3个事件用于控制请求体传输: 【1】data:当请求体数据到来时,该事件被触发,提供一个参数给回调函...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:nodejs 启动过程2
举报原因:
原因补充:

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