Introduce TypeFeedbackVector, as FixedArray grew constrictive.
authormvstanton@chromium.org <mvstanton@chromium.org>
Thu, 18 Sep 2014 09:59:53 +0000 (09:59 +0000)
committermvstanton@chromium.org <mvstanton@chromium.org>
Thu, 18 Sep 2014 09:59:53 +0000 (09:59 +0000)
The TypeFeedbackVector is poised to host significant functionality. While it
remains a FixedArray under the covers, we need a place to hold logic and
definitions unique to its function.

BUG=
R=ishell@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24027 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

16 files changed:
BUILD.gn
src/bootstrapper.cc
src/compiler.cc
src/compiler.h
src/factory.cc
src/factory.h
src/full-codegen.cc
src/liveedit.cc
src/liveedit.h
src/objects-inl.h
src/objects.h
src/type-feedback-vector.cc [new file with mode: 0644]
src/type-feedback-vector.h [new file with mode: 0644]
src/type-info.cc
src/type-info.h
tools/gyp/v8.gyp

index 4f95804996d14d61bc0d33ce96391baa26ed6d35..119d54e417feaee44466abc14fc1026fba829415 100644 (file)
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -848,6 +848,8 @@ source_set("v8_base") {
     "src/transitions-inl.h",
     "src/transitions.cc",
     "src/transitions.h",
+    "src/type-feedback-vector.cc",
+    "src/type-feedback-vector.h",
     "src/type-info.cc",
     "src/type-info.h",
     "src/types-inl.h",
index c2112526d865e85822c85faca6dbc1a3d9a053ca..855080c34869ea5b69d800df9f8f34ec626733aa 100644 (file)
@@ -1960,7 +1960,8 @@ bool Genesis::InstallNatives() {
     if (FLAG_vector_ics) {
       // Apply embeds an IC, so we need a type vector of size 1 in the shared
       // function info.
-      Handle<FixedArray> feedback_vector = factory()->NewTypeFeedbackVector(1);
+      Handle<TypeFeedbackVector> feedback_vector =
+          factory()->NewTypeFeedbackVector(1);
       apply->shared()->set_feedback_vector(*feedback_vector);
     }
 
index 1f98e30e2018bf2abe4bb50ed68afd9d15127a40..681f25edea40edbfd22e0418587da1fce0a2b5b0 100644 (file)
@@ -174,8 +174,8 @@ void CompilationInfo::Initialize(Isolate* isolate,
   if (!shared_info().is_null() && shared_info()->is_compiled()) {
     // We should initialize the CompilationInfo feedback vector from the
     // passed in shared info, rather than creating a new one.
-    feedback_vector_ = Handle<FixedArray>(shared_info()->feedback_vector(),
-                                          isolate);
+    feedback_vector_ =
+        Handle<TypeFeedbackVector>(shared_info()->feedback_vector(), isolate);
   }
 }
 
index 6bd632e37161400d536b2fb1d92a16b695cce6c1..308f138b6ae1f28645ed157423f20a2a44a92b73 100644 (file)
@@ -226,7 +226,7 @@ class CompilationInfo {
     DCHECK(global_scope_ == NULL);
     global_scope_ = global_scope;
   }
-  Handle<FixedArray> feedback_vector() const {
+  Handle<TypeFeedbackVector> feedback_vector() const {
     return feedback_vector_;
   }
   void SetCode(Handle<Code> code) { code_ = code; }
@@ -451,7 +451,7 @@ class CompilationInfo {
   Handle<Context> context_;
 
   // Used by codegen, ultimately kept rooted by the SharedFunctionInfo.
-  Handle<FixedArray> feedback_vector_;
+  Handle<TypeFeedbackVector> feedback_vector_;
 
   // Compilation mode flag and whether deoptimization is allowed.
   Mode mode_;
index 5303dd0cc25f6e1bf63f8dda30f833f5d0562af9..e4c106e8c250512dad82896f2b1f2ccaa9a2dbea 100644 (file)
@@ -1886,25 +1886,27 @@ void Factory::BecomeJSFunction(Handle<JSProxy> proxy) {
 }
 
 
-Handle<FixedArray> Factory::NewTypeFeedbackVector(int slot_count) {
+Handle<TypeFeedbackVector> Factory::NewTypeFeedbackVector(int slot_count) {
   // Ensure we can skip the write barrier
   DCHECK_EQ(isolate()->heap()->uninitialized_symbol(),
             *TypeFeedbackInfo::UninitializedSentinel(isolate()));
 
-  CALL_HEAP_FUNCTION(
-      isolate(),
-      isolate()->heap()->AllocateFixedArrayWithFiller(
-          slot_count,
-          TENURED,
-          *TypeFeedbackInfo::UninitializedSentinel(isolate())),
-      FixedArray);
+  if (slot_count == 0) {
+    return Handle<TypeFeedbackVector>::cast(empty_fixed_array());
+  }
+
+  CALL_HEAP_FUNCTION(isolate(),
+                     isolate()->heap()->AllocateFixedArrayWithFiller(
+                         slot_count, TENURED,
+                         *TypeFeedbackInfo::UninitializedSentinel(isolate())),
+                     TypeFeedbackVector);
 }
 
 
 Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
     Handle<String> name, int number_of_literals, FunctionKind kind,
     Handle<Code> code, Handle<ScopeInfo> scope_info,
-    Handle<FixedArray> feedback_vector) {
+    Handle<TypeFeedbackVector> feedback_vector) {
   DCHECK(IsValidFunctionKind(kind));
   Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name, code);
   shared->set_scope_info(*scope_info);
@@ -1972,7 +1974,7 @@ Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
   share->set_script(*undefined_value(), SKIP_WRITE_BARRIER);
   share->set_debug_info(*undefined_value(), SKIP_WRITE_BARRIER);
   share->set_inferred_name(*empty_string(), SKIP_WRITE_BARRIER);
-  share->set_feedback_vector(*empty_fixed_array(), SKIP_WRITE_BARRIER);
+  share->set_feedback_vector(*NewTypeFeedbackVector(0), SKIP_WRITE_BARRIER);
   share->set_profiler_ticks(0);
   share->set_ast_node_count(0);
   share->set_counters(0);
index 47b16f59fb480ebe151b67c5822a7cee86d28b25..24b490c3443961828d9f4529d34013acd937be36 100644 (file)
@@ -600,12 +600,12 @@ class Factory FINAL {
   Handle<SharedFunctionInfo> NewSharedFunctionInfo(
       Handle<String> name, int number_of_literals, FunctionKind kind,
       Handle<Code> code, Handle<ScopeInfo> scope_info,
-      Handle<FixedArray> feedback_vector);
+      Handle<TypeFeedbackVector> feedback_vector);
   Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name,
                                                    MaybeHandle<Code> code);
 
   // Allocate a new type feedback vector
-  Handle<FixedArray> NewTypeFeedbackVector(int slot_count);
+  Handle<TypeFeedbackVector> NewTypeFeedbackVector(int slot_count);
 
   // Allocates a new JSMessageObject object.
   Handle<JSMessageObject> NewJSMessageObject(
index c1642b1980da4d6be40b708a4c65bb6331f7491f..dd7558e8898c5455a8f0326ffee5b51fbf5c1ef9 100644 (file)
@@ -1572,7 +1572,7 @@ void FullCodeGenerator::VisitNativeFunctionLiteral(
       isolate()->factory()->NewSharedFunctionInfo(
           name, literals, FunctionKind::kNormalFunction, code,
           Handle<ScopeInfo>(fun->shared()->scope_info()),
-          Handle<FixedArray>(fun->shared()->feedback_vector()));
+          Handle<TypeFeedbackVector>(fun->shared()->feedback_vector()));
   shared->set_construct_stub(*construct_stub);
 
   // Copy the function data to the shared function info.
index 0ef701efa0bb90a82a6b23f49f05dabe026f2dec..a87c31bac17f544093162e0f93136aaa363eb864 100644 (file)
@@ -649,15 +649,15 @@ Handle<Code> FunctionInfoWrapper::GetFunctionCode() {
 }
 
 
-Handle<FixedArray> FunctionInfoWrapper::GetFeedbackVector() {
+Handle<TypeFeedbackVector> FunctionInfoWrapper::GetFeedbackVector() {
   Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_);
-  Handle<FixedArray> result;
+  Handle<TypeFeedbackVector> result;
   if (element->IsJSValue()) {
     Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element);
     Handle<Object> raw_result = UnwrapJSValue(value_wrapper);
     Handle<SharedFunctionInfo> shared =
         Handle<SharedFunctionInfo>::cast(raw_result);
-    result = Handle<FixedArray>(shared->feedback_vector(), isolate());
+    result = Handle<TypeFeedbackVector>(shared->feedback_vector(), isolate());
     CHECK_EQ(result->length(), GetSlotCount());
   } else {
     // Scripts may never have a SharedFunctionInfo created, so
@@ -1203,7 +1203,7 @@ void LiveEdit::ReplaceFunctionCode(
     }
     shared_info->DisableOptimization(kLiveEdit);
     // Update the type feedback vector
-    Handle<FixedArray> feedback_vector =
+    Handle<TypeFeedbackVector> feedback_vector =
         compile_info_wrapper.GetFeedbackVector();
     shared_info->set_feedback_vector(*feedback_vector);
   }
index 3465d886d776af703044a67166a1a0d8b63f8002..53418b0918964cf9e548f6d3e1f0d8595053d2e2 100644 (file)
@@ -307,7 +307,7 @@ class FunctionInfoWrapper : public JSArrayBasedStruct<FunctionInfoWrapper> {
 
   Handle<Code> GetFunctionCode();
 
-  Handle<FixedArray> GetFeedbackVector();
+  Handle<TypeFeedbackVector> GetFeedbackVector();
 
   Handle<Object> GetCodeScopeInfo();
 
index 4840b2de1963d869e3265036df57ff095be9bfde..8ae3cf8a69249fcfe530a9bb7ed9a265c6713ab7 100644 (file)
@@ -31,6 +31,7 @@
 #include "src/property.h"
 #include "src/prototype.h"
 #include "src/transitions-inl.h"
+#include "src/type-feedback-vector.h"
 #include "src/v8memory.h"
 
 namespace v8 {
@@ -708,6 +709,9 @@ bool Object::IsTransitionArray() const {
 }
 
 
+bool Object::IsTypeFeedbackVector() const { return IsFixedArray(); }
+
+
 bool Object::IsDeoptimizationInputData() const {
   // Must be a fixed array.
   if (!IsFixedArray()) return false;
@@ -5400,7 +5404,7 @@ ACCESSORS(SharedFunctionInfo, name, Object, kNameOffset)
 ACCESSORS(SharedFunctionInfo, optimized_code_map, Object,
                  kOptimizedCodeMapOffset)
 ACCESSORS(SharedFunctionInfo, construct_stub, Code, kConstructStubOffset)
-ACCESSORS(SharedFunctionInfo, feedback_vector, FixedArray,
+ACCESSORS(SharedFunctionInfo, feedback_vector, TypeFeedbackVector,
           kFeedbackVectorOffset)
 ACCESSORS(SharedFunctionInfo, instance_class_name, Object,
           kInstanceClassNameOffset)
index 5e4650259cab03bf50773df287721fc92a7bb102..aea26114c1169d30a42a4c1ee0ea24a2facf8304 100644 (file)
@@ -79,6 +79,7 @@
 //           - OrderedHashSet
 //           - OrderedHashMap
 //         - Context
+//         - TypeFeedbackVector
 //         - JSFunctionResultCache
 //         - ScopeInfo
 //         - TransitionArray
@@ -850,6 +851,7 @@ class GlobalObject;
 class ObjectVisitor;
 class LookupIterator;
 class StringStream;
+class TypeFeedbackVector;
 // We cannot just say "class HeapType;" if it is created from a template... =8-?
 template<class> class TypeImpl;
 struct HeapTypeConfig;
@@ -924,6 +926,7 @@ template <class C> inline bool Is(Object* obj);
   V(Map)                           \
   V(DescriptorArray)               \
   V(TransitionArray)               \
+  V(TypeFeedbackVector)            \
   V(DeoptimizationInputData)       \
   V(DeoptimizationOutputData)      \
   V(DependentCode)                 \
@@ -6975,9 +6978,8 @@ class SharedFunctionInfo: public HeapObject {
 
   // [feedback_vector] - accumulates ast node feedback from full-codegen and
   // (increasingly) from crankshafted code where sufficient feedback isn't
-  // available. Currently the field is duplicated in
-  // TypeFeedbackInfo::feedback_vector, but the allocation is done here.
-  DECL_ACCESSORS(feedback_vector, FixedArray)
+  // available.
+  DECL_ACCESSORS(feedback_vector, TypeFeedbackVector)
 
   // [instance class name]: class name for instances.
   DECL_ACCESSORS(instance_class_name, Object)
diff --git a/src/type-feedback-vector.cc b/src/type-feedback-vector.cc
new file mode 100644 (file)
index 0000000..61e9ded
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2014 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.
+
+#include "src/v8.h"
+
+#include "src/objects.h"
+#include "src/type-feedback-vector.h"
+
+namespace v8 {
+namespace internal {
+
+// static
+Handle<TypeFeedbackVector> TypeFeedbackVector::Copy(
+    Isolate* isolate, Handle<TypeFeedbackVector> vector) {
+  Handle<TypeFeedbackVector> result;
+  result = Handle<TypeFeedbackVector>::cast(
+      isolate->factory()->CopyFixedArray(Handle<FixedArray>::cast(vector)));
+  return result;
+}
+}
+}  // namespace v8::internal
diff --git a/src/type-feedback-vector.h b/src/type-feedback-vector.h
new file mode 100644 (file)
index 0000000..883a9c1
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright 2014 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.
+
+#ifndef V8_TYPE_FEEDBACK_VECTOR_H_
+#define V8_TYPE_FEEDBACK_VECTOR_H_
+
+#include "src/checks.h"
+#include "src/elements-kind.h"
+#include "src/heap/heap.h"
+#include "src/isolate.h"
+#include "src/objects.h"
+
+namespace v8 {
+namespace internal {
+
+class TypeFeedbackVector : public FixedArray {
+ public:
+  // Casting.
+  static TypeFeedbackVector* cast(Object* obj) {
+    DCHECK(obj->IsTypeFeedbackVector());
+    return reinterpret_cast<TypeFeedbackVector*>(obj);
+  }
+
+  static Handle<TypeFeedbackVector> Copy(Isolate* isolate,
+                                         Handle<TypeFeedbackVector> vector);
+
+ private:
+  DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackVector);
+};
+}
+}  // namespace v8::internal
+
+#endif  // V8_TRANSITIONS_H_
index f606ce20578dc67d4af3ffa7cde4fbcdf2266642..07c772e980d0c295668c65470b993967f7fbcfbd 100644 (file)
@@ -18,19 +18,17 @@ namespace v8 {
 namespace internal {
 
 
-TypeFeedbackOracle::TypeFeedbackOracle(Handle<Code> code,
-                                       Handle<FixedArray> feedback_vector,
-                                       Handle<Context> native_context,
-                                       Zone* zone)
-    : native_context_(native_context),
-      zone_(zone) {
+TypeFeedbackOracle::TypeFeedbackOracle(
+    Handle<Code> code, Handle<TypeFeedbackVector> feedback_vector,
+    Handle<Context> native_context, Zone* zone)
+    : native_context_(native_context), zone_(zone) {
   BuildDictionary(code);
   DCHECK(dictionary_->IsDictionary());
   // We make a copy of the feedback vector because a GC could clear
   // the type feedback info contained therein.
   // TODO(mvstanton): revisit the decision to copy when we weakly
   // traverse the feedback vector at GC time.
-  feedback_vector_ = isolate()->factory()->CopyFixedArray(feedback_vector);
+  feedback_vector_ = TypeFeedbackVector::Copy(isolate(), feedback_vector);
 }
 
 
index 44fecf634c4697803ccc3f418b8232e8d582221f..434ddd675983b6457aa325b0bb3d2f9e2ae41560 100644 (file)
@@ -20,9 +20,8 @@ class SmallMapList;
 class TypeFeedbackOracle: public ZoneObject {
  public:
   TypeFeedbackOracle(Handle<Code> code,
-                     Handle<FixedArray> feedback_vector,
-                     Handle<Context> native_context,
-                     Zone* zone);
+                     Handle<TypeFeedbackVector> feedback_vector,
+                     Handle<Context> native_context, Zone* zone);
 
   bool LoadIsUninitialized(TypeFeedbackId id);
   bool StoreIsUninitialized(TypeFeedbackId id);
@@ -120,7 +119,7 @@ class TypeFeedbackOracle: public ZoneObject {
   Handle<Context> native_context_;
   Zone* zone_;
   Handle<UnseededNumberDictionary> dictionary_;
-  Handle<FixedArray> feedback_vector_;
+  Handle<TypeFeedbackVector> feedback_vector_;
 
   DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
 };
index e7fdcd53fdc5dec528ac89f4c4e2a1830fe5160e..072991baa9a44cbd8088fe2240a800582f38eff2 100644 (file)
         '../../src/transitions-inl.h',
         '../../src/transitions.cc',
         '../../src/transitions.h',
+        '../../src/type-feedback-vector.cc',
+        '../../src/type-feedback-vector.h',
         '../../src/type-info.cc',
         '../../src/type-info.h',
         '../../src/types-inl.h',