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