Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/full-codegen/x64/full-codegen-x64.cc

Issue 1475823003: [runtime] First step to sanitize regexp literal creation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #if V8_TARGET_ARCH_X64 5 #if V8_TARGET_ARCH_X64
6 6
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 #include "src/codegen.h" 9 #include "src/codegen.h"
10 #include "src/debug/debug.h" 10 #include "src/debug/debug.h"
(...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 __ bind(&done); 1406 __ bind(&done);
1407 context()->Plug(rax); 1407 context()->Plug(rax);
1408 break; 1408 break;
1409 } 1409 }
1410 } 1410 }
1411 } 1411 }
1412 1412
1413 1413
1414 void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { 1414 void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
1415 Comment cmnt(masm_, "[ RegExpLiteral"); 1415 Comment cmnt(masm_, "[ RegExpLiteral");
1416 Label materialized;
1417 // Registers will be used as follows:
1418 // rdi = JS function.
1419 // rcx = literals array.
1420 // rbx = regexp literal.
1421 // rax = regexp literal clone.
1422 __ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); 1416 __ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
1423 __ movp(rcx, FieldOperand(rdi, JSFunction::kLiteralsOffset)); 1417 __ Move(rax, Smi::FromInt(expr->literal_index()));
1424 int literal_offset = LiteralsArray::OffsetOfLiteralAt(expr->literal_index()); 1418 __ Move(rcx, expr->pattern());
1425 __ movp(rbx, FieldOperand(rcx, literal_offset)); 1419 __ Move(rdx, expr->flags());
1426 __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex); 1420 FastCloneRegExpStub stub(isolate());
1427 __ j(not_equal, &materialized, Label::kNear); 1421 __ CallStub(&stub);
1428
1429 // Create regexp literal using runtime function
1430 // Result will be in rax.
1431 __ Push(rcx);
1432 __ Push(Smi::FromInt(expr->literal_index()));
1433 __ Push(expr->pattern());
1434 __ Push(expr->flags());
1435 __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4);
1436 __ movp(rbx, rax);
1437
1438 __ bind(&materialized);
1439 int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize;
1440 Label allocated, runtime_allocate;
1441 __ Allocate(size, rax, rcx, rdx, &runtime_allocate, TAG_OBJECT);
1442 __ jmp(&allocated);
1443
1444 __ bind(&runtime_allocate);
1445 __ Push(rbx);
1446 __ Push(Smi::FromInt(size));
1447 __ CallRuntime(Runtime::kAllocateInNewSpace, 1);
1448 __ Pop(rbx);
1449
1450 __ bind(&allocated);
1451 // Copy the content into the newly allocated memory.
1452 // (Unroll copy loop once for better throughput).
1453 for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) {
1454 __ movp(rdx, FieldOperand(rbx, i));
1455 __ movp(rcx, FieldOperand(rbx, i + kPointerSize));
1456 __ movp(FieldOperand(rax, i), rdx);
1457 __ movp(FieldOperand(rax, i + kPointerSize), rcx);
1458 }
1459 if ((size % (2 * kPointerSize)) != 0) {
1460 __ movp(rdx, FieldOperand(rbx, size - kPointerSize));
1461 __ movp(FieldOperand(rax, size - kPointerSize), rdx);
1462 }
1463 context()->Plug(rax); 1422 context()->Plug(rax);
1464 } 1423 }
1465 1424
1466 1425
1467 void FullCodeGenerator::EmitAccessor(ObjectLiteralProperty* property) { 1426 void FullCodeGenerator::EmitAccessor(ObjectLiteralProperty* property) {
1468 Expression* expression = (property == NULL) ? NULL : property->value(); 1427 Expression* expression = (property == NULL) ? NULL : property->value();
1469 if (expression == NULL) { 1428 if (expression == NULL) {
1470 __ PushRoot(Heap::kNullValueRootIndex); 1429 __ PushRoot(Heap::kNullValueRootIndex);
1471 } else { 1430 } else {
1472 VisitForStackValue(expression); 1431 VisitForStackValue(expression);
(...skipping 3454 matching lines...) Expand 10 before | Expand all | Expand 10 after
4927 Assembler::target_address_at(call_target_address, 4886 Assembler::target_address_at(call_target_address,
4928 unoptimized_code)); 4887 unoptimized_code));
4929 return OSR_AFTER_STACK_CHECK; 4888 return OSR_AFTER_STACK_CHECK;
4930 } 4889 }
4931 4890
4932 4891
4933 } // namespace internal 4892 } // namespace internal
4934 } // namespace v8 4893 } // namespace v8
4935 4894
4936 #endif // V8_TARGET_ARCH_X64 4895 #endif // V8_TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698