Commit b0e4dce6 authored by yangguo's avatar yangguo Committed by Commit bot

Move math-related typed arrays off js builtins object..

Review URL: https://codereview.chromium.org/1420473002

Cr-Commit-Position: refs/heads/master@{#31481}
parent f464f12a
...@@ -199,7 +199,7 @@ class Genesis BASE_EMBEDDED { ...@@ -199,7 +199,7 @@ class Genesis BASE_EMBEDDED {
ContextType context_type); ContextType context_type);
void InitializeExperimentalGlobal(); void InitializeExperimentalGlobal();
// Typed arrays are not serializable and have to initialized afterwards. // Typed arrays are not serializable and have to initialized afterwards.
void InitializeBuiltinTypedArrays(); bool InitializeBuiltinTypedArrays();
// Depending on the situation, expose and/or get rid of the utils object. // Depending on the situation, expose and/or get rid of the utils object.
void ConfigureUtilsObject(ContextType context_type); void ConfigureUtilsObject(ContextType context_type);
...@@ -1791,42 +1791,36 @@ static Handle<JSObject> ResolveBuiltinIdHolder(Handle<Context> native_context, ...@@ -1791,42 +1791,36 @@ static Handle<JSObject> ResolveBuiltinIdHolder(Handle<Context> native_context,
template <typename Data> template <typename Data>
Data* SetBuiltinTypedArray(Isolate* isolate, Handle<JSBuiltinsObject> builtins, Handle<JSTypedArray> CreateTypedArray(Isolate* isolate, ExternalArrayType type,
ExternalArrayType type, Data* data, size_t num_elements, Data** data) {
size_t num_elements, const char* name, size_t byte_length = num_elements * sizeof(**data);
const SharedFlag shared = SharedFlag::kNotShared,
const PretenureFlag pretenure = TENURED) {
size_t byte_length = num_elements * sizeof(*data);
Handle<JSArrayBuffer> buffer = Handle<JSArrayBuffer> buffer =
isolate->factory()->NewJSArrayBuffer(shared, pretenure); isolate->factory()->NewJSArrayBuffer(SharedFlag::kNotShared, TENURED);
bool is_external = data != nullptr; bool is_external = (*data != nullptr);
if (!is_external) { if (!is_external) {
data = reinterpret_cast<Data*>( *data = reinterpret_cast<Data*>(
isolate->array_buffer_allocator()->Allocate(byte_length)); isolate->array_buffer_allocator()->Allocate(byte_length));
} }
JSArrayBuffer::Setup(buffer, isolate, is_external, data, byte_length, shared); JSArrayBuffer::Setup(buffer, isolate, is_external, *data, byte_length,
SharedFlag::kNotShared);
Handle<JSTypedArray> typed_array = isolate->factory()->NewJSTypedArray( return isolate->factory()->NewJSTypedArray(type, buffer, 0, num_elements,
type, buffer, 0, num_elements, pretenure); TENURED);
Handle<String> name_string = isolate->factory()->InternalizeUtf8String(name);
// Reset property cell type before (re)initializing.
JSBuiltinsObject::InvalidatePropertyCell(builtins, name_string);
JSObject::SetOwnPropertyIgnoreAttributes(builtins, name_string, typed_array,
FROZEN)
.Assert();
return data;
} }
void Genesis::InitializeBuiltinTypedArrays() { bool Genesis::InitializeBuiltinTypedArrays() {
Handle<JSBuiltinsObject> builtins(native_context()->builtins()); HandleScope scope(isolate());
{ // Initially seed the per-context random number generator using the Handle<JSTypedArray> rng_state;
// per-isolate random number generator. Handle<JSTypedArray> math_constants;
Handle<JSTypedArray> rempio2result;
{
// Seed the per-context RNG using the per-isolate RNG.
const size_t num_elements = 2; const size_t num_elements = 2;
const size_t num_bytes = num_elements * sizeof(uint32_t); const size_t num_bytes = num_elements * sizeof(uint32_t);
uint32_t* state = SetBuiltinTypedArray<uint32_t>(isolate(), builtins, uint32_t* state = NULL;
kExternalUint32Array, NULL, rng_state =
num_elements, "rngstate"); CreateTypedArray(isolate(), kExternalUint32Array, num_elements, &state);
do { do {
isolate()->random_number_generator()->NextBytes(state, num_bytes); isolate()->random_number_generator()->NextBytes(state, num_bytes);
} while (state[0] == 0 || state[1] == 0); } while (state[0] == 0 || state[1] == 0);
...@@ -1834,18 +1828,28 @@ void Genesis::InitializeBuiltinTypedArrays() { ...@@ -1834,18 +1828,28 @@ void Genesis::InitializeBuiltinTypedArrays() {
{ // Initialize trigonometric lookup tables and constants. { // Initialize trigonometric lookup tables and constants.
const size_t num_elements = arraysize(fdlibm::MathConstants::constants); const size_t num_elements = arraysize(fdlibm::MathConstants::constants);
double* data = const_cast<double*>(fdlibm::MathConstants::constants); double* constants = const_cast<double*>(fdlibm::MathConstants::constants);
SetBuiltinTypedArray<double>(isolate(), builtins, kExternalFloat64Array, math_constants = CreateTypedArray(isolate(), kExternalFloat64Array,
data, num_elements, "kMath"); num_elements, &constants);
} }
{ // Initialize a result array for rempio2 calculation { // Initialize a result array for rempio2 calculation
const size_t num_elements = 2; const size_t num_elements = 2;
double* data = double* data = NULL;
SetBuiltinTypedArray<double>(isolate(), builtins, kExternalFloat64Array, rempio2result =
NULL, num_elements, "rempio2result"); CreateTypedArray(isolate(), kExternalFloat64Array, num_elements, &data);
for (size_t i = 0; i < num_elements; i++) data[i] = 0; for (size_t i = 0; i < num_elements; i++) data[i] = 0;
} }
Handle<JSObject> utils =
Handle<JSObject>::cast(isolate()->natives_utils_object());
Handle<String> name_string = isolate()->factory()->NewStringFromAsciiChecked(
"InitializeBuiltinTypedArrays");
Handle<Object> fun = JSObject::GetDataProperty(utils, name_string);
Handle<Object> receiver = isolate()->factory()->undefined_value();
Handle<Object> args[] = {utils, rng_state, math_constants, rempio2result};
return !Execution::Call(isolate(), fun, receiver, arraysize(args), args)
.is_null();
} }
...@@ -3270,6 +3274,7 @@ Genesis::Genesis(Isolate* isolate, ...@@ -3270,6 +3274,7 @@ Genesis::Genesis(Isolate* isolate,
// snapshot as we should be able to turn them off at runtime. Re-installing // snapshot as we should be able to turn them off at runtime. Re-installing
// them after they have already been deserialized would also fail. // them after they have already been deserialized would also fail.
if (context_type == FULL_CONTEXT) { if (context_type == FULL_CONTEXT) {
if (!InitializeBuiltinTypedArrays()) return;
if (!isolate->serializer_enabled()) { if (!isolate->serializer_enabled()) {
InitializeExperimentalGlobal(); InitializeExperimentalGlobal();
if (!InstallExperimentalNatives()) return; if (!InstallExperimentalNatives()) return;
...@@ -3280,9 +3285,9 @@ Genesis::Genesis(Isolate* isolate, ...@@ -3280,9 +3285,9 @@ Genesis::Genesis(Isolate* isolate,
} }
// The serializer cannot serialize typed arrays. Reset those typed arrays // The serializer cannot serialize typed arrays. Reset those typed arrays
// for each new context. // for each new context.
InitializeBuiltinTypedArrays();
} else if (context_type == DEBUG_CONTEXT) { } else if (context_type == DEBUG_CONTEXT) {
DCHECK(!isolate->serializer_enabled()); DCHECK(!isolate->serializer_enabled());
if (!InitializeBuiltinTypedArrays()) return;
InitializeExperimentalGlobal(); InitializeExperimentalGlobal();
if (!InstallDebuggerNatives()) return; if (!InstallDebuggerNatives()) return;
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var rngstate; // Initialized to a Uint32Array during genesis.
(function(global, utils) { (function(global, utils) {
"use strict"; "use strict";
...@@ -16,8 +14,13 @@ var GlobalMath = global.Math; ...@@ -16,8 +14,13 @@ var GlobalMath = global.Math;
var GlobalObject = global.Object; var GlobalObject = global.Object;
var InternalArray = utils.InternalArray; var InternalArray = utils.InternalArray;
var NaN = %GetRootNaN(); var NaN = %GetRootNaN();
var rngstate;
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
utils.SetupTypedArray(function(arg1, arg2, arg3) {
rngstate = arg1;
});
//------------------------------------------------------------------- //-------------------------------------------------------------------
// ECMA 262 - 15.8.2.1 // ECMA 262 - 15.8.2.1
......
...@@ -14,6 +14,14 @@ ...@@ -14,6 +14,14 @@
var imports = UNDEFINED; var imports = UNDEFINED;
var imports_from_experimental = UNDEFINED; var imports_from_experimental = UNDEFINED;
var exports_container = %ExportFromRuntime({}); var exports_container = %ExportFromRuntime({});
var typed_array_setup = UNDEFINED;
// Register context value to be initialized with a typed array in
// Genesis::InitializeBuiltinTypedArrays.
function SetupTypedArray(f) {
f.next = typed_array_setup;
typed_array_setup = f;
}
// Export to other scripts. // Export to other scripts.
// In normal natives, this exports functions to other normal natives. // In normal natives, this exports functions to other normal natives.
...@@ -240,6 +248,9 @@ function PostExperimentals(utils) { ...@@ -240,6 +248,9 @@ function PostExperimentals(utils) {
utils.Export = UNDEFINED; utils.Export = UNDEFINED;
utils.PostDebug = UNDEFINED; utils.PostDebug = UNDEFINED;
utils.PostExperimentals = UNDEFINED; utils.PostExperimentals = UNDEFINED;
utils.InitializeBuiltinTypedArrays = UNDEFINED;
utils.SetupTypedArray = UNDEFINED;
typed_array_setup = UNDEFINED;
} }
...@@ -255,12 +266,25 @@ function PostDebug(utils) { ...@@ -255,12 +266,25 @@ function PostDebug(utils) {
utils.ImportNow = UNDEFINED; utils.ImportNow = UNDEFINED;
utils.PostDebug = UNDEFINED; utils.PostDebug = UNDEFINED;
utils.PostExperimentals = UNDEFINED; utils.PostExperimentals = UNDEFINED;
utils.InitializeBuiltinTypedArrays = UNDEFINED;
utils.SetupTypedArray = UNDEFINED;
typed_array_setup = UNDEFINED;
}
function InitializeBuiltinTypedArrays(
utils, rng_state, math_constants, rempio2result) {
var setup_list = typed_array_setup;
for ( ; !IS_UNDEFINED(setup_list); setup_list = setup_list.next) {
setup_list(rng_state, math_constants, rempio2result);
}
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
%OptimizeObjectForAddingMultipleProperties(utils, 13); %OptimizeObjectForAddingMultipleProperties(utils, 15);
utils.Import = Import; utils.Import = Import;
utils.ImportNow = ImportNow; utils.ImportNow = ImportNow;
...@@ -275,6 +299,8 @@ utils.SetUpLockedPrototype = SetUpLockedPrototype; ...@@ -275,6 +299,8 @@ utils.SetUpLockedPrototype = SetUpLockedPrototype;
utils.PostNatives = PostNatives; utils.PostNatives = PostNatives;
utils.PostExperimentals = PostExperimentals; utils.PostExperimentals = PostExperimentals;
utils.PostDebug = PostDebug; utils.PostDebug = PostDebug;
utils.SetupTypedArray = SetupTypedArray;
utils.InitializeBuiltinTypedArrays = InitializeBuiltinTypedArrays;
%ToFastProperties(utils); %ToFastProperties(utils);
......
...@@ -23,9 +23,6 @@ ...@@ -23,9 +23,6 @@
// rempio2result is used as a container for return values of %RemPiO2. It is // rempio2result is used as a container for return values of %RemPiO2. It is
// initialized to a two-element Float64Array during genesis. // initialized to a two-element Float64Array during genesis.
var kMath;
var rempio2result;
(function(global, utils) { (function(global, utils) {
"use strict"; "use strict";
...@@ -36,15 +33,22 @@ var rempio2result; ...@@ -36,15 +33,22 @@ var rempio2result;
// Imports // Imports
var GlobalMath = global.Math; var GlobalMath = global.Math;
var kMath;
var MathAbs; var MathAbs;
var MathExp; var MathExp;
var NaN = %GetRootNaN(); var NaN = %GetRootNaN();
var rempio2result;
utils.Import(function(from) { utils.Import(function(from) {
MathAbs = from.MathAbs; MathAbs = from.MathAbs;
MathExp = from.MathExp; MathExp = from.MathExp;
}); });
utils.SetupTypedArray(function(arg1, arg2, arg3) {
kMath = arg2;
rempio2result = arg3;
});
// ------------------------------------------------------------------- // -------------------------------------------------------------------
define INVPIO2 = kMath[0]; define INVPIO2 = kMath[0];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment