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/builtins/mips/builtins-mips.cc

Issue 2335513004: [Interpreter] Adds stackcheck in InterpreterPushArgsAndCall/Construct builtins. (Closed)
Patch Set: fix for ia32 Created 4 years, 3 months 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_MIPS 5 #if V8_TARGET_ARCH_MIPS
6 6
7 #include "src/codegen.h" 7 #include "src/codegen.h"
8 #include "src/debug/debug.h" 8 #include "src/debug/debug.h"
9 #include "src/deoptimizer.h" 9 #include "src/deoptimizer.h"
10 #include "src/full-codegen/full-codegen.h" 10 #include "src/full-codegen/full-codegen.h"
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 // Push function as argument and compile for baseline. 1153 // Push function as argument and compile for baseline.
1154 __ push(a1); 1154 __ push(a1);
1155 __ CallRuntime(Runtime::kCompileBaseline); 1155 __ CallRuntime(Runtime::kCompileBaseline);
1156 1156
1157 // Restore return value. 1157 // Restore return value.
1158 __ pop(v0); 1158 __ pop(v0);
1159 } 1159 }
1160 __ Jump(ra); 1160 __ Jump(ra);
1161 } 1161 }
1162 1162
1163 static void Generate_StackOverflowCheck(MacroAssembler* masm, Register num_args,
1164 Register scratch1, Register scratch2,
1165 Label* stack_overflow) {
1166 // Check the stack for overflow. We are not trying to catch
1167 // interruptions (e.g. debug break and preemption) here, so the "real stack
1168 // limit" is checked.
1169 __ LoadRoot(scratch1, Heap::kRealStackLimitRootIndex);
1170 // Make scratch1 the space we have left. The stack might already be overflowed
1171 // here which will cause scratch1 to become negative.
1172 __ subu(scratch1, sp, scratch1);
1173 // Check if the arguments will overflow the stack.
1174 __ sll(scratch2, num_args, kPointerSizeLog2);
1175 // Signed comparison.
1176 __ Branch(stack_overflow, le, scratch1, Operand(scratch2));
1177 }
1178
1163 static void Generate_InterpreterPushArgs(MacroAssembler* masm, 1179 static void Generate_InterpreterPushArgs(MacroAssembler* masm,
1164 Register num_args, Register index, 1180 Register num_args, Register index,
1165 Register scratch, Register last_addr) { 1181 Register scratch, Register scratch2,
1182 Label* stack_overflow) {
1183 Generate_StackOverflowCheck(masm, num_args, scratch, scratch2,
1184 stack_overflow);
1185
1166 // Find the address of the last argument. 1186 // Find the address of the last argument.
1167 __ mov(last_addr, num_args); 1187 __ mov(scratch2, num_args);
1168 __ sll(last_addr, last_addr, kPointerSizeLog2); 1188 __ sll(scratch2, scratch2, kPointerSizeLog2);
1169 __ Subu(last_addr, index, Operand(last_addr)); 1189 __ Subu(scratch2, index, Operand(scratch2));
1170 1190
1171 // Push the arguments. 1191 // Push the arguments.
1172 Label loop_header, loop_check; 1192 Label loop_header, loop_check;
1173 __ Branch(&loop_check); 1193 __ Branch(&loop_check);
1174 __ bind(&loop_header); 1194 __ bind(&loop_header);
1175 __ lw(scratch, MemOperand(index)); 1195 __ lw(scratch, MemOperand(index));
1176 __ Addu(index, index, Operand(-kPointerSize)); 1196 __ Addu(index, index, Operand(-kPointerSize));
1177 __ push(scratch); 1197 __ push(scratch);
1178 __ bind(&loop_check); 1198 __ bind(&loop_check);
1179 __ Branch(&loop_header, gt, index, Operand(last_addr)); 1199 __ Branch(&loop_header, gt, index, Operand(scratch2));
1180 } 1200 }
1181 1201
1182 // static 1202 // static
1183 void Builtins::Generate_InterpreterPushArgsAndCallImpl( 1203 void Builtins::Generate_InterpreterPushArgsAndCallImpl(
1184 MacroAssembler* masm, TailCallMode tail_call_mode, 1204 MacroAssembler* masm, TailCallMode tail_call_mode,
1185 CallableType function_type) { 1205 CallableType function_type) {
1186 // ----------- S t a t e ------------- 1206 // ----------- S t a t e -------------
1187 // -- a0 : the number of arguments (not including the receiver) 1207 // -- a0 : the number of arguments (not including the receiver)
1188 // -- a2 : the address of the first argument to be pushed. Subsequent 1208 // -- a2 : the address of the first argument to be pushed. Subsequent
1189 // arguments should be consecutive above this, in the same order as 1209 // arguments should be consecutive above this, in the same order as
1190 // they are to be pushed onto the stack. 1210 // they are to be pushed onto the stack.
1191 // -- a1 : the target to call (can be any Object). 1211 // -- a1 : the target to call (can be any Object).
1192 // ----------------------------------- 1212 // -----------------------------------
1213 Label stack_overflow;
1193 1214
1194 __ Addu(t0, a0, Operand(1)); // Add one for receiver. 1215 __ Addu(t0, a0, Operand(1)); // Add one for receiver.
1195 1216
1196 // This function modifies a2, t4 and t1. 1217 // This function modifies a2, t4 and t1.
1197 Generate_InterpreterPushArgs(masm, t0, a2, t4, t1); 1218 Generate_InterpreterPushArgs(masm, t0, a2, t4, t1, &stack_overflow);
1198 1219
1199 // Call the target. 1220 // Call the target.
1200 if (function_type == CallableType::kJSFunction) { 1221 if (function_type == CallableType::kJSFunction) {
1201 __ Jump(masm->isolate()->builtins()->CallFunction(ConvertReceiverMode::kAny, 1222 __ Jump(masm->isolate()->builtins()->CallFunction(ConvertReceiverMode::kAny,
1202 tail_call_mode), 1223 tail_call_mode),
1203 RelocInfo::CODE_TARGET); 1224 RelocInfo::CODE_TARGET);
1204 } else { 1225 } else {
1205 DCHECK_EQ(function_type, CallableType::kAny); 1226 DCHECK_EQ(function_type, CallableType::kAny);
1206 __ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny, 1227 __ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny,
1207 tail_call_mode), 1228 tail_call_mode),
1208 RelocInfo::CODE_TARGET); 1229 RelocInfo::CODE_TARGET);
1209 } 1230 }
1231
1232 __ bind(&stack_overflow);
1233 {
1234 __ TailCallRuntime(Runtime::kThrowStackOverflow);
1235 __ break_(0xCC);
1236 }
1210 } 1237 }
1211 1238
1212 // static 1239 // static
1213 void Builtins::Generate_InterpreterPushArgsAndConstructImpl( 1240 void Builtins::Generate_InterpreterPushArgsAndConstructImpl(
1214 MacroAssembler* masm, CallableType construct_type) { 1241 MacroAssembler* masm, CallableType construct_type) {
1215 // ----------- S t a t e ------------- 1242 // ----------- S t a t e -------------
1216 // -- a0 : argument count (not including receiver) 1243 // -- a0 : argument count (not including receiver)
1217 // -- a3 : new target 1244 // -- a3 : new target
1218 // -- a1 : constructor to call 1245 // -- a1 : constructor to call
1219 // -- a2 : allocation site feedback if available, undefined otherwise. 1246 // -- a2 : allocation site feedback if available, undefined otherwise.
1220 // -- t4 : address of the first argument 1247 // -- t4 : address of the first argument
1221 // ----------------------------------- 1248 // -----------------------------------
1249 Label stack_overflow;
1222 1250
1223 // Push a slot for the receiver. 1251 // Push a slot for the receiver.
1224 __ push(zero_reg); 1252 __ push(zero_reg);
1225 1253
1226 // This function modified t4, t1 and t0. 1254 // This function modified t4, t1 and t0.
1227 Generate_InterpreterPushArgs(masm, a0, t4, t1, t0); 1255 Generate_InterpreterPushArgs(masm, a0, t4, t1, t0, &stack_overflow);
1228 1256
1229 __ AssertUndefinedOrAllocationSite(a2, t0); 1257 __ AssertUndefinedOrAllocationSite(a2, t0);
1230 if (construct_type == CallableType::kJSFunction) { 1258 if (construct_type == CallableType::kJSFunction) {
1231 __ AssertFunction(a1); 1259 __ AssertFunction(a1);
1232 1260
1233 // Tail call to the function-specific construct stub (still in the caller 1261 // Tail call to the function-specific construct stub (still in the caller
1234 // context at this point). 1262 // context at this point).
1235 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); 1263 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
1236 __ lw(t0, FieldMemOperand(t0, SharedFunctionInfo::kConstructStubOffset)); 1264 __ lw(t0, FieldMemOperand(t0, SharedFunctionInfo::kConstructStubOffset));
1237 __ Addu(at, t0, Operand(Code::kHeaderSize - kHeapObjectTag)); 1265 __ Addu(at, t0, Operand(Code::kHeaderSize - kHeapObjectTag));
1238 __ Jump(at); 1266 __ Jump(at);
1239 } else { 1267 } else {
1240 DCHECK_EQ(construct_type, CallableType::kAny); 1268 DCHECK_EQ(construct_type, CallableType::kAny);
1241 // Call the constructor with a0, a1, and a3 unmodified. 1269 // Call the constructor with a0, a1, and a3 unmodified.
1242 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); 1270 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
1243 } 1271 }
1272
1273 __ bind(&stack_overflow);
1274 {
1275 __ TailCallRuntime(Runtime::kThrowStackOverflow);
1276 __ break_(0xCC);
1277 }
1244 } 1278 }
1245 1279
1246 // static 1280 // static
1247 void Builtins::Generate_InterpreterPushArgsAndConstructArray( 1281 void Builtins::Generate_InterpreterPushArgsAndConstructArray(
1248 MacroAssembler* masm) { 1282 MacroAssembler* masm) {
1249 // ----------- S t a t e ------------- 1283 // ----------- S t a t e -------------
1250 // -- a0 : the number of arguments (not including the receiver) 1284 // -- a0 : the number of arguments (not including the receiver)
1251 // -- a1 : the target to call checked to be Array function. 1285 // -- a1 : the target to call checked to be Array function.
1252 // -- a2 : allocation site feedback. 1286 // -- a2 : allocation site feedback.
1253 // -- a3 : the address of the first argument to be pushed. Subsequent 1287 // -- a3 : the address of the first argument to be pushed. Subsequent
1254 // arguments should be consecutive above this, in the same order as 1288 // arguments should be consecutive above this, in the same order as
1255 // they are to be pushed onto the stack. 1289 // they are to be pushed onto the stack.
1256 // ----------------------------------- 1290 // -----------------------------------
1291 Label stack_overflow;
1257 1292
1258 __ Addu(t0, a0, Operand(1)); // Add one for receiver. 1293 __ Addu(t0, a0, Operand(1)); // Add one for receiver.
1259 1294
1260 // This function modifies a3, t4, and t1. 1295 // This function modifies a3, t4, and t1.
1261 Generate_InterpreterPushArgs(masm, t0, a3, t1, t4); 1296 Generate_InterpreterPushArgs(masm, t0, a3, t1, t4, &stack_overflow);
1262 1297
1263 // ArrayConstructor stub expects constructor in a3. Set it here. 1298 // ArrayConstructor stub expects constructor in a3. Set it here.
1264 __ mov(a3, a1); 1299 __ mov(a3, a1);
1265 1300
1266 ArrayConstructorStub stub(masm->isolate()); 1301 ArrayConstructorStub stub(masm->isolate());
1267 __ TailCallStub(&stub); 1302 __ TailCallStub(&stub);
1303
1304 __ bind(&stack_overflow);
1305 {
1306 __ TailCallRuntime(Runtime::kThrowStackOverflow);
1307 __ break_(0xCC);
1308 }
1268 } 1309 }
1269 1310
1270 void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { 1311 void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
1271 // Set the return address to the correct point in the interpreter entry 1312 // Set the return address to the correct point in the interpreter entry
1272 // trampoline. 1313 // trampoline.
1273 Smi* interpreter_entry_return_pc_offset( 1314 Smi* interpreter_entry_return_pc_offset(
1274 masm->isolate()->heap()->interpreter_entry_return_pc_offset()); 1315 masm->isolate()->heap()->interpreter_entry_return_pc_offset());
1275 DCHECK_NE(interpreter_entry_return_pc_offset, Smi::FromInt(0)); 1316 DCHECK_NE(interpreter_entry_return_pc_offset, Smi::FromInt(0));
1276 __ li(t0, Operand(masm->isolate()->builtins()->InterpreterEntryTrampoline())); 1317 __ li(t0, Operand(masm->isolate()->builtins()->InterpreterEntryTrampoline()));
1277 __ Addu(ra, t0, Operand(interpreter_entry_return_pc_offset->value() + 1318 __ Addu(ra, t0, Operand(interpreter_entry_return_pc_offset->value() +
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 } 2196 }
2156 2197
2157 // 4c. The new.target is not a constructor, throw an appropriate TypeError. 2198 // 4c. The new.target is not a constructor, throw an appropriate TypeError.
2158 __ bind(&new_target_not_constructor); 2199 __ bind(&new_target_not_constructor);
2159 { 2200 {
2160 __ sw(a3, MemOperand(sp)); 2201 __ sw(a3, MemOperand(sp));
2161 __ TailCallRuntime(Runtime::kThrowCalledNonCallable); 2202 __ TailCallRuntime(Runtime::kThrowCalledNonCallable);
2162 } 2203 }
2163 } 2204 }
2164 2205
2165 static void ArgumentAdaptorStackCheck(MacroAssembler* masm,
2166 Label* stack_overflow) {
2167 // ----------- S t a t e -------------
2168 // -- a0 : actual number of arguments
2169 // -- a1 : function (passed through to callee)
2170 // -- a2 : expected number of arguments
2171 // -- a3 : new target (passed through to callee)
2172 // -----------------------------------
2173 // Check the stack for overflow. We are not trying to catch
2174 // interruptions (e.g. debug break and preemption) here, so the "real stack
2175 // limit" is checked.
2176 __ LoadRoot(t1, Heap::kRealStackLimitRootIndex);
2177 // Make t1 the space we have left. The stack might already be overflowed
2178 // here which will cause t1 to become negative.
2179 __ subu(t1, sp, t1);
2180 // Check if the arguments will overflow the stack.
2181 __ sll(at, a2, kPointerSizeLog2);
2182 // Signed comparison.
2183 __ Branch(stack_overflow, le, t1, Operand(at));
2184 }
2185
2186 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) { 2206 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) {
2187 __ sll(a0, a0, kSmiTagSize); 2207 __ sll(a0, a0, kSmiTagSize);
2188 __ li(t0, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); 2208 __ li(t0, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
2189 __ MultiPush(a0.bit() | a1.bit() | t0.bit() | fp.bit() | ra.bit()); 2209 __ MultiPush(a0.bit() | a1.bit() | t0.bit() | fp.bit() | ra.bit());
2190 __ Addu(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp + 2210 __ Addu(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp +
2191 kPointerSize)); 2211 kPointerSize));
2192 } 2212 }
2193 2213
2194 static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) { 2214 static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) {
2195 // ----------- S t a t e ------------- 2215 // ----------- S t a t e -------------
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
2940 // We use Uless as the number of argument should always be greater than 0. 2960 // We use Uless as the number of argument should always be greater than 0.
2941 __ Branch(&too_few, Uless, a0, Operand(a2)); 2961 __ Branch(&too_few, Uless, a0, Operand(a2));
2942 2962
2943 { // Enough parameters: actual >= expected. 2963 { // Enough parameters: actual >= expected.
2944 // a0: actual number of arguments as a smi 2964 // a0: actual number of arguments as a smi
2945 // a1: function 2965 // a1: function
2946 // a2: expected number of arguments 2966 // a2: expected number of arguments
2947 // a3: new target (passed through to callee) 2967 // a3: new target (passed through to callee)
2948 __ bind(&enough); 2968 __ bind(&enough);
2949 EnterArgumentsAdaptorFrame(masm); 2969 EnterArgumentsAdaptorFrame(masm);
2950 ArgumentAdaptorStackCheck(masm, &stack_overflow); 2970 Generate_StackOverflowCheck(masm, a2, t1, at, &stack_overflow);
2951 2971
2952 // Calculate copy start address into a0 and copy end address into t1. 2972 // Calculate copy start address into a0 and copy end address into t1.
2953 __ Lsa(a0, fp, a0, kPointerSizeLog2 - kSmiTagSize); 2973 __ Lsa(a0, fp, a0, kPointerSizeLog2 - kSmiTagSize);
2954 // Adjust for return address and receiver. 2974 // Adjust for return address and receiver.
2955 __ Addu(a0, a0, Operand(2 * kPointerSize)); 2975 __ Addu(a0, a0, Operand(2 * kPointerSize));
2956 // Compute copy end address. 2976 // Compute copy end address.
2957 __ sll(t1, a2, kPointerSizeLog2); 2977 __ sll(t1, a2, kPointerSizeLog2);
2958 __ subu(t1, a0, t1); 2978 __ subu(t1, a0, t1);
2959 2979
2960 // Copy the arguments (including the receiver) to the new stack frame. 2980 // Copy the arguments (including the receiver) to the new stack frame.
2961 // a0: copy start address 2981 // a0: copy start address
2962 // a1: function 2982 // a1: function
2963 // a2: expected number of arguments 2983 // a2: expected number of arguments
2964 // a3: new target (passed through to callee) 2984 // a3: new target (passed through to callee)
2965 // t1: copy end address 2985 // t1: copy end address
2966 2986
2967 Label copy; 2987 Label copy;
2968 __ bind(&copy); 2988 __ bind(&copy);
2969 __ lw(t0, MemOperand(a0)); 2989 __ lw(t0, MemOperand(a0));
2970 __ push(t0); 2990 __ push(t0);
2971 __ Branch(USE_DELAY_SLOT, &copy, ne, a0, Operand(t1)); 2991 __ Branch(USE_DELAY_SLOT, &copy, ne, a0, Operand(t1));
2972 __ addiu(a0, a0, -kPointerSize); // In delay slot. 2992 __ addiu(a0, a0, -kPointerSize); // In delay slot.
2973 2993
2974 __ jmp(&invoke); 2994 __ jmp(&invoke);
2975 } 2995 }
2976 2996
2977 { // Too few parameters: Actual < expected. 2997 { // Too few parameters: Actual < expected.
2978 __ bind(&too_few); 2998 __ bind(&too_few);
2979 EnterArgumentsAdaptorFrame(masm); 2999 EnterArgumentsAdaptorFrame(masm);
2980 ArgumentAdaptorStackCheck(masm, &stack_overflow); 3000 Generate_StackOverflowCheck(masm, a2, t1, at, &stack_overflow);
2981 3001
2982 // Calculate copy start address into a0 and copy end address into t3. 3002 // Calculate copy start address into a0 and copy end address into t3.
2983 // a0: actual number of arguments as a smi 3003 // a0: actual number of arguments as a smi
2984 // a1: function 3004 // a1: function
2985 // a2: expected number of arguments 3005 // a2: expected number of arguments
2986 // a3: new target (passed through to callee) 3006 // a3: new target (passed through to callee)
2987 __ Lsa(a0, fp, a0, kPointerSizeLog2 - kSmiTagSize); 3007 __ Lsa(a0, fp, a0, kPointerSizeLog2 - kSmiTagSize);
2988 // Adjust for return address and receiver. 3008 // Adjust for return address and receiver.
2989 __ Addu(a0, a0, Operand(2 * kPointerSize)); 3009 __ Addu(a0, a0, Operand(2 * kPointerSize));
2990 // Compute copy end address. Also adjust for return address. 3010 // Compute copy end address. Also adjust for return address.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3052 __ break_(0xCC); 3072 __ break_(0xCC);
3053 } 3073 }
3054 } 3074 }
3055 3075
3056 #undef __ 3076 #undef __
3057 3077
3058 } // namespace internal 3078 } // namespace internal
3059 } // namespace v8 3079 } // namespace v8
3060 3080
3061 #endif // V8_TARGET_ARCH_MIPS 3081 #endif // V8_TARGET_ARCH_MIPS
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698