Commit e3e0f117 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

Statically initialize ExternalReference constants

Make values which are referenced via ExternalReference constexpr, and
initialize them statically. This avoids dynamic initialization and
protects them against being overwritten from generated code.

R=neis@chromium.org

Bug: v8:7570
Change-Id: I1c6c10fbffea12dc1f5bf726313bf8388e6530a1
Reviewed-on: https://chromium-review.googlesource.com/1013518Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52633}
parent 55110038
......@@ -54,38 +54,35 @@ namespace internal {
// -----------------------------------------------------------------------------
// Common double constants.
struct DoubleConstant BASE_EMBEDDED {
double min_int;
double one_half;
double minus_one_half;
double negative_infinity;
uint64_t the_hole_nan;
double uint32_bias;
};
static DoubleConstant double_constants;
static struct V8_ALIGNED(16) {
constexpr double double_min_int_constant = kMinInt;
constexpr double double_one_half_constant = 0.5;
constexpr double double_minus_one_half_constant = -0.5;
constexpr double double_negative_infinity_constant = -V8_INFINITY;
constexpr uint64_t double_the_hole_nan_constant = kHoleNanInt64;
constexpr double double_uint32_bias_constant =
static_cast<double>(kMaxUInt32) + 1;
constexpr struct V8_ALIGNED(16) {
uint32_t a;
uint32_t b;
uint32_t c;
uint32_t d;
} float_absolute_constant = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF};
static struct V8_ALIGNED(16) {
constexpr struct V8_ALIGNED(16) {
uint32_t a;
uint32_t b;
uint32_t c;
uint32_t d;
} float_negate_constant = {0x80000000, 0x80000000, 0x80000000, 0x80000000};
static struct V8_ALIGNED(16) {
constexpr struct V8_ALIGNED(16) {
uint64_t a;
uint64_t b;
} double_absolute_constant = {uint64_t{0x7FFFFFFFFFFFFFFF},
uint64_t{0x7FFFFFFFFFFFFFFF}};
static struct V8_ALIGNED(16) {
constexpr struct V8_ALIGNED(16) {
uint64_t a;
uint64_t b;
} double_negate_constant = {uint64_t{0x8000000000000000},
......@@ -103,16 +100,6 @@ static ExternalReference::Type BuiltinCallTypeForResultSize(int result_size) {
UNREACHABLE();
}
void ExternalReference::SetUp() {
double_constants.min_int = kMinInt;
double_constants.one_half = 0.5;
double_constants.minus_one_half = -0.5;
double_constants.the_hole_nan = kHoleNanInt64;
double_constants.negative_infinity = -V8_INFINITY;
double_constants.uint32_bias =
static_cast<double>(static_cast<uint32_t>(0xFFFFFFFF)) + 1;
}
ExternalReference::ExternalReference(Address address, Isolate* isolate)
: address_(Redirect(isolate, address)) {}
......@@ -505,53 +492,55 @@ ExternalReference ExternalReference::address_of_pending_message_obj(
}
ExternalReference ExternalReference::address_of_min_int(Isolate* isolate) {
return ExternalReference(reinterpret_cast<void*>(&double_constants.min_int));
return ExternalReference(reinterpret_cast<Address>(&double_min_int_constant));
}
ExternalReference ExternalReference::address_of_one_half(Isolate* isolate) {
return ExternalReference(reinterpret_cast<void*>(&double_constants.one_half));
return ExternalReference(
reinterpret_cast<Address>(&double_one_half_constant));
}
ExternalReference ExternalReference::address_of_minus_one_half(
Isolate* isolate) {
return ExternalReference(
reinterpret_cast<void*>(&double_constants.minus_one_half));
reinterpret_cast<Address>(&double_minus_one_half_constant));
}
ExternalReference ExternalReference::address_of_negative_infinity(
Isolate* isolate) {
return ExternalReference(
reinterpret_cast<void*>(&double_constants.negative_infinity));
reinterpret_cast<Address>(&double_negative_infinity_constant));
}
ExternalReference ExternalReference::address_of_the_hole_nan(Isolate* isolate) {
return ExternalReference(
reinterpret_cast<void*>(&double_constants.the_hole_nan));
reinterpret_cast<Address>(&double_the_hole_nan_constant));
}
ExternalReference ExternalReference::address_of_uint32_bias(Isolate* isolate) {
return ExternalReference(
reinterpret_cast<void*>(&double_constants.uint32_bias));
reinterpret_cast<Address>(&double_uint32_bias_constant));
}
ExternalReference ExternalReference::address_of_float_abs_constant(
Isolate* isolate) {
return ExternalReference(reinterpret_cast<void*>(&float_absolute_constant));
return ExternalReference(reinterpret_cast<Address>(&float_absolute_constant));
}
ExternalReference ExternalReference::address_of_float_neg_constant(
Isolate* isolate) {
return ExternalReference(reinterpret_cast<void*>(&float_negate_constant));
return ExternalReference(reinterpret_cast<Address>(&float_negate_constant));
}
ExternalReference ExternalReference::address_of_double_abs_constant(
Isolate* isolate) {
return ExternalReference(reinterpret_cast<void*>(&double_absolute_constant));
return ExternalReference(
reinterpret_cast<Address>(&double_absolute_constant));
}
ExternalReference ExternalReference::address_of_double_neg_constant(
Isolate* isolate) {
return ExternalReference(reinterpret_cast<void*>(&double_negate_constant));
return ExternalReference(reinterpret_cast<Address>(&double_negate_constant));
}
ExternalReference ExternalReference::is_profiling_address(Isolate* isolate) {
......
......@@ -248,8 +248,6 @@ class ExternalReference BASE_EMBEDDED {
EXTERNAL_REFERENCE_LIST(COUNT_EXTERNAL_REFERENCE);
#undef COUNT_EXTERNAL_REFERENCE
static void SetUp();
typedef Address ExternalReferenceRedirector(Address original, Type type);
ExternalReference() : address_(kNullAddress) {}
......
......@@ -81,7 +81,6 @@ void V8::InitializeOncePerProcessImpl() {
sampler::Sampler::SetUp();
CpuFeatures::Probe(false);
ElementsAccessor::InitializeOncePerProcess();
ExternalReference::SetUp();
Bootstrapper::InitializeOncePerProcess();
}
......
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