11cb0ef41Sopenharmony_ci// Copyright 2017 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef V8_EXECUTION_FRAME_CONSTANTS_H_ 61cb0ef41Sopenharmony_ci#define V8_EXECUTION_FRAME_CONSTANTS_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/common/globals.h" 91cb0ef41Sopenharmony_ci#include "src/flags/flags.h" 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_cinamespace v8 { 121cb0ef41Sopenharmony_cinamespace internal { 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci// Every pointer in a frame has a slot id. On 32-bit platforms, doubles consume 151cb0ef41Sopenharmony_ci// two slots. 161cb0ef41Sopenharmony_ci// 171cb0ef41Sopenharmony_ci// Stack slot indices >= 0 access the callee stack with slot 0 corresponding to 181cb0ef41Sopenharmony_ci// the callee's saved return address and 1 corresponding to the saved frame 191cb0ef41Sopenharmony_ci// pointer. Some frames have additional information stored in the fixed header, 201cb0ef41Sopenharmony_ci// for example JSFunctions store the function context and marker in the fixed 211cb0ef41Sopenharmony_ci// header, with slot index 2 corresponding to the current function context and 3 221cb0ef41Sopenharmony_ci// corresponding to the frame marker/JSFunction. 231cb0ef41Sopenharmony_ci// 241cb0ef41Sopenharmony_ci// slot JS frame 251cb0ef41Sopenharmony_ci// +-----------------+-------------------------------- 261cb0ef41Sopenharmony_ci// -n-1 | parameter n | ^ 271cb0ef41Sopenharmony_ci// |- - - - - - - - -| | 281cb0ef41Sopenharmony_ci// -n | parameter n-1 | Caller 291cb0ef41Sopenharmony_ci// ... | ... | frame slots 301cb0ef41Sopenharmony_ci// -2 | parameter 1 | (slot < 0) 311cb0ef41Sopenharmony_ci// |- - - - - - - - -| | 321cb0ef41Sopenharmony_ci// -1 | parameter 0 | v 331cb0ef41Sopenharmony_ci// -----+-----------------+-------------------------------- 341cb0ef41Sopenharmony_ci// 0 | return addr | ^ ^ 351cb0ef41Sopenharmony_ci// |- - - - - - - - -| | | 361cb0ef41Sopenharmony_ci// 1 | saved frame ptr | Fixed | 371cb0ef41Sopenharmony_ci// |- - - - - - - - -| Header <-- frame ptr | 381cb0ef41Sopenharmony_ci// 2 | [Constant Pool] | | | 391cb0ef41Sopenharmony_ci// |- - - - - - - - -| | | 401cb0ef41Sopenharmony_ci// 2+cp |Context/Frm. Type| v if a constant pool | 411cb0ef41Sopenharmony_ci// |-----------------+---- is used, cp = 1, | 421cb0ef41Sopenharmony_ci// 3+cp | | ^ otherwise, cp = 0 | 431cb0ef41Sopenharmony_ci// |- - - - - - - - -| | | 441cb0ef41Sopenharmony_ci// 4+cp | | | Callee 451cb0ef41Sopenharmony_ci// |- - - - - - - - -| | frame slots 461cb0ef41Sopenharmony_ci// ... | | Frame slots (slot >= 0) 471cb0ef41Sopenharmony_ci// |- - - - - - - - -| | | 481cb0ef41Sopenharmony_ci// | | v | 491cb0ef41Sopenharmony_ci// -----+-----------------+----- <-- stack ptr ------------- 501cb0ef41Sopenharmony_ci// 511cb0ef41Sopenharmony_ciclass CommonFrameConstants : public AllStatic { 521cb0ef41Sopenharmony_ci public: 531cb0ef41Sopenharmony_ci static constexpr int kCallerFPOffset = 0 * kSystemPointerSize; 541cb0ef41Sopenharmony_ci static constexpr int kCallerPCOffset = kCallerFPOffset + 1 * kFPOnStackSize; 551cb0ef41Sopenharmony_ci static constexpr int kCallerSPOffset = kCallerPCOffset + 1 * kPCOnStackSize; 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci // Fixed part of the frame consists of return address, caller fp, 581cb0ef41Sopenharmony_ci // constant pool (if FLAG_enable_embedded_constant_pool), context, and 591cb0ef41Sopenharmony_ci // function. CommonFrame::IterateExpressions assumes that kLastObjectOffset 601cb0ef41Sopenharmony_ci // is the last object pointer. 611cb0ef41Sopenharmony_ci static constexpr int kFixedFrameSizeAboveFp = kPCOnStackSize + kFPOnStackSize; 621cb0ef41Sopenharmony_ci static constexpr int kFixedSlotCountAboveFp = 631cb0ef41Sopenharmony_ci kFixedFrameSizeAboveFp / kSystemPointerSize; 641cb0ef41Sopenharmony_ci static constexpr int kCPSlotSize = 651cb0ef41Sopenharmony_ci FLAG_enable_embedded_constant_pool ? kSystemPointerSize : 0; 661cb0ef41Sopenharmony_ci static constexpr int kCPSlotCount = kCPSlotSize / kSystemPointerSize; 671cb0ef41Sopenharmony_ci static constexpr int kConstantPoolOffset = 681cb0ef41Sopenharmony_ci kCPSlotSize ? -1 * kSystemPointerSize : 0; 691cb0ef41Sopenharmony_ci static constexpr int kContextOrFrameTypeSize = kSystemPointerSize; 701cb0ef41Sopenharmony_ci static constexpr int kContextOrFrameTypeOffset = 711cb0ef41Sopenharmony_ci -(kCPSlotSize + kContextOrFrameTypeSize); 721cb0ef41Sopenharmony_ci}; 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ci// StandardFrames are used for both unoptimized and optimized JavaScript 751cb0ef41Sopenharmony_ci// frames. They always have a context below the saved fp/constant 761cb0ef41Sopenharmony_ci// pool, below that the JSFunction of the executing function and below that an 771cb0ef41Sopenharmony_ci// integer (not a Smi) containing the actual number of arguments passed to the 781cb0ef41Sopenharmony_ci// JavaScript code. 791cb0ef41Sopenharmony_ci// 801cb0ef41Sopenharmony_ci// slot JS frame 811cb0ef41Sopenharmony_ci// +-----------------+-------------------------------- 821cb0ef41Sopenharmony_ci// -n-1 | parameter n | ^ 831cb0ef41Sopenharmony_ci// |- - - - - - - - -| | 841cb0ef41Sopenharmony_ci// -n | parameter n-1 | Caller 851cb0ef41Sopenharmony_ci// ... | ... | frame slots 861cb0ef41Sopenharmony_ci// -2 | parameter 1 | (slot < 0) 871cb0ef41Sopenharmony_ci// |- - - - - - - - -| | 881cb0ef41Sopenharmony_ci// -1 | parameter 0 | v 891cb0ef41Sopenharmony_ci// -----+-----------------+-------------------------------- 901cb0ef41Sopenharmony_ci// 0 | return addr | ^ ^ 911cb0ef41Sopenharmony_ci// |- - - - - - - - -| | | 921cb0ef41Sopenharmony_ci// 1 | saved frame ptr | Fixed | 931cb0ef41Sopenharmony_ci// |- - - - - - - - -| Header <-- frame ptr | 941cb0ef41Sopenharmony_ci// 2 | [Constant Pool] | | | 951cb0ef41Sopenharmony_ci// |- - - - - - - - -| | | 961cb0ef41Sopenharmony_ci// 2+cp | Context | | if a constant pool | 971cb0ef41Sopenharmony_ci// |- - - - - - - - -| | is used, cp = 1, | 981cb0ef41Sopenharmony_ci// 3+cp | JSFunction | | otherwise, cp = 0 | 991cb0ef41Sopenharmony_ci// |- - - - - - - - -| | | 1001cb0ef41Sopenharmony_ci// 4+cp | argc | v | 1011cb0ef41Sopenharmony_ci// +-----------------+---- | 1021cb0ef41Sopenharmony_ci// 5+cp | expressions or | ^ Callee 1031cb0ef41Sopenharmony_ci// |- - - - - - - - -| | frame slots 1041cb0ef41Sopenharmony_ci// ... | pushed values | Frame slots (slot >= 0) 1051cb0ef41Sopenharmony_ci// |- - - - - - - - -| | | 1061cb0ef41Sopenharmony_ci// | | v | 1071cb0ef41Sopenharmony_ci// -----+-----------------+----- <-- stack ptr ------------- 1081cb0ef41Sopenharmony_ci// 1091cb0ef41Sopenharmony_ciclass StandardFrameConstants : public CommonFrameConstants { 1101cb0ef41Sopenharmony_ci public: 1111cb0ef41Sopenharmony_ci static constexpr int kFixedFrameSizeFromFp = 1121cb0ef41Sopenharmony_ci 3 * kSystemPointerSize + kCPSlotSize; 1131cb0ef41Sopenharmony_ci static constexpr int kFixedFrameSize = 1141cb0ef41Sopenharmony_ci kFixedFrameSizeAboveFp + kFixedFrameSizeFromFp; 1151cb0ef41Sopenharmony_ci static constexpr int kFixedSlotCountFromFp = 1161cb0ef41Sopenharmony_ci kFixedFrameSizeFromFp / kSystemPointerSize; 1171cb0ef41Sopenharmony_ci static constexpr int kFixedSlotCount = kFixedFrameSize / kSystemPointerSize; 1181cb0ef41Sopenharmony_ci static constexpr int kContextOffset = kContextOrFrameTypeOffset; 1191cb0ef41Sopenharmony_ci static constexpr int kFunctionOffset = -2 * kSystemPointerSize - kCPSlotSize; 1201cb0ef41Sopenharmony_ci static constexpr int kArgCOffset = -3 * kSystemPointerSize - kCPSlotSize; 1211cb0ef41Sopenharmony_ci static constexpr int kExpressionsOffset = 1221cb0ef41Sopenharmony_ci -4 * kSystemPointerSize - kCPSlotSize; 1231cb0ef41Sopenharmony_ci static constexpr int kFirstPushedFrameValueOffset = kExpressionsOffset; 1241cb0ef41Sopenharmony_ci static constexpr int kLastObjectOffset = kContextOffset; 1251cb0ef41Sopenharmony_ci}; 1261cb0ef41Sopenharmony_ci 1271cb0ef41Sopenharmony_ci// TypedFrames have a type maker value below the saved FP/constant pool to 1281cb0ef41Sopenharmony_ci// distinguish them from StandardFrames, which have a context in that position 1291cb0ef41Sopenharmony_ci// instead. 1301cb0ef41Sopenharmony_ci// 1311cb0ef41Sopenharmony_ci// slot JS frame 1321cb0ef41Sopenharmony_ci// +-----------------+-------------------------------- 1331cb0ef41Sopenharmony_ci// -n-1 | parameter n | ^ 1341cb0ef41Sopenharmony_ci// |- - - - - - - - -| | 1351cb0ef41Sopenharmony_ci// -n | parameter n-1 | Caller 1361cb0ef41Sopenharmony_ci// ... | ... | frame slots 1371cb0ef41Sopenharmony_ci// -2 | parameter 1 | (slot < 0) 1381cb0ef41Sopenharmony_ci// |- - - - - - - - -| | 1391cb0ef41Sopenharmony_ci// -1 | parameter 0 | v 1401cb0ef41Sopenharmony_ci// -----+-----------------+-------------------------------- 1411cb0ef41Sopenharmony_ci// 0 | return addr | ^ ^ 1421cb0ef41Sopenharmony_ci// |- - - - - - - - -| | | 1431cb0ef41Sopenharmony_ci// 1 | saved frame ptr | Fixed | 1441cb0ef41Sopenharmony_ci// |- - - - - - - - -| Header <-- frame ptr | 1451cb0ef41Sopenharmony_ci// 2 | [Constant Pool] | | | 1461cb0ef41Sopenharmony_ci// |- - - - - - - - -| | | 1471cb0ef41Sopenharmony_ci// 2+cp |Frame Type Marker| v if a constant pool | 1481cb0ef41Sopenharmony_ci// |-----------------+---- is used, cp = 1, | 1491cb0ef41Sopenharmony_ci// 3+cp | pushed value 0 | ^ otherwise, cp = 0 | 1501cb0ef41Sopenharmony_ci// |- - - - - - - - -| | | 1511cb0ef41Sopenharmony_ci// 4+cp | pushed value 1 | | Callee 1521cb0ef41Sopenharmony_ci// |- - - - - - - - -| | frame slots 1531cb0ef41Sopenharmony_ci// ... | | Frame slots (slot >= 0) 1541cb0ef41Sopenharmony_ci// |- - - - - - - - -| | | 1551cb0ef41Sopenharmony_ci// | | v | 1561cb0ef41Sopenharmony_ci// -----+-----------------+----- <-- stack ptr ------------- 1571cb0ef41Sopenharmony_ci// 1581cb0ef41Sopenharmony_ciclass TypedFrameConstants : public CommonFrameConstants { 1591cb0ef41Sopenharmony_ci public: 1601cb0ef41Sopenharmony_ci static constexpr int kFrameTypeSize = kContextOrFrameTypeSize; 1611cb0ef41Sopenharmony_ci static constexpr int kFrameTypeOffset = kContextOrFrameTypeOffset; 1621cb0ef41Sopenharmony_ci static constexpr int kFixedFrameSizeFromFp = kCPSlotSize + kFrameTypeSize; 1631cb0ef41Sopenharmony_ci static constexpr int kFixedSlotCountFromFp = 1641cb0ef41Sopenharmony_ci kFixedFrameSizeFromFp / kSystemPointerSize; 1651cb0ef41Sopenharmony_ci static constexpr int kFixedFrameSize = 1661cb0ef41Sopenharmony_ci StandardFrameConstants::kFixedFrameSizeAboveFp + kFixedFrameSizeFromFp; 1671cb0ef41Sopenharmony_ci static constexpr int kFixedSlotCount = kFixedFrameSize / kSystemPointerSize; 1681cb0ef41Sopenharmony_ci static constexpr int kFirstPushedFrameValueOffset = 1691cb0ef41Sopenharmony_ci -kFixedFrameSizeFromFp - kSystemPointerSize; 1701cb0ef41Sopenharmony_ci}; 1711cb0ef41Sopenharmony_ci 1721cb0ef41Sopenharmony_ci#define FRAME_PUSHED_VALUE_OFFSET(parent, x) \ 1731cb0ef41Sopenharmony_ci (parent::kFirstPushedFrameValueOffset - (x)*kSystemPointerSize) 1741cb0ef41Sopenharmony_ci#define FRAME_SIZE(parent, count) \ 1751cb0ef41Sopenharmony_ci (parent::kFixedFrameSize + (count)*kSystemPointerSize) 1761cb0ef41Sopenharmony_ci#define FRAME_SIZE_FROM_FP(parent, count) \ 1771cb0ef41Sopenharmony_ci (parent::kFixedFrameSizeFromFp + (count)*kSystemPointerSize) 1781cb0ef41Sopenharmony_ci#define DEFINE_FRAME_SIZES(parent, count) \ 1791cb0ef41Sopenharmony_ci static constexpr int kFixedFrameSize = FRAME_SIZE(parent, count); \ 1801cb0ef41Sopenharmony_ci static constexpr int kFixedSlotCount = kFixedFrameSize / kSystemPointerSize; \ 1811cb0ef41Sopenharmony_ci static constexpr int kFixedFrameSizeFromFp = \ 1821cb0ef41Sopenharmony_ci FRAME_SIZE_FROM_FP(parent, count); \ 1831cb0ef41Sopenharmony_ci static constexpr int kFixedSlotCountFromFp = \ 1841cb0ef41Sopenharmony_ci kFixedFrameSizeFromFp / kSystemPointerSize; \ 1851cb0ef41Sopenharmony_ci static constexpr int kExtraSlotCount = \ 1861cb0ef41Sopenharmony_ci kFixedFrameSize / kSystemPointerSize - \ 1871cb0ef41Sopenharmony_ci parent::kFixedFrameSize / kSystemPointerSize 1881cb0ef41Sopenharmony_ci 1891cb0ef41Sopenharmony_ci#define STANDARD_FRAME_EXTRA_PUSHED_VALUE_OFFSET(x) \ 1901cb0ef41Sopenharmony_ci FRAME_PUSHED_VALUE_OFFSET(StandardFrameConstants, x) 1911cb0ef41Sopenharmony_ci#define DEFINE_STANDARD_FRAME_SIZES(count) \ 1921cb0ef41Sopenharmony_ci DEFINE_FRAME_SIZES(StandardFrameConstants, count) 1931cb0ef41Sopenharmony_ci 1941cb0ef41Sopenharmony_ci#define TYPED_FRAME_PUSHED_VALUE_OFFSET(x) \ 1951cb0ef41Sopenharmony_ci FRAME_PUSHED_VALUE_OFFSET(TypedFrameConstants, x) 1961cb0ef41Sopenharmony_ci#define DEFINE_TYPED_FRAME_SIZES(count) \ 1971cb0ef41Sopenharmony_ci DEFINE_FRAME_SIZES(TypedFrameConstants, count) 1981cb0ef41Sopenharmony_ci 1991cb0ef41Sopenharmony_ciclass BuiltinFrameConstants : public TypedFrameConstants { 2001cb0ef41Sopenharmony_ci public: 2011cb0ef41Sopenharmony_ci // FP-relative. 2021cb0ef41Sopenharmony_ci static constexpr int kFunctionOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(0); 2031cb0ef41Sopenharmony_ci static constexpr int kLengthOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(1); 2041cb0ef41Sopenharmony_ci DEFINE_TYPED_FRAME_SIZES(2); 2051cb0ef41Sopenharmony_ci}; 2061cb0ef41Sopenharmony_ci 2071cb0ef41Sopenharmony_ci// Fixed frame slots shared by the js-to-wasm wrapper, the 2081cb0ef41Sopenharmony_ci// ReturnPromiseOnSuspend wrapper and the WasmResume wrapper. 2091cb0ef41Sopenharmony_ciclass BuiltinWasmWrapperConstants : public TypedFrameConstants { 2101cb0ef41Sopenharmony_ci public: 2111cb0ef41Sopenharmony_ci // This slot contains the number of slots at the top of the frame that need to 2121cb0ef41Sopenharmony_ci // be scanned by the GC. 2131cb0ef41Sopenharmony_ci static constexpr int kGCScanSlotCountOffset = 2141cb0ef41Sopenharmony_ci TYPED_FRAME_PUSHED_VALUE_OFFSET(0); 2151cb0ef41Sopenharmony_ci // The number of parameters passed to this function. 2161cb0ef41Sopenharmony_ci static constexpr int kInParamCountOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(1); 2171cb0ef41Sopenharmony_ci // The number of parameters according to the signature. 2181cb0ef41Sopenharmony_ci static constexpr int kParamCountOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(2); 2191cb0ef41Sopenharmony_ci}; 2201cb0ef41Sopenharmony_ci 2211cb0ef41Sopenharmony_ciclass ConstructFrameConstants : public TypedFrameConstants { 2221cb0ef41Sopenharmony_ci public: 2231cb0ef41Sopenharmony_ci // FP-relative. 2241cb0ef41Sopenharmony_ci static constexpr int kContextOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(0); 2251cb0ef41Sopenharmony_ci static constexpr int kLengthOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(1); 2261cb0ef41Sopenharmony_ci static constexpr int kConstructorOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(2); 2271cb0ef41Sopenharmony_ci static constexpr int kPaddingOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(3); 2281cb0ef41Sopenharmony_ci static constexpr int kNewTargetOrImplicitReceiverOffset = 2291cb0ef41Sopenharmony_ci TYPED_FRAME_PUSHED_VALUE_OFFSET(4); 2301cb0ef41Sopenharmony_ci DEFINE_TYPED_FRAME_SIZES(5); 2311cb0ef41Sopenharmony_ci}; 2321cb0ef41Sopenharmony_ci 2331cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY 2341cb0ef41Sopenharmony_ciclass CWasmEntryFrameConstants : public TypedFrameConstants { 2351cb0ef41Sopenharmony_ci public: 2361cb0ef41Sopenharmony_ci // FP-relative: 2371cb0ef41Sopenharmony_ci static constexpr int kCEntryFPOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(0); 2381cb0ef41Sopenharmony_ci DEFINE_TYPED_FRAME_SIZES(1); 2391cb0ef41Sopenharmony_ci}; 2401cb0ef41Sopenharmony_ci 2411cb0ef41Sopenharmony_ciclass WasmFrameConstants : public TypedFrameConstants { 2421cb0ef41Sopenharmony_ci public: 2431cb0ef41Sopenharmony_ci // FP-relative. 2441cb0ef41Sopenharmony_ci static constexpr int kWasmInstanceOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(0); 2451cb0ef41Sopenharmony_ci DEFINE_TYPED_FRAME_SIZES(1); 2461cb0ef41Sopenharmony_ci}; 2471cb0ef41Sopenharmony_ci 2481cb0ef41Sopenharmony_ciclass WasmExitFrameConstants : public WasmFrameConstants { 2491cb0ef41Sopenharmony_ci public: 2501cb0ef41Sopenharmony_ci // FP-relative. 2511cb0ef41Sopenharmony_ci static const int kCallingPCOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(1); 2521cb0ef41Sopenharmony_ci DEFINE_TYPED_FRAME_SIZES(2); 2531cb0ef41Sopenharmony_ci}; 2541cb0ef41Sopenharmony_ci#endif // V8_ENABLE_WEBASSEMBLY 2551cb0ef41Sopenharmony_ci 2561cb0ef41Sopenharmony_ciclass BuiltinContinuationFrameConstants : public TypedFrameConstants { 2571cb0ef41Sopenharmony_ci public: 2581cb0ef41Sopenharmony_ci // FP-relative. 2591cb0ef41Sopenharmony_ci static constexpr int kFunctionOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(0); 2601cb0ef41Sopenharmony_ci static constexpr int kFrameSPtoFPDeltaAtDeoptimize = 2611cb0ef41Sopenharmony_ci TYPED_FRAME_PUSHED_VALUE_OFFSET(1); 2621cb0ef41Sopenharmony_ci static constexpr int kBuiltinContextOffset = 2631cb0ef41Sopenharmony_ci TYPED_FRAME_PUSHED_VALUE_OFFSET(2); 2641cb0ef41Sopenharmony_ci static constexpr int kBuiltinIndexOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(3); 2651cb0ef41Sopenharmony_ci 2661cb0ef41Sopenharmony_ci // The argument count is in the first allocatable register, stored below the 2671cb0ef41Sopenharmony_ci // fixed part of the frame and therefore is not part of the fixed frame size. 2681cb0ef41Sopenharmony_ci static constexpr int kArgCOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(4); 2691cb0ef41Sopenharmony_ci DEFINE_TYPED_FRAME_SIZES(4); 2701cb0ef41Sopenharmony_ci 2711cb0ef41Sopenharmony_ci // Returns the number of padding stack slots needed when we have 2721cb0ef41Sopenharmony_ci // 'register_count' register slots. 2731cb0ef41Sopenharmony_ci // This is needed on some architectures to ensure the stack pointer is 2741cb0ef41Sopenharmony_ci // aligned. 2751cb0ef41Sopenharmony_ci static int PaddingSlotCount(int register_count); 2761cb0ef41Sopenharmony_ci}; 2771cb0ef41Sopenharmony_ci 2781cb0ef41Sopenharmony_ciclass ExitFrameConstants : public TypedFrameConstants { 2791cb0ef41Sopenharmony_ci public: 2801cb0ef41Sopenharmony_ci static constexpr int kSPOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(0); 2811cb0ef41Sopenharmony_ci static constexpr int kLastExitFrameField = kSPOffset; 2821cb0ef41Sopenharmony_ci DEFINE_TYPED_FRAME_SIZES(1); 2831cb0ef41Sopenharmony_ci 2841cb0ef41Sopenharmony_ci // FP-relative displacement of the caller's SP. It points just 2851cb0ef41Sopenharmony_ci // below the saved PC. 2861cb0ef41Sopenharmony_ci static constexpr int kCallerSPDisplacement = kCallerSPOffset; 2871cb0ef41Sopenharmony_ci}; 2881cb0ef41Sopenharmony_ci 2891cb0ef41Sopenharmony_ci// Behaves like an exit frame but with target and new target args. 2901cb0ef41Sopenharmony_ciclass BuiltinExitFrameConstants : public ExitFrameConstants { 2911cb0ef41Sopenharmony_ci public: 2921cb0ef41Sopenharmony_ci static constexpr int kNewTargetOffset = 2931cb0ef41Sopenharmony_ci kCallerPCOffset + 1 * kSystemPointerSize; 2941cb0ef41Sopenharmony_ci static constexpr int kTargetOffset = 2951cb0ef41Sopenharmony_ci kNewTargetOffset + 1 * kSystemPointerSize; 2961cb0ef41Sopenharmony_ci static constexpr int kArgcOffset = kTargetOffset + 1 * kSystemPointerSize; 2971cb0ef41Sopenharmony_ci static constexpr int kPaddingOffset = kArgcOffset + 1 * kSystemPointerSize; 2981cb0ef41Sopenharmony_ci static constexpr int kFirstArgumentOffset = 2991cb0ef41Sopenharmony_ci kPaddingOffset + 1 * kSystemPointerSize; 3001cb0ef41Sopenharmony_ci static constexpr int kNumExtraArgsWithoutReceiver = 4; 3011cb0ef41Sopenharmony_ci static constexpr int kNumExtraArgsWithReceiver = 3021cb0ef41Sopenharmony_ci kNumExtraArgsWithoutReceiver + 1; 3031cb0ef41Sopenharmony_ci}; 3041cb0ef41Sopenharmony_ci 3051cb0ef41Sopenharmony_ci// Unoptimized frames are used for interpreted and baseline-compiled JavaScript 3061cb0ef41Sopenharmony_ci// frames. They are a "standard" frame, with an additional fixed header for the 3071cb0ef41Sopenharmony_ci// BytecodeArray, bytecode offset (if running interpreted), feedback vector (if 3081cb0ef41Sopenharmony_ci// running baseline code), and then the interpreter register file. 3091cb0ef41Sopenharmony_ci// 3101cb0ef41Sopenharmony_ci// slot JS frame 3111cb0ef41Sopenharmony_ci// +-----------------+-------------------------------- 3121cb0ef41Sopenharmony_ci// -n-1 | parameter n | ^ 3131cb0ef41Sopenharmony_ci// |- - - - - - - - -| | 3141cb0ef41Sopenharmony_ci// -n | parameter n-1 | Caller 3151cb0ef41Sopenharmony_ci// ... | ... | frame slots 3161cb0ef41Sopenharmony_ci// -2 | parameter 1 | (slot < 0) 3171cb0ef41Sopenharmony_ci// |- - - - - - - - -| | 3181cb0ef41Sopenharmony_ci// -1 | parameter 0 | v 3191cb0ef41Sopenharmony_ci// -----+-----------------+-------------------------------- 3201cb0ef41Sopenharmony_ci// 0 | return addr | ^ ^ 3211cb0ef41Sopenharmony_ci// |- - - - - - - - -| | | 3221cb0ef41Sopenharmony_ci// 1 | saved frame ptr | Fixed | 3231cb0ef41Sopenharmony_ci// |- - - - - - - - -| Header <-- frame ptr | 3241cb0ef41Sopenharmony_ci// 2 | [Constant Pool] | | | 3251cb0ef41Sopenharmony_ci// |- - - - - - - - -| | | 3261cb0ef41Sopenharmony_ci// 2+cp | Context | | if a constant pool | 3271cb0ef41Sopenharmony_ci// |- - - - - - - - -| | is used, cp = 1, | 3281cb0ef41Sopenharmony_ci// 3+cp | JSFunction | | otherwise, cp = 0 | 3291cb0ef41Sopenharmony_ci// |- - - - - - - - -| | | 3301cb0ef41Sopenharmony_ci// 4+cp | argc | v | 3311cb0ef41Sopenharmony_ci// +-----------------+---- | 3321cb0ef41Sopenharmony_ci// 5+cp | BytecodeArray | ^ | 3331cb0ef41Sopenharmony_ci// |- - - - - - - - -| Unoptimized code header | 3341cb0ef41Sopenharmony_ci// 6+cp | offset or FBV | v | 3351cb0ef41Sopenharmony_ci// +-----------------+---- | 3361cb0ef41Sopenharmony_ci// 7+cp | register 0 | ^ Callee 3371cb0ef41Sopenharmony_ci// |- - - - - - - - -| | frame slots 3381cb0ef41Sopenharmony_ci// 8+cp | register 1 | Register file (slot >= 0) 3391cb0ef41Sopenharmony_ci// ... | ... | | | 3401cb0ef41Sopenharmony_ci// | register n-1 | | | 3411cb0ef41Sopenharmony_ci// |- - - - - - - - -| | | 3421cb0ef41Sopenharmony_ci// 8+cp+n| register n | v v 3431cb0ef41Sopenharmony_ci// -----+-----------------+----- <-- stack ptr ------------- 3441cb0ef41Sopenharmony_ci// 3451cb0ef41Sopenharmony_ciclass UnoptimizedFrameConstants : public StandardFrameConstants { 3461cb0ef41Sopenharmony_ci public: 3471cb0ef41Sopenharmony_ci // FP-relative. 3481cb0ef41Sopenharmony_ci static constexpr int kBytecodeArrayFromFp = 3491cb0ef41Sopenharmony_ci STANDARD_FRAME_EXTRA_PUSHED_VALUE_OFFSET(0); 3501cb0ef41Sopenharmony_ci static constexpr int kBytecodeOffsetOrFeedbackVectorFromFp = 3511cb0ef41Sopenharmony_ci STANDARD_FRAME_EXTRA_PUSHED_VALUE_OFFSET(1); 3521cb0ef41Sopenharmony_ci DEFINE_STANDARD_FRAME_SIZES(2); 3531cb0ef41Sopenharmony_ci 3541cb0ef41Sopenharmony_ci static constexpr int kFirstParamFromFp = 3551cb0ef41Sopenharmony_ci StandardFrameConstants::kCallerSPOffset; 3561cb0ef41Sopenharmony_ci static constexpr int kRegisterFileFromFp = 3571cb0ef41Sopenharmony_ci -kFixedFrameSizeFromFp - kSystemPointerSize; 3581cb0ef41Sopenharmony_ci static constexpr int kExpressionsOffset = kRegisterFileFromFp; 3591cb0ef41Sopenharmony_ci 3601cb0ef41Sopenharmony_ci // Expression index for {JavaScriptFrame::GetExpressionAddress}. 3611cb0ef41Sopenharmony_ci static constexpr int kBytecodeArrayExpressionIndex = -2; 3621cb0ef41Sopenharmony_ci static constexpr int kBytecodeOffsetOrFeedbackVectorExpressionIndex = -1; 3631cb0ef41Sopenharmony_ci static constexpr int kRegisterFileExpressionIndex = 0; 3641cb0ef41Sopenharmony_ci 3651cb0ef41Sopenharmony_ci // Returns the number of stack slots needed for 'register_count' registers. 3661cb0ef41Sopenharmony_ci // This is needed because some architectures must pad the stack frame with 3671cb0ef41Sopenharmony_ci // additional stack slots to ensure the stack pointer is aligned. 3681cb0ef41Sopenharmony_ci static int RegisterStackSlotCount(int register_count); 3691cb0ef41Sopenharmony_ci}; 3701cb0ef41Sopenharmony_ci 3711cb0ef41Sopenharmony_ci// Interpreter frames are unoptimized frames that are being executed by the 3721cb0ef41Sopenharmony_ci// interpreter. In this case, the "offset or FBV" slot contains the bytecode 3731cb0ef41Sopenharmony_ci// offset of the currently executing bytecode. 3741cb0ef41Sopenharmony_ciclass InterpreterFrameConstants : public UnoptimizedFrameConstants { 3751cb0ef41Sopenharmony_ci public: 3761cb0ef41Sopenharmony_ci static constexpr int kBytecodeOffsetExpressionIndex = 3771cb0ef41Sopenharmony_ci kBytecodeOffsetOrFeedbackVectorExpressionIndex; 3781cb0ef41Sopenharmony_ci 3791cb0ef41Sopenharmony_ci static constexpr int kBytecodeOffsetFromFp = 3801cb0ef41Sopenharmony_ci kBytecodeOffsetOrFeedbackVectorFromFp; 3811cb0ef41Sopenharmony_ci}; 3821cb0ef41Sopenharmony_ci 3831cb0ef41Sopenharmony_ci// Sparkplug frames are unoptimized frames that are being executed by 3841cb0ef41Sopenharmony_ci// sparkplug-compiled baseline code. base. In this case, the "offset or FBV" 3851cb0ef41Sopenharmony_ci// slot contains a cached pointer to the feedback vector. 3861cb0ef41Sopenharmony_ciclass BaselineFrameConstants : public UnoptimizedFrameConstants { 3871cb0ef41Sopenharmony_ci public: 3881cb0ef41Sopenharmony_ci static constexpr int kFeedbackVectorExpressionIndex = 3891cb0ef41Sopenharmony_ci kBytecodeOffsetOrFeedbackVectorExpressionIndex; 3901cb0ef41Sopenharmony_ci 3911cb0ef41Sopenharmony_ci static constexpr int kFeedbackVectorFromFp = 3921cb0ef41Sopenharmony_ci kBytecodeOffsetOrFeedbackVectorFromFp; 3931cb0ef41Sopenharmony_ci}; 3941cb0ef41Sopenharmony_ci 3951cb0ef41Sopenharmony_ciinline static int FPOffsetToFrameSlot(int frame_offset) { 3961cb0ef41Sopenharmony_ci return StandardFrameConstants::kFixedSlotCountAboveFp - 1 - 3971cb0ef41Sopenharmony_ci frame_offset / kSystemPointerSize; 3981cb0ef41Sopenharmony_ci} 3991cb0ef41Sopenharmony_ci 4001cb0ef41Sopenharmony_ciinline static int FrameSlotToFPOffset(int slot) { 4011cb0ef41Sopenharmony_ci return (StandardFrameConstants::kFixedSlotCountAboveFp - 1 - slot) * 4021cb0ef41Sopenharmony_ci kSystemPointerSize; 4031cb0ef41Sopenharmony_ci} 4041cb0ef41Sopenharmony_ci 4051cb0ef41Sopenharmony_ci} // namespace internal 4061cb0ef41Sopenharmony_ci} // namespace v8 4071cb0ef41Sopenharmony_ci 4081cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_IA32 4091cb0ef41Sopenharmony_ci#include "src/execution/ia32/frame-constants-ia32.h" 4101cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_X64 4111cb0ef41Sopenharmony_ci#include "src/execution/x64/frame-constants-x64.h" 4121cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_ARM64 4131cb0ef41Sopenharmony_ci#include "src/execution/arm64/frame-constants-arm64.h" 4141cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_ARM 4151cb0ef41Sopenharmony_ci#include "src/execution/arm/frame-constants-arm.h" 4161cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_PPC64 4171cb0ef41Sopenharmony_ci#include "src/execution/ppc/frame-constants-ppc.h" 4181cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_MIPS 4191cb0ef41Sopenharmony_ci#include "src/execution/mips/frame-constants-mips.h" 4201cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_MIPS64 4211cb0ef41Sopenharmony_ci#include "src/execution/mips64/frame-constants-mips64.h" 4221cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_LOONG64 4231cb0ef41Sopenharmony_ci#include "src/execution/loong64/frame-constants-loong64.h" 4241cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_S390 4251cb0ef41Sopenharmony_ci#include "src/execution/s390/frame-constants-s390.h" 4261cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_RISCV64 4271cb0ef41Sopenharmony_ci#include "src/execution/riscv64/frame-constants-riscv64.h" 4281cb0ef41Sopenharmony_ci#else 4291cb0ef41Sopenharmony_ci#error Unsupported target architecture. 4301cb0ef41Sopenharmony_ci#endif 4311cb0ef41Sopenharmony_ci 4321cb0ef41Sopenharmony_ci#endif // V8_EXECUTION_FRAME_CONSTANTS_H_ 433