OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #include "src/interpreter/bytecode-array-writer.h" | 5 #include "src/interpreter/bytecode-array-writer.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/interpreter/bytecode-label.h" | 8 #include "src/interpreter/bytecode-label.h" |
9 #include "src/interpreter/bytecode-register.h" | 9 #include "src/interpreter/bytecode-register.h" |
10 #include "src/interpreter/constant-array-builder.h" | 10 #include "src/interpreter/constant-array-builder.h" |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 Bytecode jump_bytecode = Bytecodes::FromByte(bytecodes()->at(jump_location)); | 247 Bytecode jump_bytecode = Bytecodes::FromByte(bytecodes()->at(jump_location)); |
248 DCHECK(Bytecodes::IsJumpImmediate(jump_bytecode)); | 248 DCHECK(Bytecodes::IsJumpImmediate(jump_bytecode)); |
249 size_t operand_location = jump_location + 1; | 249 size_t operand_location = jump_location + 1; |
250 DCHECK_EQ(bytecodes()->at(operand_location), k8BitJumpPlaceholder); | 250 DCHECK_EQ(bytecodes()->at(operand_location), k8BitJumpPlaceholder); |
251 if (Bytecodes::SizeForSignedOperand(delta) == OperandSize::kByte) { | 251 if (Bytecodes::SizeForSignedOperand(delta) == OperandSize::kByte) { |
252 // The jump fits within the range of an Imm operand, so cancel | 252 // The jump fits within the range of an Imm operand, so cancel |
253 // the reservation and jump directly. | 253 // the reservation and jump directly. |
254 constant_array_builder()->DiscardReservedEntry(OperandSize::kByte); | 254 constant_array_builder()->DiscardReservedEntry(OperandSize::kByte); |
255 bytecodes()->at(operand_location) = static_cast<uint8_t>(delta); | 255 bytecodes()->at(operand_location) = static_cast<uint8_t>(delta); |
256 } else { | 256 } else { |
257 // TODO(5203): Remove this temporary exception. | |
258 AllowHandleAllocation allow_handles; | |
259 // The jump does not fit within the range of an Imm operand, so | 257 // The jump does not fit within the range of an Imm operand, so |
260 // commit reservation putting the offset into the constant pool, | 258 // commit reservation putting the offset into the constant pool, |
261 // and update the jump instruction and operand. | 259 // and update the jump instruction and operand. |
262 size_t entry = constant_array_builder()->CommitReservedEntry( | 260 size_t entry = constant_array_builder()->CommitReservedEntry( |
263 OperandSize::kByte, handle(Smi::FromInt(delta), isolate())); | 261 OperandSize::kByte, Smi::FromInt(delta)); |
264 DCHECK_LE(entry, kMaxUInt32); | 262 DCHECK_LE(entry, kMaxUInt32); |
265 DCHECK_EQ(Bytecodes::SizeForUnsignedOperand(static_cast<uint32_t>(entry)), | 263 DCHECK_EQ(Bytecodes::SizeForUnsignedOperand(static_cast<uint32_t>(entry)), |
266 OperandSize::kByte); | 264 OperandSize::kByte); |
267 jump_bytecode = GetJumpWithConstantOperand(jump_bytecode); | 265 jump_bytecode = GetJumpWithConstantOperand(jump_bytecode); |
268 bytecodes()->at(jump_location) = Bytecodes::ToByte(jump_bytecode); | 266 bytecodes()->at(jump_location) = Bytecodes::ToByte(jump_bytecode); |
269 bytecodes()->at(operand_location) = static_cast<uint8_t>(entry); | 267 bytecodes()->at(operand_location) = static_cast<uint8_t>(entry); |
270 } | 268 } |
271 } | 269 } |
272 | 270 |
273 void BytecodeArrayWriter::PatchJumpWith16BitOperand(size_t jump_location, | 271 void BytecodeArrayWriter::PatchJumpWith16BitOperand(size_t jump_location, |
274 int delta) { | 272 int delta) { |
275 Bytecode jump_bytecode = Bytecodes::FromByte(bytecodes()->at(jump_location)); | 273 Bytecode jump_bytecode = Bytecodes::FromByte(bytecodes()->at(jump_location)); |
276 DCHECK(Bytecodes::IsJumpImmediate(jump_bytecode)); | 274 DCHECK(Bytecodes::IsJumpImmediate(jump_bytecode)); |
277 size_t operand_location = jump_location + 1; | 275 size_t operand_location = jump_location + 1; |
278 uint8_t operand_bytes[2]; | 276 uint8_t operand_bytes[2]; |
279 if (Bytecodes::SizeForSignedOperand(delta) <= OperandSize::kShort) { | 277 if (Bytecodes::SizeForSignedOperand(delta) <= OperandSize::kShort) { |
280 constant_array_builder()->DiscardReservedEntry(OperandSize::kShort); | 278 constant_array_builder()->DiscardReservedEntry(OperandSize::kShort); |
281 WriteUnalignedUInt16(operand_bytes, static_cast<uint16_t>(delta)); | 279 WriteUnalignedUInt16(operand_bytes, static_cast<uint16_t>(delta)); |
282 } else { | 280 } else { |
283 // TODO(5203): Remove this temporary exception. | |
284 AllowHandleAllocation allow_handles; | |
285 jump_bytecode = GetJumpWithConstantOperand(jump_bytecode); | 281 jump_bytecode = GetJumpWithConstantOperand(jump_bytecode); |
286 bytecodes()->at(jump_location) = Bytecodes::ToByte(jump_bytecode); | 282 bytecodes()->at(jump_location) = Bytecodes::ToByte(jump_bytecode); |
287 size_t entry = constant_array_builder()->CommitReservedEntry( | 283 size_t entry = constant_array_builder()->CommitReservedEntry( |
288 OperandSize::kShort, handle(Smi::FromInt(delta), isolate())); | 284 OperandSize::kShort, Smi::FromInt(delta)); |
289 WriteUnalignedUInt16(operand_bytes, static_cast<uint16_t>(entry)); | 285 WriteUnalignedUInt16(operand_bytes, static_cast<uint16_t>(entry)); |
290 } | 286 } |
291 DCHECK(bytecodes()->at(operand_location) == k8BitJumpPlaceholder && | 287 DCHECK(bytecodes()->at(operand_location) == k8BitJumpPlaceholder && |
292 bytecodes()->at(operand_location + 1) == k8BitJumpPlaceholder); | 288 bytecodes()->at(operand_location + 1) == k8BitJumpPlaceholder); |
293 bytecodes()->at(operand_location++) = operand_bytes[0]; | 289 bytecodes()->at(operand_location++) = operand_bytes[0]; |
294 bytecodes()->at(operand_location) = operand_bytes[1]; | 290 bytecodes()->at(operand_location) = operand_bytes[1]; |
295 } | 291 } |
296 | 292 |
297 void BytecodeArrayWriter::PatchJumpWith32BitOperand(size_t jump_location, | 293 void BytecodeArrayWriter::PatchJumpWith32BitOperand(size_t jump_location, |
298 int delta) { | 294 int delta) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 node->set_bytecode(node->bytecode(), k32BitJumpPlaceholder); | 384 node->set_bytecode(node->bytecode(), k32BitJumpPlaceholder); |
389 break; | 385 break; |
390 } | 386 } |
391 } | 387 } |
392 EmitBytecode(node); | 388 EmitBytecode(node); |
393 } | 389 } |
394 | 390 |
395 } // namespace interpreter | 391 } // namespace interpreter |
396 } // namespace internal | 392 } // namespace internal |
397 } // namespace v8 | 393 } // namespace v8 |
OLD | NEW |