| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 mode_(mode), | 127 mode_(mode), |
| 128 num_registers_(registers_to_save), | 128 num_registers_(registers_to_save), |
| 129 num_saved_registers_(registers_to_save), | 129 num_saved_registers_(registers_to_save), |
| 130 entry_label_(), | 130 entry_label_(), |
| 131 start_label_(), | 131 start_label_(), |
| 132 success_label_(), | 132 success_label_(), |
| 133 backtrack_label_(), | 133 backtrack_label_(), |
| 134 exit_label_() { | 134 exit_label_() { |
| 135 ASSERT_EQ(0, registers_to_save % 2); | 135 ASSERT_EQ(0, registers_to_save % 2); |
| 136 __ jmp(&entry_label_); // We'll write the entry code later. | 136 __ jmp(&entry_label_); // We'll write the entry code later. |
| 137 EmitBacktrackConstantPool(); | |
| 138 __ bind(&start_label_); // And then continue from here. | 137 __ bind(&start_label_); // And then continue from here. |
| 139 } | 138 } |
| 140 | 139 |
| 141 | 140 |
| 142 RegExpMacroAssemblerARM::~RegExpMacroAssemblerARM() { | 141 RegExpMacroAssemblerARM::~RegExpMacroAssemblerARM() { |
| 143 delete masm_; | 142 delete masm_; |
| 144 // Unuse labels in case we throw away the assembler without calling GetCode. | 143 // Unuse labels in case we throw away the assembler without calling GetCode. |
| 145 entry_label_.Unuse(); | 144 entry_label_.Unuse(); |
| 146 start_label_.Unuse(); | 145 start_label_.Unuse(); |
| 147 success_label_.Unuse(); | 146 success_label_.Unuse(); |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 __ bind(&exit_with_exception); | 864 __ bind(&exit_with_exception); |
| 866 // Exit with Result EXCEPTION(-1) to signal thrown exception. | 865 // Exit with Result EXCEPTION(-1) to signal thrown exception. |
| 867 __ mov(r0, Operand(EXCEPTION)); | 866 __ mov(r0, Operand(EXCEPTION)); |
| 868 __ jmp(&return_r0); | 867 __ jmp(&return_r0); |
| 869 } | 868 } |
| 870 | 869 |
| 871 CodeDesc code_desc; | 870 CodeDesc code_desc; |
| 872 masm_->GetCode(&code_desc); | 871 masm_->GetCode(&code_desc); |
| 873 Handle<Code> code = isolate()->factory()->NewCode( | 872 Handle<Code> code = isolate()->factory()->NewCode( |
| 874 code_desc, Code::ComputeFlags(Code::REGEXP), masm_->CodeObject()); | 873 code_desc, Code::ComputeFlags(Code::REGEXP), masm_->CodeObject()); |
| 875 PROFILE(Isolate::Current(), RegExpCodeCreateEvent(*code, *source)); | 874 PROFILE(masm_->isolate(), RegExpCodeCreateEvent(*code, *source)); |
| 876 return Handle<HeapObject>::cast(code); | 875 return Handle<HeapObject>::cast(code); |
| 877 } | 876 } |
| 878 | 877 |
| 879 | 878 |
| 880 void RegExpMacroAssemblerARM::GoTo(Label* to) { | 879 void RegExpMacroAssemblerARM::GoTo(Label* to) { |
| 881 BranchOrBacktrack(al, to); | 880 BranchOrBacktrack(al, to); |
| 882 } | 881 } |
| 883 | 882 |
| 884 | 883 |
| 885 void RegExpMacroAssemblerARM::IfRegisterGE(int reg, | 884 void RegExpMacroAssemblerARM::IfRegisterGE(int reg, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 Pop(current_input_offset()); | 930 Pop(current_input_offset()); |
| 932 } | 931 } |
| 933 | 932 |
| 934 | 933 |
| 935 void RegExpMacroAssemblerARM::PopRegister(int register_index) { | 934 void RegExpMacroAssemblerARM::PopRegister(int register_index) { |
| 936 Pop(r0); | 935 Pop(r0); |
| 937 __ str(r0, register_location(register_index)); | 936 __ str(r0, register_location(register_index)); |
| 938 } | 937 } |
| 939 | 938 |
| 940 | 939 |
| 941 static bool is_valid_memory_offset(int value) { | |
| 942 if (value < 0) value = -value; | |
| 943 return value < (1<<12); | |
| 944 } | |
| 945 | |
| 946 | |
| 947 void RegExpMacroAssemblerARM::PushBacktrack(Label* label) { | 940 void RegExpMacroAssemblerARM::PushBacktrack(Label* label) { |
| 948 if (label->is_bound()) { | 941 __ mov_label_offset(r0, label); |
| 949 int target = label->pos(); | |
| 950 __ mov(r0, Operand(target + Code::kHeaderSize - kHeapObjectTag)); | |
| 951 } else { | |
| 952 int constant_offset = GetBacktrackConstantPoolEntry(); | |
| 953 masm_->label_at_put(label, constant_offset); | |
| 954 // Reading pc-relative is based on the address 8 bytes ahead of | |
| 955 // the current opcode. | |
| 956 unsigned int offset_of_pc_register_read = | |
| 957 masm_->pc_offset() + Assembler::kPcLoadDelta; | |
| 958 int pc_offset_of_constant = | |
| 959 constant_offset - offset_of_pc_register_read; | |
| 960 ASSERT(pc_offset_of_constant < 0); | |
| 961 if (is_valid_memory_offset(pc_offset_of_constant)) { | |
| 962 Assembler::BlockConstPoolScope block_const_pool(masm_); | |
| 963 __ ldr(r0, MemOperand(pc, pc_offset_of_constant)); | |
| 964 } else { | |
| 965 // Not a 12-bit offset, so it needs to be loaded from the constant | |
| 966 // pool. | |
| 967 Assembler::BlockConstPoolScope block_const_pool(masm_); | |
| 968 __ mov(r0, Operand(pc_offset_of_constant + Assembler::kInstrSize)); | |
| 969 __ ldr(r0, MemOperand(pc, r0)); | |
| 970 } | |
| 971 } | |
| 972 Push(r0); | 942 Push(r0); |
| 973 CheckStackLimit(); | 943 CheckStackLimit(); |
| 974 } | 944 } |
| 975 | 945 |
| 976 | 946 |
| 977 void RegExpMacroAssemblerARM::PushCurrentPosition() { | 947 void RegExpMacroAssemblerARM::PushCurrentPosition() { |
| 978 Push(current_input_offset()); | 948 Push(current_input_offset()); |
| 979 } | 949 } |
| 980 | 950 |
| 981 | 951 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 void RegExpMacroAssemblerARM::WriteStackPointerToRegister(int reg) { | 1018 void RegExpMacroAssemblerARM::WriteStackPointerToRegister(int reg) { |
| 1049 __ ldr(r1, MemOperand(frame_pointer(), kStackHighEnd)); | 1019 __ ldr(r1, MemOperand(frame_pointer(), kStackHighEnd)); |
| 1050 __ sub(r0, backtrack_stackpointer(), r1); | 1020 __ sub(r0, backtrack_stackpointer(), r1); |
| 1051 __ str(r0, register_location(reg)); | 1021 __ str(r0, register_location(reg)); |
| 1052 } | 1022 } |
| 1053 | 1023 |
| 1054 | 1024 |
| 1055 // Private methods: | 1025 // Private methods: |
| 1056 | 1026 |
| 1057 void RegExpMacroAssemblerARM::CallCheckStackGuardState(Register scratch) { | 1027 void RegExpMacroAssemblerARM::CallCheckStackGuardState(Register scratch) { |
| 1058 static const int num_arguments = 3; | 1028 __ PrepareCallCFunction(3, scratch); |
| 1059 __ PrepareCallCFunction(num_arguments, scratch); | 1029 |
| 1060 // RegExp code frame pointer. | 1030 // RegExp code frame pointer. |
| 1061 __ mov(r2, frame_pointer()); | 1031 __ mov(r2, frame_pointer()); |
| 1062 // Code* of self. | 1032 // Code* of self. |
| 1063 __ mov(r1, Operand(masm_->CodeObject())); | 1033 __ mov(r1, Operand(masm_->CodeObject())); |
| 1064 // r0 becomes return address pointer. | 1034 |
| 1035 // We need to make room for the return address on the stack. |
| 1036 int stack_alignment = OS::ActivationFrameAlignment(); |
| 1037 ASSERT(IsAligned(stack_alignment, kPointerSize)); |
| 1038 __ sub(sp, sp, Operand(stack_alignment)); |
| 1039 |
| 1040 // r0 will point to the return address, placed by DirectCEntry. |
| 1041 __ mov(r0, sp); |
| 1042 |
| 1065 ExternalReference stack_guard_check = | 1043 ExternalReference stack_guard_check = |
| 1066 ExternalReference::re_check_stack_guard_state(isolate()); | 1044 ExternalReference::re_check_stack_guard_state(isolate()); |
| 1067 CallCFunctionUsingStub(stack_guard_check, num_arguments); | 1045 __ mov(ip, Operand(stack_guard_check)); |
| 1046 DirectCEntryStub stub; |
| 1047 stub.GenerateCall(masm_, ip); |
| 1048 |
| 1049 // Drop the return address from the stack. |
| 1050 __ add(sp, sp, Operand(stack_alignment)); |
| 1051 |
| 1052 ASSERT(stack_alignment != 0); |
| 1053 __ ldr(sp, MemOperand(sp, 0)); |
| 1054 |
| 1055 __ mov(code_pointer(), Operand(masm_->CodeObject())); |
| 1068 } | 1056 } |
| 1069 | 1057 |
| 1070 | 1058 |
| 1071 // Helper function for reading a value out of a stack frame. | 1059 // Helper function for reading a value out of a stack frame. |
| 1072 template <typename T> | 1060 template <typename T> |
| 1073 static T& frame_entry(Address re_frame, int frame_offset) { | 1061 static T& frame_entry(Address re_frame, int frame_offset) { |
| 1074 return reinterpret_cast<T&>(Memory::int32_at(re_frame + frame_offset)); | 1062 return reinterpret_cast<T&>(Memory::int32_at(re_frame + frame_offset)); |
| 1075 } | 1063 } |
| 1076 | 1064 |
| 1077 | 1065 |
| 1078 int RegExpMacroAssemblerARM::CheckStackGuardState(Address* return_address, | 1066 int RegExpMacroAssemblerARM::CheckStackGuardState(Address* return_address, |
| 1079 Code* re_code, | 1067 Code* re_code, |
| 1080 Address re_frame) { | 1068 Address re_frame) { |
| 1081 Isolate* isolate = frame_entry<Isolate*>(re_frame, kIsolate); | 1069 Isolate* isolate = frame_entry<Isolate*>(re_frame, kIsolate); |
| 1082 ASSERT(isolate == Isolate::Current()); | |
| 1083 if (isolate->stack_guard()->IsStackOverflow()) { | 1070 if (isolate->stack_guard()->IsStackOverflow()) { |
| 1084 isolate->StackOverflow(); | 1071 isolate->StackOverflow(); |
| 1085 return EXCEPTION; | 1072 return EXCEPTION; |
| 1086 } | 1073 } |
| 1087 | 1074 |
| 1088 // If not real stack overflow the stack guard was used to interrupt | 1075 // If not real stack overflow the stack guard was used to interrupt |
| 1089 // execution for another purpose. | 1076 // execution for another purpose. |
| 1090 | 1077 |
| 1091 // If this is a direct call from JavaScript retry the RegExp forcing the call | 1078 // If this is a direct call from JavaScript retry the RegExp forcing the call |
| 1092 // through the runtime system. Currently the direct call cannot handle a GC. | 1079 // through the runtime system. Currently the direct call cannot handle a GC. |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 void RegExpMacroAssemblerARM::CheckStackLimit() { | 1242 void RegExpMacroAssemblerARM::CheckStackLimit() { |
| 1256 ExternalReference stack_limit = | 1243 ExternalReference stack_limit = |
| 1257 ExternalReference::address_of_regexp_stack_limit(isolate()); | 1244 ExternalReference::address_of_regexp_stack_limit(isolate()); |
| 1258 __ mov(r0, Operand(stack_limit)); | 1245 __ mov(r0, Operand(stack_limit)); |
| 1259 __ ldr(r0, MemOperand(r0)); | 1246 __ ldr(r0, MemOperand(r0)); |
| 1260 __ cmp(backtrack_stackpointer(), Operand(r0)); | 1247 __ cmp(backtrack_stackpointer(), Operand(r0)); |
| 1261 SafeCall(&stack_overflow_label_, ls); | 1248 SafeCall(&stack_overflow_label_, ls); |
| 1262 } | 1249 } |
| 1263 | 1250 |
| 1264 | 1251 |
| 1265 void RegExpMacroAssemblerARM::EmitBacktrackConstantPool() { | |
| 1266 __ CheckConstPool(false, false); | |
| 1267 Assembler::BlockConstPoolScope block_const_pool(masm_); | |
| 1268 backtrack_constant_pool_offset_ = masm_->pc_offset(); | |
| 1269 for (int i = 0; i < kBacktrackConstantPoolSize; i++) { | |
| 1270 __ emit(0); | |
| 1271 } | |
| 1272 | |
| 1273 backtrack_constant_pool_capacity_ = kBacktrackConstantPoolSize; | |
| 1274 } | |
| 1275 | |
| 1276 | |
| 1277 int RegExpMacroAssemblerARM::GetBacktrackConstantPoolEntry() { | |
| 1278 while (backtrack_constant_pool_capacity_ > 0) { | |
| 1279 int offset = backtrack_constant_pool_offset_; | |
| 1280 backtrack_constant_pool_offset_ += kPointerSize; | |
| 1281 backtrack_constant_pool_capacity_--; | |
| 1282 if (masm_->pc_offset() - offset < 2 * KB) { | |
| 1283 return offset; | |
| 1284 } | |
| 1285 } | |
| 1286 Label new_pool_skip; | |
| 1287 __ jmp(&new_pool_skip); | |
| 1288 EmitBacktrackConstantPool(); | |
| 1289 __ bind(&new_pool_skip); | |
| 1290 int offset = backtrack_constant_pool_offset_; | |
| 1291 backtrack_constant_pool_offset_ += kPointerSize; | |
| 1292 backtrack_constant_pool_capacity_--; | |
| 1293 return offset; | |
| 1294 } | |
| 1295 | |
| 1296 | |
| 1297 void RegExpMacroAssemblerARM::CallCFunctionUsingStub( | |
| 1298 ExternalReference function, | |
| 1299 int num_arguments) { | |
| 1300 // Must pass all arguments in registers. The stub pushes on the stack. | |
| 1301 ASSERT(num_arguments <= 4); | |
| 1302 __ mov(code_pointer(), Operand(function)); | |
| 1303 RegExpCEntryStub stub; | |
| 1304 __ CallStub(&stub); | |
| 1305 if (OS::ActivationFrameAlignment() != 0) { | |
| 1306 __ ldr(sp, MemOperand(sp, 0)); | |
| 1307 } | |
| 1308 __ mov(code_pointer(), Operand(masm_->CodeObject())); | |
| 1309 } | |
| 1310 | |
| 1311 | |
| 1312 bool RegExpMacroAssemblerARM::CanReadUnaligned() { | 1252 bool RegExpMacroAssemblerARM::CanReadUnaligned() { |
| 1313 return CpuFeatures::IsSupported(UNALIGNED_ACCESSES) && !slow_safe(); | 1253 return CpuFeatures::IsSupported(UNALIGNED_ACCESSES) && !slow_safe(); |
| 1314 } | 1254 } |
| 1315 | 1255 |
| 1316 | 1256 |
| 1317 void RegExpMacroAssemblerARM::LoadCurrentCharacterUnchecked(int cp_offset, | 1257 void RegExpMacroAssemblerARM::LoadCurrentCharacterUnchecked(int cp_offset, |
| 1318 int characters) { | 1258 int characters) { |
| 1319 Register offset = current_input_offset(); | 1259 Register offset = current_input_offset(); |
| 1320 if (cp_offset != 0) { | 1260 if (cp_offset != 0) { |
| 1321 // r4 is not being used to store the capture start index at this point. | 1261 // r4 is not being used to store the capture start index at this point. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1344 if (characters == 2) { | 1284 if (characters == 2) { |
| 1345 __ ldr(current_character(), MemOperand(end_of_input_address(), offset)); | 1285 __ ldr(current_character(), MemOperand(end_of_input_address(), offset)); |
| 1346 } else { | 1286 } else { |
| 1347 ASSERT(characters == 1); | 1287 ASSERT(characters == 1); |
| 1348 __ ldrh(current_character(), MemOperand(end_of_input_address(), offset)); | 1288 __ ldrh(current_character(), MemOperand(end_of_input_address(), offset)); |
| 1349 } | 1289 } |
| 1350 } | 1290 } |
| 1351 } | 1291 } |
| 1352 | 1292 |
| 1353 | 1293 |
| 1354 void RegExpCEntryStub::Generate(MacroAssembler* masm_) { | |
| 1355 int stack_alignment = OS::ActivationFrameAlignment(); | |
| 1356 if (stack_alignment < kPointerSize) stack_alignment = kPointerSize; | |
| 1357 // Stack is already aligned for call, so decrement by alignment | |
| 1358 // to make room for storing the link register. | |
| 1359 __ str(lr, MemOperand(sp, stack_alignment, NegPreIndex)); | |
| 1360 __ mov(r0, sp); | |
| 1361 __ Call(r5); | |
| 1362 __ ldr(pc, MemOperand(sp, stack_alignment, PostIndex)); | |
| 1363 } | |
| 1364 | |
| 1365 #undef __ | 1294 #undef __ |
| 1366 | 1295 |
| 1367 #endif // V8_INTERPRETED_REGEXP | 1296 #endif // V8_INTERPRETED_REGEXP |
| 1368 | 1297 |
| 1369 }} // namespace v8::internal | 1298 }} // namespace v8::internal |
| 1370 | 1299 |
| 1371 #endif // V8_TARGET_ARCH_ARM | 1300 #endif // V8_TARGET_ARCH_ARM |
| OLD | NEW |