diff --git a/src/ia32/builtins-ia32.cc b/src/ia32/builtins-ia32.cc index e679d855c8..fff61de124 100644 --- a/src/ia32/builtins-ia32.cc +++ b/src/ia32/builtins-ia32.cc @@ -133,14 +133,7 @@ void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { // problem here, because it is always greater than the maximum // instance size that can be represented in a byte. ASSERT(Heap::MaxObjectSizeInPagedSpace() >= JSObject::kMaxInstanceSize); - ExternalReference new_space_allocation_top = - ExternalReference::new_space_allocation_top_address(); - __ mov(ebx, Operand::StaticVariable(new_space_allocation_top)); - __ add(edi, Operand(ebx)); // Calculate new top - ExternalReference new_space_allocation_limit = - ExternalReference::new_space_allocation_limit_address(); - __ cmp(edi, Operand::StaticVariable(new_space_allocation_limit)); - __ j(above_equal, &rt_call); + __ AllocateObjectInNewSpace(edi, ebx, edi, no_reg, &rt_call, false); // Allocated the JSObject, now initialize the fields. // eax: initial map // ebx: JSObject @@ -173,7 +166,6 @@ void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { // ebx: JSObject // edi: start of next object __ or_(Operand(ebx), Immediate(kHeapObjectTag)); - __ mov(Operand::StaticVariable(new_space_allocation_top), edi); // Check if a non-empty properties array is needed. // Allocate and initialize a FixedArray if it is. @@ -198,10 +190,14 @@ void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { // edx: number of elements in properties array ASSERT(Heap::MaxObjectSizeInPagedSpace() > (FixedArray::kHeaderSize + 255*kPointerSize)); - __ lea(ecx, Operand(edi, edx, times_pointer_size, FixedArray::kHeaderSize)); - __ cmp(ecx, Operand::StaticVariable(new_space_allocation_limit)); - __ j(above_equal, &undo_allocation); - __ mov(Operand::StaticVariable(new_space_allocation_top), ecx); + __ AllocateObjectInNewSpace(FixedArray::kHeaderSize, + times_pointer_size, + edx, + edi, + ecx, + no_reg, + &undo_allocation, + true); // Initialize the FixedArray. // ebx: JSObject @@ -245,8 +241,7 @@ void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { // allocated objects unused properties. // ebx: JSObject (previous new top) __ bind(&undo_allocation); - __ xor_(Operand(ebx), Immediate(kHeapObjectTag)); // clear the heap tag - __ mov(Operand::StaticVariable(new_space_allocation_top), ebx); + __ UndoAllocationInNewSpace(ebx); } // Allocate the new receiver object using the runtime call. diff --git a/src/ia32/codegen-ia32-inl.h b/src/ia32/codegen-ia32-inl.h index 44e937af16..43e98cbfb0 100644 --- a/src/ia32/codegen-ia32-inl.h +++ b/src/ia32/codegen-ia32-inl.h @@ -1,56 +1,56 @@ -// 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_IA32_CODEGEN_IA32_INL_H_ -#define V8_IA32_CODEGEN_IA32_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) { __ j(cc, &entry_label_); } - -void CodeGenerator::GenerateMathSin(ZoneList* args) { - GenerateFastMathOp(SIN, args); -} - - -void CodeGenerator::GenerateMathCos(ZoneList* args) { - GenerateFastMathOp(COS, args); -} - - -#undef __ - -} } // namespace v8::internal - -#endif // V8_IA32_CODEGEN_IA32_INL_H_ +// 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_IA32_CODEGEN_IA32_INL_H_ +#define V8_IA32_CODEGEN_IA32_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) { __ j(cc, &entry_label_); } + +void CodeGenerator::GenerateMathSin(ZoneList* args) { + GenerateFastMathOp(SIN, args); +} + + +void CodeGenerator::GenerateMathCos(ZoneList* args) { + GenerateFastMathOp(COS, args); +} + + +#undef __ + +} } // namespace v8::internal + +#endif // V8_IA32_CODEGEN_IA32_INL_H_ diff --git a/src/ia32/codegen-ia32.cc b/src/ia32/codegen-ia32.cc index bf1f81b137..e0efd54d2b 100644 --- a/src/ia32/codegen-ia32.cc +++ b/src/ia32/codegen-ia32.cc @@ -6947,21 +6947,18 @@ void FloatingPointHelper::AllocateHeapNumber(MacroAssembler* masm, Register scratch1, Register scratch2, Register result) { - ExternalReference allocation_top = - ExternalReference::new_space_allocation_top_address(); - ExternalReference allocation_limit = - ExternalReference::new_space_allocation_limit_address(); - __ mov(Operand(scratch1), Immediate(allocation_top)); - __ mov(result, Operand(scratch1, 0)); - __ lea(scratch2, Operand(result, HeapNumber::kSize)); // scratch2: new top - __ cmp(scratch2, Operand::StaticVariable(allocation_limit)); - __ j(above, need_gc, not_taken); - - __ mov(Operand(scratch1, 0), scratch2); // store new top + // Allocate heap number in new space. + __ AllocateObjectInNewSpace(HeapNumber::kSize, + result, + scratch1, + scratch2, + need_gc, + false); + + // Set the map and tag the result. __ mov(Operand(result, HeapObject::kMapOffset), Immediate(Factory::heap_number_map())); - // Tag old top and use as result. - __ add(Operand(result), Immediate(kHeapObjectTag)); + __ or_(Operand(result), Immediate(kHeapObjectTag)); } diff --git a/src/ia32/codegen-ia32.h b/src/ia32/codegen-ia32.h index afdbffe58e..b3afc580e0 100644 --- a/src/ia32/codegen-ia32.h +++ b/src/ia32/codegen-ia32.h @@ -1,664 +1,664 @@ -// Copyright 2006-2008 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_IA32_CODEGEN_IA32_H_ -#define V8_IA32_CODEGEN_IA32_H_ - -namespace v8 { -namespace internal { - -// Forward declarations -class DeferredCode; -class RegisterAllocator; -class RegisterFile; - -enum InitState { CONST_INIT, NOT_CONST_INIT }; -enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF }; - - -// ------------------------------------------------------------------------- -// Reference support - -// A reference is a C++ stack-allocated object that keeps an ECMA -// reference on the execution stack while in scope. For variables -// the reference is empty, indicating that it isn't necessary to -// store state on the stack for keeping track of references to those. -// For properties, we keep either one (named) or two (indexed) values -// on the execution stack to represent the reference. - -class Reference BASE_EMBEDDED { - public: - // The values of the types is important, see size(). - enum Type { ILLEGAL = -1, SLOT = 0, NAMED = 1, KEYED = 2 }; - Reference(CodeGenerator* cgen, Expression* expression); - ~Reference(); - - Expression* expression() const { return expression_; } - Type type() const { return type_; } - void set_type(Type value) { - ASSERT(type_ == ILLEGAL); - type_ = value; - } - - // The size the reference takes up on the stack. - int size() const { return (type_ == ILLEGAL) ? 0 : type_; } - - bool is_illegal() const { return type_ == ILLEGAL; } - bool is_slot() const { return type_ == SLOT; } - bool is_property() const { return type_ == NAMED || type_ == KEYED; } - - // Return the name. Only valid for named property references. - Handle GetName(); - - // Generate code to push the value of the reference on top of the - // expression stack. The reference is expected to be already on top of - // the expression stack, and it is left in place with its value above it. - void GetValue(TypeofState typeof_state); - - // Like GetValue except that the slot is expected to be written to before - // being read from again. Thae value of the reference may be invalidated, - // causing subsequent attempts to read it to fail. - void TakeValue(TypeofState typeof_state); - - // Generate code to store the value on top of the expression stack in the - // reference. The reference is expected to be immediately below the value - // on the expression stack. The stored value is left in place (with the - // reference intact below it) to support chained assignments. - void SetValue(InitState init_state); - - private: - CodeGenerator* cgen_; - Expression* expression_; - Type type_; -}; - - -// ------------------------------------------------------------------------- -// Control destinations. - -// A control destination encapsulates a pair of jump targets and a -// flag indicating which one is the preferred fall-through. The -// preferred fall-through must be unbound, the other may be already -// bound (ie, a backward target). -// -// The true and false targets may be jumped to unconditionally or -// control may split conditionally. Unconditional jumping and -// splitting should be emitted in tail position (as the last thing -// when compiling an expression) because they can cause either label -// to be bound or the non-fall through to be jumped to leaving an -// invalid virtual frame. -// -// The labels in the control destination can be extracted and -// manipulated normally without affecting the state of the -// destination. - -class ControlDestination BASE_EMBEDDED { - public: - ControlDestination(JumpTarget* true_target, - JumpTarget* false_target, - bool true_is_fall_through) - : true_target_(true_target), - false_target_(false_target), - true_is_fall_through_(true_is_fall_through), - is_used_(false) { - ASSERT(true_is_fall_through ? !true_target->is_bound() - : !false_target->is_bound()); - } - - // Accessors for the jump targets. Directly jumping or branching to - // or binding the targets will not update the destination's state. - JumpTarget* true_target() const { return true_target_; } - JumpTarget* false_target() const { return false_target_; } - - // True if the the destination has been jumped to unconditionally or - // control has been split to both targets. This predicate does not - // test whether the targets have been extracted and manipulated as - // raw jump targets. - bool is_used() const { return is_used_; } - - // True if the destination is used and the true target (respectively - // false target) was the fall through. If the target is backward, - // "fall through" included jumping unconditionally to it. - bool true_was_fall_through() const { - return is_used_ && true_is_fall_through_; - } - - bool false_was_fall_through() const { - return is_used_ && !true_is_fall_through_; - } - - // Emit a branch to one of the true or false targets, and bind the - // other target. Because this binds the fall-through target, it - // should be emitted in tail position (as the last thing when - // compiling an expression). - void Split(Condition cc) { - ASSERT(!is_used_); - if (true_is_fall_through_) { - false_target_->Branch(NegateCondition(cc)); - true_target_->Bind(); - } else { - true_target_->Branch(cc); - false_target_->Bind(); - } - is_used_ = true; - } - - // Emit an unconditional jump in tail position, to the true target - // (if the argument is true) or the false target. The "jump" will - // actually bind the jump target if it is forward, jump to it if it - // is backward. - void Goto(bool where) { - ASSERT(!is_used_); - JumpTarget* target = where ? true_target_ : false_target_; - if (target->is_bound()) { - target->Jump(); - } else { - target->Bind(); - } - is_used_ = true; - true_is_fall_through_ = where; - } - - // Mark this jump target as used as if Goto had been called, but - // without generating a jump or binding a label (the control effect - // should have already happened). This is used when the left - // subexpression of the short-circuit boolean operators are - // compiled. - void Use(bool where) { - ASSERT(!is_used_); - ASSERT((where ? true_target_ : false_target_)->is_bound()); - is_used_ = true; - true_is_fall_through_ = where; - } - - // Swap the true and false targets but keep the same actual label as - // the fall through. This is used when compiling negated - // expressions, where we want to swap the targets but preserve the - // state. - void Invert() { - JumpTarget* temp_target = true_target_; - true_target_ = false_target_; - false_target_ = temp_target; - - true_is_fall_through_ = !true_is_fall_through_; - } - - private: - // True and false jump targets. - JumpTarget* true_target_; - JumpTarget* false_target_; - - // Before using the destination: true if the true target is the - // preferred fall through, false if the false target is. After - // using the destination: true if the true target was actually used - // as the fall through, false if the false target was. - bool true_is_fall_through_; - - // True if the Split or Goto functions have been called. - bool is_used_; -}; - - -// ------------------------------------------------------------------------- -// Code generation state - -// The state is passed down the AST by the code generator (and back up, in -// the form of the state of the jump target pair). It is threaded through -// the call stack. Constructing a state implicitly pushes it on the owning -// code generator's stack of states, and destroying one implicitly pops it. -// -// The code generator state is only used for expressions, so statements have -// the initial state. - -class CodeGenState BASE_EMBEDDED { - public: - // Create an initial code generator state. Destroying the initial state - // leaves the code generator with a NULL state. - explicit CodeGenState(CodeGenerator* owner); - - // Create a code generator state based on a code generator's current - // state. The new state may or may not be inside a typeof, and has its - // own control destination. - CodeGenState(CodeGenerator* owner, - TypeofState typeof_state, - ControlDestination* destination); - - // Destroy a code generator state and restore the owning code generator's - // previous state. - ~CodeGenState(); - - // Accessors for the state. - TypeofState typeof_state() const { return typeof_state_; } - ControlDestination* destination() const { return destination_; } - - private: - // The owning code generator. - CodeGenerator* owner_; - - // A flag indicating whether we are compiling the immediate subexpression - // of a typeof expression. - TypeofState typeof_state_; - - // A control destination in case the expression has a control-flow - // effect. - ControlDestination* destination_; - - // The previous state of the owning code generator, restored when - // this state is destroyed. - CodeGenState* previous_; -}; - - -// ------------------------------------------------------------------------- -// Arguments allocation mode - -enum ArgumentsAllocationMode { - NO_ARGUMENTS_ALLOCATION, - EAGER_ARGUMENTS_ALLOCATION, - LAZY_ARGUMENTS_ALLOCATION -}; - - -// ------------------------------------------------------------------------- -// CodeGenerator - -class CodeGenerator: public AstVisitor { - public: - // Takes a function literal, generates code for it. This function should only - // be called by compiler.cc. - static Handle MakeCode(FunctionLiteral* fun, - Handle