From 637b7d645c797003a295e91f9692079c0615b335 Mon Sep 17 00:00:00 2001 From: Michael Starzinger Date: Tue, 25 Jul 2017 17:00:30 +0200 Subject: [PATCH] [asm.js] Switch StdlibSet to be a uint64_t bit set. This switches the {StdlibSet} to be a data structure that does not require dynamic memory allocation. This makes it easier to carry it around as part of a {CompilationJob} and serialize it into the heap. R=clemensh@chromium.org Change-Id: I77b2353cfdcd9438a26f04d00749159fed9b9b6c Reviewed-on: https://chromium-review.googlesource.com/584868 Commit-Queue: Michael Starzinger Reviewed-by: Clemens Hammacher Cr-Commit-Position: refs/heads/master@{#46889} --- src/asmjs/asm-js.cc | 139 ++++++++++++++++++++-------------------- src/asmjs/asm-parser.cc | 10 +-- src/asmjs/asm-parser.h | 4 +- 3 files changed, 77 insertions(+), 76 deletions(-) diff --git a/src/asmjs/asm-js.cc b/src/asmjs/asm-js.cc index 077362510e..4c5a2e9bed 100644 --- a/src/asmjs/asm-js.cc +++ b/src/asmjs/asm-js.cc @@ -34,7 +34,7 @@ const char* const AsmJs::kSingleFunctionName = "__single_function__"; namespace { enum WasmDataEntries { kWasmDataCompiledModule, - kWasmDataUsesArray, + kWasmDataUsesBitSet, kWasmDataEntryCount, }; @@ -49,62 +49,69 @@ Handle StdlibMathMember(Isolate* isolate, Handle stdlib, return value; } -bool IsStdlibMemberValid(Isolate* isolate, Handle stdlib, - wasm::AsmJsParser::StandardMember member, - bool* is_typed_array) { - switch (member) { - case wasm::AsmJsParser::StandardMember::kInfinity: { - Handle name = isolate->factory()->Infinity_string(); - Handle value = JSReceiver::GetDataProperty(stdlib, name); - return value->IsNumber() && std::isinf(value->Number()); - } - case wasm::AsmJsParser::StandardMember::kNaN: { - Handle name = isolate->factory()->NaN_string(); - Handle value = JSReceiver::GetDataProperty(stdlib, name); - return value->IsNaN(); - } -#define STDLIB_MATH_FUNC(fname, FName, ignore1, ignore2) \ - case wasm::AsmJsParser::StandardMember::kMath##FName: { \ - Handle name(isolate->factory()->InternalizeOneByteString( \ - STATIC_CHAR_VECTOR(#fname))); \ - Handle value = StdlibMathMember(isolate, stdlib, name); \ - if (!value->IsJSFunction()) return false; \ - Handle func = Handle::cast(value); \ - return func->shared()->code() == \ - isolate->builtins()->builtin(Builtins::kMath##FName); \ +bool AreStdlibMembersValid(Isolate* isolate, Handle stdlib, + wasm::AsmJsParser::StdlibSet members, + bool* is_typed_array) { + if (members.Contains(wasm::AsmJsParser::StandardMember::kInfinity)) { + members.Remove(wasm::AsmJsParser::StandardMember::kInfinity); + Handle name = isolate->factory()->Infinity_string(); + Handle value = JSReceiver::GetDataProperty(stdlib, name); + if (!value->IsNumber() || !std::isinf(value->Number())) return false; } - STDLIB_MATH_FUNCTION_LIST(STDLIB_MATH_FUNC) + if (members.Contains(wasm::AsmJsParser::StandardMember::kNaN)) { + members.Remove(wasm::AsmJsParser::StandardMember::kNaN); + Handle name = isolate->factory()->NaN_string(); + Handle value = JSReceiver::GetDataProperty(stdlib, name); + if (!value->IsNaN()) return false; + } +#define STDLIB_MATH_FUNC(fname, FName, ignore1, ignore2) \ + if (members.Contains(wasm::AsmJsParser::StandardMember::kMath##FName)) { \ + members.Remove(wasm::AsmJsParser::StandardMember::kMath##FName); \ + Handle name(isolate->factory()->InternalizeOneByteString( \ + STATIC_CHAR_VECTOR(#fname))); \ + Handle value = StdlibMathMember(isolate, stdlib, name); \ + if (!value->IsJSFunction()) return false; \ + Handle func = Handle::cast(value); \ + if (func->shared()->code() != \ + isolate->builtins()->builtin(Builtins::kMath##FName)) { \ + return false; \ + } \ + } + STDLIB_MATH_FUNCTION_LIST(STDLIB_MATH_FUNC) #undef STDLIB_MATH_FUNC -#define STDLIB_MATH_CONST(cname, const_value) \ - case wasm::AsmJsParser::StandardMember::kMath##cname: { \ - Handle name(isolate->factory()->InternalizeOneByteString( \ - STATIC_CHAR_VECTOR(#cname))); \ - Handle value = StdlibMathMember(isolate, stdlib, name); \ - return value->IsNumber() && value->Number() == const_value; \ +#define STDLIB_MATH_CONST(cname, const_value) \ + if (members.Contains(wasm::AsmJsParser::StandardMember::kMath##cname)) { \ + members.Remove(wasm::AsmJsParser::StandardMember::kMath##cname); \ + Handle name(isolate->factory()->InternalizeOneByteString( \ + STATIC_CHAR_VECTOR(#cname))); \ + Handle value = StdlibMathMember(isolate, stdlib, name); \ + if (!value->IsNumber() || value->Number() != const_value) return false; \ } - STDLIB_MATH_VALUE_LIST(STDLIB_MATH_CONST) + STDLIB_MATH_VALUE_LIST(STDLIB_MATH_CONST) #undef STDLIB_MATH_CONST -#define STDLIB_ARRAY_TYPE(fname, FName) \ - case wasm::AsmJsParser::StandardMember::k##FName: { \ - *is_typed_array = true; \ - Handle name(isolate->factory()->InternalizeOneByteString( \ - STATIC_CHAR_VECTOR(#FName))); \ - Handle value = JSReceiver::GetDataProperty(stdlib, name); \ - if (!value->IsJSFunction()) return false; \ - Handle func = Handle::cast(value); \ - return func.is_identical_to(isolate->fname()); \ +#define STDLIB_ARRAY_TYPE(fname, FName) \ + if (members.Contains(wasm::AsmJsParser::StandardMember::k##FName)) { \ + members.Remove(wasm::AsmJsParser::StandardMember::k##FName); \ + *is_typed_array = true; \ + Handle name(isolate->factory()->InternalizeOneByteString( \ + STATIC_CHAR_VECTOR(#FName))); \ + Handle value = JSReceiver::GetDataProperty(stdlib, name); \ + if (!value->IsJSFunction()) return false; \ + Handle func = Handle::cast(value); \ + if (!func.is_identical_to(isolate->fname())) return false; \ } - STDLIB_ARRAY_TYPE(int8_array_fun, Int8Array) - STDLIB_ARRAY_TYPE(uint8_array_fun, Uint8Array) - STDLIB_ARRAY_TYPE(int16_array_fun, Int16Array) - STDLIB_ARRAY_TYPE(uint16_array_fun, Uint16Array) - STDLIB_ARRAY_TYPE(int32_array_fun, Int32Array) - STDLIB_ARRAY_TYPE(uint32_array_fun, Uint32Array) - STDLIB_ARRAY_TYPE(float32_array_fun, Float32Array) - STDLIB_ARRAY_TYPE(float64_array_fun, Float64Array) + STDLIB_ARRAY_TYPE(int8_array_fun, Int8Array) + STDLIB_ARRAY_TYPE(uint8_array_fun, Uint8Array) + STDLIB_ARRAY_TYPE(int16_array_fun, Int16Array) + STDLIB_ARRAY_TYPE(uint16_array_fun, Uint16Array) + STDLIB_ARRAY_TYPE(int32_array_fun, Int32Array) + STDLIB_ARRAY_TYPE(uint32_array_fun, Uint32Array) + STDLIB_ARRAY_TYPE(float32_array_fun, Float32Array) + STDLIB_ARRAY_TYPE(float64_array_fun, Float64Array) #undef STDLIB_ARRAY_TYPE - } - UNREACHABLE(); + // All members accounted for. + DCHECK(members.IsEmpty()); + return true; } void Report(Handle