Commit f2ea65d9 authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[Debugger] Hold a strong reference to debug bytecode from DebugInfo.

With BytecodeArray flushing the SFI->BytecodeArray pointer will become pseudo weak.
In order to prevent instrumented bytecode from being flushed while the function is
being debugged, hold onto the instrumented bytecode strongly.

BUG=v8:8395

Change-Id: Ie346732b77833afa0595a84a4956295e50855392
Reviewed-on: https://chromium-review.googlesource.com/c/1312849Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57569}
parent c8cbf23a
......@@ -1205,6 +1205,7 @@ void Debug::PrepareFunctionForDebugExecution(
handle(shared->GetBytecodeArray(), isolate_);
Handle<BytecodeArray> debug_bytecode_array =
isolate_->factory()->CopyBytecodeArray(original_bytecode_array);
debug_info->set_debug_bytecode_array(*debug_bytecode_array);
shared->SetDebugBytecodeArray(*debug_bytecode_array);
maybe_original_bytecode_array = original_bytecode_array;
}
......
......@@ -3632,6 +3632,7 @@ Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) {
debug_info->set_script(shared->script_or_debug_info());
debug_info->set_original_bytecode_array(
ReadOnlyRoots(heap).undefined_value());
debug_info->set_debug_bytecode_array(ReadOnlyRoots(heap).undefined_value());
debug_info->set_break_points(ReadOnlyRoots(heap).empty_fixed_array());
// Link debug info to function.
......
......@@ -2184,6 +2184,7 @@ void DebugInfo::DebugInfoPrint(std::ostream& os) { // NOLINT
os << "\n - shared: " << Brief(shared());
os << "\n - script: " << Brief(script());
os << "\n - original bytecode array: " << Brief(original_bytecode_array());
os << "\n - debug bytecode array: " << Brief(debug_bytecode_array());
os << "\n - break_points: ";
break_points()->FixedArrayPrint(os);
os << "\n - coverage_info: " << Brief(coverage_info());
......
......@@ -27,6 +27,7 @@ SMI_ACCESSORS(DebugInfo, debugger_hints, kDebuggerHintsOffset)
ACCESSORS(DebugInfo, script, Object, kScriptOffset)
ACCESSORS(DebugInfo, original_bytecode_array, Object,
kOriginalBytecodeArrayOffset)
ACCESSORS(DebugInfo, debug_bytecode_array, Object, kDebugBytecodeArrayOffset)
ACCESSORS(DebugInfo, break_points, FixedArray, kBreakPointsStateOffset)
ACCESSORS(DebugInfo, coverage_info, Object, kCoverageInfoOffset)
......@@ -46,7 +47,9 @@ SMI_ACCESSORS(BreakPoint, id, kIdOffset)
ACCESSORS(BreakPoint, condition, String, kConditionOffset)
bool DebugInfo::HasInstrumentedBytecodeArray() {
return original_bytecode_array()->IsBytecodeArray();
DCHECK_EQ(debug_bytecode_array()->IsBytecodeArray(),
original_bytecode_array()->IsBytecodeArray());
return debug_bytecode_array()->IsBytecodeArray();
}
BytecodeArray* DebugInfo::OriginalBytecodeArray() {
......@@ -56,7 +59,8 @@ BytecodeArray* DebugInfo::OriginalBytecodeArray() {
BytecodeArray* DebugInfo::DebugBytecodeArray() {
DCHECK(HasInstrumentedBytecodeArray());
return shared()->GetDebugBytecodeArray();
DCHECK_EQ(shared()->GetDebugBytecodeArray(), debug_bytecode_array());
return BytecodeArray::cast(debug_bytecode_array());
}
} // namespace internal
......
......@@ -30,6 +30,7 @@ void DebugInfo::ClearBreakInfo(Isolate* isolate) {
// array.
shared()->SetDebugBytecodeArray(OriginalBytecodeArray());
set_original_bytecode_array(ReadOnlyRoots(isolate).undefined_value());
set_debug_bytecode_array(ReadOnlyRoots(isolate).undefined_value());
}
set_break_points(ReadOnlyRoots(isolate).empty_fixed_array());
......
......@@ -85,6 +85,10 @@ class DebugInfo : public Struct, public NeverReadOnlySpaceObject {
// points - the instrumented bytecode is held in the shared function info.
DECL_ACCESSORS(original_bytecode_array, Object)
// The debug instrumented bytecode array for functions with break points
// - also pointed to by the shared function info.
DECL_ACCESSORS(debug_bytecode_array, Object)
// Fixed array holding status information for each active break point.
DECL_ACCESSORS(break_points, FixedArray)
......@@ -167,8 +171,10 @@ class DebugInfo : public Struct, public NeverReadOnlySpaceObject {
kSharedFunctionInfoOffset + kPointerSize;
static const int kScriptOffset = kDebuggerHintsOffset + kPointerSize;
static const int kOriginalBytecodeArrayOffset = kScriptOffset + kPointerSize;
static const int kBreakPointsStateOffset =
static const int kDebugBytecodeArrayOffset =
kOriginalBytecodeArrayOffset + kPointerSize;
static const int kBreakPointsStateOffset =
kDebugBytecodeArrayOffset + kPointerSize;
static const int kFlagsOffset = kBreakPointsStateOffset + kPointerSize;
static const int kCoverageInfoOffset = kFlagsOffset + kPointerSize;
static const int kSize = kCoverageInfoOffset + kPointerSize;
......
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