V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
wasm-objects.h
1 // Copyright 2016 the V8 project authors. All rights reserved. Use of
2 // this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_WASM_WASM_OBJECTS_H_
6 #define V8_WASM_WASM_OBJECTS_H_
7 
8 #include "src/base/bits.h"
9 #include "src/debug/debug.h"
10 #include "src/debug/interface-types.h"
11 #include "src/heap/heap.h"
12 #include "src/objects.h"
13 #include "src/objects/script.h"
14 #include "src/signature.h"
15 #include "src/wasm/value-type.h"
16 
17 // Has to be the last include (doesn't have include guards)
18 #include "src/objects/object-macros.h"
19 
20 namespace v8 {
21 namespace internal {
22 namespace wasm {
23 struct CompilationEnv;
24 class InterpretedFrame;
25 struct InterpretedFrameDeleter;
26 class NativeModule;
27 class SignatureMap;
28 class WasmCode;
29 struct WasmFeatures;
30 class WasmInterpreter;
31 struct WasmModule;
32 class WireBytesRef;
33 } // namespace wasm
34 
35 class BreakPoint;
36 class JSArrayBuffer;
37 class SeqOneByteString;
38 class WasmDebugInfo;
39 class WasmInstanceObject;
40 class WasmModuleObject;
41 
42 template <class CppType>
43 class Managed;
44 
45 #define DECL_OPTIONAL_ACCESSORS(name, type) \
46  V8_INLINE bool has_##name(); \
47  DECL_ACCESSORS(name, type)
48 // TODO(3770): Replacement for the above, temporarily separate.
49 #define DECL_OPTIONAL_ACCESSORS2(name, type) \
50  V8_INLINE bool has_##name(); \
51  DECL_ACCESSORS2(name, type)
52 
53 // A helper for an entry in an indirect function table (IFT).
54 // The underlying storage in the instance is used by generated code to
55 // call functions indirectly at runtime.
56 // Each entry has the following fields:
57 // - object = target instance, if a WASM function, tuple if imported
58 // - sig_id = signature id of function
59 // - target = entrypoint to WASM code or import wrapper code
61  public:
63 
64  void clear();
65  void Set(int sig_id, Handle<WasmInstanceObject> target_instance,
66  int target_func_index);
67 
68  Object* object_ref();
69  int sig_id();
70  Address target();
71 
72  private:
73  Handle<WasmInstanceObject> const instance_;
74  int const index_;
75 };
76 
77 // A helper for an entry for an imported function, indexed statically.
78 // The underlying storage in the instance is used by generated code to
79 // call imported functions at runtime.
80 // Each entry is either:
81 // - WASM to JS, which has fields
82 // - object = a Tuple2 of the importing instance and the callable
83 // - target = entrypoint to import wrapper code
84 // - WASM to WASM, which has fields
85 // - object = target instance
86 // - target = entrypoint for the function
88  public:
90 
91  // Initialize this entry as a WASM to JS call. This accepts the isolate as a
92  // parameter, since it must allocate a tuple.
93  void SetWasmToJs(Isolate*, Handle<JSReceiver> callable,
94  const wasm::WasmCode* wasm_to_js_wrapper);
95  // Initialize this entry as a WASM to WASM call.
96  void SetWasmToWasm(WasmInstanceObject* target_instance, Address call_target);
97 
98  WasmInstanceObject* instance();
99  JSReceiver* callable();
100  Object* object_ref();
101  Address target();
102 
103  private:
104  Handle<WasmInstanceObject> const instance_;
105  int const index_;
106 };
107 
108 // Representation of a WebAssembly.Module JavaScript-level object.
109 class WasmModuleObject : public JSObject {
110  public:
111  DECL_CAST(WasmModuleObject)
112 
113  DECL_ACCESSORS(managed_native_module, Managed<wasm::NativeModule>)
114  DECL_ACCESSORS2(export_wrappers, FixedArray)
115  DECL_ACCESSORS(script, Script)
116  DECL_ACCESSORS(weak_instance_list, WeakArrayList)
117  DECL_OPTIONAL_ACCESSORS2(asm_js_offset_table, ByteArray)
118  DECL_OPTIONAL_ACCESSORS2(breakpoint_infos, FixedArray)
119  inline wasm::NativeModule* native_module() const;
120  inline const wasm::WasmModule* module() const;
121  inline void reset_breakpoint_infos();
122 
123  // Dispatched behavior.
124  DECL_PRINTER(WasmModuleObject)
125  DECL_VERIFIER(WasmModuleObject)
126 
127 // Layout description.
128 #define WASM_MODULE_OBJECT_FIELDS(V) \
129  V(kNativeModuleOffset, kPointerSize) \
130  V(kExportWrappersOffset, kPointerSize) \
131  V(kScriptOffset, kPointerSize) \
132  V(kWeakInstanceListOffset, kPointerSize) \
133  V(kAsmJsOffsetTableOffset, kPointerSize) \
134  V(kBreakPointInfosOffset, kPointerSize) \
135  V(kSize, 0)
136 
137  DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
138  WASM_MODULE_OBJECT_FIELDS)
139 #undef WASM_MODULE_OBJECT_FIELDS
140 
141  // Creates a new {WasmModuleObject} with a new {NativeModule} underneath.
142  static Handle<WasmModuleObject> New(
143  Isolate* isolate, const wasm::WasmFeatures& enabled,
144  std::shared_ptr<const wasm::WasmModule> module,
145  OwnedVector<const uint8_t> wire_bytes, Handle<Script> script,
146  Handle<ByteArray> asm_js_offset_table);
147 
148  // Creates a new {WasmModuleObject} for an existing {NativeModule} that is
149  // reference counted and might be shared between multiple Isolates.
150  static Handle<WasmModuleObject> New(
151  Isolate* isolate, std::shared_ptr<wasm::NativeModule> native_module,
152  Handle<Script> script, size_t code_size_estimate);
153  static Handle<WasmModuleObject> New(
154  Isolate* isolate, std::shared_ptr<wasm::NativeModule> native_module,
155  Handle<Script> script, Handle<FixedArray> export_wrappers,
156  size_t code_size_estimate);
157 
158  // Set a breakpoint on the given byte position inside the given module.
159  // This will affect all live and future instances of the module.
160  // The passed position might be modified to point to the next breakable
161  // location inside the same function.
162  // If it points outside a function, or behind the last breakable location,
163  // this function returns false and does not set any breakpoint.
164  static bool SetBreakPoint(Handle<WasmModuleObject>, int* position,
165  Handle<BreakPoint> break_point);
166 
167  // Check whether this module was generated from asm.js source.
168  inline bool is_asm_js();
169 
170  static void AddBreakpoint(Handle<WasmModuleObject>, int position,
171  Handle<BreakPoint> break_point);
172 
173  static void SetBreakpointsOnNewInstance(Handle<WasmModuleObject>,
175 
176  // Get the module name, if set. Returns an empty handle otherwise.
177  static MaybeHandle<String> GetModuleNameOrNull(Isolate*,
179 
180  // Get the function name of the function identified by the given index.
181  // Returns a null handle if the function is unnamed or the name is not a valid
182  // UTF-8 string.
183  static MaybeHandle<String> GetFunctionNameOrNull(Isolate*,
185  uint32_t func_index);
186 
187  // Get the function name of the function identified by the given index.
188  // Returns "wasm-function[func_index]" if the function is unnamed or the
189  // name is not a valid UTF-8 string.
190  static Handle<String> GetFunctionName(Isolate*, Handle<WasmModuleObject>,
191  uint32_t func_index);
192 
193  // Get the raw bytes of the function name of the function identified by the
194  // given index.
195  // Meant to be used for debugging or frame printing.
196  // Does not allocate, hence gc-safe.
197  Vector<const uint8_t> GetRawFunctionName(uint32_t func_index);
198 
199  // Return the byte offset of the function identified by the given index.
200  // The offset will be relative to the start of the module bytes.
201  // Returns -1 if the function index is invalid.
202  int GetFunctionOffset(uint32_t func_index);
203 
204  // Returns the function containing the given byte offset.
205  // Returns -1 if the byte offset is not contained in any function of this
206  // module.
207  int GetContainingFunction(uint32_t byte_offset);
208 
209  // Translate from byte offset in the module to function number and byte offset
210  // within that function, encoded as line and column in the position info.
211  // Returns true if the position is valid inside this module, false otherwise.
212  bool GetPositionInfo(uint32_t position, Script::PositionInfo* info);
213 
214  // Get the source position from a given function index and byte offset,
215  // for either asm.js or pure WASM modules.
216  static int GetSourcePosition(Handle<WasmModuleObject>, uint32_t func_index,
217  uint32_t byte_offset,
218  bool is_at_number_conversion);
219 
220  // Compute the disassembly of a wasm function.
221  // Returns the disassembly string and a list of <byte_offset, line, column>
222  // entries, mapping wasm byte offsets to line and column in the disassembly.
223  // The list is guaranteed to be ordered by the byte_offset.
224  // Returns an empty string and empty vector if the function index is invalid.
225  debug::WasmDisassembly DisassembleFunction(int func_index);
226 
227  // Extract a portion of the wire bytes as UTF-8 string.
228  // Returns a null handle if the respective bytes do not form a valid UTF-8
229  // string.
230  static MaybeHandle<String> ExtractUtf8StringFromModuleBytes(
232  static MaybeHandle<String> ExtractUtf8StringFromModuleBytes(
233  Isolate* isolate, Vector<const uint8_t> wire_byte,
234  wasm::WireBytesRef ref);
235 
236  // Get a list of all possible breakpoints within a given range of this module.
237  bool GetPossibleBreakpoints(const debug::Location& start,
238  const debug::Location& end,
239  std::vector<debug::BreakLocation>* locations);
240 
241  // Return an empty handle if no breakpoint is hit at that location, or a
242  // FixedArray with all hit breakpoint objects.
243  static MaybeHandle<FixedArray> CheckBreakPoints(Isolate*,
245  int position);
246 };
247 
248 // Representation of a WebAssembly.Table JavaScript-level object.
249 class WasmTableObject : public JSObject {
250  public:
251  DECL_CAST(WasmTableObject)
252 
253  DECL_ACCESSORS2(functions, FixedArray)
254  // TODO(titzer): introduce DECL_I64_ACCESSORS macro
255  DECL_ACCESSORS(maximum_length, Object)
256  DECL_ACCESSORS2(dispatch_tables, FixedArray)
257 
258 // Layout description.
259 #define WASM_TABLE_OBJECT_FIELDS(V) \
260  V(kFunctionsOffset, kPointerSize) \
261  V(kMaximumLengthOffset, kPointerSize) \
262  V(kDispatchTablesOffset, kPointerSize) \
263  V(kSize, 0)
264 
265  DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, WASM_TABLE_OBJECT_FIELDS)
266 #undef WASM_TABLE_OBJECT_FIELDS
267 
268  inline uint32_t current_length();
269  void Grow(Isolate* isolate, uint32_t count);
270 
271  static Handle<WasmTableObject> New(Isolate* isolate, uint32_t initial,
272  int64_t maximum,
273  Handle<FixedArray>* js_functions);
274  static void AddDispatchTable(Isolate* isolate, Handle<WasmTableObject> table,
276  int table_index);
277 
278  static void Set(Isolate* isolate, Handle<WasmTableObject> table,
279  int32_t index, Handle<JSFunction> function);
280 
281  static void UpdateDispatchTables(Isolate* isolate,
283  int table_index, wasm::FunctionSig* sig,
284  Handle<WasmInstanceObject> target_instance,
285  int target_func_index);
286 
287  static void ClearDispatchTables(Isolate* isolate,
288  Handle<WasmTableObject> table, int index);
289 };
290 
291 // Representation of a WebAssembly.Memory JavaScript-level object.
292 class WasmMemoryObject : public JSObject {
293  public:
294  DECL_CAST(WasmMemoryObject)
295 
296  DECL_ACCESSORS(array_buffer, JSArrayBuffer)
297  DECL_INT_ACCESSORS(maximum_pages)
298  DECL_OPTIONAL_ACCESSORS(instances, WeakArrayList)
299 
300 // Layout description.
301 #define WASM_MEMORY_OBJECT_FIELDS(V) \
302  V(kArrayBufferOffset, kPointerSize) \
303  V(kMaximumPagesOffset, kPointerSize) \
304  V(kInstancesOffset, kPointerSize) \
305  V(kSize, 0)
306 
307  DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
308  WASM_MEMORY_OBJECT_FIELDS)
309 #undef WASM_MEMORY_OBJECT_FIELDS
310 
311  // Add an instance to the internal (weak) list.
312  static void AddInstance(Isolate* isolate, Handle<WasmMemoryObject> memory,
314  // Remove an instance from the internal (weak) list.
315  static void RemoveInstance(Handle<WasmMemoryObject> memory,
317  uint32_t current_pages();
318  inline bool has_maximum_pages();
319 
320  // Return whether the underlying backing store has guard regions large enough
321  // to be used with trap handlers.
322  bool has_full_guard_region(Isolate* isolate);
323 
324  V8_EXPORT_PRIVATE static Handle<WasmMemoryObject> New(
325  Isolate* isolate, MaybeHandle<JSArrayBuffer> buffer, int32_t maximum);
326 
327  static int32_t Grow(Isolate*, Handle<WasmMemoryObject>, uint32_t pages);
328 };
329 
330 // Representation of a WebAssembly.Global JavaScript-level object.
331 class WasmGlobalObject : public JSObject {
332  public:
333  DECL_CAST(WasmGlobalObject)
334 
335  DECL_ACCESSORS(array_buffer, JSArrayBuffer)
336  DECL_INT32_ACCESSORS(offset)
337  DECL_INT_ACCESSORS(flags)
338  DECL_PRIMITIVE_ACCESSORS(type, wasm::ValueType)
339  DECL_BOOLEAN_ACCESSORS(is_mutable)
340 
341 #define WASM_GLOBAL_OBJECT_FLAGS_BIT_FIELDS(V, _) \
342  V(TypeBits, wasm::ValueType, 8, _) \
343  V(IsMutableBit, bool, 1, _)
344 
345  DEFINE_BIT_FIELDS(WASM_GLOBAL_OBJECT_FLAGS_BIT_FIELDS)
346 
347 #undef WASM_GLOBAL_OBJECT_FLAGS_BIT_FIELDS
348 
349 // Layout description.
350 #define WASM_GLOBAL_OBJECT_FIELDS(V) \
351  V(kArrayBufferOffset, kPointerSize) \
352  V(kOffsetOffset, kPointerSize) \
353  V(kFlagsOffset, kPointerSize) \
354  V(kSize, 0)
355 
356  DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
357  WASM_GLOBAL_OBJECT_FIELDS)
358 #undef WASM_GLOBAL_OBJECT_FIELDS
359 
360  V8_EXPORT_PRIVATE static MaybeHandle<WasmGlobalObject> New(
361  Isolate* isolate, MaybeHandle<JSArrayBuffer> buffer, wasm::ValueType type,
362  int32_t offset, bool is_mutable);
363 
364  inline int type_size() const;
365 
366  inline int32_t GetI32();
367  inline int64_t GetI64();
368  inline float GetF32();
369  inline double GetF64();
370 
371  inline void SetI32(int32_t value);
372  inline void SetI64(int64_t value);
373  inline void SetF32(float value);
374  inline void SetF64(double value);
375 
376  private:
377  // This function returns the address of the global's data in the
378  // JSArrayBuffer. This buffer may be allocated on-heap, in which case it may
379  // not have a fixed address.
380  inline Address address() const;
381 };
382 
383 // Representation of a WebAssembly.Instance JavaScript-level object.
384 class WasmInstanceObject : public JSObject {
385  public:
386  DECL_CAST(WasmInstanceObject)
387 
388  DECL_ACCESSORS(module_object, WasmModuleObject)
389  DECL_ACCESSORS(exports_object, JSObject)
390  DECL_ACCESSORS2(native_context, Context)
391  DECL_OPTIONAL_ACCESSORS(memory_object, WasmMemoryObject)
392  DECL_OPTIONAL_ACCESSORS(globals_buffer, JSArrayBuffer)
393  DECL_OPTIONAL_ACCESSORS2(imported_mutable_globals_buffers, FixedArray)
394  DECL_OPTIONAL_ACCESSORS(debug_info, WasmDebugInfo)
395  DECL_OPTIONAL_ACCESSORS(table_object, WasmTableObject)
396  DECL_ACCESSORS2(imported_function_refs, FixedArray)
397  DECL_OPTIONAL_ACCESSORS2(indirect_function_table_refs, FixedArray)
398  DECL_OPTIONAL_ACCESSORS(managed_native_allocations, Foreign)
399  DECL_OPTIONAL_ACCESSORS2(exceptions_table, FixedArray)
400  DECL_ACCESSORS(undefined_value, Oddball)
401  DECL_ACCESSORS(null_value, Oddball)
402  DECL_ACCESSORS2(centry_stub, Code)
403  DECL_PRIMITIVE_ACCESSORS(memory_start, byte*)
404  DECL_PRIMITIVE_ACCESSORS(memory_size, size_t)
405  DECL_PRIMITIVE_ACCESSORS(memory_mask, size_t)
406  DECL_PRIMITIVE_ACCESSORS(isolate_root, Address)
407  DECL_PRIMITIVE_ACCESSORS(stack_limit_address, Address)
408  DECL_PRIMITIVE_ACCESSORS(real_stack_limit_address, Address)
409  DECL_PRIMITIVE_ACCESSORS(imported_function_targets, Address*)
410  DECL_PRIMITIVE_ACCESSORS(globals_start, byte*)
411  DECL_PRIMITIVE_ACCESSORS(imported_mutable_globals, Address*)
412  DECL_PRIMITIVE_ACCESSORS(indirect_function_table_size, uint32_t)
413  DECL_PRIMITIVE_ACCESSORS(indirect_function_table_sig_ids, uint32_t*)
414  DECL_PRIMITIVE_ACCESSORS(indirect_function_table_targets, Address*)
415  DECL_PRIMITIVE_ACCESSORS(jump_table_start, Address)
416 
417  // Dispatched behavior.
418  DECL_PRINTER(WasmInstanceObject)
419  DECL_VERIFIER(WasmInstanceObject)
420 
421 // Layout description.
422 #define WASM_INSTANCE_OBJECT_FIELDS(V) \
423  V(kModuleObjectOffset, kPointerSize) \
424  V(kExportsObjectOffset, kPointerSize) \
425  V(kNativeContextOffset, kPointerSize) \
426  V(kMemoryObjectOffset, kPointerSize) \
427  V(kGlobalsBufferOffset, kPointerSize) \
428  V(kImportedMutableGlobalsBuffersOffset, kPointerSize) \
429  V(kDebugInfoOffset, kPointerSize) \
430  V(kTableObjectOffset, kPointerSize) \
431  V(kImportedFunctionRefsOffset, kPointerSize) \
432  V(kIndirectFunctionTableRefsOffset, kPointerSize) \
433  V(kManagedNativeAllocationsOffset, kPointerSize) \
434  V(kExceptionsTableOffset, kPointerSize) \
435  V(kUndefinedValueOffset, kPointerSize) \
436  V(kNullValueOffset, kPointerSize) \
437  V(kCEntryStubOffset, kPointerSize) \
438  V(kFirstUntaggedOffset, 0) /* marker */ \
439  V(kMemoryStartOffset, kPointerSize) /* untagged */ \
440  V(kMemorySizeOffset, kSizetSize) /* untagged */ \
441  V(kMemoryMaskOffset, kSizetSize) /* untagged */ \
442  V(kIsolateRootOffset, kPointerSize) /* untagged */ \
443  V(kStackLimitAddressOffset, kPointerSize) /* untagged */ \
444  V(kRealStackLimitAddressOffset, kPointerSize) /* untagged */ \
445  V(kImportedFunctionTargetsOffset, kPointerSize) /* untagged */ \
446  V(kGlobalsStartOffset, kPointerSize) /* untagged */ \
447  V(kImportedMutableGlobalsOffset, kPointerSize) /* untagged */ \
448  V(kIndirectFunctionTableSigIdsOffset, kPointerSize) /* untagged */ \
449  V(kIndirectFunctionTableTargetsOffset, kPointerSize) /* untagged */ \
450  V(kJumpTableStartOffset, kPointerSize) /* untagged */ \
451  V(kIndirectFunctionTableSizeOffset, kUInt32Size) /* untagged */ \
452  V(k64BitArchPaddingOffset, kPointerSize - kUInt32Size) /* padding */ \
453  V(kSize, 0)
454 
455  DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
456  WASM_INSTANCE_OBJECT_FIELDS)
457 #undef WASM_INSTANCE_OBJECT_FIELDS
458 
459  V8_EXPORT_PRIVATE const wasm::WasmModule* module();
460 
461  static bool EnsureIndirectFunctionTableWithMinimumSize(
462  Handle<WasmInstanceObject> instance, uint32_t minimum_size);
463 
464  bool has_indirect_function_table();
465 
466  void SetRawMemory(byte* mem_start, size_t mem_size);
467 
468  // Get the debug info associated with the given wasm object.
469  // If no debug info exists yet, it is created automatically.
470  static Handle<WasmDebugInfo> GetOrCreateDebugInfo(Handle<WasmInstanceObject>);
471 
473 
474  Address GetCallTarget(uint32_t func_index);
475 
476  // Iterates all fields in the object except the untagged fields.
477  class BodyDescriptor;
478 };
479 
480 // Representation of WebAssembly.Exception JavaScript-level object.
482  public:
483  DECL_CAST(WasmExceptionObject)
484 
485  DECL_ACCESSORS2(serialized_signature, PodArray<wasm::ValueType>)
486  DECL_ACCESSORS(exception_tag, HeapObject)
487 
488 // Layout description.
489 #define WASM_EXCEPTION_OBJECT_FIELDS(V) \
490  V(kSerializedSignatureOffset, kPointerSize) \
491  V(kExceptionTagOffset, kPointerSize) \
492  V(kSize, 0)
493 
494  DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
495  WASM_EXCEPTION_OBJECT_FIELDS)
496 #undef WASM_EXCEPTION_OBJECT_FIELDS
497 
498  // Checks whether the given {sig} has the same parameter types as the
499  // serialized signature stored within this exception object.
500  bool IsSignatureEqual(const wasm::FunctionSig* sig);
501 
502  static Handle<WasmExceptionObject> New(Isolate* isolate,
503  const wasm::FunctionSig* sig,
504  Handle<HeapObject> exception_tag);
505 };
506 
507 // A WASM function that is wrapped and exported to JavaScript.
509  public:
510  WasmInstanceObject* instance();
511  V8_EXPORT_PRIVATE int function_index();
512 
513  V8_EXPORT_PRIVATE static WasmExportedFunction* cast(Object* object);
514  static bool IsWasmExportedFunction(Object* object);
515 
516  static Handle<WasmExportedFunction> New(Isolate* isolate,
518  MaybeHandle<String> maybe_name,
519  int func_index, int arity,
520  Handle<Code> export_wrapper);
521 
522  Address GetWasmCallTarget();
523 
524  wasm::FunctionSig* sig();
525 };
526 
527 // Information for a WasmExportedFunction which is referenced as the function
528 // data of the SharedFunctionInfo underlying the function. For details please
529 // see the {SharedFunctionInfo::HasWasmExportedFunctionData} predicate.
531  public:
532  DECL_ACCESSORS2(wrapper_code, Code);
533  DECL_ACCESSORS(instance, WasmInstanceObject)
534  DECL_INT_ACCESSORS(jump_table_offset);
535  DECL_INT_ACCESSORS(function_index);
536 
537  DECL_CAST(WasmExportedFunctionData)
538 
539  // Dispatched behavior.
540  DECL_PRINTER(WasmExportedFunctionData)
541  DECL_VERIFIER(WasmExportedFunctionData)
542 
543 // Layout description.
544 #define WASM_EXPORTED_FUNCTION_DATA_FIELDS(V) \
545  V(kWrapperCodeOffset, kPointerSize) \
546  V(kInstanceOffset, kPointerSize) \
547  V(kJumpTableOffsetOffset, kPointerSize) /* Smi */ \
548  V(kFunctionIndexOffset, kPointerSize) /* Smi */ \
549  V(kSize, 0)
550 
551  DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
552  WASM_EXPORTED_FUNCTION_DATA_FIELDS)
553 #undef WASM_EXPORTED_FUNCTION_DATA_FIELDS
554 };
555 
557  public:
558  DECL_ACCESSORS(wasm_instance, WasmInstanceObject)
559  DECL_ACCESSORS(interpreter_handle, Object); // Foreign or undefined
560  DECL_ACCESSORS2(interpreted_functions, FixedArray);
561  DECL_OPTIONAL_ACCESSORS2(locals_names, FixedArray)
562  DECL_OPTIONAL_ACCESSORS2(c_wasm_entries, FixedArray)
563  DECL_OPTIONAL_ACCESSORS(c_wasm_entry_map, Managed<wasm::SignatureMap>)
564 
565  DECL_CAST(WasmDebugInfo)
566 
567  // Dispatched behavior.
568  DECL_PRINTER(WasmDebugInfo)
569  DECL_VERIFIER(WasmDebugInfo)
570 
571 // Layout description.
572 #define WASM_DEBUG_INFO_FIELDS(V) \
573  V(kInstanceOffset, kPointerSize) \
574  V(kInterpreterHandleOffset, kPointerSize) \
575  V(kInterpretedFunctionsOffset, kPointerSize) \
576  V(kLocalsNamesOffset, kPointerSize) \
577  V(kCWasmEntriesOffset, kPointerSize) \
578  V(kCWasmEntryMapOffset, kPointerSize) \
579  V(kSize, 0)
580 
581  DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, WASM_DEBUG_INFO_FIELDS)
582 #undef WASM_DEBUG_INFO_FIELDS
583 
585 
586  // Setup a WasmDebugInfo with an existing WasmInstance struct.
587  // Returns a pointer to the interpreter instantiated inside this
588  // WasmDebugInfo.
589  // Use for testing only.
590  V8_EXPORT_PRIVATE static wasm::WasmInterpreter* SetupForTesting(
592 
593  // Set a breakpoint in the given function at the given byte offset within that
594  // function. This will redirect all future calls to this function to the
595  // interpreter and will always pause at the given offset.
596  static void SetBreakpoint(Handle<WasmDebugInfo>, int func_index, int offset);
597 
598  // Make a set of functions always execute in the interpreter without setting
599  // breakpoints.
600  static void RedirectToInterpreter(Handle<WasmDebugInfo>,
601  Vector<int> func_indexes);
602 
603  void PrepareStep(StepAction);
604 
605  // Execute the specified function in the interpreter. Read arguments from
606  // arg_buffer.
607  // The frame_pointer will be used to identify the new activation of the
608  // interpreter for unwinding and frame inspection.
609  // Returns true if exited regularly, false if a trap occurred. In the latter
610  // case, a pending exception will have been set on the isolate.
611  static bool RunInterpreter(Isolate* isolate, Handle<WasmDebugInfo>,
612  Address frame_pointer, int func_index,
613  Address arg_buffer);
614 
615  // Get the stack of the wasm interpreter as pairs of <function index, byte
616  // offset>. The list is ordered bottom-to-top, i.e. caller before callee.
617  std::vector<std::pair<uint32_t, int>> GetInterpretedStack(
618  Address frame_pointer);
619 
620  std::unique_ptr<wasm::InterpretedFrame, wasm::InterpretedFrameDeleter>
621  GetInterpretedFrame(Address frame_pointer, int frame_index);
622 
623  // Unwind the interpreted stack belonging to the passed interpreter entry
624  // frame.
625  void Unwind(Address frame_pointer);
626 
627  // Returns the number of calls / function frames executed in the interpreter.
628  uint64_t NumInterpretedCalls();
629 
630  // Get scope details for a specific interpreted frame.
631  // This returns a JSArray of length two: One entry for the global scope, one
632  // for the local scope. Both elements are JSArrays of size
633  // ScopeIterator::kScopeDetailsSize and layout as described in debug-scopes.h.
634  // The global scope contains information about globals and the memory.
635  // The local scope contains information about parameters, locals, and stack
636  // values.
637  static Handle<JSObject> GetScopeDetails(Handle<WasmDebugInfo>,
638  Address frame_pointer,
639  int frame_index);
640  static Handle<JSObject> GetGlobalScopeObject(Handle<WasmDebugInfo>,
641  Address frame_pointer,
642  int frame_index);
643  static Handle<JSObject> GetLocalScopeObject(Handle<WasmDebugInfo>,
644  Address frame_pointer,
645  int frame_index);
646 
647  static Handle<JSFunction> GetCWasmEntry(Handle<WasmDebugInfo>,
649 };
650 
651 class AsmWasmData : public Struct {
652  public:
653  static Handle<AsmWasmData> New(
654  Isolate* isolate, std::shared_ptr<wasm::NativeModule> native_module,
655  Handle<FixedArray> export_wrappers, Handle<ByteArray> asm_js_offset_table,
656  Handle<HeapNumber> uses_bitset);
657 
658  DECL_ACCESSORS(managed_native_module, Managed<wasm::NativeModule>)
659  DECL_ACCESSORS2(export_wrappers, FixedArray)
660  DECL_ACCESSORS2(asm_js_offset_table, ByteArray)
661  DECL_ACCESSORS(uses_bitset, HeapNumber)
662 
663  DECL_CAST(AsmWasmData)
664  DECL_PRINTER(AsmWasmData)
665  DECL_VERIFIER(AsmWasmData)
666 
667 // Layout description.
668 #define ASM_WASM_DATA_FIELDS(V) \
669  V(kManagedNativeModuleOffset, kPointerSize) \
670  V(kExportWrappersOffset, kPointerSize) \
671  V(kAsmJsOffsetTableOffset, kPointerSize) \
672  V(kUsesBitsetOffset, kPointerSize) \
673  /* Total size. */ \
674  V(kSize, 0)
675 
676  DEFINE_FIELD_OFFSET_CONSTANTS(Struct::kHeaderSize, ASM_WASM_DATA_FIELDS)
677 #undef ASM_WASM_DATA_FIELDS
678 };
679 
680 #undef DECL_OPTIONAL_ACCESSORS
681 
682 } // namespace internal
683 } // namespace v8
684 
685 #include "src/objects/object-macros-undef.h"
686 
687 #endif // V8_WASM_WASM_OBJECTS_H_
Definition: libplatform.h:13
Definition: v8.h:3740