1 | /* |
2 | * Copyright (C) 2016 Yusuke Suzuki <[email protected]> |
3 | * Copyright (C) 2016-2018 Apple Inc. All rights reserved. |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * |
14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | */ |
26 | |
27 | #pragma once |
28 | |
29 | #include "CallFrameClosure.h" |
30 | #include "Exception.h" |
31 | #include "Instruction.h" |
32 | #include "Interpreter.h" |
33 | #include "JSCPtrTag.h" |
34 | #include "LLIntData.h" |
35 | #include "UnlinkedCodeBlock.h" |
36 | #include <wtf/UnalignedAccess.h> |
37 | |
38 | namespace JSC { |
39 | |
40 | inline Opcode Interpreter::getOpcode(OpcodeID id) |
41 | { |
42 | return LLInt::getOpcode(id); |
43 | } |
44 | |
45 | inline OpcodeID Interpreter::getOpcodeID(Opcode opcode) |
46 | { |
47 | #if ENABLE(COMPUTED_GOTO_OPCODES) |
48 | ASSERT(isOpcode(opcode)); |
49 | #if USE(LLINT_EMBEDDED_OPCODE_ID) |
50 | // The OpcodeID is embedded in the int32_t word preceding the location of |
51 | // the LLInt code for the opcode (see the EMBED_OPCODE_ID_IF_NEEDED macro |
52 | // in LowLevelInterpreter.cpp). |
53 | auto codePtr = MacroAssemblerCodePtr<BytecodePtrTag>::createFromExecutableAddress(opcode); |
54 | int32_t* opcodeIDAddress = codePtr.dataLocation<int32_t*>() - 1; |
55 | OpcodeID opcodeID = static_cast<OpcodeID>(WTF::unalignedLoad<int32_t>(opcodeIDAddress)); |
56 | ASSERT(opcodeID < NUMBER_OF_BYTECODE_IDS); |
57 | return opcodeID; |
58 | #else |
59 | return opcodeIDTable().get(opcode); |
60 | #endif // USE(LLINT_EMBEDDED_OPCODE_ID) |
61 | |
62 | #else // not ENABLE(COMPUTED_GOTO_OPCODES) |
63 | return opcode; |
64 | #endif |
65 | } |
66 | |
67 | ALWAYS_INLINE JSValue Interpreter::execute(CallFrameClosure& closure) |
68 | { |
69 | VM& vm = *closure.vm; |
70 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
71 | |
72 | ASSERT(!vm.isCollectorBusyOnCurrentThread()); |
73 | ASSERT(vm.currentThreadIsHoldingAPILock()); |
74 | |
75 | StackStats::CheckPoint stackCheckPoint; |
76 | |
77 | VMTraps::Mask mask(VMTraps::NeedTermination, VMTraps::NeedWatchdogCheck); |
78 | if (UNLIKELY(vm.needTrapHandling(mask))) { |
79 | vm.handleTraps(closure.oldCallFrame, mask); |
80 | RETURN_IF_EXCEPTION(throwScope, throwScope.exception()); |
81 | } |
82 | |
83 | // Execute the code: |
84 | throwScope.release(); |
85 | JSValue result = closure.functionExecutable->generatedJITCodeForCall()->execute(&vm, closure.protoCallFrame); |
86 | |
87 | return checkedReturn(result); |
88 | } |
89 | |
90 | } // namespace JSC |
91 | |