Separate output files for --trace-hydrogen.

The output filenames have now the form "hydrogen-<ProcessId>-<IsolateId>.cfg".
Minor cleanup on the way.

Note that we have a similar bug regarding statistics, but this will be handled
in a separate CL.

BUG=v8:2563

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13834 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 50703c70
...@@ -59,9 +59,9 @@ class CodeStubGraphBuilderBase : public HGraphBuilder { ...@@ -59,9 +59,9 @@ class CodeStubGraphBuilderBase : public HGraphBuilder {
CodeStubGraphBuilderBase(Isolate* isolate, HydrogenCodeStub* stub) CodeStubGraphBuilderBase(Isolate* isolate, HydrogenCodeStub* stub)
: HGraphBuilder(&info_), info_(stub, isolate), context_(NULL) { : HGraphBuilder(&info_), info_(stub, isolate), context_(NULL) {
int major_key = stub->MajorKey(); int major_key = stub->MajorKey();
descriptor_ = info_.isolate()->code_stub_interface_descriptor(major_key); descriptor_ = isolate->code_stub_interface_descriptor(major_key);
if (descriptor_->register_param_count_ < 0) { if (descriptor_->register_param_count_ < 0) {
stub->InitializeInterfaceDescriptor(info_.isolate(), descriptor_); stub->InitializeInterfaceDescriptor(isolate, descriptor_);
} }
parameters_.Reset(new HParameter*[descriptor_->register_param_count_]); parameters_.Reset(new HParameter*[descriptor_->register_param_count_]);
} }
...@@ -88,7 +88,7 @@ bool CodeStubGraphBuilderBase::BuildGraph() { ...@@ -88,7 +88,7 @@ bool CodeStubGraphBuilderBase::BuildGraph() {
const char* name = CodeStub::MajorName(stub()->MajorKey(), false); const char* name = CodeStub::MajorName(stub()->MajorKey(), false);
PrintF("-----------------------------------------------------------\n"); PrintF("-----------------------------------------------------------\n");
PrintF("Compiling stub %s using hydrogen\n", name); PrintF("Compiling stub %s using hydrogen\n", name);
HTracer::Instance()->TraceCompilation(&info_); isolate()->GetHTracer()->TraceCompilation(&info_);
} }
Zone* zone = this->zone(); Zone* zone = this->zone();
......
...@@ -277,7 +277,7 @@ OptimizingCompiler::Status OptimizingCompiler::CreateGraph() { ...@@ -277,7 +277,7 @@ OptimizingCompiler::Status OptimizingCompiler::CreateGraph() {
// Fall back to using the full code generator if it's not possible // Fall back to using the full code generator if it's not possible
// to use the Hydrogen-based optimizing compiler. We already have // to use the Hydrogen-based optimizing compiler. We already have
// generated code for this from the shared function object. // generated code for this from the shared function object.
if (AlwaysFullCompiler(info()->isolate())) { if (AlwaysFullCompiler(isolate())) {
info()->SetCode(code); info()->SetCode(code);
return SetLastStatus(BAILED_OUT); return SetLastStatus(BAILED_OUT);
} }
...@@ -330,7 +330,7 @@ OptimizingCompiler::Status OptimizingCompiler::CreateGraph() { ...@@ -330,7 +330,7 @@ OptimizingCompiler::Status OptimizingCompiler::CreateGraph() {
// performance of the hydrogen-based compiler. // performance of the hydrogen-based compiler.
bool should_recompile = !info()->shared_info()->has_deoptimization_support(); bool should_recompile = !info()->shared_info()->has_deoptimization_support();
if (should_recompile || FLAG_hydrogen_stats) { if (should_recompile || FLAG_hydrogen_stats) {
HPhase phase(HPhase::kFullCodeGen); HPhase phase(HPhase::kFullCodeGen, isolate());
CompilationInfoWithZone unoptimized(info()->shared_info()); CompilationInfoWithZone unoptimized(info()->shared_info());
// Note that we use the same AST that we will use for generating the // Note that we use the same AST that we will use for generating the
// optimized code. // optimized code.
...@@ -360,18 +360,18 @@ OptimizingCompiler::Status OptimizingCompiler::CreateGraph() { ...@@ -360,18 +360,18 @@ OptimizingCompiler::Status OptimizingCompiler::CreateGraph() {
if (FLAG_trace_hydrogen) { if (FLAG_trace_hydrogen) {
PrintF("-----------------------------------------------------------\n"); PrintF("-----------------------------------------------------------\n");
PrintF("Compiling method %s using hydrogen\n", *name->ToCString()); PrintF("Compiling method %s using hydrogen\n", *name->ToCString());
HTracer::Instance()->TraceCompilation(info()); isolate()->GetHTracer()->TraceCompilation(info());
} }
Handle<Context> native_context( Handle<Context> native_context(
info()->closure()->context()->native_context()); info()->closure()->context()->native_context());
oracle_ = new(info()->zone()) TypeFeedbackOracle( oracle_ = new(info()->zone()) TypeFeedbackOracle(
code, native_context, info()->isolate(), info()->zone()); code, native_context, isolate(), info()->zone());
graph_builder_ = new(info()->zone()) HOptimizedGraphBuilder(info(), oracle_); graph_builder_ = new(info()->zone()) HOptimizedGraphBuilder(info(), oracle_);
Timer t(this, &time_taken_to_create_graph_); Timer t(this, &time_taken_to_create_graph_);
graph_ = graph_builder_->CreateGraph(); graph_ = graph_builder_->CreateGraph();
if (info()->isolate()->has_pending_exception()) { if (isolate()->has_pending_exception()) {
info()->SetCode(Handle<Code>::null()); info()->SetCode(Handle<Code>::null());
return SetLastStatus(FAILED); return SetLastStatus(FAILED);
} }
......
...@@ -830,7 +830,7 @@ void HGraphBuilder::LoopBuilder::EndBody() { ...@@ -830,7 +830,7 @@ void HGraphBuilder::LoopBuilder::EndBody() {
HGraph* HGraphBuilder::CreateGraph() { HGraph* HGraphBuilder::CreateGraph() {
graph_ = new(zone()) HGraph(info_); graph_ = new(zone()) HGraph(info_);
if (FLAG_hydrogen_stats) HStatistics::Instance()->Initialize(info_); if (FLAG_hydrogen_stats) HStatistics::Instance()->Initialize(info_);
HPhase phase("H_Block building"); HPhase phase("H_Block building", graph()->isolate());
set_current_block(graph()->entry_block()); set_current_block(graph()->entry_block());
if (!BuildGraph()) return NULL; if (!BuildGraph()) return NULL;
return graph_; return graph_;
...@@ -1553,7 +1553,7 @@ class PostorderProcessor : public ZoneObject { ...@@ -1553,7 +1553,7 @@ class PostorderProcessor : public ZoneObject {
void HGraph::OrderBlocks() { void HGraph::OrderBlocks() {
HPhase phase("H_Block ordering"); HPhase phase("H_Block ordering", isolate());
BitVector visited(blocks_.length(), zone()); BitVector visited(blocks_.length(), zone());
ZoneList<HBasicBlock*> reverse_result(8, zone()); ZoneList<HBasicBlock*> reverse_result(8, zone());
...@@ -10713,7 +10713,7 @@ void HTracer::TraceLiveRange(LiveRange* range, const char* type, ...@@ -10713,7 +10713,7 @@ void HTracer::TraceLiveRange(LiveRange* range, const char* type,
void HTracer::FlushToFile() { void HTracer::FlushToFile() {
AppendChars(filename_, *trace_.ToCString(), trace_.length(), false); AppendChars(filename_.start(), *trace_.ToCString(), trace_.length(), false);
trace_.Reset(); trace_.Reset();
} }
...@@ -10798,10 +10798,33 @@ void HStatistics::SaveTiming(const char* name, int64_t ticks, unsigned size) { ...@@ -10798,10 +10798,33 @@ void HStatistics::SaveTiming(const char* name, int64_t ticks, unsigned size) {
const char* const HPhase::kFullCodeGen = "Full code generator"; const char* const HPhase::kFullCodeGen = "Full code generator";
void HPhase::Begin(const char* name,
HGraph* graph, HPhase::HPhase(const char* name, Isolate* isolate) {
LChunk* chunk, Init(isolate, name, NULL, NULL, NULL);
LAllocator* allocator) { }
HPhase::HPhase(const char* name, HGraph* graph) {
Init(graph->isolate(), name, graph, NULL, NULL);
}
HPhase::HPhase(const char* name, LChunk* chunk) {
Init(chunk->graph()->isolate(), name, NULL, chunk, NULL);
}
HPhase::HPhase(const char* name, LAllocator* allocator) {
Init(allocator->graph()->isolate(), name, NULL, NULL, allocator);
}
void HPhase::Init(Isolate* isolate,
const char* name,
HGraph* graph,
LChunk* chunk,
LAllocator* allocator) {
isolate_ = isolate;
name_ = name; name_ = name;
graph_ = graph; graph_ = graph;
chunk_ = chunk; chunk_ = chunk;
...@@ -10809,26 +10832,32 @@ void HPhase::Begin(const char* name, ...@@ -10809,26 +10832,32 @@ void HPhase::Begin(const char* name,
if (allocator != NULL && chunk_ == NULL) { if (allocator != NULL && chunk_ == NULL) {
chunk_ = allocator->chunk(); chunk_ = allocator->chunk();
} }
if (FLAG_hydrogen_stats) start_ = OS::Ticks(); if (FLAG_hydrogen_stats) {
start_allocation_size_ = Zone::allocation_size_; start_ticks_ = OS::Ticks();
start_allocation_size_ = Zone::allocation_size_;
}
} }
void HPhase::End() const { HPhase::~HPhase() {
if (FLAG_hydrogen_stats) { if (FLAG_hydrogen_stats) {
int64_t end = OS::Ticks(); int64_t ticks = OS::Ticks() - start_ticks_;
unsigned size = Zone::allocation_size_ - start_allocation_size_; unsigned size = Zone::allocation_size_ - start_allocation_size_;
HStatistics::Instance()->SaveTiming(name_, end - start_, size); HStatistics::Instance()->SaveTiming(name_, ticks, size);
} }
// Produce trace output if flag is set so that the first letter of the // Produce trace output if flag is set so that the first letter of the
// phase name matches the command line parameter FLAG_trace_phase. // phase name matches the command line parameter FLAG_trace_phase.
if (FLAG_trace_hydrogen && if (FLAG_trace_hydrogen &&
OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL) { OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL) {
if (graph_ != NULL) HTracer::Instance()->TraceHydrogen(name_, graph_); if (graph_ != NULL) {
if (chunk_ != NULL) HTracer::Instance()->TraceLithium(name_, chunk_); isolate_->GetHTracer()->TraceHydrogen(name_, graph_);
}
if (chunk_ != NULL) {
isolate_->GetHTracer()->TraceLithium(name_, chunk_);
}
if (allocator_ != NULL) { if (allocator_ != NULL) {
HTracer::Instance()->TraceLiveRanges(name_, allocator_); isolate_->GetHTracer()->TraceLiveRanges(name_, allocator_);
} }
} }
......
...@@ -1581,52 +1581,45 @@ class HPhase BASE_EMBEDDED { ...@@ -1581,52 +1581,45 @@ class HPhase BASE_EMBEDDED {
public: public:
static const char* const kFullCodeGen; static const char* const kFullCodeGen;
explicit HPhase(const char* name) { Begin(name, NULL, NULL, NULL); } HPhase(const char* name, Isolate* isolate);
HPhase(const char* name, HGraph* graph) { HPhase(const char* name, HGraph* graph);
Begin(name, graph, NULL, NULL); HPhase(const char* name, LChunk* chunk);
} HPhase(const char* name, LAllocator* allocator);
HPhase(const char* name, LChunk* chunk) { ~HPhase();
Begin(name, NULL, chunk, NULL);
}
HPhase(const char* name, LAllocator* allocator) {
Begin(name, NULL, NULL, allocator);
}
~HPhase() {
End();
}
private: private:
void Begin(const char* name, void Init(Isolate* isolate,
const char* name,
HGraph* graph, HGraph* graph,
LChunk* chunk, LChunk* chunk,
LAllocator* allocator); LAllocator* allocator);
void End() const;
int64_t start_; Isolate* isolate_;
const char* name_; const char* name_;
HGraph* graph_; HGraph* graph_;
LChunk* chunk_; LChunk* chunk_;
LAllocator* allocator_; LAllocator* allocator_;
int64_t start_ticks_;
unsigned start_allocation_size_; unsigned start_allocation_size_;
}; };
class HTracer: public Malloced { class HTracer: public Malloced {
public: public:
explicit HTracer(int isolate_id)
: trace_(&string_allocator_), indent_(0) {
OS::SNPrintF(filename_,
"hydrogen-%d-%d.cfg",
OS::GetCurrentProcessId(),
isolate_id);
WriteChars(filename_.start(), "", 0, false);
}
void TraceCompilation(CompilationInfo* info); void TraceCompilation(CompilationInfo* info);
void TraceHydrogen(const char* name, HGraph* graph); void TraceHydrogen(const char* name, HGraph* graph);
void TraceLithium(const char* name, LChunk* chunk); void TraceLithium(const char* name, LChunk* chunk);
void TraceLiveRanges(const char* name, LAllocator* allocator); void TraceLiveRanges(const char* name, LAllocator* allocator);
static HTracer* Instance() {
static SetOncePointer<HTracer> instance;
if (!instance.is_set()) {
instance.set(new HTracer("hydrogen.cfg"));
}
return instance.get();
}
private: private:
class Tag BASE_EMBEDDED { class Tag BASE_EMBEDDED {
public: public:
...@@ -1651,11 +1644,6 @@ class HTracer: public Malloced { ...@@ -1651,11 +1644,6 @@ class HTracer: public Malloced {
const char* name_; const char* name_;
}; };
explicit HTracer(const char* filename)
: filename_(filename), trace_(&string_allocator_), indent_(0) {
WriteChars(filename, "", 0, false);
}
void TraceLiveRange(LiveRange* range, const char* type, Zone* zone); void TraceLiveRange(LiveRange* range, const char* type, Zone* zone);
void Trace(const char* name, HGraph* graph, LChunk* chunk); void Trace(const char* name, HGraph* graph, LChunk* chunk);
void FlushToFile(); void FlushToFile();
...@@ -1691,7 +1679,7 @@ class HTracer: public Malloced { ...@@ -1691,7 +1679,7 @@ class HTracer: public Malloced {
} }
} }
const char* filename_; EmbeddedVector<char, 64> filename_;
HeapStringAllocator string_allocator_; HeapStringAllocator string_allocator_;
StringStream trace_; StringStream trace_;
int indent_; int indent_;
......
...@@ -338,7 +338,7 @@ Thread::LocalStorageKey Isolate::thread_id_key_; ...@@ -338,7 +338,7 @@ Thread::LocalStorageKey Isolate::thread_id_key_;
Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_;
Mutex* Isolate::process_wide_mutex_ = OS::CreateMutex(); Mutex* Isolate::process_wide_mutex_ = OS::CreateMutex();
Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL;
Atomic32 Isolate::isolate_counter_ = 0;
Isolate::PerIsolateThreadData* Isolate::AllocatePerIsolateThreadData( Isolate::PerIsolateThreadData* Isolate::AllocatePerIsolateThreadData(
ThreadId thread_id) { ThreadId thread_id) {
...@@ -1624,7 +1624,8 @@ void Isolate::ThreadDataTable::RemoveAllThreads(Isolate* isolate) { ...@@ -1624,7 +1624,8 @@ void Isolate::ThreadDataTable::RemoveAllThreads(Isolate* isolate) {
#define TRACE_ISOLATE(tag) \ #define TRACE_ISOLATE(tag) \
do { \ do { \
if (FLAG_trace_isolates) { \ if (FLAG_trace_isolates) { \
PrintF("Isolate %p " #tag "\n", reinterpret_cast<void*>(this)); \ PrintF("Isolate %p (id %d)" #tag "\n", \
reinterpret_cast<void*>(this), id()); \
} \ } \
} while (false) } while (false)
#else #else
...@@ -1684,6 +1685,7 @@ Isolate::Isolate() ...@@ -1684,6 +1685,7 @@ Isolate::Isolate()
optimizing_compiler_thread_(this), optimizing_compiler_thread_(this),
marking_thread_(NULL), marking_thread_(NULL),
sweeper_thread_(NULL) { sweeper_thread_(NULL) {
id_ = NoBarrier_AtomicIncrement(&isolate_counter_, 1);
TRACE_ISOLATE(constructor); TRACE_ISOLATE(constructor);
memset(isolate_addresses_, 0, memset(isolate_addresses_, 0,
...@@ -2316,6 +2318,12 @@ void Isolate::UnlinkDeferredHandles(DeferredHandles* deferred) { ...@@ -2316,6 +2318,12 @@ void Isolate::UnlinkDeferredHandles(DeferredHandles* deferred) {
} }
HTracer* Isolate::GetHTracer() {
if (htracer() == NULL) set_htracer(new HTracer(id()));
return htracer();
}
CodeStubInterfaceDescriptor* CodeStubInterfaceDescriptor*
Isolate::code_stub_interface_descriptor(int index) { Isolate::code_stub_interface_descriptor(int index) {
return code_stub_interface_descriptors_ + index; return code_stub_interface_descriptors_ + index;
......
...@@ -68,6 +68,7 @@ class Factory; ...@@ -68,6 +68,7 @@ class Factory;
class FunctionInfoListener; class FunctionInfoListener;
class HandleScopeImplementer; class HandleScopeImplementer;
class HeapProfiler; class HeapProfiler;
class HTracer;
class InlineRuntimeFunctionsTable; class InlineRuntimeFunctionsTable;
class NoAllocationStringAllocator; class NoAllocationStringAllocator;
class InnerPointerToCodeCache; class InnerPointerToCodeCache;
...@@ -372,6 +373,7 @@ typedef List<HeapObject*, PreallocatedStorageAllocationPolicy> DebugObjectCache; ...@@ -372,6 +373,7 @@ typedef List<HeapObject*, PreallocatedStorageAllocationPolicy> DebugObjectCache;
V(CpuProfiler*, cpu_profiler, NULL) \ V(CpuProfiler*, cpu_profiler, NULL) \
V(HeapProfiler*, heap_profiler, NULL) \ V(HeapProfiler*, heap_profiler, NULL) \
V(bool, observer_delivery_pending, false) \ V(bool, observer_delivery_pending, false) \
V(HTracer*, htracer, NULL) \
ISOLATE_DEBUGGER_INIT_LIST(V) ISOLATE_DEBUGGER_INIT_LIST(V)
class Isolate { class Isolate {
...@@ -1100,9 +1102,13 @@ class Isolate { ...@@ -1100,9 +1102,13 @@ class Isolate {
return sweeper_thread_; return sweeper_thread_;
} }
HTracer* GetHTracer();
private: private:
Isolate(); Isolate();
int id() const { return static_cast<int>(id_); }
friend struct GlobalState; friend struct GlobalState;
friend struct InitializeGlobalState; friend struct InitializeGlobalState;
...@@ -1170,6 +1176,9 @@ class Isolate { ...@@ -1170,6 +1176,9 @@ class Isolate {
static Isolate* default_isolate_; static Isolate* default_isolate_;
static ThreadDataTable* thread_data_table_; static ThreadDataTable* thread_data_table_;
// A global counter for all generated Isolates, might overflow.
static Atomic32 isolate_counter_;
void Deinit(); void Deinit();
static void SetIsolateThreadLocals(Isolate* isolate, static void SetIsolateThreadLocals(Isolate* isolate,
...@@ -1214,6 +1223,7 @@ class Isolate { ...@@ -1214,6 +1223,7 @@ class Isolate {
// the Error object. // the Error object.
bool IsErrorObject(Handle<Object> obj); bool IsErrorObject(Handle<Object> obj);
Atomic32 id_;
EntryStackItem* entry_stack_; EntryStackItem* entry_stack_;
int stack_trace_nesting_level_; int stack_trace_nesting_level_;
StringStream* incomplete_message_; StringStream* incomplete_message_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment