[interpreter] A couple of minor tweaks to BytecodeArray.
authorrmcilroy <rmcilroy@chromium.org>
Fri, 24 Jul 2015 14:56:26 +0000 (07:56 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 24 Jul 2015 14:56:34 +0000 (14:56 +0000)
 - 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}

src/factory.cc
src/factory.h
src/heap/heap.cc
src/heap/heap.h
src/interpreter/interpreter.h
src/objects-inl.h
src/objects.cc
src/objects.h
test/cctest/test-heap.cc

index 4fb5ec4..e2a5e05 100644 (file)
@@ -874,10 +874,11 @@ Handle<ByteArray> Factory::NewByteArray(int length, PretenureFlag pretenure) {
 
 
 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);
 }
 
index 478a48e..1253779 100644 (file)
@@ -283,7 +283,8 @@ class Factory final {
   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,
index a999dcc..80b28d1 100644 (file)
@@ -3068,7 +3068,9 @@ bool Heap::CreateInitialMaps() {
       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);
@@ -3821,7 +3823,8 @@ AllocationResult Heap::AllocateByteArray(int length, PretenureFlag pretenure) {
 
 
 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);
   }
@@ -3836,6 +3839,7 @@ AllocationResult Heap::AllocateBytecodeArray(int length,
   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;
index c981884..edc3d2c 100644 (file)
@@ -1682,7 +1682,8 @@ class Heap {
 
   // 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.
index b084ec9..9af55d9 100644 (file)
@@ -30,8 +30,6 @@ class Interpreter {
 
   void Initialize(bool create_heap_objects);
 
-  static bool MakeBytecode(CompilationInfo* info);
-
  private:
 // Bytecode handler generator functions.
 #define DECLARE_BYTECODE_HANDLER_GENERATOR(Name, _) \
index 0555440..8e28aac 100644 (file)
@@ -3639,8 +3639,17 @@ void BytecodeArray::set(int index, byte value) {
 }
 
 
-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() {
index 844887b..5e218e8 100644 (file)
@@ -11618,8 +11618,7 @@ void Code::Disassemble(const char* name, std::ostream& os) {  // NOLINT
 
 
 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) {
@@ -11635,7 +11634,7 @@ void BytecodeArray::Disassemble(std::ostream& os) {
     for (int j = bytecode_size; j < interpreter::Bytecodes::kMaximumSize; j++) {
       os << "   ";
     }
-    os << bytecode;
+    os << bytecode << "\n";
   }
 }
 
index f0180a1..342a00e 100644 (file)
@@ -4254,8 +4254,6 @@ class BytecodeArray : public FixedArrayBase {
   // 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)
 
@@ -4269,8 +4267,7 @@ class BytecodeArray : public FixedArrayBase {
 
   // 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);
 
index e0f758d..3729917 100644 (file)
@@ -571,7 +571,6 @@ TEST(BytecodeArray) {
   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();
@@ -581,13 +580,11 @@ TEST(BytecodeArray) {
 
   // 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());
@@ -601,7 +598,6 @@ TEST(BytecodeArray) {
 
   // 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++) {