PrintF("MapCheck(this)\n");
}
+ ASSERT(info()->has_receiver() && info()->receiver()->IsHeapObject());
+ Handle<HeapObject> object = Handle<HeapObject>::cast(info()->receiver());
+ Handle<Map> map(object->map());
+
EmitLoadReceiver(r1);
- __ BranchOnSmi(r1, bailout());
+ __ CheckMap(r1, r3, map, bailout(), false);
+}
- ASSERT(has_receiver() && receiver()->IsHeapObject());
- Handle<HeapObject> object = Handle<HeapObject>::cast(receiver());
- Handle<Map> map(object->map());
- __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset));
- __ mov(ip, Operand(map));
- __ cmp(r3, ip);
- __ b(ne, bailout());
+
+void FastCodeGenerator::EmitGlobalMapCheck() {
+ Comment cmnt(masm(), ";; GlobalMapCheck");
+ if (FLAG_print_ir) {
+ PrintF(";; GlobalMapCheck()");
+ }
+
+ ASSERT(info()->has_global_object());
+ Handle<Map> map(info()->global_object()->map());
+
+ __ ldr(r3, CodeGenerator::GlobalObject());
+ __ CheckMap(r3, r3, map, bailout(), true);
}
-void FastCodeGenerator::EmitGlobalVariableLoad(Handle<String> name) {
- // Compile global variable accesses as load IC calls. The only live
- // registers are cp (context) and possibly r1 (this). Both are also saved
- // in the stack and cp is preserved by the call.
- __ ldr(ip, CodeGenerator::GlobalObject());
- __ push(ip);
- __ mov(r2, Operand(name));
- Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize));
- __ Call(ic, RelocInfo::CODE_TARGET_CONTEXT);
- if (has_this_properties()) {
- // Restore this.
- EmitLoadReceiver(r1);
+void FastCodeGenerator::EmitGlobalVariableLoad(Handle<Object> cell) {
+ ASSERT(cell->IsJSGlobalPropertyCell());
+ __ mov(r0, Operand(cell));
+ __ ldr(r0, FieldMemOperand(r0, JSGlobalPropertyCell::kValueOffset));
+ if (FLAG_debug_code) {
+ __ mov(ip, Operand(Factory::the_hole_value()));
+ __ cmp(r0, ip);
+ __ Check(ne, "DontDelete cells can't contain the hole");
}
}
void FastCodeGenerator::EmitThisPropertyStore(Handle<String> name) {
LookupResult lookup;
- receiver()->Lookup(*name, &lookup);
+ info()->receiver()->Lookup(*name, &lookup);
- ASSERT(lookup.holder() == *receiver());
+ ASSERT(lookup.holder() == *info()->receiver());
ASSERT(lookup.type() == FIELD);
- Handle<Map> map(Handle<HeapObject>::cast(receiver())->map());
+ Handle<Map> map(Handle<HeapObject>::cast(info()->receiver())->map());
int index = lookup.GetFieldIndex() - map->inobject_properties();
int offset = index * kPointerSize;
}
-void FastCodeGenerator::Generate(CompilationInfo* info) {
+void FastCodeGenerator::Generate(CompilationInfo* compilation_info) {
ASSERT(info_ == NULL);
- info_ = info;
+ info_ = compilation_info;
// Save the caller's frame pointer and set up our own.
Comment prologue_cmnt(masm(), ";; Prologue");
// this point.
// Receiver (this) is allocated to r1 if there are this properties.
- if (has_this_properties()) EmitReceiverMapCheck();
+ if (info()->has_this_properties()) EmitReceiverMapCheck();
+
+ // If there is a global variable access check if the global object
+ // is the same as at lazy-compilation time.
+ if (info()->has_globals()) EmitGlobalMapCheck();
VisitStatements(function()->body());
}
+void MacroAssembler::CheckMap(Register obj,
+ Register scratch,
+ Handle<Map> map,
+ Label* fail,
+ bool is_heap_object) {
+ if (!is_heap_object) {
+ BranchOnSmi(obj, fail);
+ }
+ ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset));
+ mov(ip, Operand(map));
+ cmp(scratch, ip);
+ b(ne, fail);
+}
+
+
void MacroAssembler::TryGetFunctionPrototype(Register function,
Register result,
Register scratch,
InstanceType type);
+ // Check if the map of an object is equal to a specified map and
+ // branch to label if not. Skip the smi check if not required
+ // (object is known to be a heap object)
+ void CheckMap(Register obj,
+ Register scratch,
+ Handle<Map> map,
+ Label* fail,
+ bool is_heap_object);
+
// Load and check the instance type of an object for being a string.
// Loads the type into the second argument register.
// Returns a condition that will be enabled if the object was a string.
bool has_this_properties() { return has_this_properties_; }
void set_has_this_properties(bool flag) { has_this_properties_ = flag; }
+ bool has_global_object() {
+ return !closure().is_null() && (closure()->context()->global() != NULL);
+ }
+
+ GlobalObject* global_object() {
+ return has_global_object() ? closure()->context()->global() : NULL;
+ }
+
bool has_globals() { return has_globals_; }
void set_has_globals(bool flag) { has_globals_ = flag; }
void AstLabeler::VisitVariableProxy(VariableProxy* expr) {
expr->set_num(next_number_++);
+ Variable* var = expr->var();
+ if (var->is_global() && !var->is_this()) {
+ info_->set_has_globals(true);
+ }
}
void FastCodeGenSyntaxChecker::VisitVariableProxy(VariableProxy* expr) {
// Only global variable references are supported.
Variable* var = expr->var();
- if (!var->is_global()) BAILOUT("Non-global variable");
+ if (!var->is_global() || var->is_this()) BAILOUT("Non-global variable");
+
+ // Check if the global variable is existing and non-deletable.
+ if (info()->has_global_object()) {
+ LookupResult lookup;
+ info()->global_object()->Lookup(*expr->name(), &lookup);
+ if (!lookup.IsValid() || !lookup.IsDontDelete()) {
+ BAILOUT("Non-existing or deletable global variable");
+ }
+ }
}
SmartPointer<char> name = expr->name()->ToCString();
PrintF("%d: t%d = Global(%s)\n", expr->num(), expr->num(), *name);
}
- EmitGlobalVariableLoad(expr->name());
+
+ // Check if we can compile a global variable load directly from the cell.
+ ASSERT(info()->has_global_object());
+ LookupResult lookup;
+ info()->global_object()->Lookup(*expr->name(), &lookup);
+ // We only support DontDelete properties for now.
+ ASSERT(lookup.IsValid());
+ ASSERT(lookup.IsDontDelete());
+ Handle<Object> cell(info()->global_object()->GetPropertyCell(&lookup));
+ EmitGlobalVariableLoad(cell);
}
static Handle<Code> MakeCode(CompilationInfo* info);
- void Generate(CompilationInfo* info);
+ void Generate(CompilationInfo* compilation_info);
private:
MacroAssembler* masm() { return masm_; }
+ CompilationInfo* info() { return info_; }
Label* bailout() { return &bailout_; }
- bool has_receiver() { return !info_->receiver().is_null(); }
- Handle<Object> receiver() { return info_->receiver(); }
- bool has_this_properties() { return info_->has_this_properties(); }
FunctionLiteral* function() { return info_->function(); }
Scope* scope() { return info_->scope(); }
// arm-r1}. Emit a branch to the (single) bailout label if check fails.
void EmitReceiverMapCheck();
- // Emit code to load a global variable value into {is32-eax, x64-rax,
- // arm-r0}. Register {ia32-edx, x64-rdx, arm-r1} is preserved if it is
- // holding the receiver and {is32-ecx, x64-rcx, arm-r2} is always
- // clobbered.
- void EmitGlobalVariableLoad(Handle<String> name);
+ // Emit code to check that the global object has the same map as the
+ // global object seen at compile time.
+ void EmitGlobalMapCheck();
+
+ // Emit code to load a global variable directly from a global
+ // property cell into {ia32-eax, x64-rax, arm-r0}.
+ void EmitGlobalVariableLoad(Handle<Object> cell);
// Emit a store to an own property of this. The stored value is expected
// in {ia32-eax, x64-rax, arm-r0} and the receiver in {is32-edx, x64-rdx,
PrintF("MapCheck(this)\n");
}
+ ASSERT(info()->has_receiver() && info()->receiver()->IsHeapObject());
+ Handle<HeapObject> object = Handle<HeapObject>::cast(info()->receiver());
+ Handle<Map> map(object->map());
+
EmitLoadReceiver(edx);
- __ test(edx, Immediate(kSmiTagMask));
- __ j(zero, bailout());
+ __ CheckMap(edx, map, bailout(), false);
+}
- ASSERT(has_receiver() && receiver()->IsHeapObject());
- Handle<HeapObject> object = Handle<HeapObject>::cast(receiver());
- Handle<Map> map(object->map());
- __ cmp(FieldOperand(edx, HeapObject::kMapOffset), Immediate(map));
- __ j(not_equal, bailout());
+
+void FastCodeGenerator::EmitGlobalMapCheck() {
+ Comment cmnt(masm(), ";; GlobalMapCheck");
+ if (FLAG_print_ir) {
+ PrintF(";; GlobalMapCheck()");
+ }
+
+ ASSERT(info()->has_global_object());
+ Handle<Map> map(info()->global_object()->map());
+
+ __ mov(ebx, CodeGenerator::GlobalObject());
+ __ CheckMap(ebx, map, bailout(), true);
}
-void FastCodeGenerator::EmitGlobalVariableLoad(Handle<String> name) {
- // Compile global variable accesses as load IC calls. The only live
- // registers are esi (context) and possibly edx (this). Both are also
- // saved in the stack and esi is preserved by the call.
- __ push(CodeGenerator::GlobalObject());
- __ mov(ecx, name);
- Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize));
- __ call(ic, RelocInfo::CODE_TARGET_CONTEXT);
- if (has_this_properties()) {
- // Restore this.
- EmitLoadReceiver(edx);
- } else {
- __ nop(); // Not test eax, indicates IC has no inlined code at call site.
+void FastCodeGenerator::EmitGlobalVariableLoad(Handle<Object> cell) {
+ ASSERT(cell->IsJSGlobalPropertyCell());
+ __ mov(eax, Immediate(cell));
+ __ mov(eax, FieldOperand(eax, JSGlobalPropertyCell::kValueOffset));
+ if (FLAG_debug_code) {
+ __ cmp(eax, Factory::the_hole_value());
+ __ Check(not_equal, "DontDelete cells can't contain the hole");
}
}
void FastCodeGenerator::EmitThisPropertyStore(Handle<String> name) {
LookupResult lookup;
- receiver()->Lookup(*name, &lookup);
+ info()->receiver()->Lookup(*name, &lookup);
- ASSERT(lookup.holder() == *receiver());
+ ASSERT(lookup.holder() == *info()->receiver());
ASSERT(lookup.type() == FIELD);
- Handle<Map> map(Handle<HeapObject>::cast(receiver())->map());
+ Handle<Map> map(Handle<HeapObject>::cast(info()->receiver())->map());
int index = lookup.GetFieldIndex() - map->inobject_properties();
int offset = index * kPointerSize;
}
-void FastCodeGenerator::Generate(CompilationInfo* info) {
+void FastCodeGenerator::Generate(CompilationInfo* compilation_info) {
ASSERT(info_ == NULL);
- info_ = info;
+ info_ = compilation_info;
// Save the caller's frame pointer and set up our own.
Comment prologue_cmnt(masm(), ";; Prologue");
// point.
// Receiver (this) is allocated to edx if there are this properties.
- if (has_this_properties()) EmitReceiverMapCheck();
+ if (info()->has_this_properties()) EmitReceiverMapCheck();
+
+ // If there is a global variable access check if the global object
+ // is the same as at lazy-compilation time.
+ if (info()->has_globals()) EmitGlobalMapCheck();
VisitStatements(function()->body());
}
+void MacroAssembler::CheckMap(Register obj,
+ Handle<Map> map,
+ Label* fail,
+ bool is_heap_object) {
+ if (!is_heap_object) {
+ test(obj, Immediate(kSmiTagMask));
+ j(zero, fail);
+ }
+ cmp(FieldOperand(obj, HeapObject::kMapOffset), Immediate(map));
+ j(not_equal, fail);
+}
+
+
Condition MacroAssembler::IsObjectStringType(Register heap_object,
Register map,
Register instance_type) {
// Compare instance type for map.
void CmpInstanceType(Register map, InstanceType type);
+ // Check if the map of an object is equal to a specified map and
+ // branch to label if not. Skip the smi check if not required
+ // (object is known to be a heap object)
+ void CheckMap(Register obj,
+ Handle<Map> map,
+ Label* fail,
+ bool is_heap_object);
+
// Check if the object in register heap_object is a string. Afterwards the
// register map contains the object map and the register instance_type
// contains the instance_type. The registers map and instance_type can be the
PrintF("MapCheck(this)\n");
}
+ ASSERT(info()->has_receiver() && info()->receiver()->IsHeapObject());
+ Handle<HeapObject> object = Handle<HeapObject>::cast(info()->receiver());
+ Handle<Map> map(object->map());
+
EmitLoadReceiver(rdx);
- __ JumpIfSmi(rdx, bailout());
+ __ CheckMap(rdx, map, bailout(), false);
+}
- ASSERT(has_receiver() && receiver()->IsHeapObject());
- Handle<HeapObject> object = Handle<HeapObject>::cast(receiver());
- Handle<Map> map(object->map());
- __ Cmp(FieldOperand(rdx, HeapObject::kMapOffset), map);
- __ j(not_equal, bailout());
+
+void FastCodeGenerator::EmitGlobalMapCheck() {
+ Comment cmnt(masm(), ";; GlobalMapCheck");
+ if (FLAG_print_ir) {
+ PrintF(";; GlobalMapCheck()");
+ }
+
+ ASSERT(info()->has_global_object());
+ Handle<Map> map(info()->global_object()->map());
+
+ __ movq(rbx, CodeGenerator::GlobalObject());
+ __ CheckMap(rbx, map, bailout(), true);
}
-void FastCodeGenerator::EmitGlobalVariableLoad(Handle<String> name) {
- // Compile global variable accesses as load IC calls. The only live
- // registers are rsi (context) and possibly rdx (this). Both are also
- // saved in the stack and rsi is preserved by the call.
- __ push(CodeGenerator::GlobalObject());
- __ Move(rcx, name);
- Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize));
- __ Call(ic, RelocInfo::CODE_TARGET_CONTEXT);
- if (has_this_properties()) {
- // Restore this.
- EmitLoadReceiver(rdx);
- } else {
- __ nop(); // Not test rax, indicates IC has no inlined code at call site.
+void FastCodeGenerator::EmitGlobalVariableLoad(Handle<Object> cell) {
+ ASSERT(cell->IsJSGlobalPropertyCell());
+ __ Move(rax, cell);
+ __ movq(rax, FieldOperand(rax, JSGlobalPropertyCell::kValueOffset));
+ if (FLAG_debug_code) {
+ __ Cmp(rax, Factory::the_hole_value());
+ __ Check(not_equal, "DontDelete cells can't contain the hole");
}
}
void FastCodeGenerator::EmitThisPropertyStore(Handle<String> name) {
LookupResult lookup;
- receiver()->Lookup(*name, &lookup);
+ info()->receiver()->Lookup(*name, &lookup);
- ASSERT(lookup.holder() == *receiver());
+ ASSERT(lookup.holder() == *info()->receiver());
ASSERT(lookup.type() == FIELD);
- Handle<Map> map(Handle<HeapObject>::cast(receiver())->map());
+ Handle<Map> map(Handle<HeapObject>::cast(info()->receiver())->map());
int index = lookup.GetFieldIndex() - map->inobject_properties();
int offset = index * kPointerSize;
}
-void FastCodeGenerator::Generate(CompilationInfo* info) {
+void FastCodeGenerator::Generate(CompilationInfo* compilation_info) {
ASSERT(info_ == NULL);
- info_ = info;
+ info_ = compilation_info;
// Save the caller's frame pointer and set up our own.
Comment prologue_cmnt(masm(), ";; Prologue");
// point.
// Receiver (this) is allocated to rdx if there are this properties.
- if (has_this_properties()) EmitReceiverMapCheck();
+ if (info()->has_this_properties()) EmitReceiverMapCheck();
+
+ // If there is a global variable access check if the global object
+ // is the same as at lazy-compilation time.
+ if (info()->has_globals()) EmitGlobalMapCheck();
- VisitStatements(info->function()->body());
+ VisitStatements(info()->function()->body());
Comment return_cmnt(masm(), ";; Return(<undefined>)");
__ LoadRoot(rax, Heap::kUndefinedValueRootIndex);
}
+void MacroAssembler::CheckMap(Register obj,
+ Handle<Map> map,
+ Label* fail,
+ bool is_heap_object) {
+ if (!is_heap_object) {
+ JumpIfSmi(obj, fail);
+ }
+ Cmp(FieldOperand(obj, HeapObject::kMapOffset), map);
+ j(not_equal, fail);
+}
+
+
Condition MacroAssembler::IsObjectStringType(Register heap_object,
Register map,
Register instance_type) {
// Always use unsigned comparisons: above and below, not less and greater.
void CmpInstanceType(Register map, InstanceType type);
+ // Check if the map of an object is equal to a specified map and
+ // branch to label if not. Skip the smi check if not required
+ // (object is known to be a heap object)
+ void CheckMap(Register obj,
+ Handle<Map> map,
+ Label* fail,
+ bool is_heap_object);
+
// Check if the object in register heap_object is a string. Afterwards the
// register map contains the object map and the register instance_type
// contains the instance_type. The registers map and instance_type can be the
--- /dev/null
+// Copyright 2010 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: --fast-compiler
+
+// Test global variable loads with the fast compiler.
+var g1 = 42;
+var g2 = 43;
+var g3 = 44;
+
+function f1() { this.x = this.y = this.z = g1; }
+function f2() { this.x = g1; this.y = g2; this.z = g3; }
+
+var o = {x:0, y:0, z:0, m1:f1, m2:f2}
+
+o.m1();
+
+assertEquals(42, o.x);
+assertEquals(42, o.y);
+assertEquals(42, o.z);
+
+
+o.m2();
+
+assertEquals(42, o.x);
+assertEquals(43, o.y);
+assertEquals(44, o.z);
// (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: --nofast-compiler
+// Flags: --nofull-compiler
// The type of a regular expression should be 'function', including in
// the context of string equality comparisons.