From 3ccedf895273ac6cd43363f802f9ca6f7a4cf61c Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Mon, 12 May 2014 13:47:01 +0000 Subject: [PATCH] Clean up debugger flags. R=ulan@chromium.org Review URL: https://codereview.chromium.org/261253005 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21270 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/full-codegen-arm.cc | 5 +- src/arm/lithium-codegen-arm.cc | 2 +- src/arm/macro-assembler-arm.cc | 6 +-- src/arm/macro-assembler-arm.h | 2 +- src/arm64/full-codegen-arm64.cc | 5 +- src/arm64/lithium-codegen-arm64.cc | 2 +- src/arm64/macro-assembler-arm64.cc | 6 +-- src/arm64/macro-assembler-arm64.h | 2 +- src/bootstrapper.cc | 3 +- src/codegen.cc | 3 +- src/compiler.cc | 27 +++-------- src/compiler.h | 21 +++++--- src/debug.cc | 78 +++++++----------------------- src/debug.h | 57 +++++++++++----------- src/execution.cc | 4 +- src/factory.cc | 12 +++-- src/factory.h | 3 +- src/flag-definitions.h | 11 ----- src/frames.h | 7 --- src/full-codegen.cc | 4 +- src/ia32/full-codegen-ia32.cc | 3 +- src/ia32/lithium-codegen-ia32.cc | 2 +- src/ia32/macro-assembler-ia32.cc | 6 +-- src/ia32/macro-assembler-ia32.h | 2 +- src/isolate-inl.h | 10 ---- src/isolate.h | 7 --- src/mips/full-codegen-mips.cc | 5 +- src/mips/lithium-codegen-mips.cc | 2 +- src/mips/macro-assembler-mips.cc | 6 +-- src/mips/macro-assembler-mips.h | 2 +- src/runtime.cc | 2 +- src/x64/full-codegen-x64.cc | 3 +- src/x64/lithium-codegen-x64.cc | 2 +- src/x64/macro-assembler-x64.cc | 6 +-- src/x64/macro-assembler-x64.h | 2 +- test/cctest/test-heap.cc | 3 +- 36 files changed, 126 insertions(+), 197 deletions(-) diff --git a/src/arm/full-codegen-arm.cc b/src/arm/full-codegen-arm.cc index 221526b670..3fd57d2cc4 100644 --- a/src/arm/full-codegen-arm.cc +++ b/src/arm/full-codegen-arm.cc @@ -171,7 +171,8 @@ void FullCodeGenerator::Generate() { FrameScope frame_scope(masm_, StackFrame::MANUAL); info->set_prologue_offset(masm_->pc_offset()); - __ Prologue(BUILD_FUNCTION_FRAME); + ASSERT(!info->IsStub()); + __ Prologue(info); info->AddNoFrameRange(0, masm_->pc_offset()); { Comment cmnt(masm_, "[ Allocate locals"); @@ -349,7 +350,7 @@ void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { void FullCodeGenerator::EmitProfilingCounterReset() { int reset_value = FLAG_interrupt_budget; - if (isolate()->IsDebuggerActive()) { + if (info_->is_debug()) { // Detect debug break requests as soon as possible. reset_value = FLAG_interrupt_budget >> 4; } diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index 929f57d990..2879d64111 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -140,7 +140,7 @@ bool LCodeGen::GeneratePrologue() { info()->set_prologue_offset(masm_->pc_offset()); if (NeedsEagerFrame()) { - __ Prologue(info()->IsStub() ? BUILD_STUB_FRAME : BUILD_FUNCTION_FRAME); + __ Prologue(info()); frame_is_built_ = true; info_->AddNoFrameRange(0, masm_->pc_offset()); } diff --git a/src/arm/macro-assembler-arm.cc b/src/arm/macro-assembler-arm.cc index ac8a7d3193..f354843e4a 100644 --- a/src/arm/macro-assembler-arm.cc +++ b/src/arm/macro-assembler-arm.cc @@ -902,8 +902,8 @@ void MacroAssembler::LoadConstantPoolPointerRegister() { } -void MacroAssembler::Prologue(PrologueFrameMode frame_mode) { - if (frame_mode == BUILD_STUB_FRAME) { +void MacroAssembler::Prologue(CompilationInfo* info) { + if (info->IsStub()) { PushFixedFrame(); Push(Smi::FromInt(StackFrame::STUB)); // Adjust FP to point to saved FP. @@ -913,7 +913,7 @@ void MacroAssembler::Prologue(PrologueFrameMode frame_mode) { this, kNoCodeAgeSequenceLength); // The following three instructions must remain together and unmodified // for code aging to work properly. - if (isolate()->IsCodePreAgingActive()) { + if (info->IsCodePreAgingActive()) { // Pre-age the code. Code* stub = Code::GetPreAgedCodeAgeStub(isolate()); add(r0, pc, Operand(-8)); diff --git a/src/arm/macro-assembler-arm.h b/src/arm/macro-assembler-arm.h index de705edaa3..9a2ee7a17d 100644 --- a/src/arm/macro-assembler-arm.h +++ b/src/arm/macro-assembler-arm.h @@ -519,7 +519,7 @@ class MacroAssembler: public Assembler { Label* not_int32); // Generates function and stub prologue code. - void Prologue(PrologueFrameMode frame_mode); + void Prologue(CompilationInfo* info); // Enter exit frame. // stack_space - extra stack space, used for alignment before call to C. diff --git a/src/arm64/full-codegen-arm64.cc b/src/arm64/full-codegen-arm64.cc index af007589d3..11acbb7803 100644 --- a/src/arm64/full-codegen-arm64.cc +++ b/src/arm64/full-codegen-arm64.cc @@ -170,7 +170,8 @@ void FullCodeGenerator::Generate() { // Push(lr, fp, cp, x1); // Add(fp, jssp, 2 * kPointerSize); info->set_prologue_offset(masm_->pc_offset()); - __ Prologue(BUILD_FUNCTION_FRAME); + ASSERT(!info->IsStub()); + __ Prologue(info); info->AddNoFrameRange(0, masm_->pc_offset()); // Reserve space on the stack for locals. @@ -347,7 +348,7 @@ void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { void FullCodeGenerator::EmitProfilingCounterReset() { int reset_value = FLAG_interrupt_budget; - if (isolate()->IsDebuggerActive()) { + if (info_->is_debug()) { // Detect debug break requests as soon as possible. reset_value = FLAG_interrupt_budget >> 4; } diff --git a/src/arm64/lithium-codegen-arm64.cc b/src/arm64/lithium-codegen-arm64.cc index c1e971d5b5..caa902e282 100644 --- a/src/arm64/lithium-codegen-arm64.cc +++ b/src/arm64/lithium-codegen-arm64.cc @@ -671,7 +671,7 @@ bool LCodeGen::GeneratePrologue() { ASSERT(__ StackPointer().Is(jssp)); info()->set_prologue_offset(masm_->pc_offset()); if (NeedsEagerFrame()) { - __ Prologue(info()->IsStub() ? BUILD_STUB_FRAME : BUILD_FUNCTION_FRAME); + __ Prologue(info()); frame_is_built_ = true; info_->AddNoFrameRange(0, masm_->pc_offset()); } diff --git a/src/arm64/macro-assembler-arm64.cc b/src/arm64/macro-assembler-arm64.cc index 40b0782ac7..809821abe4 100644 --- a/src/arm64/macro-assembler-arm64.cc +++ b/src/arm64/macro-assembler-arm64.cc @@ -2982,8 +2982,8 @@ void MacroAssembler::TruncateHeapNumberToI(Register result, } -void MacroAssembler::Prologue(PrologueFrameMode frame_mode) { - if (frame_mode == BUILD_STUB_FRAME) { +void MacroAssembler::Prologue(CompilationInfo* info) { + if (info->IsStub()) { ASSERT(StackPointer().Is(jssp)); UseScratchRegisterScope temps(this); Register temp = temps.AcquireX(); @@ -2993,7 +2993,7 @@ void MacroAssembler::Prologue(PrologueFrameMode frame_mode) { __ Push(lr, fp, cp, temp); __ Add(fp, jssp, StandardFrameConstants::kFixedFrameSizeFromFp); } else { - if (isolate()->IsCodePreAgingActive()) { + if (info->IsCodePreAgingActive()) { Code* stub = Code::GetPreAgedCodeAgeStub(isolate()); __ EmitCodeAgeSequence(stub); } else { diff --git a/src/arm64/macro-assembler-arm64.h b/src/arm64/macro-assembler-arm64.h index 5dc1953638..4ce240ea8e 100644 --- a/src/arm64/macro-assembler-arm64.h +++ b/src/arm64/macro-assembler-arm64.h @@ -1648,7 +1648,7 @@ class MacroAssembler : public Assembler { void ExitFrameRestoreFPRegs(); // Generates function and stub prologue code. - void Prologue(PrologueFrameMode frame_mode); + void Prologue(CompilationInfo* info); // Enter exit frame. Exit frames are used when calling C code from generated // (JavaScript) code. diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 600571e9d9..d783d24412 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -1421,7 +1421,7 @@ bool Genesis::CompileNative(Isolate* isolate, Vector name, Handle source) { HandleScope scope(isolate); - isolate->debugger()->set_compiling_natives(true); + Debugger::IgnoreScope compiling_natives(isolate->debugger()); // During genesis, the boilerplate for stack overflow won't work until the // environment has been at least partially initialized. Add a stack check // before entering JS code to catch overflow early. @@ -1437,7 +1437,6 @@ bool Genesis::CompileNative(Isolate* isolate, true); ASSERT(isolate->has_pending_exception() != result); if (!result) isolate->clear_pending_exception(); - isolate->debugger()->set_compiling_natives(false); return result; } diff --git a/src/codegen.cc b/src/codegen.cc index 9da4ea21e5..7636509547 100644 --- a/src/codegen.cc +++ b/src/codegen.cc @@ -150,7 +150,8 @@ Handle CodeGenerator::MakeCodeEpilogue(MacroAssembler* masm, Handle code = isolate->factory()->NewCode(desc, flags, masm->CodeObject(), false, is_crankshafted, - info->prologue_offset()); + info->prologue_offset(), + info->is_debug()); isolate->counters()->total_compiled_code_size()->Increment( code->instruction_size()); isolate->heap()->IncrementCodeGeneratedBytes(is_crankshafted, diff --git a/src/compiler.cc b/src/compiler.cc index 7b9f705bc3..2873525604 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -110,9 +110,9 @@ void CompilationInfo::Initialize(Isolate* isolate, } mode_ = mode; abort_due_to_dependency_ = false; - if (script_->type()->value() == Script::TYPE_NATIVE) { - MarkAsNative(); - } + if (script_->type()->value() == Script::TYPE_NATIVE) MarkAsNative(); + if (isolate_->debugger()->is_active()) MarkAsDebug(); + if (!shared_info_.is_null()) { ASSERT(strict_mode() == SLOPPY); SetStrictMode(shared_info_->strict_mode()); @@ -279,21 +279,6 @@ class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder { }; -// Determine whether to use the full compiler for all code. If the flag -// --always-full-compiler is specified this is the case. For the virtual frame -// based compiler the full compiler is also used if a debugger is connected, as -// the code from the full compiler supports mode precise break points. For the -// crankshaft adaptive compiler debugging the optimized code is not possible at -// all. However crankshaft support recompilation of functions, so in this case -// the full compiler need not be be used if a debugger is attached, but only if -// break points has actually been set. -static bool IsDebuggerActive(Isolate* isolate) { - return isolate->use_crankshaft() ? - isolate->debug()->has_break_points() : - isolate->debugger()->IsDebuggerActive(); -} - - OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() { ASSERT(isolate()->use_crankshaft()); ASSERT(info()->IsOptimizing()); @@ -311,7 +296,9 @@ OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() { // to use the Hydrogen-based optimizing compiler. We already have // generated code for this from the shared function object. if (FLAG_always_full_compiler) return AbortOptimization(); - if (IsDebuggerActive(isolate())) return AbortOptimization(kDebuggerIsActive); + + // Do not use crankshaft if compiling for debugging. + if (info()->is_debug()) return AbortOptimization(kDebuggerIsActive); // Limit the number of times we re-compile a functions with // the optimizing compiler. @@ -711,6 +698,8 @@ MaybeHandle Compiler::GetCodeForDebugging(Handle function) { Isolate* isolate = info.isolate(); VMState state(isolate); + info.MarkAsDebug(); + ASSERT(!isolate->has_pending_exception()); Handle old_code(function->shared()->code()); ASSERT(old_code->kind() == Code::FUNCTION); diff --git a/src/compiler.h b/src/compiler.h index fd26d24d71..ac4dfd4e3e 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -50,7 +50,6 @@ class CompilationInfo { bool is_eval() const { return IsEval::decode(flags_); } bool is_global() const { return IsGlobal::decode(flags_); } StrictMode strict_mode() const { return StrictModeField::decode(flags_); } - bool is_in_loop() const { return IsInLoop::decode(flags_); } FunctionLiteral* function() const { return function_; } Scope* scope() const { return scope_; } Scope* global_scope() const { return global_scope_; } @@ -95,10 +94,6 @@ class CompilationInfo { ASSERT(this->strict_mode() == SLOPPY || this->strict_mode() == strict_mode); flags_ = StrictModeField::update(flags_, strict_mode); } - void MarkAsInLoop() { - ASSERT(is_lazy()); - flags_ |= IsInLoop::encode(true); - } void MarkAsNative() { flags_ |= IsNative::encode(true); } @@ -151,6 +146,18 @@ class CompilationInfo { return MustNotHaveEagerFrame::decode(flags_); } + void MarkAsDebug() { + flags_ |= IsDebug::encode(true); + } + + bool is_debug() const { + return IsDebug::decode(flags_); + } + + bool IsCodePreAgingActive() const { + return FLAG_optimize_for_size && FLAG_age_code && !is_debug(); + } + void SetParseRestriction(ParseRestriction restriction) { flags_ = ParseRestricitonField::update(flags_, restriction); } @@ -353,8 +360,8 @@ class CompilationInfo { // Flags that can be set for eager compilation. class IsEval: public BitField {}; class IsGlobal: public BitField {}; - // Flags that can be set for lazy compilation. - class IsInLoop: public BitField {}; + // If the function is being compiled for the debugger. + class IsDebug: public BitField {}; // Strict mode - used in eager compilation. class StrictModeField: public BitField {}; // Is this a function from our natives. diff --git a/src/debug.cc b/src/debug.cc index 300f1dbcf6..6adb38a17c 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -766,11 +766,9 @@ bool Debug::Load() { // Bail out if we're already in the process of compiling the native // JavaScript source code for the debugger. - if (debugger->compiling_natives() || - debugger->is_loading_debugger()) - return false; - debugger->set_loading_debugger(true); + if (debugger->ignore_debugger()) return false; + Debugger::IgnoreScope during_load(debugger); // Disable breakpoints and interrupts while compiling and running the // debugger scripts including the context creation code. DisableBreak disable(isolate_, true); @@ -806,7 +804,6 @@ bool Debug::Load() { false); // Compile the JavaScript for the debugger in the debugger context. - debugger->set_compiling_natives(true); bool caught_exception = !CompileDebuggerScript(isolate_, Natives::GetIndex("mirror")) || !CompileDebuggerScript(isolate_, Natives::GetIndex("debug")); @@ -816,11 +813,8 @@ bool Debug::Load() { !CompileDebuggerScript(isolate_, Natives::GetIndex("liveedit")); } - debugger->set_compiling_natives(false); - // Make sure we mark the debugger as not loading before we might // return. - debugger->set_loading_debugger(false); // Check for caught exceptions. if (caught_exception) return false; @@ -1998,37 +1992,15 @@ class ActiveFunctionsRedirector : public ThreadVisitor { }; -class ForceDebuggerActive { - public: - explicit ForceDebuggerActive(Isolate *isolate) { - isolate_ = isolate; - old_state_ = isolate->debugger()->force_debugger_active(); - isolate_->debugger()->set_force_debugger_active(true); - } - - ~ForceDebuggerActive() { - isolate_->debugger()->set_force_debugger_active(old_state_); - } - - private: - Isolate *isolate_; - bool old_state_; - - DISALLOW_COPY_AND_ASSIGN(ForceDebuggerActive); -}; - - void Debug::EnsureFunctionHasDebugBreakSlots(Handle function) { if (function->code()->kind() == Code::FUNCTION && function->code()->has_debug_break_slots()) { // Nothing to do. Function code already had debug break slots. return; } - // Make sure that the shared full code is compiled with debug // break slots. if (!function->shared()->code()->has_debug_break_slots()) { - ForceDebuggerActive force_debugger_active(isolate_); MaybeHandle code = Compiler::GetCodeForDebugging(function); // Recompilation can fail. In that case leave the code as it was. if (!code.is_null()) function->ReplaceCode(*code.ToHandleChecked()); @@ -2652,14 +2624,12 @@ void Debug::AfterGarbageCollection() { Debugger::Debugger(Isolate* isolate) - : debugger_access_(isolate->debugger_access()), - event_listener_(Handle()), + : event_listener_(Handle()), event_listener_data_(Handle()), - compiling_natives_(false), - is_loading_debugger_(false), + is_active_(false), + ignore_debugger_(false), live_edit_enabled_(true), never_unload_debugger_(false), - force_debugger_active_(false), message_handler_(NULL), debugger_unload_pending_(false), debug_message_dispatch_handler_(NULL), @@ -2760,7 +2730,7 @@ void Debugger::OnException(Handle exception, bool uncaught) { // Bail out based on state or if there is no listener for this event if (debug->InDebugger()) return; - if (!Debugger::EventActive(v8::Exception)) return; + if (!Debugger::EventActive()) return; Handle promise = debug->GetPromiseForUncaughtException(); uncaught |= !promise->IsUndefined(); @@ -2804,7 +2774,7 @@ void Debugger::OnDebugBreak(Handle break_points_hit, ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); // Bail out if there is no listener for this event - if (!Debugger::EventActive(v8::Break)) return; + if (!Debugger::EventActive()) return; // Debugger must be entered in advance. ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); @@ -2826,8 +2796,7 @@ void Debugger::OnBeforeCompile(Handle