[runtime] We don't need an actual instance type for JSIteratorResult.

It's fine to use JS_OBJECT_TYPE for JSIteratorResult and only have a
preallocated initial map for them to avoid unnecessary polymorphism
from generators / builtin iterators. The instance type doesn't
provide any advantage, since we always have to treat JSIteratorResult
objects as regular JSObjects later.

R=yangguo@chromium.org
TBR=hpayer@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#33800}
This commit is contained in:
bmeurer 2016-02-07 22:55:16 -08:00 committed by Commit bot
parent c404c4ed46
commit f3b0dbb5e7
13 changed files with 25 additions and 89 deletions

View File

@ -1575,7 +1575,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
{ // -- I t e r a t o r R e s u l t
Handle<Map> map =
factory->NewMap(JS_ITERATOR_RESULT_TYPE, JSIteratorResult::kSize);
factory->NewMap(JS_OBJECT_TYPE, JSIteratorResult::kSize);
Map::SetPrototype(map, isolate->initial_object_prototype());
Map::EnsureDescriptorSlack(map, 2);

View File

@ -1827,7 +1827,7 @@ HValue* HGraphBuilder::BuildCreateIterResultObject(HValue* value,
// Allocate the JSIteratorResult object.
HValue* result =
Add<HAllocate>(Add<HConstant>(JSIteratorResult::kSize), HType::JSObject(),
NOT_TENURED, JS_ITERATOR_RESULT_TYPE);
NOT_TENURED, JS_OBJECT_TYPE);
// Initialize the JSIteratorResult object.
HValue* native_context = BuildGetNativeContext();

View File

@ -1737,16 +1737,6 @@ Handle<JSSetIterator> Factory::NewJSSetIterator() {
}
Handle<JSIteratorResult> Factory::NewJSIteratorResult(Handle<Object> value,
Handle<Object> done) {
Handle<JSIteratorResult> result = Handle<JSIteratorResult>::cast(
NewJSObjectFromMap(isolate()->iterator_result_map()));
result->set_value(*value);
result->set_done(*done);
return result;
}
namespace {
ElementsKind GetExternalArrayElementsKind(ExternalArrayType type) {

View File

@ -469,11 +469,6 @@ class Factory final {
Handle<JSMapIterator> NewJSMapIterator();
Handle<JSSetIterator> NewJSSetIterator();
// Creates a new JSIteratorResult object with the arguments {value} and
// {done}. Implemented according to ES6 section 7.4.7 CreateIterResultObject.
Handle<JSIteratorResult> NewJSIteratorResult(Handle<Object> value,
Handle<Object> done);
// Allocates a bound function.
MaybeHandle<JSBoundFunction> NewJSBoundFunction(
Handle<JSReceiver> target_function, Handle<Object> bound_this,

View File

@ -118,7 +118,6 @@ StaticVisitorBase::VisitorId StaticVisitorBase::GetVisitorId(
case JS_MAP_TYPE:
case JS_SET_ITERATOR_TYPE:
case JS_MAP_ITERATOR_TYPE:
case JS_ITERATOR_RESULT_TYPE:
case JS_PROMISE_TYPE:
case JS_BOUND_FUNCTION_TYPE:
return GetVisitorIdForSize(kVisitJSObject, kVisitJSObjectGeneric,

View File

@ -469,7 +469,6 @@ ReturnType BodyDescriptorApply(InstanceType type, T1 p1, T2 p2, T3 p3) {
case JS_MAP_TYPE:
case JS_SET_ITERATOR_TYPE:
case JS_MAP_ITERATOR_TYPE:
case JS_ITERATOR_RESULT_TYPE:
case JS_REGEXP_TYPE:
case JS_GLOBAL_PROXY_TYPE:
case JS_GLOBAL_OBJECT_TYPE:

View File

@ -150,9 +150,6 @@ void HeapObject::HeapObjectVerify() {
case JS_MAP_ITERATOR_TYPE:
JSMapIterator::cast(this)->JSMapIteratorVerify();
break;
case JS_ITERATOR_RESULT_TYPE:
JSIteratorResult::cast(this)->JSIteratorResultVerify();
break;
case JS_WEAK_MAP_TYPE:
JSWeakMap::cast(this)->JSWeakMapVerify();
break;
@ -764,14 +761,6 @@ void JSMapIterator::JSMapIteratorVerify() {
}
void JSIteratorResult::JSIteratorResultVerify() {
CHECK(IsJSIteratorResult());
JSObjectVerify();
VerifyPointer(done());
VerifyPointer(value());
}
void JSWeakMap::JSWeakMapVerify() {
CHECK(IsJSWeakMap());
JSObjectVerify();

View File

@ -710,7 +710,6 @@ TYPE_CHECKER(JSSet, JS_SET_TYPE)
TYPE_CHECKER(JSMap, JS_MAP_TYPE)
TYPE_CHECKER(JSSetIterator, JS_SET_ITERATOR_TYPE)
TYPE_CHECKER(JSMapIterator, JS_MAP_ITERATOR_TYPE)
TYPE_CHECKER(JSIteratorResult, JS_ITERATOR_RESULT_TYPE)
TYPE_CHECKER(JSWeakMap, JS_WEAK_MAP_TYPE)
TYPE_CHECKER(JSWeakSet, JS_WEAK_SET_TYPE)
TYPE_CHECKER(JSContextExtensionObject, JS_CONTEXT_EXTENSION_OBJECT_TYPE)
@ -2112,8 +2111,6 @@ int JSObject::GetHeaderSize(InstanceType type) {
return JSSetIterator::kSize;
case JS_MAP_ITERATOR_TYPE:
return JSMapIterator::kSize;
case JS_ITERATOR_RESULT_TYPE:
return JSIteratorResult::kSize;
case JS_WEAK_MAP_TYPE:
return JSWeakMap::kSize;
case JS_WEAK_SET_TYPE:
@ -3216,7 +3213,6 @@ CAST_ACCESSOR(JSReceiver)
CAST_ACCESSOR(JSRegExp)
CAST_ACCESSOR(JSSet)
CAST_ACCESSOR(JSSetIterator)
CAST_ACCESSOR(JSIteratorResult)
CAST_ACCESSOR(JSTypedArray)
CAST_ACCESSOR(JSValue)
CAST_ACCESSOR(JSWeakMap)
@ -7738,10 +7734,6 @@ Object* JSMapIterator::CurrentValue() {
}
ACCESSORS(JSIteratorResult, done, Object, kDoneOffset)
ACCESSORS(JSIteratorResult, value, Object, kValueOffset)
String::SubStringRange::SubStringRange(String* string, int first, int length)
: string_(string),
first_(first),

View File

@ -146,9 +146,6 @@ void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT
case JS_MAP_ITERATOR_TYPE:
JSMapIterator::cast(this)->JSMapIteratorPrint(os);
break;
case JS_ITERATOR_RESULT_TYPE:
JSIteratorResult::cast(this)->JSIteratorResultPrint(os);
break;
case JS_WEAK_MAP_TYPE:
JSWeakMap::cast(this)->JSWeakMapPrint(os);
break;
@ -800,14 +797,6 @@ void JSMapIterator::JSMapIteratorPrint(std::ostream& os) { // NOLINT
}
void JSIteratorResult::JSIteratorResultPrint(std::ostream& os) { // NOLINT
JSObjectPrintHeader(os, this, "JSIteratorResult");
os << "\n - done = " << Brief(done());
os << "\n - value = " << Brief(value());
os << "\n";
}
void JSWeakMap::JSWeakMapPrint(std::ostream& os) { // NOLINT
JSObjectPrintHeader(os, this, "JSWeakMap");
os << "\n - table = " << Brief(table());

View File

@ -13078,7 +13078,6 @@ bool CanSubclassHaveInobjectProperties(InstanceType instance_type) {
case JS_MAP_TYPE:
case JS_SET_ITERATOR_TYPE:
case JS_MAP_ITERATOR_TYPE:
case JS_ITERATOR_RESULT_TYPE:
case JS_WEAK_MAP_TYPE:
case JS_WEAK_SET_TYPE:
case JS_PROMISE_TYPE:

View File

@ -429,7 +429,6 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1;
V(JS_MAP_TYPE) \
V(JS_SET_ITERATOR_TYPE) \
V(JS_MAP_ITERATOR_TYPE) \
V(JS_ITERATOR_RESULT_TYPE) \
V(JS_WEAK_MAP_TYPE) \
V(JS_WEAK_SET_TYPE) \
V(JS_PROMISE_TYPE) \
@ -723,7 +722,6 @@ enum InstanceType {
JS_MAP_TYPE,
JS_SET_ITERATOR_TYPE,
JS_MAP_ITERATOR_TYPE,
JS_ITERATOR_RESULT_TYPE,
JS_WEAK_MAP_TYPE,
JS_WEAK_SET_TYPE,
JS_PROMISE_TYPE,
@ -963,7 +961,6 @@ template <class C> inline bool Is(Object* obj);
V(JSMap) \
V(JSSetIterator) \
V(JSMapIterator) \
V(JSIteratorResult) \
V(JSWeakCollection) \
V(JSWeakMap) \
V(JSWeakSet) \
@ -2604,6 +2601,24 @@ class JSDataPropertyDescriptor: public JSObject {
};
// JSIteratorResult is just a JSObject with a specific initial map.
// This initial map adds in-object properties for "done" and "value,
// as specified by ES6 section 25.1.1.3 The IteratorResult Interface
class JSIteratorResult: public JSObject {
public:
// Offsets of object fields.
static const int kValueOffset = JSObject::kHeaderSize;
static const int kDoneOffset = kValueOffset + kPointerSize;
static const int kSize = kDoneOffset + kPointerSize;
// Indices of in-object properties.
static const int kValueIndex = 0;
static const int kDoneIndex = 1;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(JSIteratorResult);
};
// Common superclass for FixedArrays that allow implementations to share
// common accessors and some code paths.
class FixedArrayBase: public HeapObject {
@ -9884,40 +9899,6 @@ class JSMapIterator: public OrderedHashTableIterator<JSMapIterator,
};
// ES6 section 25.1.1.3 The IteratorResult Interface
class JSIteratorResult final : public JSObject {
public:
// [done]: This is the result status of an iterator next method call. If the
// end of the iterator was reached done is true. If the end was not reached
// done is false and a [value] is available.
DECL_ACCESSORS(done, Object)
// [value]: If [done] is false, this is the current iteration element value.
// If [done] is true, this is the return value of the iterator, if it supplied
// one. If the iterator does not have a return value, value is undefined.
// In that case, the value property may be absent from the conforming object
// if it does not inherit an explicit value property.
DECL_ACCESSORS(value, Object)
// Dispatched behavior.
DECLARE_PRINTER(JSIteratorResult)
DECLARE_VERIFIER(JSIteratorResult)
DECLARE_CAST(JSIteratorResult)
static const int kValueOffset = JSObject::kHeaderSize;
static const int kDoneOffset = kValueOffset + kPointerSize;
static const int kSize = kDoneOffset + kPointerSize;
// Indices of in-object properties.
static const int kValueIndex = 0;
static const int kDoneIndex = 1;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(JSIteratorResult);
};
// Base class for both JSWeakMap and JSWeakSet
class JSWeakCollection: public JSObject {
public:

View File

@ -1270,7 +1270,11 @@ RUNTIME_FUNCTION(Runtime_CreateIterResultObject) {
DCHECK_EQ(2, args.length());
CONVERT_ARG_HANDLE_CHECKED(Object, value, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, done, 1);
return *isolate->factory()->NewJSIteratorResult(value, done);
Handle<JSObject> result =
isolate->factory()->NewJSObjectFromMap(isolate->iterator_result_map());
result->InObjectPropertyAtPut(JSIteratorResult::kValueIndex, *value);
result->InObjectPropertyAtPut(JSIteratorResult::kDoneIndex, *done);
return *result;
}

View File

@ -215,7 +215,6 @@ Type::bitset BitsetType::Lub(i::Map* map) {
case JS_MAP_TYPE:
case JS_SET_ITERATOR_TYPE:
case JS_MAP_ITERATOR_TYPE:
case JS_ITERATOR_RESULT_TYPE:
case JS_WEAK_MAP_TYPE:
case JS_WEAK_SET_TYPE:
case JS_PROMISE_TYPE: