2015-09-10 16:21:34 +00:00
|
|
|
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-02-24 13:03:58 +00:00
|
|
|
#include "src/interpreter/bytecode-array-iterator.h"
|
2015-09-10 16:21:34 +00:00
|
|
|
|
2021-02-24 13:03:58 +00:00
|
|
|
#include "src/init/v8.h"
|
2015-09-10 16:21:34 +00:00
|
|
|
#include "src/interpreter/bytecode-array-builder.h"
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/numbers/hash-seed-inl.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2018-11-03 00:13:22 +00:00
|
|
|
#include "src/objects/smi.h"
|
2017-12-13 12:19:44 +00:00
|
|
|
#include "test/unittests/interpreter/bytecode-utils.h"
|
2015-09-10 16:21:34 +00:00
|
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace interpreter {
|
|
|
|
|
|
|
|
class BytecodeArrayIteratorTest : public TestWithIsolateAndZone {
|
|
|
|
public:
|
2018-09-13 09:22:50 +00:00
|
|
|
BytecodeArrayIteratorTest() = default;
|
|
|
|
~BytecodeArrayIteratorTest() override = default;
|
2015-09-10 16:21:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(BytecodeArrayIteratorTest, IteratesBytecodeArray) {
|
|
|
|
// Use a builder to create an array with containing multiple bytecodes
|
|
|
|
// with 0, 1 and 2 operands.
|
2017-10-19 15:12:42 +00:00
|
|
|
FeedbackVectorSpec feedback_spec(zone());
|
2021-02-17 14:36:58 +00:00
|
|
|
BytecodeArrayBuilder builder(zone(), 3, 17, &feedback_spec);
|
2017-02-10 17:22:45 +00:00
|
|
|
AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(),
|
2019-02-14 21:10:30 +00:00
|
|
|
HashSeed(isolate()));
|
2017-10-27 19:53:15 +00:00
|
|
|
double heap_num_0 = 2.718;
|
|
|
|
double heap_num_1 = 2.0 * Smi::kMaxValue;
|
2018-11-03 00:13:22 +00:00
|
|
|
Smi zero = Smi::zero();
|
|
|
|
Smi smi_0 = Smi::FromInt(64);
|
|
|
|
Smi smi_1 = Smi::FromInt(-65536);
|
2015-09-10 16:21:34 +00:00
|
|
|
Register reg_0(0);
|
2021-02-17 14:36:58 +00:00
|
|
|
Register reg_16(16); // Something not eligible for short Star.
|
2017-12-13 12:19:44 +00:00
|
|
|
RegisterList pair = BytecodeUtils::NewRegisterList(0, 2);
|
|
|
|
RegisterList triple = BytecodeUtils::NewRegisterList(0, 3);
|
2021-12-16 13:20:11 +00:00
|
|
|
Register param = Register::FromParameterIndex(2);
|
2017-02-10 17:22:45 +00:00
|
|
|
const AstRawString* name = ast_factory.GetOneByteString("abc");
|
2016-11-10 11:25:17 +00:00
|
|
|
uint32_t name_index = 2;
|
2017-10-19 15:12:42 +00:00
|
|
|
uint32_t load_feedback_slot = feedback_spec.AddLoadICSlot().ToInt();
|
|
|
|
uint32_t forin_feedback_slot = feedback_spec.AddForInSlot().ToInt();
|
|
|
|
uint32_t load_global_feedback_slot =
|
2021-05-11 09:03:52 +00:00
|
|
|
feedback_spec.AddLoadGlobalICSlot(TypeofMode::kNotInside).ToInt();
|
2015-09-10 16:21:34 +00:00
|
|
|
|
|
|
|
builder.LoadLiteral(heap_num_0)
|
2016-05-12 19:18:07 +00:00
|
|
|
.StoreAccumulatorInRegister(reg_0)
|
2015-09-10 16:21:34 +00:00
|
|
|
.LoadLiteral(heap_num_1)
|
2016-05-12 19:18:07 +00:00
|
|
|
.StoreAccumulatorInRegister(reg_0)
|
2015-09-10 16:21:34 +00:00
|
|
|
.LoadLiteral(zero)
|
2016-05-12 19:18:07 +00:00
|
|
|
.StoreAccumulatorInRegister(reg_0)
|
2015-09-10 16:21:34 +00:00
|
|
|
.LoadLiteral(smi_0)
|
2016-05-12 19:18:07 +00:00
|
|
|
.StoreAccumulatorInRegister(reg_0)
|
2015-09-10 16:21:34 +00:00
|
|
|
.LoadLiteral(smi_1)
|
2021-02-17 14:36:58 +00:00
|
|
|
.StoreAccumulatorInRegister(reg_16)
|
2015-09-10 16:21:34 +00:00
|
|
|
.LoadAccumulatorWithRegister(reg_0)
|
2016-08-08 01:15:22 +00:00
|
|
|
.BinaryOperation(Token::Value::ADD, reg_0, 2)
|
2021-02-17 14:36:58 +00:00
|
|
|
.StoreAccumulatorInRegister(reg_16)
|
|
|
|
.LoadNamedProperty(reg_16, name, load_feedback_slot)
|
2016-08-08 01:15:22 +00:00
|
|
|
.BinaryOperation(Token::Value::ADD, reg_0, 3)
|
2016-04-01 12:08:53 +00:00
|
|
|
.StoreAccumulatorInRegister(param)
|
2016-10-05 16:44:38 +00:00
|
|
|
.CallRuntimeForPair(Runtime::kLoadLookupSlotForCall, param, pair)
|
2017-10-19 15:12:42 +00:00
|
|
|
.ForInPrepare(triple, forin_feedback_slot)
|
2016-09-30 09:02:59 +00:00
|
|
|
.CallRuntime(Runtime::kLoadIC_Miss, reg_0)
|
2016-02-04 15:06:25 +00:00
|
|
|
.Debugger()
|
2021-05-11 09:03:52 +00:00
|
|
|
.LoadGlobal(name, load_global_feedback_slot, TypeofMode::kNotInside)
|
2015-09-10 16:21:34 +00:00
|
|
|
.Return();
|
|
|
|
|
|
|
|
// Test iterator sees the expected output from the builder.
|
[offthread] Add an OffThreadIsolate
The Factory/OffThreadFactory allows us to cleanly separate object
construction behaviour between main-thread and off-thread in a
syntactically consistent way (so that methods templated on the factory
type can be made to work on both).
However, there are cases where we also have to access the Isolate, for
handle creation or exception throwing. So far we have been pushing more
and more "customization points" into the factories to allow these
factory-templated methods to dispatch on this isolate behaviour via
these factory methods. Unfortunately, this is an increasing layering
violation between Factory and Isolate, particularly around exception
handling.
Now, we introduce an OffThreadIsolate, analogous to Isolate in the same
way as OffThreadFactory is analogous to Factory. All methods which were
templated on Factory are now templated on Isolate, and methods which
used to take an Isolate, and which were recently changed to take a
templated Factory, are changed/reverted to take a templated Isolate.
OffThreadFactory gets an isolate() method to match Factory's.
Notably, FactoryHandle is changed to "HandleFor", where the template
argument can be either of the Isolate type or the Factory type (allowing
us to dispatch on both depending on what is available).
Bug: chromium:1011762
Change-Id: Id144176f7da534dd76f3d535ab2ade008b6845e3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2030909
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66101}
2020-02-04 10:50:53 +00:00
|
|
|
ast_factory.Internalize(isolate());
|
2016-08-18 13:42:05 +00:00
|
|
|
BytecodeArrayIterator iterator(builder.ToBytecodeArray(isolate()));
|
2016-04-01 12:08:53 +00:00
|
|
|
const int kPrefixByteSize = 1;
|
|
|
|
int offset = 0;
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
2019-06-17 15:25:41 +00:00
|
|
|
EXPECT_EQ(iterator.GetConstantForIndexOperand(0, isolate())->Number(),
|
|
|
|
heap_num_0);
|
2015-09-10 16:21:34 +00:00
|
|
|
CHECK(!iterator.done());
|
2016-04-01 12:08:53 +00:00
|
|
|
offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
|
2015-09-10 16:21:34 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2021-02-17 14:36:58 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar0);
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
2016-05-12 19:18:07 +00:00
|
|
|
CHECK(!iterator.done());
|
2021-02-17 14:36:58 +00:00
|
|
|
offset += Bytecodes::Size(Bytecode::kStar0, OperandScale::kSingle);
|
2016-05-12 19:18:07 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
2019-06-17 15:25:41 +00:00
|
|
|
EXPECT_EQ(iterator.GetConstantForIndexOperand(0, isolate())->Number(),
|
|
|
|
heap_num_1);
|
2015-09-10 16:21:34 +00:00
|
|
|
CHECK(!iterator.done());
|
2016-04-01 12:08:53 +00:00
|
|
|
offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
|
2015-09-10 16:21:34 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2021-02-17 14:36:58 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar0);
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
2016-05-12 19:18:07 +00:00
|
|
|
CHECK(!iterator.done());
|
2021-02-17 14:36:58 +00:00
|
|
|
offset += Bytecodes::Size(Bytecode::kStar0, OperandScale::kSingle);
|
2016-05-12 19:18:07 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaZero);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
2015-09-10 16:21:34 +00:00
|
|
|
CHECK(!iterator.done());
|
2016-04-01 12:08:53 +00:00
|
|
|
offset += Bytecodes::Size(Bytecode::kLdaZero, OperandScale::kSingle);
|
2015-09-10 16:21:34 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2021-02-17 14:36:58 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar0);
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
2016-05-12 19:18:07 +00:00
|
|
|
CHECK(!iterator.done());
|
2021-02-17 14:36:58 +00:00
|
|
|
offset += Bytecodes::Size(Bytecode::kStar0, OperandScale::kSingle);
|
2016-05-12 19:18:07 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
|
|
|
EXPECT_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_0);
|
2015-09-10 16:21:34 +00:00
|
|
|
CHECK(!iterator.done());
|
2016-04-01 12:08:53 +00:00
|
|
|
offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kSingle);
|
2015-09-10 16:21:34 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2021-02-17 14:36:58 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar0);
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
2016-05-12 19:18:07 +00:00
|
|
|
CHECK(!iterator.done());
|
2021-02-17 14:36:58 +00:00
|
|
|
offset += Bytecodes::Size(Bytecode::kStar0, OperandScale::kSingle);
|
2016-05-12 19:18:07 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kQuadruple);
|
|
|
|
EXPECT_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_1);
|
2015-09-10 16:21:34 +00:00
|
|
|
CHECK(!iterator.done());
|
2016-04-01 12:08:53 +00:00
|
|
|
offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kQuadruple) +
|
|
|
|
kPrefixByteSize;
|
2015-09-10 16:21:34 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
2021-02-17 14:36:58 +00:00
|
|
|
EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_16.index());
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
|
2016-05-12 19:18:07 +00:00
|
|
|
CHECK(!iterator.done());
|
|
|
|
offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
|
|
|
|
iterator.Advance();
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdar);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
|
|
|
EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
|
2015-09-10 16:21:34 +00:00
|
|
|
CHECK(!iterator.done());
|
2016-04-01 12:08:53 +00:00
|
|
|
offset += Bytecodes::Size(Bytecode::kLdar, OperandScale::kSingle);
|
2015-09-10 16:21:34 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kAdd);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
|
|
|
EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
|
|
|
|
EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
|
2016-05-27 15:57:35 +00:00
|
|
|
CHECK(!iterator.done());
|
2016-08-08 01:15:22 +00:00
|
|
|
offset += Bytecodes::Size(Bytecode::kAdd, OperandScale::kSingle);
|
2016-05-27 15:57:35 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
2021-02-17 14:36:58 +00:00
|
|
|
EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_16.index());
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
|
2016-05-12 19:18:07 +00:00
|
|
|
CHECK(!iterator.done());
|
|
|
|
offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
|
|
|
|
iterator.Advance();
|
|
|
|
|
[ic] name Set/Define/Store property operations more consistently
For background and reasoning, see
https://docs.google.com/document/d/1jvSEvXFHRkxg4JX-j6ho3nRqAF8vZI2Ai7RI8AY54gM/edit
This is the first step towards pulling the DefineNamedOwn operation out
of StoreIC.
Summary of the renamed identifiers:
Bytecodes:
- StaNamedProperty -> SetNamedProperty: calls StoreIC and emitted for
normal named property sets like obj.x = 1.
- StaNamedOwnProperty -> DefineNamedOwnProperty: calls
DefineNamedOwnIC (previously StoreOwnIC), and emitted for
initialization of named properties in object literals and named
public class fields.
- StaKeyedProperty -> SetKeyedProperty: calls KeyedStoreIC and emitted
for keyed property sets like obj[x] = 1.
- StaKeyedPropertyAsDefine -> DefineKeyedOwnProperty: calls
DefineKeyedOwnIC (previously KeyedDefineOwnIC) and emitted for
initialization of private class fields and computed public class
fields.
- StaDataPropertyInLiteral -> DefineKeyedOwnPropertyInLiteral: calls
DefineKeyedOwnPropertyInLiteral runtime function (previously
DefineDataPropertyInLiteral) and emitted for initialization of keyed
properties in object literals and static class initializers. (note
that previously the StoreDataPropertyInLiteral runtime function name
was taken by object spreads and array literal creation instead)
- LdaKeyedProperty -> GetKeyedProperty, LdaNamedProperty ->
GetNamedProperty, LdaNamedPropertyFromSuper ->
GetNamedPropertyFromSuper: we drop the Sta prefix for the property
store operations since the accumulator use is implicit and to make
the wording more natural, for symmetry the Lda prefix for the
property load operations is also dropped.
opcodes:
- (JS)StoreNamed -> (JS)SetNamedProperty: implements set semantics for
named properties, compiled from SetNamedProperty (previously
StaNamedProperty) and lowers to StoreIC or Runtime::kSetNamedProperty
- (JS)StoreNamedOwn -> (JS)DefineNamedOwnProperty: implements define
semantics for initializing named own properties in object literal and
public class fields, compiled from DefineNamedOwnProperty (previously
StaNamedOwnProperty) and lowers to DefineNamedOwnIC
(previously StoreOwnIC)
- (JS)StoreProperty -> (JS)SetKeyedProperty: implements set semantics
for keyed properties, only compiled from SetKeyedProperty(previously
StaKeyedProperty) and lowers to KeyedStoreIC
- (JS)DefineProperty -> (JS)DefineKeyedOwnProperty: implements define
semantics for initialization of private class fields and computed
public class fields, compiled from DefineKeyedOwnProperty (previously
StaKeyedPropertyAsDefine) and calls DefineKeyedOwnIC (previously
KeyedDefineOwnIC).
- (JS)StoreDataPropertyInLiteral ->
(JS)DefineKeyedOwnPropertyInLiteral: implements define semantics for
initialization of keyed properties in object literals and static
class initializers, compiled from DefineKeyedOwnPropertyInLiteral
(previously StaDataPropertyInLiteral) and calls the
DefineKeyedOwnPropertyInLiteral runtime function (previously
DefineDataPropertyInLiteral).
Runtime:
- DefineDataPropertyInLiteral -> DefineKeyedOwnPropertyInLiteral:
following the bytecode/opcodes change, this is used by
DefineKeyedOwnPropertyInLiteral (previously StaDataPropertyInLiteral)
for object and class literal initialization.
- StoreDataPropertyInLiteral -> DefineKeyedOwnPropertyInLiteral_Simple:
it's just a simplified version of DefineDataPropertyInLiteral that
does not update feedback or perform function name configuration.
This is used by object spread and array literal creation. Since we
are renaming DefineDataPropertyInLiteral to
DefineKeyedOwnPropertyInLiteral, rename this simplified version with
a `_Simple` suffix. We can consider merging it into
DefineKeyedOwnPropertyInLiteral in the future. See
https://docs.google.com/document/d/1jvSEvXFHRkxg4JX-j6ho3nRqAF8vZI2Ai7RI8AY54gM/edit?disco=AAAAQQIz6mU
- Other changes following the bytecode/IR changes
IC:
- StoreOwn -> DefineNamedOwn: used for initialization of named
properties in object literals and named public class fields.
- StoreOwnIC -> DefineNamedOwnIC
- StoreMode::kStoreOwn -> StoreMode::kDefineNamedOwn
- StoreICMode::kStoreOwn -> StoreICMode::kDefineNamedOwn
- IsStoreOwn() -> IsDefineNamedOwn()
- DefineOwn -> DefineKeyedOwn: IsDefineOwnIC() was already just
IsDefineKeyedOwnIC(), and IsAnyDefineOwn() includes both named and
keyed defines so we don't need an extra generic predicate.
- StoreMode::kDefineOwn -> StoreMode::kDefineKeyedOwn
- StoreICMode::kDefineOwn -> StoreICMode::kDefineKeyedOwn
- IsDefineOwn() -> IsDefineKeyedOwn()
- IsDefineOwnIC() -> IsDefineKeyedOwnIC()
- Removing IsKeyedDefineOwnIC() as its now a duplicate of
IsDefineKeyedOwnIC()
- KeyedDefineOwnIC -> DefineKeyedOwnIC,
KeyedDefineOwnGenericGenerator() -> DefineKeyedOwnGenericGenerator:
make the ordering of terms more consistent
- IsAnyStoreOwn() -> IsAnyDefineOwn(): this includes the renamed and
DefineNamedOwn and DefineKeyedOwn. Also is_any_store_own() is
removed since it's just a duplicate of this.
- IsKeyedStoreOwn() -> IsDefineNamedOwn(): it's unclear where the
"keyed" part came from, but it's only used when DefineNamedOwnIC
(previously StoreOwnIC) reuses KeyedStoreIC, so rename it accordingly
Interpreter & compiler:
- BytecodeArrayBuilder: following bytecode changes
- StoreNamedProperty -> SetNamedProperty
- StoreNamedOwnProperty -> DefineNamedOwnProperty
- StoreKeyedProperty -> SetKeyedProperty
- DefineKeyedProperty -> DefineKeyedOwnProperty
- StoreDataPropertyInLiteral -> DefineKeyedOwnPropertyInLiteral
- FeedbackSlotKind:
- kDefineOwnKeyed -> kDefineKeyedOwn: make the ordering of terms more
consistent
- kStoreOwnNamed -> kDefineNamedOwn: following the IC change
- kStoreNamed{Sloppy|Strict} -> kSetNamed{Sloppy|Strict}: only
used in StoreIC for set semantics
- kStoreKeyed{Sloppy|Strict} -> kSetKeyed{Sloppy|Strict}: only used
in KeyedStoreIC for set semantics
- kStoreDataPropertyInLiteral -> kDefineKeyedOwnPropertyInLiteral:
following the IC change
- BytecodeGraphBuilder
- StoreMode::kNormal, kOwn -> NamedStoreMode::kSet, kDefineOwn: this
is only used by BytecodeGraphBuilder::BuildNamedStore() to tell the
difference between SetNamedProperty and DefineNamedOwnProperty
operations.
Not changed:
- StoreIC and KeyedStoreIC currently contain mixed logic for both Set
and Define operations, and the paths are controlled by feedback. The
plan is to refactor the hierarchy like this:
```
- StoreIC
- DefineNamedOwnIC
- SetNamedIC (there could also be a NamedStoreIC if that's helpful)
- KeyedStoreIC
- SetKeyedIC
- DefineKeyedOwnIC
- DefineKeyedOwnICLiteral (could be merged into DefineKeyedOwnIC)
- StoreInArrayLiteralIC
- ...
```
StoreIC and KeyedStoreIC would then contain helpers shared by their
subclasses, therefore it still makes sense to keep the word "Store"
in their names since they would be generic base classes for both set
and define operations.
- The Lda and Sta prefixes of bytecodes not involving object properties
(e.g. Ldar, Star, LdaZero) are kept, since this patch focuses on
property operations, and distinction between Set and Define might be
less relevant or nonexistent for bytecodes not involving object
properties. We could consider rename some of them in future patches
if that's helpful though.
Bug: v8:12548
Change-Id: Ia36997b02f59a87da3247f20e0560a7eb13077f3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3481475
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Reviewed-by: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: Joyee Cheung <joyee@igalia.com>
Cr-Commit-Position: refs/heads/main@{#79409}
2022-03-08 17:36:04 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kGetNamedProperty);
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
2021-02-17 14:36:58 +00:00
|
|
|
EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_16.index());
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.GetIndexOperand(1), name_index);
|
2017-10-19 15:12:42 +00:00
|
|
|
EXPECT_EQ(iterator.GetIndexOperand(2), load_feedback_slot);
|
2015-09-10 16:21:34 +00:00
|
|
|
CHECK(!iterator.done());
|
[ic] name Set/Define/Store property operations more consistently
For background and reasoning, see
https://docs.google.com/document/d/1jvSEvXFHRkxg4JX-j6ho3nRqAF8vZI2Ai7RI8AY54gM/edit
This is the first step towards pulling the DefineNamedOwn operation out
of StoreIC.
Summary of the renamed identifiers:
Bytecodes:
- StaNamedProperty -> SetNamedProperty: calls StoreIC and emitted for
normal named property sets like obj.x = 1.
- StaNamedOwnProperty -> DefineNamedOwnProperty: calls
DefineNamedOwnIC (previously StoreOwnIC), and emitted for
initialization of named properties in object literals and named
public class fields.
- StaKeyedProperty -> SetKeyedProperty: calls KeyedStoreIC and emitted
for keyed property sets like obj[x] = 1.
- StaKeyedPropertyAsDefine -> DefineKeyedOwnProperty: calls
DefineKeyedOwnIC (previously KeyedDefineOwnIC) and emitted for
initialization of private class fields and computed public class
fields.
- StaDataPropertyInLiteral -> DefineKeyedOwnPropertyInLiteral: calls
DefineKeyedOwnPropertyInLiteral runtime function (previously
DefineDataPropertyInLiteral) and emitted for initialization of keyed
properties in object literals and static class initializers. (note
that previously the StoreDataPropertyInLiteral runtime function name
was taken by object spreads and array literal creation instead)
- LdaKeyedProperty -> GetKeyedProperty, LdaNamedProperty ->
GetNamedProperty, LdaNamedPropertyFromSuper ->
GetNamedPropertyFromSuper: we drop the Sta prefix for the property
store operations since the accumulator use is implicit and to make
the wording more natural, for symmetry the Lda prefix for the
property load operations is also dropped.
opcodes:
- (JS)StoreNamed -> (JS)SetNamedProperty: implements set semantics for
named properties, compiled from SetNamedProperty (previously
StaNamedProperty) and lowers to StoreIC or Runtime::kSetNamedProperty
- (JS)StoreNamedOwn -> (JS)DefineNamedOwnProperty: implements define
semantics for initializing named own properties in object literal and
public class fields, compiled from DefineNamedOwnProperty (previously
StaNamedOwnProperty) and lowers to DefineNamedOwnIC
(previously StoreOwnIC)
- (JS)StoreProperty -> (JS)SetKeyedProperty: implements set semantics
for keyed properties, only compiled from SetKeyedProperty(previously
StaKeyedProperty) and lowers to KeyedStoreIC
- (JS)DefineProperty -> (JS)DefineKeyedOwnProperty: implements define
semantics for initialization of private class fields and computed
public class fields, compiled from DefineKeyedOwnProperty (previously
StaKeyedPropertyAsDefine) and calls DefineKeyedOwnIC (previously
KeyedDefineOwnIC).
- (JS)StoreDataPropertyInLiteral ->
(JS)DefineKeyedOwnPropertyInLiteral: implements define semantics for
initialization of keyed properties in object literals and static
class initializers, compiled from DefineKeyedOwnPropertyInLiteral
(previously StaDataPropertyInLiteral) and calls the
DefineKeyedOwnPropertyInLiteral runtime function (previously
DefineDataPropertyInLiteral).
Runtime:
- DefineDataPropertyInLiteral -> DefineKeyedOwnPropertyInLiteral:
following the bytecode/opcodes change, this is used by
DefineKeyedOwnPropertyInLiteral (previously StaDataPropertyInLiteral)
for object and class literal initialization.
- StoreDataPropertyInLiteral -> DefineKeyedOwnPropertyInLiteral_Simple:
it's just a simplified version of DefineDataPropertyInLiteral that
does not update feedback or perform function name configuration.
This is used by object spread and array literal creation. Since we
are renaming DefineDataPropertyInLiteral to
DefineKeyedOwnPropertyInLiteral, rename this simplified version with
a `_Simple` suffix. We can consider merging it into
DefineKeyedOwnPropertyInLiteral in the future. See
https://docs.google.com/document/d/1jvSEvXFHRkxg4JX-j6ho3nRqAF8vZI2Ai7RI8AY54gM/edit?disco=AAAAQQIz6mU
- Other changes following the bytecode/IR changes
IC:
- StoreOwn -> DefineNamedOwn: used for initialization of named
properties in object literals and named public class fields.
- StoreOwnIC -> DefineNamedOwnIC
- StoreMode::kStoreOwn -> StoreMode::kDefineNamedOwn
- StoreICMode::kStoreOwn -> StoreICMode::kDefineNamedOwn
- IsStoreOwn() -> IsDefineNamedOwn()
- DefineOwn -> DefineKeyedOwn: IsDefineOwnIC() was already just
IsDefineKeyedOwnIC(), and IsAnyDefineOwn() includes both named and
keyed defines so we don't need an extra generic predicate.
- StoreMode::kDefineOwn -> StoreMode::kDefineKeyedOwn
- StoreICMode::kDefineOwn -> StoreICMode::kDefineKeyedOwn
- IsDefineOwn() -> IsDefineKeyedOwn()
- IsDefineOwnIC() -> IsDefineKeyedOwnIC()
- Removing IsKeyedDefineOwnIC() as its now a duplicate of
IsDefineKeyedOwnIC()
- KeyedDefineOwnIC -> DefineKeyedOwnIC,
KeyedDefineOwnGenericGenerator() -> DefineKeyedOwnGenericGenerator:
make the ordering of terms more consistent
- IsAnyStoreOwn() -> IsAnyDefineOwn(): this includes the renamed and
DefineNamedOwn and DefineKeyedOwn. Also is_any_store_own() is
removed since it's just a duplicate of this.
- IsKeyedStoreOwn() -> IsDefineNamedOwn(): it's unclear where the
"keyed" part came from, but it's only used when DefineNamedOwnIC
(previously StoreOwnIC) reuses KeyedStoreIC, so rename it accordingly
Interpreter & compiler:
- BytecodeArrayBuilder: following bytecode changes
- StoreNamedProperty -> SetNamedProperty
- StoreNamedOwnProperty -> DefineNamedOwnProperty
- StoreKeyedProperty -> SetKeyedProperty
- DefineKeyedProperty -> DefineKeyedOwnProperty
- StoreDataPropertyInLiteral -> DefineKeyedOwnPropertyInLiteral
- FeedbackSlotKind:
- kDefineOwnKeyed -> kDefineKeyedOwn: make the ordering of terms more
consistent
- kStoreOwnNamed -> kDefineNamedOwn: following the IC change
- kStoreNamed{Sloppy|Strict} -> kSetNamed{Sloppy|Strict}: only
used in StoreIC for set semantics
- kStoreKeyed{Sloppy|Strict} -> kSetKeyed{Sloppy|Strict}: only used
in KeyedStoreIC for set semantics
- kStoreDataPropertyInLiteral -> kDefineKeyedOwnPropertyInLiteral:
following the IC change
- BytecodeGraphBuilder
- StoreMode::kNormal, kOwn -> NamedStoreMode::kSet, kDefineOwn: this
is only used by BytecodeGraphBuilder::BuildNamedStore() to tell the
difference between SetNamedProperty and DefineNamedOwnProperty
operations.
Not changed:
- StoreIC and KeyedStoreIC currently contain mixed logic for both Set
and Define operations, and the paths are controlled by feedback. The
plan is to refactor the hierarchy like this:
```
- StoreIC
- DefineNamedOwnIC
- SetNamedIC (there could also be a NamedStoreIC if that's helpful)
- KeyedStoreIC
- SetKeyedIC
- DefineKeyedOwnIC
- DefineKeyedOwnICLiteral (could be merged into DefineKeyedOwnIC)
- StoreInArrayLiteralIC
- ...
```
StoreIC and KeyedStoreIC would then contain helpers shared by their
subclasses, therefore it still makes sense to keep the word "Store"
in their names since they would be generic base classes for both set
and define operations.
- The Lda and Sta prefixes of bytecodes not involving object properties
(e.g. Ldar, Star, LdaZero) are kept, since this patch focuses on
property operations, and distinction between Set and Define might be
less relevant or nonexistent for bytecodes not involving object
properties. We could consider rename some of them in future patches
if that's helpful though.
Bug: v8:12548
Change-Id: Ia36997b02f59a87da3247f20e0560a7eb13077f3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3481475
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Reviewed-by: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: Joyee Cheung <joyee@igalia.com>
Cr-Commit-Position: refs/heads/main@{#79409}
2022-03-08 17:36:04 +00:00
|
|
|
offset += Bytecodes::Size(Bytecode::kGetNamedProperty, OperandScale::kSingle);
|
2015-09-10 16:21:34 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kAdd);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
|
|
|
EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
|
|
|
|
EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
|
2016-05-25 09:55:26 +00:00
|
|
|
CHECK(!iterator.done());
|
2016-08-08 01:15:22 +00:00
|
|
|
offset += Bytecodes::Size(Bytecode::kAdd, OperandScale::kSingle);
|
2016-05-25 09:55:26 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kStar);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
|
|
|
EXPECT_EQ(iterator.GetRegisterOperand(0).index(), param.index());
|
|
|
|
EXPECT_EQ(iterator.GetRegisterOperandRange(0), 1);
|
2016-04-01 12:08:53 +00:00
|
|
|
CHECK(!iterator.done());
|
|
|
|
offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
|
|
|
|
iterator.Advance();
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kCallRuntimeForPair);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
|
|
|
EXPECT_EQ(iterator.GetRuntimeIdOperand(0), Runtime::kLoadLookupSlotForCall);
|
|
|
|
EXPECT_EQ(iterator.GetRegisterOperand(1).index(), param.index());
|
|
|
|
EXPECT_EQ(iterator.GetRegisterOperandRange(1), 1);
|
|
|
|
EXPECT_EQ(iterator.GetRegisterCountOperand(2), 1u);
|
|
|
|
EXPECT_EQ(iterator.GetRegisterOperand(3).index(), reg_0.index());
|
|
|
|
EXPECT_EQ(iterator.GetRegisterOperandRange(3), 2);
|
2016-04-01 12:08:53 +00:00
|
|
|
CHECK(!iterator.done());
|
|
|
|
offset +=
|
|
|
|
Bytecodes::Size(Bytecode::kCallRuntimeForPair, OperandScale::kSingle);
|
|
|
|
iterator.Advance();
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kForInPrepare);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
|
|
|
EXPECT_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
|
|
|
|
EXPECT_EQ(iterator.GetRegisterOperandRange(0), 3);
|
2017-10-19 15:12:42 +00:00
|
|
|
EXPECT_EQ(iterator.GetIndexOperand(1), forin_feedback_slot);
|
2015-09-10 16:21:34 +00:00
|
|
|
CHECK(!iterator.done());
|
2016-04-01 12:08:53 +00:00
|
|
|
offset += Bytecodes::Size(Bytecode::kForInPrepare, OperandScale::kSingle);
|
2015-09-10 16:21:34 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kCallRuntime);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
|
|
|
EXPECT_EQ(iterator.GetRuntimeIdOperand(0), Runtime::kLoadIC_Miss);
|
|
|
|
EXPECT_EQ(iterator.GetRegisterOperand(1).index(), reg_0.index());
|
|
|
|
EXPECT_EQ(iterator.GetRegisterCountOperand(2), 1u);
|
2015-10-02 18:13:41 +00:00
|
|
|
CHECK(!iterator.done());
|
2016-04-01 12:08:53 +00:00
|
|
|
offset += Bytecodes::Size(Bytecode::kCallRuntime, OperandScale::kSingle);
|
2015-10-02 18:13:41 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kDebugger);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
2016-02-04 15:06:25 +00:00
|
|
|
CHECK(!iterator.done());
|
2016-04-01 12:08:53 +00:00
|
|
|
offset += Bytecodes::Size(Bytecode::kDebugger, OperandScale::kSingle);
|
2016-02-04 15:06:25 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kLdaGlobal);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
2017-10-19 15:12:42 +00:00
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
|
|
|
EXPECT_EQ(iterator.current_bytecode_size(), 3);
|
|
|
|
EXPECT_EQ(iterator.GetIndexOperand(1), load_global_feedback_slot);
|
|
|
|
offset += Bytecodes::Size(Bytecode::kLdaGlobal, OperandScale::kSingle);
|
2016-03-21 17:08:21 +00:00
|
|
|
iterator.Advance();
|
|
|
|
|
2017-09-01 10:49:06 +00:00
|
|
|
EXPECT_EQ(iterator.current_bytecode(), Bytecode::kReturn);
|
|
|
|
EXPECT_EQ(iterator.current_offset(), offset);
|
|
|
|
EXPECT_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
|
2015-09-10 16:21:34 +00:00
|
|
|
CHECK(!iterator.done());
|
|
|
|
iterator.Advance();
|
|
|
|
CHECK(iterator.done());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace interpreter
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|