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

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

Issue 2356583003: PPC/s390: [Interpreter] Adds stackcheck in InterpreterPushArgsAndCall/Construct builtins. (Closed)
Patch Set: Applied suggested changes. 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 | « no previous file | src/builtins/s390/builtins-s390.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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_PPC 5 #if V8_TARGET_ARCH_PPC
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 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 // Push function as argument and compile for baseline. 1192 // Push function as argument and compile for baseline.
1193 __ push(r4); 1193 __ push(r4);
1194 __ CallRuntime(Runtime::kCompileBaseline); 1194 __ CallRuntime(Runtime::kCompileBaseline);
1195 1195
1196 // Restore return value. 1196 // Restore return value.
1197 __ pop(r3); 1197 __ pop(r3);
1198 } 1198 }
1199 __ blr(); 1199 __ blr();
1200 } 1200 }
1201 1201
1202 static void Generate_StackOverflowCheck(MacroAssembler* masm, Register num_args,
1203 Register scratch,
1204 Label* stack_overflow) {
1205 // Check the stack for overflow. We are not trying to catch
1206 // interruptions (e.g. debug break and preemption) here, so the "real stack
1207 // limit" is checked.
1208 __ LoadRoot(scratch, Heap::kRealStackLimitRootIndex);
1209 // Make scratch the space we have left. The stack might already be overflowed
1210 // here which will cause scratch to become negative.
1211 __ sub(scratch, sp, scratch);
1212 // Check if the arguments will overflow the stack.
1213 __ ShiftLeftImm(r0, num_args, Operand(kPointerSizeLog2));
1214 __ cmp(scratch, r0);
1215 __ ble(stack_overflow); // Signed comparison.
1216 }
1217
1202 static void Generate_InterpreterPushArgs(MacroAssembler* masm, 1218 static void Generate_InterpreterPushArgs(MacroAssembler* masm,
1203 Register num_args, Register index, 1219 Register num_args, Register index,
1204 Register count, Register scratch) { 1220 Register count, Register scratch,
1205 // TODO(mythria): Add a stack check before pushing arguments. 1221 Label* stack_overflow) {
1222 // A stack check before pushing arguments.
1223 Generate_StackOverflowCheck(masm, num_args, scratch, stack_overflow);
1224
1206 Label loop; 1225 Label loop;
1207 __ addi(index, index, Operand(kPointerSize)); // Bias up for LoadPU 1226 __ addi(index, index, Operand(kPointerSize)); // Bias up for LoadPU
1208 __ mtctr(count); 1227 __ mtctr(count);
1209 __ bind(&loop); 1228 __ bind(&loop);
1210 __ LoadPU(scratch, MemOperand(index, -kPointerSize)); 1229 __ LoadPU(scratch, MemOperand(index, -kPointerSize));
1211 __ push(scratch); 1230 __ push(scratch);
1212 __ bdnz(&loop); 1231 __ bdnz(&loop);
1213 } 1232 }
1214 1233
1215 // static 1234 // static
1216 void Builtins::Generate_InterpreterPushArgsAndCallImpl( 1235 void Builtins::Generate_InterpreterPushArgsAndCallImpl(
1217 MacroAssembler* masm, TailCallMode tail_call_mode, 1236 MacroAssembler* masm, TailCallMode tail_call_mode,
1218 CallableType function_type) { 1237 CallableType function_type) {
1219 // ----------- S t a t e ------------- 1238 // ----------- S t a t e -------------
1220 // -- r3 : the number of arguments (not including the receiver) 1239 // -- r3 : the number of arguments (not including the receiver)
1221 // -- r5 : the address of the first argument to be pushed. Subsequent 1240 // -- r5 : the address of the first argument to be pushed. Subsequent
1222 // arguments should be consecutive above this, in the same order as 1241 // arguments should be consecutive above this, in the same order as
1223 // they are to be pushed onto the stack. 1242 // they are to be pushed onto the stack.
1224 // -- r4 : the target to call (can be any Object). 1243 // -- r4 : the target to call (can be any Object).
1225 // ----------------------------------- 1244 // -----------------------------------
1245 Label stack_overflow;
1226 1246
1227 // Calculate number of arguments (add one for receiver). 1247 // Calculate number of arguments (add one for receiver).
1228 __ addi(r6, r3, Operand(1)); 1248 __ addi(r6, r3, Operand(1));
1229 1249
1230 // TODO(mythria): Add a stack check before pushing arguments.
1231 // Push the arguments. r5, r6, r7 will be modified. 1250 // Push the arguments. r5, r6, r7 will be modified.
1232 Generate_InterpreterPushArgs(masm, r6, r5, r6, r7); 1251 Generate_InterpreterPushArgs(masm, r6, r5, r6, r7, &stack_overflow);
1233 1252
1234 // Call the target. 1253 // Call the target.
1235 if (function_type == CallableType::kJSFunction) { 1254 if (function_type == CallableType::kJSFunction) {
1236 __ Jump(masm->isolate()->builtins()->CallFunction(ConvertReceiverMode::kAny, 1255 __ Jump(masm->isolate()->builtins()->CallFunction(ConvertReceiverMode::kAny,
1237 tail_call_mode), 1256 tail_call_mode),
1238 RelocInfo::CODE_TARGET); 1257 RelocInfo::CODE_TARGET);
1239 } else { 1258 } else {
1240 DCHECK_EQ(function_type, CallableType::kAny); 1259 DCHECK_EQ(function_type, CallableType::kAny);
1241 __ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny, 1260 __ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny,
1242 tail_call_mode), 1261 tail_call_mode),
1243 RelocInfo::CODE_TARGET); 1262 RelocInfo::CODE_TARGET);
1244 } 1263 }
1264
1265 __ bind(&stack_overflow);
1266 {
1267 __ TailCallRuntime(Runtime::kThrowStackOverflow);
1268 // Unreachable Code.
1269 __ bkpt(0);
1270 }
1245 } 1271 }
1246 1272
1247 // static 1273 // static
1248 void Builtins::Generate_InterpreterPushArgsAndConstructImpl( 1274 void Builtins::Generate_InterpreterPushArgsAndConstructImpl(
1249 MacroAssembler* masm, CallableType construct_type) { 1275 MacroAssembler* masm, CallableType construct_type) {
1250 // ----------- S t a t e ------------- 1276 // ----------- S t a t e -------------
1251 // -- r3 : argument count (not including receiver) 1277 // -- r3 : argument count (not including receiver)
1252 // -- r6 : new target 1278 // -- r6 : new target
1253 // -- r4 : constructor to call 1279 // -- r4 : constructor to call
1254 // -- r5 : allocation site feedback if available, undefined otherwise. 1280 // -- r5 : allocation site feedback if available, undefined otherwise.
1255 // -- r7 : address of the first argument 1281 // -- r7 : address of the first argument
1256 // ----------------------------------- 1282 // -----------------------------------
1283 Label stack_overflow;
1257 1284
1258 // Push a slot for the receiver to be constructed. 1285 // Push a slot for the receiver to be constructed.
1259 __ li(r0, Operand::Zero()); 1286 __ li(r0, Operand::Zero());
1260 __ push(r0); 1287 __ push(r0);
1261 1288
1262 // Push the arguments (skip if none). 1289 // Push the arguments (skip if none).
1263 Label skip; 1290 Label skip;
1264 __ cmpi(r3, Operand::Zero()); 1291 __ cmpi(r3, Operand::Zero());
1265 __ beq(&skip); 1292 __ beq(&skip);
1266 // Push the arguments. r8, r7, r9 will be modified. 1293 // Push the arguments. r8, r7, r9 will be modified.
1267 Generate_InterpreterPushArgs(masm, r3, r7, r3, r8); 1294 Generate_InterpreterPushArgs(masm, r3, r7, r3, r8, &stack_overflow);
1268 __ bind(&skip); 1295 __ bind(&skip);
1269 1296
1270 __ AssertUndefinedOrAllocationSite(r5, r8); 1297 __ AssertUndefinedOrAllocationSite(r5, r8);
1271 if (construct_type == CallableType::kJSFunction) { 1298 if (construct_type == CallableType::kJSFunction) {
1272 __ AssertFunction(r4); 1299 __ AssertFunction(r4);
1273 1300
1274 // Tail call to the function-specific construct stub (still in the caller 1301 // Tail call to the function-specific construct stub (still in the caller
1275 // context at this point). 1302 // context at this point).
1276 __ LoadP(r7, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset)); 1303 __ LoadP(r7, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
1277 __ LoadP(r7, FieldMemOperand(r7, SharedFunctionInfo::kConstructStubOffset)); 1304 __ LoadP(r7, FieldMemOperand(r7, SharedFunctionInfo::kConstructStubOffset));
1278 // Jump to the construct function. 1305 // Jump to the construct function.
1279 __ addi(ip, r7, Operand(Code::kHeaderSize - kHeapObjectTag)); 1306 __ addi(ip, r7, Operand(Code::kHeaderSize - kHeapObjectTag));
1280 __ Jump(ip); 1307 __ Jump(ip);
1281 1308
1282 } else { 1309 } else {
1283 DCHECK_EQ(construct_type, CallableType::kAny); 1310 DCHECK_EQ(construct_type, CallableType::kAny);
1284 // Call the constructor with r3, r4, and r6 unmodified. 1311 // Call the constructor with r3, r4, and r6 unmodified.
1285 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); 1312 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
1286 } 1313 }
1314
1315 __ bind(&stack_overflow);
1316 {
1317 __ TailCallRuntime(Runtime::kThrowStackOverflow);
1318 // Unreachable Code.
1319 __ bkpt(0);
1320 }
1287 } 1321 }
1288 1322
1289 // static 1323 // static
1290 void Builtins::Generate_InterpreterPushArgsAndConstructArray( 1324 void Builtins::Generate_InterpreterPushArgsAndConstructArray(
1291 MacroAssembler* masm) { 1325 MacroAssembler* masm) {
1292 // ----------- S t a t e ------------- 1326 // ----------- S t a t e -------------
1293 // -- r3 : argument count (not including receiver) 1327 // -- r3 : argument count (not including receiver)
1294 // -- r4 : target to call verified to be Array function 1328 // -- r4 : target to call verified to be Array function
1295 // -- r5 : allocation site feedback if available, undefined otherwise. 1329 // -- r5 : allocation site feedback if available, undefined otherwise.
1296 // -- r6 : address of the first argument 1330 // -- r6 : address of the first argument
1297 // ----------------------------------- 1331 // -----------------------------------
1332 Label stack_overflow;
1298 1333
1299 __ addi(r7, r3, Operand(1)); // Add one for receiver. 1334 __ addi(r7, r3, Operand(1)); // Add one for receiver.
1300 1335
1301 // TODO(mythria): Add a stack check before pushing arguments.
1302 // Push the arguments. r6, r8, r3 will be modified. 1336 // Push the arguments. r6, r8, r3 will be modified.
1303 Generate_InterpreterPushArgs(masm, r7, r6, r7, r8); 1337 Generate_InterpreterPushArgs(masm, r7, r6, r7, r8, &stack_overflow);
1304 1338
1305 // Array constructor expects constructor in r6. It is same as r4 here. 1339 // Array constructor expects constructor in r6. It is same as r4 here.
1306 __ mr(r6, r4); 1340 __ mr(r6, r4);
1307 1341
1308 ArrayConstructorStub stub(masm->isolate()); 1342 ArrayConstructorStub stub(masm->isolate());
1309 __ TailCallStub(&stub); 1343 __ TailCallStub(&stub);
1344
1345 __ bind(&stack_overflow);
1346 {
1347 __ TailCallRuntime(Runtime::kThrowStackOverflow);
1348 // Unreachable code.
1349 __ bkpt(0);
1350 }
1310 } 1351 }
1311 1352
1312 void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { 1353 void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
1313 // Set the return address to the correct point in the interpreter entry 1354 // Set the return address to the correct point in the interpreter entry
1314 // trampoline. 1355 // trampoline.
1315 Smi* interpreter_entry_return_pc_offset( 1356 Smi* interpreter_entry_return_pc_offset(
1316 masm->isolate()->heap()->interpreter_entry_return_pc_offset()); 1357 masm->isolate()->heap()->interpreter_entry_return_pc_offset());
1317 DCHECK_NE(interpreter_entry_return_pc_offset, Smi::FromInt(0)); 1358 DCHECK_NE(interpreter_entry_return_pc_offset, Smi::FromInt(0));
1318 __ Move(r5, masm->isolate()->builtins()->InterpreterEntryTrampoline()); 1359 __ Move(r5, masm->isolate()->builtins()->InterpreterEntryTrampoline());
1319 __ addi(r0, r5, Operand(interpreter_entry_return_pc_offset->value() + 1360 __ addi(r0, r5, Operand(interpreter_entry_return_pc_offset->value() +
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
2145 } 2186 }
2146 2187
2147 // 4c. The new.target is not a constructor, throw an appropriate TypeError. 2188 // 4c. The new.target is not a constructor, throw an appropriate TypeError.
2148 __ bind(&new_target_not_constructor); 2189 __ bind(&new_target_not_constructor);
2149 { 2190 {
2150 __ StoreP(r6, MemOperand(sp, 0)); 2191 __ StoreP(r6, MemOperand(sp, 0));
2151 __ TailCallRuntime(Runtime::kThrowCalledNonCallable); 2192 __ TailCallRuntime(Runtime::kThrowCalledNonCallable);
2152 } 2193 }
2153 } 2194 }
2154 2195
2155 static void ArgumentAdaptorStackCheck(MacroAssembler* masm,
2156 Label* stack_overflow) {
2157 // ----------- S t a t e -------------
2158 // -- r3 : actual number of arguments
2159 // -- r4 : function (passed through to callee)
2160 // -- r5 : expected number of arguments
2161 // -- r6 : new target (passed through to callee)
2162 // -----------------------------------
2163 // Check the stack for overflow. We are not trying to catch
2164 // interruptions (e.g. debug break and preemption) here, so the "real stack
2165 // limit" is checked.
2166 __ LoadRoot(r8, Heap::kRealStackLimitRootIndex);
2167 // Make r8 the space we have left. The stack might already be overflowed
2168 // here which will cause r8 to become negative.
2169 __ sub(r8, sp, r8);
2170 // Check if the arguments will overflow the stack.
2171 __ ShiftLeftImm(r0, r5, Operand(kPointerSizeLog2));
2172 __ cmp(r8, r0);
2173 __ ble(stack_overflow); // Signed comparison.
2174 }
2175
2176 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) { 2196 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) {
2177 __ SmiTag(r3); 2197 __ SmiTag(r3);
2178 __ LoadSmiLiteral(r7, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); 2198 __ LoadSmiLiteral(r7, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
2179 __ mflr(r0); 2199 __ mflr(r0);
2180 __ push(r0); 2200 __ push(r0);
2181 if (FLAG_enable_embedded_constant_pool) { 2201 if (FLAG_enable_embedded_constant_pool) {
2182 __ Push(fp, kConstantPoolRegister, r7, r4, r3); 2202 __ Push(fp, kConstantPoolRegister, r7, r4, r3);
2183 } else { 2203 } else {
2184 __ Push(fp, r7, r4, r3); 2204 __ Push(fp, r7, r4, r3);
2185 } 2205 }
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
2875 Label enough, too_few; 2895 Label enough, too_few;
2876 __ LoadP(ip, FieldMemOperand(r4, JSFunction::kCodeEntryOffset)); 2896 __ LoadP(ip, FieldMemOperand(r4, JSFunction::kCodeEntryOffset));
2877 __ cmp(r3, r5); 2897 __ cmp(r3, r5);
2878 __ blt(&too_few); 2898 __ blt(&too_few);
2879 __ cmpi(r5, Operand(SharedFunctionInfo::kDontAdaptArgumentsSentinel)); 2899 __ cmpi(r5, Operand(SharedFunctionInfo::kDontAdaptArgumentsSentinel));
2880 __ beq(&dont_adapt_arguments); 2900 __ beq(&dont_adapt_arguments);
2881 2901
2882 { // Enough parameters: actual >= expected 2902 { // Enough parameters: actual >= expected
2883 __ bind(&enough); 2903 __ bind(&enough);
2884 EnterArgumentsAdaptorFrame(masm); 2904 EnterArgumentsAdaptorFrame(masm);
2885 ArgumentAdaptorStackCheck(masm, &stack_overflow); 2905 Generate_StackOverflowCheck(masm, r5, r8, &stack_overflow);
2886 2906
2887 // Calculate copy start address into r3 and copy end address into r7. 2907 // Calculate copy start address into r3 and copy end address into r7.
2888 // r3: actual number of arguments as a smi 2908 // r3: actual number of arguments as a smi
2889 // r4: function 2909 // r4: function
2890 // r5: expected number of arguments 2910 // r5: expected number of arguments
2891 // r6: new target (passed through to callee) 2911 // r6: new target (passed through to callee)
2892 // ip: code entry to call 2912 // ip: code entry to call
2893 __ SmiToPtrArrayOffset(r3, r3); 2913 __ SmiToPtrArrayOffset(r3, r3);
2894 __ add(r3, r3, fp); 2914 __ add(r3, r3, fp);
2895 // adjust for return address and receiver 2915 // adjust for return address and receiver
(...skipping 17 matching lines...) Expand all
2913 __ subi(r3, r3, Operand(kPointerSize)); 2933 __ subi(r3, r3, Operand(kPointerSize));
2914 __ bne(&copy); 2934 __ bne(&copy);
2915 2935
2916 __ b(&invoke); 2936 __ b(&invoke);
2917 } 2937 }
2918 2938
2919 { // Too few parameters: Actual < expected 2939 { // Too few parameters: Actual < expected
2920 __ bind(&too_few); 2940 __ bind(&too_few);
2921 2941
2922 EnterArgumentsAdaptorFrame(masm); 2942 EnterArgumentsAdaptorFrame(masm);
2923 ArgumentAdaptorStackCheck(masm, &stack_overflow); 2943 Generate_StackOverflowCheck(masm, r5, r8, &stack_overflow);
2924 2944
2925 // Calculate copy start address into r0 and copy end address is fp. 2945 // Calculate copy start address into r0 and copy end address is fp.
2926 // r3: actual number of arguments as a smi 2946 // r3: actual number of arguments as a smi
2927 // r4: function 2947 // r4: function
2928 // r5: expected number of arguments 2948 // r5: expected number of arguments
2929 // r6: new target (passed through to callee) 2949 // r6: new target (passed through to callee)
2930 // ip: code entry to call 2950 // ip: code entry to call
2931 __ SmiToPtrArrayOffset(r3, r3); 2951 __ SmiToPtrArrayOffset(r3, r3);
2932 __ add(r3, r3, fp); 2952 __ add(r3, r3, fp);
2933 2953
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2992 __ CallRuntime(Runtime::kThrowStackOverflow); 3012 __ CallRuntime(Runtime::kThrowStackOverflow);
2993 __ bkpt(0); 3013 __ bkpt(0);
2994 } 3014 }
2995 } 3015 }
2996 3016
2997 #undef __ 3017 #undef __
2998 } // namespace internal 3018 } // namespace internal
2999 } // namespace v8 3019 } // namespace v8
3000 3020
3001 #endif // V8_TARGET_ARCH_PPC 3021 #endif // V8_TARGET_ARCH_PPC
OLDNEW
« no previous file with comments | « no previous file | src/builtins/s390/builtins-s390.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698