[Interpereter] Inline FastNewClosure into CreateClosure bytecode handler

BUG=v8:4280

Review-Url: https://codereview.chromium.org/2113613002
Cr-Commit-Position: refs/heads/master@{#37453}
This commit is contained in:
rmcilroy 2016-06-30 08:32:28 -07:00 committed by Commit bot
parent c17b44bd3a
commit 02c3414d62
19 changed files with 118 additions and 69 deletions

View File

@ -323,10 +323,10 @@ BytecodeArrayBuilder& BytecodeArrayBuilder::StoreKeyedProperty(
}
BytecodeArrayBuilder& BytecodeArrayBuilder::CreateClosure(
Handle<SharedFunctionInfo> shared_info, PretenureFlag tenured) {
Handle<SharedFunctionInfo> shared_info, int flags) {
size_t entry = GetConstantPoolEntry(shared_info);
Output(Bytecode::kCreateClosure, UnsignedOperand(entry),
UnsignedOperand(static_cast<size_t>(tenured)));
UnsignedOperand(flags));
return *this;
}

View File

@ -129,7 +129,7 @@ class BytecodeArrayBuilder final : public ZoneObject {
// Create a new closure for the SharedFunctionInfo.
BytecodeArrayBuilder& CreateClosure(Handle<SharedFunctionInfo> shared_info,
PretenureFlag tenured);
int flags);
// Create a new arguments object in the accumulator.
BytecodeArrayBuilder& CreateArguments(CreateArgumentsType type);

View File

@ -1300,8 +1300,9 @@ void BytecodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) {
if (shared_info.is_null()) {
return SetStackOverflow();
}
builder()->CreateClosure(shared_info,
expr->pretenure() ? TENURED : NOT_TENURED);
uint8_t flags = CreateClosureFlags::Encode(expr->pretenure(),
scope()->is_function_scope());
builder()->CreateClosure(shared_info, flags);
execution_result()->SetResultInAccumulator();
}
@ -1518,18 +1519,10 @@ void BytecodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
// Copy the literal boilerplate.
int fast_clone_properties_count = 0;
if (FastCloneShallowObjectStub::IsSupported(expr)) {
STATIC_ASSERT(
FastCloneShallowObjectStub::kMaximumClonedProperties <=
1 << CreateObjectLiteralFlags::FastClonePropertiesCountBits::kShift);
fast_clone_properties_count =
FastCloneShallowObjectStub::PropertiesCount(expr->properties_count());
}
uint8_t flags =
CreateObjectLiteralFlags::FlagsBits::encode(expr->ComputeFlags()) |
CreateObjectLiteralFlags::FastClonePropertiesCountBits::encode(
fast_clone_properties_count);
uint8_t flags = CreateObjectLiteralFlags::Encode(
FastCloneShallowObjectStub::IsSupported(expr),
FastCloneShallowObjectStub::PropertiesCount(expr->properties_count()),
expr->ComputeFlags());
builder()->CreateObjectLiteral(expr->constant_properties(),
expr->literal_index(), flags);

View File

@ -7,6 +7,7 @@
#include <iomanip>
#include "src/base/bits.h"
#include "src/code-stubs.h"
#include "src/frames.h"
#include "src/interpreter/bytecode-traits.h"
#include "src/interpreter/interpreter.h"
@ -916,6 +917,33 @@ std::string Register::ToString(int parameter_count) {
}
}
// static
uint8_t CreateObjectLiteralFlags::Encode(bool fast_clone_supported,
int properties_count,
int runtime_flags) {
uint8_t result = FlagsBits::encode(runtime_flags);
if (fast_clone_supported) {
STATIC_ASSERT(
FastCloneShallowObjectStub::kMaximumClonedProperties <=
1 << CreateObjectLiteralFlags::FastClonePropertiesCountBits::kShift);
DCHECK_LE(properties_count,
FastCloneShallowObjectStub::kMaximumClonedProperties);
result |= CreateObjectLiteralFlags::FastClonePropertiesCountBits::encode(
properties_count);
}
return result;
}
// static
uint8_t CreateClosureFlags::Encode(bool pretenure, bool is_function_scope) {
uint8_t result = PretenuredBit::encode(pretenure);
if (!FLAG_always_opt && !FLAG_prepare_always_opt &&
pretenure == NOT_TENURED && is_function_scope) {
result |= FastNewClosureBit::encode(true);
}
return result;
}
} // namespace interpreter
} // namespace internal
} // namespace v8

View File

@ -661,7 +661,23 @@ class CreateObjectLiteralFlags {
class FlagsBits : public BitField8<int, 0, 3> {};
class FastClonePropertiesCountBits
: public BitField8<int, FlagsBits::kNext, 3> {};
STATIC_ASSERT((FlagsBits::kMask & FastClonePropertiesCountBits::kMask) == 0);
static uint8_t Encode(bool fast_clone_supported, int properties_count,
int runtime_flags);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(CreateObjectLiteralFlags);
};
class CreateClosureFlags {
public:
class PretenuredBit : public BitField8<bool, 0, 1> {};
class FastNewClosureBit : public BitField8<bool, PretenuredBit::kNext, 1> {};
static uint8_t Encode(bool pretenure, bool is_function_scope);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(CreateClosureFlags);
};
std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode);

View File

@ -1492,17 +1492,29 @@ void Interpreter::DoCreateObjectLiteral(InterpreterAssembler* assembler) {
// Creates a new closure for SharedFunctionInfo at position |index| in the
// constant pool and with the PretenureFlag <tenured>.
void Interpreter::DoCreateClosure(InterpreterAssembler* assembler) {
// TODO(rmcilroy): Possibly call FastNewClosureStub when possible instead of
// calling into the runtime.
Node* index = __ BytecodeOperandIdx(0);
Node* shared = __ LoadConstantPoolEntry(index);
Node* tenured_raw = __ BytecodeOperandFlag(1);
Node* tenured = __ SmiTag(tenured_raw);
Node* flags = __ BytecodeOperandFlag(1);
Node* context = __ GetContext();
Node* result =
__ CallRuntime(Runtime::kInterpreterNewClosure, context, shared, tenured);
__ SetAccumulator(result);
Label call_runtime(assembler, Label::kDeferred);
Node* fast_new_closure = __ Word32And(
flags, __ Int32Constant(CreateClosureFlags::FastNewClosureBit::kMask));
__ GotoUnless(fast_new_closure, &call_runtime);
__ SetAccumulator(FastNewClosureStub::Generate(assembler, shared, context));
__ Dispatch();
__ Bind(&call_runtime);
{
STATIC_ASSERT(CreateClosureFlags::PretenuredBit::kShift == 0);
Node* tenured_raw = __ Word32And(
flags, __ Int32Constant(CreateClosureFlags::PretenuredBit::kMask));
Node* tenured = __ SmiTag(tenured_raw);
Node* result = __ CallRuntime(Runtime::kInterpreterNewClosure, context,
shared, tenured);
__ SetAccumulator(result);
__ Dispatch();
}
}
// CreateMappedArguments

View File

@ -712,7 +712,7 @@ bytecodes: [
B(PushContext), R(3),
B(LdaTheHole),
B(StaContextSlot), R(context), U8(4),
B(CreateClosure), U8(1), U8(0),
B(CreateClosure), U8(1), U8(2),
B(Star), R(0),
/* 73 S> */ B(LdaSmi), U8(1),
/* 73 E> */ B(StaContextSlot), R(context), U8(4),

View File

@ -114,7 +114,7 @@ bytecodes: [
B(PushContext), R(2),
B(LdaTheHole),
B(StaContextSlot), R(context), U8(4),
B(CreateClosure), U8(1), U8(0),
B(CreateClosure), U8(1), U8(2),
B(Star), R(0),
/* 53 S> */ B(LdaSmi), U8(10),
/* 53 E> */ B(StaContextSlot), R(context), U8(4),
@ -168,7 +168,7 @@ bytecodes: [
B(PushContext), R(3),
B(LdaTheHole),
B(StaContextSlot), R(context), U8(4),
B(CreateClosure), U8(1), U8(0),
B(CreateClosure), U8(1), U8(2),
B(Star), R(0),
/* 76 S> */ B(LdaSmi), U8(2),
/* 76 E> */ B(StaContextSlot), R(context), U8(4),

View File

@ -24,7 +24,7 @@ bytecodes: [
B(Ldar), R(new_target),
B(StaContextSlot), R(context), U8(6),
/* 30 E> */ B(StackCheck),
/* 34 S> */ B(CreateClosure), U8(0), U8(0),
/* 34 S> */ B(CreateClosure), U8(0), U8(2),
/* 36 E> */ B(StaLookupSlotSloppy), U8(1),
/* 52 S> */ B(LdaConstant), U8(2),
B(Star), R(3),

View File

@ -25,7 +25,7 @@ bytecodes: [
B(Star), R(0),
B(LdaTheHole),
B(Star), R(2),
B(CreateClosure), U8(0), U8(0),
B(CreateClosure), U8(0), U8(2),
B(Star), R(3),
B(LdaSmi), U8(34),
B(Star), R(4),
@ -36,7 +36,7 @@ bytecodes: [
B(LdrNamedProperty), R(2), U8(1), U8(1), R(3),
B(LdaConstant), U8(2),
B(Star), R(5),
B(CreateClosure), U8(3), U8(0),
B(CreateClosure), U8(3), U8(2),
B(Star), R(6),
B(LdaSmi), U8(2),
B(Star), R(7),
@ -77,7 +77,7 @@ bytecodes: [
B(Star), R(0),
B(LdaTheHole),
B(Star), R(2),
B(CreateClosure), U8(0), U8(0),
B(CreateClosure), U8(0), U8(2),
B(Star), R(3),
B(LdaSmi), U8(34),
B(Star), R(4),
@ -88,7 +88,7 @@ bytecodes: [
B(LdrNamedProperty), R(2), U8(1), U8(1), R(3),
B(LdaConstant), U8(2),
B(Star), R(5),
B(CreateClosure), U8(3), U8(0),
B(CreateClosure), U8(3), U8(2),
B(Star), R(6),
B(LdaSmi), U8(2),
B(Star), R(7),
@ -137,7 +137,7 @@ bytecodes: [
B(Star), R(0),
B(LdaTheHole),
B(Star), R(3),
B(CreateClosure), U8(2), U8(0),
B(CreateClosure), U8(2), U8(2),
B(Star), R(4),
B(LdaSmi), U8(62),
B(Star), R(5),
@ -149,7 +149,7 @@ bytecodes: [
/* 75 E> */ B(LdaContextSlot), R(context), U8(4),
B(ToName),
B(Star), R(6),
B(CreateClosure), U8(4), U8(0),
B(CreateClosure), U8(4), U8(2),
B(Star), R(7),
B(LdaSmi), U8(2),
B(Star), R(8),
@ -165,7 +165,7 @@ bytecodes: [
B(Mov), R(3), R(5),
B(JumpIfToBooleanFalse), U8(7),
B(CallRuntime), U16(Runtime::kThrowStaticPrototypeError), R(0), U8(0),
B(CreateClosure), U8(5), U8(0),
B(CreateClosure), U8(5), U8(2),
B(Star), R(7),
B(LdaSmi), U8(1),
B(Star), R(9),
@ -208,7 +208,7 @@ bytecodes: [
B(Star), R(0),
B(LdaTheHole),
B(Star), R(3),
B(CreateClosure), U8(0), U8(0),
B(CreateClosure), U8(0), U8(2),
B(Star), R(4),
B(LdaSmi), U8(49),
B(Star), R(5),

View File

@ -119,7 +119,7 @@ bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(1),
/* 42 E> */ B(StaContextSlot), R(context), U8(4),
/* 45 S> */ B(CreateClosure), U8(0), U8(0),
/* 45 S> */ B(CreateClosure), U8(0), U8(2),
/* 75 S> */ B(LdrContextSlot), R(context), U8(4), R(1),
B(LdaSmi), U8(24),
B(BitwiseOr), R(1),

View File

@ -19,7 +19,7 @@ bytecodes: [
B(PushContext), R(1),
B(LdaTheHole),
B(StaContextSlot), R(context), U8(4),
B(CreateClosure), U8(0), U8(0),
B(CreateClosure), U8(0), U8(2),
B(Star), R(0),
/* 30 E> */ B(StackCheck),
/* 44 S> */ B(LdaSmi), U8(10),
@ -45,7 +45,7 @@ bytecodes: [
B(PushContext), R(1),
B(LdaTheHole),
B(StaContextSlot), R(context), U8(4),
B(CreateClosure), U8(0), U8(0),
B(CreateClosure), U8(0), U8(2),
B(Star), R(0),
/* 30 E> */ B(StackCheck),
/* 44 S> */ B(LdaSmi), U8(10),
@ -76,7 +76,7 @@ bytecodes: [
B(PushContext), R(1),
B(LdaTheHole),
B(StaContextSlot), R(context), U8(4),
B(CreateClosure), U8(0), U8(0),
B(CreateClosure), U8(0), U8(2),
B(Star), R(0),
/* 30 E> */ B(StackCheck),
/* 47 S> */ B(LdaSmi), U8(20),
@ -112,7 +112,7 @@ bytecodes: [
B(PushContext), R(1),
B(LdaTheHole),
B(StaContextSlot), R(context), U8(4),
B(CreateClosure), U8(0), U8(0),
B(CreateClosure), U8(0), U8(2),
B(Star), R(0),
/* 30 E> */ B(StackCheck),
/* 44 S> */ B(LdaSmi), U8(10),

View File

@ -22,7 +22,7 @@ bytecodes: [
B(Ldar), R(arg0),
B(StaContextSlot), R(context), U8(4),
/* 10 E> */ B(StackCheck),
/* 19 S> */ B(CreateClosure), U8(0), U8(0),
/* 19 S> */ B(CreateClosure), U8(0), U8(2),
/* 52 S> */ B(Return),
]
constant pool: [
@ -45,7 +45,7 @@ bytecodes: [
B(Ldar), R(arg0),
B(StaContextSlot), R(context), U8(4),
/* 10 E> */ B(StackCheck),
/* 27 S> */ B(CreateClosure), U8(0), U8(0),
/* 27 S> */ B(CreateClosure), U8(0), U8(2),
B(Star), R(0),
/* 53 S> */ B(LdaContextSlot), R(context), U8(4),
/* 66 S> */ B(Return),
@ -72,7 +72,7 @@ bytecodes: [
B(Ldar), R(arg2),
B(StaContextSlot), R(context), U8(4),
/* 10 E> */ B(StackCheck),
/* 29 S> */ B(CreateClosure), U8(0), U8(0),
/* 29 S> */ B(CreateClosure), U8(0), U8(2),
/* 61 S> */ B(Return),
]
constant pool: [
@ -95,7 +95,7 @@ bytecodes: [
/* 10 E> */ B(StackCheck),
/* 26 S> */ B(Ldar), R(this),
/* 26 E> */ B(StaContextSlot), R(context), U8(4),
/* 32 S> */ B(CreateClosure), U8(0), U8(0),
/* 32 S> */ B(CreateClosure), U8(0), U8(2),
/* 65 S> */ B(Return),
]
constant pool: [

View File

@ -18,7 +18,7 @@ bytecodes: [
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), U8(1),
B(PushContext), R(0),
/* 30 E> */ B(StackCheck),
/* 41 S> */ B(CreateClosure), U8(0), U8(0),
/* 41 S> */ B(CreateClosure), U8(0), U8(2),
/* 71 S> */ B(Return),
]
constant pool: [
@ -40,7 +40,7 @@ bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(1),
/* 42 E> */ B(StaContextSlot), R(context), U8(4),
/* 45 S> */ B(CreateClosure), U8(0), U8(0),
/* 45 S> */ B(CreateClosure), U8(0), U8(2),
/* 75 S> */ B(Return),
]
constant pool: [
@ -64,7 +64,7 @@ bytecodes: [
/* 42 E> */ B(StaContextSlot), R(context), U8(4),
/* 53 S> */ B(LdaSmi), U8(2),
/* 53 E> */ B(StaContextSlot), R(context), U8(5),
/* 56 S> */ B(CreateClosure), U8(0), U8(0),
/* 56 S> */ B(CreateClosure), U8(0), U8(2),
/* 92 S> */ B(Return),
]
constant pool: [
@ -85,7 +85,7 @@ bytecodes: [
B(PushContext), R(0),
/* 30 E> */ B(StackCheck),
/* 41 S> */ B(LdrUndefined), R(2),
B(CreateClosure), U8(0), U8(0),
B(CreateClosure), U8(0), U8(2),
B(Star), R(1),
/* 64 E> */ B(Call), R(1), R(2), U8(1), U8(1),
/* 68 S> */ B(LdaContextSlot), R(context), U8(4),
@ -123,7 +123,7 @@ bytecodes: [
B(StaContextSlot), R(context), U8(4),
/* 69 S> */ B(LdaSmi), U8(2),
/* 69 E> */ B(StaContextSlot), R(context), U8(4),
/* 72 S> */ B(CreateClosure), U8(1), U8(0),
/* 72 S> */ B(CreateClosure), U8(1), U8(2),
B(PopContext), R(0),
/* 104 S> */ B(Return),
]

View File

@ -214,7 +214,7 @@ bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(1),
/* 42 E> */ B(StaContextSlot), R(context), U8(4),
/* 53 S> */ B(CreateClosure), U8(0), U8(0),
/* 53 S> */ B(CreateClosure), U8(0), U8(2),
B(Star), R(0),
/* 78 S> */ B(LdaContextSlot), R(context), U8(4),
B(Inc),
@ -240,7 +240,7 @@ bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(1),
/* 42 E> */ B(StaContextSlot), R(context), U8(4),
/* 53 S> */ B(CreateClosure), U8(0), U8(0),
/* 53 S> */ B(CreateClosure), U8(0), U8(2),
B(Star), R(0),
/* 78 S> */ B(LdaContextSlot), R(context), U8(4),
B(ToNumber),

View File

@ -111,7 +111,7 @@ bytecodes: [
/* 56 S> */ B(CreateObjectLiteral), U8(0), U8(0), U8(1),
B(Star), R(1),
/* 56 E> */ B(StaContextSlot), R(context), U8(4),
/* 64 S> */ B(CreateClosure), U8(1), U8(0),
/* 64 S> */ B(CreateClosure), U8(1), U8(2),
/* 93 S> */ B(LdrContextSlot), R(context), U8(4), R(1),
B(LdaSmi), U8(1),
B(DeletePropertyStrict), R(1),

View File

@ -16,7 +16,7 @@ parameter count: 1
bytecode array length: 5
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 34 S> */ B(CreateClosure), U8(0), U8(0),
/* 34 S> */ B(CreateClosure), U8(0), U8(2),
/* 55 S> */ B(Return),
]
constant pool: [
@ -35,7 +35,7 @@ bytecode array length: 14
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 34 S> */ B(LdrUndefined), R(1),
B(CreateClosure), U8(0), U8(0),
B(CreateClosure), U8(0), U8(2),
B(Star), R(0),
/* 56 E> */ B(Call), R(0), R(1), U8(1), U8(1),
/* 59 S> */ B(Return),
@ -56,7 +56,7 @@ bytecode array length: 18
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 34 S> */ B(LdrUndefined), R(1),
B(CreateClosure), U8(0), U8(0),
B(CreateClosure), U8(0), U8(2),
B(Star), R(0),
B(LdaSmi), U8(1),
B(Star), R(2),

View File

@ -19,7 +19,7 @@ bytecodes: [
B(PushContext), R(1),
B(LdaTheHole),
B(StaContextSlot), R(context), U8(4),
B(CreateClosure), U8(0), U8(0),
B(CreateClosure), U8(0), U8(2),
B(Star), R(0),
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(10),
@ -45,7 +45,7 @@ bytecodes: [
B(PushContext), R(1),
B(LdaTheHole),
B(StaContextSlot), R(context), U8(4),
B(CreateClosure), U8(0), U8(0),
B(CreateClosure), U8(0), U8(2),
B(Star), R(0),
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(10),
@ -76,7 +76,7 @@ bytecodes: [
B(PushContext), R(1),
B(LdaTheHole),
B(StaContextSlot), R(context), U8(4),
B(CreateClosure), U8(0), U8(0),
B(CreateClosure), U8(0), U8(2),
B(Star), R(0),
/* 30 E> */ B(StackCheck),
/* 45 S> */ B(LdaSmi), U8(20),
@ -111,7 +111,7 @@ bytecodes: [
B(PushContext), R(1),
B(LdaTheHole),
B(StaContextSlot), R(context), U8(4),
B(CreateClosure), U8(0), U8(0),
B(CreateClosure), U8(0), U8(2),
B(Star), R(0),
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(10),

View File

@ -107,7 +107,7 @@ bytecodes: [
/* 30 E> */ B(StackCheck),
/* 34 S> */ B(CreateObjectLiteral), U8(0), U8(0), U8(1),
B(Star), R(0),
B(CreateClosure), U8(1), U8(0),
B(CreateClosure), U8(1), U8(2),
B(StaNamedPropertySloppy), R(0), U8(2), U8(1),
B(Ldar), R(0),
/* 67 S> */ B(Return),
@ -131,7 +131,7 @@ bytecodes: [
/* 30 E> */ B(StackCheck),
/* 34 S> */ B(CreateObjectLiteral), U8(0), U8(0), U8(1),
B(Star), R(0),
B(CreateClosure), U8(1), U8(0),
B(CreateClosure), U8(1), U8(2),
B(StaNamedPropertySloppy), R(0), U8(2), U8(1),
B(Ldar), R(0),
/* 68 S> */ B(Return),
@ -157,7 +157,7 @@ bytecodes: [
B(Star), R(0),
B(LdaConstant), U8(1),
B(Star), R(2),
B(CreateClosure), U8(2), U8(0),
B(CreateClosure), U8(2), U8(2),
B(Star), R(3),
B(LdaNull),
B(Star), R(4),
@ -189,9 +189,9 @@ bytecodes: [
B(Star), R(0),
B(LdaConstant), U8(1),
B(Star), R(2),
B(CreateClosure), U8(2), U8(0),
B(CreateClosure), U8(2), U8(2),
B(Star), R(3),
B(CreateClosure), U8(3), U8(0),
B(CreateClosure), U8(3), U8(2),
B(Star), R(4),
B(LdaZero),
B(Star), R(5),
@ -224,7 +224,7 @@ bytecodes: [
B(Star), R(2),
B(LdaNull),
B(Star), R(3),
B(CreateClosure), U8(2), U8(0),
B(CreateClosure), U8(2), U8(2),
B(Star), R(4),
B(LdaZero),
B(Star), R(5),
@ -429,7 +429,7 @@ bytecodes: [
B(CallRuntime), U16(Runtime::kDefineDataPropertyInLiteral), R(2), U8(5),
B(LdaConstant), U8(3),
B(Star), R(3),
B(CreateClosure), U8(4), U8(0),
B(CreateClosure), U8(4), U8(2),
B(Star), R(4),
B(LdaZero),
B(Star), R(5),
@ -437,7 +437,7 @@ bytecodes: [
B(CallRuntime), U16(Runtime::kDefineGetterPropertyUnchecked), R(2), U8(4),
B(LdaConstant), U8(3),
B(Star), R(3),
B(CreateClosure), U8(5), U8(0),
B(CreateClosure), U8(5), U8(2),
B(Star), R(4),
B(LdaZero),
B(Star), R(5),