Home | History | Annotate | Download | only in builtins
      1 // Copyright 2016 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "src/code-stub-assembler.h"
      6 
      7 namespace v8 {
      8 namespace internal {
      9 
     10 typedef compiler::Node Node;
     11 typedef compiler::CodeAssemblerState CodeAssemblerState;
     12 typedef compiler::CodeAssemblerLabel CodeAssemblerLabel;
     13 
     14 class ConstructorBuiltinsAssembler : public CodeStubAssembler {
     15  public:
     16   explicit ConstructorBuiltinsAssembler(CodeAssemblerState* state)
     17       : CodeStubAssembler(state) {}
     18 
     19   Node* EmitFastNewClosure(Node* shared_info, Node* feedback_vector, Node* slot,
     20                            Node* context);
     21   Node* EmitFastNewFunctionContext(Node* closure, Node* slots, Node* context,
     22                                    ScopeType scope_type);
     23   static int MaximumFunctionContextSlots();
     24 
     25   Node* EmitFastCloneRegExp(Node* closure, Node* literal_index, Node* pattern,
     26                             Node* flags, Node* context);
     27   Node* EmitFastCloneShallowArray(Node* closure, Node* literal_index,
     28                                   Node* context,
     29                                   CodeAssemblerLabel* call_runtime,
     30                                   AllocationSiteMode allocation_site_mode);
     31 
     32   // Maximum number of elements in copied array (chosen so that even an array
     33   // backed by a double backing store will fit into new-space).
     34   static const int kMaximumClonedShallowArrayElements =
     35       JSArray::kInitialMaxFastElementArray * kPointerSize / kDoubleSize;
     36 
     37   void CreateFastCloneShallowArrayBuiltin(
     38       AllocationSiteMode allocation_site_mode);
     39 
     40   // Maximum number of properties in copied objects.
     41   static const int kMaximumClonedShallowObjectProperties = 6;
     42   static int FastCloneShallowObjectPropertiesCount(int literal_length);
     43   Node* EmitFastCloneShallowObject(CodeAssemblerLabel* call_runtime,
     44                                    Node* closure, Node* literals_index,
     45                                    Node* properties_count);
     46   void CreateFastCloneShallowObjectBuiltin(int properties_count);
     47 
     48   Node* EmitFastNewObject(Node* context, Node* target, Node* new_target);
     49 
     50   Node* EmitFastNewObject(Node* context, Node* target, Node* new_target,
     51                           CodeAssemblerLabel* call_runtime);
     52 
     53  private:
     54   static const int kMaximumSlots = 0x8000;
     55   static const int kSmallMaximumSlots = 10;
     56 
     57   Node* NonEmptyShallowClone(Node* boilerplate, Node* boilerplate_map,
     58                              Node* boilerplate_elements, Node* allocation_site,
     59                              Node* capacity, ElementsKind kind);
     60 
     61   // FastNewFunctionContext can only allocate closures which fit in the
     62   // new space.
     63   STATIC_ASSERT(((kMaximumSlots + Context::MIN_CONTEXT_SLOTS) * kPointerSize +
     64                  FixedArray::kHeaderSize) < kMaxRegularHeapObjectSize);
     65 };
     66 
     67 }  // namespace internal
     68 }  // namespace v8
     69