PPC/s390: [regexp] Apply the backtrack limit in jitted code
Port 0089006fc5
Original Commit Message:
.. similar to how it is applied in the interpreter. We reserve a stack
slot for the backtrack count, increment it on each backtrack, and fail
if the limit is hit.
R=jgruber@chromium.org, joransiu@ca.ibm.com, jyan@ca.ibm.com, michael_dawson@ca.ibm.com
BUG=
LOG=N
Change-Id: Ic0c0f8569b2c2596976136d96971e7fa39f9e145
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1872430
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Joran Siu <joransiu@ca.ibm.com>
Commit-Queue: Milad Farazmand <miladfar@ca.ibm.com>
Cr-Commit-Position: refs/heads/master@{#64473}
This commit is contained in:
parent
b0c7ed06f3
commit
4d779bac70
@ -170,6 +170,19 @@ void RegExpMacroAssemblerPPC::AdvanceRegister(int reg, int by) {
|
||||
|
||||
void RegExpMacroAssemblerPPC::Backtrack() {
|
||||
CheckPreemption();
|
||||
if (has_backtrack_limit()) {
|
||||
Label next;
|
||||
__ LoadP(r3, MemOperand(frame_pointer(), kBacktrackCount), r0);
|
||||
__ addi(r3, r3, Operand(1));
|
||||
__ StoreP(r3, MemOperand(frame_pointer(), kBacktrackCount), r0);
|
||||
__ cmpi(r3, Operand(backtrack_limit()));
|
||||
__ bne(&next);
|
||||
|
||||
// Exceeded limits are treated as a failed match.
|
||||
Fail();
|
||||
|
||||
__ bind(&next);
|
||||
}
|
||||
// Pop Code offset from backtrack stack, add Code and jump to location.
|
||||
Pop(r3);
|
||||
__ add(r3, r3, code_pointer());
|
||||
@ -682,9 +695,16 @@ Handle<HeapObject> RegExpMacroAssemblerPPC::GetCode(Handle<String> source) {
|
||||
// Set frame pointer in space for it if this is not a direct call
|
||||
// from generated code.
|
||||
__ addi(frame_pointer(), sp, Operand(8 * kPointerSize));
|
||||
|
||||
STATIC_ASSERT(kSuccessfulCaptures == kInputString - kSystemPointerSize);
|
||||
__ li(r3, Operand::Zero());
|
||||
__ push(r3); // Make room for success counter and initialize it to 0.
|
||||
STATIC_ASSERT(kStringStartMinusOne ==
|
||||
kSuccessfulCaptures - kSystemPointerSize);
|
||||
__ push(r3); // Make room for "string start - 1" constant.
|
||||
STATIC_ASSERT(kBacktrackCount == kStringStartMinusOne - kSystemPointerSize);
|
||||
__ push(r3); // The backtrack counter.
|
||||
|
||||
// Check if we have space on the stack for registers.
|
||||
Label stack_limit_hit;
|
||||
Label stack_ok;
|
||||
|
@ -112,8 +112,9 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerPPC
|
||||
// the frame in GetCode.
|
||||
static const int kSuccessfulCaptures = kInputString - kPointerSize;
|
||||
static const int kStringStartMinusOne = kSuccessfulCaptures - kPointerSize;
|
||||
static const int kBacktrackCount = kStringStartMinusOne - kSystemPointerSize;
|
||||
// First register address. Following registers are below it on the stack.
|
||||
static const int kRegisterZero = kStringStartMinusOne - kPointerSize;
|
||||
static const int kRegisterZero = kBacktrackCount - kSystemPointerSize;
|
||||
|
||||
// Initial size of code buffer.
|
||||
static const int kRegExpCodeSize = 1024;
|
||||
|
@ -164,6 +164,19 @@ void RegExpMacroAssemblerS390::AdvanceRegister(int reg, int by) {
|
||||
|
||||
void RegExpMacroAssemblerS390::Backtrack() {
|
||||
CheckPreemption();
|
||||
if (has_backtrack_limit()) {
|
||||
Label next;
|
||||
__ LoadP(r2, MemOperand(frame_pointer(), kBacktrackCount), r0);
|
||||
__ AddP(r2, r2, Operand(1));
|
||||
__ StoreP(r2, MemOperand(frame_pointer(), kBacktrackCount), r0);
|
||||
__ CmpLogicalP(r2, Operand(backtrack_limit()));
|
||||
__ bne(&next);
|
||||
|
||||
// Exceeded limits are treated as a failed match.
|
||||
Fail();
|
||||
|
||||
__ bind(&next);
|
||||
}
|
||||
// Pop Code offset from backtrack stack, add Code and jump to location.
|
||||
Pop(r2);
|
||||
__ AddP(r2, code_pointer());
|
||||
@ -659,10 +672,14 @@ Handle<HeapObject> RegExpMacroAssemblerS390::GetCode(Handle<String> source) {
|
||||
// from generated code.
|
||||
__ LoadRR(frame_pointer(), sp);
|
||||
__ lay(sp, MemOperand(sp, -10 * kSystemPointerSize));
|
||||
STATIC_ASSERT(kSuccessfulCaptures == kInputString - kSystemPointerSize);
|
||||
__ mov(r1, Operand::Zero()); // success counter
|
||||
STATIC_ASSERT(kStringStartMinusOne ==
|
||||
kSuccessfulCaptures - kSystemPointerSize);
|
||||
__ LoadRR(r0, r1); // offset of location
|
||||
__ StoreMultipleP(r0, r9, MemOperand(sp, 0));
|
||||
|
||||
STATIC_ASSERT(kBacktrackCount == kStringStartMinusOne - kSystemPointerSize);
|
||||
__ Push(r1); // The backtrack counter.
|
||||
// Check if we have space on the stack for registers.
|
||||
Label stack_limit_hit;
|
||||
Label stack_ok;
|
||||
|
@ -114,8 +114,9 @@ class V8_EXPORT_PRIVATE RegExpMacroAssemblerS390
|
||||
static const int kSuccessfulCaptures = kInputString - kSystemPointerSize;
|
||||
static const int kStringStartMinusOne =
|
||||
kSuccessfulCaptures - kSystemPointerSize;
|
||||
static const int kBacktrackCount = kStringStartMinusOne - kSystemPointerSize;
|
||||
// First register address. Following registers are below it on the stack.
|
||||
static const int kRegisterZero = kStringStartMinusOne - kSystemPointerSize;
|
||||
static const int kRegisterZero = kBacktrackCount - kSystemPointerSize;
|
||||
|
||||
// Initial size of code buffer.
|
||||
static const int kRegExpCodeSize = 1024;
|
||||
|
Loading…
Reference in New Issue
Block a user