Changeset 34851 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jun 28, 2008, 8:50:49 AM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r34850 r34851 1 1 2008-06-28 Darin Adler <[email protected]> 2 2 3 Reviewed by Oliver Hunt. 3 Reviewed by Oliver. 4 5 - https://bugs.webkit.org/show_bug.cgi?id=19787 6 create most arrays from values in registers rather than with multiple put operations 7 8 SunSpider says 0.8% faster. 9 10 * VM/CodeBlock.cpp: 11 (KJS::CodeBlock::dump): Added argv and argc parameters to new_array. 12 * VM/Machine.cpp: 13 (KJS::Machine::privateExecute): Ditto. 14 15 * VM/CodeGenerator.cpp: 16 (KJS::CodeGenerator::emitNewArray): Added. 17 * VM/CodeGenerator.h: Added ElementNode* argument to emitNewArray. 18 19 * kjs/nodes.cpp: 20 (KJS::ArrayNode::emitCode): Pass the ElementNode to emitNewArray so it can be 21 initialized with as many elements as possible. If the array doesn't have any 22 holes in it, that's all that's needed. If there are holes, then emit some separate 23 put operations for the other values in the array and for the length as needed. 24 25 * kjs/nodes.h: Added some accessors to ElementNode so the code generator can 26 iterate through elements and generate code to evaluate them. Now ArrayNode does 27 not need to be a friend. Also took out some unused PlacementNewAdoptType 28 constructors. 29 30 2008-06-28 Darin Adler <[email protected]> 31 32 Reviewed by Oliver. 4 33 5 34 * kjs/nodes.h: Remove obsolete PlacementNewAdopt constructors. -
trunk/JavaScriptCore/VM/CodeBlock.cpp
r34842 r34851 31 31 #include "CodeBlock.h" 32 32 33 #include "JSValue.h" 33 34 #include "Machine.h" 34 35 #include "debugger.h" 35 #include "JSValue.h"36 36 #include <stdio.h> 37 37 … … 218 218 } 219 219 case op_new_array: { 220 int r0 = (++it)->u.operand; 221 printf("[%4d] new_array\t %s\n", location, registerName(r0).c_str()); 220 int dst = (++it)->u.operand; 221 int argv = (++it)->u.operand; 222 int argc = (++it)->u.operand; 223 printf("[%4d] new_array\t %s, %s, %d\n", location, registerName(dst).c_str(), registerName(argv).c_str(), argc); 222 224 break; 223 225 } -
trunk/JavaScriptCore/VM/CodeGenerator.cpp
r34842 r34851 31 31 #include "CodeGenerator.h" 32 32 33 #include "JSFunction.h" 33 34 #include "Machine.h" 34 #include "JSFunction.h"35 35 36 36 using namespace std; … … 792 792 } 793 793 794 RegisterID* CodeGenerator::emitNewFunction(RegisterID* r0, FuncDeclNode* n) 794 RegisterID* CodeGenerator::emitNewArray(RegisterID* dst, ElementNode* elements) 795 { 796 Vector<RefPtr<RegisterID>, 16> argv; 797 for (ElementNode* n = elements; n; n = n->next()) { 798 if (n->elision()) 799 break; 800 argv.append(newTemporary()); 801 emitNode(argv.last().get(), n->value()); 802 } 803 emitOpcode(op_new_array); 804 instructions().append(dst->index()); 805 instructions().append(argv.size() ? argv[0]->index() : 0); // argv 806 instructions().append(argv.size()); // argc 807 return dst; 808 } 809 810 RegisterID* CodeGenerator::emitNewFunction(RegisterID* dst, FuncDeclNode* n) 795 811 { 796 812 emitOpcode(op_new_func); 797 instructions().append( r0->index());813 instructions().append(dst->index()); 798 814 instructions().append(addConstant(n)); 799 return r0;815 return dst; 800 816 } 801 817 -
trunk/JavaScriptCore/VM/CodeGenerator.h
r34838 r34851 200 200 201 201 RegisterID* emitNewObject(RegisterID* dst) { return emitNullaryOp(op_new_object, dst); } 202 RegisterID* emitNewArray(RegisterID* dst ) { return emitNullaryOp(op_new_array, dst); }202 RegisterID* emitNewArray(RegisterID* dst, ElementNode*); // stops at first elision 203 203 204 204 RegisterID* emitNewFunction(RegisterID* dst, FuncDeclNode* func); -
trunk/JavaScriptCore/VM/Machine.cpp
r34849 r34851 36 36 #include "ExecState.h" 37 37 #include "JSActivation.h" 38 #include "JSArray.h" 39 #include "JSFunction.h" 38 40 #include "JSLock.h" 39 41 #include "JSPropertyNameIterator.h" 42 #include "JSString.h" 40 43 #include "Parser.h" 41 44 #include "Profiler.h" 45 #include "RegExpObject.h" 42 46 #include "Register.h" 43 #include "JSArray.h"44 47 #include "debugger.h" 45 #include "JSFunction.h"46 #include "JSString.h"47 48 #include "object_object.h" 48 49 #include "operations.h" 49 #include "RegExpObject.h"50 51 50 #include <stdio.h> 52 51 … … 1037 1036 } 1038 1037 BEGIN_OPCODE(op_new_array) { 1039 /* new_array dst(r) 1040 1041 Constructs a new emptyArray instance using the original1038 /* new_array dst(r) firstArg(r) argCount(n) 1039 1040 Constructs a new Array instance using the original 1042 1041 constructor, and puts the result in register dst. 1043 */ 1044 int dst = (++vPC)->u.operand; 1045 r[dst].u.jsValue = constructEmptyArray(exec); 1042 The array will contain argCount elements with values 1043 taken from registers starting at register firstArg. 1044 */ 1045 int dst = (++vPC)->u.operand; 1046 int firstArg = (++vPC)->u.operand; 1047 int argCount = (++vPC)->u.operand; 1048 ArgList args(reinterpret_cast<JSValue***>(®isterBase), r - registerBase + firstArg, argCount); 1049 r[dst].u.jsValue = constructArray(exec, args); 1046 1050 1047 1051 ++vPC; -
trunk/JavaScriptCore/kjs/nodes.cpp
r34843 r34851 48 48 namespace KJS { 49 49 50 static inline UString::Rep* rep(const Identifier& ident)51 {52 return ident.ustring().rep();53 }54 55 50 // ------------------------------ Node ----------------------------------------- 56 51 57 52 #ifndef NDEBUG 53 58 54 #ifndef LOG_CHANNEL_PREFIX 59 55 #define LOG_CHANNEL_PREFIX Log 60 56 #endif 57 61 58 static WTFLogChannel LogKJSNodeLeaks = { 0x00000000, "", WTFLogChannelOn }; 62 59 … … 100 97 --count; 101 98 } 99 102 100 #endif 103 101 … … 215 213 } 216 214 217 static inline int currentSourceId(ExecState* exec) KJS_FAST_CALL;218 static inline int currentSourceId(ExecState*)219 {220 ASSERT_NOT_REACHED();221 return 0;222 }223 224 static inline const UString currentSourceURL(ExecState* exec) KJS_FAST_CALL;225 static inline const UString currentSourceURL(ExecState*)226 {227 ASSERT_NOT_REACHED();228 return UString();229 }230 231 215 RegisterID* Node::emitThrowError(CodeGenerator& generator, ErrorType e, const char* msg) 232 216 { … … 346 330 // ------------------------------ ArrayNode ------------------------------------ 347 331 348 349 332 RegisterID* ArrayNode::emitCode(CodeGenerator& generator, RegisterID* dst) 350 333 { 351 RefPtr<RegisterID> newArray = generator.emitNewArray(generator.tempDestination(dst)); 334 // FIXME: Should we put all of this code into emitNewArray? 335 352 336 unsigned length = 0; 353 354 RegisterID* value; 355 for (ElementNode* n = m_element.get(); n; n = n->m_next.get()) { 356 value = generator.emitNode(n->m_node.get()); 357 length += n->m_elision; 358 generator.emitPutByIndex(newArray.get(), length++, value); 359 } 360 361 value = generator.emitLoad(generator.newTemporary(), jsNumber(generator.globalExec(), m_elision + length)); 362 generator.emitPutById(newArray.get(), generator.propertyNames().length, value); 363 364 return generator.moveToDestinationIfNeeded(dst, newArray.get()); 337 ElementNode* firstPutElement; 338 for (firstPutElement = m_element.get(); firstPutElement; firstPutElement = firstPutElement->next()) { 339 if (firstPutElement->elision()) 340 break; 341 ++length; 342 } 343 344 if (!firstPutElement && !m_elision) 345 return generator.emitNewArray(generator.finalDestination(dst), m_element.get()); 346 347 RefPtr<RegisterID> array = generator.emitNewArray(generator.tempDestination(dst), m_element.get()); 348 349 for (ElementNode* n = firstPutElement; n; n = n->next()) { 350 RegisterID* value = generator.emitNode(n->value()); 351 length += n->elision(); 352 generator.emitPutByIndex(array.get(), length++, value); 353 } 354 355 if (m_elision) { 356 RegisterID* value = generator.emitLoad(generator.newTemporary(), jsNumber(generator.globalExec(), m_elision + length)); 357 generator.emitPutById(array.get(), generator.propertyNames().length, value); 358 } 359 360 return generator.moveToDestinationIfNeeded(dst, array.get()); 365 361 } 366 362 … … 371 367 if (m_list) 372 368 return generator.emitNode(dst, m_list.get()); 373 else 374 return generator.emitNewObject(generator.finalDestination(dst)); 369 return generator.emitNewObject(generator.finalDestination(dst)); 375 370 } 376 371 -
trunk/JavaScriptCore/kjs/nodes.h
r34850 r34851 30 30 #include "LabelStack.h" 31 31 #include "Opcode.h" 32 #include "regexp.h"33 32 #include "RegisterID.h" 34 33 #include "SourceRange.h" 35 34 #include "SymbolTable.h" 36 #include <wtf/UnusedParam.h>35 #include "regexp.h" 37 36 #include <wtf/ListRefPtr.h> 38 37 #include <wtf/MathExtras.h> 39 38 #include <wtf/OwnPtr.h> 39 #include <wtf/UnusedParam.h> 40 40 #include <wtf/Vector.h> 41 41 … … 48 48 namespace KJS { 49 49 50 class ArgumentsNode;51 50 class CodeBlock; 52 51 class CodeGenerator; 53 class ConstDeclNode;54 52 class FuncDeclNode; 55 53 class Node; … … 390 388 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 391 389 390 int elision() const { return m_elision; } 391 ExpressionNode* value() { return m_node.get(); } 392 393 ElementNode* next() { return m_next.get(); } 392 394 PassRefPtr<ElementNode> releaseNext() KJS_FAST_CALL { return m_next.release(); } 393 395 394 396 private: 395 friend class ArrayNode;396 397 ListRefPtr<ElementNode> m_next; 397 398 int m_elision;
Note:
See TracChangeset
for help on using the changeset viewer.