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

Side by Side Diff: src/builtins/mips64/builtins-mips64.cc

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

Powered by Google App Engine
This is Rietveld 408576698