| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
#include "jit/InlinableNatives.h" |
| 8 |
|
| 9 |
#ifdef JS_HAS_INTL_API |
| 10 |
# include "builtin/intl/Collator.h" |
| 11 |
# include "builtin/intl/DateTimeFormat.h" |
| 12 |
# include "builtin/intl/DisplayNames.h" |
| 13 |
# include "builtin/intl/DurationFormat.h" |
| 14 |
# include "builtin/intl/ListFormat.h" |
| 15 |
# include "builtin/intl/NumberFormat.h" |
| 16 |
# include "builtin/intl/PluralRules.h" |
| 17 |
# include "builtin/intl/RelativeTimeFormat.h" |
| 18 |
# include "builtin/intl/Segmenter.h" |
| 19 |
#endif |
| 20 |
#ifdef ENABLE_EXPLICIT_RESOURCE_MANAGEMENT |
| 21 |
# include "builtin/AsyncDisposableStackObject.h" |
| 22 |
# include "builtin/DisposableStackObject.h" |
| 23 |
#endif |
| 24 |
#include "builtin/MapObject.h" |
| 25 |
#include "js/experimental/JitInfo.h" |
| 26 |
#include "vm/ArrayBufferObject.h" |
| 27 |
#include "vm/AsyncIteration.h" |
| 28 |
#include "vm/Iteration.h" |
| 29 |
#include "vm/SharedArrayObject.h" |
| 30 |
|
| 31 |
using namespace js; |
| 32 |
using namespace js::jit; |
| 33 |
|
| 34 |
#define ADD_NATIVE(native) \ |
| 35 |
const JSJitInfo js::jit::JitInfo_##native{ \ |
| 36 |
{nullptr}, \ |
| 37 |
{uint16_t(InlinableNative::native)}, \ |
| 38 |
{0}, \ |
| 39 |
JSJitInfo::InlinableNative}; |
| 40 |
INLINABLE_NATIVE_LIST(ADD_NATIVE) |
| 41 |
#undef ADD_NATIVE |
| 42 |
|
| 43 |
const JSClass* js::jit::InlinableNativeGuardToClass(InlinableNative native) { |
| 44 |
switch (native) { |
| 45 |
#ifdef JS_HAS_INTL_API |
| 46 |
// Intl natives. |
| 47 |
case InlinableNative::IntlGuardToCollator: |
| 48 |
return &CollatorObject::class_; |
| 49 |
case InlinableNative::IntlGuardToDateTimeFormat: |
| 50 |
return &DateTimeFormatObject::class_; |
| 51 |
case InlinableNative::IntlGuardToDisplayNames: |
| 52 |
return &DisplayNamesObject::class_; |
| 53 |
case InlinableNative::IntlGuardToDurationFormat: |
| 54 |
return &DurationFormatObject::class_; |
| 55 |
case InlinableNative::IntlGuardToListFormat: |
| 56 |
return &ListFormatObject::class_; |
| 57 |
case InlinableNative::IntlGuardToNumberFormat: |
| 58 |
return &NumberFormatObject::class_; |
| 59 |
case InlinableNative::IntlGuardToPluralRules: |
| 60 |
return &PluralRulesObject::class_; |
| 61 |
case InlinableNative::IntlGuardToRelativeTimeFormat: |
| 62 |
return &RelativeTimeFormatObject::class_; |
| 63 |
case InlinableNative::IntlGuardToSegmenter: |
| 64 |
return &SegmenterObject::class_; |
| 65 |
case InlinableNative::IntlGuardToSegments: |
| 66 |
return &SegmentsObject::class_; |
| 67 |
case InlinableNative::IntlGuardToSegmentIterator: |
| 68 |
return &SegmentIteratorObject::class_; |
| 69 |
#else |
| 70 |
case InlinableNative::IntlGuardToCollator: |
| 71 |
case InlinableNative::IntlGuardToDateTimeFormat: |
| 72 |
case InlinableNative::IntlGuardToDisplayNames: |
| 73 |
case InlinableNative::IntlGuardToListFormat: |
| 74 |
case InlinableNative::IntlGuardToNumberFormat: |
| 75 |
case InlinableNative::IntlGuardToPluralRules: |
| 76 |
case InlinableNative::IntlGuardToRelativeTimeFormat: |
| 77 |
case InlinableNative::IntlGuardToSegmenter: |
| 78 |
case InlinableNative::IntlGuardToSegments: |
| 79 |
case InlinableNative::IntlGuardToSegmentIterator: |
| 80 |
MOZ_CRASH("Intl API disabled"); |
| 81 |
#endif |
| 82 |
|
| 83 |
// Utility intrinsics. |
| 84 |
case InlinableNative::IntrinsicGuardToArrayIterator: |
| 85 |
return &ArrayIteratorObject::class_; |
| 86 |
case InlinableNative::IntrinsicGuardToMapIterator: |
| 87 |
return &MapIteratorObject::class_; |
| 88 |
case InlinableNative::IntrinsicGuardToSetIterator: |
| 89 |
return &SetIteratorObject::class_; |
| 90 |
case InlinableNative::IntrinsicGuardToStringIterator: |
| 91 |
return &StringIteratorObject::class_; |
| 92 |
case InlinableNative::IntrinsicGuardToRegExpStringIterator: |
| 93 |
return &RegExpStringIteratorObject::class_; |
| 94 |
case InlinableNative::IntrinsicGuardToWrapForValidIterator: |
| 95 |
return &WrapForValidIteratorObject::class_; |
| 96 |
case InlinableNative::IntrinsicGuardToIteratorHelper: |
| 97 |
return &IteratorHelperObject::class_; |
| 98 |
#ifdef NIGHTLY_BUILD |
| 99 |
case InlinableNative::IntrinsicGuardToIteratorRange: |
| 100 |
return &IteratorRangeObject::class_; |
| 101 |
#endif |
| 102 |
case InlinableNative::IntrinsicGuardToAsyncIteratorHelper: |
| 103 |
return &AsyncIteratorHelperObject::class_; |
| 104 |
#ifdef ENABLE_EXPLICIT_RESOURCE_MANAGEMENT |
| 105 |
case InlinableNative::IntrinsicGuardToAsyncDisposableStack: |
| 106 |
return &AsyncDisposableStackObject::class_; |
| 107 |
case InlinableNative::IntrinsicGuardToDisposableStack: |
| 108 |
return &DisposableStackObject::class_; |
| 109 |
#endif |
| 110 |
|
| 111 |
case InlinableNative::IntrinsicGuardToMapObject: |
| 112 |
return &MapObject::class_; |
| 113 |
case InlinableNative::IntrinsicGuardToSetObject: |
| 114 |
return &SetObject::class_; |
| 115 |
case InlinableNative::IntrinsicGuardToArrayBuffer: |
| 116 |
return &FixedLengthArrayBufferObject::class_; |
| 117 |
case InlinableNative::IntrinsicGuardToSharedArrayBuffer: |
| 118 |
return &FixedLengthSharedArrayBufferObject::class_; |
| 119 |
|
| 120 |
default: |
| 121 |
MOZ_CRASH("Not a GuardTo instruction"); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
// Returns true if |native| can be inlined cross-realm. Especially inlined |
| 126 |
// natives that can allocate objects or throw exceptions shouldn't be inlined |
| 127 |
// cross-realm without a careful analysis because we might use the wrong realm! |
| 128 |
// |
| 129 |
// Note that self-hosting intrinsics are never called cross-realm. See the |
| 130 |
// MOZ_CRASH below. |
| 131 |
// |
| 132 |
// If you are adding a new inlinable native, the safe thing is to |return false| |
| 133 |
// here. |
| 134 |
bool js::jit::CanInlineNativeCrossRealm(InlinableNative native) { |
| 135 |
switch (native) { |
| 136 |
case InlinableNative::MathAbs: |
| 137 |
case InlinableNative::MathFloor: |
| 138 |
case InlinableNative::MathCeil: |
| 139 |
case InlinableNative::MathRound: |
| 140 |
case InlinableNative::MathClz32: |
| 141 |
case InlinableNative::MathSqrt: |
| 142 |
case InlinableNative::MathATan2: |
| 143 |
case InlinableNative::MathHypot: |
| 144 |
case InlinableNative::MathMax: |
| 145 |
case InlinableNative::MathMin: |
| 146 |
case InlinableNative::MathPow: |
| 147 |
case InlinableNative::MathImul: |
| 148 |
case InlinableNative::MathFRound: |
| 149 |
case InlinableNative::MathF16Round: |
| 150 |
case InlinableNative::MathTrunc: |
| 151 |
case InlinableNative::MathSign: |
| 152 |
case InlinableNative::MathSin: |
| 153 |
case InlinableNative::MathTan: |
| 154 |
case InlinableNative::MathCos: |
| 155 |
case InlinableNative::MathExp: |
| 156 |
case InlinableNative::MathLog: |
| 157 |
case InlinableNative::MathASin: |
| 158 |
case InlinableNative::MathATan: |
| 159 |
case InlinableNative::MathACos: |
| 160 |
case InlinableNative::MathLog10: |
| 161 |
case InlinableNative::MathLog2: |
| 162 |
case InlinableNative::MathLog1P: |
| 163 |
case InlinableNative::MathExpM1: |
| 164 |
case InlinableNative::MathCosH: |
| 165 |
case InlinableNative::MathSinH: |
| 166 |
case InlinableNative::MathTanH: |
| 167 |
case InlinableNative::MathACosH: |
| 168 |
case InlinableNative::MathASinH: |
| 169 |
case InlinableNative::MathATanH: |
| 170 |
case InlinableNative::MathCbrt: |
| 171 |
case InlinableNative::Boolean: |
| 172 |
return true; |
| 173 |
|
| 174 |
case InlinableNative::Array: |
| 175 |
// Cross-realm case handled by inlineArray. |
| 176 |
return true; |
| 177 |
|
| 178 |
case InlinableNative::MathRandom: |
| 179 |
// RNG state is per-realm. |
| 180 |
return false; |
| 181 |
|
| 182 |
case InlinableNative::IntlGuardToCollator: |
| 183 |
case InlinableNative::IntlGuardToDateTimeFormat: |
| 184 |
case InlinableNative::IntlGuardToDisplayNames: |
| 185 |
case InlinableNative::IntlGuardToDurationFormat: |
| 186 |
case InlinableNative::IntlGuardToListFormat: |
| 187 |
case InlinableNative::IntlGuardToNumberFormat: |
| 188 |
case InlinableNative::IntlGuardToPluralRules: |
| 189 |
case InlinableNative::IntlGuardToRelativeTimeFormat: |
| 190 |
case InlinableNative::IntlGuardToSegmenter: |
| 191 |
case InlinableNative::IntlGuardToSegments: |
| 192 |
case InlinableNative::IntlGuardToSegmentIterator: |
| 193 |
case InlinableNative::IsRegExpObject: |
| 194 |
case InlinableNative::IsOptimizableRegExpObject: |
| 195 |
case InlinableNative::IsPossiblyWrappedRegExpObject: |
| 196 |
case InlinableNative::IsRegExpPrototypeOptimizable: |
| 197 |
case InlinableNative::RegExpMatcher: |
| 198 |
case InlinableNative::RegExpSearcher: |
| 199 |
case InlinableNative::RegExpSearcherLastLimit: |
| 200 |
case InlinableNative::RegExpHasCaptureGroups: |
| 201 |
case InlinableNative::GetFirstDollarIndex: |
| 202 |
case InlinableNative::IntrinsicNewArrayIterator: |
| 203 |
case InlinableNative::IntrinsicNewStringIterator: |
| 204 |
case InlinableNative::IntrinsicNewRegExpStringIterator: |
| 205 |
case InlinableNative::IntrinsicStringReplaceString: |
| 206 |
case InlinableNative::IntrinsicStringSplitString: |
| 207 |
case InlinableNative::IntrinsicUnsafeSetReservedSlot: |
| 208 |
case InlinableNative::IntrinsicUnsafeGetReservedSlot: |
| 209 |
case InlinableNative::IntrinsicUnsafeGetObjectFromReservedSlot: |
| 210 |
case InlinableNative::IntrinsicUnsafeGetInt32FromReservedSlot: |
| 211 |
case InlinableNative::IntrinsicUnsafeGetStringFromReservedSlot: |
| 212 |
case InlinableNative::IntrinsicIsCallable: |
| 213 |
case InlinableNative::IntrinsicIsConstructor: |
| 214 |
case InlinableNative::IntrinsicToObject: |
| 215 |
case InlinableNative::IntrinsicIsObject: |
| 216 |
case InlinableNative::IntrinsicIsCrossRealmArrayConstructor: |
| 217 |
case InlinableNative::IntrinsicCanOptimizeArraySpecies: |
| 218 |
case InlinableNative::IntrinsicCanOptimizeStringProtoSymbolLookup: |
| 219 |
case InlinableNative::IntrinsicToInteger: |
| 220 |
case InlinableNative::IntrinsicToLength: |
| 221 |
case InlinableNative::IntrinsicIsConstructing: |
| 222 |
case InlinableNative::IntrinsicIsSuspendedGenerator: |
| 223 |
case InlinableNative::IntrinsicSubstringKernel: |
| 224 |
case InlinableNative::IntrinsicGuardToArrayIterator: |
| 225 |
case InlinableNative::IntrinsicGuardToMapIterator: |
| 226 |
case InlinableNative::IntrinsicGuardToSetIterator: |
| 227 |
case InlinableNative::IntrinsicGuardToStringIterator: |
| 228 |
case InlinableNative::IntrinsicGuardToRegExpStringIterator: |
| 229 |
case InlinableNative::IntrinsicGuardToWrapForValidIterator: |
| 230 |
case InlinableNative::IntrinsicGuardToIteratorHelper: |
| 231 |
case InlinableNative::IntrinsicGuardToAsyncIteratorHelper: |
| 232 |
#ifdef NIGHTLY_BUILD |
| 233 |
case InlinableNative::IntrinsicGuardToIteratorRange: |
| 234 |
#endif |
| 235 |
case InlinableNative::IntrinsicIsPackedArray: |
| 236 |
case InlinableNative::IntrinsicGuardToMapObject: |
| 237 |
case InlinableNative::IntrinsicGetNextMapEntryForIterator: |
| 238 |
case InlinableNative::IntrinsicGuardToSetObject: |
| 239 |
case InlinableNative::IntrinsicGetNextSetEntryForIterator: |
| 240 |
case InlinableNative::IntrinsicGuardToArrayBuffer: |
| 241 |
case InlinableNative::IntrinsicGuardToSharedArrayBuffer: |
| 242 |
case InlinableNative::IntrinsicIsTypedArrayConstructor: |
| 243 |
case InlinableNative::IntrinsicIsTypedArray: |
| 244 |
case InlinableNative::IntrinsicIsPossiblyWrappedTypedArray: |
| 245 |
case InlinableNative::IntrinsicPossiblyWrappedTypedArrayLength: |
| 246 |
case InlinableNative::IntrinsicRegExpBuiltinExec: |
| 247 |
case InlinableNative::IntrinsicRegExpBuiltinExecForTest: |
| 248 |
case InlinableNative::IntrinsicRegExpExec: |
| 249 |
case InlinableNative::IntrinsicRegExpExecForTest: |
| 250 |
case InlinableNative::IntrinsicTypedArrayLength: |
| 251 |
case InlinableNative::IntrinsicTypedArrayLengthZeroOnOutOfBounds: |
| 252 |
case InlinableNative::IntrinsicTypedArrayByteOffset: |
| 253 |
case InlinableNative::IntrinsicTypedArrayElementSize: |
| 254 |
case InlinableNative::IntrinsicArrayIteratorPrototypeOptimizable: |
| 255 |
case InlinableNative::IntrinsicThisTimeValue: |
| 256 |
#ifdef ENABLE_EXPLICIT_RESOURCE_MANAGEMENT |
| 257 |
case InlinableNative::IntrinsicGuardToAsyncDisposableStack: |
| 258 |
case InlinableNative::IntrinsicGuardToDisposableStack: |
| 259 |
#endif |
| 260 |
MOZ_CRASH("Unexpected cross-realm intrinsic call"); |
| 261 |
|
| 262 |
case InlinableNative::TestBailout: |
| 263 |
case InlinableNative::TestAssertFloat32: |
| 264 |
case InlinableNative::TestAssertRecoveredOnBailout: |
| 265 |
// Testing functions, not worth inlining cross-realm. |
| 266 |
return false; |
| 267 |
|
| 268 |
case InlinableNative::ArrayIsArray: |
| 269 |
case InlinableNative::ArrayJoin: |
| 270 |
case InlinableNative::ArrayPop: |
| 271 |
case InlinableNative::ArrayShift: |
| 272 |
case InlinableNative::ArrayPush: |
| 273 |
case InlinableNative::ArraySlice: |
| 274 |
case InlinableNative::AtomicsCompareExchange: |
| 275 |
case InlinableNative::AtomicsExchange: |
| 276 |
case InlinableNative::AtomicsLoad: |
| 277 |
case InlinableNative::AtomicsStore: |
| 278 |
case InlinableNative::AtomicsAdd: |
| 279 |
case InlinableNative::AtomicsSub: |
| 280 |
case InlinableNative::AtomicsAnd: |
| 281 |
case InlinableNative::AtomicsOr: |
| 282 |
case InlinableNative::AtomicsXor: |
| 283 |
case InlinableNative::AtomicsIsLockFree: |
| 284 |
case InlinableNative::AtomicsPause: |
| 285 |
case InlinableNative::BigInt: |
| 286 |
case InlinableNative::BigIntAsIntN: |
| 287 |
case InlinableNative::BigIntAsUintN: |
| 288 |
case InlinableNative::DataViewGetInt8: |
| 289 |
case InlinableNative::DataViewGetUint8: |
| 290 |
case InlinableNative::DataViewGetInt16: |
| 291 |
case InlinableNative::DataViewGetUint16: |
| 292 |
case InlinableNative::DataViewGetInt32: |
| 293 |
case InlinableNative::DataViewGetUint32: |
| 294 |
case InlinableNative::DataViewGetFloat16: |
| 295 |
case InlinableNative::DataViewGetFloat32: |
| 296 |
case InlinableNative::DataViewGetFloat64: |
| 297 |
case InlinableNative::DataViewGetBigInt64: |
| 298 |
case InlinableNative::DataViewGetBigUint64: |
| 299 |
case InlinableNative::DataViewSetInt8: |
| 300 |
case InlinableNative::DataViewSetUint8: |
| 301 |
case InlinableNative::DataViewSetInt16: |
| 302 |
case InlinableNative::DataViewSetUint16: |
| 303 |
case InlinableNative::DataViewSetInt32: |
| 304 |
case InlinableNative::DataViewSetUint32: |
| 305 |
case InlinableNative::DataViewSetFloat16: |
| 306 |
case InlinableNative::DataViewSetFloat32: |
| 307 |
case InlinableNative::DataViewSetFloat64: |
| 308 |
case InlinableNative::DataViewSetBigInt64: |
| 309 |
case InlinableNative::DataViewSetBigUint64: |
| 310 |
case InlinableNative::DateGetTime: |
| 311 |
case InlinableNative::DateGetFullYear: |
| 312 |
case InlinableNative::DateGetMonth: |
| 313 |
case InlinableNative::DateGetDate: |
| 314 |
case InlinableNative::DateGetDay: |
| 315 |
case InlinableNative::DateGetHours: |
| 316 |
case InlinableNative::DateGetMinutes: |
| 317 |
case InlinableNative::DateGetSeconds: |
| 318 |
case InlinableNative::FunctionBind: |
| 319 |
case InlinableNative::MapConstructor: |
| 320 |
case InlinableNative::MapGet: |
| 321 |
case InlinableNative::MapHas: |
| 322 |
case InlinableNative::MapDelete: |
| 323 |
case InlinableNative::MapSet: |
| 324 |
case InlinableNative::Number: |
| 325 |
case InlinableNative::NumberParseInt: |
| 326 |
case InlinableNative::NumberToString: |
| 327 |
case InlinableNative::ReflectGetPrototypeOf: |
| 328 |
case InlinableNative::SetConstructor: |
| 329 |
case InlinableNative::SetHas: |
| 330 |
case InlinableNative::SetDelete: |
| 331 |
case InlinableNative::SetAdd: |
| 332 |
case InlinableNative::SetSize: |
| 333 |
case InlinableNative::String: |
| 334 |
case InlinableNative::StringToString: |
| 335 |
case InlinableNative::StringValueOf: |
| 336 |
case InlinableNative::StringCharCodeAt: |
| 337 |
case InlinableNative::StringCodePointAt: |
| 338 |
case InlinableNative::StringFromCharCode: |
| 339 |
case InlinableNative::StringFromCodePoint: |
| 340 |
case InlinableNative::StringCharAt: |
| 341 |
case InlinableNative::StringAt: |
| 342 |
case InlinableNative::StringIncludes: |
| 343 |
case InlinableNative::StringIndexOf: |
| 344 |
case InlinableNative::StringLastIndexOf: |
| 345 |
case InlinableNative::StringStartsWith: |
| 346 |
case InlinableNative::StringEndsWith: |
| 347 |
case InlinableNative::StringToLowerCase: |
| 348 |
case InlinableNative::StringToUpperCase: |
| 349 |
case InlinableNative::StringTrim: |
| 350 |
case InlinableNative::StringTrimStart: |
| 351 |
case InlinableNative::StringTrimEnd: |
| 352 |
case InlinableNative::Object: |
| 353 |
case InlinableNative::ObjectCreate: |
| 354 |
case InlinableNative::ObjectIs: |
| 355 |
case InlinableNative::ObjectIsPrototypeOf: |
| 356 |
case InlinableNative::ObjectKeys: |
| 357 |
case InlinableNative::ObjectToString: |
| 358 |
case InlinableNative::TypedArrayConstructor: |
| 359 |
#ifdef FUZZING_JS_FUZZILLI |
| 360 |
case InlinableNative::FuzzilliHash: |
| 361 |
#endif |
| 362 |
// Default to false for most natives. |
| 363 |
return false; |
| 364 |
|
| 365 |
case InlinableNative::Limit: |
| 366 |
break; |
| 367 |
} |
| 368 |
MOZ_CRASH("Unknown native"); |
| 369 |
} |