Commit a0364972 authored by bmeurer's avatar bmeurer Committed by Commit bot

[stubs] Store typeof string on Oddballs.

First step to simplify the TypeofStub. This is similar to the
optimization that we use for ToNumber and ToString on Oddballs already.

R=yangguo@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#30108}
parent f4c079d4
......@@ -6915,7 +6915,7 @@ class Internals {
1 * kApiPointerSize + kApiIntSize;
static const int kStringResourceOffset = 3 * kApiPointerSize;
static const int kOddballKindOffset = 3 * kApiPointerSize;
static const int kOddballKindOffset = 4 * kApiPointerSize;
static const int kForeignAddressOffset = kApiPointerSize;
static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
......
......@@ -322,7 +322,6 @@ Handle<Code> NumberToStringStub::GenerateCode() {
// Returns the type string of a value; see ECMA-262, 11.4.3 (p 47).
// Possible optimizations: put the type string into the oddballs.
template <>
HValue* CodeStubGraphBuilder<TypeofStub>::BuildCodeStub() {
Factory* factory = isolate()->factory();
......@@ -341,7 +340,6 @@ HValue* CodeStubGraphBuilder<TypeofStub>::BuildCodeStub() {
{ Push(number_string); }
is_number.Else();
{
HConstant* undefined_string = Add<HConstant>(factory->undefined_string());
HValue* map = AddLoadMap(object, smi_check);
HValue* instance_type = Add<HLoadNamedField>(
map, nullptr, HObjectAccess::ForMapInstanceType());
......@@ -358,24 +356,8 @@ HValue* CodeStubGraphBuilder<TypeofStub>::BuildCodeStub() {
instance_type, Add<HConstant>(ODDBALL_TYPE), Token::EQ);
is_oddball.Then();
{
IfBuilder is_true_or_false(this);
is_true_or_false.If<HCompareObjectEqAndBranch>(
object, graph()->GetConstantTrue());
is_true_or_false.OrIf<HCompareObjectEqAndBranch>(
object, graph()->GetConstantFalse());
is_true_or_false.Then();
{ Push(Add<HConstant>(factory->boolean_string())); }
is_true_or_false.Else();
{
IfBuilder is_null(this);
is_null.If<HCompareObjectEqAndBranch>(object,
graph()->GetConstantNull());
is_null.Then();
{ Push(object_string); }
is_null.Else();
{ Push(undefined_string); }
}
is_true_or_false.End();
Push(Add<HLoadNamedField>(object, nullptr,
HObjectAccess::ForOddballTypeOf()));
}
is_oddball.Else();
{
......@@ -454,7 +436,7 @@ HValue* CodeStubGraphBuilder<TypeofStub>::BuildCodeStub() {
is_undetectable.Then();
{
// typeof an undetectable object is 'undefined'.
Push(undefined_string);
Push(Add<HConstant>(factory->undefined_string()));
}
is_undetectable.Else();
{
......
......@@ -62,12 +62,11 @@ Handle<PrototypeInfo> Factory::NewPrototypeInfo() {
}
Handle<Oddball> Factory::NewOddball(Handle<Map> map,
const char* to_string,
Handle<Oddball> Factory::NewOddball(Handle<Map> map, const char* to_string,
Handle<Object> to_number,
byte kind) {
const char* type_of, byte kind) {
Handle<Oddball> oddball = New<Oddball>(map, OLD_SPACE);
Oddball::Initialize(isolate(), oddball, to_string, to_number, kind);
Oddball::Initialize(isolate(), oddball, to_string, to_number, type_of, kind);
return oddball;
}
......
......@@ -16,9 +16,8 @@ class FeedbackVectorSpec;
// Interface for handle based allocation.
class Factory final {
public:
Handle<Oddball> NewOddball(Handle<Map> map,
const char* to_string,
Handle<Object> to_number,
Handle<Oddball> NewOddball(Handle<Map> map, const char* to_string,
Handle<Object> to_number, const char* type_of,
byte kind);
// Allocates a fixed array initialized with undefined values.
......
......@@ -3180,44 +3180,47 @@ void Heap::CreateInitialObjects() {
// Finish initializing oddballs after creating the string table.
Oddball::Initialize(isolate(), factory->undefined_value(), "undefined",
factory->nan_value(), Oddball::kUndefined);
factory->nan_value(), "undefined", Oddball::kUndefined);
// Initialize the null_value.
Oddball::Initialize(isolate(), factory->null_value(), "null",
handle(Smi::FromInt(0), isolate()), Oddball::kNull);
handle(Smi::FromInt(0), isolate()), "object",
Oddball::kNull);
set_true_value(*factory->NewOddball(factory->boolean_map(), "true",
handle(Smi::FromInt(1), isolate()),
Oddball::kTrue));
"boolean", Oddball::kTrue));
set_false_value(*factory->NewOddball(factory->boolean_map(), "false",
handle(Smi::FromInt(0), isolate()),
Oddball::kFalse));
"boolean", Oddball::kFalse));
set_the_hole_value(*factory->NewOddball(factory->the_hole_map(), "hole",
handle(Smi::FromInt(-1), isolate()),
Oddball::kTheHole));
"undefined", Oddball::kTheHole));
set_uninitialized_value(*factory->NewOddball(
factory->uninitialized_map(), "uninitialized",
handle(Smi::FromInt(-1), isolate()), Oddball::kUninitialized));
set_uninitialized_value(
*factory->NewOddball(factory->uninitialized_map(), "uninitialized",
handle(Smi::FromInt(-1), isolate()), "undefined",
Oddball::kUninitialized));
set_arguments_marker(*factory->NewOddball(
factory->arguments_marker_map(), "arguments_marker",
handle(Smi::FromInt(-4), isolate()), Oddball::kArgumentMarker));
set_arguments_marker(
*factory->NewOddball(factory->arguments_marker_map(), "arguments_marker",
handle(Smi::FromInt(-4), isolate()), "undefined",
Oddball::kArgumentMarker));
set_no_interceptor_result_sentinel(*factory->NewOddball(
factory->no_interceptor_result_sentinel_map(),
"no_interceptor_result_sentinel", handle(Smi::FromInt(-2), isolate()),
Oddball::kOther));
"undefined", Oddball::kOther));
set_termination_exception(*factory->NewOddball(
factory->termination_exception_map(), "termination_exception",
handle(Smi::FromInt(-3), isolate()), Oddball::kOther));
handle(Smi::FromInt(-3), isolate()), "undefined", Oddball::kOther));
set_exception(*factory->NewOddball(factory->exception_map(), "exception",
handle(Smi::FromInt(-5), isolate()),
Oddball::kException));
"undefined", Oddball::kException));
for (unsigned i = 0; i < arraysize(constant_string_table); i++) {
Handle<String> str =
......
......@@ -5987,6 +5987,11 @@ class HObjectAccess final {
Representation::Integer32());
}
static HObjectAccess ForOddballTypeOf() {
return HObjectAccess(kInobject, Oddball::kTypeOfOffset,
Representation::HeapObject());
}
static HObjectAccess ForElementsPointer() {
return HObjectAccess(kElementsPointer, JSObject::kElementsOffset);
}
......
......@@ -1995,6 +1995,7 @@ void JSObject::initialize_elements() {
ACCESSORS(Oddball, to_string, String, kToStringOffset)
ACCESSORS(Oddball, to_number, Object, kToNumberOffset)
ACCESSORS(Oddball, type_of, String, kTypeOfOffset)
byte Oddball::kind() const {
......
......@@ -10182,15 +10182,16 @@ Handle<String> JSFunction::GetDebugName(Handle<JSFunction> function) {
}
void Oddball::Initialize(Isolate* isolate,
Handle<Oddball> oddball,
const char* to_string,
Handle<Object> to_number,
byte kind) {
void Oddball::Initialize(Isolate* isolate, Handle<Oddball> oddball,
const char* to_string, Handle<Object> to_number,
const char* type_of, byte kind) {
Handle<String> internalized_to_string =
isolate->factory()->InternalizeUtf8String(to_string);
oddball->set_to_string(*internalized_to_string);
Handle<String> internalized_type_of =
isolate->factory()->InternalizeUtf8String(type_of);
oddball->set_to_number(*to_number);
oddball->set_to_string(*internalized_to_string);
oddball->set_type_of(*internalized_type_of);
oddball->set_kind(kind);
}
......
......@@ -9204,6 +9204,9 @@ class Oddball: public HeapObject {
// [to_number]: Cached to_number computed at startup.
DECL_ACCESSORS(to_number, Object)
// [typeof]: Cached type_of computed at startup.
DECL_ACCESSORS(type_of, String)
inline byte kind() const;
inline void set_kind(byte kind);
......@@ -9213,16 +9216,15 @@ class Oddball: public HeapObject {
DECLARE_VERIFIER(Oddball)
// Initialize the fields.
static void Initialize(Isolate* isolate,
Handle<Oddball> oddball,
const char* to_string,
Handle<Object> to_number,
byte kind);
static void Initialize(Isolate* isolate, Handle<Oddball> oddball,
const char* to_string, Handle<Object> to_number,
const char* type_of, byte kind);
// Layout description.
static const int kToStringOffset = HeapObject::kHeaderSize;
static const int kToNumberOffset = kToStringOffset + kPointerSize;
static const int kKindOffset = kToNumberOffset + kPointerSize;
static const int kTypeOfOffset = kToNumberOffset + kPointerSize;
static const int kKindOffset = kTypeOfOffset + kPointerSize;
static const int kSize = kKindOffset + kPointerSize;
static const byte kFalse = 0;
......@@ -9236,8 +9238,7 @@ class Oddball: public HeapObject {
static const byte kOther = 7;
static const byte kException = 8;
typedef FixedBodyDescriptor<kToStringOffset,
kToNumberOffset + kPointerSize,
typedef FixedBodyDescriptor<kToStringOffset, kTypeOfOffset + kPointerSize,
kSize> BodyDescriptor;
STATIC_ASSERT(kKindOffset == Internals::kOddballKindOffset);
......
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