V8 Project
v8::internal::BackEdgeTable Class Reference

#include <full-codegen.h>

+ Collaboration diagram for v8::internal::BackEdgeTable:

Public Types

enum  BackEdgeState { INTERRUPT , ON_STACK_REPLACEMENT , OSR_AFTER_STACK_CHECK }
 

Public Member Functions

 BackEdgeTable (Code *code, DisallowHeapAllocation *required)
 
uint32_t length ()
 
BailoutId ast_id (uint32_t index)
 
uint32_t loop_depth (uint32_t index)
 
uint32_t pc_offset (uint32_t index)
 
Address pc (uint32_t index)
 

Static Public Member Functions

static void Patch (Isolate *isolate, Code *unoptimized_code)
 
static void PatchAt (Code *unoptimized_code, Address pc, BackEdgeState target_state, Code *replacement_code)
 
static void Revert (Isolate *isolate, Code *unoptimized_code)
 
static void AddStackCheck (Handle< Code > code, uint32_t pc_offset)
 
static void RemoveStackCheck (Handle< Code > code, uint32_t pc_offset)
 
static BackEdgeState GetBackEdgeState (Isolate *isolate, Code *unoptimized_code, Address pc_after)
 

Private Member Functions

Address entry_at (uint32_t index)
 

Private Attributes

Address start_
 
Address instruction_start_
 
uint32_t length_
 

Static Private Attributes

static const int kTableLengthSize = kIntSize
 
static const int kAstIdOffset = 0 * kIntSize
 
static const int kPcOffsetOffset = 1 * kIntSize
 
static const int kLoopDepthOffset = 2 * kIntSize
 
static const int kEntrySize = 3 * kIntSize
 

Detailed Description

Definition at line 877 of file full-codegen.h.

Member Enumeration Documentation

◆ BackEdgeState

Enumerator
INTERRUPT 
ON_STACK_REPLACEMENT 
OSR_AFTER_STACK_CHECK 

Definition at line 906 of file full-codegen.h.

Constructor & Destructor Documentation

◆ BackEdgeTable()

v8::internal::BackEdgeTable::BackEdgeTable ( Code code,
DisallowHeapAllocation required 
)
inline

Definition at line 879 of file full-codegen.h.

879  {
880  DCHECK(code->kind() == Code::FUNCTION);
881  instruction_start_ = code->instruction_start();
882  Address table_address = instruction_start_ + code->back_edge_table_offset();
883  length_ = Memory::uint32_at(table_address);
884  start_ = table_address + kTableLengthSize;
885  }
static const int kTableLengthSize
Definition: full-codegen.h:948
static uint32_t & uint32_at(Address addr)
Definition: v8memory.h:24
#define DCHECK(condition)
Definition: logging.h:205
byte * Address
Definition: globals.h:101

References v8::internal::Code::back_edge_table_offset(), DCHECK, v8::internal::Code::instruction_start(), instruction_start_, v8::internal::Code::kind(), kTableLengthSize, length_, start_, and v8::internal::Memory::uint32_at().

+ Here is the call graph for this function:

Member Function Documentation

◆ AddStackCheck()

void v8::internal::BackEdgeTable::AddStackCheck ( Handle< Code code,
uint32_t  pc_offset 
)
static

Definition at line 1675 of file full-codegen.cc.

1675  {
1676  DisallowHeapAllocation no_gc;
1677  Isolate* isolate = code->GetIsolate();
1678  Address pc = code->instruction_start() + pc_offset;
1679  Code* patch = isolate->builtins()->builtin(Builtins::kOsrAfterStackCheck);
1680  PatchAt(*code, pc, OSR_AFTER_STACK_CHECK, patch);
1681 }
uint32_t pc_offset(uint32_t index)
Definition: full-codegen.h:898
static void PatchAt(Code *unoptimized_code, Address pc, BackEdgeState target_state, Code *replacement_code)
Address pc(uint32_t index)
Definition: full-codegen.h:902
PerThreadAssertScopeDebugOnly< HEAP_ALLOCATION_ASSERT, false > DisallowHeapAllocation
Definition: assert-scope.h:110

References v8::internal::Builtins::builtin(), v8::internal::Isolate::builtins(), and v8::internal::pc.

Referenced by v8::internal::RUNTIME_FUNCTION().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ast_id()

BailoutId v8::internal::BackEdgeTable::ast_id ( uint32_t  index)
inline

Definition at line 889 of file full-codegen.h.

889  {
890  return BailoutId(static_cast<int>(
892  }
Address entry_at(uint32_t index)
Definition: full-codegen.h:943
static const int kAstIdOffset
Definition: full-codegen.h:949

References entry_at(), kAstIdOffset, and v8::internal::Memory::uint32_at().

Referenced by v8::internal::Code::TranslateAstIdToPcOffset(), and v8::internal::Code::TranslatePcOffsetToAstId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ entry_at()

Address v8::internal::BackEdgeTable::entry_at ( uint32_t  index)
inlineprivate

Definition at line 943 of file full-codegen.h.

943  {
944  DCHECK(index < length_);
945  return start_ + index * kEntrySize;
946  }
static const int kEntrySize
Definition: full-codegen.h:952

References DCHECK, kEntrySize, length_, and start_.

Referenced by ast_id(), loop_depth(), and pc_offset().

+ Here is the caller graph for this function:

◆ GetBackEdgeState()

static BackEdgeState v8::internal::BackEdgeTable::GetBackEdgeState ( Isolate isolate,
Code unoptimized_code,
Address  pc_after 
)
static

◆ length()

uint32_t v8::internal::BackEdgeTable::length ( )
inline

Definition at line 887 of file full-codegen.h.

887 { return length_; }

References length_.

Referenced by Patch(), Revert(), v8::internal::Code::TranslateAstIdToPcOffset(), and v8::internal::Code::TranslatePcOffsetToAstId().

+ Here is the caller graph for this function:

◆ loop_depth()

uint32_t v8::internal::BackEdgeTable::loop_depth ( uint32_t  index)
inline

Definition at line 894 of file full-codegen.h.

894  {
896  }
static const int kLoopDepthOffset
Definition: full-codegen.h:951

References entry_at(), kLoopDepthOffset, and v8::internal::Memory::uint32_at().

Referenced by Patch(), and Revert().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Patch()

void v8::internal::BackEdgeTable::Patch ( Isolate isolate,
Code unoptimized_code 
)
static

Definition at line 1627 of file full-codegen.cc.

1627  {
1628  DisallowHeapAllocation no_gc;
1629  Code* patch = isolate->builtins()->builtin(Builtins::kOnStackReplacement);
1630 
1631  // Increment loop nesting level by one and iterate over the back edge table
1632  // to find the matching loops to patch the interrupt
1633  // call to an unconditional call to the replacement code.
1634  int loop_nesting_level = unoptimized->allow_osr_at_loop_nesting_level() + 1;
1635  if (loop_nesting_level > Code::kMaxLoopNestingMarker) return;
1636 
1637  BackEdgeTable back_edges(unoptimized, &no_gc);
1638  for (uint32_t i = 0; i < back_edges.length(); i++) {
1639  if (static_cast<int>(back_edges.loop_depth(i)) == loop_nesting_level) {
1641  unoptimized,
1642  back_edges.pc(i)));
1643  PatchAt(unoptimized, back_edges.pc(i), ON_STACK_REPLACEMENT, patch);
1644  }
1645  }
1646 
1647  unoptimized->set_allow_osr_at_loop_nesting_level(loop_nesting_level);
1648  DCHECK(Verify(isolate, unoptimized));
1649 }
BackEdgeTable(Code *code, DisallowHeapAllocation *required)
Definition: full-codegen.h:879
static BackEdgeState GetBackEdgeState(Isolate *isolate, Code *unoptimized_code, Address pc_after)
static const int kMaxLoopNestingMarker
Definition: objects.h:5346
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206

References v8::internal::Code::allow_osr_at_loop_nesting_level(), v8::internal::Builtins::builtin(), v8::internal::Isolate::builtins(), DCHECK, DCHECK_EQ, v8::internal::Code::kMaxLoopNestingMarker, length(), loop_depth(), pc(), and v8::internal::Code::set_allow_osr_at_loop_nesting_level().

Referenced by v8::internal::RuntimeProfiler::AttemptOnStackReplacement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PatchAt()

static void v8::internal::BackEdgeTable::PatchAt ( Code unoptimized_code,
Address  pc,
BackEdgeState  target_state,
Code replacement_code 
)
static

◆ pc()

Address v8::internal::BackEdgeTable::pc ( uint32_t  index)
inline

Definition at line 902 of file full-codegen.h.

902  {
903  return instruction_start_ + pc_offset(index);
904  }

References instruction_start_, and pc_offset().

Referenced by Patch(), and Revert().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pc_offset()

uint32_t v8::internal::BackEdgeTable::pc_offset ( uint32_t  index)
inline

Definition at line 898 of file full-codegen.h.

898  {
899  return Memory::uint32_at(entry_at(index) + kPcOffsetOffset);
900  }
static const int kPcOffsetOffset
Definition: full-codegen.h:950

References entry_at(), kPcOffsetOffset, and v8::internal::Memory::uint32_at().

Referenced by pc(), v8::internal::Code::TranslateAstIdToPcOffset(), and v8::internal::Code::TranslatePcOffsetToAstId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RemoveStackCheck()

void v8::internal::BackEdgeTable::RemoveStackCheck ( Handle< Code code,
uint32_t  pc_offset 
)
static

Definition at line 1684 of file full-codegen.cc.

1684  {
1685  DisallowHeapAllocation no_gc;
1686  Isolate* isolate = code->GetIsolate();
1687  Address pc = code->instruction_start() + pc_offset;
1688 
1689  if (OSR_AFTER_STACK_CHECK == GetBackEdgeState(isolate, *code, pc)) {
1690  Code* patch = isolate->builtins()->builtin(Builtins::kOnStackReplacement);
1691  PatchAt(*code, pc, ON_STACK_REPLACEMENT, patch);
1692  }
1693 }

References v8::internal::Builtins::builtin(), v8::internal::Isolate::builtins(), and v8::internal::pc.

Referenced by v8::internal::DisposeOptimizedCompileJob(), and v8::internal::OptimizingCompilerThread::InstallOptimizedFunctions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Revert()

void v8::internal::BackEdgeTable::Revert ( Isolate isolate,
Code unoptimized_code 
)
static

Definition at line 1652 of file full-codegen.cc.

1652  {
1653  DisallowHeapAllocation no_gc;
1654  Code* patch = isolate->builtins()->builtin(Builtins::kInterruptCheck);
1655 
1656  // Iterate over the back edge table and revert the patched interrupt calls.
1657  int loop_nesting_level = unoptimized->allow_osr_at_loop_nesting_level();
1658 
1659  BackEdgeTable back_edges(unoptimized, &no_gc);
1660  for (uint32_t i = 0; i < back_edges.length(); i++) {
1661  if (static_cast<int>(back_edges.loop_depth(i)) <= loop_nesting_level) {
1663  unoptimized,
1664  back_edges.pc(i)));
1665  PatchAt(unoptimized, back_edges.pc(i), INTERRUPT, patch);
1666  }
1667  }
1668 
1669  unoptimized->set_allow_osr_at_loop_nesting_level(0);
1670  // Assert that none of the back edges are patched anymore.
1671  DCHECK(Verify(isolate, unoptimized));
1672 }
#define DCHECK_NE(v1, v2)
Definition: logging.h:207

References v8::internal::Code::allow_osr_at_loop_nesting_level(), v8::internal::Builtins::builtin(), v8::internal::Isolate::builtins(), DCHECK, DCHECK_NE, length(), loop_depth(), pc(), and v8::internal::Code::set_allow_osr_at_loop_nesting_level().

Referenced by v8::internal::RUNTIME_FUNCTION().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ instruction_start_

Address v8::internal::BackEdgeTable::instruction_start_
private

Definition at line 955 of file full-codegen.h.

Referenced by BackEdgeTable(), and pc().

◆ kAstIdOffset

const int v8::internal::BackEdgeTable::kAstIdOffset = 0 * kIntSize
staticprivate

Definition at line 949 of file full-codegen.h.

Referenced by ast_id().

◆ kEntrySize

const int v8::internal::BackEdgeTable::kEntrySize = 3 * kIntSize
staticprivate

Definition at line 952 of file full-codegen.h.

Referenced by entry_at().

◆ kLoopDepthOffset

const int v8::internal::BackEdgeTable::kLoopDepthOffset = 2 * kIntSize
staticprivate

Definition at line 951 of file full-codegen.h.

Referenced by loop_depth().

◆ kPcOffsetOffset

const int v8::internal::BackEdgeTable::kPcOffsetOffset = 1 * kIntSize
staticprivate

Definition at line 950 of file full-codegen.h.

Referenced by pc_offset().

◆ kTableLengthSize

const int v8::internal::BackEdgeTable::kTableLengthSize = kIntSize
staticprivate

Definition at line 948 of file full-codegen.h.

Referenced by BackEdgeTable().

◆ length_

uint32_t v8::internal::BackEdgeTable::length_
private

Definition at line 956 of file full-codegen.h.

Referenced by BackEdgeTable(), entry_at(), and length().

◆ start_

Address v8::internal::BackEdgeTable::start_
private

Definition at line 954 of file full-codegen.h.

Referenced by BackEdgeTable(), and entry_at().


The documentation for this class was generated from the following files: