2012-02-10 12:36:05 +00:00
|
|
|
// Copyright 2012 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());
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-02-28 18:26:04 +00:00
|
|
|
void StubCache::Initialize() {
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(IsPowerOf2(kPrimaryTableSize));
|
|
|
|
ASSERT(IsPowerOf2(kSecondaryTableSize));
|
2012-02-28 18:26:04 +00:00
|
|
|
Clear();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2011-09-12 10:50:50 +00:00
|
|
|
STATIC_ASSERT((Code::ICStateField::kMask & 1) == 1);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-18 12:19:18 +00:00
|
|
|
Handle<Code> StubCache::ComputeLoadNonexistent(Handle<String> name,
|
|
|
|
Handle<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-10-18 12:19:18 +00:00
|
|
|
Handle<String> cache_name = factory()->empty_string();
|
2010-04-15 11:25:41 +00:00
|
|
|
if (receiver->IsGlobalObject()) cache_name = name;
|
2011-10-18 12:19:18 +00:00
|
|
|
Handle<JSObject> last = receiver;
|
2011-03-30 08:18:56 +00:00
|
|
|
while (last->GetPrototype() != heap()->null_value()) {
|
2011-10-18 12:19:18 +00:00
|
|
|
last = Handle<JSObject>(JSObject::cast(last->GetPrototype()));
|
2010-04-15 11:25:41 +00:00
|
|
|
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);
|
2011-10-18 12:19:18 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*cache_name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
LoadStubCompiler compiler(isolate_);
|
|
|
|
Handle<Code> code =
|
|
|
|
compiler.CompileLoadNonexistent(cache_name, receiver, last);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::LOAD_IC_TAG, *code, *cache_name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, *cache_name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, cache_name, code);
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2010-04-15 11:25:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-18 12:19:18 +00:00
|
|
|
Handle<Code> StubCache::ComputeLoadField(Handle<String> name,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<JSObject> holder,
|
2010-10-25 15:22:03 +00:00
|
|
|
int field_index) {
|
2011-10-18 12:19:18 +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);
|
2011-10-18 12:19:18 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
LoadStubCompiler compiler(isolate_);
|
|
|
|
Handle<Code> code =
|
|
|
|
compiler.CompileLoadField(receiver, holder, field_index, name);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::LOAD_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, *name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-18 12:19:18 +00:00
|
|
|
Handle<Code> StubCache::ComputeLoadCallback(Handle<String> name,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<JSObject> holder,
|
|
|
|
Handle<AccessorInfo> callback) {
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(v8::ToCData<Address>(callback->getter()) != 0);
|
2011-10-18 12:19:18 +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);
|
2011-10-18 12:19:18 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
LoadStubCompiler compiler(isolate_);
|
|
|
|
Handle<Code> code =
|
|
|
|
compiler.CompileLoadCallback(name, receiver, holder, callback);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::LOAD_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, *name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-18 12:19:18 +00:00
|
|
|
Handle<Code> StubCache::ComputeLoadConstant(Handle<String> name,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<JSObject> holder,
|
2011-12-06 12:11:08 +00:00
|
|
|
Handle<JSFunction> value) {
|
2011-10-18 12:19:18 +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);
|
2011-10-18 12:19:18 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
LoadStubCompiler compiler(isolate_);
|
|
|
|
Handle<Code> code =
|
|
|
|
compiler.CompileLoadConstant(receiver, holder, value, name);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::LOAD_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, *name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-18 12:19:18 +00:00
|
|
|
Handle<Code> StubCache::ComputeLoadInterceptor(Handle<String> name,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<JSObject> holder) {
|
|
|
|
ASSERT(IC::GetCodeCacheForObject(*receiver, *holder) == OWN_MAP);
|
2008-07-03 15:10:15 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, INTERCEPTOR);
|
2011-10-18 12:19:18 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
LoadStubCompiler compiler(isolate_);
|
|
|
|
Handle<Code> code =
|
|
|
|
compiler.CompileLoadInterceptor(receiver, holder, name);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::LOAD_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, *name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-18 12:19:18 +00:00
|
|
|
Handle<Code> StubCache::ComputeLoadNormal() {
|
|
|
|
return isolate_->builtins()->LoadIC_Normal();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2011-10-25 12:26:07 +00:00
|
|
|
|
2011-10-18 12:19:18 +00:00
|
|
|
Handle<Code> StubCache::ComputeLoadGlobal(Handle<String> name,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<GlobalObject> holder,
|
|
|
|
Handle<JSGlobalPropertyCell> cell,
|
2010-10-25 15:22:03 +00:00
|
|
|
bool is_dont_delete) {
|
2011-10-18 12:19:18 +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);
|
2011-10-18 12:19:18 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
LoadStubCompiler compiler(isolate_);
|
|
|
|
Handle<Code> code =
|
|
|
|
compiler.CompileLoadGlobal(receiver, holder, cell, name, is_dont_delete);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::LOAD_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, *name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2009-06-30 10:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 09:35:47 +00:00
|
|
|
Handle<Code> StubCache::ComputeKeyedLoadField(Handle<String> name,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<JSObject> holder,
|
2010-10-25 15:22:03 +00:00
|
|
|
int field_index) {
|
2011-10-20 09:35:47 +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);
|
2011-10-20 09:35:47 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
KeyedLoadStubCompiler compiler(isolate_);
|
|
|
|
Handle<Code> code =
|
|
|
|
compiler.CompileLoadField(name, receiver, holder, field_index);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, *name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2008-07-03 15:10:15 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 09:35:47 +00:00
|
|
|
Handle<Code> StubCache::ComputeKeyedLoadConstant(Handle<String> name,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<JSObject> holder,
|
2011-12-06 12:11:08 +00:00
|
|
|
Handle<JSFunction> value) {
|
2011-10-20 09:35:47 +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);
|
2011-10-20 09:35:47 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
KeyedLoadStubCompiler compiler(isolate_);
|
|
|
|
Handle<Code> code =
|
|
|
|
compiler.CompileLoadConstant(name, receiver, holder, value);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, *name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2008-07-03 15:10:15 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 09:35:47 +00:00
|
|
|
Handle<Code> StubCache::ComputeKeyedLoadInterceptor(Handle<String> name,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<JSObject> holder) {
|
|
|
|
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);
|
2011-10-20 09:35:47 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
KeyedLoadStubCompiler compiler(isolate_);
|
|
|
|
Handle<Code> code = compiler.CompileLoadInterceptor(receiver, holder, name);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, *name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2008-07-03 15:10:15 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 09:35:47 +00:00
|
|
|
Handle<Code> StubCache::ComputeKeyedLoadCallback(
|
|
|
|
Handle<String> name,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<JSObject> holder,
|
|
|
|
Handle<AccessorInfo> callback) {
|
|
|
|
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);
|
2011-10-20 09:35:47 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
KeyedLoadStubCompiler compiler(isolate_);
|
|
|
|
Handle<Code> code =
|
|
|
|
compiler.CompileLoadCallback(name, receiver, holder, callback);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, *name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2008-07-03 15:10:15 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 09:35:47 +00:00
|
|
|
Handle<Code> StubCache::ComputeKeyedLoadArrayLength(Handle<String> name,
|
|
|
|
Handle<JSArray> receiver) {
|
2008-07-03 15:10:15 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, CALLBACKS);
|
2011-10-20 09:35:47 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
KeyedLoadStubCompiler compiler(isolate_);
|
|
|
|
Handle<Code> code = compiler.CompileLoadArrayLength(name);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, *name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2008-07-03 15:10:15 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 09:35:47 +00:00
|
|
|
Handle<Code> StubCache::ComputeKeyedLoadStringLength(Handle<String> name,
|
|
|
|
Handle<String> receiver) {
|
2008-07-03 15:10:15 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, CALLBACKS);
|
2011-10-20 09:35:47 +00:00
|
|
|
Handle<Map> map(receiver->map());
|
|
|
|
Handle<Object> probe(map->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
KeyedLoadStubCompiler compiler(isolate_);
|
|
|
|
Handle<Code> code = compiler.CompileLoadStringLength(name);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, *name, *code));
|
|
|
|
Map::UpdateCodeCache(map, name, code);
|
2008-07-03 15:10:15 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 09:35:47 +00:00
|
|
|
Handle<Code> StubCache::ComputeKeyedLoadFunctionPrototype(
|
|
|
|
Handle<String> name,
|
|
|
|
Handle<JSFunction> receiver) {
|
2008-07-03 15:10:15 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, CALLBACKS);
|
2011-10-20 09:35:47 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
KeyedLoadStubCompiler compiler(isolate_);
|
|
|
|
Handle<Code> code = compiler.CompileLoadFunctionPrototype(name);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, *name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2008-07-03 15:10:15 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-19 09:17:01 +00:00
|
|
|
Handle<Code> StubCache::ComputeStoreField(Handle<String> name,
|
|
|
|
Handle<JSObject> receiver,
|
2010-10-25 15:22:03 +00:00
|
|
|
int field_index,
|
2011-10-19 09:17:01 +00:00
|
|
|
Handle<Map> transition,
|
2011-03-02 04:53:43 +00:00
|
|
|
StrictModeFlag strict_mode) {
|
2011-10-19 09:17:01 +00:00
|
|
|
PropertyType type = (transition.is_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);
|
2011-10-19 09:17:01 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
StoreStubCompiler compiler(isolate_, strict_mode);
|
|
|
|
Handle<Code> code =
|
|
|
|
compiler.CompileStoreField(receiver, field_index, transition, name);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::STORE_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::STORE_IC, *name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-21 11:42:54 +00:00
|
|
|
Handle<Code> StubCache::ComputeKeyedLoadOrStoreElement(
|
|
|
|
Handle<JSObject> receiver,
|
2011-10-11 09:33:00 +00:00
|
|
|
KeyedIC::StubKind stub_kind,
|
2011-05-17 17:29:13 +00:00
|
|
|
StrictModeFlag strict_mode) {
|
2012-02-10 12:36:05 +00:00
|
|
|
KeyedAccessGrowMode grow_mode =
|
|
|
|
KeyedIC::GetGrowModeFromStubKind(stub_kind);
|
|
|
|
Code::ExtraICState extra_state =
|
|
|
|
Code::ComputeExtraICState(grow_mode, strict_mode);
|
2011-05-17 17:29:13 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(
|
2011-10-11 09:33:00 +00:00
|
|
|
stub_kind == KeyedIC::LOAD ? Code::KEYED_LOAD_IC
|
|
|
|
: Code::KEYED_STORE_IC,
|
2011-05-17 17:29:13 +00:00
|
|
|
NORMAL,
|
2012-02-10 12:36:05 +00:00
|
|
|
extra_state);
|
2011-10-21 11:42:54 +00:00
|
|
|
Handle<String> name;
|
2011-10-11 09:33:00 +00:00
|
|
|
switch (stub_kind) {
|
|
|
|
case KeyedIC::LOAD:
|
2011-10-21 11:42:54 +00:00
|
|
|
name = isolate()->factory()->KeyedLoadElementMonomorphic_symbol();
|
2011-10-11 09:33:00 +00:00
|
|
|
break;
|
|
|
|
case KeyedIC::STORE_NO_TRANSITION:
|
2011-10-21 11:42:54 +00:00
|
|
|
name = isolate()->factory()->KeyedStoreElementMonomorphic_symbol();
|
2011-10-11 09:33:00 +00:00
|
|
|
break;
|
2012-02-10 12:36:05 +00:00
|
|
|
case KeyedIC::STORE_AND_GROW_NO_TRANSITION:
|
|
|
|
name = isolate()->factory()->KeyedStoreAndGrowElementMonomorphic_symbol();
|
|
|
|
break;
|
2011-10-11 09:33:00 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
2011-10-21 11:42:54 +00:00
|
|
|
Handle<Map> receiver_map(receiver->map());
|
|
|
|
Handle<Object> probe(receiver_map->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
2011-05-18 13:17:29 +00:00
|
|
|
|
2011-10-21 11:42:54 +00:00
|
|
|
Handle<Code> code;
|
2011-10-11 09:33:00 +00:00
|
|
|
switch (stub_kind) {
|
|
|
|
case KeyedIC::LOAD: {
|
2011-10-18 12:19:18 +00:00
|
|
|
KeyedLoadStubCompiler compiler(isolate_);
|
2011-10-21 11:42:54 +00:00
|
|
|
code = compiler.CompileLoadElement(receiver_map);
|
2011-10-11 09:33:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-02-10 12:36:05 +00:00
|
|
|
case KeyedIC::STORE_AND_GROW_NO_TRANSITION: {
|
|
|
|
KeyedStoreStubCompiler compiler(isolate_, strict_mode,
|
|
|
|
ALLOW_JSARRAY_GROWTH);
|
|
|
|
code = compiler.CompileStoreElement(receiver_map);
|
|
|
|
break;
|
|
|
|
}
|
2011-10-11 09:33:00 +00:00
|
|
|
case KeyedIC::STORE_NO_TRANSITION: {
|
2012-02-10 12:36:05 +00:00
|
|
|
KeyedStoreStubCompiler compiler(isolate_, strict_mode,
|
|
|
|
DO_NOT_ALLOW_JSARRAY_GROWTH);
|
2011-10-21 11:42:54 +00:00
|
|
|
code = compiler.CompileStoreElement(receiver_map);
|
2011-10-11 09:33:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
2011-05-18 13:17:29 +00:00
|
|
|
}
|
2011-10-21 11:42:54 +00:00
|
|
|
|
|
|
|
ASSERT(!code.is_null());
|
2011-10-11 09:33:00 +00:00
|
|
|
|
|
|
|
if (stub_kind == KeyedIC::LOAD) {
|
2011-10-21 11:42:54 +00:00
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, *code, 0));
|
2011-05-18 13:17:29 +00:00
|
|
|
} else {
|
2011-10-21 11:42:54 +00:00
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::KEYED_STORE_IC_TAG, *code, 0));
|
2011-01-21 23:58:00 +00:00
|
|
|
}
|
2011-10-21 11:42:54 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2011-01-21 23:58:00 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-19 09:17:01 +00:00
|
|
|
Handle<Code> StubCache::ComputeStoreNormal(StrictModeFlag strict_mode) {
|
|
|
|
return (strict_mode == kStrictMode)
|
|
|
|
? isolate_->builtins()->Builtins::StoreIC_Normal_Strict()
|
|
|
|
: isolate_->builtins()->Builtins::StoreIC_Normal();
|
2010-06-30 12:27:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-19 09:17:01 +00:00
|
|
|
Handle<Code> StubCache::ComputeStoreGlobal(Handle<String> name,
|
|
|
|
Handle<GlobalObject> receiver,
|
|
|
|
Handle<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);
|
2011-10-19 09:17:01 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
StoreStubCompiler compiler(isolate_, strict_mode);
|
|
|
|
Handle<Code> code = compiler.CompileStoreGlobal(receiver, cell, name);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::STORE_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::STORE_IC, *name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2009-06-30 10:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-19 09:17:01 +00:00
|
|
|
Handle<Code> StubCache::ComputeStoreCallback(Handle<String> name,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<AccessorInfo> callback,
|
|
|
|
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);
|
2011-10-19 09:17:01 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
StoreStubCompiler compiler(isolate_, strict_mode);
|
|
|
|
Handle<Code> code = compiler.CompileStoreCallback(receiver, callback, name);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::STORE_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::STORE_IC, *name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-19 09:17:01 +00:00
|
|
|
Handle<Code> StubCache::ComputeStoreInterceptor(Handle<String> name,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
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);
|
2011-10-19 09:17:01 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
StoreStubCompiler compiler(isolate_, strict_mode);
|
|
|
|
Handle<Code> code = compiler.CompileStoreInterceptor(receiver, name);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::STORE_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::STORE_IC, *name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2011-10-20 13:54:16 +00:00
|
|
|
Handle<Code> StubCache::ComputeKeyedStoreField(Handle<String> name,
|
|
|
|
Handle<JSObject> receiver,
|
2010-10-25 15:22:03 +00:00
|
|
|
int field_index,
|
2011-10-20 13:54:16 +00:00
|
|
|
Handle<Map> transition,
|
2011-03-02 04:53:43 +00:00
|
|
|
StrictModeFlag strict_mode) {
|
2011-10-20 13:54:16 +00:00
|
|
|
PropertyType type = (transition.is_null()) ? FIELD : MAP_TRANSITION;
|
2011-03-02 04:53:43 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(
|
|
|
|
Code::KEYED_STORE_IC, type, strict_mode);
|
2011-10-20 13:54:16 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
2012-02-10 12:36:05 +00:00
|
|
|
KeyedStoreStubCompiler compiler(isolate(), strict_mode,
|
|
|
|
DO_NOT_ALLOW_JSARRAY_GROWTH);
|
2011-10-20 13:54:16 +00:00
|
|
|
Handle<Code> code =
|
|
|
|
compiler.CompileStoreField(receiver, field_index, transition, name);
|
|
|
|
PROFILE(isolate_, CodeCreateEvent(Logger::KEYED_STORE_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_STORE_IC, *name, *code));
|
2011-10-20 17:08:53 +00:00
|
|
|
JSObject::UpdateMapCodeCache(receiver, name, code);
|
2008-07-03 15:10:15 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2011-10-20 13:54:16 +00:00
|
|
|
|
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
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallConstant(int argc,
|
2010-10-25 15:22:03 +00:00
|
|
|
Code::Kind kind,
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::ExtraICState extra_state,
|
|
|
|
Handle<String> name,
|
|
|
|
Handle<Object> object,
|
|
|
|
Handle<JSObject> holder,
|
|
|
|
Handle<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 =
|
2011-10-20 17:08:53 +00:00
|
|
|
IC::GetCodeCacheForObject(*object, *holder);
|
|
|
|
Handle<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-10-20 17:08:53 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(kind, CONSTANT_FUNCTION, extra_state,
|
|
|
|
cache_holder, argc);
|
|
|
|
Handle<Object> probe(map_holder->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
CallStubCompiler compiler(isolate_, argc, kind, extra_state, cache_holder);
|
|
|
|
Handle<Code> code =
|
|
|
|
compiler.CompileCallConstant(object, holder, function, name, check);
|
|
|
|
code->set_check_type(check);
|
|
|
|
ASSERT_EQ(flags, code->flags());
|
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_IC_TAG), *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_IC, *name, *code));
|
|
|
|
JSObject::UpdateMapCodeCache(map_holder, name, code);
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallField(int argc,
|
2010-10-25 15:22:03 +00:00
|
|
|
Code::Kind kind,
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::ExtraICState extra_state,
|
|
|
|
Handle<String> name,
|
|
|
|
Handle<Object> object,
|
|
|
|
Handle<JSObject> holder,
|
2010-10-25 15:22:03 +00:00
|
|
|
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 =
|
2011-10-20 17:08:53 +00:00
|
|
|
IC::GetCodeCacheForObject(*object, *holder);
|
|
|
|
Handle<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-10-20 17:08:53 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(kind, FIELD, extra_state,
|
|
|
|
cache_holder, argc);
|
|
|
|
Handle<Object> probe(map_holder->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
CallStubCompiler compiler(isolate_, argc, kind, extra_state, cache_holder);
|
|
|
|
Handle<Code> code =
|
|
|
|
compiler.CompileCallField(Handle<JSObject>::cast(object),
|
|
|
|
holder, index, name);
|
|
|
|
ASSERT_EQ(flags, code->flags());
|
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_IC_TAG), *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_IC, *name, *code));
|
|
|
|
JSObject::UpdateMapCodeCache(map_holder, name, code);
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallInterceptor(int argc,
|
|
|
|
Code::Kind kind,
|
|
|
|
Code::ExtraICState extra_state,
|
|
|
|
Handle<String> name,
|
|
|
|
Handle<Object> object,
|
|
|
|
Handle<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 =
|
2011-10-20 17:08:53 +00:00
|
|
|
IC::GetCodeCacheForObject(*object, *holder);
|
|
|
|
Handle<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-10-20 17:08:53 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(kind, INTERCEPTOR, extra_state,
|
|
|
|
cache_holder, argc);
|
|
|
|
Handle<Object> probe(map_holder->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
CallStubCompiler compiler(isolate(), argc, kind, extra_state, cache_holder);
|
|
|
|
Handle<Code> code =
|
|
|
|
compiler.CompileCallInterceptor(Handle<JSObject>::cast(object),
|
|
|
|
holder, name);
|
|
|
|
ASSERT_EQ(flags, code->flags());
|
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_IC_TAG), *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_IC, *name, *code));
|
|
|
|
JSObject::UpdateMapCodeCache(map_holder, name, code);
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallGlobal(int argc,
|
2010-10-25 15:22:03 +00:00
|
|
|
Code::Kind kind,
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::ExtraICState extra_state,
|
|
|
|
Handle<String> name,
|
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<GlobalObject> holder,
|
|
|
|
Handle<JSGlobalPropertyCell> cell,
|
|
|
|
Handle<JSFunction> function) {
|
2010-07-02 14:15:04 +00:00
|
|
|
InlineCacheHolderFlag cache_holder =
|
2011-10-20 17:08:53 +00:00
|
|
|
IC::GetCodeCacheForObject(*receiver, *holder);
|
|
|
|
Handle<JSObject> map_holder(IC::GetCodeCacheHolder(*receiver, cache_holder));
|
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(kind, NORMAL, extra_state,
|
|
|
|
cache_holder, argc);
|
|
|
|
Handle<Object> probe(map_holder->map()->FindInCodeCache(*name, flags));
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
CallStubCompiler compiler(isolate(), argc, kind, extra_state, cache_holder);
|
|
|
|
Handle<Code> code =
|
|
|
|
compiler.CompileCallGlobal(receiver, holder, cell, function, name);
|
|
|
|
ASSERT_EQ(flags, code->flags());
|
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_IC_TAG), *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_IC, *name, *code));
|
|
|
|
JSObject::UpdateMapCodeCache(map_holder, name, code);
|
2010-06-14 10:10:42 +00:00
|
|
|
return code;
|
2009-06-30 10:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
static void FillCache(Isolate* isolate, Handle<Code> code) {
|
2012-01-16 09:44:35 +00:00
|
|
|
Handle<UnseededNumberDictionary> dictionary =
|
|
|
|
UnseededNumberDictionary::Set(isolate->factory()->non_monomorphic_cache(),
|
|
|
|
code->flags(),
|
|
|
|
code);
|
2011-10-20 17:08:53 +00:00
|
|
|
isolate->heap()->public_set_non_monomorphic_cache(*dictionary);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-07 08:27:32 +00:00
|
|
|
Code* StubCache::FindCallInitialize(int argc,
|
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-10-20 17:08:53 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeFlags(kind, UNINITIALIZED, extra_state, NORMAL, argc);
|
|
|
|
|
|
|
|
// Use raw_unchecked... so we don't get assert failures during GC.
|
2012-01-16 09:44:35 +00:00
|
|
|
UnseededNumberDictionary* dictionary =
|
2011-10-20 17:08:53 +00:00
|
|
|
isolate()->heap()->raw_unchecked_non_monomorphic_cache();
|
|
|
|
int entry = dictionary->FindEntry(isolate(), flags);
|
|
|
|
ASSERT(entry != -1);
|
|
|
|
Object* code = dictionary->ValueAt(entry);
|
2008-07-03 15:10:15 +00:00
|
|
|
// This might be called during the marking phase of the collector
|
|
|
|
// hence the unchecked cast.
|
2011-10-20 17:08:53 +00:00
|
|
|
return reinterpret_cast<Code*>(code);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallInitialize(int argc,
|
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-10-20 17:08:53 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeFlags(kind, UNINITIALIZED, extra_state, NORMAL, argc);
|
2012-01-16 09:44:35 +00:00
|
|
|
Handle<UnseededNumberDictionary> cache =
|
|
|
|
isolate_->factory()->non_monomorphic_cache();
|
2011-10-20 17:08:53 +00:00
|
|
|
int entry = cache->FindEntry(isolate_, flags);
|
|
|
|
if (entry != -1) return Handle<Code>(Code::cast(cache->ValueAt(entry)));
|
|
|
|
|
2011-10-18 12:19:18 +00:00
|
|
|
StubCompiler compiler(isolate_);
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> code = compiler.CompileCallInitialize(flags);
|
|
|
|
FillCache(isolate_, code);
|
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallInitialize(int argc, RelocInfo::Mode mode) {
|
|
|
|
return ComputeCallInitialize(argc, mode, Code::CALL_IC);
|
2010-11-11 10:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-13 12:53:28 +00:00
|
|
|
Handle<Code> StubCache::ComputeKeyedCallInitialize(int argc) {
|
2011-10-20 17:28:14 +00:00
|
|
|
return ComputeCallInitialize(argc, RelocInfo::CODE_TARGET,
|
|
|
|
Code::KEYED_CALL_IC);
|
2010-11-11 10:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallPreMonomorphic(
|
2011-05-24 14:01:36 +00:00
|
|
|
int argc,
|
|
|
|
Code::Kind kind,
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::ExtraICState extra_state) {
|
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeFlags(kind, PREMONOMORPHIC, extra_state, NORMAL, argc);
|
2012-01-16 09:44:35 +00:00
|
|
|
Handle<UnseededNumberDictionary> cache =
|
|
|
|
isolate_->factory()->non_monomorphic_cache();
|
2011-10-20 17:08:53 +00:00
|
|
|
int entry = cache->FindEntry(isolate_, flags);
|
|
|
|
if (entry != -1) return Handle<Code>(Code::cast(cache->ValueAt(entry)));
|
|
|
|
|
2011-10-18 12:19:18 +00:00
|
|
|
StubCompiler compiler(isolate_);
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> code = compiler.CompileCallPreMonomorphic(flags);
|
|
|
|
FillCache(isolate_, code);
|
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallNormal(int argc,
|
2011-05-24 14:01:36 +00:00
|
|
|
Code::Kind kind,
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::ExtraICState extra_state) {
|
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeFlags(kind, MONOMORPHIC, extra_state, NORMAL, argc);
|
2012-01-16 09:44:35 +00:00
|
|
|
Handle<UnseededNumberDictionary> cache =
|
|
|
|
isolate_->factory()->non_monomorphic_cache();
|
2011-10-20 17:08:53 +00:00
|
|
|
int entry = cache->FindEntry(isolate_, flags);
|
|
|
|
if (entry != -1) return Handle<Code>(Code::cast(cache->ValueAt(entry)));
|
|
|
|
|
2011-10-18 12:19:18 +00:00
|
|
|
StubCompiler compiler(isolate_);
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> code = compiler.CompileCallNormal(flags);
|
|
|
|
FillCache(isolate_, code);
|
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallArguments(int argc, Code::Kind kind) {
|
2011-06-16 14:12:58 +00:00
|
|
|
ASSERT(kind == Code::KEYED_CALL_IC);
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeFlags(kind, MEGAMORPHIC, Code::kNoExtraICState,
|
|
|
|
NORMAL, argc);
|
2012-01-16 09:44:35 +00:00
|
|
|
Handle<UnseededNumberDictionary> cache =
|
|
|
|
isolate_->factory()->non_monomorphic_cache();
|
2011-10-20 17:08:53 +00:00
|
|
|
int entry = cache->FindEntry(isolate_, flags);
|
|
|
|
if (entry != -1) return Handle<Code>(Code::cast(cache->ValueAt(entry)));
|
|
|
|
|
2011-10-18 12:19:18 +00:00
|
|
|
StubCompiler compiler(isolate_);
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> code = compiler.CompileCallArguments(flags);
|
|
|
|
FillCache(isolate_, code);
|
|
|
|
return code;
|
2011-06-16 14:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallMegamorphic(
|
2011-05-24 14:01:36 +00:00
|
|
|
int argc,
|
|
|
|
Code::Kind kind,
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::ExtraICState extra_state) {
|
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeFlags(kind, MEGAMORPHIC, extra_state,
|
|
|
|
NORMAL, argc);
|
2012-01-16 09:44:35 +00:00
|
|
|
Handle<UnseededNumberDictionary> cache =
|
|
|
|
isolate_->factory()->non_monomorphic_cache();
|
2011-10-20 17:08:53 +00:00
|
|
|
int entry = cache->FindEntry(isolate_, flags);
|
|
|
|
if (entry != -1) return Handle<Code>(Code::cast(cache->ValueAt(entry)));
|
|
|
|
|
2011-10-18 12:19:18 +00:00
|
|
|
StubCompiler compiler(isolate_);
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> code = compiler.CompileCallMegamorphic(flags);
|
|
|
|
FillCache(isolate_, code);
|
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallMiss(int argc,
|
2011-05-24 14:01:36 +00:00
|
|
|
Code::Kind kind,
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::ExtraICState extra_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-10-20 17:08:53 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeFlags(kind, MONOMORPHIC_PROTOTYPE_FAILURE, extra_state,
|
|
|
|
NORMAL, argc, OWN_MAP);
|
2012-01-16 09:44:35 +00:00
|
|
|
Handle<UnseededNumberDictionary> cache =
|
|
|
|
isolate_->factory()->non_monomorphic_cache();
|
2011-10-20 17:08:53 +00:00
|
|
|
int entry = cache->FindEntry(isolate_, flags);
|
|
|
|
if (entry != -1) return Handle<Code>(Code::cast(cache->ValueAt(entry)));
|
|
|
|
|
|
|
|
StubCompiler compiler(isolate_);
|
|
|
|
Handle<Code> code = compiler.CompileCallMiss(flags);
|
|
|
|
FillCache(isolate_, code);
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallDebugBreak(int argc,
|
|
|
|
Code::Kind kind) {
|
2011-05-24 14:01:36 +00:00
|
|
|
// Extra IC state is irrelevant for debug break ICs. They jump to
|
|
|
|
// the actual call ic to carry out the work.
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeFlags(kind, DEBUG_BREAK, Code::kNoExtraICState,
|
|
|
|
NORMAL, argc);
|
2012-01-16 09:44:35 +00:00
|
|
|
Handle<UnseededNumberDictionary> cache =
|
|
|
|
isolate_->factory()->non_monomorphic_cache();
|
2011-10-20 17:08:53 +00:00
|
|
|
int entry = cache->FindEntry(isolate_, flags);
|
|
|
|
if (entry != -1) return Handle<Code>(Code::cast(cache->ValueAt(entry)));
|
|
|
|
|
2011-10-18 12:19:18 +00:00
|
|
|
StubCompiler compiler(isolate_);
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> code = compiler.CompileCallDebugBreak(flags);
|
|
|
|
FillCache(isolate_, code);
|
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallDebugPrepareStepIn(int argc,
|
|
|
|
Code::Kind kind) {
|
2011-05-24 14:01:36 +00:00
|
|
|
// Extra IC state is irrelevant for debug break ICs. They jump to
|
|
|
|
// the actual call ic to carry out the work.
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeFlags(kind, DEBUG_PREPARE_STEP_IN, Code::kNoExtraICState,
|
|
|
|
NORMAL, argc);
|
2012-01-16 09:44:35 +00:00
|
|
|
Handle<UnseededNumberDictionary> cache =
|
|
|
|
isolate_->factory()->non_monomorphic_cache();
|
2011-10-20 17:08:53 +00:00
|
|
|
int entry = cache->FindEntry(isolate_, flags);
|
|
|
|
if (entry != -1) return Handle<Code>(Code::cast(cache->ValueAt(entry)));
|
|
|
|
|
2011-10-18 12:19:18 +00:00
|
|
|
StubCompiler compiler(isolate_);
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> code = compiler.CompileCallDebugPrepareStepIn(flags);
|
|
|
|
FillCache(isolate_, code);
|
|
|
|
return code;
|
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() {
|
2011-09-28 10:32:12 +00:00
|
|
|
Code* empty = isolate_->builtins()->builtin(Builtins::kIllegal);
|
2008-07-03 15:10:15 +00:00
|
|
|
for (int i = 0; i < kPrimaryTableSize; i++) {
|
2011-09-29 11:52:05 +00:00
|
|
|
primary_[i].key = heap()->empty_string();
|
|
|
|
primary_[i].value = empty;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
for (int j = 0; j < kSecondaryTableSize; j++) {
|
2011-09-29 11:52:05 +00:00
|
|
|
secondary_[j].key = heap()->empty_string();
|
|
|
|
secondary_[j].value = empty;
|
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,
|
2011-12-14 14:01:54 +00:00
|
|
|
Code::Flags flags,
|
|
|
|
Handle<Context> global_context) {
|
2010-12-07 11:31:57 +00:00
|
|
|
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);
|
2011-12-14 14:01:54 +00:00
|
|
|
if (entry(primary_, offset) == &primary_[i] &&
|
|
|
|
!TypeFeedbackOracle::CanRetainOtherContext(map, *global_context)) {
|
2010-12-07 11:31:57 +00:00
|
|
|
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);
|
2011-12-14 14:01:54 +00:00
|
|
|
if (entry(secondary_, offset) == &secondary_[i] &&
|
|
|
|
!TypeFeedbackOracle::CanRetainOtherContext(map, *global_context)) {
|
2010-12-07 11:31:57 +00:00
|
|
|
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-10-28 09:10:29 +00:00
|
|
|
ASSERT(args.smi_at(3) == kStrictMode || args.smi_at(3) == kNonStrictMode);
|
2011-06-10 12:15:30 +00:00
|
|
|
StrictModeFlag strict_mode = static_cast<StrictModeFlag>(args.smi_at(3));
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCompiler::CompileCallInitialize(Code::Flags flags) {
|
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-10-20 17:08:53 +00:00
|
|
|
Code::ExtraICState extra_state = Code::ExtractExtraICStateFromFlags(flags);
|
2010-06-07 08:27:32 +00:00
|
|
|
if (kind == Code::CALL_IC) {
|
2011-10-20 17:08:53 +00:00
|
|
|
CallIC::GenerateInitialize(masm(), argc, extra_state);
|
2010-06-07 08:27:32 +00:00
|
|
|
} else {
|
|
|
|
KeyedCallIC::GenerateInitialize(masm(), argc);
|
|
|
|
}
|
2011-10-21 10:19:16 +00:00
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, "CompileCallInitialize");
|
2011-03-23 11:13:07 +00:00
|
|
|
isolate()->counters()->call_initialize_stubs()->Increment();
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_INITIALIZE_TAG),
|
2011-10-21 10:19:16 +00:00
|
|
|
*code, code->arguments_count()));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_INITIALIZE, *code));
|
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCompiler::CompileCallPreMonomorphic(Code::Flags flags) {
|
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-10-20 17:08:53 +00:00
|
|
|
Code::ExtraICState extra_state = Code::ExtractExtraICStateFromFlags(flags);
|
2010-06-07 08:27:32 +00:00
|
|
|
if (kind == Code::CALL_IC) {
|
2011-10-20 17:08:53 +00:00
|
|
|
CallIC::GenerateInitialize(masm(), argc, extra_state);
|
2010-06-07 08:27:32 +00:00
|
|
|
} else {
|
|
|
|
KeyedCallIC::GenerateInitialize(masm(), argc);
|
|
|
|
}
|
2011-10-24 09:33:11 +00:00
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, "CompileCallPreMonomorphic");
|
2011-03-23 11:13:07 +00:00
|
|
|
isolate()->counters()->call_premonomorphic_stubs()->Increment();
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_PRE_MONOMORPHIC_TAG),
|
2011-10-24 09:33:11 +00:00
|
|
|
*code, code->arguments_count()));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_PRE_MONOMORPHIC, *code));
|
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCompiler::CompileCallNormal(Code::Flags flags) {
|
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);
|
|
|
|
}
|
2011-10-24 09:33:11 +00:00
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, "CompileCallNormal");
|
2011-03-23 11:13:07 +00:00
|
|
|
isolate()->counters()->call_normal_stubs()->Increment();
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_NORMAL_TAG),
|
2011-10-24 09:33:11 +00:00
|
|
|
*code, code->arguments_count()));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_NORMAL, *code));
|
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCompiler::CompileCallMegamorphic(Code::Flags flags) {
|
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-10-20 17:08:53 +00:00
|
|
|
Code::ExtraICState extra_state = Code::ExtractExtraICStateFromFlags(flags);
|
2010-06-07 08:27:32 +00:00
|
|
|
if (kind == Code::CALL_IC) {
|
2011-10-20 17:08:53 +00:00
|
|
|
CallIC::GenerateMegamorphic(masm(), argc, extra_state);
|
2010-06-07 08:27:32 +00:00
|
|
|
} else {
|
|
|
|
KeyedCallIC::GenerateMegamorphic(masm(), argc);
|
|
|
|
}
|
2011-10-24 10:55:00 +00:00
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, "CompileCallMegamorphic");
|
2011-03-23 11:13:07 +00:00
|
|
|
isolate()->counters()->call_megamorphic_stubs()->Increment();
|
2011-06-16 14:12:58 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_MEGAMORPHIC_TAG),
|
2011-10-24 10:55:00 +00:00
|
|
|
*code, code->arguments_count()));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_MEGAMORPHIC, *code));
|
|
|
|
return code;
|
2011-06-16 14:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCompiler::CompileCallArguments(Code::Flags flags) {
|
2011-06-16 14:12:58 +00:00
|
|
|
int argc = Code::ExtractArgumentsCountFromFlags(flags);
|
|
|
|
KeyedCallIC::GenerateNonStrictArguments(masm(), argc);
|
2011-10-24 10:55:00 +00:00
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, "CompileCallArguments");
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
2011-10-24 10:55:00 +00:00
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(Code::ExtractKindFromFlags(flags),
|
|
|
|
CALL_MEGAMORPHIC_TAG),
|
|
|
|
*code, code->arguments_count()));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_MEGAMORPHIC, *code));
|
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCompiler::CompileCallMiss(Code::Flags flags) {
|
2011-10-24 09:33:11 +00:00
|
|
|
int argc = Code::ExtractArgumentsCountFromFlags(flags);
|
|
|
|
Code::Kind kind = Code::ExtractKindFromFlags(flags);
|
|
|
|
Code::ExtraICState extra_state = Code::ExtractExtraICStateFromFlags(flags);
|
|
|
|
if (kind == Code::CALL_IC) {
|
|
|
|
CallIC::GenerateMiss(masm(), argc, extra_state);
|
|
|
|
} else {
|
|
|
|
KeyedCallIC::GenerateMiss(masm(), argc);
|
|
|
|
}
|
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, "CompileCallMiss");
|
|
|
|
isolate()->counters()->call_megamorphic_stubs()->Increment();
|
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_MISS_TAG),
|
|
|
|
*code, code->arguments_count()));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_MISS, *code));
|
|
|
|
return code;
|
2011-10-20 17:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCompiler::CompileCallDebugBreak(Code::Flags flags) {
|
2008-12-09 11:12:14 +00:00
|
|
|
Debug::GenerateCallICDebugBreak(masm());
|
2011-10-24 10:55:00 +00:00
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, "CompileCallDebugBreak");
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
2011-10-24 10:55:00 +00:00
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(Code::ExtractKindFromFlags(flags),
|
|
|
|
CALL_DEBUG_BREAK_TAG),
|
|
|
|
*code, code->arguments_count()));
|
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCompiler::CompileCallDebugPrepareStepIn(Code::Flags flags) {
|
2011-10-24 10:55:00 +00:00
|
|
|
// Use the same code for the the step in preparations as we do for the
|
|
|
|
// miss case.
|
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
|
|
|
// 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);
|
|
|
|
}
|
2011-10-24 10:55:00 +00:00
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, "CompileCallDebugPrepareStepIn");
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(
|
|
|
|
CALL_LOGGER_TAG(kind, CALL_DEBUG_PREPARE_STEP_IN_TAG),
|
2011-10-24 10:55:00 +00:00
|
|
|
*code,
|
2011-03-18 20:35:07 +00:00
|
|
|
code->arguments_count()));
|
2011-10-24 10:55:00 +00:00
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-10-24 10:55:00 +00:00
|
|
|
#endif // ENABLE_DEBUGGER_SUPPORT
|
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
|
|
|
|
2011-10-24 10:55:00 +00:00
|
|
|
|
2011-10-21 10:19:16 +00:00
|
|
|
Handle<Code> StubCompiler::GetCodeWithFlags(Code::Flags flags,
|
2010-10-25 15:22:03 +00:00
|
|
|
const char* name) {
|
2011-10-21 10:19:16 +00:00
|
|
|
// Create code object in the heap.
|
|
|
|
CodeDesc desc;
|
|
|
|
masm_.GetCode(&desc);
|
|
|
|
Handle<Code> code = factory()->NewCode(desc, flags, masm_.CodeObject());
|
|
|
|
#ifdef ENABLE_DISASSEMBLER
|
|
|
|
if (FLAG_print_code_stubs) code->Disassemble(name);
|
|
|
|
#endif
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-25 09:24:49 +00:00
|
|
|
Handle<Code> StubCompiler::GetCodeWithFlags(Code::Flags flags,
|
|
|
|
Handle<String> name) {
|
|
|
|
return (FLAG_print_code_stubs && !name.is_null())
|
|
|
|
? GetCodeWithFlags(flags, *name->ToCString())
|
|
|
|
: GetCodeWithFlags(flags, reinterpret_cast<char*>(NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-28 12:37:29 +00:00
|
|
|
void StubCompiler::LookupPostInterceptor(Handle<JSObject> holder,
|
|
|
|
Handle<String> name,
|
2010-02-02 11:32:17 +00:00
|
|
|
LookupResult* lookup) {
|
2011-10-28 12:37:29 +00:00
|
|
|
holder->LocalLookupRealNamedProperty(*name, lookup);
|
|
|
|
if (lookup->IsProperty()) return;
|
|
|
|
|
|
|
|
lookup->NotFound();
|
|
|
|
if (holder->GetPrototype()->IsNull()) return;
|
|
|
|
|
|
|
|
holder->GetPrototype()->Lookup(*name, lookup);
|
2010-02-02 11:32:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-25 12:26:07 +00:00
|
|
|
Handle<Code> LoadStubCompiler::GetCode(PropertyType type, Handle<String> name) {
|
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, type);
|
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, name);
|
|
|
|
PROFILE(isolate(), CodeCreateEvent(Logger::LOAD_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, *name, *code));
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2009-03-04 06:14:34 +00:00
|
|
|
|
2011-10-25 12:26:07 +00:00
|
|
|
Handle<Code> KeyedLoadStubCompiler::GetCode(PropertyType type,
|
|
|
|
Handle<String> name,
|
|
|
|
InlineCacheState state) {
|
|
|
|
Code::Flags flags = Code::ComputeFlags(
|
|
|
|
Code::KEYED_LOAD_IC, state, Code::kNoExtraICState, type);
|
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, name);
|
|
|
|
PROFILE(isolate(), CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, *name, *code));
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-10-26 10:45:24 +00:00
|
|
|
Handle<Code> StoreStubCompiler::GetCode(PropertyType type,
|
|
|
|
Handle<String> name) {
|
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeMonomorphicFlags(Code::STORE_IC, type, strict_mode_);
|
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, name);
|
|
|
|
PROFILE(isolate(), CodeCreateEvent(Logger::STORE_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::STORE_IC, *name, *code));
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> KeyedStoreStubCompiler::GetCode(PropertyType type,
|
|
|
|
Handle<String> name,
|
2011-05-18 13:17:29 +00:00
|
|
|
InlineCacheState state) {
|
2012-02-10 12:36:05 +00:00
|
|
|
Code::ExtraICState extra_state =
|
|
|
|
Code::ComputeExtraICState(grow_mode_, strict_mode_);
|
2011-09-13 12:53:28 +00:00
|
|
|
Code::Flags flags =
|
2012-02-10 12:36:05 +00:00
|
|
|
Code::ComputeFlags(Code::KEYED_STORE_IC, state, extra_state, type);
|
2011-10-26 10:45:24 +00:00
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, name);
|
|
|
|
PROFILE(isolate(), CodeCreateEvent(Logger::KEYED_STORE_IC_TAG, *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::KEYED_STORE_IC, *name, *code));
|
|
|
|
return code;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-18 12:19:18 +00:00
|
|
|
CallStubCompiler::CallStubCompiler(Isolate* isolate,
|
|
|
|
int argc,
|
2010-07-02 14:15:04 +00:00
|
|
|
Code::Kind kind,
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::ExtraICState extra_state,
|
2010-07-02 14:15:04 +00:00
|
|
|
InlineCacheHolderFlag cache_holder)
|
2011-10-18 12:19:18 +00:00
|
|
|
: StubCompiler(isolate),
|
|
|
|
arguments_(argc),
|
2011-01-18 16:54:48 +00:00
|
|
|
kind_(kind),
|
2011-10-20 17:08:53 +00:00
|
|
|
extra_state_(extra_state),
|
2011-01-18 16:54:48 +00:00
|
|
|
cache_holder_(cache_holder) {
|
2010-07-02 14:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-28 12:37:29 +00:00
|
|
|
bool CallStubCompiler::HasCustomCallGenerator(Handle<JSFunction> function) {
|
|
|
|
if (function->shared()->HasBuiltinFunctionId()) {
|
|
|
|
BuiltinFunctionId id = function->shared()->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
|
|
|
}
|
2011-10-28 12:37:29 +00:00
|
|
|
|
2011-03-17 17:25:54 +00:00
|
|
|
CallOptimization optimization(function);
|
2011-10-28 12:37:29 +00:00
|
|
|
return optimization.is_simple_api_call();
|
2010-12-14 18:53:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-28 12:37:29 +00:00
|
|
|
Handle<Code> CallStubCompiler::CompileCustomCall(
|
|
|
|
Handle<Object> object,
|
|
|
|
Handle<JSObject> holder,
|
|
|
|
Handle<JSGlobalPropertyCell> cell,
|
|
|
|
Handle<JSFunction> function,
|
|
|
|
Handle<String> fname) {
|
2011-03-17 17:25:54 +00:00
|
|
|
ASSERT(HasCustomCallGenerator(function));
|
|
|
|
|
2011-10-28 12:37:29 +00:00
|
|
|
if (function->shared()->HasBuiltinFunctionId()) {
|
|
|
|
BuiltinFunctionId id = function->shared()->builtin_function_id();
|
|
|
|
#define CALL_GENERATOR_CASE(name) \
|
|
|
|
if (id == k##name) { \
|
|
|
|
return CallStubCompiler::Compile##name##Call(object, \
|
|
|
|
holder, \
|
|
|
|
cell, \
|
|
|
|
function, \
|
|
|
|
fname); \
|
2011-03-17 17:25:54 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-25 09:24:49 +00:00
|
|
|
Handle<Code> CallStubCompiler::GetCode(PropertyType type, Handle<String> name) {
|
|
|
|
int argc = arguments_.immediate();
|
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(kind_,
|
|
|
|
type,
|
|
|
|
extra_state_,
|
|
|
|
cache_holder_,
|
|
|
|
argc);
|
|
|
|
return GetCodeWithFlags(flags, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> CallStubCompiler::GetCode(Handle<JSFunction> function) {
|
|
|
|
Handle<String> function_name;
|
|
|
|
if (function->shared()->name()->IsString()) {
|
|
|
|
function_name = Handle<String>(String::cast(function->shared()->name()));
|
|
|
|
}
|
|
|
|
return GetCode(CONSTANT_FUNCTION, function_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-28 14:08:43 +00:00
|
|
|
Handle<Code> ConstructStubCompiler::GetCode() {
|
2009-08-26 12:22:44 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(Code::STUB);
|
2011-10-28 14:08:43 +00:00
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, "ConstructStub");
|
|
|
|
PROFILE(isolate(), CodeCreateEvent(Logger::STUB_TAG, *code, "ConstructStub"));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::STUB, "ConstructStub", *code));
|
|
|
|
return code;
|
2009-08-26 12:22:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-28 14:06:35 +00:00
|
|
|
CallOptimization::CallOptimization(LookupResult* lookup) {
|
2012-01-23 12:01:47 +00:00
|
|
|
if (lookup->IsFound() &&
|
|
|
|
lookup->IsCacheable() &&
|
|
|
|
lookup->type() == CONSTANT_FUNCTION) {
|
2010-04-28 14:06:35 +00:00
|
|
|
// We only optimize constant function calls.
|
2011-10-28 12:37:29 +00:00
|
|
|
Initialize(Handle<JSFunction>(lookup->GetConstantFunction()));
|
2012-01-23 12:01:47 +00:00
|
|
|
} else {
|
|
|
|
Initialize(Handle<JSFunction>::null());
|
2010-04-28 14:06:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-28 12:37:29 +00:00
|
|
|
CallOptimization::CallOptimization(Handle<JSFunction> function) {
|
2010-04-28 14:06:35 +00:00
|
|
|
Initialize(function);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-28 12:37:29 +00:00
|
|
|
int CallOptimization::GetPrototypeDepthOfExpectedType(
|
|
|
|
Handle<JSObject> object,
|
|
|
|
Handle<JSObject> holder) const {
|
|
|
|
ASSERT(is_simple_api_call());
|
|
|
|
if (expected_receiver_type_.is_null()) return 0;
|
2010-04-28 14:06:35 +00:00
|
|
|
int depth = 0;
|
2011-10-28 12:37:29 +00:00
|
|
|
while (!object.is_identical_to(holder)) {
|
|
|
|
if (object->IsInstanceOf(*expected_receiver_type_)) return depth;
|
|
|
|
object = Handle<JSObject>(JSObject::cast(object->GetPrototype()));
|
2010-04-28 14:06:35 +00:00
|
|
|
++depth;
|
|
|
|
}
|
2011-10-28 12:37:29 +00:00
|
|
|
if (holder->IsInstanceOf(*expected_receiver_type_)) return depth;
|
2010-04-28 14:06:35 +00:00
|
|
|
return kInvalidProtoDepth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-28 12:37:29 +00:00
|
|
|
void CallOptimization::Initialize(Handle<JSFunction> function) {
|
|
|
|
constant_function_ = Handle<JSFunction>::null();
|
2010-04-28 14:06:35 +00:00
|
|
|
is_simple_api_call_ = false;
|
2011-10-28 12:37:29 +00:00
|
|
|
expected_receiver_type_ = Handle<FunctionTemplateInfo>::null();
|
|
|
|
api_call_info_ = Handle<CallHandlerInfo>::null();
|
2010-04-28 14:06:35 +00:00
|
|
|
|
2011-10-28 12:37:29 +00:00
|
|
|
if (function.is_null() || !function->is_compiled()) return;
|
2010-04-28 14:06:35 +00:00
|
|
|
|
|
|
|
constant_function_ = function;
|
|
|
|
AnalyzePossibleApiFunction(function);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-28 12:37:29 +00:00
|
|
|
void CallOptimization::AnalyzePossibleApiFunction(Handle<JSFunction> function) {
|
|
|
|
if (!function->shared()->IsApiFunction()) return;
|
|
|
|
Handle<FunctionTemplateInfo> info(function->shared()->get_api_func_data());
|
2010-04-28 14:06:35 +00:00
|
|
|
|
|
|
|
// Require a C++ callback.
|
|
|
|
if (info->call_code()->IsUndefined()) return;
|
2011-10-28 12:37:29 +00:00
|
|
|
api_call_info_ =
|
|
|
|
Handle<CallHandlerInfo>(CallHandlerInfo::cast(info->call_code()));
|
2010-04-28 14:06:35 +00:00
|
|
|
|
|
|
|
// Accept signatures that either have no restrictions at all or
|
|
|
|
// only have restrictions on the receiver.
|
|
|
|
if (!info->signature()->IsUndefined()) {
|
2011-10-28 12:37:29 +00:00
|
|
|
Handle<SignatureInfo> signature =
|
|
|
|
Handle<SignatureInfo>(SignatureInfo::cast(info->signature()));
|
2010-04-28 14:06:35 +00:00
|
|
|
if (!signature->args()->IsUndefined()) return;
|
|
|
|
if (!signature->receiver()->IsUndefined()) {
|
|
|
|
expected_receiver_type_ =
|
2011-10-28 12:37:29 +00:00
|
|
|
Handle<FunctionTemplateInfo>(
|
|
|
|
FunctionTemplateInfo::cast(signature->receiver()));
|
2010-04-28 14:06:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
is_simple_api_call_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|