2011-05-18 13:17:29 +00:00
|
|
|
// Copyright 2011 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
|
|
|
#include "api.h"
|
|
|
|
#include "arguments.h"
|
2011-08-22 14:23:37 +00:00
|
|
|
#include "ast.h"
|
2011-06-10 07:49:49 +00:00
|
|
|
#include "code-stubs.h"
|
2011-01-18 16:11:01 +00:00
|
|
|
#include "gdb-jit.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "ic-inl.h"
|
|
|
|
#include "stub-cache.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "vm-state-inl.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
// StubCache implementation.
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
StubCache::StubCache(Isolate* isolate) : isolate_(isolate) {
|
|
|
|
ASSERT(isolate == Isolate::Current());
|
|
|
|
memset(primary_, 0, sizeof(primary_[0]) * StubCache::kPrimaryTableSize);
|
|
|
|
memset(secondary_, 0, sizeof(secondary_[0]) * StubCache::kSecondaryTableSize);
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
void StubCache::Initialize(bool create_heap_objects) {
|
|
|
|
ASSERT(IsPowerOf2(kPrimaryTableSize));
|
|
|
|
ASSERT(IsPowerOf2(kSecondaryTableSize));
|
|
|
|
if (create_heap_objects) {
|
|
|
|
HandleScope scope;
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Code* StubCache::Set(String* name, Map* map, Code* code) {
|
|
|
|
// Get the flags from the code.
|
|
|
|
Code::Flags flags = Code::RemoveTypeFromFlags(code->flags());
|
|
|
|
|
|
|
|
// Validate that the name does not move on scavenge, and that we
|
|
|
|
// can use identity checks instead of string equality checks.
|
2011-03-30 08:18:56 +00:00
|
|
|
ASSERT(!heap()->InNewSpace(name));
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(name->IsSymbol());
|
|
|
|
|
|
|
|
// The state bits are not important to the hash function because
|
|
|
|
// the stub cache only contains monomorphic stubs. Make sure that
|
|
|
|
// the bits are the least significant so they will be the ones
|
|
|
|
// masked out.
|
2008-07-30 08:49:36 +00:00
|
|
|
ASSERT(Code::ExtractICStateFromFlags(flags) == MONOMORPHIC);
|
|
|
|
ASSERT(Code::kFlagsICStateShift == 0);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Make sure that the code type is not included in the hash.
|
|
|
|
ASSERT(Code::ExtractTypeFromFlags(flags) == 0);
|
|
|
|
|
|
|
|
// Compute the primary entry.
|
|
|
|
int primary_offset = PrimaryOffset(name, flags, map);
|
|
|
|
Entry* primary = entry(primary_, primary_offset);
|
|
|
|
Code* hit = primary->value;
|
|
|
|
|
|
|
|
// If the primary entry has useful data in it, we retire it to the
|
|
|
|
// secondary cache before overwriting it.
|
2011-03-23 13:40:07 +00:00
|
|
|
if (hit != isolate_->builtins()->builtin(Builtins::kIllegal)) {
|
2008-07-03 15:10:15 +00:00
|
|
|
Code::Flags primary_flags = Code::RemoveTypeFromFlags(hit->flags());
|
|
|
|
int secondary_offset =
|
|
|
|
SecondaryOffset(primary->key, primary_flags, primary_offset);
|
|
|
|
Entry* secondary = entry(secondary_, secondary_offset);
|
|
|
|
*secondary = *primary;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update primary cache.
|
|
|
|
primary->key = name;
|
|
|
|
primary->value = code;
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeLoadNonexistent(String* name,
|
|
|
|
JSObject* receiver) {
|
2010-07-02 14:15:04 +00:00
|
|
|
ASSERT(receiver->IsGlobalObject() || receiver->HasFastProperties());
|
2010-04-15 11:25:41 +00:00
|
|
|
// If no global objects are present in the prototype chain, the load
|
|
|
|
// nonexistent IC stub can be shared for all names for a given map
|
|
|
|
// and we use the empty string for the map cache in that case. If
|
|
|
|
// there are global objects involved, we need to check global
|
|
|
|
// property cells in the stub and therefore the stub will be
|
|
|
|
// specific to the name.
|
2011-03-30 08:18:56 +00:00
|
|
|
String* cache_name = heap()->empty_string();
|
2010-04-15 11:25:41 +00:00
|
|
|
if (receiver->IsGlobalObject()) cache_name = name;
|
|
|
|
JSObject* last = receiver;
|
2011-03-30 08:18:56 +00:00
|
|
|
while (last->GetPrototype() != heap()->null_value()) {
|
2010-04-15 11:25:41 +00:00
|
|
|
last = JSObject::cast(last->GetPrototype());
|
|
|
|
if (last->IsGlobalObject()) cache_name = name;
|
|
|
|
}
|
|
|
|
// Compile the stub that is either shared for all names or
|
|
|
|
// name specific if there are global objects involved.
|
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(Code::LOAD_IC, NONEXISTENT);
|
|
|
|
Object* code = receiver->map()->FindInCodeCache(cache_name, flags);
|
|
|
|
if (code->IsUndefined()) {
|
|
|
|
LoadStubCompiler compiler;
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileLoadNonexistent(cache_name, receiver, last);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::LOAD_IC_TAG, Code::cast(code), cache_name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, cache_name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(cache_name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2010-04-15 11:25:41 +00:00
|
|
|
}
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2010-04-15 11:25:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeLoadField(String* name,
|
|
|
|
JSObject* receiver,
|
|
|
|
JSObject* holder,
|
|
|
|
int field_index) {
|
2010-07-02 14:15:04 +00:00
|
|
|
ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP);
|
2008-07-03 15:10:15 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, FIELD);
|
2010-08-25 13:25:54 +00:00
|
|
|
Object* code = receiver->map()->FindInCodeCache(name, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (code->IsUndefined()) {
|
|
|
|
LoadStubCompiler compiler;
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileLoadField(receiver, holder, field_index, name);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::LOAD_IC_TAG, Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeLoadCallback(String* name,
|
|
|
|
JSObject* receiver,
|
|
|
|
JSObject* holder,
|
|
|
|
AccessorInfo* callback) {
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(v8::ToCData<Address>(callback->getter()) != 0);
|
2010-07-02 14:15:04 +00:00
|
|
|
ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP);
|
2008-07-03 15:10:15 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, CALLBACKS);
|
2010-08-25 13:25:54 +00:00
|
|
|
Object* code = receiver->map()->FindInCodeCache(name, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (code->IsUndefined()) {
|
|
|
|
LoadStubCompiler compiler;
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileLoadCallback(name, receiver, holder, callback);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::LOAD_IC_TAG, Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeLoadConstant(String* name,
|
|
|
|
JSObject* receiver,
|
|
|
|
JSObject* holder,
|
|
|
|
Object* value) {
|
2010-07-02 14:15:04 +00:00
|
|
|
ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP);
|
2008-07-03 15:10:15 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(Code::LOAD_IC, CONSTANT_FUNCTION);
|
2010-08-25 13:25:54 +00:00
|
|
|
Object* code = receiver->map()->FindInCodeCache(name, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (code->IsUndefined()) {
|
|
|
|
LoadStubCompiler compiler;
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileLoadConstant(receiver, holder, value, name);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::LOAD_IC_TAG, Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeLoadInterceptor(String* name,
|
|
|
|
JSObject* receiver,
|
|
|
|
JSObject* holder) {
|
2010-07-02 14:15:04 +00:00
|
|
|
ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP);
|
2008-07-03 15:10:15 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, INTERCEPTOR);
|
2010-08-25 13:25:54 +00:00
|
|
|
Object* code = receiver->map()->FindInCodeCache(name, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (code->IsUndefined()) {
|
|
|
|
LoadStubCompiler compiler;
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileLoadInterceptor(receiver, holder, name);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::LOAD_IC_TAG, Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeLoadNormal() {
|
2011-03-23 13:40:07 +00:00
|
|
|
return isolate_->builtins()->builtin(Builtins::kLoadIC_Normal);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeLoadGlobal(String* name,
|
|
|
|
JSObject* receiver,
|
|
|
|
GlobalObject* holder,
|
|
|
|
JSGlobalPropertyCell* cell,
|
|
|
|
bool is_dont_delete) {
|
2010-07-02 14:15:04 +00:00
|
|
|
ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP);
|
2009-06-30 10:05:36 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, NORMAL);
|
2010-08-25 13:25:54 +00:00
|
|
|
Object* code = receiver->map()->FindInCodeCache(name, flags);
|
2009-06-30 10:05:36 +00:00
|
|
|
if (code->IsUndefined()) {
|
|
|
|
LoadStubCompiler compiler;
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code = compiler.CompileLoadGlobal(receiver,
|
|
|
|
holder,
|
|
|
|
cell,
|
|
|
|
name,
|
|
|
|
is_dont_delete);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::LOAD_IC_TAG, Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2009-06-30 10:05:36 +00:00
|
|
|
}
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2009-06-30 10:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeKeyedLoadField(String* name,
|
|
|
|
JSObject* receiver,
|
|
|
|
JSObject* holder,
|
|
|
|
int field_index) {
|
2010-07-02 14:15:04 +00:00
|
|
|
ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP);
|
2008-07-03 15:10:15 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, FIELD);
|
2010-08-25 13:25:54 +00:00
|
|
|
Object* code = receiver->map()->FindInCodeCache(name, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (code->IsUndefined()) {
|
|
|
|
KeyedLoadStubCompiler compiler;
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileLoadField(name, receiver, holder, field_index);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeKeyedLoadConstant(String* name,
|
|
|
|
JSObject* receiver,
|
|
|
|
JSObject* holder,
|
|
|
|
Object* value) {
|
2010-07-02 14:15:04 +00:00
|
|
|
ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP);
|
2008-07-03 15:10:15 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, CONSTANT_FUNCTION);
|
2010-08-25 13:25:54 +00:00
|
|
|
Object* code = receiver->map()->FindInCodeCache(name, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (code->IsUndefined()) {
|
|
|
|
KeyedLoadStubCompiler compiler;
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileLoadConstant(name, receiver, holder, value);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeKeyedLoadInterceptor(String* name,
|
|
|
|
JSObject* receiver,
|
|
|
|
JSObject* holder) {
|
2010-07-02 14:15:04 +00:00
|
|
|
ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP);
|
2008-07-03 15:10:15 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, INTERCEPTOR);
|
2010-08-25 13:25:54 +00:00
|
|
|
Object* code = receiver->map()->FindInCodeCache(name, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (code->IsUndefined()) {
|
|
|
|
KeyedLoadStubCompiler compiler;
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileLoadInterceptor(receiver, holder, name);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeKeyedLoadCallback(String* name,
|
|
|
|
JSObject* receiver,
|
|
|
|
JSObject* holder,
|
|
|
|
AccessorInfo* callback) {
|
2010-07-02 14:15:04 +00:00
|
|
|
ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP);
|
2008-07-03 15:10:15 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, CALLBACKS);
|
2010-08-25 13:25:54 +00:00
|
|
|
Object* code = receiver->map()->FindInCodeCache(name, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (code->IsUndefined()) {
|
|
|
|
KeyedLoadStubCompiler compiler;
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileLoadCallback(name, receiver, holder, callback);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeKeyedLoadArrayLength(String* name,
|
|
|
|
JSArray* receiver) {
|
2008-07-03 15:10:15 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, CALLBACKS);
|
2010-07-02 14:15:04 +00:00
|
|
|
ASSERT(receiver->IsJSObject());
|
2010-08-25 13:25:54 +00:00
|
|
|
Object* code = receiver->map()->FindInCodeCache(name, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (code->IsUndefined()) {
|
|
|
|
KeyedLoadStubCompiler compiler;
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code = compiler.CompileLoadArrayLength(name);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeKeyedLoadStringLength(String* name,
|
|
|
|
String* receiver) {
|
2008-07-03 15:10:15 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, CALLBACKS);
|
2010-07-02 14:15:04 +00:00
|
|
|
Map* map = receiver->map();
|
|
|
|
Object* code = map->FindInCodeCache(name, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (code->IsUndefined()) {
|
|
|
|
KeyedLoadStubCompiler compiler;
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code = compiler.CompileLoadStringLength(name);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result = map->UpdateCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeKeyedLoadFunctionPrototype(
|
|
|
|
String* name,
|
|
|
|
JSFunction* receiver) {
|
2008-07-03 15:10:15 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, CALLBACKS);
|
2010-08-25 13:25:54 +00:00
|
|
|
Object* code = receiver->map()->FindInCodeCache(name, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (code->IsUndefined()) {
|
|
|
|
KeyedLoadStubCompiler compiler;
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code = compiler.CompileLoadFunctionPrototype(name);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeStoreField(String* name,
|
|
|
|
JSObject* receiver,
|
|
|
|
int field_index,
|
2011-02-13 16:19:53 +00:00
|
|
|
Map* transition,
|
2011-03-02 04:53:43 +00:00
|
|
|
StrictModeFlag strict_mode) {
|
2008-07-03 15:10:15 +00:00
|
|
|
PropertyType type = (transition == NULL) ? FIELD : MAP_TRANSITION;
|
2011-02-13 16:19:53 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(
|
2011-03-02 04:53:43 +00:00
|
|
|
Code::STORE_IC, type, strict_mode);
|
2008-07-03 15:10:15 +00:00
|
|
|
Object* code = receiver->map()->FindInCodeCache(name, flags);
|
|
|
|
if (code->IsUndefined()) {
|
2011-03-02 04:53:43 +00:00
|
|
|
StoreStubCompiler compiler(strict_mode);
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileStoreField(receiver, field_index, transition, name);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::STORE_IC_TAG, Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::STORE_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-09 15:19:37 +00:00
|
|
|
MaybeObject* StubCache::ComputeKeyedLoadOrStoreElement(
|
2011-05-17 17:29:13 +00:00
|
|
|
JSObject* receiver,
|
|
|
|
bool is_store,
|
|
|
|
StrictModeFlag strict_mode) {
|
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(
|
2011-05-18 13:17:29 +00:00
|
|
|
is_store ? Code::KEYED_STORE_IC :
|
|
|
|
Code::KEYED_LOAD_IC,
|
2011-05-17 17:29:13 +00:00
|
|
|
NORMAL,
|
|
|
|
strict_mode);
|
2011-05-18 13:17:29 +00:00
|
|
|
String* name = is_store
|
2011-06-09 15:19:37 +00:00
|
|
|
? isolate()->heap()->KeyedStoreElementMonomorphic_symbol()
|
|
|
|
: isolate()->heap()->KeyedLoadElementMonomorphic_symbol();
|
2011-05-18 13:17:29 +00:00
|
|
|
Object* maybe_code = receiver->map()->FindInCodeCache(name, flags);
|
|
|
|
if (!maybe_code->IsUndefined()) return Code::cast(maybe_code);
|
|
|
|
|
|
|
|
MaybeObject* maybe_new_code = NULL;
|
2011-06-10 07:49:49 +00:00
|
|
|
Map* receiver_map = receiver->map();
|
2011-05-18 13:17:29 +00:00
|
|
|
if (is_store) {
|
|
|
|
KeyedStoreStubCompiler compiler(strict_mode);
|
2011-06-10 07:49:49 +00:00
|
|
|
maybe_new_code = compiler.CompileStoreElement(receiver_map);
|
2011-05-18 13:17:29 +00:00
|
|
|
} else {
|
|
|
|
KeyedLoadStubCompiler compiler;
|
2011-06-10 07:49:49 +00:00
|
|
|
maybe_new_code = compiler.CompileLoadElement(receiver_map);
|
2011-05-18 13:17:29 +00:00
|
|
|
}
|
|
|
|
Code* code;
|
|
|
|
if (!maybe_new_code->To(&code)) return maybe_new_code;
|
|
|
|
if (is_store) {
|
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::KEYED_STORE_IC_TAG,
|
|
|
|
Code::cast(code), 0));
|
|
|
|
} else {
|
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG,
|
|
|
|
Code::cast(code), 0));
|
|
|
|
}
|
|
|
|
ASSERT(code->IsCode());
|
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
2011-01-21 23:58:00 +00:00
|
|
|
}
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-02 04:53:43 +00:00
|
|
|
MaybeObject* StubCache::ComputeStoreNormal(StrictModeFlag strict_mode) {
|
2011-03-18 20:35:07 +00:00
|
|
|
return isolate_->builtins()->builtin((strict_mode == kStrictMode)
|
2011-03-23 13:40:07 +00:00
|
|
|
? Builtins::kStoreIC_Normal_Strict
|
|
|
|
: Builtins::kStoreIC_Normal);
|
2010-06-30 12:27:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeStoreGlobal(String* name,
|
|
|
|
GlobalObject* receiver,
|
2011-02-13 16:19:53 +00:00
|
|
|
JSGlobalPropertyCell* cell,
|
2011-03-02 04:53:43 +00:00
|
|
|
StrictModeFlag strict_mode) {
|
2011-02-13 16:19:53 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(
|
2011-03-02 04:53:43 +00:00
|
|
|
Code::STORE_IC, NORMAL, strict_mode);
|
2009-06-30 10:05:36 +00:00
|
|
|
Object* code = receiver->map()->FindInCodeCache(name, flags);
|
|
|
|
if (code->IsUndefined()) {
|
2011-03-02 04:53:43 +00:00
|
|
|
StoreStubCompiler compiler(strict_mode);
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileStoreGlobal(receiver, cell, name);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::STORE_IC_TAG, Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::STORE_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2009-06-30 10:05:36 +00:00
|
|
|
}
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2009-06-30 10:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-13 16:19:53 +00:00
|
|
|
MaybeObject* StubCache::ComputeStoreCallback(
|
|
|
|
String* name,
|
|
|
|
JSObject* receiver,
|
|
|
|
AccessorInfo* callback,
|
2011-03-02 04:53:43 +00:00
|
|
|
StrictModeFlag strict_mode) {
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(v8::ToCData<Address>(callback->setter()) != 0);
|
2011-02-13 16:19:53 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(
|
2011-03-02 04:53:43 +00:00
|
|
|
Code::STORE_IC, CALLBACKS, strict_mode);
|
2008-07-03 15:10:15 +00:00
|
|
|
Object* code = receiver->map()->FindInCodeCache(name, flags);
|
|
|
|
if (code->IsUndefined()) {
|
2011-03-02 04:53:43 +00:00
|
|
|
StoreStubCompiler compiler(strict_mode);
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileStoreCallback(receiver, callback, name);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::STORE_IC_TAG, Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::STORE_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-13 16:19:53 +00:00
|
|
|
MaybeObject* StubCache::ComputeStoreInterceptor(
|
|
|
|
String* name,
|
|
|
|
JSObject* receiver,
|
2011-03-02 04:53:43 +00:00
|
|
|
StrictModeFlag strict_mode) {
|
2011-02-13 16:19:53 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(
|
2011-03-02 04:53:43 +00:00
|
|
|
Code::STORE_IC, INTERCEPTOR, strict_mode);
|
2008-07-03 15:10:15 +00:00
|
|
|
Object* code = receiver->map()->FindInCodeCache(name, flags);
|
|
|
|
if (code->IsUndefined()) {
|
2011-03-02 04:53:43 +00:00
|
|
|
StoreStubCompiler compiler(strict_mode);
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileStoreInterceptor(receiver, name);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(Logger::STORE_IC_TAG, Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::STORE_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeKeyedStoreField(String* name,
|
|
|
|
JSObject* receiver,
|
|
|
|
int field_index,
|
2011-03-02 04:53:43 +00:00
|
|
|
Map* transition,
|
|
|
|
StrictModeFlag strict_mode) {
|
2008-07-03 15:10:15 +00:00
|
|
|
PropertyType type = (transition == NULL) ? FIELD : MAP_TRANSITION;
|
2011-03-02 04:53:43 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(
|
|
|
|
Code::KEYED_STORE_IC, type, strict_mode);
|
2008-07-03 15:10:15 +00:00
|
|
|
Object* code = receiver->map()->FindInCodeCache(name, flags);
|
|
|
|
if (code->IsUndefined()) {
|
2011-03-02 04:53:43 +00:00
|
|
|
KeyedStoreStubCompiler compiler(strict_mode);
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileStoreField(receiver, field_index, transition, name);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2011-03-30 08:18:56 +00:00
|
|
|
PROFILE(isolate(),
|
2011-03-18 20:35:07 +00:00
|
|
|
CodeCreateEvent(Logger::KEYED_STORE_IC_TAG,
|
|
|
|
Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_STORE_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
receiver->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2010-06-07 08:27:32 +00:00
|
|
|
#define CALL_LOGGER_TAG(kind, type) \
|
|
|
|
(kind == Code::CALL_IC ? Logger::type : Logger::KEYED_##type)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeCallConstant(int argc,
|
|
|
|
InLoopFlag in_loop,
|
|
|
|
Code::Kind kind,
|
2011-01-18 16:54:48 +00:00
|
|
|
Code::ExtraICState extra_ic_state,
|
2010-10-25 15:22:03 +00:00
|
|
|
String* name,
|
|
|
|
Object* object,
|
|
|
|
JSObject* holder,
|
|
|
|
JSFunction* function) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Compute the check type and the map.
|
2010-07-02 14:15:04 +00:00
|
|
|
InlineCacheHolderFlag cache_holder =
|
|
|
|
IC::GetCodeCacheForObject(object, holder);
|
2010-08-25 13:25:54 +00:00
|
|
|
JSObject* map_holder = IC::GetCodeCacheHolder(object, cache_holder);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Compute check type based on receiver/holder.
|
2010-12-07 11:31:57 +00:00
|
|
|
CheckType check = RECEIVER_MAP_CHECK;
|
2008-07-03 15:10:15 +00:00
|
|
|
if (object->IsString()) {
|
2010-12-07 11:31:57 +00:00
|
|
|
check = STRING_CHECK;
|
2008-07-03 15:10:15 +00:00
|
|
|
} else if (object->IsNumber()) {
|
2010-12-07 11:31:57 +00:00
|
|
|
check = NUMBER_CHECK;
|
2008-07-03 15:10:15 +00:00
|
|
|
} else if (object->IsBoolean()) {
|
2010-12-07 11:31:57 +00:00
|
|
|
check = BOOLEAN_CHECK;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2011-01-18 16:54:48 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(kind,
|
|
|
|
CONSTANT_FUNCTION,
|
|
|
|
extra_ic_state,
|
|
|
|
cache_holder,
|
|
|
|
in_loop,
|
|
|
|
argc);
|
2010-08-25 13:25:54 +00:00
|
|
|
Object* code = map_holder->map()->FindInCodeCache(name, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (code->IsUndefined()) {
|
|
|
|
// If the function hasn't been compiled yet, we cannot do it now
|
|
|
|
// because it may cause GC. To avoid this issue, we return an
|
|
|
|
// internal error which will make sure we do not update any
|
|
|
|
// caches.
|
|
|
|
if (!function->is_compiled()) return Failure::InternalError();
|
|
|
|
// Compile the stub - only create stubs for fully compiled functions.
|
2011-01-18 16:54:48 +00:00
|
|
|
CallStubCompiler compiler(
|
|
|
|
argc, in_loop, kind, extra_ic_state, cache_holder);
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileCallConstant(object, holder, function, name, check);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
Code::cast(code)->set_check_type(check);
|
2009-06-30 14:07:29 +00:00
|
|
|
ASSERT_EQ(flags, Code::cast(code)->flags());
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_IC_TAG),
|
2010-06-07 08:27:32 +00:00
|
|
|
Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
map_holder->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeCallField(int argc,
|
|
|
|
InLoopFlag in_loop,
|
|
|
|
Code::Kind kind,
|
2011-05-24 14:01:36 +00:00
|
|
|
Code::ExtraICState extra_ic_state,
|
2010-10-25 15:22:03 +00:00
|
|
|
String* name,
|
|
|
|
Object* object,
|
|
|
|
JSObject* holder,
|
|
|
|
int index) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Compute the check type and the map.
|
2010-07-02 14:15:04 +00:00
|
|
|
InlineCacheHolderFlag cache_holder =
|
|
|
|
IC::GetCodeCacheForObject(object, holder);
|
2010-08-25 13:25:54 +00:00
|
|
|
JSObject* map_holder = IC::GetCodeCacheHolder(object, cache_holder);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// TODO(1233596): We cannot do receiver map check for non-JS objects
|
|
|
|
// because they may be represented as immediates without a
|
|
|
|
// map. Instead, we check against the map in the holder.
|
|
|
|
if (object->IsNumber() || object->IsBoolean() || object->IsString()) {
|
|
|
|
object = holder;
|
|
|
|
}
|
|
|
|
|
2010-06-07 08:27:32 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(kind,
|
2009-05-25 18:29:02 +00:00
|
|
|
FIELD,
|
2011-05-24 14:01:36 +00:00
|
|
|
extra_ic_state,
|
2010-07-02 14:15:04 +00:00
|
|
|
cache_holder,
|
2009-05-25 18:29:02 +00:00
|
|
|
in_loop,
|
|
|
|
argc);
|
2010-08-25 13:25:54 +00:00
|
|
|
Object* code = map_holder->map()->FindInCodeCache(name, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (code->IsUndefined()) {
|
2011-01-18 16:54:48 +00:00
|
|
|
CallStubCompiler compiler(
|
2011-05-24 14:01:36 +00:00
|
|
|
argc, in_loop, kind, extra_ic_state, cache_holder);
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileCallField(JSObject::cast(object),
|
|
|
|
holder,
|
|
|
|
index,
|
|
|
|
name);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2009-06-30 14:07:29 +00:00
|
|
|
ASSERT_EQ(flags, Code::cast(code)->flags());
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_IC_TAG),
|
2010-06-07 08:27:32 +00:00
|
|
|
Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
map_holder->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 14:01:36 +00:00
|
|
|
MaybeObject* StubCache::ComputeCallInterceptor(
|
|
|
|
int argc,
|
|
|
|
Code::Kind kind,
|
|
|
|
Code::ExtraICState extra_ic_state,
|
|
|
|
String* name,
|
|
|
|
Object* object,
|
|
|
|
JSObject* holder) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Compute the check type and the map.
|
2010-07-02 14:15:04 +00:00
|
|
|
InlineCacheHolderFlag cache_holder =
|
|
|
|
IC::GetCodeCacheForObject(object, holder);
|
2010-08-25 13:25:54 +00:00
|
|
|
JSObject* map_holder = IC::GetCodeCacheHolder(object, cache_holder);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// TODO(1233596): We cannot do receiver map check for non-JS objects
|
|
|
|
// because they may be represented as immediates without a
|
|
|
|
// map. Instead, we check against the map in the holder.
|
|
|
|
if (object->IsNumber() || object->IsBoolean() || object->IsString()) {
|
|
|
|
object = holder;
|
|
|
|
}
|
|
|
|
|
2011-01-18 16:54:48 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(kind,
|
|
|
|
INTERCEPTOR,
|
2011-05-24 14:01:36 +00:00
|
|
|
extra_ic_state,
|
2011-01-18 16:54:48 +00:00
|
|
|
cache_holder,
|
|
|
|
NOT_IN_LOOP,
|
|
|
|
argc);
|
2010-08-25 13:25:54 +00:00
|
|
|
Object* code = map_holder->map()->FindInCodeCache(name, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (code->IsUndefined()) {
|
2011-01-18 16:54:48 +00:00
|
|
|
CallStubCompiler compiler(
|
2011-05-24 14:01:36 +00:00
|
|
|
argc, NOT_IN_LOOP, kind, extra_ic_state, cache_holder);
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
compiler.CompileCallInterceptor(JSObject::cast(object), holder, name);
|
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2009-06-30 14:07:29 +00:00
|
|
|
ASSERT_EQ(flags, Code::cast(code)->flags());
|
2011-03-30 08:18:56 +00:00
|
|
|
PROFILE(isolate(),
|
2011-03-18 20:35:07 +00:00
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_IC_TAG),
|
2010-06-07 08:27:32 +00:00
|
|
|
Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
map_holder->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeCallNormal(int argc,
|
|
|
|
InLoopFlag in_loop,
|
|
|
|
Code::Kind kind,
|
2011-05-24 14:01:36 +00:00
|
|
|
Code::ExtraICState extra_ic_state,
|
2010-10-25 15:22:03 +00:00
|
|
|
String* name,
|
|
|
|
JSObject* receiver) {
|
|
|
|
Object* code;
|
2011-05-24 14:01:36 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
|
|
|
ComputeCallNormal(argc, in_loop, kind, extra_ic_state);
|
2010-10-25 15:22:03 +00:00
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeCallGlobal(int argc,
|
|
|
|
InLoopFlag in_loop,
|
|
|
|
Code::Kind kind,
|
2011-05-24 14:01:36 +00:00
|
|
|
Code::ExtraICState extra_ic_state,
|
2010-10-25 15:22:03 +00:00
|
|
|
String* name,
|
|
|
|
JSObject* receiver,
|
|
|
|
GlobalObject* holder,
|
|
|
|
JSGlobalPropertyCell* cell,
|
|
|
|
JSFunction* function) {
|
2010-07-02 14:15:04 +00:00
|
|
|
InlineCacheHolderFlag cache_holder =
|
|
|
|
IC::GetCodeCacheForObject(receiver, holder);
|
2010-08-25 13:25:54 +00:00
|
|
|
JSObject* map_holder = IC::GetCodeCacheHolder(receiver, cache_holder);
|
2011-01-18 16:54:48 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(kind,
|
|
|
|
NORMAL,
|
2011-05-24 14:01:36 +00:00
|
|
|
extra_ic_state,
|
2011-01-18 16:54:48 +00:00
|
|
|
cache_holder,
|
|
|
|
in_loop,
|
|
|
|
argc);
|
2010-08-25 13:25:54 +00:00
|
|
|
Object* code = map_holder->map()->FindInCodeCache(name, flags);
|
2009-06-30 10:05:36 +00:00
|
|
|
if (code->IsUndefined()) {
|
|
|
|
// If the function hasn't been compiled yet, we cannot do it now
|
|
|
|
// because it may cause GC. To avoid this issue, we return an
|
|
|
|
// internal error which will make sure we do not update any
|
|
|
|
// caches.
|
|
|
|
if (!function->is_compiled()) return Failure::InternalError();
|
2011-01-18 16:54:48 +00:00
|
|
|
CallStubCompiler compiler(
|
2011-05-24 14:01:36 +00:00
|
|
|
argc, in_loop, kind, extra_ic_state, cache_holder);
|
2010-10-25 15:22:03 +00:00
|
|
|
{ MaybeObject* maybe_code =
|
2011-05-30 13:23:17 +00:00
|
|
|
compiler.CompileCallGlobal(receiver, holder, cell, function, name);
|
2010-10-25 15:22:03 +00:00
|
|
|
if (!maybe_code->ToObject(&code)) return maybe_code;
|
|
|
|
}
|
2009-06-30 14:07:29 +00:00
|
|
|
ASSERT_EQ(flags, Code::cast(code)->flags());
|
2011-03-30 08:18:56 +00:00
|
|
|
PROFILE(isolate(),
|
2011-03-18 20:35:07 +00:00
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_IC_TAG),
|
2010-06-07 08:27:32 +00:00
|
|
|
Code::cast(code), name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_IC, name, Code::cast(code)));
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
map_holder->UpdateMapCodeCache(name, Code::cast(code));
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2009-06-30 10:05:36 +00:00
|
|
|
}
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2009-06-30 10:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
static Object* GetProbeValue(Isolate* isolate, Code::Flags flags) {
|
2009-07-08 19:12:58 +00:00
|
|
|
// Use raw_unchecked... so we don't get assert failures during GC.
|
2011-03-18 20:35:07 +00:00
|
|
|
NumberDictionary* dictionary =
|
|
|
|
isolate->heap()->raw_unchecked_non_monomorphic_cache();
|
|
|
|
int entry = dictionary->FindEntry(isolate, flags);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (entry != -1) return dictionary->ValueAt(entry);
|
2011-03-18 20:35:07 +00:00
|
|
|
return isolate->heap()->raw_unchecked_undefined_value();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
MUST_USE_RESULT static MaybeObject* ProbeCache(Isolate* isolate,
|
|
|
|
Code::Flags flags) {
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
Object* probe = GetProbeValue(isolate, flags);
|
|
|
|
if (probe != heap->undefined_value()) return probe;
|
2008-07-03 15:10:15 +00:00
|
|
|
// Seed the cache with an undefined value to make sure that any
|
|
|
|
// generated code object can always be inserted into the cache
|
|
|
|
// without causing allocation failures.
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
2011-03-18 20:35:07 +00:00
|
|
|
heap->non_monomorphic_cache()->AtNumberPut(flags,
|
|
|
|
heap->undefined_value());
|
2010-10-25 15:22:03 +00:00
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
heap->public_set_non_monomorphic_cache(NumberDictionary::cast(result));
|
2008-07-03 15:10:15 +00:00
|
|
|
return probe;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
static MaybeObject* FillCache(Isolate* isolate, MaybeObject* maybe_code) {
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* code;
|
|
|
|
if (maybe_code->ToObject(&code)) {
|
|
|
|
if (code->IsCode()) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
int entry = heap->non_monomorphic_cache()->FindEntry(
|
|
|
|
Code::cast(code)->flags());
|
2010-10-25 15:22:03 +00:00
|
|
|
// The entry must be present see comment in ProbeCache.
|
|
|
|
ASSERT(entry != -1);
|
2011-03-18 20:35:07 +00:00
|
|
|
ASSERT(heap->non_monomorphic_cache()->ValueAt(entry) ==
|
|
|
|
heap->undefined_value());
|
|
|
|
heap->non_monomorphic_cache()->ValueAtPut(entry, code);
|
|
|
|
CHECK(GetProbeValue(isolate, Code::cast(code)->flags()) == code);
|
2010-10-25 15:22:03 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-10-25 15:22:03 +00:00
|
|
|
return maybe_code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-07 08:27:32 +00:00
|
|
|
Code* StubCache::FindCallInitialize(int argc,
|
|
|
|
InLoopFlag in_loop,
|
2011-05-24 14:01:36 +00:00
|
|
|
RelocInfo::Mode mode,
|
2010-06-07 08:27:32 +00:00
|
|
|
Code::Kind kind) {
|
2011-05-24 14:01:36 +00:00
|
|
|
Code::ExtraICState extra_state =
|
|
|
|
CallICBase::StringStubState::encode(DEFAULT_STRING_STUB) |
|
|
|
|
CallICBase::Contextual::encode(mode == RelocInfo::CODE_TARGET_CONTEXT);
|
2011-01-18 16:54:48 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(kind,
|
|
|
|
in_loop,
|
|
|
|
UNINITIALIZED,
|
2011-05-24 14:01:36 +00:00
|
|
|
extra_state,
|
2011-01-18 16:54:48 +00:00
|
|
|
NORMAL,
|
|
|
|
argc);
|
2011-03-30 08:18:56 +00:00
|
|
|
Object* result = ProbeCache(isolate(), flags)->ToObjectUnchecked();
|
|
|
|
ASSERT(result != heap()->undefined_value());
|
2008-07-03 15:10:15 +00:00
|
|
|
// This might be called during the marking phase of the collector
|
|
|
|
// hence the unchecked cast.
|
|
|
|
return reinterpret_cast<Code*>(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeCallInitialize(int argc,
|
|
|
|
InLoopFlag in_loop,
|
2011-05-24 14:01:36 +00:00
|
|
|
RelocInfo::Mode mode,
|
2010-10-25 15:22:03 +00:00
|
|
|
Code::Kind kind) {
|
2011-05-24 14:01:36 +00:00
|
|
|
Code::ExtraICState extra_state =
|
|
|
|
CallICBase::StringStubState::encode(DEFAULT_STRING_STUB) |
|
|
|
|
CallICBase::Contextual::encode(mode == RelocInfo::CODE_TARGET_CONTEXT);
|
2011-01-18 16:54:48 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(kind,
|
|
|
|
in_loop,
|
|
|
|
UNINITIALIZED,
|
2011-05-24 14:01:36 +00:00
|
|
|
extra_state,
|
2011-01-18 16:54:48 +00:00
|
|
|
NORMAL,
|
|
|
|
argc);
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* probe;
|
2011-03-18 20:35:07 +00:00
|
|
|
{ MaybeObject* maybe_probe = ProbeCache(isolate_, flags);
|
2010-10-25 15:22:03 +00:00
|
|
|
if (!maybe_probe->ToObject(&probe)) return maybe_probe;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
if (!probe->IsUndefined()) return probe;
|
|
|
|
StubCompiler compiler;
|
2011-03-18 20:35:07 +00:00
|
|
|
return FillCache(isolate_, compiler.CompileCallInitialize(flags));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 14:01:36 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallInitialize(int argc,
|
|
|
|
InLoopFlag in_loop,
|
|
|
|
RelocInfo::Mode mode) {
|
2010-11-11 10:33:51 +00:00
|
|
|
if (in_loop == IN_LOOP) {
|
|
|
|
// Force the creation of the corresponding stub outside loops,
|
|
|
|
// because it may be used when clearing the ICs later - it is
|
|
|
|
// possible for a series of IC transitions to lose the in-loop
|
|
|
|
// information, and the IC clearing code can't generate a stub
|
|
|
|
// that it needs so we need to ensure it is generated already.
|
2011-05-24 14:01:36 +00:00
|
|
|
ComputeCallInitialize(argc, NOT_IN_LOOP, mode);
|
2010-11-11 10:33:51 +00:00
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate_,
|
2011-05-24 14:01:36 +00:00
|
|
|
ComputeCallInitialize(argc, in_loop, mode, Code::CALL_IC),
|
|
|
|
Code);
|
2010-11-11 10:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> StubCache::ComputeKeyedCallInitialize(int argc,
|
|
|
|
InLoopFlag in_loop) {
|
|
|
|
if (in_loop == IN_LOOP) {
|
|
|
|
// Force the creation of the corresponding stub outside loops,
|
|
|
|
// because it may be used when clearing the ICs later - it is
|
|
|
|
// possible for a series of IC transitions to lose the in-loop
|
|
|
|
// information, and the IC clearing code can't generate a stub
|
|
|
|
// that it needs so we need to ensure it is generated already.
|
|
|
|
ComputeKeyedCallInitialize(argc, NOT_IN_LOOP);
|
|
|
|
}
|
|
|
|
CALL_HEAP_FUNCTION(
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate_,
|
2011-05-24 14:01:36 +00:00
|
|
|
ComputeCallInitialize(argc,
|
|
|
|
in_loop,
|
|
|
|
RelocInfo::CODE_TARGET,
|
|
|
|
Code::KEYED_CALL_IC),
|
|
|
|
Code);
|
2010-11-11 10:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 14:01:36 +00:00
|
|
|
MaybeObject* StubCache::ComputeCallPreMonomorphic(
|
|
|
|
int argc,
|
|
|
|
InLoopFlag in_loop,
|
|
|
|
Code::Kind kind,
|
|
|
|
Code::ExtraICState extra_ic_state) {
|
2011-01-18 16:54:48 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(kind,
|
|
|
|
in_loop,
|
|
|
|
PREMONOMORPHIC,
|
2011-05-24 14:01:36 +00:00
|
|
|
extra_ic_state,
|
2011-01-18 16:54:48 +00:00
|
|
|
NORMAL,
|
|
|
|
argc);
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* probe;
|
2011-03-18 20:35:07 +00:00
|
|
|
{ MaybeObject* maybe_probe = ProbeCache(isolate_, flags);
|
2010-10-25 15:22:03 +00:00
|
|
|
if (!maybe_probe->ToObject(&probe)) return maybe_probe;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
if (!probe->IsUndefined()) return probe;
|
|
|
|
StubCompiler compiler;
|
2011-03-18 20:35:07 +00:00
|
|
|
return FillCache(isolate_, compiler.CompileCallPreMonomorphic(flags));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCache::ComputeCallNormal(int argc,
|
|
|
|
InLoopFlag in_loop,
|
2011-05-24 14:01:36 +00:00
|
|
|
Code::Kind kind,
|
|
|
|
Code::ExtraICState extra_ic_state) {
|
2011-01-18 16:54:48 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(kind,
|
|
|
|
in_loop,
|
|
|
|
MONOMORPHIC,
|
2011-05-24 14:01:36 +00:00
|
|
|
extra_ic_state,
|
2011-01-18 16:54:48 +00:00
|
|
|
NORMAL,
|
|
|
|
argc);
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* probe;
|
2011-03-18 20:35:07 +00:00
|
|
|
{ MaybeObject* maybe_probe = ProbeCache(isolate_, flags);
|
2010-10-25 15:22:03 +00:00
|
|
|
if (!maybe_probe->ToObject(&probe)) return maybe_probe;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
if (!probe->IsUndefined()) return probe;
|
|
|
|
StubCompiler compiler;
|
2011-03-18 20:35:07 +00:00
|
|
|
return FillCache(isolate_, compiler.CompileCallNormal(flags));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-16 14:12:58 +00:00
|
|
|
MaybeObject* StubCache::ComputeCallArguments(int argc,
|
|
|
|
InLoopFlag in_loop,
|
|
|
|
Code::Kind kind) {
|
|
|
|
ASSERT(kind == Code::KEYED_CALL_IC);
|
|
|
|
Code::Flags flags = Code::ComputeFlags(kind,
|
|
|
|
in_loop,
|
|
|
|
MEGAMORPHIC,
|
|
|
|
Code::kNoExtraICState,
|
|
|
|
NORMAL,
|
|
|
|
argc);
|
|
|
|
Object* probe;
|
|
|
|
{ MaybeObject* maybe_probe = ProbeCache(isolate_, flags);
|
|
|
|
if (!maybe_probe->ToObject(&probe)) return maybe_probe;
|
|
|
|
}
|
|
|
|
if (!probe->IsUndefined()) return probe;
|
|
|
|
StubCompiler compiler;
|
|
|
|
return FillCache(isolate_, compiler.CompileCallArguments(flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 14:01:36 +00:00
|
|
|
MaybeObject* StubCache::ComputeCallMegamorphic(
|
|
|
|
int argc,
|
|
|
|
InLoopFlag in_loop,
|
|
|
|
Code::Kind kind,
|
|
|
|
Code::ExtraICState extra_ic_state) {
|
2011-01-18 16:54:48 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(kind,
|
|
|
|
in_loop,
|
|
|
|
MEGAMORPHIC,
|
2011-05-24 14:01:36 +00:00
|
|
|
extra_ic_state,
|
2011-01-18 16:54:48 +00:00
|
|
|
NORMAL,
|
|
|
|
argc);
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* probe;
|
2011-03-18 20:35:07 +00:00
|
|
|
{ MaybeObject* maybe_probe = ProbeCache(isolate_, flags);
|
2010-10-25 15:22:03 +00:00
|
|
|
if (!maybe_probe->ToObject(&probe)) return maybe_probe;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
if (!probe->IsUndefined()) return probe;
|
|
|
|
StubCompiler compiler;
|
2011-03-18 20:35:07 +00:00
|
|
|
return FillCache(isolate_, compiler.CompileCallMegamorphic(flags));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 14:01:36 +00:00
|
|
|
MaybeObject* StubCache::ComputeCallMiss(int argc,
|
|
|
|
Code::Kind kind,
|
|
|
|
Code::ExtraICState extra_ic_state) {
|
2010-06-07 08:27:32 +00:00
|
|
|
// MONOMORPHIC_PROTOTYPE_FAILURE state is used to make sure that miss stubs
|
|
|
|
// and monomorphic stubs are not mixed up together in the stub cache.
|
2011-01-18 16:54:48 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(kind,
|
|
|
|
NOT_IN_LOOP,
|
|
|
|
MONOMORPHIC_PROTOTYPE_FAILURE,
|
2011-05-24 14:01:36 +00:00
|
|
|
extra_ic_state,
|
2011-01-18 16:54:48 +00:00
|
|
|
NORMAL,
|
|
|
|
argc,
|
|
|
|
OWN_MAP);
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* probe;
|
2011-03-18 20:35:07 +00:00
|
|
|
{ MaybeObject* maybe_probe = ProbeCache(isolate_, flags);
|
2010-10-25 15:22:03 +00:00
|
|
|
if (!maybe_probe->ToObject(&probe)) return maybe_probe;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
if (!probe->IsUndefined()) return probe;
|
|
|
|
StubCompiler compiler;
|
2011-03-18 20:35:07 +00:00
|
|
|
return FillCache(isolate_, compiler.CompileCallMiss(flags));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2011-05-24 14:01:36 +00:00
|
|
|
MaybeObject* StubCache::ComputeCallDebugBreak(
|
|
|
|
int argc,
|
|
|
|
Code::Kind kind) {
|
|
|
|
// Extra IC state is irrelevant for debug break ICs. They jump to
|
|
|
|
// the actual call ic to carry out the work.
|
2011-01-18 16:54:48 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(kind,
|
|
|
|
NOT_IN_LOOP,
|
|
|
|
DEBUG_BREAK,
|
|
|
|
Code::kNoExtraICState,
|
|
|
|
NORMAL,
|
|
|
|
argc);
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* probe;
|
2011-03-18 20:35:07 +00:00
|
|
|
{ MaybeObject* maybe_probe = ProbeCache(isolate_, flags);
|
2010-10-25 15:22:03 +00:00
|
|
|
if (!maybe_probe->ToObject(&probe)) return maybe_probe;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
if (!probe->IsUndefined()) return probe;
|
|
|
|
StubCompiler compiler;
|
2011-03-18 20:35:07 +00:00
|
|
|
return FillCache(isolate_, compiler.CompileCallDebugBreak(flags));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 14:01:36 +00:00
|
|
|
MaybeObject* StubCache::ComputeCallDebugPrepareStepIn(
|
|
|
|
int argc,
|
|
|
|
Code::Kind kind) {
|
|
|
|
// Extra IC state is irrelevant for debug break ICs. They jump to
|
|
|
|
// the actual call ic to carry out the work.
|
2011-01-18 16:54:48 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(kind,
|
|
|
|
NOT_IN_LOOP,
|
|
|
|
DEBUG_PREPARE_STEP_IN,
|
|
|
|
Code::kNoExtraICState,
|
|
|
|
NORMAL,
|
|
|
|
argc);
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* probe;
|
2011-03-18 20:35:07 +00:00
|
|
|
{ MaybeObject* maybe_probe = ProbeCache(isolate_, flags);
|
2010-10-25 15:22:03 +00:00
|
|
|
if (!maybe_probe->ToObject(&probe)) return maybe_probe;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
if (!probe->IsUndefined()) return probe;
|
|
|
|
StubCompiler compiler;
|
2011-03-18 20:35:07 +00:00
|
|
|
return FillCache(isolate_, compiler.CompileCallDebugPrepareStepIn(flags));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-04-20 16:36:13 +00:00
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
void StubCache::Clear() {
|
|
|
|
for (int i = 0; i < kPrimaryTableSize; i++) {
|
2011-03-30 08:18:56 +00:00
|
|
|
primary_[i].key = heap()->empty_string();
|
2011-03-18 20:35:07 +00:00
|
|
|
primary_[i].value = isolate_->builtins()->builtin(
|
2011-03-23 13:40:07 +00:00
|
|
|
Builtins::kIllegal);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
for (int j = 0; j < kSecondaryTableSize; j++) {
|
2011-03-30 08:18:56 +00:00
|
|
|
secondary_[j].key = heap()->empty_string();
|
2011-03-18 20:35:07 +00:00
|
|
|
secondary_[j].value = isolate_->builtins()->builtin(
|
2011-03-23 13:40:07 +00:00
|
|
|
Builtins::kIllegal);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-22 14:23:37 +00:00
|
|
|
void StubCache::CollectMatchingMaps(SmallMapList* types,
|
2010-12-07 11:31:57 +00:00
|
|
|
String* name,
|
|
|
|
Code::Flags flags) {
|
|
|
|
for (int i = 0; i < kPrimaryTableSize; i++) {
|
|
|
|
if (primary_[i].key == name) {
|
|
|
|
Map* map = primary_[i].value->FindFirstMap();
|
|
|
|
// Map can be NULL, if the stub is constant function call
|
|
|
|
// with a primitive receiver.
|
|
|
|
if (map == NULL) continue;
|
|
|
|
|
|
|
|
int offset = PrimaryOffset(name, flags, map);
|
|
|
|
if (entry(primary_, offset) == &primary_[i]) {
|
|
|
|
types->Add(Handle<Map>(map));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < kSecondaryTableSize; i++) {
|
|
|
|
if (secondary_[i].key == name) {
|
|
|
|
Map* map = secondary_[i].value->FindFirstMap();
|
|
|
|
// Map can be NULL, if the stub is constant function call
|
|
|
|
// with a primitive receiver.
|
|
|
|
if (map == NULL) continue;
|
|
|
|
|
|
|
|
// Lookup in primary table and skip duplicates.
|
|
|
|
int primary_offset = PrimaryOffset(name, flags, map);
|
|
|
|
Entry* primary_entry = entry(primary_, primary_offset);
|
|
|
|
if (primary_entry->key == name) {
|
|
|
|
Map* primary_map = primary_entry->value->FindFirstMap();
|
|
|
|
if (map == primary_map) continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lookup in secondary table and add matches.
|
|
|
|
int offset = SecondaryOffset(name, flags, primary_offset);
|
|
|
|
if (entry(secondary_, offset) == &secondary_[i]) {
|
|
|
|
types->Add(Handle<Map>(map));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// StubCompiler implementation.
|
|
|
|
|
|
|
|
|
2011-03-30 14:17:39 +00:00
|
|
|
RUNTIME_FUNCTION(MaybeObject*, LoadCallbackProperty) {
|
2009-11-04 08:51:48 +00:00
|
|
|
ASSERT(args[0]->IsJSObject());
|
|
|
|
ASSERT(args[1]->IsJSObject());
|
2010-11-19 09:06:00 +00:00
|
|
|
AccessorInfo* callback = AccessorInfo::cast(args[3]);
|
2009-03-18 18:50:35 +00:00
|
|
|
Address getter_address = v8::ToCData<Address>(callback->getter());
|
|
|
|
v8::AccessorGetter fun = FUNCTION_CAST<v8::AccessorGetter>(getter_address);
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(fun != NULL);
|
2010-11-19 09:06:00 +00:00
|
|
|
v8::AccessorInfo info(&args[0]);
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
v8::Handle<v8::Value> result;
|
|
|
|
{
|
|
|
|
// Leaving JavaScript.
|
2011-03-18 20:35:07 +00:00
|
|
|
VMState state(isolate, EXTERNAL);
|
|
|
|
ExternalCallbackScope call_scope(isolate, getter_address);
|
2009-09-30 12:25:46 +00:00
|
|
|
result = fun(v8::Utils::ToLocal(args.at<String>(4)), info);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
RETURN_IF_SCHEDULED_EXCEPTION(isolate);
|
|
|
|
if (result.IsEmpty()) return HEAP->undefined_value();
|
2009-03-18 18:50:35 +00:00
|
|
|
return *v8::Utils::OpenHandle(*result);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-30 14:17:39 +00:00
|
|
|
RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty) {
|
2009-09-30 12:25:46 +00:00
|
|
|
JSObject* recv = JSObject::cast(args[0]);
|
2008-07-03 15:10:15 +00:00
|
|
|
AccessorInfo* callback = AccessorInfo::cast(args[1]);
|
2009-03-18 18:50:35 +00:00
|
|
|
Address setter_address = v8::ToCData<Address>(callback->setter());
|
|
|
|
v8::AccessorSetter fun = FUNCTION_CAST<v8::AccessorSetter>(setter_address);
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(fun != NULL);
|
|
|
|
Handle<String> name = args.at<String>(2);
|
|
|
|
Handle<Object> value = args.at<Object>(3);
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate);
|
|
|
|
LOG(isolate, ApiNamedPropertyAccess("store", recv, *name));
|
|
|
|
CustomArguments custom_args(isolate, callback->data(), recv, recv);
|
2009-09-30 12:25:46 +00:00
|
|
|
v8::AccessorInfo info(custom_args.end());
|
2008-07-03 15:10:15 +00:00
|
|
|
{
|
|
|
|
// Leaving JavaScript.
|
2011-03-18 20:35:07 +00:00
|
|
|
VMState state(isolate, EXTERNAL);
|
|
|
|
ExternalCallbackScope call_scope(isolate, setter_address);
|
2008-07-03 15:10:15 +00:00
|
|
|
fun(v8::Utils::ToLocal(name), v8::Utils::ToLocal(value), info);
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
RETURN_IF_SCHEDULED_EXCEPTION(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
return *value;
|
|
|
|
}
|
|
|
|
|
2010-03-25 17:08:22 +00:00
|
|
|
|
|
|
|
static const int kAccessorInfoOffsetInInterceptorArgs = 2;
|
|
|
|
|
|
|
|
|
2009-07-29 12:34:21 +00:00
|
|
|
/**
|
|
|
|
* Attempts to load a property with an interceptor (which must be present),
|
|
|
|
* but doesn't search the prototype chain.
|
|
|
|
*
|
|
|
|
* Returns |Heap::no_interceptor_result_sentinel()| if interceptor doesn't
|
|
|
|
* provide any value for the given name.
|
|
|
|
*/
|
2011-03-30 14:17:39 +00:00
|
|
|
RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly) {
|
2010-03-25 17:08:22 +00:00
|
|
|
Handle<String> name_handle = args.at<String>(0);
|
|
|
|
Handle<InterceptorInfo> interceptor_info = args.at<InterceptorInfo>(1);
|
|
|
|
ASSERT(kAccessorInfoOffsetInInterceptorArgs == 2);
|
|
|
|
ASSERT(args[2]->IsJSObject()); // Receiver.
|
|
|
|
ASSERT(args[3]->IsJSObject()); // Holder.
|
|
|
|
ASSERT(args.length() == 5); // Last arg is data object.
|
2009-03-18 18:50:35 +00:00
|
|
|
|
2009-07-28 14:46:06 +00:00
|
|
|
Address getter_address = v8::ToCData<Address>(interceptor_info->getter());
|
|
|
|
v8::NamedPropertyGetter getter =
|
|
|
|
FUNCTION_CAST<v8::NamedPropertyGetter>(getter_address);
|
|
|
|
ASSERT(getter != NULL);
|
|
|
|
|
|
|
|
{
|
|
|
|
// Use the interceptor getter.
|
2010-03-25 17:08:22 +00:00
|
|
|
v8::AccessorInfo info(args.arguments() -
|
|
|
|
kAccessorInfoOffsetInInterceptorArgs);
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate);
|
2009-07-28 14:46:06 +00:00
|
|
|
v8::Handle<v8::Value> r;
|
|
|
|
{
|
|
|
|
// Leaving JavaScript.
|
2011-03-18 20:35:07 +00:00
|
|
|
VMState state(isolate, EXTERNAL);
|
2009-07-28 14:46:06 +00:00
|
|
|
r = getter(v8::Utils::ToLocal(name_handle), info);
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
RETURN_IF_SCHEDULED_EXCEPTION(isolate);
|
2009-07-28 14:46:06 +00:00
|
|
|
if (!r.IsEmpty()) {
|
|
|
|
return *v8::Utils::OpenHandle(*r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
return isolate->heap()->no_interceptor_result_sentinel();
|
2009-07-29 12:34:21 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
static MaybeObject* ThrowReferenceError(String* name) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// If the load is non-contextual, just return the undefined result.
|
|
|
|
// Note that both keyed and non-keyed loads may end up here, so we
|
|
|
|
// can't use either LoadIC or KeyedLoadIC constructors.
|
2011-03-18 20:35:07 +00:00
|
|
|
IC ic(IC::NO_EXTRA_FRAME, Isolate::Current());
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(ic.target()->is_load_stub() || ic.target()->is_keyed_load_stub());
|
2011-03-18 20:35:07 +00:00
|
|
|
if (!ic.SlowIsContextual()) return HEAP->undefined_value();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Throw a reference error.
|
2009-07-29 12:34:21 +00:00
|
|
|
HandleScope scope;
|
|
|
|
Handle<String> name_handle(name);
|
|
|
|
Handle<Object> error =
|
2011-03-18 20:35:07 +00:00
|
|
|
FACTORY->NewReferenceError("not_defined",
|
2009-07-29 12:34:21 +00:00
|
|
|
HandleVector(&name_handle, 1));
|
2011-03-18 20:35:07 +00:00
|
|
|
return Isolate::Current()->Throw(*error);
|
2009-07-29 12:34:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
static MaybeObject* LoadWithInterceptor(Arguments* args,
|
|
|
|
PropertyAttributes* attrs) {
|
2010-03-25 17:08:22 +00:00
|
|
|
Handle<String> name_handle = args->at<String>(0);
|
|
|
|
Handle<InterceptorInfo> interceptor_info = args->at<InterceptorInfo>(1);
|
|
|
|
ASSERT(kAccessorInfoOffsetInInterceptorArgs == 2);
|
|
|
|
Handle<JSObject> receiver_handle = args->at<JSObject>(2);
|
|
|
|
Handle<JSObject> holder_handle = args->at<JSObject>(3);
|
|
|
|
ASSERT(args->length() == 5); // Last arg is data object.
|
2009-07-29 12:34:21 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = receiver_handle->GetIsolate();
|
|
|
|
|
2009-07-29 12:34:21 +00:00
|
|
|
Address getter_address = v8::ToCData<Address>(interceptor_info->getter());
|
|
|
|
v8::NamedPropertyGetter getter =
|
|
|
|
FUNCTION_CAST<v8::NamedPropertyGetter>(getter_address);
|
|
|
|
ASSERT(getter != NULL);
|
|
|
|
|
2009-03-18 18:50:35 +00:00
|
|
|
{
|
2009-07-29 12:34:21 +00:00
|
|
|
// Use the interceptor getter.
|
2010-03-25 17:08:22 +00:00
|
|
|
v8::AccessorInfo info(args->arguments() -
|
|
|
|
kAccessorInfoOffsetInInterceptorArgs);
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate);
|
2009-07-29 12:34:21 +00:00
|
|
|
v8::Handle<v8::Value> r;
|
|
|
|
{
|
|
|
|
// Leaving JavaScript.
|
2011-03-18 20:35:07 +00:00
|
|
|
VMState state(isolate, EXTERNAL);
|
2009-07-29 12:34:21 +00:00
|
|
|
r = getter(v8::Utils::ToLocal(name_handle), info);
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
RETURN_IF_SCHEDULED_EXCEPTION(isolate);
|
2009-07-29 12:34:21 +00:00
|
|
|
if (!r.IsEmpty()) {
|
|
|
|
*attrs = NONE;
|
|
|
|
return *v8::Utils::OpenHandle(*r);
|
|
|
|
}
|
2009-03-18 18:50:35 +00:00
|
|
|
}
|
2009-07-29 12:34:21 +00:00
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* result = holder_handle->GetPropertyPostInterceptor(
|
2009-07-29 12:34:21 +00:00
|
|
|
*receiver_handle,
|
|
|
|
*name_handle,
|
|
|
|
attrs);
|
2011-03-18 20:35:07 +00:00
|
|
|
RETURN_IF_SCHEDULED_EXCEPTION(isolate);
|
2009-07-29 12:34:21 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads a property with an interceptor performing post interceptor
|
|
|
|
* lookup if interceptor failed.
|
|
|
|
*/
|
2011-03-30 14:17:39 +00:00
|
|
|
RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad) {
|
2009-07-29 12:34:21 +00:00
|
|
|
PropertyAttributes attr = NONE;
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result = LoadWithInterceptor(&args, &attr);
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
2009-07-29 12:34:21 +00:00
|
|
|
|
|
|
|
// If the property is present, return it.
|
|
|
|
if (attr != ABSENT) return result;
|
2010-03-25 17:08:22 +00:00
|
|
|
return ThrowReferenceError(String::cast(args[0]));
|
2009-07-29 12:34:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-30 14:17:39 +00:00
|
|
|
RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall) {
|
2009-07-29 12:34:21 +00:00
|
|
|
PropertyAttributes attr;
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* result = LoadWithInterceptor(&args, &attr);
|
2011-03-18 20:35:07 +00:00
|
|
|
RETURN_IF_SCHEDULED_EXCEPTION(isolate);
|
2009-07-29 12:34:21 +00:00
|
|
|
// This is call IC. In this case, we simply return the undefined result which
|
|
|
|
// will lead to an exception when trying to invoke the result as a
|
|
|
|
// function.
|
|
|
|
return result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-30 14:17:39 +00:00
|
|
|
RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty) {
|
2011-03-02 04:53:43 +00:00
|
|
|
ASSERT(args.length() == 4);
|
2009-03-18 18:50:35 +00:00
|
|
|
JSObject* recv = JSObject::cast(args[0]);
|
|
|
|
String* name = String::cast(args[1]);
|
|
|
|
Object* value = args[2];
|
2011-06-10 12:15:30 +00:00
|
|
|
StrictModeFlag strict_mode = static_cast<StrictModeFlag>(args.smi_at(3));
|
2011-03-03 16:17:28 +00:00
|
|
|
ASSERT(strict_mode == kStrictMode || strict_mode == kNonStrictMode);
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(recv->HasNamedInterceptor());
|
|
|
|
PropertyAttributes attr = NONE;
|
2011-03-02 04:53:43 +00:00
|
|
|
MaybeObject* result = recv->SetPropertyWithInterceptor(
|
2011-03-03 16:17:28 +00:00
|
|
|
name, value, attr, strict_mode);
|
2009-03-18 18:50:35 +00:00
|
|
|
return result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-30 14:17:39 +00:00
|
|
|
RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor) {
|
2010-02-12 14:21:18 +00:00
|
|
|
JSObject* receiver = JSObject::cast(args[0]);
|
2011-06-10 12:15:30 +00:00
|
|
|
ASSERT(args.smi_at(1) >= 0);
|
|
|
|
uint32_t index = args.smi_at(1);
|
2010-02-12 14:21:18 +00:00
|
|
|
return receiver->GetElementWithInterceptor(receiver, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCompiler::CompileCallInitialize(Code::Flags flags) {
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate());
|
2008-07-03 15:10:15 +00:00
|
|
|
int argc = Code::ExtractArgumentsCountFromFlags(flags);
|
2010-06-07 08:27:32 +00:00
|
|
|
Code::Kind kind = Code::ExtractKindFromFlags(flags);
|
2011-05-24 14:01:36 +00:00
|
|
|
Code::ExtraICState extra_ic_state = Code::ExtractExtraICStateFromFlags(flags);
|
2010-06-07 08:27:32 +00:00
|
|
|
if (kind == Code::CALL_IC) {
|
2011-05-24 14:01:36 +00:00
|
|
|
CallIC::GenerateInitialize(masm(), argc, extra_ic_state);
|
2010-06-07 08:27:32 +00:00
|
|
|
} else {
|
|
|
|
KeyedCallIC::GenerateInitialize(masm(), argc);
|
|
|
|
}
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
GetCodeWithFlags(flags, "CompileCallInitialize");
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-03-23 11:13:07 +00:00
|
|
|
isolate()->counters()->call_initialize_stubs()->Increment();
|
2010-10-25 15:22:03 +00:00
|
|
|
Code* code = Code::cast(result);
|
|
|
|
USE(code);
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_INITIALIZE_TAG),
|
2010-10-25 15:22:03 +00:00
|
|
|
code, code->arguments_count()));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_INITIALIZE, Code::cast(code)));
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCompiler::CompileCallPreMonomorphic(Code::Flags flags) {
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate());
|
2008-07-03 15:10:15 +00:00
|
|
|
int argc = Code::ExtractArgumentsCountFromFlags(flags);
|
2009-07-16 08:38:52 +00:00
|
|
|
// The code of the PreMonomorphic stub is the same as the code
|
|
|
|
// of the Initialized stub. They just differ on the code object flags.
|
2010-06-07 08:27:32 +00:00
|
|
|
Code::Kind kind = Code::ExtractKindFromFlags(flags);
|
2011-05-24 14:01:36 +00:00
|
|
|
Code::ExtraICState extra_ic_state = Code::ExtractExtraICStateFromFlags(flags);
|
2010-06-07 08:27:32 +00:00
|
|
|
if (kind == Code::CALL_IC) {
|
2011-05-24 14:01:36 +00:00
|
|
|
CallIC::GenerateInitialize(masm(), argc, extra_ic_state);
|
2010-06-07 08:27:32 +00:00
|
|
|
} else {
|
|
|
|
KeyedCallIC::GenerateInitialize(masm(), argc);
|
|
|
|
}
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
GetCodeWithFlags(flags, "CompileCallPreMonomorphic");
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-03-23 11:13:07 +00:00
|
|
|
isolate()->counters()->call_premonomorphic_stubs()->Increment();
|
2010-10-25 15:22:03 +00:00
|
|
|
Code* code = Code::cast(result);
|
|
|
|
USE(code);
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_PRE_MONOMORPHIC_TAG),
|
2010-10-25 15:22:03 +00:00
|
|
|
code, code->arguments_count()));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_PRE_MONOMORPHIC, Code::cast(code)));
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCompiler::CompileCallNormal(Code::Flags flags) {
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate());
|
2008-07-03 15:10:15 +00:00
|
|
|
int argc = Code::ExtractArgumentsCountFromFlags(flags);
|
2010-06-07 08:27:32 +00:00
|
|
|
Code::Kind kind = Code::ExtractKindFromFlags(flags);
|
|
|
|
if (kind == Code::CALL_IC) {
|
2011-05-24 14:01:36 +00:00
|
|
|
// Call normal is always with a explict receiver.
|
|
|
|
ASSERT(!CallIC::Contextual::decode(
|
|
|
|
Code::ExtractExtraICStateFromFlags(flags)));
|
2010-06-07 08:27:32 +00:00
|
|
|
CallIC::GenerateNormal(masm(), argc);
|
|
|
|
} else {
|
|
|
|
KeyedCallIC::GenerateNormal(masm(), argc);
|
|
|
|
}
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result = GetCodeWithFlags(flags, "CompileCallNormal");
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-03-23 11:13:07 +00:00
|
|
|
isolate()->counters()->call_normal_stubs()->Increment();
|
2010-10-25 15:22:03 +00:00
|
|
|
Code* code = Code::cast(result);
|
|
|
|
USE(code);
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_NORMAL_TAG),
|
2010-10-25 15:22:03 +00:00
|
|
|
code, code->arguments_count()));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_NORMAL, Code::cast(code)));
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCompiler::CompileCallMegamorphic(Code::Flags flags) {
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate());
|
2008-07-03 15:10:15 +00:00
|
|
|
int argc = Code::ExtractArgumentsCountFromFlags(flags);
|
2010-06-07 08:27:32 +00:00
|
|
|
Code::Kind kind = Code::ExtractKindFromFlags(flags);
|
2011-05-24 14:01:36 +00:00
|
|
|
Code::ExtraICState extra_ic_state = Code::ExtractExtraICStateFromFlags(flags);
|
2010-06-07 08:27:32 +00:00
|
|
|
if (kind == Code::CALL_IC) {
|
2011-05-24 14:01:36 +00:00
|
|
|
CallIC::GenerateMegamorphic(masm(), argc, extra_ic_state);
|
2010-06-07 08:27:32 +00:00
|
|
|
} else {
|
|
|
|
KeyedCallIC::GenerateMegamorphic(masm(), argc);
|
|
|
|
}
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
GetCodeWithFlags(flags, "CompileCallMegamorphic");
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-03-23 11:13:07 +00:00
|
|
|
isolate()->counters()->call_megamorphic_stubs()->Increment();
|
2010-10-25 15:22:03 +00:00
|
|
|
Code* code = Code::cast(result);
|
|
|
|
USE(code);
|
2011-06-16 14:12:58 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_MEGAMORPHIC_TAG),
|
|
|
|
code, code->arguments_count()));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_MEGAMORPHIC, Code::cast(code)));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MaybeObject* StubCompiler::CompileCallArguments(Code::Flags flags) {
|
|
|
|
HandleScope scope(isolate());
|
|
|
|
int argc = Code::ExtractArgumentsCountFromFlags(flags);
|
|
|
|
KeyedCallIC::GenerateNonStrictArguments(masm(), argc);
|
|
|
|
Code::Kind kind = Code::ExtractKindFromFlags(flags);
|
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
GetCodeWithFlags(flags, "CompileCallArguments");
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
|
|
|
Code* code = Code::cast(result);
|
|
|
|
USE(code);
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_MEGAMORPHIC_TAG),
|
2010-10-25 15:22:03 +00:00
|
|
|
code, code->arguments_count()));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_MEGAMORPHIC, Code::cast(code)));
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCompiler::CompileCallMiss(Code::Flags flags) {
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate());
|
2008-07-03 15:10:15 +00:00
|
|
|
int argc = Code::ExtractArgumentsCountFromFlags(flags);
|
2010-06-07 08:27:32 +00:00
|
|
|
Code::Kind kind = Code::ExtractKindFromFlags(flags);
|
2011-05-24 14:01:36 +00:00
|
|
|
Code::ExtraICState extra_ic_state = Code::ExtractExtraICStateFromFlags(flags);
|
2010-06-07 08:27:32 +00:00
|
|
|
if (kind == Code::CALL_IC) {
|
2011-05-24 14:01:36 +00:00
|
|
|
CallIC::GenerateMiss(masm(), argc, extra_ic_state);
|
2010-06-07 08:27:32 +00:00
|
|
|
} else {
|
|
|
|
KeyedCallIC::GenerateMiss(masm(), argc);
|
|
|
|
}
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result = GetCodeWithFlags(flags, "CompileCallMiss");
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-03-23 11:13:07 +00:00
|
|
|
isolate()->counters()->call_megamorphic_stubs()->Increment();
|
2010-10-25 15:22:03 +00:00
|
|
|
Code* code = Code::cast(result);
|
|
|
|
USE(code);
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_MISS_TAG),
|
2010-10-25 15:22:03 +00:00
|
|
|
code, code->arguments_count()));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_MISS, Code::cast(code)));
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCompiler::CompileCallDebugBreak(Code::Flags flags) {
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate());
|
2008-12-09 11:12:14 +00:00
|
|
|
Debug::GenerateCallICDebugBreak(masm());
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
GetCodeWithFlags(flags, "CompileCallDebugBreak");
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-10-25 15:22:03 +00:00
|
|
|
Code* code = Code::cast(result);
|
|
|
|
USE(code);
|
|
|
|
Code::Kind kind = Code::ExtractKindFromFlags(flags);
|
|
|
|
USE(kind);
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_DEBUG_BREAK_TAG),
|
2010-10-25 15:22:03 +00:00
|
|
|
code, code->arguments_count()));
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCompiler::CompileCallDebugPrepareStepIn(Code::Flags flags) {
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate());
|
2008-07-03 15:10:15 +00:00
|
|
|
// Use the same code for the the step in preparations as we do for
|
|
|
|
// the miss case.
|
|
|
|
int argc = Code::ExtractArgumentsCountFromFlags(flags);
|
2010-06-07 08:27:32 +00:00
|
|
|
Code::Kind kind = Code::ExtractKindFromFlags(flags);
|
|
|
|
if (kind == Code::CALL_IC) {
|
2011-05-24 14:01:36 +00:00
|
|
|
// For the debugger extra ic state is irrelevant.
|
|
|
|
CallIC::GenerateMiss(masm(), argc, Code::kNoExtraICState);
|
2010-06-07 08:27:32 +00:00
|
|
|
} else {
|
|
|
|
KeyedCallIC::GenerateMiss(masm(), argc);
|
|
|
|
}
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
GetCodeWithFlags(flags, "CompileCallDebugPrepareStepIn");
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-10-25 15:22:03 +00:00
|
|
|
Code* code = Code::cast(result);
|
|
|
|
USE(code);
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(
|
|
|
|
CALL_LOGGER_TAG(kind, CALL_DEBUG_PREPARE_STEP_IN_TAG),
|
|
|
|
code,
|
|
|
|
code->arguments_count()));
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
2009-04-20 16:36:13 +00:00
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-06-07 08:27:32 +00:00
|
|
|
#undef CALL_LOGGER_TAG
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCompiler::GetCodeWithFlags(Code::Flags flags,
|
|
|
|
const char* name) {
|
2009-07-10 09:40:47 +00:00
|
|
|
// Check for allocation failures during stub compilation.
|
|
|
|
if (failure_->IsFailure()) return failure_;
|
|
|
|
|
|
|
|
// Create code object in the heap.
|
2008-07-03 15:10:15 +00:00
|
|
|
CodeDesc desc;
|
|
|
|
masm_.GetCode(&desc);
|
2011-03-30 08:18:56 +00:00
|
|
|
MaybeObject* result = heap()->CreateCode(desc, flags, masm_.CodeObject());
|
2009-03-04 06:14:34 +00:00
|
|
|
#ifdef ENABLE_DISASSEMBLER
|
2008-07-03 15:10:15 +00:00
|
|
|
if (FLAG_print_code_stubs && !result->IsFailure()) {
|
2010-10-25 15:22:03 +00:00
|
|
|
Code::cast(result->ToObjectUnchecked())->Disassemble(name);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StubCompiler::GetCodeWithFlags(Code::Flags flags, String* name) {
|
2009-03-04 06:14:34 +00:00
|
|
|
if (FLAG_print_code_stubs && (name != NULL)) {
|
|
|
|
return GetCodeWithFlags(flags, *name->ToCString());
|
|
|
|
}
|
|
|
|
return GetCodeWithFlags(flags, reinterpret_cast<char*>(NULL));
|
|
|
|
}
|
|
|
|
|
2010-02-18 15:10:35 +00:00
|
|
|
|
2010-02-02 11:32:17 +00:00
|
|
|
void StubCompiler::LookupPostInterceptor(JSObject* holder,
|
|
|
|
String* name,
|
|
|
|
LookupResult* lookup) {
|
|
|
|
holder->LocalLookupRealNamedProperty(name, lookup);
|
2010-02-18 15:10:35 +00:00
|
|
|
if (!lookup->IsProperty()) {
|
|
|
|
lookup->NotFound();
|
2010-02-02 11:32:17 +00:00
|
|
|
Object* proto = holder->GetPrototype();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (!proto->IsNull()) {
|
2010-02-02 11:32:17 +00:00
|
|
|
proto->Lookup(name, lookup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-04 06:14:34 +00:00
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* LoadStubCompiler::GetCode(PropertyType type, String* name) {
|
2009-03-04 06:14:34 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, type);
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* result = GetCodeWithFlags(flags, name);
|
2010-09-24 11:45:12 +00:00
|
|
|
if (!result->IsFailure()) {
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(Logger::LOAD_IC_TAG,
|
2010-10-25 15:22:03 +00:00
|
|
|
Code::cast(result->ToObjectUnchecked()),
|
|
|
|
name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC,
|
|
|
|
name,
|
|
|
|
Code::cast(result->ToObjectUnchecked())));
|
2010-09-24 11:45:12 +00:00
|
|
|
}
|
|
|
|
return result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-18 13:17:29 +00:00
|
|
|
MaybeObject* KeyedLoadStubCompiler::GetCode(PropertyType type,
|
|
|
|
String* name,
|
|
|
|
InlineCacheState state) {
|
|
|
|
Code::Flags flags = Code::ComputeFlags(
|
|
|
|
Code::KEYED_LOAD_IC, NOT_IN_LOOP, state, Code::kNoExtraICState, type);
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* result = GetCodeWithFlags(flags, name);
|
2010-09-24 11:45:12 +00:00
|
|
|
if (!result->IsFailure()) {
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG,
|
2010-10-25 15:22:03 +00:00
|
|
|
Code::cast(result->ToObjectUnchecked()),
|
|
|
|
name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC,
|
|
|
|
name,
|
|
|
|
Code::cast(result->ToObjectUnchecked())));
|
2010-09-24 11:45:12 +00:00
|
|
|
}
|
|
|
|
return result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* StoreStubCompiler::GetCode(PropertyType type, String* name) {
|
2011-03-02 04:53:43 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(
|
|
|
|
Code::STORE_IC, type, strict_mode_);
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* result = GetCodeWithFlags(flags, name);
|
2010-09-24 11:45:12 +00:00
|
|
|
if (!result->IsFailure()) {
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(Logger::STORE_IC_TAG,
|
2010-10-25 15:22:03 +00:00
|
|
|
Code::cast(result->ToObjectUnchecked()),
|
|
|
|
name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::STORE_IC,
|
|
|
|
name,
|
|
|
|
Code::cast(result->ToObjectUnchecked())));
|
2010-09-24 11:45:12 +00:00
|
|
|
}
|
|
|
|
return result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-18 13:17:29 +00:00
|
|
|
MaybeObject* KeyedStoreStubCompiler::GetCode(PropertyType type,
|
|
|
|
String* name,
|
|
|
|
InlineCacheState state) {
|
|
|
|
Code::Flags flags = Code::ComputeFlags(
|
|
|
|
Code::KEYED_STORE_IC, NOT_IN_LOOP, state, strict_mode_, type);
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* result = GetCodeWithFlags(flags, name);
|
2010-09-24 11:45:12 +00:00
|
|
|
if (!result->IsFailure()) {
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(Logger::KEYED_STORE_IC_TAG,
|
2010-10-25 15:22:03 +00:00
|
|
|
Code::cast(result->ToObjectUnchecked()),
|
|
|
|
name));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_STORE_IC,
|
|
|
|
name,
|
|
|
|
Code::cast(result->ToObjectUnchecked())));
|
2010-09-24 11:45:12 +00:00
|
|
|
}
|
|
|
|
return result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-08 10:46:10 +00:00
|
|
|
void KeyedStoreStubCompiler::GenerateStoreDictionaryElement(
|
|
|
|
MacroAssembler* masm) {
|
|
|
|
KeyedStoreIC::GenerateSlow(masm);
|
2011-06-10 07:49:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-02 14:15:04 +00:00
|
|
|
CallStubCompiler::CallStubCompiler(int argc,
|
|
|
|
InLoopFlag in_loop,
|
|
|
|
Code::Kind kind,
|
2011-01-18 16:54:48 +00:00
|
|
|
Code::ExtraICState extra_ic_state,
|
2010-07-02 14:15:04 +00:00
|
|
|
InlineCacheHolderFlag cache_holder)
|
2011-01-18 16:54:48 +00:00
|
|
|
: arguments_(argc),
|
|
|
|
in_loop_(in_loop),
|
|
|
|
kind_(kind),
|
|
|
|
extra_ic_state_(extra_ic_state),
|
|
|
|
cache_holder_(cache_holder) {
|
2010-07-02 14:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-17 17:25:54 +00:00
|
|
|
bool CallStubCompiler::HasCustomCallGenerator(JSFunction* function) {
|
|
|
|
SharedFunctionInfo* info = function->shared();
|
|
|
|
if (info->HasBuiltinFunctionId()) {
|
|
|
|
BuiltinFunctionId id = info->builtin_function_id();
|
2010-12-14 18:53:48 +00:00
|
|
|
#define CALL_GENERATOR_CASE(name) if (id == k##name) return true;
|
2011-03-17 17:25:54 +00:00
|
|
|
CUSTOM_CALL_IC_GENERATORS(CALL_GENERATOR_CASE)
|
2010-12-14 18:53:48 +00:00
|
|
|
#undef CALL_GENERATOR_CASE
|
2011-03-17 17:25:54 +00:00
|
|
|
}
|
|
|
|
CallOptimization optimization(function);
|
|
|
|
if (optimization.is_simple_api_call()) {
|
|
|
|
return true;
|
|
|
|
}
|
2010-12-14 18:53:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-17 17:25:54 +00:00
|
|
|
MaybeObject* CallStubCompiler::CompileCustomCall(Object* object,
|
2010-10-25 15:22:03 +00:00
|
|
|
JSObject* holder,
|
|
|
|
JSGlobalPropertyCell* cell,
|
|
|
|
JSFunction* function,
|
|
|
|
String* fname) {
|
2011-03-17 17:25:54 +00:00
|
|
|
ASSERT(HasCustomCallGenerator(function));
|
|
|
|
|
|
|
|
SharedFunctionInfo* info = function->shared();
|
|
|
|
if (info->HasBuiltinFunctionId()) {
|
|
|
|
BuiltinFunctionId id = info->builtin_function_id();
|
|
|
|
#define CALL_GENERATOR_CASE(name) \
|
|
|
|
if (id == k##name) { \
|
|
|
|
return CallStubCompiler::Compile##name##Call(object, \
|
|
|
|
holder, \
|
|
|
|
cell, \
|
|
|
|
function, \
|
|
|
|
fname); \
|
|
|
|
}
|
|
|
|
CUSTOM_CALL_IC_GENERATORS(CALL_GENERATOR_CASE)
|
2010-05-06 13:21:53 +00:00
|
|
|
#undef CALL_GENERATOR_CASE
|
2011-03-17 17:25:54 +00:00
|
|
|
}
|
|
|
|
CallOptimization optimization(function);
|
|
|
|
ASSERT(optimization.is_simple_api_call());
|
|
|
|
return CompileFastApiCall(optimization,
|
|
|
|
object,
|
|
|
|
holder,
|
|
|
|
cell,
|
|
|
|
function,
|
|
|
|
fname);
|
2010-05-06 13:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* CallStubCompiler::GetCode(PropertyType type, String* name) {
|
2008-07-03 15:10:15 +00:00
|
|
|
int argc = arguments_.immediate();
|
2010-06-07 08:27:32 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(kind_,
|
2009-05-25 18:29:02 +00:00
|
|
|
type,
|
2011-01-18 16:54:48 +00:00
|
|
|
extra_ic_state_,
|
2010-07-02 14:15:04 +00:00
|
|
|
cache_holder_,
|
2009-06-30 14:07:29 +00:00
|
|
|
in_loop_,
|
2009-05-25 18:29:02 +00:00
|
|
|
argc);
|
2009-03-04 06:14:34 +00:00
|
|
|
return GetCodeWithFlags(flags, name);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* CallStubCompiler::GetCode(JSFunction* function) {
|
2010-05-06 13:21:53 +00:00
|
|
|
String* function_name = NULL;
|
|
|
|
if (function->shared()->name()->IsString()) {
|
|
|
|
function_name = String::cast(function->shared()->name());
|
|
|
|
}
|
|
|
|
return GetCode(CONSTANT_FUNCTION, function_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MaybeObject* ConstructStubCompiler::GetCode() {
|
2009-08-26 12:22:44 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(Code::STUB);
|
2010-10-25 15:22:03 +00:00
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result = GetCodeWithFlags(flags, "ConstructStub");
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
2009-09-02 06:55:49 +00:00
|
|
|
}
|
2010-10-25 15:22:03 +00:00
|
|
|
Code* code = Code::cast(result);
|
|
|
|
USE(code);
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(), CodeCreateEvent(Logger::STUB_TAG, code, "ConstructStub"));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(GDBJITInterface::STUB, "ConstructStub", Code::cast(code)));
|
2009-09-02 06:55:49 +00:00
|
|
|
return result;
|
2009-08-26 12:22:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-28 14:06:35 +00:00
|
|
|
CallOptimization::CallOptimization(LookupResult* lookup) {
|
|
|
|
if (!lookup->IsProperty() || !lookup->IsCacheable() ||
|
|
|
|
lookup->type() != CONSTANT_FUNCTION) {
|
|
|
|
Initialize(NULL);
|
|
|
|
} else {
|
|
|
|
// We only optimize constant function calls.
|
|
|
|
Initialize(lookup->GetConstantFunction());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CallOptimization::CallOptimization(JSFunction* function) {
|
|
|
|
Initialize(function);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CallOptimization::GetPrototypeDepthOfExpectedType(JSObject* object,
|
|
|
|
JSObject* holder) const {
|
|
|
|
ASSERT(is_simple_api_call_);
|
|
|
|
if (expected_receiver_type_ == NULL) return 0;
|
|
|
|
int depth = 0;
|
|
|
|
while (object != holder) {
|
|
|
|
if (object->IsInstanceOf(expected_receiver_type_)) return depth;
|
|
|
|
object = JSObject::cast(object->GetPrototype());
|
|
|
|
++depth;
|
|
|
|
}
|
|
|
|
if (holder->IsInstanceOf(expected_receiver_type_)) return depth;
|
|
|
|
return kInvalidProtoDepth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CallOptimization::Initialize(JSFunction* function) {
|
|
|
|
constant_function_ = NULL;
|
|
|
|
is_simple_api_call_ = false;
|
|
|
|
expected_receiver_type_ = NULL;
|
|
|
|
api_call_info_ = NULL;
|
|
|
|
|
|
|
|
if (function == NULL || !function->is_compiled()) return;
|
|
|
|
|
|
|
|
constant_function_ = function;
|
|
|
|
AnalyzePossibleApiFunction(function);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CallOptimization::AnalyzePossibleApiFunction(JSFunction* function) {
|
|
|
|
SharedFunctionInfo* sfi = function->shared();
|
|
|
|
if (!sfi->IsApiFunction()) return;
|
|
|
|
FunctionTemplateInfo* info = sfi->get_api_func_data();
|
|
|
|
|
|
|
|
// Require a C++ callback.
|
|
|
|
if (info->call_code()->IsUndefined()) return;
|
|
|
|
api_call_info_ = CallHandlerInfo::cast(info->call_code());
|
|
|
|
|
|
|
|
// Accept signatures that either have no restrictions at all or
|
|
|
|
// only have restrictions on the receiver.
|
|
|
|
if (!info->signature()->IsUndefined()) {
|
|
|
|
SignatureInfo* signature = SignatureInfo::cast(info->signature());
|
|
|
|
if (!signature->args()->IsUndefined()) return;
|
|
|
|
if (!signature->receiver()->IsUndefined()) {
|
|
|
|
expected_receiver_type_ =
|
|
|
|
FunctionTemplateInfo::cast(signature->receiver());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
is_simple_api_call_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|