1 | /* |
2 | * Copyright (C) 2009-2018 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | |
28 | #include "BatchedTransitionOptimizer.h" |
29 | #include "CodeBlock.h" |
30 | #include "Debugger.h" |
31 | #include "EvalCodeBlock.h" |
32 | #include "FunctionCodeBlock.h" |
33 | #include "JIT.h" |
34 | #include "JSCInlines.h" |
35 | #include "LLIntEntrypoint.h" |
36 | #include "ModuleProgramCodeBlock.h" |
37 | #include "Parser.h" |
38 | #include "ProgramCodeBlock.h" |
39 | #include "TypeProfiler.h" |
40 | #include "VMInlines.h" |
41 | #include <wtf/CommaPrinter.h> |
42 | |
43 | namespace JSC { |
44 | |
45 | const ClassInfo ExecutableBase::s_info = { "Executable" , nullptr, nullptr, nullptr, CREATE_METHOD_TABLE(ExecutableBase) }; |
46 | |
47 | void ExecutableBase::destroy(JSCell* cell) |
48 | { |
49 | static_cast<ExecutableBase*>(cell)->ExecutableBase::~ExecutableBase(); |
50 | } |
51 | |
52 | void ExecutableBase::dump(PrintStream& out) const |
53 | { |
54 | ExecutableBase* realThis = const_cast<ExecutableBase*>(this); |
55 | |
56 | switch (type()) { |
57 | case NativeExecutableType: { |
58 | NativeExecutable* native = jsCast<NativeExecutable*>(realThis); |
59 | out.print("NativeExecutable:" , RawPointer(bitwise_cast<void*>(native->function())), "/" , RawPointer(bitwise_cast<void*>(native->constructor()))); |
60 | return; |
61 | } |
62 | case EvalExecutableType: { |
63 | EvalExecutable* eval = jsCast<EvalExecutable*>(realThis); |
64 | if (CodeBlock* codeBlock = eval->codeBlock()) |
65 | out.print(*codeBlock); |
66 | else |
67 | out.print("EvalExecutable w/o CodeBlock" ); |
68 | return; |
69 | } |
70 | case ProgramExecutableType: { |
71 | ProgramExecutable* eval = jsCast<ProgramExecutable*>(realThis); |
72 | if (CodeBlock* codeBlock = eval->codeBlock()) |
73 | out.print(*codeBlock); |
74 | else |
75 | out.print("ProgramExecutable w/o CodeBlock" ); |
76 | return; |
77 | } |
78 | case ModuleProgramExecutableType: { |
79 | ModuleProgramExecutable* executable = jsCast<ModuleProgramExecutable*>(realThis); |
80 | if (CodeBlock* codeBlock = executable->codeBlock()) |
81 | out.print(*codeBlock); |
82 | else |
83 | out.print("ModuleProgramExecutable w/o CodeBlock" ); |
84 | return; |
85 | } |
86 | case FunctionExecutableType: { |
87 | FunctionExecutable* function = jsCast<FunctionExecutable*>(realThis); |
88 | if (!function->eitherCodeBlock()) |
89 | out.print("FunctionExecutable w/o CodeBlock" ); |
90 | else { |
91 | CommaPrinter comma("/" ); |
92 | if (function->codeBlockForCall()) |
93 | out.print(comma, *function->codeBlockForCall()); |
94 | if (function->codeBlockForConstruct()) |
95 | out.print(comma, *function->codeBlockForConstruct()); |
96 | } |
97 | return; |
98 | } |
99 | default: |
100 | RELEASE_ASSERT_NOT_REACHED(); |
101 | } |
102 | } |
103 | |
104 | CodeBlockHash ExecutableBase::hashFor(CodeSpecializationKind kind) const |
105 | { |
106 | if (type() == NativeExecutableType) |
107 | return jsCast<const NativeExecutable*>(this)->hashFor(kind); |
108 | |
109 | return jsCast<const ScriptExecutable*>(this)->hashFor(kind); |
110 | } |
111 | |
112 | } // namespace JSC |
113 | |