mirror of https://github.com/lukechilds/node.git
Ryan
16 years ago
310 changed files with 13940 additions and 8075 deletions
File diff suppressed because it is too large
@ -0,0 +1,378 @@ |
|||
// Copyright 2009 the V8 project authors. All rights reserved.
|
|||
// Redistribution and use in source and binary forms, with or without
|
|||
// modification, are permitted provided that the following conditions are
|
|||
// met:
|
|||
//
|
|||
// * Redistributions of source code must retain the above copyright
|
|||
// notice, this list of conditions and the following disclaimer.
|
|||
// * Redistributions in binary form must reproduce the above
|
|||
// copyright notice, this list of conditions and the following
|
|||
// disclaimer in the documentation and/or other materials provided
|
|||
// with the distribution.
|
|||
// * Neither the name of Google Inc. nor the names of its
|
|||
// contributors may be used to endorse or promote products derived
|
|||
// from this software without specific prior written permission.
|
|||
//
|
|||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
|||
// This benchmark is based on a JavaScript log processing module used
|
|||
// by the V8 profiler to generate execution time profiles for runs of
|
|||
// JavaScript applications, and it effectively measures how fast the
|
|||
// JavaScript engine is at allocating nodes and reclaiming the memory
|
|||
// used for old nodes. Because of the way splay trees work, the engine
|
|||
// also has to deal with a lot of changes to the large tree object
|
|||
// graph.
|
|||
|
|||
var Splay = new BenchmarkSuite('Splay', 126125, [ |
|||
new Benchmark("Splay", SplayRun, SplaySetup, SplayTearDown) |
|||
]); |
|||
|
|||
|
|||
// Configuration.
|
|||
var kSplayTreeSize = 8000; |
|||
var kSplayTreeModifications = 80; |
|||
var kSplayTreePayloadDepth = 5; |
|||
|
|||
var splayTree = null; |
|||
|
|||
|
|||
function GeneratePayloadTree(depth, key) { |
|||
if (depth == 0) { |
|||
return { |
|||
array : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], |
|||
string : 'String for key ' + key + ' in leaf node' |
|||
}; |
|||
} else { |
|||
return { |
|||
left: GeneratePayloadTree(depth - 1, key), |
|||
right: GeneratePayloadTree(depth - 1, key) |
|||
}; |
|||
} |
|||
} |
|||
|
|||
|
|||
function GenerateKey() { |
|||
// The benchmark framework guarantees that Math.random is
|
|||
// deterministic; see base.js.
|
|||
return Math.random(); |
|||
} |
|||
|
|||
|
|||
function InsertNewNode() { |
|||
// Insert new node with a unique key.
|
|||
var key; |
|||
do { |
|||
key = GenerateKey(); |
|||
} while (splayTree.find(key) != null); |
|||
splayTree.insert(key, GeneratePayloadTree(kSplayTreePayloadDepth, key)); |
|||
return key; |
|||
} |
|||
|
|||
|
|||
|
|||
function SplaySetup() { |
|||
splayTree = new SplayTree(); |
|||
for (var i = 0; i < kSplayTreeSize; i++) InsertNewNode(); |
|||
} |
|||
|
|||
|
|||
function SplayTearDown() { |
|||
// Allow the garbage collector to reclaim the memory
|
|||
// used by the splay tree no matter how we exit the
|
|||
// tear down function.
|
|||
var keys = splayTree.exportKeys(); |
|||
splayTree = null; |
|||
|
|||
// Verify that the splay tree has the right size.
|
|||
var length = keys.length; |
|||
if (length != kSplayTreeSize) { |
|||
throw new Error("Splay tree has wrong size"); |
|||
} |
|||
|
|||
// Verify that the splay tree has sorted, unique keys.
|
|||
for (var i = 0; i < length - 1; i++) { |
|||
if (keys[i] >= keys[i + 1]) { |
|||
throw new Error("Splay tree not sorted"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
function SplayRun() { |
|||
// Replace a few nodes in the splay tree.
|
|||
for (var i = 0; i < kSplayTreeModifications; i++) { |
|||
var key = InsertNewNode(); |
|||
var greatest = splayTree.findGreatestLessThan(key); |
|||
if (greatest == null) splayTree.remove(key); |
|||
else splayTree.remove(greatest.key); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Constructs a Splay tree. A splay tree is a self-balancing binary |
|||
* search tree with the additional property that recently accessed |
|||
* elements are quick to access again. It performs basic operations |
|||
* such as insertion, look-up and removal in O(log(n)) amortized time. |
|||
* |
|||
* @constructor |
|||
*/ |
|||
function SplayTree() { |
|||
}; |
|||
|
|||
|
|||
/** |
|||
* Pointer to the root node of the tree. |
|||
* |
|||
* @type {SplayTree.Node} |
|||
* @private |
|||
*/ |
|||
SplayTree.prototype.root_ = null; |
|||
|
|||
|
|||
/** |
|||
* @return {boolean} Whether the tree is empty. |
|||
*/ |
|||
SplayTree.prototype.isEmpty = function() { |
|||
return !this.root_; |
|||
}; |
|||
|
|||
|
|||
/** |
|||
* Inserts a node into the tree with the specified key and value if |
|||
* the tree does not already contain a node with the specified key. If |
|||
* the value is inserted, it becomes the root of the tree. |
|||
* |
|||
* @param {number} key Key to insert into the tree. |
|||
* @param {*} value Value to insert into the tree. |
|||
*/ |
|||
SplayTree.prototype.insert = function(key, value) { |
|||
if (this.isEmpty()) { |
|||
this.root_ = new SplayTree.Node(key, value); |
|||
return; |
|||
} |
|||
// Splay on the key to move the last node on the search path for
|
|||
// the key to the root of the tree.
|
|||
this.splay_(key); |
|||
if (this.root_.key == key) { |
|||
return; |
|||
} |
|||
var node = new SplayTree.Node(key, value); |
|||
if (key > this.root_.key) { |
|||
node.left = this.root_; |
|||
node.right = this.root_.right; |
|||
this.root_.right = null; |
|||
} else { |
|||
node.right = this.root_; |
|||
node.left = this.root_.left; |
|||
this.root_.left = null; |
|||
} |
|||
this.root_ = node; |
|||
}; |
|||
|
|||
|
|||
/** |
|||
* Removes a node with the specified key from the tree if the tree |
|||
* contains a node with this key. The removed node is returned. If the |
|||
* key is not found, an exception is thrown. |
|||
* |
|||
* @param {number} key Key to find and remove from the tree. |
|||
* @return {SplayTree.Node} The removed node. |
|||
*/ |
|||
SplayTree.prototype.remove = function(key) { |
|||
if (this.isEmpty()) { |
|||
throw Error('Key not found: ' + key); |
|||
} |
|||
this.splay_(key); |
|||
if (this.root_.key != key) { |
|||
throw Error('Key not found: ' + key); |
|||
} |
|||
var removed = this.root_; |
|||
if (!this.root_.left) { |
|||
this.root_ = this.root_.right; |
|||
} else { |
|||
var right = this.root_.right; |
|||
this.root_ = this.root_.left; |
|||
// Splay to make sure that the new root has an empty right child.
|
|||
this.splay_(key); |
|||
// Insert the original right child as the right child of the new
|
|||
// root.
|
|||
this.root_.right = right; |
|||
} |
|||
return removed; |
|||
}; |
|||
|
|||
|
|||
/** |
|||
* Returns the node having the specified key or null if the tree doesn't contain |
|||
* a node with the specified key. |
|||
* |
|||
* @param {number} key Key to find in the tree. |
|||
* @return {SplayTree.Node} Node having the specified key. |
|||
*/ |
|||
SplayTree.prototype.find = function(key) { |
|||
if (this.isEmpty()) { |
|||
return null; |
|||
} |
|||
this.splay_(key); |
|||
return this.root_.key == key ? this.root_ : null; |
|||
}; |
|||
|
|||
|
|||
/** |
|||
* @return {SplayTree.Node} Node having the maximum key value that |
|||
* is less or equal to the specified key value. |
|||
*/ |
|||
SplayTree.prototype.findGreatestLessThan = function(key) { |
|||
if (this.isEmpty()) { |
|||
return null; |
|||
} |
|||
// Splay on the key to move the node with the given key or the last
|
|||
// node on the search path to the top of the tree.
|
|||
this.splay_(key); |
|||
// Now the result is either the root node or the greatest node in
|
|||
// the left subtree.
|
|||
if (this.root_.key <= key) { |
|||
return this.root_; |
|||
} else if (this.root_.left) { |
|||
return this.findMax(this.root_.left); |
|||
} else { |
|||
return null; |
|||
} |
|||
}; |
|||
|
|||
|
|||
/** |
|||
* @return {Array<*>} An array containing all the keys of tree's nodes. |
|||
*/ |
|||
SplayTree.prototype.exportKeys = function() { |
|||
var result = []; |
|||
if (!this.isEmpty()) { |
|||
this.root_.traverse_(function(node) { result.push(node.key); }); |
|||
} |
|||
return result; |
|||
}; |
|||
|
|||
|
|||
/** |
|||
* Perform the splay operation for the given key. Moves the node with |
|||
* the given key to the top of the tree. If no node has the given |
|||
* key, the last node on the search path is moved to the top of the |
|||
* tree. This is the simplified top-down splaying algorithm from: |
|||
* "Self-adjusting Binary Search Trees" by Sleator and Tarjan |
|||
* |
|||
* @param {number} key Key to splay the tree on. |
|||
* @private |
|||
*/ |
|||
SplayTree.prototype.splay_ = function(key) { |
|||
if (this.isEmpty()) { |
|||
return; |
|||
} |
|||
// Create a dummy node. The use of the dummy node is a bit
|
|||
// counter-intuitive: The right child of the dummy node will hold
|
|||
// the L tree of the algorithm. The left child of the dummy node
|
|||
// will hold the R tree of the algorithm. Using a dummy node, left
|
|||
// and right will always be nodes and we avoid special cases.
|
|||
var dummy, left, right; |
|||
dummy = left = right = new SplayTree.Node(null, null); |
|||
var current = this.root_; |
|||
while (true) { |
|||
if (key < current.key) { |
|||
if (!current.left) { |
|||
break; |
|||
} |
|||
if (key < current.left.key) { |
|||
// Rotate right.
|
|||
var tmp = current.left; |
|||
current.left = tmp.right; |
|||
tmp.right = current; |
|||
current = tmp; |
|||
if (!current.left) { |
|||
break; |
|||
} |
|||
} |
|||
// Link right.
|
|||
right.left = current; |
|||
right = current; |
|||
current = current.left; |
|||
} else if (key > current.key) { |
|||
if (!current.right) { |
|||
break; |
|||
} |
|||
if (key > current.right.key) { |
|||
// Rotate left.
|
|||
var tmp = current.right; |
|||
current.right = tmp.left; |
|||
tmp.left = current; |
|||
current = tmp; |
|||
if (!current.right) { |
|||
break; |
|||
} |
|||
} |
|||
// Link left.
|
|||
left.right = current; |
|||
left = current; |
|||
current = current.right; |
|||
} else { |
|||
break; |
|||
} |
|||
} |
|||
// Assemble.
|
|||
left.right = current.left; |
|||
right.left = current.right; |
|||
current.left = dummy.right; |
|||
current.right = dummy.left; |
|||
this.root_ = current; |
|||
}; |
|||
|
|||
|
|||
/** |
|||
* Constructs a Splay tree node. |
|||
* |
|||
* @param {number} key Key. |
|||
* @param {*} value Value. |
|||
*/ |
|||
SplayTree.Node = function(key, value) { |
|||
this.key = key; |
|||
this.value = value; |
|||
}; |
|||
|
|||
|
|||
/** |
|||
* @type {SplayTree.Node} |
|||
*/ |
|||
SplayTree.Node.prototype.left = null; |
|||
|
|||
|
|||
/** |
|||
* @type {SplayTree.Node} |
|||
*/ |
|||
SplayTree.Node.prototype.right = null; |
|||
|
|||
|
|||
/** |
|||
* Performs an ordered traversal of the subtree starting at |
|||
* this SplayTree.Node. |
|||
* |
|||
* @param {function(SplayTree.Node)} f Visitor function. |
|||
* @private |
|||
*/ |
|||
SplayTree.Node.prototype.traverse_ = function(f) { |
|||
var current = this; |
|||
while (current) { |
|||
var left = current.left; |
|||
if (left) left.traverse_(f); |
|||
f(current); |
|||
current = current.right; |
|||
} |
|||
}; |
@ -0,0 +1,46 @@ |
|||
// Copyright 2009 the V8 project authors. All rights reserved.
|
|||
// Redistribution and use in source and binary forms, with or without
|
|||
// modification, are permitted provided that the following conditions are
|
|||
// met:
|
|||
//
|
|||
// * Redistributions of source code must retain the above copyright
|
|||
// notice, this list of conditions and the following disclaimer.
|
|||
// * Redistributions in binary form must reproduce the above
|
|||
// copyright notice, this list of conditions and the following
|
|||
// disclaimer in the documentation and/or other materials provided
|
|||
// with the distribution.
|
|||
// * Neither the name of Google Inc. nor the names of its
|
|||
// contributors may be used to endorse or promote products derived
|
|||
// from this software without specific prior written permission.
|
|||
//
|
|||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
|||
|
|||
#ifndef V8_ARM_CODEGEN_ARM_INL_H_ |
|||
#define V8_ARM_CODEGEN_ARM_INL_H_ |
|||
|
|||
namespace v8 { |
|||
namespace internal { |
|||
|
|||
#define __ ACCESS_MASM(masm_) |
|||
|
|||
// Platform-specific inline functions.
|
|||
|
|||
void DeferredCode::Jump() { __ jmp(&entry_label_); } |
|||
void DeferredCode::Branch(Condition cc) { __ b(cc, &entry_label_); } |
|||
|
|||
#undef __ |
|||
|
|||
} } // namespace v8::internal
|
|||
|
|||
#endif // V8_ARM_CODEGEN_ARM_INL_H_
|
File diff suppressed because it is too large
@ -0,0 +1,103 @@ |
|||
// Copyright 2009 the V8 project authors. All rights reserved.
|
|||
// Redistribution and use in source and binary forms, with or without
|
|||
// modification, are permitted provided that the following conditions are
|
|||
// met:
|
|||
//
|
|||
// * Redistributions of source code must retain the above copyright
|
|||
// notice, this list of conditions and the following disclaimer.
|
|||
// * Redistributions in binary form must reproduce the above
|
|||
// copyright notice, this list of conditions and the following
|
|||
// disclaimer in the documentation and/or other materials provided
|
|||
// with the distribution.
|
|||
// * Neither the name of Google Inc. nor the names of its
|
|||
// contributors may be used to endorse or promote products derived
|
|||
// from this software without specific prior written permission.
|
|||
//
|
|||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
|||
#ifndef V8_ARM_REGISTER_ALLOCATOR_ARM_INL_H_ |
|||
#define V8_ARM_REGISTER_ALLOCATOR_ARM_INL_H_ |
|||
|
|||
#include "v8.h" |
|||
|
|||
namespace v8 { |
|||
namespace internal { |
|||
|
|||
// -------------------------------------------------------------------------
|
|||
// RegisterAllocator implementation.
|
|||
|
|||
bool RegisterAllocator::IsReserved(Register reg) { |
|||
return reg.is(cp) || reg.is(fp) || reg.is(sp) || reg.is(pc); |
|||
} |
|||
|
|||
|
|||
|
|||
// The register allocator uses small integers to represent the
|
|||
// non-reserved assembler registers. The mapping is:
|
|||
//
|
|||
// r0 <-> 0
|
|||
// r1 <-> 1
|
|||
// r2 <-> 2
|
|||
// r3 <-> 3
|
|||
// r4 <-> 4
|
|||
// r5 <-> 5
|
|||
// r6 <-> 6
|
|||
// r7 <-> 7
|
|||
// r9 <-> 8
|
|||
// r10 <-> 9
|
|||
// ip <-> 10
|
|||
// lr <-> 11
|
|||
|
|||
int RegisterAllocator::ToNumber(Register reg) { |
|||
ASSERT(reg.is_valid() && !IsReserved(reg)); |
|||
static int numbers[] = { |
|||
0, // r0
|
|||
1, // r1
|
|||
2, // r2
|
|||
3, // r3
|
|||
4, // r4
|
|||
5, // r5
|
|||
6, // r6
|
|||
7, // r7
|
|||
-1, // cp
|
|||
8, // r9
|
|||
9, // r10
|
|||
-1, // fp
|
|||
10, // ip
|
|||
-1, // sp
|
|||
11, // lr
|
|||
-1 // pc
|
|||
}; |
|||
return numbers[reg.code()]; |
|||
} |
|||
|
|||
|
|||
Register RegisterAllocator::ToRegister(int num) { |
|||
ASSERT(num >= 0 && num < kNumRegisters); |
|||
static Register registers[] = |
|||
{ r0, r1, r2, r3, r4, r5, r6, r7, r9, r10, ip, lr }; |
|||
return registers[num]; |
|||
} |
|||
|
|||
|
|||
void RegisterAllocator::Initialize() { |
|||
Reset(); |
|||
// The non-reserved r1 and lr registers are live on JS function entry.
|
|||
Use(r1); // JS function.
|
|||
Use(lr); // Return address.
|
|||
} |
|||
|
|||
|
|||
} } // namespace v8::internal
|
|||
|
|||
#endif // V8_ARM_REGISTER_ALLOCATOR_ARM_INL_H_
|
@ -0,0 +1,43 @@ |
|||
// Copyright 2009 the V8 project authors. All rights reserved.
|
|||
// Redistribution and use in source and binary forms, with or without
|
|||
// modification, are permitted provided that the following conditions are
|
|||
// met:
|
|||
//
|
|||
// * Redistributions of source code must retain the above copyright
|
|||
// notice, this list of conditions and the following disclaimer.
|
|||
// * Redistributions in binary form must reproduce the above
|
|||
// copyright notice, this list of conditions and the following
|
|||
// disclaimer in the documentation and/or other materials provided
|
|||
// with the distribution.
|
|||
// * Neither the name of Google Inc. nor the names of its
|
|||
// contributors may be used to endorse or promote products derived
|
|||
// from this software without specific prior written permission.
|
|||
//
|
|||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
|||
#ifndef V8_ARM_REGISTER_ALLOCATOR_ARM_H_ |
|||
#define V8_ARM_REGISTER_ALLOCATOR_ARM_H_ |
|||
|
|||
namespace v8 { |
|||
namespace internal { |
|||
|
|||
class RegisterAllocatorConstants : public AllStatic { |
|||
public: |
|||
static const int kNumRegisters = 12; |
|||
static const int kInvalidRegister = -1; |
|||
}; |
|||
|
|||
|
|||
} } // namespace v8::internal
|
|||
|
|||
#endif // V8_ARM_REGISTER_ALLOCATOR_ARM_H_
|
@ -0,0 +1,265 @@ |
|||
// Copyright 2009 the V8 project authors. All rights reserved.
|
|||
// Redistribution and use in source and binary forms, with or without
|
|||
// modification, are permitted provided that the following conditions are
|
|||
// met:
|
|||
//
|
|||
// * Redistributions of source code must retain the above copyright
|
|||
// notice, this list of conditions and the following disclaimer.
|
|||
// * Redistributions in binary form must reproduce the above
|
|||
// copyright notice, this list of conditions and the following
|
|||
// disclaimer in the documentation and/or other materials provided
|
|||
// with the distribution.
|
|||
// * Neither the name of Google Inc. nor the names of its
|
|||
// contributors may be used to endorse or promote products derived
|
|||
// from this software without specific prior written permission.
|
|||
//
|
|||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
|||
#ifndef V8_FRAME_ELEMENT_H_ |
|||
#define V8_FRAME_ELEMENT_H_ |
|||
|
|||
#include "register-allocator-inl.h" |
|||
|
|||
namespace v8 { |
|||
namespace internal { |
|||
|
|||
// -------------------------------------------------------------------------
|
|||
// Virtual frame elements
|
|||
//
|
|||
// The internal elements of the virtual frames. There are several kinds of
|
|||
// elements:
|
|||
// * Invalid: elements that are uninitialized or not actually part
|
|||
// of the virtual frame. They should not be read.
|
|||
// * Memory: an element that resides in the actual frame. Its address is
|
|||
// given by its position in the virtual frame.
|
|||
// * Register: an element that resides in a register.
|
|||
// * Constant: an element whose value is known at compile time.
|
|||
|
|||
class FrameElement BASE_EMBEDDED { |
|||
public: |
|||
enum SyncFlag { |
|||
NOT_SYNCED, |
|||
SYNCED |
|||
}; |
|||
|
|||
// The default constructor creates an invalid frame element.
|
|||
FrameElement() { |
|||
value_ = StaticTypeField::encode(StaticType::UNKNOWN_TYPE) |
|||
| TypeField::encode(INVALID) |
|||
| CopiedField::encode(false) |
|||
| SyncedField::encode(false) |
|||
| DataField::encode(0); |
|||
} |
|||
|
|||
// Factory function to construct an invalid frame element.
|
|||
static FrameElement InvalidElement() { |
|||
FrameElement result; |
|||
return result; |
|||
} |
|||
|
|||
// Factory function to construct an in-memory frame element.
|
|||
static FrameElement MemoryElement() { |
|||
FrameElement result(MEMORY, no_reg, SYNCED); |
|||
return result; |
|||
} |
|||
|
|||
// Factory function to construct an in-register frame element.
|
|||
static FrameElement RegisterElement(Register reg, |
|||
SyncFlag is_synced, |
|||
StaticType static_type = StaticType()) { |
|||
return FrameElement(REGISTER, reg, is_synced, static_type); |
|||
} |
|||
|
|||
// Factory function to construct a frame element whose value is known at
|
|||
// compile time.
|
|||
static FrameElement ConstantElement(Handle<Object> value, |
|||
SyncFlag is_synced) { |
|||
FrameElement result(value, is_synced); |
|||
return result; |
|||
} |
|||
|
|||
// Static indirection table for handles to constants. If a frame
|
|||
// element represents a constant, the data contains an index into
|
|||
// this table of handles to the actual constants.
|
|||
typedef ZoneList<Handle<Object> > ZoneObjectList; |
|||
|
|||
static ZoneObjectList* ConstantList() { |
|||
static ZoneObjectList list(10); |
|||
return &list; |
|||
} |
|||
|
|||
// Clear the constants indirection table.
|
|||
static void ClearConstantList() { |
|||
ConstantList()->Clear(); |
|||
} |
|||
|
|||
bool is_synced() const { return SyncedField::decode(value_); } |
|||
|
|||
void set_sync() { |
|||
ASSERT(type() != MEMORY); |
|||
value_ = value_ | SyncedField::encode(true); |
|||
} |
|||
|
|||
void clear_sync() { |
|||
ASSERT(type() != MEMORY); |
|||
value_ = value_ & ~SyncedField::mask(); |
|||
} |
|||
|
|||
bool is_valid() const { return type() != INVALID; } |
|||
bool is_memory() const { return type() == MEMORY; } |
|||
bool is_register() const { return type() == REGISTER; } |
|||
bool is_constant() const { return type() == CONSTANT; } |
|||
bool is_copy() const { return type() == COPY; } |
|||
|
|||
bool is_copied() const { return CopiedField::decode(value_); } |
|||
void set_copied() { value_ = value_ | CopiedField::encode(true); } |
|||
void clear_copied() { value_ = value_ & ~CopiedField::mask(); } |
|||
|
|||
Register reg() const { |
|||
ASSERT(is_register()); |
|||
uint32_t reg = DataField::decode(value_); |
|||
Register result; |
|||
result.code_ = reg; |
|||
return result; |
|||
} |
|||
|
|||
Handle<Object> handle() const { |
|||
ASSERT(is_constant()); |
|||
return ConstantList()->at(DataField::decode(value_)); |
|||
} |
|||
|
|||
int index() const { |
|||
ASSERT(is_copy()); |
|||
return DataField::decode(value_); |
|||
} |
|||
|
|||
StaticType static_type() { |
|||
return StaticType(StaticTypeField::decode(value_)); |
|||
} |
|||
|
|||
void set_static_type(StaticType static_type) { |
|||
value_ = value_ & ~StaticTypeField::mask(); |
|||
value_ = value_ | StaticTypeField::encode(static_type.static_type_); |
|||
} |
|||
|
|||
bool Equals(FrameElement other) { |
|||
uint32_t masked_difference = (value_ ^ other.value_) & ~CopiedField::mask(); |
|||
if (!masked_difference) { |
|||
// The elements are equal if they agree exactly except on copied field.
|
|||
return true; |
|||
} else { |
|||
// If two constants have the same value, and agree otherwise, return true.
|
|||
return !(masked_difference & ~DataField::mask()) && |
|||
is_constant() && |
|||
handle().is_identical_to(other.handle()); |
|||
} |
|||
} |
|||
|
|||
// Test if two FrameElements refer to the same memory or register location.
|
|||
bool SameLocation(FrameElement* other) { |
|||
if (type() == other->type()) { |
|||
if (value_ == other->value_) return true; |
|||
if (is_constant() && handle().is_identical_to(other->handle())) { |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
// Given a pair of non-null frame element pointers, return one of them
|
|||
// as an entry frame candidate or null if they are incompatible.
|
|||
FrameElement* Combine(FrameElement* other) { |
|||
// If either is invalid, the result is.
|
|||
if (!is_valid()) return this; |
|||
if (!other->is_valid()) return other; |
|||
|
|||
if (!SameLocation(other)) return NULL; |
|||
// If either is unsynced, the result is. The result static type is
|
|||
// the merge of the static types. It's safe to set it on one of the
|
|||
// frame elements, and harmless too (because we are only going to
|
|||
// merge the reaching frames and will ensure that the types are
|
|||
// coherent, and changing the static type does not emit code).
|
|||
FrameElement* result = is_synced() ? other : this; |
|||
result->set_static_type(static_type().merge(other->static_type())); |
|||
return result; |
|||
} |
|||
|
|||
private: |
|||
enum Type { |
|||
INVALID, |
|||
MEMORY, |
|||
REGISTER, |
|||
CONSTANT, |
|||
COPY |
|||
}; |
|||
|
|||
// Used to construct memory and register elements.
|
|||
FrameElement(Type type, Register reg, SyncFlag is_synced) { |
|||
value_ = StaticTypeField::encode(StaticType::UNKNOWN_TYPE) |
|||
| TypeField::encode(type) |
|||
| CopiedField::encode(false) |
|||
| SyncedField::encode(is_synced != NOT_SYNCED) |
|||
| DataField::encode(reg.code_ > 0 ? reg.code_ : 0); |
|||
} |
|||
|
|||
FrameElement(Type type, Register reg, SyncFlag is_synced, StaticType stype) { |
|||
value_ = StaticTypeField::encode(stype.static_type_) |
|||
| TypeField::encode(type) |
|||
| CopiedField::encode(false) |
|||
| SyncedField::encode(is_synced != NOT_SYNCED) |
|||
| DataField::encode(reg.code_ > 0 ? reg.code_ : 0); |
|||
} |
|||
|
|||
// Used to construct constant elements.
|
|||
FrameElement(Handle<Object> value, SyncFlag is_synced) { |
|||
value_ = StaticTypeField::encode(StaticType::TypeOf(*value).static_type_) |
|||
| TypeField::encode(CONSTANT) |
|||
| CopiedField::encode(false) |
|||
| SyncedField::encode(is_synced != NOT_SYNCED) |
|||
| DataField::encode(ConstantList()->length()); |
|||
ConstantList()->Add(value); |
|||
} |
|||
|
|||
Type type() const { return TypeField::decode(value_); } |
|||
void set_type(Type type) { |
|||
value_ = value_ & ~TypeField::mask(); |
|||
value_ = value_ | TypeField::encode(type); |
|||
} |
|||
|
|||
void set_index(int new_index) { |
|||
ASSERT(is_copy()); |
|||
value_ = value_ & ~DataField::mask(); |
|||
value_ = value_ | DataField::encode(new_index); |
|||
} |
|||
|
|||
void set_reg(Register new_reg) { |
|||
ASSERT(is_register()); |
|||
value_ = value_ & ~DataField::mask(); |
|||
value_ = value_ | DataField::encode(new_reg.code_); |
|||
} |
|||
|
|||
// Encode static type, type, copied, synced and data in one 32 bit integer.
|
|||
uint32_t value_; |
|||
|
|||
class StaticTypeField: public BitField<StaticType::StaticTypeEnum, 0, 3> {}; |
|||
class TypeField: public BitField<Type, 3, 3> {}; |
|||
class CopiedField: public BitField<uint32_t, 6, 1> {}; |
|||
class SyncedField: public BitField<uint32_t, 7, 1> {}; |
|||
class DataField: public BitField<uint32_t, 8, 32 - 9> {}; |
|||
|
|||
friend class VirtualFrame; |
|||
}; |
|||
|
|||
} } // namespace v8::internal
|
|||
|
|||
#endif // V8_FRAME_ELEMENT_H_
|
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue