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

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

Issue 2385943002: Revert of [wasm] further simplification of WasmCompiledModule (Closed)
Patch Set: Created 4 years, 2 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 | « no previous file | src/wasm/wasm-module.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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_MODULE_H_ 5 #ifndef V8_WASM_MODULE_H_
6 #define V8_WASM_MODULE_H_ 6 #define V8_WASM_MODULE_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "src/api.h" 10 #include "src/api.h"
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 \ 367 \
368 bool has_##NAME() const { return get(ID)->Is##TYPE(); } \ 368 bool has_##NAME() const { return get(ID)->Is##TYPE(); } \
369 \ 369 \
370 void reset_##NAME() { set_undefined(ID); } 370 void reset_##NAME() { set_undefined(ID); }
371 371
372 #define WCM_OBJECT(TYPE, NAME) WCM_OBJECT_OR_WEAK(TYPE, NAME, kID_##NAME) 372 #define WCM_OBJECT(TYPE, NAME) WCM_OBJECT_OR_WEAK(TYPE, NAME, kID_##NAME)
373 373
374 #define WCM_SMALL_NUMBER(TYPE, NAME) \ 374 #define WCM_SMALL_NUMBER(TYPE, NAME) \
375 TYPE NAME() const { \ 375 TYPE NAME() const { \
376 return static_cast<TYPE>(Smi::cast(get(kID_##NAME))->value()); \ 376 return static_cast<TYPE>(Smi::cast(get(kID_##NAME))->value()); \
377 } \
378 \
379 void set_##NAME(TYPE value) { \
380 set(kID_##NAME, Smi::FromInt(static_cast<int>(value))); \
381 }
382
383 #define WCM_LARGE_NUMBER(TYPE, NAME) \
384 TYPE NAME() const { \
385 return static_cast<TYPE>(HeapNumber::cast(get(kID_##NAME))->value()); \
386 } \
387 \
388 void set_##NAME(TYPE value) { \
389 HeapNumber::cast(get(kID_##NAME))->set_value(static_cast<double>(value)); \
377 } 390 }
378 391
379 #define WCM_WEAK_LINK(TYPE, NAME) \ 392 #define WCM_WEAK_LINK(TYPE, NAME) \
380 WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME); \ 393 WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME); \
381 \ 394 \
382 Handle<TYPE> NAME() const { \ 395 Handle<TYPE> NAME() const { \
383 return handle(TYPE::cast(weak_##NAME()->value())); \ 396 return handle(TYPE::cast(weak_##NAME()->value())); \
384 } 397 }
385 398
386 #define WCM_PROPERTY_TABLE(MACRO) \ 399 #define WCM_PROPERTY_TABLE(MACRO) \
387 MACRO(OBJECT, FixedArray, code_table) \ 400 MACRO(OBJECT, FixedArray, code_table) \
388 MACRO(OBJECT, FixedArray, import_data) \ 401 MACRO(OBJECT, FixedArray, import_data) \
389 MACRO(OBJECT, FixedArray, exports) \ 402 MACRO(OBJECT, FixedArray, exports) \
390 MACRO(OBJECT, FixedArray, startup_function) \ 403 MACRO(OBJECT, FixedArray, startup_function) \
391 MACRO(OBJECT, FixedArray, indirect_function_tables) \ 404 MACRO(OBJECT, FixedArray, indirect_function_tables) \
392 MACRO(OBJECT, String, module_bytes) \ 405 MACRO(OBJECT, String, module_bytes) \
393 MACRO(OBJECT, ByteArray, function_names) \ 406 MACRO(OBJECT, ByteArray, function_names) \
394 MACRO(SMALL_NUMBER, uint32_t, min_memory_pages) \ 407 MACRO(LARGE_NUMBER, uint32_t, min_required_memory) \
395 MACRO(OBJECT, FixedArray, data_segments_info) \ 408 MACRO(OBJECT, FixedArray, data_segments_info) \
396 MACRO(OBJECT, ByteArray, data_segments) \ 409 MACRO(OBJECT, ByteArray, data_segments) \
397 MACRO(SMALL_NUMBER, uint32_t, globals_size) \ 410 MACRO(LARGE_NUMBER, uint32_t, globals_size) \
398 MACRO(OBJECT, JSArrayBuffer, heap) \ 411 MACRO(LARGE_NUMBER, uint32_t, mem_size) \
412 MACRO(OBJECT, JSArrayBuffer, mem_start) \
399 MACRO(SMALL_NUMBER, bool, export_memory) \ 413 MACRO(SMALL_NUMBER, bool, export_memory) \
400 MACRO(SMALL_NUMBER, ModuleOrigin, origin) \ 414 MACRO(SMALL_NUMBER, ModuleOrigin, origin) \
401 MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \ 415 MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \
402 MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \ 416 MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \
403 MACRO(WEAK_LINK, JSObject, owning_instance) \ 417 MACRO(WEAK_LINK, JSObject, owning_instance) \
404 MACRO(WEAK_LINK, JSObject, module_object) 418 MACRO(WEAK_LINK, JSObject, module_object)
405 419
406 private: 420 private:
407 enum PropertyIndices { 421 enum PropertyIndices {
408 #define INDICES(IGNORE1, IGNORE2, NAME) kID_##NAME, 422 #define INDICES(IGNORE1, IGNORE2, NAME) kID_##NAME,
409 WCM_PROPERTY_TABLE(INDICES) Count 423 WCM_PROPERTY_TABLE(INDICES) Count
410 #undef INDICES 424 #undef INDICES
411 }; 425 };
412 426
413 public: 427 public:
414 static Handle<WasmCompiledModule> New(Isolate* isolate, 428 static Handle<WasmCompiledModule> New(Isolate* isolate) {
415 uint32_t min_memory_pages, 429 Handle<FixedArray> ret =
416 uint32_t globals_size, 430 isolate->factory()->NewFixedArray(PropertyIndices::Count, TENURED);
417 bool export_memory, 431 Handle<HeapNumber> number;
418 ModuleOrigin origin); 432 #define WCM_INIT_OBJECT(IGNORE1, IGNORE2)
433 #define WCM_INIT_WEAK_LINK(IGNORE1, IGNORE2)
434 #define WCM_INIT_SMALL_NUMBER(IGNORE1, IGNORE2)
435 #define WCM_INIT_LARGE_NUMBER(IGNORE, NAME) \
436 number = isolate->factory()->NewHeapNumber(0.0, MUTABLE, TENURED); \
437 ret->set(kID_##NAME, *number);
438
439 #define INITIALIZER(KIND, TYPE, NAME) WCM_INIT_##KIND(TYPE, NAME)
440 WCM_PROPERTY_TABLE(INITIALIZER)
441 #undef INITIALIZER
442 return handle(WasmCompiledModule::cast(*ret));
443 }
419 444
420 static Handle<WasmCompiledModule> Clone(Isolate* isolate, 445 static Handle<WasmCompiledModule> Clone(Isolate* isolate,
421 Handle<WasmCompiledModule> module) { 446 Handle<WasmCompiledModule> module) {
422 Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast( 447 Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast(
423 isolate->factory()->CopyFixedArray(module)); 448 isolate->factory()->CopyFixedArray(module));
449 Handle<HeapNumber> number =
450 isolate->factory()->NewHeapNumber(0.0, MUTABLE, TENURED);
451 ret->set(kID_mem_size, *number);
452 ret->set_mem_size(module->mem_size());
424 return ret; 453 return ret;
425 } 454 }
426 455
427 uint32_t mem_size() const {
428 DCHECK(has_heap());
429 return heap()->byte_length()->Number();
430 }
431
432 uint32_t default_mem_size() const {
433 return min_memory_pages() * WasmModule::kPageSize;
434 }
435
436 #define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME) 456 #define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME)
437 WCM_PROPERTY_TABLE(DECLARATION) 457 WCM_PROPERTY_TABLE(DECLARATION)
438 #undef DECLARATION 458 #undef DECLARATION
439 459
440 private: 460 private:
441 DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule); 461 DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule);
442 }; 462 };
443 463
444 // Extract a function name from the given wasm object. 464 // Extract a function name from the given wasm object.
445 // Returns "<WASM UNNAMED>" if the function is unnamed or the name is not a 465 // Returns "<WASM UNNAMED>" if the function is unnamed or the name is not a
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 int instance_count); 545 int instance_count);
526 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); 546 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj);
527 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); 547 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance);
528 548
529 } // namespace testing 549 } // namespace testing
530 } // namespace wasm 550 } // namespace wasm
531 } // namespace internal 551 } // namespace internal
532 } // namespace v8 552 } // namespace v8
533 553
534 #endif // V8_WASM_MODULE_H_ 554 #endif // V8_WASM_MODULE_H_
OLDNEW
« no previous file with comments | « no previous file | src/wasm/wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698