Commit 9bb7b980 authored by rmcilroy's avatar rmcilroy Committed by Commit bot

[interpreter] A couple of minor tweaks to BytecodeArray.

 - Ensure frame_size is always set during allocation.
 - Add DCHECKs that frame_size is a valid value
 - Remove locals_count, which we don't need yet (possibly every)
 - Add a newline at the end of BytecodeArray::Dissassemble
   for each bytecode.

BUG=v8:4280
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#29852}
parent fa987b4b
...@@ -874,10 +874,11 @@ Handle<ByteArray> Factory::NewByteArray(int length, PretenureFlag pretenure) { ...@@ -874,10 +874,11 @@ Handle<ByteArray> Factory::NewByteArray(int length, PretenureFlag pretenure) {
Handle<BytecodeArray> Factory::NewBytecodeArray(int length, Handle<BytecodeArray> Factory::NewBytecodeArray(int length,
const byte* raw_bytecodes) { const byte* raw_bytecodes,
int frame_size) {
DCHECK(0 <= length); DCHECK(0 <= length);
CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateBytecodeArray( CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateBytecodeArray(
length, raw_bytecodes), length, raw_bytecodes, frame_size),
BytecodeArray); BytecodeArray);
} }
......
...@@ -283,7 +283,8 @@ class Factory final { ...@@ -283,7 +283,8 @@ class Factory final {
Handle<ByteArray> NewByteArray(int length, Handle<ByteArray> NewByteArray(int length,
PretenureFlag pretenure = NOT_TENURED); PretenureFlag pretenure = NOT_TENURED);
Handle<BytecodeArray> NewBytecodeArray(int length, const byte* raw_bytecodes); Handle<BytecodeArray> NewBytecodeArray(int length, const byte* raw_bytecodes,
int frame_size);
Handle<ExternalArray> NewExternalArray( Handle<ExternalArray> NewExternalArray(
int length, int length,
......
...@@ -3068,7 +3068,9 @@ bool Heap::CreateInitialMaps() { ...@@ -3068,7 +3068,9 @@ bool Heap::CreateInitialMaps() {
set_empty_byte_array(byte_array); set_empty_byte_array(byte_array);
BytecodeArray* bytecode_array; BytecodeArray* bytecode_array;
if (!AllocateBytecodeArray(0, nullptr).To(&bytecode_array)) { AllocationResult allocation =
AllocateBytecodeArray(0, nullptr, kPointerSize);
if (!allocation.To(&bytecode_array)) {
return false; return false;
} }
set_empty_bytecode_array(bytecode_array); set_empty_bytecode_array(bytecode_array);
...@@ -3821,7 +3823,8 @@ AllocationResult Heap::AllocateByteArray(int length, PretenureFlag pretenure) { ...@@ -3821,7 +3823,8 @@ AllocationResult Heap::AllocateByteArray(int length, PretenureFlag pretenure) {
AllocationResult Heap::AllocateBytecodeArray(int length, AllocationResult Heap::AllocateBytecodeArray(int length,
const byte* const raw_bytecodes) { const byte* const raw_bytecodes,
int frame_size) {
if (length < 0 || length > BytecodeArray::kMaxLength) { if (length < 0 || length > BytecodeArray::kMaxLength) {
v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true); v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true);
} }
...@@ -3836,6 +3839,7 @@ AllocationResult Heap::AllocateBytecodeArray(int length, ...@@ -3836,6 +3839,7 @@ AllocationResult Heap::AllocateBytecodeArray(int length,
result->set_map_no_write_barrier(bytecode_array_map()); result->set_map_no_write_barrier(bytecode_array_map());
BytecodeArray* instance = BytecodeArray::cast(result); BytecodeArray* instance = BytecodeArray::cast(result);
instance->set_length(length); instance->set_length(length);
instance->set_frame_size(frame_size);
CopyBytes(instance->GetFirstBytecodeAddress(), raw_bytecodes, length); CopyBytes(instance->GetFirstBytecodeAddress(), raw_bytecodes, length);
return result; return result;
......
...@@ -1682,7 +1682,8 @@ class Heap { ...@@ -1682,7 +1682,8 @@ class Heap {
// Allocates a bytecode array with given contents. // Allocates a bytecode array with given contents.
MUST_USE_RESULT AllocationResult MUST_USE_RESULT AllocationResult
AllocateBytecodeArray(int length, const byte* raw_bytecodes); AllocateBytecodeArray(int length, const byte* raw_bytecodes,
int frame_size);
// Copy the code and scope info part of the code object, but insert // Copy the code and scope info part of the code object, but insert
// the provided data as the relocation information. // the provided data as the relocation information.
......
...@@ -30,8 +30,6 @@ class Interpreter { ...@@ -30,8 +30,6 @@ class Interpreter {
void Initialize(bool create_heap_objects); void Initialize(bool create_heap_objects);
static bool MakeBytecode(CompilationInfo* info);
private: private:
// Bytecode handler generator functions. // Bytecode handler generator functions.
#define DECLARE_BYTECODE_HANDLER_GENERATOR(Name, _) \ #define DECLARE_BYTECODE_HANDLER_GENERATOR(Name, _) \
......
...@@ -3639,8 +3639,17 @@ void BytecodeArray::set(int index, byte value) { ...@@ -3639,8 +3639,17 @@ void BytecodeArray::set(int index, byte value) {
} }
INT_ACCESSORS(BytecodeArray, frame_size, kFrameSizeOffset) void BytecodeArray::set_frame_size(int frame_size) {
INT_ACCESSORS(BytecodeArray, number_of_locals, kNumberOfLocalsOffset) // We need at least one stack slot for the return register.
DCHECK_GE(frame_size, kPointerSize);
DCHECK(IsAligned(frame_size, static_cast<unsigned>(kPointerSize)));
WRITE_INT_FIELD(this, kFrameSizeOffset, frame_size);
}
int BytecodeArray::frame_size() const {
return READ_INT_FIELD(this, kFrameSizeOffset);
}
Address BytecodeArray::GetFirstBytecodeAddress() { Address BytecodeArray::GetFirstBytecodeAddress() {
......
...@@ -11618,8 +11618,7 @@ void Code::Disassemble(const char* name, std::ostream& os) { // NOLINT ...@@ -11618,8 +11618,7 @@ void Code::Disassemble(const char* name, std::ostream& os) { // NOLINT
void BytecodeArray::Disassemble(std::ostream& os) { void BytecodeArray::Disassemble(std::ostream& os) {
os << "Frame size " << frame_size() os << "Frame size " << frame_size() << "\n";
<< ", number of locals = " << number_of_locals() << "\n";
Vector<char> buf = Vector<char>::New(50); Vector<char> buf = Vector<char>::New(50);
int bytecode_size = 0; int bytecode_size = 0;
for (int i = 0; i < this->length(); i += bytecode_size) { for (int i = 0; i < this->length(); i += bytecode_size) {
...@@ -11635,7 +11634,7 @@ void BytecodeArray::Disassemble(std::ostream& os) { ...@@ -11635,7 +11634,7 @@ void BytecodeArray::Disassemble(std::ostream& os) {
for (int j = bytecode_size; j < interpreter::Bytecodes::kMaximumSize; j++) { for (int j = bytecode_size; j < interpreter::Bytecodes::kMaximumSize; j++) {
os << " "; os << " ";
} }
os << bytecode; os << bytecode << "\n";
} }
} }
......
...@@ -4254,8 +4254,6 @@ class BytecodeArray : public FixedArrayBase { ...@@ -4254,8 +4254,6 @@ class BytecodeArray : public FixedArrayBase {
// Accessors for frame size and the number of locals // Accessors for frame size and the number of locals
inline int frame_size() const; inline int frame_size() const;
inline void set_frame_size(int value); inline void set_frame_size(int value);
inline int number_of_locals() const;
inline void set_number_of_locals(int value);
DECLARE_CAST(BytecodeArray) DECLARE_CAST(BytecodeArray)
...@@ -4269,8 +4267,7 @@ class BytecodeArray : public FixedArrayBase { ...@@ -4269,8 +4267,7 @@ class BytecodeArray : public FixedArrayBase {
// Layout description. // Layout description.
static const int kFrameSizeOffset = FixedArrayBase::kHeaderSize; static const int kFrameSizeOffset = FixedArrayBase::kHeaderSize;
static const int kNumberOfLocalsOffset = kFrameSizeOffset + kIntSize; static const int kHeaderSize = kFrameSizeOffset + kIntSize;
static const int kHeaderSize = kNumberOfLocalsOffset + kIntSize;
static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
......
...@@ -571,7 +571,6 @@ TEST(BytecodeArray) { ...@@ -571,7 +571,6 @@ TEST(BytecodeArray) {
static const uint8_t kRawBytes[] = {0xc3, 0x7e, 0xa5, 0x5a}; static const uint8_t kRawBytes[] = {0xc3, 0x7e, 0xa5, 0x5a};
static const int kRawBytesSize = sizeof(kRawBytes); static const int kRawBytesSize = sizeof(kRawBytes);
static const int kFrameSize = 32; static const int kFrameSize = 32;
static const int kNumberOfLocals = 20;
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
...@@ -581,13 +580,11 @@ TEST(BytecodeArray) { ...@@ -581,13 +580,11 @@ TEST(BytecodeArray) {
// Allocate and initialize BytecodeArray // Allocate and initialize BytecodeArray
Handle<BytecodeArray> array = Handle<BytecodeArray> array =
factory->NewBytecodeArray(kRawBytesSize, kRawBytes); factory->NewBytecodeArray(kRawBytesSize, kRawBytes, kFrameSize);
array->set_frame_size(kFrameSize);
array->set_number_of_locals(kNumberOfLocals);
CHECK(array->IsBytecodeArray()); CHECK(array->IsBytecodeArray());
CHECK_EQ(array->length(), (int)sizeof(kRawBytes)); CHECK_EQ(array->length(), (int)sizeof(kRawBytes));
CHECK_EQ(array->frame_size(), kFrameSize);
CHECK_LE(array->address(), array->GetFirstBytecodeAddress()); CHECK_LE(array->address(), array->GetFirstBytecodeAddress());
CHECK_GE(array->address() + array->BytecodeArraySize(), CHECK_GE(array->address() + array->BytecodeArraySize(),
array->GetFirstBytecodeAddress() + array->length()); array->GetFirstBytecodeAddress() + array->length());
...@@ -601,7 +598,6 @@ TEST(BytecodeArray) { ...@@ -601,7 +598,6 @@ TEST(BytecodeArray) {
// BytecodeArray should survive // BytecodeArray should survive
CHECK_EQ(array->length(), kRawBytesSize); CHECK_EQ(array->length(), kRawBytesSize);
CHECK_EQ(array->number_of_locals(), kNumberOfLocals);
CHECK_EQ(array->frame_size(), kFrameSize); CHECK_EQ(array->frame_size(), kFrameSize);
for (int i = 0; i < kRawBytesSize; i++) { for (int i = 0; i < kRawBytesSize; i++) {
......
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