Do not create LIFO arrays.
authorDavid Anderson <dvander@alliedmods.net>
Sat Sep 15 13:15:51 2012 -0700 (2012-09-15)
changeset 182c52ca323063f
parent 181 e731795f925c
child 183 05571208642f
Do not create LIFO arrays.
src/BytecodeCompiler.cpp
src/Opcodes.cpp
src/Opcodes.tbl
     1.1 --- a/src/BytecodeCompiler.cpp	Fri Sep 14 02:38:14 2012 -0700
     1.2 +++ b/src/BytecodeCompiler.cpp	Sat Sep 15 13:15:51 2012 -0700
     1.3 @@ -777,10 +777,8 @@
     1.4          __ note_position(node->pos());
     1.5          if (var->scope()->kind() == Scope::GLOBAL)
     1.6              __ newarray(map, Heap::Tenure_Old);
     1.7 -        else if (var->needsHeapAllocation())
     1.8 +        else
     1.9              __ newarray(map, Heap::Tenure_Default);
    1.10 -        else
    1.11 -            __ newarray(map, Heap::Tenure_Stack);
    1.12  
    1.13          if (node->initialization()) {
    1.14              node->initialization()->accept(this);
    1.15 @@ -827,9 +825,8 @@
    1.16      // Sniff out natives, which have a specific opcode and are guaranteed to
    1.17      // be called via name proxy.
    1.18      NamedFunction *native = NULL;
    1.19 -    if (funType->isNative()) {
    1.20 +    if (funType->isNative())
    1.21          native = node->callee()->toNameProxy()->binding()->toNamedFunction();
    1.22 -    }
    1.23  
    1.24      Local<Type> given(zone_);
    1.25      for (size_t i = node->arguments()->length() - 1; i < node->arguments()->length(); i--) {
    1.26 @@ -920,7 +917,13 @@
    1.27                  // change in the future, we do the same thing and dupe the
    1.28                  // newly allocated array.
    1.29                  map = ArrayMap::cast(array->map());
    1.30 -                __ newarray(map, Heap::Tenure_Stack);
    1.31 +                
    1.32 +                // Natives cannot escape array references, so we can allocate
    1.33 +                // them on the LIFO stack.
    1.34 +                if (funType->isNative())
    1.35 +                    __ newarray(map, Heap::Tenure_Stack);
    1.36 +                else
    1.37 +                    __ newarray(map, Heap::Tenure_Default);
    1.38                  __ dup();
    1.39                  __ object(array);
    1.40                  __ copyarray();
     2.1 --- a/src/Opcodes.cpp	Fri Sep 14 02:38:14 2012 -0700
     2.2 +++ b/src/Opcodes.cpp	Sat Sep 15 13:15:51 2012 -0700
     2.3 @@ -248,6 +248,8 @@
     2.4                  fprintf(fp, " ; lifo");
     2.5              else if (tenure == Heap::Tenure_Old)
     2.6                  fprintf(fp, " ; pretenured");
     2.7 +            else if (tenure == Heap::Tenure_Default)
     2.8 +                fprintf(fp, " ; newborn");
     2.9              break;
    2.10            }
    2.11  
    2.12 @@ -260,6 +262,8 @@
    2.13                  fprintf(fp, " ; lifo");
    2.14              else if (tenure == Heap::Tenure_Old)
    2.15                  fprintf(fp, " ; pretenured");
    2.16 +            else if (tenure == Heap::Tenure_Default)
    2.17 +                fprintf(fp, " ; newborn");
    2.18              break;
    2.19            }
    2.20  
     3.1 --- a/src/Opcodes.tbl	Fri Sep 14 02:38:14 2012 -0700
     3.2 +++ b/src/Opcodes.tbl	Sat Sep 15 13:15:51 2012 -0700
     3.3 @@ -107,7 +107,7 @@
     3.4  // ArrayMap to use is specified as an index into the script's Map table.
     3.5  //
     3.6  // Format:
     3.7 -//  [u8 op] [u32 index]
     3.8 +//  [u8 op] [u8 tenure] [u32 index]
     3.9  OPDEF(OP_NEWARRAY,      40,         "newarray",     6,      0,  1)
    3.10  
    3.11  // Performs an array-to-array assignment.
    3.12 @@ -243,7 +243,7 @@
    3.13  // StructMap to use is specified as an index into the script's Map table.
    3.14  //
    3.15  // Format:
    3.16 -//  [u8 op] [u32 index]
    3.17 +//  [u8 op] [u8 tenure] [u32 index]
    3.18  OPDEF(OP_NEWSTRUCT,     96,         "newstruct",    6,      0, 1)
    3.19  
    3.20  // Performs a struct-to-struct assignment.