Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/wasm/wasm-objects.h

Issue 2784233004: [wasm] Further simplify WasmCompiledModule. (Closed)
Patch Set: . Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | src/wasm/wasm-objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_WASM_OBJECTS_H_ 5 #ifndef V8_WASM_OBJECTS_H_
6 #define V8_WASM_OBJECTS_H_ 6 #define V8_WASM_OBJECTS_H_
7 7
8 #include "src/debug/debug.h" 8 #include "src/debug/debug.h"
9 #include "src/debug/interface-types.h" 9 #include "src/debug/interface-types.h"
10 #include "src/objects.h" 10 #include "src/objects.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // we embed them as objects, and they may move. 251 // we embed them as objects, and they may move.
252 class WasmCompiledModule : public FixedArray { 252 class WasmCompiledModule : public FixedArray {
253 public: 253 public:
254 enum Fields { kFieldCount }; 254 enum Fields { kFieldCount };
255 255
256 static WasmCompiledModule* cast(Object* fixed_array) { 256 static WasmCompiledModule* cast(Object* fixed_array) {
257 SLOW_DCHECK(IsWasmCompiledModule(fixed_array)); 257 SLOW_DCHECK(IsWasmCompiledModule(fixed_array));
258 return reinterpret_cast<WasmCompiledModule*>(fixed_array); 258 return reinterpret_cast<WasmCompiledModule*>(fixed_array);
259 } 259 }
260 260
261 #define WCM_OBJECT_OR_WEAK(TYPE, NAME, ID, TYPE_CHECK) \ 261 #define WCM_OBJECT_OR_WEAK(TYPE, NAME, ID, TYPE_CHECK, SETTER_MODIFIER) \
262 Handle<TYPE> NAME() const { return handle(ptr_to_##NAME()); } \ 262 public: \
263 \ 263 Handle<TYPE> NAME() const { return handle(ptr_to_##NAME()); } \
264 MaybeHandle<TYPE> maybe_##NAME() const { \ 264 \
265 if (has_##NAME()) return NAME(); \ 265 MaybeHandle<TYPE> maybe_##NAME() const { \
266 return MaybeHandle<TYPE>(); \ 266 if (has_##NAME()) return NAME(); \
267 } \ 267 return MaybeHandle<TYPE>(); \
268 \ 268 } \
269 TYPE* maybe_ptr_to_##NAME() const { \ 269 \
270 Object* obj = get(ID); \ 270 TYPE* maybe_ptr_to_##NAME() const { \
271 if (!(TYPE_CHECK)) return nullptr; \ 271 Object* obj = get(ID); \
272 return TYPE::cast(obj); \ 272 if (!(TYPE_CHECK)) return nullptr; \
273 } \ 273 return TYPE::cast(obj); \
274 \ 274 } \
275 TYPE* ptr_to_##NAME() const { \ 275 \
276 Object* obj = get(ID); \ 276 TYPE* ptr_to_##NAME() const { \
277 DCHECK(TYPE_CHECK); \ 277 Object* obj = get(ID); \
278 return TYPE::cast(obj); \ 278 DCHECK(TYPE_CHECK); \
279 } \ 279 return TYPE::cast(obj); \
280 \ 280 } \
281 void set_##NAME(Handle<TYPE> value) { set_ptr_to_##NAME(*value); } \ 281 \
282 \ 282 bool has_##NAME() const { \
283 void set_ptr_to_##NAME(TYPE* value) { set(ID, value); } \ 283 Object* obj = get(ID); \
284 \ 284 return TYPE_CHECK; \
285 bool has_##NAME() const { \ 285 } \
286 Object* obj = get(ID); \ 286 \
287 return TYPE_CHECK; \ 287 void reset_##NAME() { set_undefined(ID); } \
288 } \ 288 \
289 \ 289 SETTER_MODIFIER: \
290 void reset_##NAME() { set_undefined(ID); } 290 void set_##NAME(Handle<TYPE> value) { set_ptr_to_##NAME(*value); } \
291 void set_ptr_to_##NAME(TYPE* value) { set(ID, value); }
291 292
292 #define WCM_OBJECT(TYPE, NAME) \ 293 #define WCM_OBJECT(TYPE, NAME) \
293 WCM_OBJECT_OR_WEAK(TYPE, NAME, kID_##NAME, obj->Is##TYPE()) 294 WCM_OBJECT_OR_WEAK(TYPE, NAME, kID_##NAME, obj->Is##TYPE(), public)
295
296 #define WCM_CONST_OBJECT(TYPE, NAME) \
297 WCM_OBJECT_OR_WEAK(TYPE, NAME, kID_##NAME, obj->Is##TYPE(), private)
294 298
295 #define WCM_WASM_OBJECT(TYPE, NAME) \ 299 #define WCM_WASM_OBJECT(TYPE, NAME) \
296 WCM_OBJECT_OR_WEAK(TYPE, NAME, kID_##NAME, TYPE::Is##TYPE(obj)) 300 WCM_OBJECT_OR_WEAK(TYPE, NAME, kID_##NAME, TYPE::Is##TYPE(obj), private)
297 301
298 #define WCM_SMALL_FIXED_NUMBER(TYPE, NAME) \ 302 #define WCM_SMALL_CONST_NUMBER(TYPE, NAME) \
303 public: \
299 TYPE NAME() const { \ 304 TYPE NAME() const { \
300 return static_cast<TYPE>(Smi::cast(get(kID_##NAME))->value()); \ 305 return static_cast<TYPE>(Smi::cast(get(kID_##NAME))->value()); \
301 } \ 306 } \
307 \
308 private: \
302 void set_##NAME(TYPE value) { set(kID_##NAME, Smi::FromInt(value)); } 309 void set_##NAME(TYPE value) { set(kID_##NAME, Smi::FromInt(value)); }
303 310
304 #define WCM_SMALL_NUMBER(TYPE, NAME) \ 311 #define WCM_WEAK_LINK(TYPE, NAME) \
305 TYPE NAME() const { \ 312 WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME, obj->IsWeakCell(), \
306 return static_cast<TYPE>(Smi::cast(get(kID_##NAME))->value()); \ 313 public) \
307 } \ 314 \
308 void set_##NAME(TYPE value) { set(kID_##NAME, Smi::FromInt(value)); } \ 315 public: \
309 bool has_##NAME() const { return get(kID_##NAME)->IsSmi(); } 316 Handle<TYPE> NAME() const { \
310 317 return handle(TYPE::cast(weak_##NAME()->value())); \
311 #define WCM_WEAK_LINK(TYPE, NAME) \
312 WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME, obj->IsWeakCell()); \
313 \
314 Handle<TYPE> NAME() const { \
315 return handle(TYPE::cast(weak_##NAME()->value())); \
316 } 318 }
317 319
318 #define WCM_LARGE_NUMBER(TYPE, NAME) \ 320 #define WCM_LARGE_NUMBER(TYPE, NAME) \
321 public: \
319 TYPE NAME() const { \ 322 TYPE NAME() const { \
320 Object* value = get(kID_##NAME); \ 323 Object* value = get(kID_##NAME); \
321 DCHECK(value->IsMutableHeapNumber()); \ 324 DCHECK(value->IsMutableHeapNumber()); \
322 return static_cast<TYPE>(HeapNumber::cast(value)->value()); \ 325 return static_cast<TYPE>(HeapNumber::cast(value)->value()); \
323 } \ 326 } \
324 \ 327 \
325 void set_##NAME(TYPE value) { \ 328 void set_##NAME(TYPE value) { \
326 Object* number = get(kID_##NAME); \ 329 Object* number = get(kID_##NAME); \
327 DCHECK(number->IsMutableHeapNumber()); \ 330 DCHECK(number->IsMutableHeapNumber()); \
328 HeapNumber::cast(number)->set_value(static_cast<double>(value)); \ 331 HeapNumber::cast(number)->set_value(static_cast<double>(value)); \
329 } \ 332 } \
330 \ 333 \
331 static void recreate_##NAME(Handle<WasmCompiledModule> obj, \ 334 static void recreate_##NAME(Handle<WasmCompiledModule> obj, \
332 Factory* factory, TYPE init_val) { \ 335 Factory* factory, TYPE init_val) { \
333 Handle<HeapNumber> number = factory->NewHeapNumber( \ 336 Handle<HeapNumber> number = factory->NewHeapNumber( \
334 static_cast<double>(init_val), MutableMode::MUTABLE, TENURED); \ 337 static_cast<double>(init_val), MutableMode::MUTABLE, TENURED); \
335 obj->set(kID_##NAME, *number); \ 338 obj->set(kID_##NAME, *number); \
336 } \ 339 } \
337 bool has_##NAME() const { return get(kID_##NAME)->IsMutableHeapNumber(); } 340 bool has_##NAME() const { return get(kID_##NAME)->IsMutableHeapNumber(); }
338 341
342 // Add values here if they are required for creating new instances or
343 // for deserialization, and if they are serializable.
344 // By default, instance values go to WasmInstanceObject, however, if
345 // we embed the generated code with a value, then we track that value here.
339 #define CORE_WCM_PROPERTY_TABLE(MACRO) \ 346 #define CORE_WCM_PROPERTY_TABLE(MACRO) \
340 MACRO(WASM_OBJECT, WasmSharedModuleData, shared) \ 347 MACRO(WASM_OBJECT, WasmSharedModuleData, shared) \
341 MACRO(OBJECT, Context, native_context) \ 348 MACRO(OBJECT, Context, native_context) \
342 MACRO(SMALL_FIXED_NUMBER, uint32_t, num_imported_functions) \ 349 MACRO(SMALL_CONST_NUMBER, uint32_t, num_imported_functions) \
343 MACRO(OBJECT, FixedArray, code_table) \ 350 MACRO(CONST_OBJECT, FixedArray, code_table) \
344 MACRO(OBJECT, FixedArray, weak_exported_functions) \ 351 MACRO(OBJECT, FixedArray, weak_exported_functions) \
345 MACRO(OBJECT, FixedArray, function_tables) \ 352 MACRO(OBJECT, FixedArray, function_tables) \
346 MACRO(OBJECT, FixedArray, signature_tables) \ 353 MACRO(OBJECT, FixedArray, signature_tables) \
347 MACRO(OBJECT, FixedArray, empty_function_tables) \ 354 MACRO(CONST_OBJECT, FixedArray, empty_function_tables) \
348 MACRO(LARGE_NUMBER, size_t, embedded_mem_start) \ 355 MACRO(LARGE_NUMBER, size_t, embedded_mem_start) \
349 MACRO(LARGE_NUMBER, size_t, globals_start) \ 356 MACRO(LARGE_NUMBER, size_t, globals_start) \
350 MACRO(LARGE_NUMBER, uint32_t, embedded_mem_size) \ 357 MACRO(LARGE_NUMBER, uint32_t, embedded_mem_size) \
351 MACRO(SMALL_FIXED_NUMBER, uint32_t, min_mem_pages) \ 358 MACRO(SMALL_CONST_NUMBER, uint32_t, min_mem_pages) \
352 MACRO(SMALL_FIXED_NUMBER, uint32_t, max_mem_pages) \ 359 MACRO(SMALL_CONST_NUMBER, uint32_t, max_mem_pages) \
353 MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \ 360 MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \
354 MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \ 361 MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \
355 MACRO(WEAK_LINK, JSObject, owning_instance) \ 362 MACRO(WEAK_LINK, JSObject, owning_instance) \
356 MACRO(WEAK_LINK, WasmModuleObject, wasm_module) 363 MACRO(WEAK_LINK, WasmModuleObject, wasm_module)
357 364
358 #if DEBUG 365 #if DEBUG
359 #define DEBUG_ONLY_TABLE(MACRO) MACRO(SMALL_NUMBER, uint32_t, instance_id) 366 #define DEBUG_ONLY_TABLE(MACRO) MACRO(SMALL_CONST_NUMBER, uint32_t, instance_id)
360 #else 367 #else
361 #define DEBUG_ONLY_TABLE(IGNORE) 368 #define DEBUG_ONLY_TABLE(IGNORE)
362 uint32_t instance_id() const { return static_cast<uint32_t>(-1); } 369 uint32_t instance_id() const { return static_cast<uint32_t>(-1); }
bradnelson 2017/04/04 21:04:13 Maybe explicitly mark public/private on this one.
Mircea Trofin 2017/04/04 23:05:36 Done.
363 #endif 370 #endif
364 371
365 #define WCM_PROPERTY_TABLE(MACRO) \ 372 #define WCM_PROPERTY_TABLE(MACRO) \
366 CORE_WCM_PROPERTY_TABLE(MACRO) \ 373 CORE_WCM_PROPERTY_TABLE(MACRO) \
367 DEBUG_ONLY_TABLE(MACRO) 374 DEBUG_ONLY_TABLE(MACRO)
368 375
369 private: 376 private:
370 enum PropertyIndices { 377 enum PropertyIndices {
371 #define INDICES(IGNORE1, IGNORE2, NAME) kID_##NAME, 378 #define INDICES(IGNORE1, IGNORE2, NAME) kID_##NAME,
372 WCM_PROPERTY_TABLE(INDICES) Count 379 WCM_PROPERTY_TABLE(INDICES) Count
373 #undef INDICES 380 #undef INDICES
374 }; 381 };
375 382
376 public: 383 public:
377 static Handle<WasmCompiledModule> New(Isolate* isolate, 384 static Handle<WasmCompiledModule> New(
378 Handle<WasmSharedModuleData> shared); 385 Isolate* isolate, Handle<WasmSharedModuleData> shared,
386 Handle<FixedArray> code_table,
387 MaybeHandle<FixedArray> maybe_empty_function_tables,
388 MaybeHandle<FixedArray> maybe_signature_tables);
379 389
380 static Handle<WasmCompiledModule> Clone(Isolate* isolate, 390 static Handle<WasmCompiledModule> Clone(Isolate* isolate,
381 Handle<WasmCompiledModule> module); 391 Handle<WasmCompiledModule> module);
382 static void Reset(Isolate* isolate, WasmCompiledModule* module); 392 static void Reset(Isolate* isolate, WasmCompiledModule* module);
383 393
384 Address GetEmbeddedMemStartOrNull() const { 394 Address GetEmbeddedMemStartOrNull() const {
385 DisallowHeapAllocation no_gc; 395 DisallowHeapAllocation no_gc;
386 if (has_embedded_mem_start()) { 396 if (has_embedded_mem_start()) {
387 return reinterpret_cast<Address>(embedded_mem_start()); 397 return reinterpret_cast<Address>(embedded_mem_start());
388 } 398 }
(...skipping 16 matching lines...) Expand all
405 Factory* factory, Handle<WasmCompiledModule> compiled_module, 415 Factory* factory, Handle<WasmCompiledModule> compiled_module,
406 Handle<JSArrayBuffer> buffer); 416 Handle<JSArrayBuffer> buffer);
407 static void SetGlobalsStartAddressFrom( 417 static void SetGlobalsStartAddressFrom(
408 Factory* factory, Handle<WasmCompiledModule> compiled_module, 418 Factory* factory, Handle<WasmCompiledModule> compiled_module,
409 Handle<JSArrayBuffer> buffer); 419 Handle<JSArrayBuffer> buffer);
410 420
411 #define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME) 421 #define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME)
412 WCM_PROPERTY_TABLE(DECLARATION) 422 WCM_PROPERTY_TABLE(DECLARATION)
413 #undef DECLARATION 423 #undef DECLARATION
414 424
425 public:
415 // Allow to call method on WasmSharedModuleData also on this object. 426 // Allow to call method on WasmSharedModuleData also on this object.
416 #define FORWARD_SHARED(type, name) \ 427 #define FORWARD_SHARED(type, name) \
417 type name() { return shared()->name(); } 428 type name() { return shared()->name(); }
418 FORWARD_SHARED(SeqOneByteString*, module_bytes) 429 FORWARD_SHARED(SeqOneByteString*, module_bytes)
419 FORWARD_SHARED(wasm::WasmModule*, module) 430 FORWARD_SHARED(wasm::WasmModule*, module)
420 FORWARD_SHARED(Script*, script) 431 FORWARD_SHARED(Script*, script)
421 FORWARD_SHARED(bool, is_asm_js) 432 FORWARD_SHARED(bool, is_asm_js)
422 #undef FORWARD_SHARED 433 #undef FORWARD_SHARED
423 434
424 static bool IsWasmCompiledModule(Object* obj); 435 static bool IsWasmCompiledModule(Object* obj);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 // call / exported function), func_index must be set. Otherwise it can be -1. 518 // call / exported function), func_index must be set. Otherwise it can be -1.
508 // If patch_caller is set, then all direct calls to functions which were 519 // If patch_caller is set, then all direct calls to functions which were
509 // already lazily compiled are patched (at least the given call site). 520 // already lazily compiled are patched (at least the given call site).
510 // Returns the Code to be called at the given call site, or an empty Handle if 521 // Returns the Code to be called at the given call site, or an empty Handle if
511 // an error occured during lazy compilation. In this case, an exception has 522 // an error occured during lazy compilation. In this case, an exception has
512 // been set on the isolate. 523 // been set on the isolate.
513 static MaybeHandle<Code> CompileLazy(Isolate*, Handle<WasmInstanceObject>, 524 static MaybeHandle<Code> CompileLazy(Isolate*, Handle<WasmInstanceObject>,
514 Handle<Code> caller, int offset, 525 Handle<Code> caller, int offset,
515 int func_index, bool patch_caller); 526 int func_index, bool patch_caller);
516 527
528 void ReplaceCodeTableForTesting(Handle<FixedArray> testing_table) {
529 set_code_table(testing_table);
530 }
531
517 private: 532 private:
518 void InitId(); 533 void InitId();
519 534
520 DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule); 535 DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule);
521 }; 536 };
522 537
523 class WasmDebugInfo : public FixedArray { 538 class WasmDebugInfo : public FixedArray {
524 public: 539 public:
525 // The 0-th field is used by the Blink Wrapper Tracer. 540 // The 0-th field is used by the Blink Wrapper Tracer.
526 enum Fields { 541 enum Fields {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 }; 648 };
634 }; 649 };
635 650
636 #undef DECLARE_ACCESSORS 651 #undef DECLARE_ACCESSORS
637 #undef DECLARE_OPTIONAL_ACCESSORS 652 #undef DECLARE_OPTIONAL_ACCESSORS
638 653
639 } // namespace internal 654 } // namespace internal
640 } // namespace v8 655 } // namespace v8
641 656
642 #endif // V8_WASM_OBJECTS_H_ 657 #endif // V8_WASM_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | src/wasm/wasm-objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698