A simple question on HEscapeAnalysisPhase in V8

15 views
Skip to first unread message

maxs...@gmail.com

unread,
Apr 7, 2015, 12:47:15 AM4/7/15
to v8-u...@googlegroups.com
Hi, all:
      I am a newbie to V8. When I use the following test-case to study the EscapeAnalysis pass in V8, I found that:
 ===========================test case start===========================
$ cat examp0.js 
function f(x) {
    var o = new Object();
    if (x < 30)
        x = x - 5;
    else
        x = 23;
    o.myprop = x;
}

for (var i = 0; i < 1000; ++i) {
    f(i);
}
 ===========================test case end ===========================

I add a HIR dump function like this:

=================================================================
+ void HEscapeAnalysisPhase::dumpCurrentGraph() {
+     HGraph *G = graph();
+     const ZoneList<HBasicBlock*>* blocks = G->blocks();
+     for (int i = 0; i < blocks->length(); i++) {
+         HBasicBlock* current = blocks->at(i);
+         std::cout << "B" << current->block_id() << ":\n";
+         for (HInstructionIterator it(current); !it.Done(); it.Advance()) {
+             HInstruction* instruction = it.Current();
+             std::cout << " " << NameOf(instruction) << " " << *instruction << "\n";
+         }
+     }
+     return;
+ }
  void HEscapeAnalysisPhase::Run() {
    // TODO(mstarzinger): We disable escape analysis with OSR for now, because
    // spill slots might be uninitialized. Needs investigation.
    if (graph()->has_osr()) return;
+   dumpCurrentGraph();
    int max_fixpoint_iteration_count = FLAG_escape_analysis_iterations;
    ...
=================================================================

the results and questions:

1, V8 calls the HEscapeAnalysisPhase::Run() for 4 times.
    question?   When does v8 call this function?
2,  dumpCurrentGraph() corrupt in the fourth call, the error messages are:
=======================================================
$ d8 --use_escape_analysis --trace_escape_analysis examp0.js 1>code.hir

#
# Fatal error in .././src/isolate.h, line 497
# Check failed: isolate != __null.
#

==== C stack trace ===============================

 1: V8_Fatal
 2: v8::internal::Isolate::Current()
 3: v8::internal::HConstant::PrintDataTo(std::ostream&) const
 4: v8::internal::HInstruction::PrintTo(std::ostream&) const
 5: v8::internal::operator<<(std::ostream&, v8::internal::HValue const&)
 6: v8::internal::HEscapeAnalysisPhase::dumpCurrentGraph()
 7: v8::internal::HEscapeAnalysisPhase::Run()
 8: void v8::internal::HGraph::Run<v8::internal::HEscapeAnalysisPhase>()
 9: v8::internal::HGraph::Optimize(v8::internal::BailoutReason*)
10: v8::internal::OptimizedCompileJob::OptimizeGraph()
11: v8::internal::OptimizingCompilerThread::CompileNext(v8::internal::OptimizedCompileJob*)
12: v8::internal::OptimizingCompilerThread::Run()
13: v8::base::Thread::NotifyStartedAndRun()
14: ??
15: ??
16: clone
Illegal instruction (core dumped)
=======================================================
question?  wha's the reason?

Thanks for your help. Thanks.

Jakob Kummerow

unread,
Apr 7, 2015, 4:35:03 AM4/7/15
to v8-u...@googlegroups.com
On Tue, Apr 7, 2015 at 6:47 AM, <maxs...@gmail.com> wrote:
I add a HIR dump function like this:

You might like to know that there already is a --trace-hydrogen flag. It produces a hydrogen.cfg file that you can load into c1visualizer.
 
1, V8 calls the HEscapeAnalysisPhase::Run() for 4 times.
    question?   When does v8 call this function?

When the "Crankshaft" compiler compiles something (functions or stubs). You can grep for it.
 
2,  dumpCurrentGraph() corrupt in the fourth call, the error messages are:
question?  wha's the reason?

The concurrent compilation thread doesn't have access to an isolate, so it can't convert instructions to strings as "std::cout << *instruction" requires. --noconcurrent-recompilation should help.

Reply all
Reply to author
Forward
0 new messages