-
-
Notifications
You must be signed in to change notification settings - Fork 36.6k
Expand file tree
/
Copy pathwasm-objects.h
More file actions
1746 lines (1442 loc) Β· 72.4 KB
/
Copy pathwasm-objects.h
File metadata and controls
1746 lines (1442 loc) Β· 72.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2016 the V8 project authors. All rights reserved. Use of
// this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_WASM_WASM_OBJECTS_H_
#define V8_WASM_WASM_OBJECTS_H_
#if !V8_ENABLE_WEBASSEMBLY
#error This header should only be included if WebAssembly is enabled.
#endif // !V8_ENABLE_WEBASSEMBLY
#include <memory>
#include <optional>
#include "include/v8-wasm.h"
#include "src/base/bit-field.h"
#include "src/debug/interface-types.h"
#include "src/heap/heap.h"
#include "src/objects/backing-store.h"
#include "src/objects/contexts.h"
#include "src/objects/foreign.h"
#include "src/objects/js-function.h"
#include "src/objects/js-objects.h"
#include "src/objects/objects-body-descriptors.h"
#include "src/objects/objects.h"
#include "src/objects/struct.h"
#include "src/objects/trusted-object.h"
#include "src/wasm/module-instantiate.h"
#include "src/wasm/stacks.h"
#include "src/wasm/struct-types.h"
#include "src/wasm/value-type.h"
#include "src/wasm/wasm-code-manager.h"
#include "src/wasm/wasm-module.h"
// Has to be the last include (doesn't have include guards)
#include "src/objects/object-macros.h"
namespace v8 {
namespace internal {
namespace wasm {
class NativeModule;
class WasmCode;
struct WasmFunction;
struct WasmGlobal;
class WasmImportWrapperHandle;
struct WasmModule;
struct WasmTag;
using WasmTagSig = FunctionSig;
class WasmValue;
class WireBytesRef;
} // namespace wasm
class BreakPoint;
class JSArrayBuffer;
class SeqOneByteString;
class StructBodyDescriptor;
class WasmCapiFunction;
class WasmDispatchTableForImports;
class WasmExceptionTag;
class WasmExportedFunction;
class WasmExternalFunction;
class WasmTrustedInstanceData;
class WasmJSFunction;
class WasmModuleObject;
enum class SharedFlag : uint8_t;
template <typename CppType>
class Managed;
template <typename CppType>
class TrustedManaged;
#include "torque-generated/src/wasm/wasm-objects-tq.inc"
#define DECL_OPTIONAL_ACCESSORS(name, type) \
DECL_GETTER(has_##name, bool) \
DECL_ACCESSORS(name, type)
class V8_EXPORT_PRIVATE FunctionTargetAndImplicitArg {
public:
FunctionTargetAndImplicitArg(
Isolate* isolate,
DirectHandle<WasmTrustedInstanceData> target_instance_data,
int target_func_index);
// The "implicit_arg" will be a WasmTrustedInstanceData or a WasmImportData.
DirectHandle<TrustedObject> implicit_arg() { return implicit_arg_; }
WasmCodePointer call_target() { return call_target_; }
#if V8_ENABLE_DRUMBRAKE
int target_func_index() { return target_func_index_; }
#endif // V8_ENABLE_DRUMBRAKE
private:
DirectHandle<TrustedObject> implicit_arg_;
WasmCodePointer call_target_;
#if V8_ENABLE_DRUMBRAKE
int target_func_index_;
#endif // V8_ENABLE_DRUMBRAKE
};
namespace wasm {
enum class OnResume : int { kContinue, kThrow };
// Generated "constructor" functions (per the Custom Descriptors proposal)
// store the exported Wasm function they're calling in a context slot.
// We use the first slot in a context with one slot.
static constexpr int kConstructorFunctionContextSlot =
Context::MIN_CONTEXT_SLOTS;
static constexpr int kConstructorFunctionContextLength =
kConstructorFunctionContextSlot + 1;
// Same trick for generated method wrappers.
static constexpr int kMethodWrapperContextSlot = Context::MIN_CONTEXT_SLOTS;
static constexpr int kMethodWrapperContextLength =
kMethodWrapperContextSlot + 1;
} // namespace wasm
// A helper for an entry for an imported function, indexed statically.
// The underlying storage in the instance is used by generated code to
// call imported functions at runtime.
// Each entry is either:
// - Wasm to Wrapper, which has fields
// - object = a WasmImportData
// - target = entrypoint to import wrapper code
// - Wasm to Wasm, which has fields
// - object = target instance data
// - target = entrypoint for the function
class ImportedFunctionEntry {
public:
inline ImportedFunctionEntry(DirectHandle<WasmTrustedInstanceData>,
int index);
// Initialize this entry as a Wasm to Wasm call.
void SetWasmToWasm(Tagged<WasmTrustedInstanceData> target_instance_object,
WasmCodePointer call_target,
wasm::CanonicalTypeIndex sig_id
#if V8_ENABLE_DRUMBRAKE
,
int exported_function_index
#endif // V8_ENABLE_DRUMBRAKE
);
// Initialize this entry as a Wasm to non-Wasm call, i.e. anything that needs
// an import wrapper. This accepts the isolate as a parameter since it
// allocates a WasmImportData.
V8_EXPORT_PRIVATE void SetWasmToWrapper(
Isolate*, DirectHandle<JSReceiver> callable,
std::shared_ptr<wasm::WasmImportWrapperHandle> wrapper_handle,
wasm::Suspend suspend, const wasm::CanonicalSig* sig);
Tagged<JSReceiver> callable();
Tagged<Object> maybe_callable();
Tagged<Object> implicit_arg();
WasmCodePointer target();
#if V8_ENABLE_DRUMBRAKE
int function_index_in_called_module();
#endif // V8_ENABLE_DRUMBRAKE
private:
DirectHandle<WasmTrustedInstanceData> const instance_data_;
int const index_;
};
enum InternalizeString : bool { kInternalize = true, kNoInternalize = false };
// Representation of a WebAssembly.Module JavaScript-level object.
class WasmModuleObject
: public TorqueGeneratedWasmModuleObject<WasmModuleObject, JSObject> {
public:
inline wasm::NativeModule* native_module() const;
inline const std::shared_ptr<wasm::NativeModule>& shared_native_module()
const;
// Dispatched behavior.
DECL_PRINTER(WasmModuleObject)
// Creates a new {WasmModuleObject} for an existing {NativeModule} that is
// reference counted and might be shared between multiple Isolates.
V8_EXPORT_PRIVATE static DirectHandle<WasmModuleObject> New(
Isolate* isolate, std::shared_ptr<wasm::NativeModule> native_module,
DirectHandle<Script> script);
// Get the module name, if set. Returns an empty handle otherwise.
static MaybeDirectHandle<String> GetModuleNameOrNull(
Isolate*, DirectHandle<WasmModuleObject>);
// Get the function name of the function identified by the given index.
// Returns a null handle if the function is unnamed or the name is not a valid
// UTF-8 string.
static MaybeDirectHandle<String> GetFunctionNameOrNull(
Isolate*, DirectHandle<WasmModuleObject>, uint32_t func_index);
// Get the raw bytes of the function name of the function identified by the
// given index.
// Meant to be used for debugging or frame printing.
// Does not allocate, hence gc-safe.
base::Vector<const uint8_t> GetRawFunctionName(int func_index);
// Extract a portion of the wire bytes as UTF-8 string, optionally
// internalized. (Prefer to internalize early if the string will be used for a
// property lookup anyway.)
static DirectHandle<String> ExtractUtf8StringFromModuleBytes(
Isolate*, base::Vector<const uint8_t> wire_bytes, wasm::WireBytesRef,
InternalizeString);
TQ_OBJECT_CONSTRUCTORS(WasmModuleObject)
};
#if V8_ENABLE_SANDBOX || DEBUG
// This should be checked on all code paths that write into WasmDispatchTables.
bool FunctionSigMatchesTable(wasm::CanonicalTypeIndex sig_id,
wasm::CanonicalValueType table_type);
#endif
// Representation of a WebAssembly.Table JavaScript-level object.
class WasmTableObject
: public TorqueGeneratedWasmTableObject<WasmTableObject, JSObject> {
public:
class BodyDescriptor;
inline wasm::ValueType type(const wasm::WasmModule* module);
inline wasm::CanonicalValueType canonical_type(
const wasm::WasmModule* module);
// Use this when you don't care whether the type stored on the in-sandbox
// object might have been corrupted to contain an invalid type index.
// That implies that you can't even canonicalize the type!
inline wasm::ValueType unsafe_type();
DECL_TRUSTED_POINTER_ACCESSORS(trusted_data, WasmTrustedInstanceData)
DECL_TRUSTED_POINTER_ACCESSORS(trusted_dispatch_table, WasmDispatchTable)
DECL_VERIFIER(WasmTableObject)
V8_EXPORT_PRIVATE static int Grow(Isolate* isolate,
DirectHandle<WasmTableObject> table,
uint32_t count,
DirectHandle<Object> init_value);
// TODO(jkummerow): Consider getting rid of {type}, use {canonical_type}
// instead.
V8_EXPORT_PRIVATE static DirectHandle<WasmTableObject> New(
Isolate* isolate, DirectHandle<WasmTrustedInstanceData> trusted_data,
wasm::ValueType type, wasm::CanonicalValueType canonical_type,
uint32_t initial, bool has_maximum, uint64_t maximum,
DirectHandle<Object> initial_value, wasm::AddressType address_type,
DirectHandle<WasmDispatchTable>* out_dispatch_table = nullptr);
inline bool is_in_bounds(uint32_t entry_index);
inline bool is_table64() const;
// Get the declared maximum as uint64_t or nullopt if no maximum was declared.
inline std::optional<uint64_t> maximum_length_u64() const;
// Thin wrapper around {JsToWasmObject}.
static MaybeDirectHandle<Object> JSToWasmElement(
Isolate* isolate, DirectHandle<WasmTableObject> table,
DirectHandle<Object> entry, const char** error_message);
// This function will not handle JS objects; i.e., {entry} needs to be in wasm
// representation.
V8_EXPORT_PRIVATE static void Set(Isolate* isolate,
DirectHandle<WasmTableObject> table,
uint32_t index, DirectHandle<Object> entry);
V8_EXPORT_PRIVATE static DirectHandle<Object> Get(
Isolate* isolate, DirectHandle<WasmTableObject> table, uint32_t index);
V8_EXPORT_PRIVATE static void Fill(Isolate* isolate,
DirectHandle<WasmTableObject> table,
uint32_t start, DirectHandle<Object> entry,
uint32_t count);
// TODO(wasm): Unify these three methods into one.
static void UpdateDispatchTable(
Isolate* isolate, DirectHandle<WasmTableObject> table, int entry_index,
const wasm::WasmFunction* func,
DirectHandle<WasmTrustedInstanceData> target_instance
#if V8_ENABLE_DRUMBRAKE
,
int target_func_index
#endif // V8_ENABLE_DRUMBRAKE
);
static void UpdateDispatchTable(Isolate* isolate,
DirectHandle<WasmTableObject> table,
int entry_index,
DirectHandle<WasmJSFunction> function);
static void UpdateDispatchTable(Isolate* isolate,
DirectHandle<WasmTableObject> table,
int entry_index,
DirectHandle<WasmCapiFunction> capi_function);
void ClearDispatchTable(int index);
V8_EXPORT_PRIVATE static void SetFunctionTablePlaceholder(
Isolate* isolate, DirectHandle<WasmTableObject> table, int entry_index,
DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
int func_index);
// This function reads the content of a function table entry and returns it
// through the output parameters.
static void GetFunctionTableEntry(
Isolate* isolate, DirectHandle<WasmTableObject> table, int entry_index,
bool* is_valid, bool* is_null,
MaybeDirectHandle<WasmTrustedInstanceData>* instance_data,
int* function_index,
MaybeDirectHandle<WasmJSFunction>* maybe_js_function);
private:
// {entry} is either {Null} or a {WasmInternalFunction}.
static void SetFunctionTableEntry(Isolate* isolate,
DirectHandle<WasmTableObject> table,
int entry_index,
DirectHandle<Object> entry);
TQ_OBJECT_CONSTRUCTORS(WasmTableObject)
};
class WasmMemoryMapDescriptor
: public TorqueGeneratedWasmMemoryMapDescriptor<WasmMemoryMapDescriptor,
JSObject> {
public:
V8_EXPORT_PRIVATE static MaybeDirectHandle<WasmMemoryMapDescriptor>
NewFromAnonymous(Isolate* isolate, size_t length);
V8_EXPORT_PRIVATE static DirectHandle<WasmMemoryMapDescriptor>
NewFromFileDescriptor(
Isolate* isolate,
v8::WasmMemoryMapDescriptor::WasmFileDescriptor file_descriptor);
// Returns the number of bytes that got mapped into the WebAssembly.Memory.
V8_EXPORT_PRIVATE size_t MapDescriptor(DirectHandle<WasmMemoryObject> memory,
size_t offset);
// Returns `false` if an error occurred, otherwise `true`.
V8_EXPORT_PRIVATE bool UnmapDescriptor();
class BodyDescriptor;
TQ_OBJECT_CONSTRUCTORS(WasmMemoryMapDescriptor)
};
// Representation of a WebAssembly.Memory JavaScript-level object.
class WasmMemoryObject
: public TorqueGeneratedWasmMemoryObject<WasmMemoryObject, JSObject> {
public:
class BodyDescriptor;
DECL_ACCESSORS(instances, Tagged<WeakArrayList>)
// Add a use of this memory object to the given instance. This updates the
// internal weak list of instances that use this memory and also updates the
// fields of the instance to reference this memory's buffer.
// Note that we update both the non-shared and shared (if any) parts of the
// instance for faster access to shared memory.
V8_EXPORT_PRIVATE static void UseInInstance(
Isolate* isolate, DirectHandle<WasmMemoryObject> memory,
DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
DirectHandle<WasmTrustedInstanceData> shared_trusted_instance_data,
int memory_index_in_instance);
inline bool has_maximum_pages();
inline bool is_memory64() const;
V8_EXPORT_PRIVATE static DirectHandle<WasmMemoryObject> New(
Isolate* isolate, DirectHandle<JSArrayBuffer> buffer, int maximum,
wasm::AddressType address_type);
V8_EXPORT_PRIVATE static MaybeDirectHandle<WasmMemoryObject> New(
Isolate* isolate, int initial, int maximum, SharedFlag shared,
wasm::AddressType address_type);
// Assign a new (grown) buffer to this memory, also updating the shortcut
// fields of all instances that use this memory.
void SetNewBuffer(Isolate* isolate, Tagged<JSArrayBuffer> new_buffer);
// Updates all WebAssembly instances that use this Memory as a memory, after
// growing or refreshing the memory.
void UpdateInstances(Isolate* isolate);
// Fix up a resizable ArrayBuffer that exposes Wasm memory.
//
// Usually, an ArrayBuffer is setup from metadata on its BackingStore.
// However, ABs that are actually WebAssembly memories may have metadata that
// diverge from their BackingStore's.
//
// SABs' is_resizable_by_js may be true even when the BackingStore's
// equivalent field is false. This happens when there are both growable and
// non-growable SABs pointing to the same shared WebAssembly memory.
//
// AB and SABs' max_byte_length is the requested max passed to the
// WebAssembly.Memory constructor, while the BackingStore's max is an
// engine-determined heuristic that may be smaller.
//
// Both divergences are impossible for JS-created buffers.
void FixUpResizableArrayBuffer(Tagged<JSArrayBuffer> new_buffer);
// Detaches the existing buffer, makes a new buffer backed by
// new_backing_store, and update all the links.
static DirectHandle<JSArrayBuffer> RefreshBuffer(
Isolate* isolate, DirectHandle<WasmMemoryObject> memory,
std::shared_ptr<BackingStore> new_backing_store);
// Makes a new SharedArrayBuffer backed by the same backing store.
static DirectHandle<JSArrayBuffer> RefreshSharedBuffer(
Isolate* isolate, DirectHandle<WasmMemoryObject> memory,
DirectHandle<JSArrayBuffer> old_buffer, ResizableFlag resizable_by_js);
V8_EXPORT_PRIVATE static int32_t Grow(Isolate*,
DirectHandle<WasmMemoryObject>,
uint32_t pages);
// Makes the ArrayBuffer fixed-length. Assumes the current ArrayBuffer is
// resizable. Detaches the existing buffer if it is not shared.
static DirectHandle<JSArrayBuffer> ToFixedLengthBuffer(
Isolate* isolate, DirectHandle<WasmMemoryObject> memory,
DirectHandle<JSArrayBuffer> old_buffer);
// Makes the ArrayBuffer resizable by JS. Assumes the current ArrayBuffer is
// fixed-length. Detaches the existing buffer if it is not shared.
static DirectHandle<JSArrayBuffer> ToResizableBuffer(
Isolate* isolate, DirectHandle<WasmMemoryObject> memory,
DirectHandle<JSArrayBuffer> old_buffer);
static constexpr int kNoMaximum = -1;
TQ_OBJECT_CONSTRUCTORS(WasmMemoryObject)
};
// Representation of a WebAssembly.Global JavaScript-level object.
class WasmGlobalObject
: public TorqueGeneratedWasmGlobalObject<WasmGlobalObject, JSObject> {
public:
class BodyDescriptor;
DECL_ACCESSORS(untagged_buffer, Tagged<JSArrayBuffer>)
DECL_ACCESSORS(tagged_buffer, Tagged<FixedArray>)
DECL_PRIMITIVE_ACCESSORS(type, wasm::ValueType)
DECL_TRUSTED_POINTER_ACCESSORS(trusted_data, WasmTrustedInstanceData)
// Dispatched behavior.
DECL_PRINTER(WasmGlobalObject)
V8_EXPORT_PRIVATE static MaybeDirectHandle<WasmGlobalObject> New(
Isolate* isolate, DirectHandle<WasmTrustedInstanceData> instance_object,
MaybeDirectHandle<JSArrayBuffer> maybe_untagged_buffer,
MaybeDirectHandle<FixedArray> maybe_tagged_buffer, wasm::ValueType type,
int32_t offset, bool is_mutable);
inline int type_size() const;
inline int32_t GetI32();
inline int64_t GetI64();
inline float GetF32();
inline double GetF64();
inline uint8_t* GetS128RawBytes();
inline DirectHandle<Object> GetRef();
inline void SetI32(int32_t value);
inline void SetI64(int64_t value);
inline void SetF32(float value);
inline void SetF64(double value);
// {value} must be an object in Wasm representation.
inline void SetRef(DirectHandle<Object> value);
private:
// This function returns the address of the global's data in the
// JSArrayBuffer. This buffer may be allocated on-heap, in which case it may
// not have a fixed address.
inline Address address() const;
TQ_OBJECT_CONSTRUCTORS(WasmGlobalObject)
};
class FeedbackConstants {
public:
static constexpr int kHeaderSlots = 1;
static constexpr int kSlotsPerInstruction = 2;
};
// The trusted part of a WebAssembly instance.
// This object lives in trusted space and is never modified from user space.
class V8_EXPORT_PRIVATE WasmTrustedInstanceData : public ExposedTrustedObject {
public:
DECL_OPTIONAL_ACCESSORS(instance_object, Tagged<WasmInstanceObject>)
DECL_OPTIONAL_ACCESSORS(native_context, Tagged<Context>)
DECL_ACCESSORS(memory_objects, Tagged<FixedArray>)
#if V8_ENABLE_DRUMBRAKE
DECL_OPTIONAL_ACCESSORS(interpreter_object, Tagged<Tuple2>)
#endif // V8_ENABLE_DRUMBRAKE
DECL_OPTIONAL_ACCESSORS(untagged_globals_buffer, Tagged<JSArrayBuffer>)
DECL_OPTIONAL_ACCESSORS(tagged_globals_buffer, Tagged<FixedArray>)
DECL_OPTIONAL_ACCESSORS(imported_mutable_globals_buffers, Tagged<FixedArray>)
// tables: FixedArray of WasmTableObject.
DECL_OPTIONAL_ACCESSORS(tables, Tagged<FixedArray>)
DECL_PROTECTED_POINTER_ACCESSORS(dispatch_table_for_imports,
WasmDispatchTableForImports)
DECL_ACCESSORS(imported_mutable_globals, Tagged<FixedAddressArray>)
#if V8_ENABLE_DRUMBRAKE
// Points to an array that contains the function index for each imported Wasm
// function. This is required to call imported functions from the Wasm
// interpreter.
DECL_ACCESSORS(imported_function_indices, Tagged<FixedInt32Array>)
#endif // V8_ENABLE_DRUMBRAKE
DECL_PROTECTED_POINTER_ACCESSORS(shared_part, WasmTrustedInstanceData)
DECL_PROTECTED_POINTER_ACCESSORS(dispatch_table0, WasmDispatchTable)
DECL_PROTECTED_POINTER_ACCESSORS(dispatch_tables, ProtectedFixedArray)
DECL_OPTIONAL_ACCESSORS(tags_table, Tagged<FixedArray>)
DECL_ACCESSORS(func_refs, Tagged<FixedArray>)
DECL_ACCESSORS(managed_object_maps, Tagged<FixedArray>)
DECL_ACCESSORS(feedback_vectors, Tagged<FixedArray>)
DECL_ACCESSORS(well_known_imports, Tagged<FixedArray>)
DECL_PRIMITIVE_ACCESSORS(memory0_start, uint8_t*)
DECL_PRIMITIVE_ACCESSORS(memory0_size, size_t)
DECL_PROTECTED_POINTER_ACCESSORS(managed_native_module,
TrustedManaged<wasm::NativeModule>)
DECL_PRIMITIVE_ACCESSORS(globals_start, uint8_t*)
DECL_PRIMITIVE_ACCESSORS(jump_table_start, Address)
DECL_PRIMITIVE_ACCESSORS(hook_on_function_call_address, Address)
DECL_PRIMITIVE_ACCESSORS(tiering_budget_array, std::atomic<uint32_t>*)
DECL_PROTECTED_POINTER_ACCESSORS(memory_bases_and_sizes,
TrustedFixedAddressArray)
DECL_ACCESSORS(data_segment_starts, Tagged<FixedAddressArray>)
DECL_ACCESSORS(data_segment_sizes, Tagged<FixedUInt32Array>)
DECL_ACCESSORS(element_segments, Tagged<FixedArray>)
DECL_PRIMITIVE_ACCESSORS(break_on_entry, uint8_t)
// Clear uninitialized padding space. This ensures that the snapshot content
// is deterministic. Depending on the V8 build mode there could be no padding.
inline void clear_padding();
inline Tagged<WasmMemoryObject> memory_object(int memory_index) const;
inline uint8_t* memory_base(int memory_index) const;
inline size_t memory_size(int memory_index) const;
inline wasm::NativeModule* native_module() const;
inline Tagged<WasmModuleObject> module_object() const;
inline const wasm::WasmModule* module() const;
// Dispatched behavior.
DECL_PRINTER(WasmTrustedInstanceData)
DECL_VERIFIER(WasmTrustedInstanceData)
// Layout description.
#define FIELD_LIST(V) \
/* Often-accessed fields go first to minimize generated code size. */ \
/* Less than system pointer sized fields come first. */ \
V(kProtectedDispatchTable0Offset, kTaggedSize) \
V(kProtectedDispatchTableForImportsOffset, kTaggedSize) \
V(kImportedMutableGlobalsOffset, kTaggedSize) \
IF_WASM_DRUMBRAKE(V, kImportedFunctionIndicesOffset, kTaggedSize) \
/* Optional padding to align system pointer size fields */ \
V(kOptionalPaddingOffset, POINTER_SIZE_PADDING(kOptionalPaddingOffset)) \
V(kMemory0StartOffset, kSystemPointerSize) \
V(kMemory0SizeOffset, kSizetSize) \
V(kGlobalsStartOffset, kSystemPointerSize) \
V(kJumpTableStartOffset, kSystemPointerSize) \
/* End of often-accessed fields. */ \
/* Continue with system pointer size fields to maintain alignment. */ \
V(kHookOnFunctionCallAddressOffset, kSystemPointerSize) \
V(kTieringBudgetArrayOffset, kSystemPointerSize) \
/* Less than system pointer size aligned fields are below. */ \
V(kProtectedMemoryBasesAndSizesOffset, kTaggedSize) \
V(kDataSegmentStartsOffset, kTaggedSize) \
V(kDataSegmentSizesOffset, kTaggedSize) \
V(kElementSegmentsOffset, kTaggedSize) \
V(kInstanceObjectOffset, kTaggedSize) \
V(kNativeContextOffset, kTaggedSize) \
V(kProtectedSharedPartOffset, kTaggedSize) \
V(kMemoryObjectsOffset, kTaggedSize) \
V(kUntaggedGlobalsBufferOffset, kTaggedSize) \
V(kTaggedGlobalsBufferOffset, kTaggedSize) \
V(kImportedMutableGlobalsBuffersOffset, kTaggedSize) \
IF_WASM_DRUMBRAKE(V, kInterpreterObjectOffset, kTaggedSize) \
V(kTablesOffset, kTaggedSize) \
V(kProtectedDispatchTablesOffset, kTaggedSize) \
V(kTagsTableOffset, kTaggedSize) \
V(kFuncRefsOffset, kTaggedSize) \
V(kManagedObjectMapsOffset, kTaggedSize) \
V(kFeedbackVectorsOffset, kTaggedSize) \
V(kWellKnownImportsOffset, kTaggedSize) \
V(kProtectedManagedNativeModuleOffset, kTaggedSize) \
V(kBreakOnEntryOffset, kUInt8Size) \
/* More padding to make the header pointer-size aligned */ \
V(kHeaderPaddingOffset, POINTER_SIZE_PADDING(kHeaderPaddingOffset)) \
V(kHeaderSize, 0) \
V(kSize, 0)
DEFINE_FIELD_OFFSET_CONSTANTS(ExposedTrustedObject::kHeaderSize, FIELD_LIST)
static_assert(IsAligned(kHeaderSize, kTaggedSize));
// TODO(ishell, v8:8875): When pointer compression is enabled 8-byte size
// fields (external pointers, doubles and BigInt data) are only kTaggedSize
// aligned so checking for alignments of fields bigger than kTaggedSize
// doesn't make sense until v8:8875 is fixed.
#define ASSERT_FIELD_ALIGNED(offset, size) \
static_assert(size == 0 || IsAligned(offset, size) || \
(COMPRESS_POINTERS_BOOL && (size == kSystemPointerSize) && \
IsAligned(offset, kTaggedSize)));
FIELD_LIST(ASSERT_FIELD_ALIGNED)
#undef ASSERT_FIELD_ALIGNED
#undef FIELD_LIST
// GC support: List all tagged fields and protected fields.
// V(offset, name)
#define WASM_TAGGED_INSTANCE_DATA_FIELDS(V) \
V(kInstanceObjectOffset, "instance_object") \
V(kNativeContextOffset, "native_context") \
V(kMemoryObjectsOffset, "memory_objects") \
V(kUntaggedGlobalsBufferOffset, "untagged_globals_buffer") \
V(kTaggedGlobalsBufferOffset, "tagged_globals_buffer") \
V(kImportedMutableGlobalsBuffersOffset, "imported_mutable_globals_buffers") \
IF_WASM_DRUMBRAKE(V, kInterpreterObjectOffset, "interpreter_object") \
V(kTablesOffset, "tables") \
V(kTagsTableOffset, "tags_table") \
V(kFuncRefsOffset, "func_refs") \
V(kManagedObjectMapsOffset, "managed_object_maps") \
V(kFeedbackVectorsOffset, "feedback_vectors") \
V(kWellKnownImportsOffset, "well_known_imports") \
V(kImportedMutableGlobalsOffset, "imported_mutable_globals") \
IF_WASM_DRUMBRAKE(V, kImportedFunctionIndicesOffset, \
"imported_function_indices") \
V(kDataSegmentStartsOffset, "data_segment_starts") \
V(kDataSegmentSizesOffset, "data_segment_sizes") \
V(kElementSegmentsOffset, "element_segments")
#define WASM_PROTECTED_INSTANCE_DATA_FIELDS(V) \
V(kProtectedSharedPartOffset, "shared_part") \
V(kProtectedMemoryBasesAndSizesOffset, "memory_bases_and_sizes") \
V(kProtectedDispatchTable0Offset, "dispatch_table0") \
V(kProtectedDispatchTablesOffset, "dispatch_tables") \
V(kProtectedDispatchTableForImportsOffset, "dispatch_table_for_imports") \
V(kProtectedManagedNativeModuleOffset, "managed_native_module")
#define WASM_INSTANCE_FIELD_OFFSET(offset, _) offset,
#define WASM_INSTANCE_FIELD_NAME(_, name) name,
#if V8_ENABLE_DRUMBRAKE
static constexpr size_t kWasmInterpreterAdditionalFields = 2;
#else
static constexpr size_t kWasmInterpreterAdditionalFields = 0;
#endif // V8_ENABLE_DRUMBRAKE
static constexpr size_t kTaggedFieldsCount =
16 + kWasmInterpreterAdditionalFields;
static constexpr std::array<uint16_t, kTaggedFieldsCount>
kTaggedFieldOffsets = {
WASM_TAGGED_INSTANCE_DATA_FIELDS(WASM_INSTANCE_FIELD_OFFSET)};
static constexpr std::array<const char*, kTaggedFieldsCount>
kTaggedFieldNames = {
WASM_TAGGED_INSTANCE_DATA_FIELDS(WASM_INSTANCE_FIELD_NAME)};
static constexpr std::array<uint16_t, 6> kProtectedFieldOffsets = {
WASM_PROTECTED_INSTANCE_DATA_FIELDS(WASM_INSTANCE_FIELD_OFFSET)};
static constexpr std::array<const char*, 6> kProtectedFieldNames = {
WASM_PROTECTED_INSTANCE_DATA_FIELDS(WASM_INSTANCE_FIELD_NAME)};
#undef WASM_INSTANCE_FIELD_OFFSET
#undef WASM_INSTANCE_FIELD_NAME
#undef WASM_TAGGED_INSTANCE_DATA_FIELDS
#undef WASM_PROTECTED_INSTANCE_DATA_FIELDS
static_assert(kTaggedFieldOffsets.size() == kTaggedFieldNames.size(),
"every tagged field offset needs a name");
static_assert(kProtectedFieldOffsets.size() == kProtectedFieldNames.size(),
"every protected field offset needs a name");
void SetRawMemory(int memory_index, uint8_t* mem_start, size_t mem_size);
#if V8_ENABLE_DRUMBRAKE
// Get the interpreter object associated with the given wasm object.
// If no interpreter object exists yet, it is created automatically.
static DirectHandle<Tuple2> GetOrCreateInterpreterObject(
DirectHandle<WasmInstanceObject>);
static DirectHandle<Tuple2> GetInterpreterObject(
DirectHandle<WasmInstanceObject>);
#endif // V8_ENABLE_DRUMBRAKE
static DirectHandle<WasmTrustedInstanceData> New(
Isolate*, DirectHandle<WasmModuleObject>,
std::shared_ptr<wasm::NativeModule>, bool shared);
WasmCodePointer GetCallTarget(uint32_t func_index);
inline Tagged<WasmDispatchTable> dispatch_table(uint32_t table_index);
inline bool has_dispatch_table(uint32_t table_index);
// Copies table entries. Returns {false} if the ranges are out-of-bounds.
static bool CopyTableEntries(
Isolate* isolate,
DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
uint32_t table_dst_index, uint32_t table_src_index, uint32_t dst,
uint32_t src, uint32_t count) V8_WARN_UNUSED_RESULT;
// Loads a range of elements from element segment into a table.
// Returns the empty {Optional} if the operation succeeds, or an {Optional}
// with the error {MessageTemplate} if it fails.
static std::optional<MessageTemplate> InitTableEntries(
Isolate* isolate,
DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
DirectHandle<WasmTrustedInstanceData> shared_trusted_instance_data,
uint32_t table_index, uint32_t segment_index, uint32_t dst, uint32_t src,
uint32_t count) V8_WARN_UNUSED_RESULT;
class BodyDescriptor;
// Read a WasmFuncRef from the func_refs FixedArray. Returns true on success
// and writes the result in the output parameter. Returns false if no func_ref
// exists yet for this function. Use GetOrCreateFuncRef to always create one.
bool try_get_func_ref(int index, Tagged<WasmFuncRef>* result);
// Acquires the {WasmFuncRef} for a given {function_index} from the cache of
// the given {trusted_instance_data}, or creates a new {WasmInternalFunction}
// and {WasmFuncRef} if it does not exist yet. The new objects are added to
// the cache of the {trusted_instance_data} immediately.
// {precreate_external}: Allocate the corresponding WasmExportedFunction
// immediately (which is slightly more efficient than letting
// {WasmInternalFunction::GetOrCreateExternal} do the work separately).
static DirectHandle<WasmFuncRef> GetOrCreateFuncRef(
Isolate* isolate,
DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
int function_index,
wasm::PrecreateExternal precreate_external = wasm::kOnlyInternalFunction);
// Get a raw pointer to the location where the given global is stored.
// {global} must not be a reference type.
uint8_t* GetGlobalStorage(const wasm::WasmGlobal&);
// Get the FixedArray and the index in that FixedArray for the given global,
// which must be a reference type.
std::pair<Tagged<FixedArray>, uint32_t> GetGlobalBufferAndIndex(
const wasm::WasmGlobal&);
// Get the value of a global.
wasm::WasmValue GetGlobalValue(Isolate*, const wasm::WasmGlobal&);
OBJECT_CONSTRUCTORS(WasmTrustedInstanceData, ExposedTrustedObject);
private:
void InitDataSegmentArrays(const wasm::NativeModule*);
};
// Representation of a WebAssembly.Instance JavaScript-level object.
// This is mostly a wrapper around the WasmTrustedInstanceData, plus any
// user-set properties.
class WasmInstanceObject
: public TorqueGeneratedWasmInstanceObject<WasmInstanceObject, JSObject> {
public:
DECL_TRUSTED_POINTER_ACCESSORS(trusted_data, WasmTrustedInstanceData)
inline const wasm::WasmModule* module() const;
class BodyDescriptor;
DECL_PRINTER(WasmInstanceObject)
TQ_OBJECT_CONSTRUCTORS(WasmInstanceObject)
};
// Representation of WebAssembly.Exception JavaScript-level object.
class WasmTagObject
: public TorqueGeneratedWasmTagObject<WasmTagObject, JSObject> {
public:
class BodyDescriptor;
// Checks whether the given {sig} has the same parameter types as the
// serialized signature stored within this tag object.
bool MatchesSignature(wasm::CanonicalTypeIndex expected_index);
static DirectHandle<WasmTagObject> New(
Isolate* isolate, const wasm::FunctionSig* sig,
wasm::CanonicalTypeIndex type_index, DirectHandle<HeapObject> tag,
DirectHandle<WasmTrustedInstanceData> instance);
DECL_TRUSTED_POINTER_ACCESSORS(trusted_data, WasmTrustedInstanceData)
TQ_OBJECT_CONSTRUCTORS(WasmTagObject)
};
// Off-heap data object owned by a WasmDispatchTable. Owns the {shared_ptr}s
// which manage the lifetimes of the {WasmImportWrapperHandle}s.
class WasmDispatchTableData {
public:
// If a wrapper is installed at the given {index}, returns the corresponding
// {WasmImportWrapperHandle} so that it can be reused in other tables.
V8_EXPORT_PRIVATE
std::optional<std::shared_ptr<wasm::WasmImportWrapperHandle>>
MaybeGetWrapperHandle(int index) const;
#ifdef DEBUG
WasmCodePointer WrapperCodePointerForDebugging(int index);
#endif
void Add(int index,
std::shared_ptr<wasm::WasmImportWrapperHandle> wrapper_handle);
void Remove(int index);
private:
friend class WasmDispatchTable;
std::unordered_map<int, std::shared_ptr<wasm::WasmImportWrapperHandle>>
wrappers_;
};
// The dispatch table is referenced from a WasmTableObject and from every
// WasmTrustedInstanceData which uses the table. It is used from generated code
// for executing indirect calls.
class WasmDispatchTable : public ExposedTrustedObject {
public:
#if V8_ENABLE_DRUMBRAKE
static const uint32_t kInvalidFunctionIndex = UINT_MAX;
#endif // V8_ENABLE_DRUMBRAKE
// Indicate whether we are modifying an existing entry (for which we might
// have to update the ref count), or if we are initializing a slot for the
// first time (in which case we should not read the uninitialized memory).
enum NewOrExistingEntry : bool { kNewEntry, kExistingEntry };
class BodyDescriptor;
static constexpr size_t kLengthOffset = kHeaderSize;
static constexpr size_t kCapacityOffset = kLengthOffset + kUInt32Size;
static constexpr size_t kProtectedOffheapDataOffset =
kCapacityOffset + kUInt32Size;
static constexpr size_t kProtectedUsesOffset =
kProtectedOffheapDataOffset + kTaggedSize;
static constexpr size_t kTableTypeOffset = kProtectedUsesOffset + kTaggedSize;
static constexpr size_t kPaddingSize = TAGGED_SIZE_8_BYTES ? kUInt32Size : 0;
static constexpr size_t kEntriesOffset =
kTableTypeOffset + kUInt32Size + kPaddingSize;
// Entries consist of
// - target (WasmCodePointer == entry in WasmCodePointerTable),
#if V8_ENABLE_DRUMBRAKE
// - function_index (uint32_t) (located in place of target pointer),
#endif // V8_ENABLE_DRUMBRAKE
// - sig (canonical type index == uint32_t); unused for imports which check
// the signature statically,
// - implicit_arg (protected pointer, tagged sized).
static constexpr size_t kTargetBias = 0;
#if V8_ENABLE_DRUMBRAKE
// In jitless mode, reuse the 'target' field storage to hold the (uint32_t)
// function index.
static constexpr size_t kFunctionIndexBias = kTargetBias;
#endif // V8_ENABLE_DRUMBRAKE
static_assert(sizeof(WasmCodePointer) == kUInt32Size);
static constexpr size_t kSigBias = kTargetBias + kUInt32Size;
static constexpr size_t kImplicitArgBias = kSigBias + kUInt32Size;
static constexpr size_t kEntrySize = kImplicitArgBias + kTaggedSize;
// Tagged fields must be tagged-size-aligned.
static_assert(IsAligned(kProtectedOffheapDataOffset, kTaggedSize));
static_assert(IsAligned(kEntriesOffset, kTaggedSize));
static_assert(IsAligned(kEntrySize, kTaggedSize));
static_assert(IsAligned(kImplicitArgBias, kTaggedSize));
// The total byte size must still fit in an integer.
static constexpr int kMaxLength = (kMaxInt - kEntriesOffset) / kEntrySize;
static constexpr int SizeFor(int length) {
DCHECK_LE(length, kMaxLength);
return kEntriesOffset + length * kEntrySize;
}
static constexpr int OffsetOf(int index) {
DCHECK_LT(index, kMaxLength);
return SizeFor(index);
}
// The current length of this dispatch table. This is always <= the capacity.
inline int length() const;
inline int length(AcquireLoadTag) const;
// The current capacity. Can be bigger than the current length to allow for
// more efficient growing.
inline int capacity() const;
DECL_PROTECTED_POINTER_ACCESSORS(protected_offheap_data,
TrustedManaged<WasmDispatchTableData>)
inline WasmDispatchTableData* offheap_data() const;
// Stores all WasmTrustedInstanceData that refer to this WasmDispatchTable.
DECL_PROTECTED_POINTER_ACCESSORS(protected_uses, ProtectedWeakFixedArray)
// Stores the canonical type of the table.
DECL_PRIMITIVE_ACCESSORS(table_type, wasm::CanonicalValueType)
// {implicit_arg} will be a WasmImportData, a WasmTrustedInstanceData, or
// Smi::zero() (if the entry was cleared).
inline Tagged<Object> implicit_arg(int index) const;
inline WasmCodePointer target(int index) const;
inline wasm::CanonicalTypeIndex sig(int index) const;
// Set an entry for indirect calls that don't go to a WasmToJS wrapper.
// Wrappers are special since we own the CPT entries for the wrappers.
// {implicit_arg} has to be a WasmTrustedInstanceData, or Smi::zero() for
// clearing the slot.
void V8_EXPORT_PRIVATE SetForNonWrapper(
int index, Tagged<Union<Smi, WasmTrustedInstanceData>> implicit_arg,
WasmCodePointer call_target, wasm::CanonicalTypeIndex sig_id,
#if V8_ENABLE_DRUMBRAKE
uint32_t function_index,
#endif // V8_ENABLE_DRUMBRAKE
NewOrExistingEntry new_or_existing);
// Set an entry for indirect calls to a WasmToJS wrapper.
void V8_EXPORT_PRIVATE
SetForWrapper(int index, Tagged<WasmImportData> implicit_arg,
std::shared_ptr<wasm::WasmImportWrapperHandle> wrapper_handle,
wasm::CanonicalTypeIndex sig_id,
#if V8_ENABLE_DRUMBRAKE
uint32_t function_index,
#endif // V8_ENABLE_DRUMBRAKE
NewOrExistingEntry new_or_existing);
#if V8_ENABLE_DRUMBRAKE
inline uint32_t function_index(int index) const;
#endif // V8_ENABLE_DRUMBRAKE
void Clear(int index, NewOrExistingEntry new_or_existing);
std::optional<std::shared_ptr<wasm::WasmImportWrapperHandle>>
MaybeGetWrapperHandle(int index);
static void V8_EXPORT_PRIVATE
AddUse(Isolate* isolate, DirectHandle<WasmDispatchTable> dispatch_table,
DirectHandle<WasmTrustedInstanceData> instance, int table_index);
// Internal helpers for management of the uses list. These could be factored
// out into a class similar to WeakArrayList if there are additional use
// cases for them.
// The first slot in the list is the used length. After that, we store
// pairs of <instance, table_index>.
static Tagged<ProtectedWeakFixedArray> MaybeGrowUsesList(
Isolate* isolate, DirectHandle<WasmDispatchTable> dispatch_table);
static V8_WARN_UNUSED_RESULT DirectHandle<WasmDispatchTable> Grow(
Isolate*, DirectHandle<WasmDispatchTable>, uint32_t new_length);
DECL_PRINTER(WasmDispatchTable)
DECL_VERIFIER(WasmDispatchTable)
OBJECT_CONSTRUCTORS(WasmDispatchTable, ExposedTrustedObject);
};
class WasmDispatchTableForImports : public TrustedObject {
public:
class BodyDescriptor;
static constexpr size_t kLengthOffset = kHeaderSize;
static constexpr size_t kPaddingSize = TAGGED_SIZE_8_BYTES ? kUInt32Size : 0;
static constexpr size_t kProtectedOffheapDataOffset =
kLengthOffset + kUInt32Size + kPaddingSize;
static constexpr size_t kEntriesOffset =
kProtectedOffheapDataOffset + kTaggedSize;
// Entries consist of
// - target (WasmCodePointer == entry in WasmCodePointerTable),
#if V8_ENABLE_DRUMBRAKE
// - function_index (uint32_t) (located in place of target pointer),
#endif // V8_ENABLE_DRUMBRAKE
// - implicit_arg (protected pointer, tagged sized).
static constexpr size_t kTargetBias = 0;
#if V8_ENABLE_DRUMBRAKE
// In jitless mode, reuse the 'target' field storage to hold the (uint32_t)
// function index.
static constexpr size_t kFunctionIndexBias = kTargetBias;
#endif // V8_ENABLE_DRUMBRAKE
static constexpr size_t kEntryPaddingSize =
TAGGED_SIZE_8_BYTES ? kUInt32Size : 0;
static_assert(sizeof(WasmCodePointer) == kUInt32Size);
static constexpr size_t kImplicitArgBias =
kTargetBias + kEntryPaddingSize + kUInt32Size;
static constexpr size_t kEntrySize = kImplicitArgBias + kTaggedSize;
// Tagged fields must be tagged-size-aligned.
static_assert(IsAligned(kProtectedOffheapDataOffset, kTaggedSize));
static_assert(IsAligned(kEntriesOffset, kTaggedSize));
static_assert(IsAligned(kEntrySize, kTaggedSize));
static_assert(IsAligned(kImplicitArgBias, kTaggedSize));
// The total byte size must still fit in an integer.
static constexpr int kMaxLength = (kMaxInt - kEntriesOffset) / kEntrySize;
static constexpr int SizeFor(int length) {
DCHECK_LE(length, kMaxLength);
return kEntriesOffset + length * kEntrySize;
}
static constexpr int OffsetOf(int index) {
DCHECK_LT(index, kMaxLength);
return SizeFor(index);
}
// The current length of this dispatch table. This is always <= the capacity.
inline int length() const;
inline int length(AcquireLoadTag) const;
DECL_PROTECTED_POINTER_ACCESSORS(protected_offheap_data,
TrustedManaged<WasmDispatchTableData>)
inline WasmDispatchTableData* offheap_data() const;
// {implicit_arg} will be a WasmImportData, a WasmTrustedInstanceData, or
// Smi::zero() (if the entry was cleared).