Handle<BytecodeArray> Factory::NewBytecodeArray(int length,
- const byte* raw_bytecodes) {
+ const byte* raw_bytecodes,
+ int frame_size) {
DCHECK(0 <= length);
CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateBytecodeArray(
- length, raw_bytecodes),
+ length, raw_bytecodes, frame_size),
BytecodeArray);
}
Handle<ByteArray> NewByteArray(int length,
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(
int length,
set_empty_byte_array(byte_array);
BytecodeArray* bytecode_array;
- if (!AllocateBytecodeArray(0, nullptr).To(&bytecode_array)) {
+ AllocationResult allocation =
+ AllocateBytecodeArray(0, nullptr, kPointerSize);
+ if (!allocation.To(&bytecode_array)) {
return false;
}
set_empty_bytecode_array(bytecode_array);
AllocationResult Heap::AllocateBytecodeArray(int length,
- const byte* const raw_bytecodes) {
+ const byte* const raw_bytecodes,
+ int frame_size) {
if (length < 0 || length > BytecodeArray::kMaxLength) {
v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true);
}
result->set_map_no_write_barrier(bytecode_array_map());
BytecodeArray* instance = BytecodeArray::cast(result);
instance->set_length(length);
+ instance->set_frame_size(frame_size);
CopyBytes(instance->GetFirstBytecodeAddress(), raw_bytecodes, length);
return result;
// Allocates a bytecode array with given contents.
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
// the provided data as the relocation information.
void Initialize(bool create_heap_objects);
- static bool MakeBytecode(CompilationInfo* info);
-
private:
// Bytecode handler generator functions.
#define DECLARE_BYTECODE_HANDLER_GENERATOR(Name, _) \
}
-INT_ACCESSORS(BytecodeArray, frame_size, kFrameSizeOffset)
-INT_ACCESSORS(BytecodeArray, number_of_locals, kNumberOfLocalsOffset)
+void BytecodeArray::set_frame_size(int frame_size) {
+ // 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() {
void BytecodeArray::Disassemble(std::ostream& os) {
- os << "Frame size " << frame_size()
- << ", number of locals = " << number_of_locals() << "\n";
+ os << "Frame size " << frame_size() << "\n";
Vector<char> buf = Vector<char>::New(50);
int bytecode_size = 0;
for (int i = 0; i < this->length(); i += bytecode_size) {
for (int j = bytecode_size; j < interpreter::Bytecodes::kMaximumSize; j++) {
os << " ";
}
- os << bytecode;
+ os << bytecode << "\n";
}
}
// Accessors for frame size and the number of locals
inline int frame_size() const;
inline void set_frame_size(int value);
- inline int number_of_locals() const;
- inline void set_number_of_locals(int value);
DECLARE_CAST(BytecodeArray)
// Layout description.
static const int kFrameSizeOffset = FixedArrayBase::kHeaderSize;
- static const int kNumberOfLocalsOffset = kFrameSizeOffset + kIntSize;
- static const int kHeaderSize = kNumberOfLocalsOffset + kIntSize;
+ static const int kHeaderSize = kFrameSizeOffset + kIntSize;
static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
static const uint8_t kRawBytes[] = {0xc3, 0x7e, 0xa5, 0x5a};
static const int kRawBytesSize = sizeof(kRawBytes);
static const int kFrameSize = 32;
- static const int kNumberOfLocals = 20;
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
// Allocate and initialize BytecodeArray
Handle<BytecodeArray> array =
- factory->NewBytecodeArray(kRawBytesSize, kRawBytes);
-
- array->set_frame_size(kFrameSize);
- array->set_number_of_locals(kNumberOfLocals);
+ factory->NewBytecodeArray(kRawBytesSize, kRawBytes, kFrameSize);
CHECK(array->IsBytecodeArray());
CHECK_EQ(array->length(), (int)sizeof(kRawBytes));
+ CHECK_EQ(array->frame_size(), kFrameSize);
CHECK_LE(array->address(), array->GetFirstBytecodeAddress());
CHECK_GE(array->address() + array->BytecodeArraySize(),
array->GetFirstBytecodeAddress() + array->length());
// BytecodeArray should survive
CHECK_EQ(array->length(), kRawBytesSize);
- CHECK_EQ(array->number_of_locals(), kNumberOfLocals);
CHECK_EQ(array->frame_size(), kFrameSize);
for (int i = 0; i < kRawBytesSize; i++) {