Commit 3947056c authored by vegorov@chromium.org's avatar vegorov@chromium.org

Avoid embedding new space objects into code objects in the lithium gap resolver.

R=danno@chromium.org
BUG=http://crbug.com/108296
TEST=test/mjsunit/regress/regress-108296.js

Review URL: http://codereview.chromium.org/8960004

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10301 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 70056762
...@@ -385,6 +385,18 @@ DoubleRegister LCodeGen::EmitLoadDoubleRegister(LOperand* op, ...@@ -385,6 +385,18 @@ DoubleRegister LCodeGen::EmitLoadDoubleRegister(LOperand* op,
} }
Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const {
Handle<Object> literal = chunk_->LookupLiteral(op);
ASSERT(chunk_->LookupLiteralRepresentation(op).IsTagged());
return literal;
}
bool LCodeGen::IsInteger32(LConstantOperand* op) const {
return chunk_->LookupLiteralRepresentation(op).IsInteger32();
}
int LCodeGen::ToInteger32(LConstantOperand* op) const { int LCodeGen::ToInteger32(LConstantOperand* op) const {
Handle<Object> value = chunk_->LookupLiteral(op); Handle<Object> value = chunk_->LookupLiteral(op);
ASSERT(chunk_->LookupLiteralRepresentation(op).IsInteger32()); ASSERT(chunk_->LookupLiteralRepresentation(op).IsInteger32());
......
...@@ -93,6 +93,9 @@ class LCodeGen BASE_EMBEDDED { ...@@ -93,6 +93,9 @@ class LCodeGen BASE_EMBEDDED {
// Returns a MemOperand pointing to the high word of a DoubleStackSlot. // Returns a MemOperand pointing to the high word of a DoubleStackSlot.
MemOperand ToHighMemOperand(LOperand* op) const; MemOperand ToHighMemOperand(LOperand* op) const;
bool IsInteger32(LConstantOperand* op) const;
Handle<Object> ToHandle(LConstantOperand* op) const;
// Try to generate code for the entire chunk, but it may fail if the // Try to generate code for the entire chunk, but it may fail if the
// chunk contains constructs we cannot handle. Returns true if the // chunk contains constructs we cannot handle. Returns true if the
// code generation attempt succeeded. // code generation attempt succeeded.
......
...@@ -248,13 +248,24 @@ void LGapResolver::EmitMove(int index) { ...@@ -248,13 +248,24 @@ void LGapResolver::EmitMove(int index) {
} }
} else if (source->IsConstantOperand()) { } else if (source->IsConstantOperand()) {
Operand source_operand = cgen_->ToOperand(source); LConstantOperand* constant_source = LConstantOperand::cast(source);
if (destination->IsRegister()) { if (destination->IsRegister()) {
__ mov(cgen_->ToRegister(destination), source_operand); Register dst = cgen_->ToRegister(destination);
if (cgen_->IsInteger32(constant_source)) {
__ mov(dst, Operand(cgen_->ToInteger32(constant_source)));
} else {
__ LoadObject(dst, cgen_->ToHandle(constant_source));
}
} else { } else {
ASSERT(destination->IsStackSlot()); ASSERT(destination->IsStackSlot());
ASSERT(!in_cycle_); // Constant moves happen after all cycles are gone. ASSERT(!in_cycle_); // Constant moves happen after all cycles are gone.
__ mov(kSavedValueRegister, source_operand); if (cgen_->IsInteger32(constant_source)) {
__ mov(kSavedValueRegister,
Operand(cgen_->ToInteger32(constant_source)));
} else {
__ LoadObject(kSavedValueRegister,
cgen_->ToHandle(constant_source));
}
__ str(kSavedValueRegister, cgen_->ToMemOperand(destination)); __ str(kSavedValueRegister, cgen_->ToMemOperand(destination));
} }
......
...@@ -168,6 +168,14 @@ class MacroAssembler: public Assembler { ...@@ -168,6 +168,14 @@ class MacroAssembler: public Assembler {
void LoadHeapObject(Register dst, Handle<HeapObject> object); void LoadHeapObject(Register dst, Handle<HeapObject> object);
void LoadObject(Register result, Handle<Object> object) {
if (object->IsHeapObject()) {
LoadHeapObject(result, Handle<HeapObject>::cast(object));
} else {
Move(result, object);
}
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// GC Support // GC Support
......
...@@ -354,18 +354,8 @@ double LCodeGen::ToDouble(LConstantOperand* op) const { ...@@ -354,18 +354,8 @@ double LCodeGen::ToDouble(LConstantOperand* op) const {
} }
Immediate LCodeGen::ToImmediate(LOperand* op) { bool LCodeGen::IsInteger32(LConstantOperand* op) const {
LConstantOperand* const_op = LConstantOperand::cast(op); return chunk_->LookupLiteralRepresentation(op).IsInteger32();
Handle<Object> literal = chunk_->LookupLiteral(const_op);
Representation r = chunk_->LookupLiteralRepresentation(const_op);
if (r.IsInteger32()) {
ASSERT(literal->IsNumber());
return Immediate(static_cast<int32_t>(literal->Number()));
} else if (r.IsDouble()) {
Abort("unsupported double immediate");
}
ASSERT(r.IsTagged());
return Immediate(literal);
} }
...@@ -1167,7 +1157,7 @@ void LCodeGen::DoSubI(LSubI* instr) { ...@@ -1167,7 +1157,7 @@ void LCodeGen::DoSubI(LSubI* instr) {
ASSERT(left->Equals(instr->result())); ASSERT(left->Equals(instr->result()));
if (right->IsConstantOperand()) { if (right->IsConstantOperand()) {
__ sub(ToOperand(left), ToImmediate(right)); __ sub(ToOperand(left), ToInteger32Immediate(right));
} else { } else {
__ sub(ToRegister(left), ToOperand(right)); __ sub(ToRegister(left), ToOperand(right));
} }
...@@ -1306,7 +1296,7 @@ void LCodeGen::DoAddI(LAddI* instr) { ...@@ -1306,7 +1296,7 @@ void LCodeGen::DoAddI(LAddI* instr) {
ASSERT(left->Equals(instr->result())); ASSERT(left->Equals(instr->result()));
if (right->IsConstantOperand()) { if (right->IsConstantOperand()) {
__ add(ToOperand(left), ToImmediate(right)); __ add(ToOperand(left), ToInteger32Immediate(right));
} else { } else {
__ add(ToRegister(left), ToOperand(right)); __ add(ToRegister(left), ToOperand(right));
} }
...@@ -1578,9 +1568,9 @@ void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) { ...@@ -1578,9 +1568,9 @@ void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) {
__ j(parity_even, chunk_->GetAssemblyLabel(false_block)); __ j(parity_even, chunk_->GetAssemblyLabel(false_block));
} else { } else {
if (right->IsConstantOperand()) { if (right->IsConstantOperand()) {
__ cmp(ToRegister(left), ToImmediate(right)); __ cmp(ToRegister(left), ToInteger32Immediate(right));
} else if (left->IsConstantOperand()) { } else if (left->IsConstantOperand()) {
__ cmp(ToOperand(right), ToImmediate(left)); __ cmp(ToOperand(right), ToInteger32Immediate(left));
// We transposed the operands. Reverse the condition. // We transposed the operands. Reverse the condition.
cc = ReverseCondition(cc); cc = ReverseCondition(cc);
} else { } else {
...@@ -3261,7 +3251,7 @@ void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { ...@@ -3261,7 +3251,7 @@ void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) {
void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) {
if (instr->index()->IsConstantOperand()) { if (instr->index()->IsConstantOperand()) {
__ cmp(ToOperand(instr->length()), __ cmp(ToOperand(instr->length()),
ToImmediate(LConstantOperand::cast(instr->index()))); Immediate(ToInteger32(LConstantOperand::cast(instr->index()))));
DeoptimizeIf(below_equal, instr->environment()); DeoptimizeIf(below_equal, instr->environment());
} else { } else {
__ cmp(ToRegister(instr->index()), ToOperand(instr->length())); __ cmp(ToRegister(instr->index()), ToOperand(instr->length()));
......
...@@ -78,7 +78,13 @@ class LCodeGen BASE_EMBEDDED { ...@@ -78,7 +78,13 @@ class LCodeGen BASE_EMBEDDED {
Operand ToOperand(LOperand* op) const; Operand ToOperand(LOperand* op) const;
Register ToRegister(LOperand* op) const; Register ToRegister(LOperand* op) const;
XMMRegister ToDoubleRegister(LOperand* op) const; XMMRegister ToDoubleRegister(LOperand* op) const;
Immediate ToImmediate(LOperand* op);
bool IsInteger32(LConstantOperand* op) const;
Immediate ToInteger32Immediate(LOperand* op) const {
return Immediate(ToInteger32(LConstantOperand::cast(op)));
}
Handle<Object> ToHandle(LConstantOperand* op) const;
// The operand denoting the second word (the one with a higher address) of // The operand denoting the second word (the one with a higher address) of
// a double stack slot. // a double stack slot.
...@@ -225,7 +231,7 @@ class LCodeGen BASE_EMBEDDED { ...@@ -225,7 +231,7 @@ class LCodeGen BASE_EMBEDDED {
Register ToRegister(int index) const; Register ToRegister(int index) const;
XMMRegister ToDoubleRegister(int index) const; XMMRegister ToDoubleRegister(int index) const;
int ToInteger32(LConstantOperand* op) const; int ToInteger32(LConstantOperand* op) const;
Handle<Object> ToHandle(LConstantOperand* op) const;
double ToDouble(LConstantOperand* op) const; double ToDouble(LConstantOperand* op) const;
Operand BuildFastArrayOperand(LOperand* elements_pointer, Operand BuildFastArrayOperand(LOperand* elements_pointer,
LOperand* key, LOperand* key,
......
...@@ -303,14 +303,24 @@ void LGapResolver::EmitMove(int index) { ...@@ -303,14 +303,24 @@ void LGapResolver::EmitMove(int index) {
} }
} else if (source->IsConstantOperand()) { } else if (source->IsConstantOperand()) {
ASSERT(destination->IsRegister() || destination->IsStackSlot()); LConstantOperand* constant_source = LConstantOperand::cast(source);
Immediate src = cgen_->ToImmediate(source);
if (destination->IsRegister()) { if (destination->IsRegister()) {
Register dst = cgen_->ToRegister(destination); Register dst = cgen_->ToRegister(destination);
__ Set(dst, src); if (cgen_->IsInteger32(constant_source)) {
__ Set(dst, cgen_->ToInteger32Immediate(constant_source));
} else {
__ LoadObject(dst, cgen_->ToHandle(constant_source));
}
} else { } else {
ASSERT(destination->IsStackSlot());
Operand dst = cgen_->ToOperand(destination); Operand dst = cgen_->ToOperand(destination);
__ Set(dst, src); if (cgen_->IsInteger32(constant_source)) {
__ Set(dst, cgen_->ToInteger32Immediate(constant_source));
} else {
Register tmp = EnsureTempRegister();
__ LoadObject(tmp, cgen_->ToHandle(constant_source));
__ mov(dst, tmp);
}
} }
} else if (source->IsDoubleRegister()) { } else if (source->IsDoubleRegister()) {
......
...@@ -240,6 +240,14 @@ class MacroAssembler: public Assembler { ...@@ -240,6 +240,14 @@ class MacroAssembler: public Assembler {
void LoadHeapObject(Register result, Handle<HeapObject> object); void LoadHeapObject(Register result, Handle<HeapObject> object);
void PushHeapObject(Handle<HeapObject> object); void PushHeapObject(Handle<HeapObject> object);
void LoadObject(Register result, Handle<Object> object) {
if (object->IsHeapObject()) {
LoadHeapObject(result, Handle<HeapObject>::cast(object));
} else {
Set(result, Immediate(object));
}
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// JavaScript invokes // JavaScript invokes
......
...@@ -198,7 +198,7 @@ void LGapResolver::EmitMove(int index) { ...@@ -198,7 +198,7 @@ void LGapResolver::EmitMove(int index) {
if (cgen_->IsInteger32Constant(constant_source)) { if (cgen_->IsInteger32Constant(constant_source)) {
__ movl(dst, Immediate(cgen_->ToInteger32(constant_source))); __ movl(dst, Immediate(cgen_->ToInteger32(constant_source)));
} else { } else {
__ Move(dst, cgen_->ToHandle(constant_source)); __ LoadObject(dst, cgen_->ToHandle(constant_source));
} }
} else { } else {
ASSERT(destination->IsStackSlot()); ASSERT(destination->IsStackSlot());
...@@ -207,7 +207,8 @@ void LGapResolver::EmitMove(int index) { ...@@ -207,7 +207,8 @@ void LGapResolver::EmitMove(int index) {
// Allow top 32 bits of an untagged Integer32 to be arbitrary. // Allow top 32 bits of an untagged Integer32 to be arbitrary.
__ movl(dst, Immediate(cgen_->ToInteger32(constant_source))); __ movl(dst, Immediate(cgen_->ToInteger32(constant_source)));
} else { } else {
__ Move(dst, cgen_->ToHandle(constant_source)); __ LoadObject(kScratchRegister, cgen_->ToHandle(constant_source));
__ movq(dst, kScratchRegister);
} }
} }
......
...@@ -789,6 +789,14 @@ class MacroAssembler: public Assembler { ...@@ -789,6 +789,14 @@ class MacroAssembler: public Assembler {
void LoadHeapObject(Register result, Handle<HeapObject> object); void LoadHeapObject(Register result, Handle<HeapObject> object);
void PushHeapObject(Handle<HeapObject> object); void PushHeapObject(Handle<HeapObject> object);
void LoadObject(Register result, Handle<Object> object) {
if (object->IsHeapObject()) {
LoadHeapObject(result, Handle<HeapObject>::cast(object));
} else {
Move(result, object);
}
}
// Load a global cell into a register. // Load a global cell into a register.
void LoadGlobalCell(Register dst, Handle<JSGlobalPropertyCell> cell); void LoadGlobalCell(Register dst, Handle<JSGlobalPropertyCell> cell);
......
// Copyright 2011 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.
// Flags: --allow-natives-syntax
// This test checks that young immediates embedded into code objects
// are referenced through a cell.
function f (k, a, b) {
// Create control flow for a.foo. Control flow resolution will
// be generated as a part of a gap move. Gap move operate on immediates as
// a.foo is a CONSTANT_FUNCTION.
var x = k ? a.foo : a.foo;
return x.prototype;
}
var a = { };
// Make sure that foo is a CONSTANT_FUNCTION but not be pretenured.
a.foo = (function () { return function () {}; })();
// Ensure that both branches of ternary operator have monomorphic type feedback.
f(true, a, a);
f(true, a, a);
f(false, a, a);
f(false, a, a);
%OptimizeFunctionOnNextCall(f);
f(true, a, a);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment