• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2024 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Contains tables related to the v8 (Javasrcript Engine) Datasource.
15
16These tables are WIP, the schema is not stable and you should not rely on them
17for any serious business just yet""
18"""
19
20from python.generators.trace_processor_table.public import Alias
21from python.generators.trace_processor_table.public import Column as C
22from python.generators.trace_processor_table.public import ColumnDoc
23from python.generators.trace_processor_table.public import CppInt32
24from python.generators.trace_processor_table.public import CppInt64
25from python.generators.trace_processor_table.public import CppOptional
26from python.generators.trace_processor_table.public import CppString
27from python.generators.trace_processor_table.public import CppTableId
28from python.generators.trace_processor_table.public import CppUint32
29from python.generators.trace_processor_table.public import CppUint32 as CppBool
30from python.generators.trace_processor_table.public import Table
31from python.generators.trace_processor_table.public import TableDoc
32from .jit_tables import JIT_CODE_TABLE
33
34V8_ISOLATE = Table(
35    python_module=__file__,
36    class_name='V8IsolateTable',
37    sql_name='__intrinsic_v8_isolate',
38    columns=[
39        C('upid', CppUint32()),
40        C('internal_isolate_id', CppInt32()),
41        C('embedded_blob_code_start_address', CppInt64()),
42        C('embedded_blob_code_size', CppInt64()),
43        C('code_range_base_address', CppOptional(CppInt64())),
44        C('code_range_size', CppOptional(CppInt64())),
45        C('shared_code_range', CppOptional(CppBool())),
46        C('embedded_blob_code_copy_start_address', CppOptional(CppInt64())),
47    ],
48    tabledoc=TableDoc(
49        doc='Represents one Isolate instance',
50        group='v8',
51        columns={
52            'upid':
53                'Process the isolate was created in.',
54            'internal_isolate_id':
55                'Internal id used by the v8 engine. Unique in a process.',
56            'embedded_blob_code_start_address':
57                'Absolute start address of the embedded code blob.',
58            'embedded_blob_code_size':
59                'Size in bytes of the embedded code blob.',
60            'code_range_base_address':
61                'If this Isolate defines a CodeRange its base address is stored'
62                ' here',
63            'code_range_size':
64                'If this Isolate defines a CodeRange its size is stored here',
65            'shared_code_range':
66                'Whether the code range for this Isolate is shared with others'
67                ' in the same process. There is at max one such shared code'
68                ' range per process.',
69            'embedded_blob_code_copy_start_address':
70                'Used when short builtin calls are enabled, where embedded'
71                ' builtins are copied into the CodeRange so calls can be'
72                ' nearer.',
73        },
74    ),
75)
76
77V8_JS_SCRIPT = Table(
78    python_module=__file__,
79    class_name='V8JsScriptTable',
80    sql_name='__intrinsic_v8_js_script',
81    columns=[
82        C('v8_isolate_id', CppTableId(V8_ISOLATE)),
83        C('internal_script_id', CppInt32()),
84        C('script_type', CppString()),
85        C('name', CppString()),
86        C('source', CppOptional(CppString())),
87    ],
88    tabledoc=TableDoc(
89        doc='Represents one Javascript script',
90        group='v8',
91        columns={
92            'v8_isolate_id': 'V8 Isolate',
93            'internal_script_id': 'Script id used by the V8 engine',
94            'script_type': '',
95            'name': '',
96            'source': 'Actual contents of the script.',
97        },
98    ),
99)
100
101V8_WASM_SCRIPT = Table(
102    python_module=__file__,
103    class_name='V8WasmScriptTable',
104    sql_name='__intrinsic_v8_wasm_script',
105    columns=[
106        C('v8_isolate_id', CppTableId(V8_ISOLATE)),
107        C('internal_script_id', CppInt32()),
108        C('url', CppString()),
109        C('source', CppOptional(CppString())),
110    ],
111    tabledoc=TableDoc(
112        doc='Represents one WASM script',
113        group='v8',
114        columns={
115            'v8_isolate_id': 'V8 Isolate',
116            'internal_script_id': 'Script id used by the V8 engine',
117            'url': 'URL of the source',
118            'source': 'Actual contents of the script.',
119        },
120    ),
121)
122
123V8_JS_FUNCTION = Table(
124    python_module=__file__,
125    class_name='V8JsFunctionTable',
126    sql_name='__intrinsic_v8_js_function',
127    columns=[
128        C('name', CppString()),
129        C('v8_js_script_id', CppTableId(V8_JS_SCRIPT)),
130        C('is_toplevel', CppBool()),
131        C('kind', CppString()),
132        C('line', CppOptional(CppUint32())),
133        C('col', CppOptional(CppUint32())),
134    ],
135    tabledoc=TableDoc(
136        doc='Represents a v8 Javascript function',
137        group='v8',
138        columns={
139            'name':
140                '',
141            'v8_js_script_id':
142                ColumnDoc(
143                    doc='Script where the function is defined.',
144                    joinable='v8_js_script.id',
145                ),
146            'is_toplevel':
147                'Whether this function represents the top level script',
148            'kind':
149                'Function kind (e.g. regular function or constructor)',
150            'line':
151                'Line in script where function is defined. Starts at 1',
152            'col':
153                'Column in script where function is defined. Starts at 1',
154        },
155    ),
156)
157
158V8_JS_CODE = Table(
159    python_module=__file__,
160    class_name='V8JsCodeTable',
161    sql_name='__intrinsic_v8_js_code',
162    columns=[
163        C('jit_code_id', CppOptional(CppTableId(JIT_CODE_TABLE))),
164        C('v8_js_function_id', CppTableId(V8_JS_FUNCTION)),
165        C('tier', CppString()),
166        C('bytecode_base64', CppOptional(CppString())),
167    ],
168    tabledoc=TableDoc(
169        doc="""
170          Represents a v8 code snippet for a Javascript function. A given
171          function can have multiple code snippets (e.g. for different
172          compilation tiers, or as the function moves around the heap)
173        """,
174        group='v8',
175        columns={
176            'jit_code_id':
177                ColumnDoc(
178                    doc="""
179                  Set for all tiers except IGNITION.
180                    """,
181                    joinable='__intrinsic_jit_code.id',
182                ),
183            'v8_js_function_id':
184                ColumnDoc(
185                    doc='JS function for this snippet.',
186                    joinable='__intrinsic_v8_js_function.id',
187                ),
188            'tier':
189                'Compilation tier',
190            'bytecode_base64':
191                'Set only for the IGNITION tier (base64 encoded)',
192        },
193    ),
194)
195
196V8_INTERNAL_CODE = Table(
197    python_module=__file__,
198    class_name='V8InternalCodeTable',
199    sql_name='__intrinsic_v8_internal_code',
200    columns=[
201        C('jit_code_id', CppTableId(JIT_CODE_TABLE)),
202        C('v8_isolate_id', CppTableId(V8_ISOLATE)),
203        C('function_name', CppString()),
204        C('code_type', CppString()),
205    ],
206    tabledoc=TableDoc(
207        doc="""
208          Represents a v8 code snippet for a v8 internal function.
209        """,
210        group='v8',
211        columns={
212            'jit_code_id':
213                ColumnDoc(
214                    doc='Associated JitCode.',
215                    joinable='__intrinsic_jit_code.id',
216                ),
217            'v8_isolate_id':
218                ColumnDoc(
219                    doc="""
220                  V8 Isolate this code was created in.
221                    """,
222                    joinable='__intrinsic_v8_isolate.id'),
223            'function_name':
224                'Function name.',
225            'code_type':
226                'Type of internal function (e.g. BYTECODE_HANDLER, BUILTIN)',
227        },
228    ),
229)
230
231V8_WASM_CODE = Table(
232    python_module=__file__,
233    class_name='V8WasmCodeTable',
234    sql_name='__intrinsic_v8_wasm_code',
235    columns=[
236        C('jit_code_id', CppTableId(JIT_CODE_TABLE)),
237        C('v8_isolate_id', CppTableId(V8_ISOLATE)),
238        C('v8_wasm_script_id', CppTableId(V8_WASM_SCRIPT)),
239        C('function_name', CppString()),
240        C('tier', CppString()),
241        C('code_offset_in_module', CppInt32()),
242    ],
243    tabledoc=TableDoc(
244        doc="""
245          Represents the code associated to a WASM function
246        """,
247        group='v8',
248        columns={
249            'jit_code_id':
250                ColumnDoc(
251                    doc='Associated JitCode.',
252                    joinable='__intrinsic_jit_code.id',
253                ),
254            'v8_isolate_id':
255                ColumnDoc(
256                    doc="""
257                  V8 Isolate this code was created in.
258                    """,
259                    joinable='__intrinsic_v8_isolate.id'),
260            'v8_wasm_script_id':
261                ColumnDoc(
262                    doc="""
263                  Script where the function is defined.
264                    """,
265                    joinable='v8_wasm_script.id',
266                ),
267            'function_name':
268                'Function name.',
269            'tier':
270                'Compilation tier',
271            'code_offset_in_module':
272                """Offset into the WASM module where the function starts""",
273        },
274    ),
275)
276
277V8_REGEXP_CODE = Table(
278    python_module=__file__,
279    class_name='V8RegexpCodeTable',
280    sql_name='__intrinsic_v8_regexp_code',
281    columns=[
282        C('jit_code_id', CppTableId(JIT_CODE_TABLE)),
283        C('v8_isolate_id', CppTableId(V8_ISOLATE)),
284        C('pattern', CppString()),
285    ],
286    tabledoc=TableDoc(
287        doc="""
288          Represents the code associated to a regular expression
289        """,
290        group='v8',
291        columns={
292            'jit_code_id':
293                ColumnDoc(
294                    doc='Associated JitCode.',
295                    joinable='__intrinsic_jit_code.id',
296                ),
297            'v8_isolate_id':
298                ColumnDoc(
299                    doc="""
300                  V8 Isolate this code was created in.
301                    """,
302                    joinable='__intrinsic_v8_isolate.id'),
303            'pattern':
304                """The pattern the this regular expression was compiled from""",
305        },
306    ),
307)
308
309# Keep this list sorted.
310ALL_TABLES = [
311    V8_ISOLATE,
312    V8_JS_SCRIPT,
313    V8_WASM_SCRIPT,
314    V8_JS_FUNCTION,
315    V8_JS_CODE,
316    V8_INTERNAL_CODE,
317    V8_WASM_CODE,
318    V8_REGEXP_CODE,
319]
320