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"
|
2013-07-03 15:39:18 +00:00
|
|
|
#include "cpu-profiler.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"
|
2013-12-20 13:33:20 +00:00
|
|
|
#include "type-info.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.
|
|
|
|
|
|
|
|
|
2013-06-26 13:36:16 +00:00
|
|
|
StubCache::StubCache(Isolate* isolate)
|
2013-09-05 11:27:22 +00:00
|
|
|
: isolate_(isolate) { }
|
2011-03-18 20:35:07 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
Code* StubCache::Set(Name* name, Map* map, Code* code) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// 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
|
2013-03-04 15:00:57 +00:00
|
|
|
// can use identity checks instead of structural equality checks.
|
2011-03-30 08:18:56 +00:00
|
|
|
ASSERT(!heap()->InNewSpace(name));
|
2013-03-04 15:00:57 +00:00
|
|
|
ASSERT(name->IsUniqueName());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// 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);
|
2012-02-29 10:45:59 +00:00
|
|
|
Code* old_code = primary->value;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// If the primary entry has useful data in it, we retire it to the
|
|
|
|
// secondary cache before overwriting it.
|
2012-02-29 10:45:59 +00:00
|
|
|
if (old_code != isolate_->builtins()->builtin(Builtins::kIllegal)) {
|
|
|
|
Map* old_map = primary->map;
|
|
|
|
Code::Flags old_flags = Code::RemoveTypeFromFlags(old_code->flags());
|
|
|
|
int seed = PrimaryOffset(primary->key, old_flags, old_map);
|
|
|
|
int secondary_offset = SecondaryOffset(primary->key, old_flags, seed);
|
2008-07-03 15:10:15 +00:00
|
|
|
Entry* secondary = entry(secondary_, secondary_offset);
|
|
|
|
*secondary = *primary;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update primary cache.
|
|
|
|
primary->key = name;
|
|
|
|
primary->value = code;
|
2012-02-29 10:45:59 +00:00
|
|
|
primary->map = map;
|
|
|
|
isolate()->counters()->megamorphic_stub_cache_updates()->Increment();
|
2008-07-03 15:10:15 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-05 17:38:35 +00:00
|
|
|
Handle<Code> StubCache::FindIC(Handle<Name> name,
|
2013-11-22 15:08:22 +00:00
|
|
|
Handle<Map> stub_holder,
|
2013-03-05 17:38:35 +00:00
|
|
|
Code::Kind kind,
|
2013-11-28 15:32:55 +00:00
|
|
|
ExtraICState extra_state,
|
2013-11-14 16:25:31 +00:00
|
|
|
InlineCacheHolderFlag cache_holder) {
|
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(
|
|
|
|
kind, extra_state, cache_holder);
|
2013-11-22 15:08:22 +00:00
|
|
|
Handle<Object> probe(stub_holder->FindInCodeCache(*name, flags), isolate_);
|
2013-03-04 14:03:27 +00:00
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
return Handle<Code>::null();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-11 13:48:14 +00:00
|
|
|
Handle<Code> StubCache::FindHandler(Handle<Name> name,
|
2013-11-22 15:08:22 +00:00
|
|
|
Handle<Map> stub_holder,
|
2013-10-11 13:48:14 +00:00
|
|
|
Code::Kind kind,
|
2013-11-28 18:13:30 +00:00
|
|
|
InlineCacheHolderFlag cache_holder) {
|
2013-07-09 08:22:41 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(
|
2013-11-28 18:13:30 +00:00
|
|
|
Code::HANDLER, kNoExtraICState, cache_holder, Code::NORMAL, kind);
|
2013-11-14 16:25:31 +00:00
|
|
|
|
2013-11-22 15:08:22 +00:00
|
|
|
Handle<Object> probe(stub_holder->FindInCodeCache(*name, flags), isolate_);
|
2013-07-09 08:22:41 +00:00
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
return Handle<Code>::null();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-28 15:32:55 +00:00
|
|
|
Handle<Code> StubCache::ComputeMonomorphicIC(
|
|
|
|
Handle<Name> name,
|
|
|
|
Handle<Type> type,
|
|
|
|
Handle<Code> handler,
|
|
|
|
ExtraICState extra_ic_state) {
|
2013-10-01 09:30:07 +00:00
|
|
|
Code::Kind kind = handler->handler_kind();
|
2013-11-18 17:18:14 +00:00
|
|
|
InlineCacheHolderFlag flag = IC::GetCodeCacheFlag(*type);
|
|
|
|
|
|
|
|
Handle<Map> stub_holder;
|
|
|
|
Handle<Code> ic;
|
|
|
|
// There are multiple string maps that all use the same prototype. That
|
|
|
|
// prototype cannot hold multiple handlers, one for each of the string maps,
|
|
|
|
// for a single name. Hence, turn off caching of the IC.
|
|
|
|
bool can_be_cached = !type->Is(Type::String());
|
|
|
|
if (can_be_cached) {
|
|
|
|
stub_holder = IC::GetCodeCacheHolder(flag, *type, isolate());
|
2013-11-28 15:32:55 +00:00
|
|
|
ic = FindIC(name, stub_holder, kind, extra_ic_state, flag);
|
2013-11-18 17:18:14 +00:00
|
|
|
if (!ic.is_null()) return ic;
|
|
|
|
}
|
2013-03-04 14:03:27 +00:00
|
|
|
|
2013-10-01 09:30:07 +00:00
|
|
|
if (kind == Code::LOAD_IC) {
|
2014-01-07 14:14:34 +00:00
|
|
|
LoadStubCompiler ic_compiler(isolate(), extra_ic_state, flag);
|
2013-11-18 17:18:14 +00:00
|
|
|
ic = ic_compiler.CompileMonomorphicIC(type, handler, name);
|
2013-10-01 09:30:07 +00:00
|
|
|
} else if (kind == Code::KEYED_LOAD_IC) {
|
2014-01-07 14:14:34 +00:00
|
|
|
KeyedLoadStubCompiler ic_compiler(isolate(), extra_ic_state, flag);
|
2013-11-18 17:18:14 +00:00
|
|
|
ic = ic_compiler.CompileMonomorphicIC(type, handler, name);
|
2013-10-01 09:30:07 +00:00
|
|
|
} else if (kind == Code::STORE_IC) {
|
2013-12-02 11:59:44 +00:00
|
|
|
StoreStubCompiler ic_compiler(isolate(), extra_ic_state);
|
2013-11-18 17:18:14 +00:00
|
|
|
ic = ic_compiler.CompileMonomorphicIC(type, handler, name);
|
2013-10-01 09:30:07 +00:00
|
|
|
} else {
|
|
|
|
ASSERT(kind == Code::KEYED_STORE_IC);
|
2013-12-02 11:59:44 +00:00
|
|
|
ASSERT(STANDARD_STORE ==
|
|
|
|
KeyedStoreIC::GetKeyedAccessStoreMode(extra_ic_state));
|
|
|
|
KeyedStoreStubCompiler ic_compiler(isolate(), extra_ic_state);
|
2013-11-18 17:18:14 +00:00
|
|
|
ic = ic_compiler.CompileMonomorphicIC(type, handler, name);
|
2013-10-01 09:30:07 +00:00
|
|
|
}
|
2013-07-09 08:22:41 +00:00
|
|
|
|
2013-11-18 17:18:14 +00:00
|
|
|
if (can_be_cached) Map::UpdateCodeCache(stub_holder, name, ic);
|
2013-07-09 08:22:41 +00:00
|
|
|
return ic;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Code> StubCache::ComputeLoadNonexistent(Handle<Name> name,
|
2013-11-22 15:08:22 +00:00
|
|
|
Handle<Type> type) {
|
|
|
|
InlineCacheHolderFlag flag = IC::GetCodeCacheFlag(*type);
|
|
|
|
Handle<Map> stub_holder = IC::GetCodeCacheHolder(flag, *type, isolate());
|
|
|
|
// If no dictionary mode 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 dictionary
|
|
|
|
// mode objects involved, we need to do negative lookups in the stub and
|
|
|
|
// therefore the stub will be specific to the name.
|
|
|
|
Handle<Map> current_map = stub_holder;
|
|
|
|
Handle<Name> cache_name = current_map->is_dictionary_map()
|
|
|
|
? name : Handle<Name>::cast(isolate()->factory()->empty_string());
|
|
|
|
Handle<Object> next(current_map->prototype(), isolate());
|
|
|
|
Handle<JSObject> last = Handle<JSObject>::null();
|
|
|
|
while (!next->IsNull()) {
|
|
|
|
last = Handle<JSObject>::cast(next);
|
|
|
|
next = handle(current_map->prototype(), isolate());
|
|
|
|
current_map = handle(Handle<HeapObject>::cast(next)->map());
|
|
|
|
if (current_map->is_dictionary_map()) cache_name = name;
|
|
|
|
}
|
2013-01-31 16:18:18 +00:00
|
|
|
|
2010-04-15 11:25:41 +00:00
|
|
|
// Compile the stub that is either shared for all names or
|
|
|
|
// name specific if there are global objects involved.
|
2013-11-14 16:25:31 +00:00
|
|
|
Handle<Code> handler = FindHandler(
|
2013-11-22 15:08:22 +00:00
|
|
|
cache_name, stub_holder, Code::LOAD_IC, flag);
|
2013-03-04 14:03:27 +00:00
|
|
|
if (!handler.is_null()) return handler;
|
2011-10-18 12:19:18 +00:00
|
|
|
|
2013-11-22 15:08:22 +00:00
|
|
|
LoadStubCompiler compiler(isolate_, flag);
|
|
|
|
handler = compiler.CompileLoadNonexistent(type, last, cache_name);
|
|
|
|
Map::UpdateCodeCache(stub_holder, cache_name, handler);
|
2013-03-04 14:03:27 +00:00
|
|
|
return handler;
|
2010-04-15 11:25:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-23 15:35:43 +00:00
|
|
|
Handle<Code> StubCache::ComputeKeyedLoadElement(Handle<Map> receiver_map) {
|
2013-02-27 15:33:37 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC);
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> name =
|
2013-02-28 17:03:34 +00:00
|
|
|
isolate()->factory()->KeyedLoadElementMonomorphic_string();
|
2013-01-23 15:35:43 +00:00
|
|
|
|
|
|
|
Handle<Object> probe(receiver_map->FindInCodeCache(*name, flags), isolate_);
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
KeyedLoadStubCompiler compiler(isolate());
|
|
|
|
Handle<Code> code = compiler.CompileLoadElement(receiver_map);
|
|
|
|
|
|
|
|
Map::UpdateCodeCache(receiver_map, name, code);
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> StubCache::ComputeKeyedStoreElement(
|
2012-06-08 13:06:24 +00:00
|
|
|
Handle<Map> receiver_map,
|
2013-01-23 15:35:43 +00:00
|
|
|
StrictModeFlag strict_mode,
|
2013-03-06 21:51:07 +00:00
|
|
|
KeyedAccessStoreMode store_mode) {
|
2013-11-28 15:32:55 +00:00
|
|
|
ExtraICState extra_state =
|
|
|
|
KeyedStoreIC::ComputeExtraICState(strict_mode, store_mode);
|
2013-01-23 15:35:43 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(
|
2013-02-27 15:33:37 +00:00
|
|
|
Code::KEYED_STORE_IC, extra_state);
|
2013-01-23 15:35:43 +00:00
|
|
|
|
2013-03-06 21:51:07 +00:00
|
|
|
ASSERT(store_mode == STANDARD_STORE ||
|
2013-03-20 10:37:13 +00:00
|
|
|
store_mode == STORE_AND_GROW_NO_TRANSITION ||
|
|
|
|
store_mode == STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS ||
|
|
|
|
store_mode == STORE_NO_TRANSITION_HANDLE_COW);
|
2013-01-23 15:35:43 +00:00
|
|
|
|
2013-03-06 21:51:07 +00:00
|
|
|
Handle<String> name =
|
|
|
|
isolate()->factory()->KeyedStoreElementMonomorphic_string();
|
2012-11-16 08:38:11 +00:00
|
|
|
Handle<Object> probe(receiver_map->FindInCodeCache(*name, flags), isolate_);
|
2011-10-21 11:42:54 +00:00
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
2011-05-18 13:17:29 +00:00
|
|
|
|
2013-12-02 11:59:44 +00:00
|
|
|
KeyedStoreStubCompiler compiler(isolate(), extra_state);
|
2013-01-23 15:35:43 +00:00
|
|
|
Handle<Code> code = compiler.CompileStoreElement(receiver_map);
|
2011-10-11 09:33:00 +00:00
|
|
|
|
2012-06-08 13:06:24 +00:00
|
|
|
Map::UpdateCodeCache(receiver_map, name, code);
|
2013-11-28 15:32:55 +00:00
|
|
|
ASSERT(KeyedStoreIC::GetKeyedAccessStoreMode(code->extra_ic_state())
|
|
|
|
== store_mode);
|
2011-01-21 23:58:00 +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
|
|
|
|
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,
|
2013-11-28 15:32:55 +00:00
|
|
|
ExtraICState extra_state,
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> name,
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Object> object,
|
|
|
|
Handle<JSObject> holder,
|
|
|
|
Handle<JSFunction> function) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Compute the check type and the map.
|
2013-11-14 16:25:31 +00:00
|
|
|
InlineCacheHolderFlag cache_holder = IC::GetCodeCacheForObject(*object);
|
|
|
|
Handle<HeapObject> stub_holder(IC::GetCodeCacheHolder(
|
2013-03-04 14:03:27 +00:00
|
|
|
isolate_, *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;
|
2013-03-01 13:28:55 +00:00
|
|
|
} else if (object->IsSymbol()) {
|
|
|
|
check = SYMBOL_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
|
|
|
}
|
|
|
|
|
2013-02-06 11:48:29 +00:00
|
|
|
if (check != RECEIVER_MAP_CHECK &&
|
|
|
|
!function->IsBuiltin() &&
|
|
|
|
function->shared()->is_classic_mode()) {
|
|
|
|
// Calling non-strict non-builtins with a value as the receiver
|
|
|
|
// requires boxing.
|
|
|
|
return Handle<Code>::null();
|
|
|
|
}
|
|
|
|
|
2013-02-27 15:33:37 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(
|
2013-11-19 12:04:54 +00:00
|
|
|
kind, extra_state, cache_holder, Code::FAST, argc);
|
2013-03-04 14:03:27 +00:00
|
|
|
Handle<Object> probe(stub_holder->map()->FindInCodeCache(*name, flags),
|
2012-11-16 08:38:11 +00:00
|
|
|
isolate_);
|
2011-10-20 17:08:53 +00:00
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
|
|
|
CallStubCompiler compiler(isolate_, argc, kind, extra_state, cache_holder);
|
|
|
|
Handle<Code> code =
|
2013-02-06 11:48:29 +00:00
|
|
|
compiler.CompileCallConstant(object, holder, name, check, function);
|
2011-10-20 17:08:53 +00:00
|
|
|
code->set_check_type(check);
|
2013-03-18 13:35:17 +00:00
|
|
|
ASSERT(flags == code->flags());
|
2011-10-20 17:08:53 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_IC_TAG), *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_IC, *name, *code));
|
2013-06-19 09:25:24 +00:00
|
|
|
|
|
|
|
if (CallStubCompiler::CanBeCached(function)) {
|
2013-09-12 22:04:04 +00:00
|
|
|
HeapObject::UpdateMapCodeCache(stub_holder, name, code);
|
2013-06-19 09:25:24 +00:00
|
|
|
}
|
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,
|
2013-11-28 15:32:55 +00:00
|
|
|
ExtraICState extra_state,
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> name,
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Object> object,
|
|
|
|
Handle<JSObject> holder,
|
2012-11-13 11:07:04 +00:00
|
|
|
PropertyIndex index) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Compute the check type and the map.
|
2013-11-14 16:25:31 +00:00
|
|
|
InlineCacheHolderFlag cache_holder = IC::GetCodeCacheForObject(*object);
|
|
|
|
Handle<HeapObject> stub_holder(IC::GetCodeCacheHolder(
|
2013-03-04 14:03:27 +00:00
|
|
|
isolate_, *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.
|
2013-03-01 13:28:55 +00:00
|
|
|
if (object->IsNumber() || object->IsSymbol() ||
|
|
|
|
object->IsBoolean() || object->IsString()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
object = holder;
|
|
|
|
}
|
|
|
|
|
2013-02-27 15:33:37 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(
|
2013-11-19 12:04:54 +00:00
|
|
|
kind, extra_state, cache_holder, Code::FAST, argc);
|
2013-03-04 14:03:27 +00:00
|
|
|
Handle<Object> probe(stub_holder->map()->FindInCodeCache(*name, flags),
|
2012-11-16 08:38:11 +00:00
|
|
|
isolate_);
|
2011-10-20 17:08:53 +00:00
|
|
|
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);
|
2013-03-18 13:35:17 +00:00
|
|
|
ASSERT(flags == code->flags());
|
2011-10-20 17:08:53 +00:00
|
|
|
PROFILE(isolate_,
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_IC_TAG), *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_IC, *name, *code));
|
2013-09-12 22:04:04 +00:00
|
|
|
HeapObject::UpdateMapCodeCache(stub_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,
|
2013-11-28 15:32:55 +00:00
|
|
|
ExtraICState extra_state,
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> name,
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Object> object,
|
|
|
|
Handle<JSObject> holder) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Compute the check type and the map.
|
2013-11-14 16:25:31 +00:00
|
|
|
InlineCacheHolderFlag cache_holder = IC::GetCodeCacheForObject(*object);
|
|
|
|
Handle<HeapObject> stub_holder(IC::GetCodeCacheHolder(
|
2013-03-04 14:03:27 +00:00
|
|
|
isolate_, *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.
|
2013-03-01 13:28:55 +00:00
|
|
|
if (object->IsNumber() || object->IsSymbol() ||
|
|
|
|
object->IsBoolean() || object->IsString()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
object = holder;
|
|
|
|
}
|
|
|
|
|
2013-02-27 15:33:37 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(
|
2013-11-19 12:04:54 +00:00
|
|
|
kind, extra_state, cache_holder, Code::FAST, argc);
|
2013-03-04 14:03:27 +00:00
|
|
|
Handle<Object> probe(stub_holder->map()->FindInCodeCache(*name, flags),
|
2012-11-16 08:38:11 +00:00
|
|
|
isolate_);
|
2011-10-20 17:08:53 +00:00
|
|
|
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);
|
2013-03-18 13:35:17 +00:00
|
|
|
ASSERT(flags == code->flags());
|
2011-10-20 17:08:53 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_IC_TAG), *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_IC, *name, *code));
|
2013-09-12 22:04:04 +00:00
|
|
|
HeapObject::UpdateMapCodeCache(stub_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,
|
2013-11-28 15:32:55 +00:00
|
|
|
ExtraICState extra_state,
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> name,
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<JSObject> receiver,
|
|
|
|
Handle<GlobalObject> holder,
|
2013-06-14 16:06:12 +00:00
|
|
|
Handle<PropertyCell> cell,
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<JSFunction> function) {
|
2013-02-27 15:33:37 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(
|
2013-11-14 16:25:31 +00:00
|
|
|
kind, extra_state, OWN_MAP, Code::NORMAL, argc);
|
2013-10-01 13:17:04 +00:00
|
|
|
Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags),
|
2012-11-16 08:38:11 +00:00
|
|
|
isolate_);
|
2011-10-20 17:08:53 +00:00
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
2013-10-01 13:17:04 +00:00
|
|
|
CallStubCompiler compiler(isolate(), argc, kind, extra_state);
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> code =
|
|
|
|
compiler.CompileCallGlobal(receiver, holder, cell, function, name);
|
2013-03-18 13:35:17 +00:00
|
|
|
ASSERT(flags == code->flags());
|
2011-10-20 17:08:53 +00:00
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_IC_TAG), *code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::CALL_IC, *name, *code));
|
2013-06-19 09:25:24 +00:00
|
|
|
if (CallStubCompiler::CanBeCached(function)) {
|
2013-10-01 13:17:04 +00:00
|
|
|
HeapObject::UpdateMapCodeCache(receiver, name, code);
|
2013-06-19 09:25:24 +00:00
|
|
|
}
|
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,
|
2014-01-07 14:14:34 +00:00
|
|
|
ContextualMode mode,
|
2010-06-07 08:27:32 +00:00
|
|
|
Code::Kind kind) {
|
2013-11-28 15:32:55 +00:00
|
|
|
ExtraICState extra_state =
|
2011-05-24 14:01:36 +00:00
|
|
|
CallICBase::StringStubState::encode(DEFAULT_STRING_STUB) |
|
2014-01-07 14:14:34 +00:00
|
|
|
CallICBase::Contextual::encode(mode);
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::Flags flags =
|
2012-06-25 11:35:23 +00:00
|
|
|
Code::ComputeFlags(kind, UNINITIALIZED, extra_state, Code::NORMAL, argc);
|
2012-01-16 09:44:35 +00:00
|
|
|
UnseededNumberDictionary* dictionary =
|
2012-10-25 11:52:37 +00:00
|
|
|
isolate()->heap()->non_monomorphic_cache();
|
2011-10-20 17:08:53 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-07 14:14:34 +00:00
|
|
|
Code* StubCache::FindPreMonomorphicIC(Code::Kind kind, ExtraICState state) {
|
|
|
|
Code::Flags flags = Code::ComputeFlags(kind, PREMONOMORPHIC, state);
|
|
|
|
UnseededNumberDictionary* dictionary =
|
|
|
|
isolate()->heap()->non_monomorphic_cache();
|
|
|
|
int entry = dictionary->FindEntry(isolate(), flags);
|
|
|
|
ASSERT(entry != -1);
|
|
|
|
Object* code = dictionary->ValueAt(entry);
|
|
|
|
// This might be called during the marking phase of the collector
|
|
|
|
// hence the unchecked cast.
|
|
|
|
return reinterpret_cast<Code*>(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 17:08:53 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallInitialize(int argc,
|
2014-01-07 14:14:34 +00:00
|
|
|
ContextualMode mode,
|
2010-10-25 15:22:03 +00:00
|
|
|
Code::Kind kind) {
|
2013-11-28 15:32:55 +00:00
|
|
|
ExtraICState extra_state =
|
2014-01-07 14:14:34 +00:00
|
|
|
CallICBase::ComputeExtraICState(mode, DEFAULT_STRING_STUB);
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::Flags flags =
|
2012-06-25 11:35:23 +00:00
|
|
|
Code::ComputeFlags(kind, UNINITIALIZED, extra_state, Code::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-07 14:14:34 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallInitialize(int argc, ContextualMode mode) {
|
2011-10-20 17:08:53 +00:00
|
|
|
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) {
|
2014-01-07 14:14:34 +00:00
|
|
|
return ComputeCallInitialize(argc, NOT_CONTEXTUAL, 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,
|
2013-11-28 15:32:55 +00:00
|
|
|
ExtraICState extra_state) {
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::Flags flags =
|
2012-06-25 11:35:23 +00:00
|
|
|
Code::ComputeFlags(kind, PREMONOMORPHIC, extra_state, Code::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,
|
2013-11-28 15:32:55 +00:00
|
|
|
ExtraICState extra_state) {
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::Flags flags =
|
2012-06-25 11:35:23 +00:00
|
|
|
Code::ComputeFlags(kind, MONOMORPHIC, extra_state, Code::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-25 11:55:29 +00:00
|
|
|
Handle<Code> StubCache::ComputeCallArguments(int argc) {
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::Flags flags =
|
2013-01-25 11:55:29 +00:00
|
|
|
Code::ComputeFlags(Code::KEYED_CALL_IC, MEGAMORPHIC,
|
2013-11-28 15:32:55 +00:00
|
|
|
kNoExtraICState, Code::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,
|
2013-11-28 15:32:55 +00:00
|
|
|
ExtraICState extra_state) {
|
2011-10-20 17:08:53 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeFlags(kind, MEGAMORPHIC, extra_state,
|
2012-06-25 11:35:23 +00:00
|
|
|
Code::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-07 14:14:34 +00:00
|
|
|
Handle<Code> StubCache::ComputeLoad(InlineCacheState ic_state,
|
|
|
|
ExtraICState extra_state) {
|
|
|
|
Code::Flags flags = Code::ComputeFlags(Code::LOAD_IC, ic_state, extra_state);
|
|
|
|
Handle<UnseededNumberDictionary> cache =
|
|
|
|
isolate_->factory()->non_monomorphic_cache();
|
|
|
|
int entry = cache->FindEntry(isolate_, flags);
|
|
|
|
if (entry != -1) return Handle<Code>(Code::cast(cache->ValueAt(entry)));
|
|
|
|
|
|
|
|
StubCompiler compiler(isolate_);
|
|
|
|
Handle<Code> code;
|
|
|
|
if (ic_state == UNINITIALIZED) {
|
|
|
|
code = compiler.CompileLoadInitialize(flags);
|
|
|
|
} else if (ic_state == PREMONOMORPHIC) {
|
|
|
|
code = compiler.CompileLoadPreMonomorphic(flags);
|
|
|
|
} else if (ic_state == MEGAMORPHIC) {
|
|
|
|
code = compiler.CompileLoadMegamorphic(flags);
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
FillCache(isolate_, code);
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> StubCache::ComputeStore(InlineCacheState ic_state,
|
|
|
|
ExtraICState extra_state) {
|
|
|
|
Code::Flags flags = Code::ComputeFlags(Code::STORE_IC, ic_state, extra_state);
|
|
|
|
Handle<UnseededNumberDictionary> cache =
|
|
|
|
isolate_->factory()->non_monomorphic_cache();
|
|
|
|
int entry = cache->FindEntry(isolate_, flags);
|
|
|
|
if (entry != -1) return Handle<Code>(Code::cast(cache->ValueAt(entry)));
|
|
|
|
|
|
|
|
StubCompiler compiler(isolate_);
|
|
|
|
Handle<Code> code;
|
|
|
|
if (ic_state == UNINITIALIZED) {
|
|
|
|
code = compiler.CompileStoreInitialize(flags);
|
|
|
|
} else if (ic_state == PREMONOMORPHIC) {
|
|
|
|
code = compiler.CompileStorePreMonomorphic(flags);
|
|
|
|
} else if (ic_state == GENERIC) {
|
|
|
|
code = compiler.CompileStoreGeneric(flags);
|
|
|
|
} else if (ic_state == MEGAMORPHIC) {
|
|
|
|
code = compiler.CompileStoreMegamorphic(flags);
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
FillCache(isolate_, code);
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
2013-11-28 15:32:55 +00:00
|
|
|
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,
|
2012-06-25 11:35:23 +00:00
|
|
|
Code::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-24 11:32:17 +00:00
|
|
|
Handle<Code> StubCache::ComputeCompareNil(Handle<Map> receiver_map,
|
2013-05-16 10:59:17 +00:00
|
|
|
CompareNilICStub& stub) {
|
2013-04-24 11:32:17 +00:00
|
|
|
Handle<String> name(isolate_->heap()->empty_string());
|
|
|
|
if (!receiver_map->is_shared()) {
|
|
|
|
Handle<Code> cached_ic = FindIC(name, receiver_map, Code::COMPARE_NIL_IC,
|
2013-10-02 17:23:30 +00:00
|
|
|
stub.GetExtraICState());
|
2013-04-24 11:32:17 +00:00
|
|
|
if (!cached_ic.is_null()) return cached_ic;
|
|
|
|
}
|
|
|
|
|
2013-07-05 10:34:02 +00:00
|
|
|
Handle<Code> ic = stub.GetCodeCopyFromTemplate(isolate_);
|
|
|
|
ic->ReplaceNthObject(1, isolate_->heap()->meta_map(), *receiver_map);
|
2013-04-24 11:32:17 +00:00
|
|
|
|
|
|
|
if (!receiver_map->is_shared()) {
|
|
|
|
Map::UpdateCodeCache(receiver_map, name, ic);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ic;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-18 17:18:14 +00:00
|
|
|
// TODO(verwaest): Change this method so it takes in a TypeHandleList.
|
2013-01-23 15:35:43 +00:00
|
|
|
Handle<Code> StubCache::ComputeLoadElementPolymorphic(
|
|
|
|
MapHandleList* receiver_maps) {
|
|
|
|
Code::Flags flags = Code::ComputeFlags(Code::KEYED_LOAD_IC, POLYMORPHIC);
|
|
|
|
Handle<PolymorphicCodeCache> cache =
|
|
|
|
isolate_->factory()->polymorphic_code_cache();
|
|
|
|
Handle<Object> probe = cache->Lookup(receiver_maps, flags);
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
2013-11-18 17:18:14 +00:00
|
|
|
TypeHandleList types(receiver_maps->length());
|
|
|
|
for (int i = 0; i < receiver_maps->length(); i++) {
|
2014-01-09 19:52:15 +00:00
|
|
|
types.Add(handle(Type::Class(receiver_maps->at(i)), isolate()));
|
2013-11-18 17:18:14 +00:00
|
|
|
}
|
2013-03-04 14:03:27 +00:00
|
|
|
CodeHandleList handlers(receiver_maps->length());
|
2013-01-23 15:35:43 +00:00
|
|
|
KeyedLoadStubCompiler compiler(isolate_);
|
2013-03-04 14:03:27 +00:00
|
|
|
compiler.CompileElementHandlers(receiver_maps, &handlers);
|
|
|
|
Handle<Code> code = compiler.CompilePolymorphicIC(
|
2013-11-18 17:18:14 +00:00
|
|
|
&types, &handlers, factory()->empty_string(), Code::NORMAL, ELEMENT);
|
2013-03-04 14:03:27 +00:00
|
|
|
|
|
|
|
isolate()->counters()->keyed_load_polymorphic_stubs()->Increment();
|
|
|
|
|
2013-01-23 15:35:43 +00:00
|
|
|
PolymorphicCodeCache::Update(cache, receiver_maps, flags, code);
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-28 15:32:55 +00:00
|
|
|
Handle<Code> StubCache::ComputePolymorphicIC(
|
|
|
|
TypeHandleList* types,
|
|
|
|
CodeHandleList* handlers,
|
|
|
|
int number_of_valid_types,
|
|
|
|
Handle<Name> name,
|
|
|
|
ExtraICState extra_ic_state) {
|
|
|
|
|
2013-10-01 09:30:07 +00:00
|
|
|
Handle<Code> handler = handlers->at(0);
|
|
|
|
Code::Kind kind = handler->handler_kind();
|
2013-11-18 17:18:14 +00:00
|
|
|
Code::StubType type = number_of_valid_types == 1 ? handler->type()
|
|
|
|
: Code::NORMAL;
|
2013-10-01 09:30:07 +00:00
|
|
|
if (kind == Code::LOAD_IC) {
|
2014-01-07 14:14:34 +00:00
|
|
|
LoadStubCompiler ic_compiler(isolate_, extra_ic_state);
|
2013-10-01 09:30:07 +00:00
|
|
|
return ic_compiler.CompilePolymorphicIC(
|
2013-11-18 17:18:14 +00:00
|
|
|
types, handlers, name, type, PROPERTY);
|
2013-10-01 09:30:07 +00:00
|
|
|
} else {
|
|
|
|
ASSERT(kind == Code::STORE_IC);
|
2014-01-07 14:14:34 +00:00
|
|
|
StoreStubCompiler ic_compiler(isolate_, extra_ic_state);
|
2013-10-01 09:30:07 +00:00
|
|
|
return ic_compiler.CompilePolymorphicIC(
|
2013-11-18 17:18:14 +00:00
|
|
|
types, handlers, name, type, PROPERTY);
|
2013-10-01 09:30:07 +00:00
|
|
|
}
|
2013-07-09 08:22:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-23 15:35:43 +00:00
|
|
|
Handle<Code> StubCache::ComputeStoreElementPolymorphic(
|
|
|
|
MapHandleList* receiver_maps,
|
2013-03-06 21:51:07 +00:00
|
|
|
KeyedAccessStoreMode store_mode,
|
2013-01-23 15:35:43 +00:00
|
|
|
StrictModeFlag strict_mode) {
|
2013-03-06 21:51:07 +00:00
|
|
|
ASSERT(store_mode == STANDARD_STORE ||
|
2013-03-20 10:37:13 +00:00
|
|
|
store_mode == STORE_AND_GROW_NO_TRANSITION ||
|
|
|
|
store_mode == STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS ||
|
|
|
|
store_mode == STORE_NO_TRANSITION_HANDLE_COW);
|
2013-01-23 15:35:43 +00:00
|
|
|
Handle<PolymorphicCodeCache> cache =
|
|
|
|
isolate_->factory()->polymorphic_code_cache();
|
2013-11-28 15:32:55 +00:00
|
|
|
ExtraICState extra_state = KeyedStoreIC::ComputeExtraICState(
|
|
|
|
strict_mode, store_mode);
|
2013-01-23 15:35:43 +00:00
|
|
|
Code::Flags flags =
|
|
|
|
Code::ComputeFlags(Code::KEYED_STORE_IC, POLYMORPHIC, extra_state);
|
|
|
|
Handle<Object> probe = cache->Lookup(receiver_maps, flags);
|
|
|
|
if (probe->IsCode()) return Handle<Code>::cast(probe);
|
|
|
|
|
2013-12-02 11:59:44 +00:00
|
|
|
KeyedStoreStubCompiler compiler(isolate_, extra_state);
|
2013-01-23 15:35:43 +00:00
|
|
|
Handle<Code> code = compiler.CompileStoreElementPolymorphic(receiver_maps);
|
|
|
|
PolymorphicCodeCache::Update(cache, receiver_maps, flags, 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 =
|
2013-01-10 14:15:12 +00:00
|
|
|
Code::ComputeFlags(kind, DEBUG_STUB, DEBUG_BREAK,
|
2012-06-25 11:35:23 +00:00
|
|
|
Code::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 =
|
2013-01-10 14:15:12 +00:00
|
|
|
Code::ComputeFlags(kind, DEBUG_STUB, DEBUG_PREPARE_STEP_IN,
|
2012-06-25 11:35:23 +00:00
|
|
|
Code::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();
|
2013-05-21 12:59:48 +00:00
|
|
|
primary_[i].map = NULL;
|
2011-09-29 11:52:05 +00:00
|
|
|
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();
|
2013-05-21 12:59:48 +00:00
|
|
|
secondary_[j].map = NULL;
|
2011-09-29 11:52:05 +00:00
|
|
|
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,
|
2013-05-02 15:40:07 +00:00
|
|
|
Handle<Name> name,
|
2011-12-14 14:01:54 +00:00
|
|
|
Code::Flags flags,
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Context> native_context,
|
2012-06-20 08:58:41 +00:00
|
|
|
Zone* zone) {
|
2010-12-07 11:31:57 +00:00
|
|
|
for (int i = 0; i < kPrimaryTableSize; i++) {
|
2013-05-02 15:40:07 +00:00
|
|
|
if (primary_[i].key == *name) {
|
2013-03-05 17:38:35 +00:00
|
|
|
Map* map = primary_[i].map;
|
2010-12-07 11:31:57 +00:00
|
|
|
// Map can be NULL, if the stub is constant function call
|
|
|
|
// with a primitive receiver.
|
|
|
|
if (map == NULL) continue;
|
|
|
|
|
2013-05-02 15:40:07 +00:00
|
|
|
int offset = PrimaryOffset(*name, flags, map);
|
2011-12-14 14:01:54 +00:00
|
|
|
if (entry(primary_, offset) == &primary_[i] &&
|
2012-08-17 09:03:08 +00:00
|
|
|
!TypeFeedbackOracle::CanRetainOtherContext(map, *native_context)) {
|
2013-05-02 15:40:07 +00:00
|
|
|
types->AddMapIfMissing(Handle<Map>(map), zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < kSecondaryTableSize; i++) {
|
2013-05-02 15:40:07 +00:00
|
|
|
if (secondary_[i].key == *name) {
|
2013-03-05 17:38:35 +00:00
|
|
|
Map* map = secondary_[i].map;
|
2010-12-07 11:31:57 +00:00
|
|
|
// 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.
|
2013-05-02 15:40:07 +00:00
|
|
|
int primary_offset = PrimaryOffset(*name, flags, map);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Lookup in secondary table and add matches.
|
2013-05-02 15:40:07 +00:00
|
|
|
int offset = SecondaryOffset(*name, flags, primary_offset);
|
2011-12-14 14:01:54 +00:00
|
|
|
if (entry(secondary_, offset) == &secondary_[i] &&
|
2012-08-17 09:03:08 +00:00
|
|
|
!TypeFeedbackOracle::CanRetainOtherContext(map, *native_context)) {
|
2013-05-02 15:40:07 +00:00
|
|
|
types->AddMapIfMissing(Handle<Map>(map), zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// StubCompiler implementation.
|
|
|
|
|
|
|
|
|
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]);
|
2013-02-12 14:33:08 +00:00
|
|
|
ExecutableAccessorInfo* callback = ExecutableAccessorInfo::cast(args[1]);
|
2009-03-18 18:50:35 +00:00
|
|
|
Address setter_address = v8::ToCData<Address>(callback->setter());
|
2013-08-27 11:47:52 +00:00
|
|
|
v8::AccessorSetterCallback fun =
|
|
|
|
FUNCTION_CAST<v8::AccessorSetterCallback>(setter_address);
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(fun != NULL);
|
2012-06-08 07:45:11 +00:00
|
|
|
ASSERT(callback->IsCompatibleReceiver(recv));
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> name = args.at<Name>(2);
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Object> value = args.at<Object>(3);
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate);
|
2013-03-04 15:00:57 +00:00
|
|
|
|
|
|
|
// TODO(rossberg): Support symbols in the API.
|
|
|
|
if (name->IsSymbol()) return *value;
|
|
|
|
Handle<String> str = Handle<String>::cast(name);
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
LOG(isolate, ApiNamedPropertyAccess("store", recv, *name));
|
2013-05-21 06:36:24 +00:00
|
|
|
PropertyCallbackArguments
|
|
|
|
custom_args(isolate, callback->data(), recv, recv);
|
2013-06-20 14:47:35 +00:00
|
|
|
custom_args.Call(fun, v8::Utils::ToLocal(str), v8::Utils::ToLocal(value));
|
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
|
|
|
|
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) {
|
2013-09-12 14:32:14 +00:00
|
|
|
ASSERT(args.length() == StubCache::kInterceptorArgsLength);
|
|
|
|
Handle<Name> name_handle =
|
|
|
|
args.at<Name>(StubCache::kInterceptorArgsNameIndex);
|
|
|
|
Handle<InterceptorInfo> interceptor_info =
|
|
|
|
args.at<InterceptorInfo>(StubCache::kInterceptorArgsInfoIndex);
|
2009-03-18 18:50:35 +00:00
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
// TODO(rossberg): Support symbols in the API.
|
|
|
|
if (name_handle->IsSymbol())
|
|
|
|
return isolate->heap()->no_interceptor_result_sentinel();
|
|
|
|
Handle<String> name = Handle<String>::cast(name_handle);
|
|
|
|
|
2009-07-28 14:46:06 +00:00
|
|
|
Address getter_address = v8::ToCData<Address>(interceptor_info->getter());
|
2013-08-27 11:47:52 +00:00
|
|
|
v8::NamedPropertyGetterCallback getter =
|
|
|
|
FUNCTION_CAST<v8::NamedPropertyGetterCallback>(getter_address);
|
2009-07-28 14:46:06 +00:00
|
|
|
ASSERT(getter != NULL);
|
|
|
|
|
2013-05-21 06:36:24 +00:00
|
|
|
Handle<JSObject> receiver =
|
2013-09-12 14:32:14 +00:00
|
|
|
args.at<JSObject>(StubCache::kInterceptorArgsThisIndex);
|
2013-05-21 06:36:24 +00:00
|
|
|
Handle<JSObject> holder =
|
2013-09-12 14:32:14 +00:00
|
|
|
args.at<JSObject>(StubCache::kInterceptorArgsHolderIndex);
|
|
|
|
PropertyCallbackArguments callback_args(
|
|
|
|
isolate, interceptor_info->data(), *receiver, *holder);
|
2009-07-28 14:46:06 +00:00
|
|
|
{
|
|
|
|
// Use the interceptor getter.
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate);
|
2013-06-20 14:47:35 +00:00
|
|
|
v8::Handle<v8::Value> r =
|
|
|
|
callback_args.Call(getter, v8::Utils::ToLocal(name));
|
2011-03-18 20:35:07 +00:00
|
|
|
RETURN_IF_SCHEDULED_EXCEPTION(isolate);
|
2009-07-28 14:46:06 +00:00
|
|
|
if (!r.IsEmpty()) {
|
2012-09-10 13:38:21 +00:00
|
|
|
Handle<Object> result = v8::Utils::OpenHandle(*r);
|
|
|
|
result->VerifyApiCallResultType();
|
2009-07-28 14:46:06 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
static MaybeObject* ThrowReferenceError(Isolate* isolate, Name* 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.
|
2013-10-01 09:47:18 +00:00
|
|
|
HandleScope scope(isolate);
|
2013-02-15 09:27:10 +00:00
|
|
|
IC ic(IC::NO_EXTRA_FRAME, isolate);
|
2013-11-15 09:34:44 +00:00
|
|
|
ASSERT(ic.IsLoadStub());
|
2014-01-07 14:14:34 +00:00
|
|
|
if (!ic.IsContextual()) {
|
|
|
|
return isolate->heap()->undefined_value();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Throw a reference error.
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> name_handle(name);
|
2009-07-29 12:34:21 +00:00
|
|
|
Handle<Object> error =
|
2013-06-04 10:30:05 +00:00
|
|
|
isolate->factory()->NewReferenceError("not_defined",
|
|
|
|
HandleVector(&name_handle, 1));
|
2013-02-15 09:27:10 +00:00
|
|
|
return isolate->Throw(*error);
|
2009-07-29 12:34:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-10 15:27:02 +00:00
|
|
|
static Handle<Object> LoadWithInterceptor(Arguments* args,
|
|
|
|
PropertyAttributes* attrs) {
|
2013-09-12 14:32:14 +00:00
|
|
|
ASSERT(args->length() == StubCache::kInterceptorArgsLength);
|
|
|
|
Handle<Name> name_handle =
|
|
|
|
args->at<Name>(StubCache::kInterceptorArgsNameIndex);
|
|
|
|
Handle<InterceptorInfo> interceptor_info =
|
|
|
|
args->at<InterceptorInfo>(StubCache::kInterceptorArgsInfoIndex);
|
2013-05-21 06:36:24 +00:00
|
|
|
Handle<JSObject> receiver_handle =
|
2013-09-12 14:32:14 +00:00
|
|
|
args->at<JSObject>(StubCache::kInterceptorArgsThisIndex);
|
2013-05-21 06:36:24 +00:00
|
|
|
Handle<JSObject> holder_handle =
|
2013-09-12 14:32:14 +00:00
|
|
|
args->at<JSObject>(StubCache::kInterceptorArgsHolderIndex);
|
2009-07-29 12:34:21 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = receiver_handle->GetIsolate();
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
// TODO(rossberg): Support symbols in the API.
|
2013-10-10 15:27:02 +00:00
|
|
|
if (name_handle->IsSymbol()) {
|
|
|
|
return JSObject::GetPropertyPostInterceptor(
|
|
|
|
holder_handle, receiver_handle, name_handle, attrs);
|
|
|
|
}
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<String> name = Handle<String>::cast(name_handle);
|
|
|
|
|
2009-07-29 12:34:21 +00:00
|
|
|
Address getter_address = v8::ToCData<Address>(interceptor_info->getter());
|
2013-08-27 11:47:52 +00:00
|
|
|
v8::NamedPropertyGetterCallback getter =
|
|
|
|
FUNCTION_CAST<v8::NamedPropertyGetterCallback>(getter_address);
|
2009-07-29 12:34:21 +00:00
|
|
|
ASSERT(getter != NULL);
|
|
|
|
|
2013-05-21 06:36:24 +00:00
|
|
|
PropertyCallbackArguments callback_args(isolate,
|
|
|
|
interceptor_info->data(),
|
|
|
|
*receiver_handle,
|
|
|
|
*holder_handle);
|
2009-03-18 18:50:35 +00:00
|
|
|
{
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate);
|
2013-10-10 15:27:02 +00:00
|
|
|
// Use the interceptor getter.
|
2013-06-20 14:47:35 +00:00
|
|
|
v8::Handle<v8::Value> r =
|
|
|
|
callback_args.Call(getter, v8::Utils::ToLocal(name));
|
2013-10-10 15:27:02 +00:00
|
|
|
RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object);
|
2009-07-29 12:34:21 +00:00
|
|
|
if (!r.IsEmpty()) {
|
|
|
|
*attrs = NONE;
|
2012-09-10 13:38:21 +00:00
|
|
|
Handle<Object> result = v8::Utils::OpenHandle(*r);
|
|
|
|
result->VerifyApiCallResultType();
|
2013-10-10 15:27:02 +00:00
|
|
|
return scope.CloseAndEscape(result);
|
2009-07-29 12:34:21 +00:00
|
|
|
}
|
2009-03-18 18:50:35 +00:00
|
|
|
}
|
2009-07-29 12:34:21 +00:00
|
|
|
|
2013-10-10 15:27:02 +00:00
|
|
|
Handle<Object> result = JSObject::GetPropertyPostInterceptor(
|
|
|
|
holder_handle, receiver_handle, name_handle, attrs);
|
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;
|
2013-10-10 15:27:02 +00:00
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<Object> result = LoadWithInterceptor(&args, &attr);
|
|
|
|
RETURN_IF_EMPTY_HANDLE(isolate, result);
|
2009-07-29 12:34:21 +00:00
|
|
|
|
|
|
|
// If the property is present, return it.
|
2013-10-10 15:27:02 +00:00
|
|
|
if (attr != ABSENT) return *result;
|
2013-03-04 15:00:57 +00:00
|
|
|
return ThrowReferenceError(isolate, Name::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;
|
2013-10-10 15:27:02 +00:00
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<Object> result = LoadWithInterceptor(&args, &attr);
|
|
|
|
RETURN_IF_EMPTY_HANDLE(isolate, result);
|
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.
|
2013-10-10 15:27:02 +00:00
|
|
|
return *result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-30 14:17:39 +00:00
|
|
|
RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty) {
|
2013-09-17 11:01:43 +00:00
|
|
|
HandleScope scope(isolate);
|
2013-11-28 18:11:15 +00:00
|
|
|
ASSERT(args.length() == 3);
|
|
|
|
StoreIC ic(IC::NO_EXTRA_FRAME, isolate);
|
|
|
|
Handle<JSObject> receiver = args.at<JSObject>(0);
|
|
|
|
Handle<Name> name = args.at<Name>(1);
|
|
|
|
Handle<Object> value = args.at<Object>(2);
|
|
|
|
ASSERT(receiver->HasNamedInterceptor());
|
2008-07-03 15:10:15 +00:00
|
|
|
PropertyAttributes attr = NONE;
|
2013-09-17 11:01:43 +00:00
|
|
|
Handle<Object> result = JSObject::SetPropertyWithInterceptor(
|
2013-11-28 18:11:15 +00:00
|
|
|
receiver, name, value, attr, ic.strict_mode());
|
2013-09-17 11:01:43 +00:00
|
|
|
RETURN_IF_EMPTY_HANDLE(isolate, result);
|
|
|
|
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);
|
2013-11-28 15:32:55 +00:00
|
|
|
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);
|
2013-11-28 15:32:55 +00:00
|
|
|
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);
|
2013-11-28 15:32:55 +00:00
|
|
|
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));
|
2014-01-07 14:14:34 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> StubCompiler::CompileLoadInitialize(Code::Flags flags) {
|
|
|
|
LoadIC::GenerateInitialize(masm());
|
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, "CompileLoadInitialize");
|
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(Logger::LOAD_INITIALIZE_TAG, *code, 0));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, *code));
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> StubCompiler::CompileLoadPreMonomorphic(Code::Flags flags) {
|
|
|
|
LoadIC::GeneratePreMonomorphic(masm());
|
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, "CompileLoadPreMonomorphic");
|
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(Logger::LOAD_PREMONOMORPHIC_TAG, *code, 0));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, *code));
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> StubCompiler::CompileLoadMegamorphic(Code::Flags flags) {
|
|
|
|
ExtraICState extra_state = Code::ExtractExtraICStateFromFlags(flags);
|
|
|
|
ContextualMode mode = IC::GetContextualMode(extra_state);
|
|
|
|
LoadIC::GenerateMegamorphic(masm(), mode);
|
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, "CompileLoadMegamorphic");
|
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(Logger::LOAD_MEGAMORPHIC_TAG, *code, 0));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::LOAD_IC, *code));
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> StubCompiler::CompileStoreInitialize(Code::Flags flags) {
|
|
|
|
StoreIC::GenerateInitialize(masm());
|
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, "CompileStoreInitialize");
|
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(Logger::STORE_INITIALIZE_TAG, *code, 0));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::STORE_IC, *code));
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> StubCompiler::CompileStorePreMonomorphic(Code::Flags flags) {
|
|
|
|
StoreIC::GeneratePreMonomorphic(masm());
|
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, "CompileStorePreMonomorphic");
|
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(Logger::STORE_PREMONOMORPHIC_TAG, *code, 0));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::STORE_IC, *code));
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> StubCompiler::CompileStoreGeneric(Code::Flags flags) {
|
|
|
|
ExtraICState extra_state = Code::ExtractExtraICStateFromFlags(flags);
|
|
|
|
StrictModeFlag strict_mode = StoreIC::GetStrictMode(extra_state);
|
|
|
|
StoreIC::GenerateRuntimeSetProperty(masm(), strict_mode);
|
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, "CompileStoreGeneric");
|
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(Logger::STORE_GENERIC_TAG, *code, 0));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::STORE_IC, *code));
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> StubCompiler::CompileStoreMegamorphic(Code::Flags flags) {
|
|
|
|
ExtraICState extra_state = Code::ExtractExtraICStateFromFlags(flags);
|
|
|
|
StoreIC::GenerateMegamorphic(masm(), extra_state);
|
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, "CompileStoreMegamorphic");
|
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(Logger::STORE_MEGAMORPHIC_TAG, *code, 0));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::STORE_IC, *code));
|
2011-10-24 10:55:00 +00:00
|
|
|
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);
|
2013-11-28 15:32:55 +00:00
|
|
|
ExtraICState extra_state = Code::ExtractExtraICStateFromFlags(flags);
|
2011-10-24 09:33:11 +00:00
|
|
|
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.
|
2013-11-28 15:32:55 +00:00
|
|
|
CallIC::GenerateMiss(masm(), argc, 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());
|
2013-12-13 10:27:19 +00:00
|
|
|
if (code->has_major_key()) {
|
|
|
|
code->set_major_key(CodeStub::NoCache);
|
|
|
|
}
|
2011-10-21 10:19:16 +00:00
|
|
|
#ifdef ENABLE_DISASSEMBLER
|
2013-11-14 16:25:31 +00:00
|
|
|
if (FLAG_print_code_stubs) code->Disassemble(name);
|
2011-10-21 10:19:16 +00:00
|
|
|
#endif
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-25 09:24:49 +00:00
|
|
|
Handle<Code> StubCompiler::GetCodeWithFlags(Code::Flags flags,
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> name) {
|
|
|
|
return (FLAG_print_code_stubs && !name.is_null() && name->IsString())
|
2013-12-09 07:41:20 +00:00
|
|
|
? GetCodeWithFlags(flags, Handle<String>::cast(name)->ToCString().get())
|
2013-07-17 08:46:44 +00:00
|
|
|
: GetCodeWithFlags(flags, NULL);
|
2011-10-25 09:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-28 12:37:29 +00:00
|
|
|
void StubCompiler::LookupPostInterceptor(Handle<JSObject> holder,
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> name,
|
2010-02-02 11:32:17 +00:00
|
|
|
LookupResult* lookup) {
|
2011-10-28 12:37:29 +00:00
|
|
|
holder->LocalLookupRealNamedProperty(*name, lookup);
|
2012-07-16 14:47:28 +00:00
|
|
|
if (lookup->IsFound()) return;
|
2011-10-28 12:37:29 +00:00
|
|
|
if (holder->GetPrototype()->IsNull()) return;
|
|
|
|
holder->GetPrototype()->Lookup(*name, lookup);
|
2010-02-02 11:32:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 13:39:36 +00:00
|
|
|
#define __ ACCESS_MASM(masm())
|
|
|
|
|
|
|
|
|
2013-11-29 12:57:47 +00:00
|
|
|
CallKind CallStubCompiler::call_kind() {
|
2013-12-02 11:59:44 +00:00
|
|
|
return CallICBase::Contextual::decode(extra_state())
|
2013-11-29 12:57:47 +00:00
|
|
|
? CALL_AS_FUNCTION
|
|
|
|
: CALL_AS_METHOD;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-28 13:56:49 +00:00
|
|
|
void CallStubCompiler::HandlerFrontendFooter(Label* miss) {
|
|
|
|
__ bind(miss);
|
|
|
|
GenerateMissBranch();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-29 12:57:47 +00:00
|
|
|
void CallStubCompiler::GenerateJumpFunctionIgnoreReceiver(
|
|
|
|
Handle<JSFunction> function) {
|
|
|
|
ParameterCount expected(function);
|
|
|
|
__ InvokeFunction(function, expected, arguments(),
|
|
|
|
JUMP_FUNCTION, NullCallWrapper(), call_kind());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CallStubCompiler::GenerateJumpFunction(Handle<Object> object,
|
|
|
|
Handle<JSFunction> function) {
|
2014-01-07 10:46:39 +00:00
|
|
|
PatchGlobalProxy(object, function);
|
2013-11-29 12:57:47 +00:00
|
|
|
GenerateJumpFunctionIgnoreReceiver(function);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CallStubCompiler::GenerateJumpFunction(Handle<Object> object,
|
|
|
|
Register actual_closure,
|
|
|
|
Handle<JSFunction> function) {
|
2014-01-07 10:46:39 +00:00
|
|
|
PatchGlobalProxy(object, function);
|
2013-11-29 12:57:47 +00:00
|
|
|
ParameterCount expected(function);
|
|
|
|
__ InvokeFunction(actual_closure, expected, arguments(),
|
|
|
|
JUMP_FUNCTION, NullCallWrapper(), call_kind());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> CallStubCompiler::CompileCallConstant(
|
|
|
|
Handle<Object> object,
|
|
|
|
Handle<JSObject> holder,
|
|
|
|
Handle<Name> name,
|
|
|
|
CheckType check,
|
|
|
|
Handle<JSFunction> function) {
|
|
|
|
if (HasCustomCallGenerator(function)) {
|
|
|
|
Handle<Code> code = CompileCustomCall(object, holder,
|
|
|
|
Handle<Cell>::null(),
|
|
|
|
function, Handle<String>::cast(name),
|
|
|
|
Code::FAST);
|
|
|
|
// A null handle means bail out to the regular compiler code below.
|
|
|
|
if (!code.is_null()) return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
Label miss;
|
|
|
|
HandlerFrontendHeader(object, holder, name, check, &miss);
|
|
|
|
GenerateJumpFunction(object, function);
|
|
|
|
HandlerFrontendFooter(&miss);
|
|
|
|
|
|
|
|
// Return the generated code.
|
|
|
|
return GetCode(function);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-11 14:05:23 +00:00
|
|
|
Register LoadStubCompiler::HandlerFrontendHeader(
|
2013-11-22 15:08:22 +00:00
|
|
|
Handle<Type> type,
|
2013-07-09 08:22:41 +00:00
|
|
|
Register object_reg,
|
|
|
|
Handle<JSObject> holder,
|
|
|
|
Handle<Name> name,
|
|
|
|
Label* miss) {
|
2013-11-14 16:25:31 +00:00
|
|
|
PrototypeCheckType check_type = CHECK_ALL_MAPS;
|
|
|
|
int function_index = -1;
|
2013-11-22 15:08:22 +00:00
|
|
|
if (type->Is(Type::String())) {
|
|
|
|
function_index = Context::STRING_FUNCTION_INDEX;
|
|
|
|
} else if (type->Is(Type::Symbol())) {
|
|
|
|
function_index = Context::SYMBOL_FUNCTION_INDEX;
|
|
|
|
} else if (type->Is(Type::Number())) {
|
|
|
|
function_index = Context::NUMBER_FUNCTION_INDEX;
|
|
|
|
} else if (type->Is(Type::Boolean())) {
|
|
|
|
// Booleans use the generic oddball map, so an additional check is needed to
|
|
|
|
// ensure the receiver is really a boolean.
|
|
|
|
GenerateBooleanCheck(object_reg, miss);
|
|
|
|
function_index = Context::BOOLEAN_FUNCTION_INDEX;
|
2013-11-14 16:25:31 +00:00
|
|
|
} else {
|
2013-11-22 15:08:22 +00:00
|
|
|
check_type = SKIP_RECEIVER;
|
|
|
|
}
|
2013-11-14 16:25:31 +00:00
|
|
|
|
2013-11-22 15:08:22 +00:00
|
|
|
if (check_type == CHECK_ALL_MAPS) {
|
2013-11-14 16:25:31 +00:00
|
|
|
GenerateDirectLoadGlobalFunctionPrototype(
|
|
|
|
masm(), function_index, scratch1(), miss);
|
2013-11-22 15:08:22 +00:00
|
|
|
Object* function = isolate()->native_context()->get(function_index);
|
|
|
|
Object* prototype = JSFunction::cast(function)->instance_prototype();
|
|
|
|
type = IC::CurrentTypeOf(handle(prototype, isolate()), isolate());
|
2013-11-14 16:25:31 +00:00
|
|
|
object_reg = scratch1();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the maps starting from the prototype haven't changed.
|
2013-11-22 15:06:20 +00:00
|
|
|
return CheckPrototypes(
|
2013-11-22 15:08:22 +00:00
|
|
|
type, object_reg, holder, scratch1(), scratch2(), scratch3(),
|
|
|
|
name, miss, check_type);
|
2013-02-27 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-09 08:22:41 +00:00
|
|
|
// HandlerFrontend for store uses the name register. It has to be restored
|
|
|
|
// before a miss.
|
2013-10-11 14:05:23 +00:00
|
|
|
Register StoreStubCompiler::HandlerFrontendHeader(
|
2013-11-22 15:08:22 +00:00
|
|
|
Handle<Type> type,
|
2013-07-09 08:22:41 +00:00
|
|
|
Register object_reg,
|
|
|
|
Handle<JSObject> holder,
|
|
|
|
Handle<Name> name,
|
|
|
|
Label* miss) {
|
2013-11-22 15:08:22 +00:00
|
|
|
return CheckPrototypes(type, object_reg, holder, this->name(),
|
|
|
|
scratch1(), scratch2(), name, miss, SKIP_RECEIVER);
|
2013-07-09 08:22:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-18 17:18:14 +00:00
|
|
|
bool BaseLoadStoreStubCompiler::IncludesNumberType(TypeHandleList* types) {
|
|
|
|
for (int i = 0; i < types->length(); ++i) {
|
|
|
|
if (types->at(i)->Is(Type::Number())) return true;
|
2013-11-14 16:37:36 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-22 15:08:22 +00:00
|
|
|
Register BaseLoadStoreStubCompiler::HandlerFrontend(Handle<Type> type,
|
2013-07-09 08:22:41 +00:00
|
|
|
Register object_reg,
|
|
|
|
Handle<JSObject> holder,
|
2013-11-14 16:25:31 +00:00
|
|
|
Handle<Name> name) {
|
2013-02-27 15:28:53 +00:00
|
|
|
Label miss;
|
|
|
|
|
2013-11-22 15:08:22 +00:00
|
|
|
Register reg = HandlerFrontendHeader(type, object_reg, holder, name, &miss);
|
2013-02-27 15:28:53 +00:00
|
|
|
|
2013-11-14 16:25:31 +00:00
|
|
|
HandlerFrontendFooter(name, &miss);
|
|
|
|
|
2013-02-27 15:28:53 +00:00
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-22 15:08:22 +00:00
|
|
|
void LoadStubCompiler::NonexistentHandlerFrontend(Handle<Type> type,
|
|
|
|
Handle<JSObject> last,
|
|
|
|
Handle<Name> name) {
|
2013-11-04 14:14:09 +00:00
|
|
|
Label miss;
|
|
|
|
|
2013-11-22 15:08:22 +00:00
|
|
|
Register holder;
|
|
|
|
Handle<Map> last_map;
|
|
|
|
if (last.is_null()) {
|
|
|
|
holder = receiver();
|
|
|
|
last_map = IC::TypeToMap(*type, isolate());
|
|
|
|
// If |type| has null as its prototype, |last| is Handle<JSObject>::null().
|
|
|
|
ASSERT(last_map->prototype() == isolate()->heap()->null_value());
|
|
|
|
} else {
|
|
|
|
holder = HandlerFrontendHeader(type, receiver(), last, name, &miss);
|
|
|
|
last_map = handle(last->map());
|
|
|
|
}
|
2013-11-04 14:14:09 +00:00
|
|
|
|
2013-11-22 15:08:22 +00:00
|
|
|
if (last_map->is_dictionary_map() &&
|
|
|
|
!last_map->IsJSGlobalObjectMap() &&
|
|
|
|
!last_map->IsJSGlobalProxyMap()) {
|
2013-11-04 14:14:09 +00:00
|
|
|
if (!name->IsUniqueName()) {
|
|
|
|
ASSERT(name->IsString());
|
|
|
|
name = factory()->InternalizeString(Handle<String>::cast(name));
|
|
|
|
}
|
2013-11-22 15:08:22 +00:00
|
|
|
ASSERT(last.is_null() ||
|
|
|
|
last->property_dictionary()->FindEntry(*name) ==
|
|
|
|
NameDictionary::kNotFound);
|
2013-11-04 14:14:09 +00:00
|
|
|
GenerateDictionaryNegativeLookup(masm(), &miss, holder, name,
|
|
|
|
scratch2(), scratch3());
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the last object in the prototype chain is a global object,
|
|
|
|
// check that the global property cell is empty.
|
2013-11-22 15:08:22 +00:00
|
|
|
if (last_map->IsJSGlobalObjectMap()) {
|
|
|
|
Handle<JSGlobalObject> global = last.is_null()
|
|
|
|
? Handle<JSGlobalObject>::cast(type->AsConstant())
|
|
|
|
: Handle<JSGlobalObject>::cast(last);
|
2013-11-04 14:14:09 +00:00
|
|
|
GenerateCheckPropertyCell(masm(), global, name, scratch2(), &miss);
|
|
|
|
}
|
|
|
|
|
2013-11-14 16:25:31 +00:00
|
|
|
HandlerFrontendFooter(name, &miss);
|
2013-11-04 14:14:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-11 14:05:23 +00:00
|
|
|
Handle<Code> LoadStubCompiler::CompileLoadField(
|
2013-11-22 15:08:22 +00:00
|
|
|
Handle<Type> type,
|
2013-05-08 15:02:08 +00:00
|
|
|
Handle<JSObject> holder,
|
|
|
|
Handle<Name> name,
|
|
|
|
PropertyIndex field,
|
|
|
|
Representation representation) {
|
2013-03-04 14:03:27 +00:00
|
|
|
Label miss;
|
|
|
|
|
2013-11-22 15:08:22 +00:00
|
|
|
Register reg = HandlerFrontendHeader(type, receiver(), holder, name, &miss);
|
2013-03-04 14:03:27 +00:00
|
|
|
|
2013-05-08 15:02:08 +00:00
|
|
|
GenerateLoadField(reg, holder, field, representation);
|
2013-03-04 14:03:27 +00:00
|
|
|
|
|
|
|
__ bind(&miss);
|
2013-03-13 14:11:05 +00:00
|
|
|
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
2013-02-01 13:39:36 +00:00
|
|
|
|
|
|
|
// Return the generated code.
|
2013-11-19 12:04:54 +00:00
|
|
|
return GetCode(kind(), Code::FAST, name);
|
2013-02-01 13:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-11 14:05:23 +00:00
|
|
|
Handle<Code> LoadStubCompiler::CompileLoadConstant(
|
2013-11-22 15:08:22 +00:00
|
|
|
Handle<Type> type,
|
2013-02-01 13:39:36 +00:00
|
|
|
Handle<JSObject> holder,
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> name,
|
2013-07-24 12:34:50 +00:00
|
|
|
Handle<Object> value) {
|
2013-11-22 15:08:22 +00:00
|
|
|
HandlerFrontend(type, receiver(), holder, name);
|
2013-02-27 15:28:53 +00:00
|
|
|
GenerateLoadConstant(value);
|
2013-02-01 13:39:36 +00:00
|
|
|
|
|
|
|
// Return the generated code.
|
2013-11-19 12:04:54 +00:00
|
|
|
return GetCode(kind(), Code::FAST, name);
|
2013-02-01 13:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-11 14:05:23 +00:00
|
|
|
Handle<Code> LoadStubCompiler::CompileLoadCallback(
|
2013-11-22 15:08:22 +00:00
|
|
|
Handle<Type> type,
|
2013-02-01 13:39:36 +00:00
|
|
|
Handle<JSObject> holder,
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> name,
|
2013-02-27 15:28:53 +00:00
|
|
|
Handle<ExecutableAccessorInfo> callback) {
|
|
|
|
Register reg = CallbackHandlerFrontend(
|
2013-11-22 15:08:22 +00:00
|
|
|
type, receiver(), holder, name, callback);
|
2013-02-27 15:28:53 +00:00
|
|
|
GenerateLoadCallback(reg, callback);
|
2013-02-01 13:39:36 +00:00
|
|
|
|
|
|
|
// Return the generated code.
|
2013-11-19 12:04:54 +00:00
|
|
|
return GetCode(kind(), Code::FAST, name);
|
2013-02-01 13:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-11 14:05:23 +00:00
|
|
|
Handle<Code> LoadStubCompiler::CompileLoadCallback(
|
2013-11-22 15:08:22 +00:00
|
|
|
Handle<Type> type,
|
2013-09-05 11:18:52 +00:00
|
|
|
Handle<JSObject> holder,
|
|
|
|
Handle<Name> name,
|
|
|
|
const CallOptimization& call_optimization) {
|
|
|
|
ASSERT(call_optimization.is_simple_api_call());
|
|
|
|
Handle<JSFunction> callback = call_optimization.constant_function();
|
2013-11-22 15:08:22 +00:00
|
|
|
CallbackHandlerFrontend(type, receiver(), holder, name, callback);
|
2013-09-05 11:18:52 +00:00
|
|
|
GenerateLoadCallback(call_optimization);
|
|
|
|
|
|
|
|
// Return the generated code.
|
2013-11-19 12:04:54 +00:00
|
|
|
return GetCode(kind(), Code::FAST, name);
|
2013-09-05 11:18:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-11 14:05:23 +00:00
|
|
|
Handle<Code> LoadStubCompiler::CompileLoadInterceptor(
|
2013-11-22 15:08:22 +00:00
|
|
|
Handle<Type> type,
|
2013-02-01 13:39:36 +00:00
|
|
|
Handle<JSObject> holder,
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> name) {
|
2013-02-01 13:39:36 +00:00
|
|
|
LookupResult lookup(isolate());
|
|
|
|
LookupPostInterceptor(holder, name, &lookup);
|
|
|
|
|
2013-11-22 15:08:22 +00:00
|
|
|
Register reg = HandlerFrontend(type, receiver(), holder, name);
|
2013-02-01 13:39:36 +00:00
|
|
|
// TODO(368): Compile in the whole chain: all the interceptors in
|
|
|
|
// prototypes and ultimate answer.
|
2013-11-22 15:08:22 +00:00
|
|
|
GenerateLoadInterceptor(reg, type, holder, &lookup, name);
|
2013-02-01 13:39:36 +00:00
|
|
|
|
|
|
|
// Return the generated code.
|
2013-11-19 12:04:54 +00:00
|
|
|
return GetCode(kind(), Code::FAST, name);
|
2013-02-01 13:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-11 14:05:23 +00:00
|
|
|
void LoadStubCompiler::GenerateLoadPostInterceptor(
|
2013-02-27 15:28:53 +00:00
|
|
|
Register interceptor_reg,
|
|
|
|
Handle<JSObject> interceptor_holder,
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> name,
|
2013-02-27 15:28:53 +00:00
|
|
|
LookupResult* lookup) {
|
|
|
|
Handle<JSObject> holder(lookup->holder());
|
|
|
|
if (lookup->IsField()) {
|
2013-03-04 14:03:27 +00:00
|
|
|
PropertyIndex field = lookup->GetFieldIndex();
|
|
|
|
if (interceptor_holder.is_identical_to(holder)) {
|
2013-05-08 15:02:08 +00:00
|
|
|
GenerateLoadField(
|
|
|
|
interceptor_reg, holder, field, lookup->representation());
|
2013-03-04 14:03:27 +00:00
|
|
|
} else {
|
|
|
|
// We found FIELD property in prototype chain of interceptor's holder.
|
|
|
|
// Retrieve a field from field's holder.
|
|
|
|
Register reg = HandlerFrontend(
|
2013-11-22 15:08:22 +00:00
|
|
|
IC::CurrentTypeOf(interceptor_holder, isolate()),
|
|
|
|
interceptor_reg, holder, name);
|
2013-05-08 15:02:08 +00:00
|
|
|
GenerateLoadField(
|
|
|
|
reg, holder, field, lookup->representation());
|
2013-03-04 14:03:27 +00:00
|
|
|
}
|
2013-02-27 15:28:53 +00:00
|
|
|
} else {
|
|
|
|
// We found CALLBACKS property in prototype chain of interceptor's
|
|
|
|
// holder.
|
|
|
|
ASSERT(lookup->type() == CALLBACKS);
|
|
|
|
Handle<ExecutableAccessorInfo> callback(
|
|
|
|
ExecutableAccessorInfo::cast(lookup->GetCallbackObject()));
|
|
|
|
ASSERT(callback->getter() != NULL);
|
|
|
|
|
|
|
|
Register reg = CallbackHandlerFrontend(
|
2013-11-22 15:08:22 +00:00
|
|
|
IC::CurrentTypeOf(interceptor_holder, isolate()),
|
|
|
|
interceptor_reg, holder, name, callback);
|
2013-02-27 15:28:53 +00:00
|
|
|
GenerateLoadCallback(reg, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-09 08:22:41 +00:00
|
|
|
Handle<Code> BaseLoadStoreStubCompiler::CompileMonomorphicIC(
|
2013-11-18 17:18:14 +00:00
|
|
|
Handle<Type> type,
|
2013-03-04 14:03:27 +00:00
|
|
|
Handle<Code> handler,
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> name) {
|
2013-11-18 17:18:14 +00:00
|
|
|
TypeHandleList types(1);
|
2013-03-04 14:03:27 +00:00
|
|
|
CodeHandleList handlers(1);
|
2013-11-18 17:18:14 +00:00
|
|
|
types.Add(type);
|
2013-03-04 14:03:27 +00:00
|
|
|
handlers.Add(handler);
|
2013-11-18 17:18:14 +00:00
|
|
|
Code::StubType stub_type = handler->type();
|
|
|
|
return CompilePolymorphicIC(&types, &handlers, name, stub_type, PROPERTY);
|
2013-03-04 14:03:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-27 15:28:53 +00:00
|
|
|
Handle<Code> LoadStubCompiler::CompileLoadViaGetter(
|
2013-11-22 15:08:22 +00:00
|
|
|
Handle<Type> type,
|
2013-02-27 15:28:53 +00:00
|
|
|
Handle<JSObject> holder,
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> name,
|
2013-02-27 15:28:53 +00:00
|
|
|
Handle<JSFunction> getter) {
|
2013-11-22 15:08:22 +00:00
|
|
|
HandlerFrontend(type, receiver(), holder, name);
|
2013-10-11 14:05:23 +00:00
|
|
|
GenerateLoadViaGetter(masm(), receiver(), getter);
|
2013-02-27 15:28:53 +00:00
|
|
|
|
|
|
|
// Return the generated code.
|
2013-11-19 12:04:54 +00:00
|
|
|
return GetCode(kind(), Code::FAST, name);
|
2013-02-27 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-11 14:05:23 +00:00
|
|
|
Handle<Code> StoreStubCompiler::CompileStoreTransition(
|
2013-04-11 09:48:03 +00:00
|
|
|
Handle<JSObject> object,
|
|
|
|
LookupResult* lookup,
|
|
|
|
Handle<Map> transition,
|
|
|
|
Handle<Name> name) {
|
2013-07-09 08:22:41 +00:00
|
|
|
Label miss, slow;
|
|
|
|
|
|
|
|
// Ensure no transitions to deprecated maps are followed.
|
|
|
|
__ CheckMapDeprecated(transition, scratch1(), &miss);
|
|
|
|
|
|
|
|
// Check that we are allowed to write this.
|
|
|
|
if (object->GetPrototype()->IsJSObject()) {
|
|
|
|
Handle<JSObject> holder;
|
|
|
|
// holder == object indicates that no property was found.
|
|
|
|
if (lookup->holder() != *object) {
|
|
|
|
holder = Handle<JSObject>(lookup->holder());
|
|
|
|
} else {
|
|
|
|
// Find the top object.
|
|
|
|
holder = object;
|
|
|
|
do {
|
|
|
|
holder = Handle<JSObject>(JSObject::cast(holder->GetPrototype()));
|
|
|
|
} while (holder->GetPrototype()->IsJSObject());
|
|
|
|
}
|
2013-04-11 09:48:03 +00:00
|
|
|
|
2013-11-22 15:08:22 +00:00
|
|
|
Register holder_reg = HandlerFrontendHeader(
|
|
|
|
IC::CurrentTypeOf(object, isolate()), receiver(), holder, name, &miss);
|
2013-07-09 08:22:41 +00:00
|
|
|
|
|
|
|
// If no property was found, and the holder (the last object in the
|
|
|
|
// prototype chain) is in slow mode, we need to do a negative lookup on the
|
|
|
|
// holder.
|
|
|
|
if (lookup->holder() == *object) {
|
|
|
|
GenerateNegativeHolderLookup(masm(), holder, holder_reg, name, &miss);
|
|
|
|
}
|
|
|
|
}
|
2013-04-11 09:48:03 +00:00
|
|
|
|
|
|
|
GenerateStoreTransition(masm(),
|
|
|
|
object,
|
|
|
|
lookup,
|
|
|
|
transition,
|
|
|
|
name,
|
|
|
|
receiver(), this->name(), value(),
|
2013-05-08 15:02:08 +00:00
|
|
|
scratch1(), scratch2(), scratch3(),
|
2013-04-11 09:48:03 +00:00
|
|
|
&miss,
|
2013-05-08 15:02:08 +00:00
|
|
|
&slow);
|
2013-04-11 09:48:03 +00:00
|
|
|
|
|
|
|
// Handle store cache miss.
|
2013-07-09 08:22:41 +00:00
|
|
|
GenerateRestoreName(masm(), &miss, name);
|
2013-04-11 09:48:03 +00:00
|
|
|
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
|
|
|
|
2013-05-08 15:02:08 +00:00
|
|
|
GenerateRestoreName(masm(), &slow, name);
|
|
|
|
TailCallBuiltin(masm(), SlowBuiltin(kind()));
|
|
|
|
|
2013-04-11 09:48:03 +00:00
|
|
|
// Return the generated code.
|
2013-11-19 12:04:54 +00:00
|
|
|
return GetCode(kind(), Code::FAST, name);
|
2013-04-11 09:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-11 14:05:23 +00:00
|
|
|
Handle<Code> StoreStubCompiler::CompileStoreField(Handle<JSObject> object,
|
|
|
|
LookupResult* lookup,
|
|
|
|
Handle<Name> name) {
|
2013-04-11 09:48:03 +00:00
|
|
|
Label miss;
|
2013-03-13 14:11:05 +00:00
|
|
|
|
2013-11-22 15:08:22 +00:00
|
|
|
HandlerFrontendHeader(IC::CurrentTypeOf(object, isolate()),
|
|
|
|
receiver(), object, name, &miss);
|
2013-03-13 14:11:05 +00:00
|
|
|
|
|
|
|
// Generate store field code.
|
|
|
|
GenerateStoreField(masm(),
|
|
|
|
object,
|
2013-03-25 12:55:27 +00:00
|
|
|
lookup,
|
2013-03-13 14:11:05 +00:00
|
|
|
receiver(), this->name(), value(), scratch1(), scratch2(),
|
2013-04-11 09:48:03 +00:00
|
|
|
&miss);
|
2013-03-13 14:11:05 +00:00
|
|
|
|
|
|
|
// Handle store cache miss.
|
|
|
|
__ bind(&miss);
|
|
|
|
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
|
|
|
|
|
|
|
// Return the generated code.
|
2013-11-19 12:04:54 +00:00
|
|
|
return GetCode(kind(), Code::FAST, name);
|
2013-03-13 14:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-15 12:07:35 +00:00
|
|
|
Handle<Code> StoreStubCompiler::CompileStoreViaSetter(
|
|
|
|
Handle<JSObject> object,
|
|
|
|
Handle<JSObject> holder,
|
2013-07-09 08:22:41 +00:00
|
|
|
Handle<Name> name,
|
2013-03-15 12:07:35 +00:00
|
|
|
Handle<JSFunction> setter) {
|
2013-11-22 15:08:22 +00:00
|
|
|
HandlerFrontend(IC::CurrentTypeOf(object, isolate()),
|
|
|
|
receiver(), holder, name);
|
2013-03-15 12:07:35 +00:00
|
|
|
GenerateStoreViaSetter(masm(), setter);
|
|
|
|
|
2013-11-19 12:04:54 +00:00
|
|
|
return GetCode(kind(), Code::FAST, name);
|
2013-03-15 12:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> KeyedLoadStubCompiler::CompileLoadElement(
|
|
|
|
Handle<Map> receiver_map) {
|
|
|
|
ElementsKind elements_kind = receiver_map->elements_kind();
|
|
|
|
if (receiver_map->has_fast_elements() ||
|
|
|
|
receiver_map->has_external_array_elements()) {
|
|
|
|
Handle<Code> stub = KeyedLoadFastElementStub(
|
|
|
|
receiver_map->instance_type() == JS_ARRAY_TYPE,
|
|
|
|
elements_kind).GetCode(isolate());
|
|
|
|
__ DispatchMap(receiver(), scratch1(), receiver_map, stub, DO_SMI_CHECK);
|
|
|
|
} else {
|
2013-11-15 17:53:35 +00:00
|
|
|
Handle<Code> stub = FLAG_compiled_keyed_dictionary_loads
|
|
|
|
? KeyedLoadDictionaryElementStub().GetCode(isolate())
|
|
|
|
: KeyedLoadDictionaryElementPlatformStub().GetCode(isolate());
|
2013-03-15 12:07:35 +00:00
|
|
|
__ DispatchMap(receiver(), scratch1(), receiver_map, stub, DO_SMI_CHECK);
|
|
|
|
}
|
|
|
|
|
|
|
|
TailCallBuiltin(masm(), Builtins::kKeyedLoadIC_Miss);
|
|
|
|
|
|
|
|
// Return the generated code.
|
|
|
|
return GetICCode(kind(), Code::NORMAL, factory()->empty_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> KeyedStoreStubCompiler::CompileStoreElement(
|
|
|
|
Handle<Map> receiver_map) {
|
|
|
|
ElementsKind elements_kind = receiver_map->elements_kind();
|
|
|
|
bool is_jsarray = receiver_map->instance_type() == JS_ARRAY_TYPE;
|
2013-03-20 10:37:13 +00:00
|
|
|
Handle<Code> stub;
|
2013-08-19 22:12:46 +00:00
|
|
|
if (receiver_map->has_fast_elements() ||
|
|
|
|
receiver_map->has_external_array_elements()) {
|
2013-03-20 10:37:13 +00:00
|
|
|
stub = KeyedStoreFastElementStub(
|
|
|
|
is_jsarray,
|
|
|
|
elements_kind,
|
2013-12-02 11:59:44 +00:00
|
|
|
store_mode()).GetCode(isolate());
|
2013-03-20 10:37:13 +00:00
|
|
|
} else {
|
|
|
|
stub = KeyedStoreElementStub(is_jsarray,
|
|
|
|
elements_kind,
|
2013-12-02 11:59:44 +00:00
|
|
|
store_mode()).GetCode(isolate());
|
2013-03-20 10:37:13 +00:00
|
|
|
}
|
2013-03-15 12:07:35 +00:00
|
|
|
|
|
|
|
__ DispatchMap(receiver(), scratch1(), receiver_map, stub, DO_SMI_CHECK);
|
|
|
|
|
|
|
|
TailCallBuiltin(masm(), Builtins::kKeyedStoreIC_Miss);
|
|
|
|
|
|
|
|
// Return the generated code.
|
|
|
|
return GetICCode(kind(), Code::NORMAL, factory()->empty_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 13:39:36 +00:00
|
|
|
#undef __
|
|
|
|
|
|
|
|
|
2013-03-13 14:11:05 +00:00
|
|
|
void StubCompiler::TailCallBuiltin(MacroAssembler* masm, Builtins::Name name) {
|
|
|
|
Handle<Code> code(masm->isolate()->builtins()->builtin(name));
|
|
|
|
GenerateTailCall(masm, code);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-11 14:05:23 +00:00
|
|
|
void BaseLoadStoreStubCompiler::JitEvent(Handle<Name> name, Handle<Code> code) {
|
|
|
|
#ifdef ENABLE_GDB_JIT_INTERFACE
|
|
|
|
GDBJITInterface::CodeTag tag;
|
|
|
|
if (kind_ == Code::LOAD_IC) {
|
|
|
|
tag = GDBJITInterface::LOAD_IC;
|
|
|
|
} else if (kind_ == Code::KEYED_LOAD_IC) {
|
|
|
|
tag = GDBJITInterface::KEYED_LOAD_IC;
|
|
|
|
} else if (kind_ == Code::STORE_IC) {
|
|
|
|
tag = GDBJITInterface::STORE_IC;
|
|
|
|
} else {
|
|
|
|
tag = GDBJITInterface::KEYED_STORE_IC;
|
|
|
|
}
|
|
|
|
GDBJIT(AddCode(tag, *name, *code));
|
|
|
|
#endif
|
2013-09-11 16:27:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-11 14:05:23 +00:00
|
|
|
void BaseLoadStoreStubCompiler::InitializeRegisters() {
|
|
|
|
if (kind_ == Code::LOAD_IC) {
|
|
|
|
registers_ = LoadStubCompiler::registers();
|
|
|
|
} else if (kind_ == Code::KEYED_LOAD_IC) {
|
|
|
|
registers_ = KeyedLoadStubCompiler::registers();
|
|
|
|
} else if (kind_ == Code::STORE_IC) {
|
|
|
|
registers_ = StoreStubCompiler::registers();
|
|
|
|
} else {
|
|
|
|
registers_ = KeyedStoreStubCompiler::registers();
|
|
|
|
}
|
2013-03-13 14:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-09 08:22:41 +00:00
|
|
|
Handle<Code> BaseLoadStoreStubCompiler::GetICCode(Code::Kind kind,
|
|
|
|
Code::StubType type,
|
|
|
|
Handle<Name> name,
|
|
|
|
InlineCacheState state) {
|
2013-10-01 09:30:07 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(kind, state, extra_state(), type);
|
2013-03-05 17:38:35 +00:00
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, name);
|
|
|
|
PROFILE(isolate(), CodeCreateEvent(log_kind(code), *code, *name));
|
|
|
|
JitEvent(name, code);
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-01 09:30:07 +00:00
|
|
|
Handle<Code> BaseLoadStoreStubCompiler::GetCode(Code::Kind kind,
|
|
|
|
Code::StubType type,
|
|
|
|
Handle<Name> name) {
|
2013-03-13 14:11:05 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(
|
2013-11-14 16:25:31 +00:00
|
|
|
Code::HANDLER, MONOMORPHIC, extra_state(), type, kind, cache_holder_);
|
2013-03-13 14:11:05 +00:00
|
|
|
Handle<Code> code = GetCodeWithFlags(flags, name);
|
|
|
|
PROFILE(isolate(), CodeCreateEvent(log_kind(code), *code, *name));
|
|
|
|
JitEvent(name, code);
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 14:03:27 +00:00
|
|
|
void KeyedLoadStubCompiler::CompileElementHandlers(MapHandleList* receiver_maps,
|
|
|
|
CodeHandleList* handlers) {
|
2013-01-23 15:35:43 +00:00
|
|
|
for (int i = 0; i < receiver_maps->length(); ++i) {
|
|
|
|
Handle<Map> receiver_map = receiver_maps->at(i);
|
|
|
|
Handle<Code> cached_stub;
|
|
|
|
|
|
|
|
if ((receiver_map->instance_type() & kNotStringTag) == 0) {
|
|
|
|
cached_stub = isolate()->builtins()->KeyedLoadIC_String();
|
2014-01-08 09:57:28 +00:00
|
|
|
} else if (receiver_map->instance_type() < FIRST_JS_RECEIVER_TYPE) {
|
|
|
|
cached_stub = isolate()->builtins()->KeyedLoadIC_Slow();
|
2013-01-23 15:35:43 +00:00
|
|
|
} else {
|
|
|
|
bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE;
|
|
|
|
ElementsKind elements_kind = receiver_map->elements_kind();
|
|
|
|
|
|
|
|
if (IsFastElementsKind(elements_kind) ||
|
|
|
|
IsExternalArrayElementsKind(elements_kind)) {
|
|
|
|
cached_stub =
|
2013-02-27 12:33:24 +00:00
|
|
|
KeyedLoadFastElementStub(is_js_array,
|
|
|
|
elements_kind).GetCode(isolate());
|
2013-01-23 15:35:43 +00:00
|
|
|
} else {
|
|
|
|
ASSERT(elements_kind == DICTIONARY_ELEMENTS);
|
2013-02-27 12:33:24 +00:00
|
|
|
cached_stub = KeyedLoadDictionaryElementStub().GetCode(isolate());
|
2013-01-23 15:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-04 14:03:27 +00:00
|
|
|
handlers->Add(cached_stub);
|
2013-01-23 15:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> KeyedStoreStubCompiler::CompileStoreElementPolymorphic(
|
|
|
|
MapHandleList* receiver_maps) {
|
|
|
|
// Collect MONOMORPHIC stubs for all |receiver_maps|.
|
2013-03-04 14:03:27 +00:00
|
|
|
CodeHandleList handlers(receiver_maps->length());
|
2013-01-23 15:35:43 +00:00
|
|
|
MapHandleList transitioned_maps(receiver_maps->length());
|
|
|
|
for (int i = 0; i < receiver_maps->length(); ++i) {
|
|
|
|
Handle<Map> receiver_map(receiver_maps->at(i));
|
|
|
|
Handle<Code> cached_stub;
|
|
|
|
Handle<Map> transitioned_map =
|
|
|
|
receiver_map->FindTransitionedMap(receiver_maps);
|
|
|
|
|
|
|
|
// TODO(mvstanton): The code below is doing pessimistic elements
|
|
|
|
// transitions. I would like to stop doing that and rely on Allocation Site
|
|
|
|
// Tracking to do a better job of ensuring the data types are what they need
|
|
|
|
// to be. Not all the elements are in place yet, pessimistic elements
|
|
|
|
// transitions are still important for performance.
|
|
|
|
bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE;
|
|
|
|
ElementsKind elements_kind = receiver_map->elements_kind();
|
|
|
|
if (!transitioned_map.is_null()) {
|
2013-07-29 09:12:16 +00:00
|
|
|
cached_stub = ElementsTransitionAndStoreStub(
|
|
|
|
elements_kind,
|
|
|
|
transitioned_map->elements_kind(),
|
|
|
|
is_js_array,
|
2013-12-02 11:59:44 +00:00
|
|
|
store_mode()).GetCode(isolate());
|
2014-01-08 09:57:28 +00:00
|
|
|
} else if (receiver_map->instance_type() < FIRST_JS_RECEIVER_TYPE) {
|
|
|
|
cached_stub = isolate()->builtins()->KeyedStoreIC_Slow();
|
2013-01-23 15:35:43 +00:00
|
|
|
} else {
|
2013-08-19 22:12:46 +00:00
|
|
|
if (receiver_map->has_fast_elements() ||
|
|
|
|
receiver_map->has_external_array_elements()) {
|
2013-03-20 10:37:13 +00:00
|
|
|
cached_stub = KeyedStoreFastElementStub(
|
|
|
|
is_js_array,
|
|
|
|
elements_kind,
|
2013-12-02 11:59:44 +00:00
|
|
|
store_mode()).GetCode(isolate());
|
2013-03-20 10:37:13 +00:00
|
|
|
} else {
|
|
|
|
cached_stub = KeyedStoreElementStub(
|
|
|
|
is_js_array,
|
|
|
|
elements_kind,
|
2013-12-02 11:59:44 +00:00
|
|
|
store_mode()).GetCode(isolate());
|
2013-03-20 10:37:13 +00:00
|
|
|
}
|
2013-01-23 15:35:43 +00:00
|
|
|
}
|
|
|
|
ASSERT(!cached_stub.is_null());
|
2013-03-04 14:03:27 +00:00
|
|
|
handlers.Add(cached_stub);
|
2013-01-23 15:35:43 +00:00
|
|
|
transitioned_maps.Add(transitioned_map);
|
|
|
|
}
|
|
|
|
Handle<Code> code =
|
2013-03-04 14:03:27 +00:00
|
|
|
CompileStorePolymorphic(receiver_maps, &handlers, &transitioned_maps);
|
2013-01-23 15:35:43 +00:00
|
|
|
isolate()->counters()->keyed_store_polymorphic_stubs()->Increment();
|
|
|
|
PROFILE(isolate(),
|
|
|
|
CodeCreateEvent(Logger::KEYED_STORE_POLYMORPHIC_IC_TAG, *code, 0));
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
2013-11-28 15:32:55 +00:00
|
|
|
ExtraICState extra_state,
|
2010-07-02 14:15:04 +00:00
|
|
|
InlineCacheHolderFlag cache_holder)
|
2013-12-02 11:59:44 +00:00
|
|
|
: StubCompiler(isolate, extra_state),
|
2011-10-18 12:19:18 +00:00
|
|
|
arguments_(argc),
|
2011-01-18 16:54:48 +00:00
|
|
|
kind_(kind),
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-19 09:25:24 +00:00
|
|
|
bool CallStubCompiler::CanBeCached(Handle<JSFunction> function) {
|
|
|
|
if (function->shared()->HasBuiltinFunctionId()) {
|
|
|
|
BuiltinFunctionId id = function->shared()->builtin_function_id();
|
|
|
|
#define CALL_GENERATOR_CASE(name) if (id == k##name) return false;
|
|
|
|
SITE_SPECIFIC_CALL_GENERATORS(CALL_GENERATOR_CASE)
|
|
|
|
#undef CALL_GENERATOR_CASE
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-28 12:37:29 +00:00
|
|
|
Handle<Code> CallStubCompiler::CompileCustomCall(
|
|
|
|
Handle<Object> object,
|
|
|
|
Handle<JSObject> holder,
|
2013-06-12 15:03:44 +00:00
|
|
|
Handle<Cell> cell,
|
2011-10-28 12:37:29 +00:00
|
|
|
Handle<JSFunction> function,
|
2013-06-19 09:25:24 +00:00
|
|
|
Handle<String> fname,
|
|
|
|
Code::StubType type) {
|
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, \
|
2013-06-19 09:25:24 +00:00
|
|
|
fname, \
|
|
|
|
type); \
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-25 11:35:23 +00:00
|
|
|
Handle<Code> CallStubCompiler::GetCode(Code::StubType type,
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<Name> name) {
|
2011-10-25 09:24:49 +00:00
|
|
|
int argc = arguments_.immediate();
|
2013-11-14 16:25:31 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(
|
2013-12-02 11:59:44 +00:00
|
|
|
kind_, extra_state(), cache_holder_, type, argc);
|
2011-10-25 09:24:49 +00:00
|
|
|
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()));
|
|
|
|
}
|
2013-11-19 12:04:54 +00:00
|
|
|
return GetCode(Code::FAST, function_name);
|
2011-10-25 09:24:49 +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() &&
|
2013-07-24 12:34:50 +00:00
|
|
|
lookup->IsConstantFunction()) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +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)) {
|
2013-11-19 13:38:15 +00:00
|
|
|
if (expected_receiver_type_->IsTemplateFor(object->map())) return depth;
|
2011-10-28 12:37:29 +00:00
|
|
|
object = Handle<JSObject>(JSObject::cast(object->GetPrototype()));
|
2012-12-04 13:45:48 +00:00
|
|
|
if (!object->map()->is_hidden_prototype()) return kInvalidProtoDepth;
|
2010-04-28 14:06:35 +00:00
|
|
|
++depth;
|
|
|
|
}
|
2013-11-19 13:38:15 +00:00
|
|
|
if (expected_receiver_type_->IsTemplateFor(holder->map())) 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
|