| 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/Snapshots.h" |
| 8 |
|
| 9 |
#include "jit/JitSpewer.h" |
| 10 |
#ifdef TRACK_SNAPSHOTS |
| 11 |
# include "jit/LIR.h" |
| 12 |
#endif |
| 13 |
#include "jit/MIR-wasm.h" |
| 14 |
#include "jit/MIR.h" |
| 15 |
#include "jit/Recover.h" |
| 16 |
#include "js/Printer.h" |
| 17 |
|
| 18 |
using namespace js; |
| 19 |
using namespace js::jit; |
| 20 |
|
| 21 |
// [SMDOC] IonMonkey Snapshot encoding |
| 22 |
// |
| 23 |
// Encodings: |
| 24 |
// [ptr] A fixed-size pointer. |
| 25 |
// [vwu] A variable-width unsigned integer. |
| 26 |
// [vws] A variable-width signed integer. |
| 27 |
// [u8] An 8-bit unsigned integer. |
| 28 |
// [u8'] An 8-bit unsigned integer which is potentially extended with packed |
| 29 |
// data. |
| 30 |
// [u8"] Packed data which is stored and packed in the previous [u8']. |
| 31 |
// [vwu*] A list of variable-width unsigned integers. |
| 32 |
// [pld] Payload of Recover Value Allocation: |
| 33 |
// PAYLOAD_NONE: |
| 34 |
// There is no payload. |
| 35 |
// |
| 36 |
// PAYLOAD_INDEX: |
| 37 |
// [vwu] Index, such as the constant pool index. |
| 38 |
// |
| 39 |
// PAYLOAD_STACK_OFFSET: |
| 40 |
// [vws] Stack offset based on the base of the Ion frame. |
| 41 |
// |
| 42 |
// PAYLOAD_GPR: |
| 43 |
// [u8] Code of the general register. |
| 44 |
// |
| 45 |
// PAYLOAD_FPU: |
| 46 |
// [u8] Code of the FPU register. |
| 47 |
// |
| 48 |
// PAYLOAD_PACKED_TAG: |
| 49 |
// [u8"] Bits 5-7: JSValueType is encoded on the low bits of the Mode |
| 50 |
// of the RValueAllocation. |
| 51 |
// |
| 52 |
// Snapshot header: |
| 53 |
// |
| 54 |
// [vwu] bits ((n+1),63]: recover instruction offset |
| 55 |
// bits [0,n): bailout kind (n = SNAPSHOT_BAILOUTKIND_BITS) |
| 56 |
// |
| 57 |
// Snapshot body, repeated "frame count" times, from oldest frame to newest |
| 58 |
// frame. Note that the first frame doesn't have the "parent PC" field. |
| 59 |
// |
| 60 |
// [ptr] Debug only: JSScript* |
| 61 |
// [vwu] pc offset |
| 62 |
// [vwu] # of RVA's indexes, including nargs |
| 63 |
// [vwu*] List of indexes to R(ecover)ValueAllocation table. Contains |
| 64 |
// nargs + nfixed + stackDepth items. |
| 65 |
// |
| 66 |
// Recover value allocations are encoded at the end of the Snapshot buffer, and |
| 67 |
// they are padded on ALLOCATION_TABLE_ALIGNMENT. The encoding of each |
| 68 |
// allocation is determined by the RValueAllocation::Layout, which can be |
| 69 |
// obtained from the RValueAllocation::Mode with layoutFromMode function. The |
| 70 |
// layout structure list the type of payload which are used to serialized / |
| 71 |
// deserialized / dumped the content of the allocations. |
| 72 |
// |
| 73 |
// R(ecover)ValueAllocation items: |
| 74 |
// [u8'] Mode, which defines the type of the payload as well as the |
| 75 |
// interpretation. |
| 76 |
// [pld] first payload (packed tag, index, stack offset, register, ...) |
| 77 |
// [pld] second payload (register, stack offset, none) |
| 78 |
// |
| 79 |
// Modes: |
| 80 |
// CONSTANT [INDEX] |
| 81 |
// Index into the constant pool. |
| 82 |
// |
| 83 |
// CST_UNDEFINED [] |
| 84 |
// Constant value which correspond to the "undefined" JS value. |
| 85 |
// |
| 86 |
// CST_NULL [] |
| 87 |
// Constant value which correspond to the "null" JS value. |
| 88 |
// |
| 89 |
// DOUBLE_REG [FPU_REG] |
| 90 |
// Double value stored in a FPU register. |
| 91 |
// |
| 92 |
// FLOAT32_REG [FPU_REG] |
| 93 |
// Float32 value stored in a FPU register. |
| 94 |
// |
| 95 |
// FLOAT32_STACK [STACK_OFFSET] |
| 96 |
// Float32 value stored on the stack. |
| 97 |
// |
| 98 |
// UNTYPED_REG [GPR_REG] |
| 99 |
// UNTYPED_STACK [STACK_OFFSET] |
| 100 |
// UNTYPED_REG_REG [GPR_REG, GPR_REG] |
| 101 |
// UNTYPED_REG_STACK [GPR_REG, STACK_OFFSET] |
| 102 |
// UNTYPED_STACK_REG [STACK_OFFSET, GPR_REG] |
| 103 |
// UNTYPED_STACK_STACK [STACK_OFFSET, STACK_OFFSET] |
| 104 |
// Value with dynamically known type. On 32 bits architecture, the |
| 105 |
// first register/stack-offset correspond to the holder of the type, |
| 106 |
// and the second correspond to the payload of the JS Value. |
| 107 |
// |
| 108 |
// RECOVER_INSTRUCTION [INDEX] |
| 109 |
// Index into the list of recovered instruction results. |
| 110 |
// |
| 111 |
// RI_WITH_DEFAULT_CST [INDEX] [INDEX] |
| 112 |
// The first payload is the index into the list of recovered |
| 113 |
// instruction results. The second payload is the index in the |
| 114 |
// constant pool. |
| 115 |
// |
| 116 |
// INTPTR_CST [INDEX]: (32-bit platform) |
| 117 |
// INTPTR_CST [INDEX] [INDEX]: (64-bit platform) |
| 118 |
// Unpacked IntPtr value stored in intptr_t. Split into either one or |
| 119 |
// two int32_t values, whose indices into the constant pool is stored |
| 120 |
// in the payloads. |
| 121 |
// |
| 122 |
// INTPTR_REG [GPR_REG]: |
| 123 |
// Unpacked IntPtr value stored in intptr_t. Payload is stored in a |
| 124 |
// register. |
| 125 |
// |
| 126 |
// INTPTR_STACK [STACK_OFFSET]: |
| 127 |
// Unpacked IntPtr value stored in intptr_t. Payload is stored at an |
| 128 |
// offset on the stack. |
| 129 |
// |
| 130 |
// INTPTR_INT32_STACK [STACK_OFFSET]: |
| 131 |
// Unpacked IntPtr value stored in int32_t. Payload is stored at an |
| 132 |
// offset on the stack. |
| 133 |
// |
| 134 |
// TYPED_REG [PACKED_TAG, GPR_REG]: |
| 135 |
// Value with statically known type, which payload is stored in a |
| 136 |
// register. |
| 137 |
// |
| 138 |
// TYPED_STACK [PACKED_TAG, STACK_OFFSET]: |
| 139 |
// Value with statically known type, which payload is stored at an |
| 140 |
// offset on the stack. |
| 141 |
// |
| 142 |
// INT64_CST [INDEX] [INDEX]: |
| 143 |
// Unpacked Int64 value stored in int64_t. Split into two int32_t |
| 144 |
// values, whose indices into the constant pool is stored in the |
| 145 |
// payloads. |
| 146 |
// |
| 147 |
// INT64_REG [GPR_REG]: |
| 148 |
// INT64_STACK [STACK_OFFSET]: |
| 149 |
// INT64_REG_REG [GPR_REG, GPR_REG] |
| 150 |
// INT64_REG_STACK [GPR_REG, STACK_OFFSET] |
| 151 |
// INT64_STACK_REG [STACK_OFFSET, GPR_REG] |
| 152 |
// INT64_STACK_STACK [STACK_OFFSET, STACK_OFFSET] |
| 153 |
// Unpacked Int64 value. On 32 bits architecture, the first |
| 154 |
// register/stack-offset correspond to the low 32-bits, and the |
| 155 |
// second correspond to the high 32-bits. |
| 156 |
// |
| 157 |
// INT64_INT32_STACK [STACK_OFFSET]: (64-bit platform) |
| 158 |
// Unpacked Int64 value stored in int32_t. Payload is stored at an |
| 159 |
// offset on the stack. |
| 160 |
|
| 161 |
const RValueAllocation::Layout& RValueAllocation::layoutFromMode(Mode mode) { |
| 162 |
switch (mode) { |
| 163 |
case CONSTANT: { |
| 164 |
static const RValueAllocation::Layout layout = {PAYLOAD_INDEX, |
| 165 |
PAYLOAD_NONE, "constant"}; |
| 166 |
return layout; |
| 167 |
} |
| 168 |
|
| 169 |
case CST_UNDEFINED: { |
| 170 |
static const RValueAllocation::Layout layout = { |
| 171 |
PAYLOAD_NONE, PAYLOAD_NONE, "undefined"}; |
| 172 |
return layout; |
| 173 |
} |
| 174 |
|
| 175 |
case CST_NULL: { |
| 176 |
static const RValueAllocation::Layout layout = {PAYLOAD_NONE, |
| 177 |
PAYLOAD_NONE, "null"}; |
| 178 |
return layout; |
| 179 |
} |
| 180 |
|
| 181 |
case DOUBLE_REG: { |
| 182 |
static const RValueAllocation::Layout layout = {PAYLOAD_FPU, PAYLOAD_NONE, |
| 183 |
"double"}; |
| 184 |
return layout; |
| 185 |
} |
| 186 |
case FLOAT32_REG: { |
| 187 |
static const RValueAllocation::Layout layout = {PAYLOAD_FPU, PAYLOAD_NONE, |
| 188 |
"float32"}; |
| 189 |
return layout; |
| 190 |
} |
| 191 |
case FLOAT32_STACK: { |
| 192 |
static const RValueAllocation::Layout layout = {PAYLOAD_STACK_OFFSET, |
| 193 |
PAYLOAD_NONE, "float32"}; |
| 194 |
return layout; |
| 195 |
} |
| 196 |
#if defined(JS_NUNBOX32) |
| 197 |
case UNTYPED_REG_REG: { |
| 198 |
static const RValueAllocation::Layout layout = {PAYLOAD_GPR, PAYLOAD_GPR, |
| 199 |
"value"}; |
| 200 |
return layout; |
| 201 |
} |
| 202 |
case UNTYPED_REG_STACK: { |
| 203 |
static const RValueAllocation::Layout layout = { |
| 204 |
PAYLOAD_GPR, PAYLOAD_STACK_OFFSET, "value"}; |
| 205 |
return layout; |
| 206 |
} |
| 207 |
case UNTYPED_STACK_REG: { |
| 208 |
static const RValueAllocation::Layout layout = {PAYLOAD_STACK_OFFSET, |
| 209 |
PAYLOAD_GPR, "value"}; |
| 210 |
return layout; |
| 211 |
} |
| 212 |
case UNTYPED_STACK_STACK: { |
| 213 |
static const RValueAllocation::Layout layout = { |
| 214 |
PAYLOAD_STACK_OFFSET, PAYLOAD_STACK_OFFSET, "value"}; |
| 215 |
return layout; |
| 216 |
} |
| 217 |
#elif defined(JS_PUNBOX64) |
| 218 |
case UNTYPED_REG: { |
| 219 |
static const RValueAllocation::Layout layout = {PAYLOAD_GPR, PAYLOAD_NONE, |
| 220 |
"value"}; |
| 221 |
return layout; |
| 222 |
} |
| 223 |
case UNTYPED_STACK: { |
| 224 |
static const RValueAllocation::Layout layout = {PAYLOAD_STACK_OFFSET, |
| 225 |
PAYLOAD_NONE, "value"}; |
| 226 |
return layout; |
| 227 |
} |
| 228 |
#endif |
| 229 |
case RECOVER_INSTRUCTION: { |
| 230 |
static const RValueAllocation::Layout layout = { |
| 231 |
PAYLOAD_INDEX, PAYLOAD_NONE, "instruction"}; |
| 232 |
return layout; |
| 233 |
} |
| 234 |
case RI_WITH_DEFAULT_CST: { |
| 235 |
static const RValueAllocation::Layout layout = { |
| 236 |
PAYLOAD_INDEX, PAYLOAD_INDEX, "instruction with default"}; |
| 237 |
return layout; |
| 238 |
} |
| 239 |
|
| 240 |
case INTPTR_CST: { |
| 241 |
#if !defined(JS_64BIT) |
| 242 |
static const RValueAllocation::Layout layout = { |
| 243 |
PAYLOAD_INDEX, PAYLOAD_NONE, "unpacked intptr constant"}; |
| 244 |
static_assert(sizeof(int32_t) == sizeof(intptr_t)); |
| 245 |
#else |
| 246 |
static const RValueAllocation::Layout layout = { |
| 247 |
PAYLOAD_INDEX, PAYLOAD_INDEX, "unpacked intptr constant"}; |
| 248 |
static_assert(2 * sizeof(int32_t) == sizeof(intptr_t)); |
| 249 |
#endif |
| 250 |
return layout; |
| 251 |
} |
| 252 |
|
| 253 |
case INTPTR_REG: { |
| 254 |
static const RValueAllocation::Layout layout = {PAYLOAD_GPR, PAYLOAD_NONE, |
| 255 |
"unpacked intptr"}; |
| 256 |
return layout; |
| 257 |
} |
| 258 |
|
| 259 |
case INTPTR_STACK: { |
| 260 |
static const RValueAllocation::Layout layout = { |
| 261 |
PAYLOAD_STACK_OFFSET, PAYLOAD_NONE, "unpacked intptr"}; |
| 262 |
return layout; |
| 263 |
} |
| 264 |
|
| 265 |
case INTPTR_INT32_STACK: { |
| 266 |
static const RValueAllocation::Layout layout = { |
| 267 |
PAYLOAD_STACK_OFFSET, PAYLOAD_NONE, "unpacked intptr (int32)"}; |
| 268 |
return layout; |
| 269 |
} |
| 270 |
|
| 271 |
case INT64_CST: { |
| 272 |
static const RValueAllocation::Layout layout = { |
| 273 |
PAYLOAD_INDEX, PAYLOAD_INDEX, "unpacked int64 constant"}; |
| 274 |
static_assert(2 * sizeof(int32_t) == sizeof(int64_t)); |
| 275 |
return layout; |
| 276 |
} |
| 277 |
|
| 278 |
#if defined(JS_NUNBOX32) |
| 279 |
case INT64_REG_REG: { |
| 280 |
static const RValueAllocation::Layout layout = {PAYLOAD_GPR, PAYLOAD_GPR, |
| 281 |
"unpacked int64"}; |
| 282 |
return layout; |
| 283 |
} |
| 284 |
|
| 285 |
case INT64_REG_STACK: { |
| 286 |
static const RValueAllocation::Layout layout = { |
| 287 |
PAYLOAD_GPR, PAYLOAD_STACK_OFFSET, "unpacked int64"}; |
| 288 |
return layout; |
| 289 |
} |
| 290 |
|
| 291 |
case INT64_STACK_REG: { |
| 292 |
static const RValueAllocation::Layout layout = { |
| 293 |
PAYLOAD_STACK_OFFSET, PAYLOAD_GPR, "unpacked int64"}; |
| 294 |
return layout; |
| 295 |
} |
| 296 |
|
| 297 |
case INT64_STACK_STACK: { |
| 298 |
static const RValueAllocation::Layout layout = { |
| 299 |
PAYLOAD_STACK_OFFSET, PAYLOAD_STACK_OFFSET, "unpacked int64"}; |
| 300 |
return layout; |
| 301 |
} |
| 302 |
#elif defined(JS_PUNBOX64) |
| 303 |
case INT64_REG: { |
| 304 |
static const RValueAllocation::Layout layout = {PAYLOAD_GPR, PAYLOAD_NONE, |
| 305 |
"unpacked int64"}; |
| 306 |
return layout; |
| 307 |
} |
| 308 |
|
| 309 |
case INT64_STACK: { |
| 310 |
static const RValueAllocation::Layout layout = { |
| 311 |
PAYLOAD_STACK_OFFSET, PAYLOAD_NONE, "unpacked int64"}; |
| 312 |
return layout; |
| 313 |
} |
| 314 |
|
| 315 |
case INT64_INT32_STACK: { |
| 316 |
static const RValueAllocation::Layout layout = { |
| 317 |
PAYLOAD_STACK_OFFSET, PAYLOAD_NONE, "unpacked int64 (int32)"}; |
| 318 |
return layout; |
| 319 |
} |
| 320 |
#endif |
| 321 |
|
| 322 |
default: { |
| 323 |
static const RValueAllocation::Layout regLayout = { |
| 324 |
PAYLOAD_PACKED_TAG, PAYLOAD_GPR, "typed value"}; |
| 325 |
|
| 326 |
static const RValueAllocation::Layout stackLayout = { |
| 327 |
PAYLOAD_PACKED_TAG, PAYLOAD_STACK_OFFSET, "typed value"}; |
| 328 |
|
| 329 |
if (mode >= TYPED_REG_MIN && mode <= TYPED_REG_MAX) { |
| 330 |
return regLayout; |
| 331 |
} |
| 332 |
if (mode >= TYPED_STACK_MIN && mode <= TYPED_STACK_MAX) { |
| 333 |
return stackLayout; |
| 334 |
} |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
MOZ_CRASH_UNSAFE_PRINTF("Unexpected mode: 0x%x", uint32_t(mode)); |
| 339 |
} |
| 340 |
|
| 341 |
// Pad serialized RValueAllocations by a multiple of X bytes in the allocation |
| 342 |
// buffer. By padding serialized value allocations, we are building an |
| 343 |
// indexable table of elements of X bytes, and thus we can safely divide any |
| 344 |
// offset within the buffer by X to obtain an index. |
| 345 |
// |
| 346 |
// By padding, we are loosing space within the allocation buffer, but we |
| 347 |
// multiple by X the number of indexes that we can store on one byte in each |
| 348 |
// snapshots. |
| 349 |
// |
| 350 |
// Some value allocations are taking more than X bytes to be encoded, in which |
| 351 |
// case we will pad to a multiple of X, and we are wasting indexes. The choice |
| 352 |
// of X should be balanced between the wasted padding of serialized value |
| 353 |
// allocation, and the saving made in snapshot indexes. |
| 354 |
static const size_t ALLOCATION_TABLE_ALIGNMENT = 2; /* bytes */ |
| 355 |
|
| 356 |
void RValueAllocation::readPayload(CompactBufferReader& reader, |
| 357 |
PayloadType type, uint8_t* mode, |
| 358 |
Payload* p) { |
| 359 |
switch (type) { |
| 360 |
case PAYLOAD_NONE: |
| 361 |
break; |
| 362 |
case PAYLOAD_INDEX: |
| 363 |
p->index = reader.readUnsigned(); |
| 364 |
break; |
| 365 |
case PAYLOAD_STACK_OFFSET: |
| 366 |
p->stackOffset = reader.readSigned(); |
| 367 |
break; |
| 368 |
case PAYLOAD_GPR: |
| 369 |
p->gpr = Register::FromCode(reader.readByte()); |
| 370 |
break; |
| 371 |
case PAYLOAD_FPU: |
| 372 |
p->fpu.data = reader.readByte(); |
| 373 |
break; |
| 374 |
case PAYLOAD_PACKED_TAG: |
| 375 |
p->type = JSValueType(*mode & PACKED_TAG_MASK); |
| 376 |
*mode = *mode & ~PACKED_TAG_MASK; |
| 377 |
break; |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
RValueAllocation RValueAllocation::read(CompactBufferReader& reader) { |
| 382 |
uint8_t mode = reader.readByte(); |
| 383 |
const Layout& layout = layoutFromMode(Mode(mode & MODE_BITS_MASK)); |
| 384 |
Payload arg1, arg2; |
| 385 |
|
| 386 |
readPayload(reader, layout.type1, &mode, &arg1); |
| 387 |
readPayload(reader, layout.type2, &mode, &arg2); |
| 388 |
return RValueAllocation(Mode(mode), arg1, arg2); |
| 389 |
} |
| 390 |
|
| 391 |
void RValueAllocation::writePayload(CompactBufferWriter& writer, |
| 392 |
PayloadType type, Payload p) { |
| 393 |
switch (type) { |
| 394 |
case PAYLOAD_NONE: |
| 395 |
break; |
| 396 |
case PAYLOAD_INDEX: |
| 397 |
writer.writeUnsigned(p.index); |
| 398 |
break; |
| 399 |
case PAYLOAD_STACK_OFFSET: |
| 400 |
writer.writeSigned(p.stackOffset); |
| 401 |
break; |
| 402 |
case PAYLOAD_GPR: |
| 403 |
static_assert(Registers::Total <= 0x100, |
| 404 |
"Not enough bytes to encode all registers."); |
| 405 |
writer.writeByte(p.gpr.code()); |
| 406 |
break; |
| 407 |
case PAYLOAD_FPU: |
| 408 |
static_assert(FloatRegisters::Total <= 0x100, |
| 409 |
"Not enough bytes to encode all float registers."); |
| 410 |
writer.writeByte(p.fpu.code()); |
| 411 |
break; |
| 412 |
case PAYLOAD_PACKED_TAG: { |
| 413 |
// This code assumes that the PACKED_TAG payload is following the |
| 414 |
// writeByte of the mode. |
| 415 |
if (!writer.oom()) { |
| 416 |
MOZ_ASSERT(writer.length()); |
| 417 |
uint8_t* mode = writer.buffer() + (writer.length() - 1); |
| 418 |
MOZ_ASSERT((*mode & PACKED_TAG_MASK) == 0 && |
| 419 |
(p.type & ~PACKED_TAG_MASK) == 0); |
| 420 |
*mode = *mode | p.type; |
| 421 |
} |
| 422 |
break; |
| 423 |
} |
| 424 |
} |
| 425 |
} |
| 426 |
|
| 427 |
void RValueAllocation::writePadding(CompactBufferWriter& writer) { |
| 428 |
// Write 0x7f in all padding bytes. |
| 429 |
while (writer.length() % ALLOCATION_TABLE_ALIGNMENT) { |
| 430 |
writer.writeByte(0x7f); |
| 431 |
} |
| 432 |
} |
| 433 |
|
| 434 |
void RValueAllocation::write(CompactBufferWriter& writer) const { |
| 435 |
const Layout& layout = layoutFromMode(mode()); |
| 436 |
MOZ_ASSERT(layout.type2 != PAYLOAD_PACKED_TAG); |
| 437 |
MOZ_ASSERT(writer.length() % ALLOCATION_TABLE_ALIGNMENT == 0); |
| 438 |
|
| 439 |
writer.writeByte(mode_); |
| 440 |
writePayload(writer, layout.type1, arg1_); |
| 441 |
writePayload(writer, layout.type2, arg2_); |
| 442 |
writePadding(writer); |
| 443 |
} |
| 444 |
|
| 445 |
HashNumber RValueAllocation::hash() const { |
| 446 |
HashNumber res = 0; |
| 447 |
res = HashNumber(mode_); |
| 448 |
res = arg1_.index + (res << 6) + (res << 16) - res; |
| 449 |
res = arg2_.index + (res << 6) + (res << 16) - res; |
| 450 |
return res; |
| 451 |
} |
| 452 |
|
| 453 |
#ifdef JS_JITSPEW |
| 454 |
void RValueAllocation::dumpPayload(GenericPrinter& out, PayloadType type, |
| 455 |
Payload p) { |
| 456 |
switch (type) { |
| 457 |
case PAYLOAD_NONE: |
| 458 |
break; |
| 459 |
case PAYLOAD_INDEX: |
| 460 |
out.printf("index %u", p.index); |
| 461 |
break; |
| 462 |
case PAYLOAD_STACK_OFFSET: |
| 463 |
out.printf("stack %d", p.stackOffset); |
| 464 |
break; |
| 465 |
case PAYLOAD_GPR: |
| 466 |
out.printf("reg %s", p.gpr.name()); |
| 467 |
break; |
| 468 |
case PAYLOAD_FPU: |
| 469 |
out.printf("reg %s", p.fpu.name()); |
| 470 |
break; |
| 471 |
case PAYLOAD_PACKED_TAG: |
| 472 |
out.printf("%s", ValTypeToString(p.type)); |
| 473 |
break; |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
void RValueAllocation::dump(GenericPrinter& out) const { |
| 478 |
const Layout& layout = layoutFromMode(mode()); |
| 479 |
out.printf("%s", layout.name); |
| 480 |
|
| 481 |
if (layout.type1 != PAYLOAD_NONE) { |
| 482 |
out.printf(" ("); |
| 483 |
} |
| 484 |
dumpPayload(out, layout.type1, arg1_); |
| 485 |
if (layout.type2 != PAYLOAD_NONE) { |
| 486 |
out.printf(", "); |
| 487 |
} |
| 488 |
dumpPayload(out, layout.type2, arg2_); |
| 489 |
if (layout.type1 != PAYLOAD_NONE) { |
| 490 |
out.printf(")"); |
| 491 |
} |
| 492 |
} |
| 493 |
#endif // JS_JITSPEW |
| 494 |
|
| 495 |
SnapshotReader::SnapshotReader(const uint8_t* snapshots, uint32_t offset, |
| 496 |
uint32_t RVATableSize, uint32_t listSize) |
| 497 |
: reader_(snapshots + offset, snapshots + listSize), |
| 498 |
allocReader_(snapshots + listSize, snapshots + listSize + RVATableSize), |
| 499 |
allocTable_(snapshots + listSize), |
| 500 |
allocRead_(0) { |
| 501 |
if (!snapshots) { |
| 502 |
return; |
| 503 |
} |
| 504 |
JitSpew(JitSpew_IonSnapshots, "Creating snapshot reader"); |
| 505 |
readSnapshotHeader(); |
| 506 |
} |
| 507 |
|
| 508 |
#define COMPUTE_SHIFT_AFTER_(name) (name##_BITS + name##_SHIFT) |
| 509 |
#define COMPUTE_MASK_(name) (((uint64_t(1) << name##_BITS) - 1) << name##_SHIFT) |
| 510 |
|
| 511 |
// Details of snapshot header packing. |
| 512 |
static const uint32_t SNAPSHOT_BAILOUTKIND_SHIFT = 0; |
| 513 |
static const uint32_t SNAPSHOT_BAILOUTKIND_BITS = 6; |
| 514 |
static const uint64_t SNAPSHOT_BAILOUTKIND_MASK = |
| 515 |
COMPUTE_MASK_(SNAPSHOT_BAILOUTKIND); |
| 516 |
|
| 517 |
static_assert((1 << SNAPSHOT_BAILOUTKIND_BITS) - 1 >= |
| 518 |
uint8_t(BailoutKind::Limit), |
| 519 |
"Not enough bits for BailoutKinds"); |
| 520 |
|
| 521 |
static const uint32_t SNAPSHOT_ROFFSET_SHIFT = |
| 522 |
COMPUTE_SHIFT_AFTER_(SNAPSHOT_BAILOUTKIND); |
| 523 |
static const uint32_t SNAPSHOT_ROFFSET_BITS = 64 - SNAPSHOT_ROFFSET_SHIFT; |
| 524 |
static const uint64_t SNAPSHOT_ROFFSET_MASK = COMPUTE_MASK_(SNAPSHOT_ROFFSET); |
| 525 |
|
| 526 |
#undef COMPUTE_MASK_ |
| 527 |
#undef COMPUTE_SHIFT_AFTER_ |
| 528 |
|
| 529 |
void SnapshotReader::readSnapshotHeader() { |
| 530 |
uint64_t bits = reader_.readUnsigned64(); |
| 531 |
|
| 532 |
bailoutKind_ = BailoutKind((bits & SNAPSHOT_BAILOUTKIND_MASK) >> |
| 533 |
SNAPSHOT_BAILOUTKIND_SHIFT); |
| 534 |
recoverOffset_ = (bits & SNAPSHOT_ROFFSET_MASK) >> SNAPSHOT_ROFFSET_SHIFT; |
| 535 |
|
| 536 |
JitSpew(JitSpew_IonSnapshots, "Read snapshot header with bailout kind %u", |
| 537 |
uint32_t(bailoutKind_)); |
| 538 |
|
| 539 |
#ifdef TRACK_SNAPSHOTS |
| 540 |
readTrackSnapshot(); |
| 541 |
#endif |
| 542 |
} |
| 543 |
|
| 544 |
#ifdef TRACK_SNAPSHOTS |
| 545 |
void SnapshotReader::readTrackSnapshot() { |
| 546 |
pcOpcode_ = reader_.readUnsigned(); |
| 547 |
mirOpcode_ = reader_.readUnsigned(); |
| 548 |
mirId_ = reader_.readUnsigned(); |
| 549 |
lirOpcode_ = reader_.readUnsigned(); |
| 550 |
lirId_ = reader_.readUnsigned(); |
| 551 |
} |
| 552 |
|
| 553 |
void SnapshotReader::spewBailingFrom() const { |
| 554 |
# ifdef JS_JITSPEW |
| 555 |
if (JitSpewEnabled(JitSpew_IonBailouts)) { |
| 556 |
JitSpewHeader(JitSpew_IonBailouts); |
| 557 |
Fprinter& out = JitSpewPrinter(); |
| 558 |
out.printf(" bailing from bytecode: %s, MIR: ", CodeName(JSOp(pcOpcode_))); |
| 559 |
MDefinition::PrintOpcodeName(out, MDefinition::Opcode(mirOpcode_)); |
| 560 |
out.printf(" [%u], LIR: ", mirId_); |
| 561 |
LInstruction::printName(out, LInstruction::Opcode(lirOpcode_)); |
| 562 |
out.printf(" [%u]", lirId_); |
| 563 |
out.printf("\n"); |
| 564 |
} |
| 565 |
# endif |
| 566 |
} |
| 567 |
#endif |
| 568 |
|
| 569 |
uint32_t SnapshotReader::readAllocationIndex() { |
| 570 |
allocRead_++; |
| 571 |
return reader_.readUnsigned(); |
| 572 |
} |
| 573 |
|
| 574 |
RValueAllocation SnapshotReader::readAllocation() { |
| 575 |
JitSpew(JitSpew_IonSnapshots, "Reading slot %u", allocRead_); |
| 576 |
uint32_t offset = readAllocationIndex() * ALLOCATION_TABLE_ALIGNMENT; |
| 577 |
allocReader_.seek(allocTable_, offset); |
| 578 |
return RValueAllocation::read(allocReader_); |
| 579 |
} |
| 580 |
|
| 581 |
SnapshotWriter::SnapshotWriter() |
| 582 |
// Based on the measurements made in Bug 962555 comment 20, this length |
| 583 |
// should be enough to prevent the reallocation of the hash table for at |
| 584 |
// least half of the compilations. |
| 585 |
: allocMap_(32) {} |
| 586 |
|
| 587 |
RecoverReader::RecoverReader(SnapshotReader& snapshot, const uint8_t* recovers, |
| 588 |
uint32_t size) |
| 589 |
: reader_(nullptr, nullptr), numInstructions_(0), numInstructionsRead_(0) { |
| 590 |
if (!recovers) { |
| 591 |
return; |
| 592 |
} |
| 593 |
reader_ = |
| 594 |
CompactBufferReader(recovers + snapshot.recoverOffset(), recovers + size); |
| 595 |
readRecoverHeader(); |
| 596 |
readInstruction(); |
| 597 |
} |
| 598 |
|
| 599 |
RecoverReader::RecoverReader(const RecoverReader& rr) |
| 600 |
: reader_(rr.reader_), |
| 601 |
numInstructions_(rr.numInstructions_), |
| 602 |
numInstructionsRead_(rr.numInstructionsRead_) { |
| 603 |
if (reader_.currentPosition()) { |
| 604 |
rr.instruction()->cloneInto(&rawData_); |
| 605 |
} |
| 606 |
} |
| 607 |
|
| 608 |
RecoverReader& RecoverReader::operator=(const RecoverReader& rr) { |
| 609 |
reader_ = rr.reader_; |
| 610 |
numInstructions_ = rr.numInstructions_; |
| 611 |
numInstructionsRead_ = rr.numInstructionsRead_; |
| 612 |
if (reader_.currentPosition()) { |
| 613 |
rr.instruction()->cloneInto(&rawData_); |
| 614 |
} |
| 615 |
return *this; |
| 616 |
} |
| 617 |
|
| 618 |
void RecoverReader::readRecoverHeader() { |
| 619 |
numInstructions_ = reader_.readUnsigned(); |
| 620 |
MOZ_ASSERT(numInstructions_); |
| 621 |
|
| 622 |
JitSpew(JitSpew_IonSnapshots, "Read recover header with instructionCount %u", |
| 623 |
numInstructions_); |
| 624 |
} |
| 625 |
|
| 626 |
void RecoverReader::readInstruction() { |
| 627 |
MOZ_ASSERT(moreInstructions()); |
| 628 |
RInstruction::readRecoverData(reader_, &rawData_); |
| 629 |
numInstructionsRead_++; |
| 630 |
} |
| 631 |
|
| 632 |
SnapshotOffset SnapshotWriter::startSnapshot(RecoverOffset recoverOffset, |
| 633 |
BailoutKind kind) { |
| 634 |
lastStart_ = writer_.length(); |
| 635 |
allocWritten_ = 0; |
| 636 |
|
| 637 |
JitSpew(JitSpew_IonSnapshots, |
| 638 |
"starting snapshot with recover offset %" PRIu64 ", bailout kind %u", |
| 639 |
recoverOffset, uint32_t(kind)); |
| 640 |
|
| 641 |
MOZ_ASSERT(uint64_t(kind) < (uint64_t(1) << SNAPSHOT_BAILOUTKIND_BITS)); |
| 642 |
MOZ_ASSERT(recoverOffset < (RecoverOffset(1) << SNAPSHOT_ROFFSET_BITS)); |
| 643 |
uint64_t bits = (uint64_t(kind) << SNAPSHOT_BAILOUTKIND_SHIFT) | |
| 644 |
(recoverOffset << SNAPSHOT_ROFFSET_SHIFT); |
| 645 |
|
| 646 |
writer_.writeUnsigned64(bits); |
| 647 |
return lastStart_; |
| 648 |
} |
| 649 |
|
| 650 |
#ifdef TRACK_SNAPSHOTS |
| 651 |
void SnapshotWriter::trackSnapshot(uint32_t pcOpcode, uint32_t mirOpcode, |
| 652 |
uint32_t mirId, uint32_t lirOpcode, |
| 653 |
uint32_t lirId) { |
| 654 |
writer_.writeUnsigned(pcOpcode); |
| 655 |
writer_.writeUnsigned(mirOpcode); |
| 656 |
writer_.writeUnsigned(mirId); |
| 657 |
writer_.writeUnsigned(lirOpcode); |
| 658 |
writer_.writeUnsigned(lirId); |
| 659 |
} |
| 660 |
#endif |
| 661 |
|
| 662 |
bool SnapshotWriter::add(const RValueAllocation& alloc) { |
| 663 |
uint32_t offset; |
| 664 |
RValueAllocMap::AddPtr p = allocMap_.lookupForAdd(alloc); |
| 665 |
if (!p) { |
| 666 |
offset = allocWriter_.length(); |
| 667 |
alloc.write(allocWriter_); |
| 668 |
if (!allocMap_.add(p, alloc, offset)) { |
| 669 |
allocWriter_.setOOM(); |
| 670 |
return false; |
| 671 |
} |
| 672 |
} else { |
| 673 |
offset = p->value(); |
| 674 |
} |
| 675 |
|
| 676 |
#ifdef JS_JITSPEW |
| 677 |
if (JitSpewEnabled(JitSpew_IonSnapshots)) { |
| 678 |
JitSpewHeader(JitSpew_IonSnapshots); |
| 679 |
Fprinter& out = JitSpewPrinter(); |
| 680 |
out.printf(" slot %u (%u): ", allocWritten_, offset); |
| 681 |
alloc.dump(out); |
| 682 |
out.printf("\n"); |
| 683 |
} |
| 684 |
#endif |
| 685 |
|
| 686 |
allocWritten_++; |
| 687 |
writer_.writeUnsigned(offset / ALLOCATION_TABLE_ALIGNMENT); |
| 688 |
return true; |
| 689 |
} |
| 690 |
|
| 691 |
void SnapshotWriter::endSnapshot() { |
| 692 |
// Place a sentinel for asserting on the other end. |
| 693 |
#ifdef DEBUG |
| 694 |
writer_.writeSigned(-1); |
| 695 |
#endif |
| 696 |
|
| 697 |
JitSpew(JitSpew_IonSnapshots, |
| 698 |
"ending snapshot total size: %u bytes (start %u)", |
| 699 |
uint32_t(writer_.length() - lastStart_), lastStart_); |
| 700 |
} |
| 701 |
|
| 702 |
RecoverOffset RecoverWriter::startRecover(uint32_t instructionCount) { |
| 703 |
MOZ_ASSERT(instructionCount); |
| 704 |
instructionCount_ = instructionCount; |
| 705 |
instructionsWritten_ = 0; |
| 706 |
|
| 707 |
JitSpew(JitSpew_IonSnapshots, "starting recover with %u instruction(s)", |
| 708 |
instructionCount); |
| 709 |
|
| 710 |
RecoverOffset recoverOffset = writer_.length(); |
| 711 |
writer_.writeUnsigned(instructionCount); |
| 712 |
return recoverOffset; |
| 713 |
} |
| 714 |
|
| 715 |
void RecoverWriter::writeInstruction(const MNode* rp) { |
| 716 |
if (!rp->writeRecoverData(writer_)) { |
| 717 |
writer_.setOOM(); |
| 718 |
} |
| 719 |
instructionsWritten_++; |
| 720 |
} |
| 721 |
|
| 722 |
void RecoverWriter::endRecover() { |
| 723 |
MOZ_ASSERT(instructionCount_ == instructionsWritten_); |
| 724 |
} |