2012-02-10 12:36:05 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2010-03-24 15:29:41 +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.
|
|
|
|
|
2010-03-26 11:34:00 +00:00
|
|
|
#include "v8.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
#include "ast.h"
|
2011-06-20 10:19:00 +00:00
|
|
|
#include "code-stubs.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "compiler.h"
|
|
|
|
#include "ic.h"
|
|
|
|
#include "macro-assembler.h"
|
|
|
|
#include "stub-cache.h"
|
2010-03-25 12:44:15 +00:00
|
|
|
#include "type-info.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
#include "ic-inl.h"
|
2010-03-24 15:29:41 +00:00
|
|
|
#include "objects-inl.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
2013-06-12 17:20:37 +00:00
|
|
|
TypeInfo TypeInfo::FromValue(Handle<Object> value) {
|
2010-03-24 15:29:41 +00:00
|
|
|
if (value->IsSmi()) {
|
2013-06-12 17:20:37 +00:00
|
|
|
return TypeInfo::Smi();
|
2010-03-24 15:29:41 +00:00
|
|
|
} else if (value->IsHeapNumber()) {
|
2013-06-12 17:20:37 +00:00
|
|
|
return TypeInfo::IsInt32Double(HeapNumber::cast(*value)->value())
|
2010-03-25 12:44:15 +00:00
|
|
|
? TypeInfo::Integer32()
|
|
|
|
: TypeInfo::Double();
|
2010-03-29 11:48:57 +00:00
|
|
|
} else if (value->IsString()) {
|
2013-06-12 17:20:37 +00:00
|
|
|
return TypeInfo::String();
|
2010-03-24 15:29:41 +00:00
|
|
|
}
|
2013-06-12 17:20:37 +00:00
|
|
|
return TypeInfo::Unknown();
|
2010-03-24 15:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-13 14:16:08 +00:00
|
|
|
TypeFeedbackOracle::TypeFeedbackOracle(Handle<Code> code,
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Context> native_context,
|
2012-06-11 12:42:31 +00:00
|
|
|
Isolate* isolate,
|
2013-03-12 07:06:36 +00:00
|
|
|
Zone* zone)
|
|
|
|
: native_context_(native_context),
|
|
|
|
isolate_(isolate),
|
|
|
|
zone_(zone) {
|
2011-06-20 12:33:08 +00:00
|
|
|
BuildDictionary(code);
|
2013-05-07 12:02:15 +00:00
|
|
|
ASSERT(dictionary_->IsDictionary());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
static uint32_t IdToKey(TypeFeedbackId ast_id) {
|
|
|
|
return static_cast<uint32_t>(ast_id.ToInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> TypeFeedbackOracle::GetInfo(TypeFeedbackId ast_id) {
|
|
|
|
int entry = dictionary_->FindEntry(IdToKey(ast_id));
|
2013-06-07 13:21:20 +00:00
|
|
|
if (entry != UnseededNumberDictionary::kNotFound) {
|
|
|
|
Object* value = dictionary_->ValueAt(entry);
|
2013-06-12 15:03:44 +00:00
|
|
|
if (value->IsCell()) {
|
|
|
|
Cell* cell = Cell::cast(value);
|
2013-06-07 13:21:20 +00:00
|
|
|
return Handle<Object>(cell->value(), isolate_);
|
|
|
|
} else {
|
|
|
|
return Handle<Object>(value, isolate_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Handle<Object>::cast(isolate_->factory()->undefined_value());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-12 15:03:44 +00:00
|
|
|
Handle<Cell> TypeFeedbackOracle::GetInfoCell(
|
2013-06-07 13:21:20 +00:00
|
|
|
TypeFeedbackId ast_id) {
|
|
|
|
int entry = dictionary_->FindEntry(IdToKey(ast_id));
|
|
|
|
if (entry != UnseededNumberDictionary::kNotFound) {
|
2013-06-12 15:03:44 +00:00
|
|
|
Cell* cell = Cell::cast(dictionary_->ValueAt(entry));
|
|
|
|
return Handle<Cell>(cell, isolate_);
|
2013-06-07 13:21:20 +00:00
|
|
|
}
|
2013-06-12 15:03:44 +00:00
|
|
|
return Handle<Cell>::null();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-19 15:54:37 +00:00
|
|
|
bool TypeFeedbackOracle::LoadIsUninitialized(Property* expr) {
|
2012-08-06 14:13:09 +00:00
|
|
|
Handle<Object> map_or_code = GetInfo(expr->PropertyFeedbackId());
|
2012-03-19 15:54:37 +00:00
|
|
|
if (map_or_code->IsMap()) return false;
|
|
|
|
if (map_or_code->IsCode()) {
|
|
|
|
Handle<Code> code = Handle<Code>::cast(map_or_code);
|
|
|
|
return code->is_inline_cache_stub() && code->ic_state() == UNINITIALIZED;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-16 06:37:49 +00:00
|
|
|
bool TypeFeedbackOracle::LoadIsMonomorphicNormal(Property* expr) {
|
2012-08-06 14:13:09 +00:00
|
|
|
Handle<Object> map_or_code = GetInfo(expr->PropertyFeedbackId());
|
2011-03-09 15:01:16 +00:00
|
|
|
if (map_or_code->IsMap()) return true;
|
|
|
|
if (map_or_code->IsCode()) {
|
2011-05-19 13:26:47 +00:00
|
|
|
Handle<Code> code = Handle<Code>::cast(map_or_code);
|
2012-08-06 14:25:19 +00:00
|
|
|
bool preliminary_checks = code->is_keyed_load_stub() &&
|
2011-05-18 13:17:29 +00:00
|
|
|
code->ic_state() == MONOMORPHIC &&
|
2012-08-06 14:25:19 +00:00
|
|
|
Code::ExtractTypeFromFlags(code->flags()) == Code::NORMAL;
|
|
|
|
if (!preliminary_checks) return false;
|
|
|
|
Map* map = code->FindFirstMap();
|
2013-05-21 11:20:24 +00:00
|
|
|
if (map == NULL) return false;
|
|
|
|
map = map->CurrentMapForDeprecated();
|
2012-08-17 09:03:08 +00:00
|
|
|
return map != NULL && !CanRetainOtherContext(map, *native_context_);
|
2011-03-09 15:01:16 +00:00
|
|
|
}
|
|
|
|
return false;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-23 10:41:21 +00:00
|
|
|
bool TypeFeedbackOracle::LoadIsPreMonomorphic(Property* expr) {
|
|
|
|
Handle<Object> map_or_code = GetInfo(expr->PropertyFeedbackId());
|
|
|
|
if (map_or_code->IsCode()) {
|
|
|
|
Handle<Code> code = Handle<Code>::cast(map_or_code);
|
|
|
|
return code->is_inline_cache_stub() && code->ic_state() == PREMONOMORPHIC;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-08 12:01:51 +00:00
|
|
|
bool TypeFeedbackOracle::LoadIsPolymorphic(Property* expr) {
|
2012-08-06 14:13:09 +00:00
|
|
|
Handle<Object> map_or_code = GetInfo(expr->PropertyFeedbackId());
|
2011-06-20 10:19:00 +00:00
|
|
|
if (map_or_code->IsCode()) {
|
|
|
|
Handle<Code> code = Handle<Code>::cast(map_or_code);
|
2013-01-08 12:01:51 +00:00
|
|
|
return code->is_keyed_load_stub() && code->ic_state() == POLYMORPHIC;
|
2011-06-20 10:19:00 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 13:09:43 +00:00
|
|
|
bool TypeFeedbackOracle::StoreIsUninitialized(TypeFeedbackId ast_id) {
|
|
|
|
Handle<Object> map_or_code = GetInfo(ast_id);
|
|
|
|
if (map_or_code->IsMap()) return false;
|
2013-07-11 07:52:57 +00:00
|
|
|
if (!map_or_code->IsCode()) return false;
|
2013-06-20 13:09:43 +00:00
|
|
|
Handle<Code> code = Handle<Code>::cast(map_or_code);
|
|
|
|
return code->ic_state() == UNINITIALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
bool TypeFeedbackOracle::StoreIsMonomorphicNormal(TypeFeedbackId ast_id) {
|
|
|
|
Handle<Object> map_or_code = GetInfo(ast_id);
|
2011-03-09 15:01:16 +00:00
|
|
|
if (map_or_code->IsMap()) return true;
|
|
|
|
if (map_or_code->IsCode()) {
|
2011-05-19 13:26:47 +00:00
|
|
|
Handle<Code> code = Handle<Code>::cast(map_or_code);
|
2012-08-06 14:25:19 +00:00
|
|
|
bool preliminary_checks =
|
|
|
|
code->is_keyed_store_stub() &&
|
2011-06-16 06:37:49 +00:00
|
|
|
code->ic_state() == MONOMORPHIC &&
|
2012-08-06 14:25:19 +00:00
|
|
|
Code::ExtractTypeFromFlags(code->flags()) == Code::NORMAL;
|
|
|
|
if (!preliminary_checks) return false;
|
|
|
|
Map* map = code->FindFirstMap();
|
2013-05-21 11:20:24 +00:00
|
|
|
if (map == NULL) return false;
|
|
|
|
map = map->CurrentMapForDeprecated();
|
2012-08-17 09:03:08 +00:00
|
|
|
return map != NULL && !CanRetainOtherContext(map, *native_context_);
|
2011-03-09 15:01:16 +00:00
|
|
|
}
|
|
|
|
return false;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-23 10:41:21 +00:00
|
|
|
bool TypeFeedbackOracle::StoreIsPreMonomorphic(TypeFeedbackId ast_id) {
|
|
|
|
Handle<Object> map_or_code = GetInfo(ast_id);
|
|
|
|
if (map_or_code->IsCode()) {
|
|
|
|
Handle<Code> code = Handle<Code>::cast(map_or_code);
|
|
|
|
return code->ic_state() == PREMONOMORPHIC;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-09 08:22:41 +00:00
|
|
|
bool TypeFeedbackOracle::StoreIsKeyedPolymorphic(TypeFeedbackId ast_id) {
|
2012-08-06 14:13:09 +00:00
|
|
|
Handle<Object> map_or_code = GetInfo(ast_id);
|
2011-06-20 10:19:00 +00:00
|
|
|
if (map_or_code->IsCode()) {
|
|
|
|
Handle<Code> code = Handle<Code>::cast(map_or_code);
|
2013-08-19 22:12:46 +00:00
|
|
|
return code->is_keyed_store_stub() &&
|
2013-01-08 12:01:51 +00:00
|
|
|
code->ic_state() == POLYMORPHIC;
|
2011-06-20 10:19:00 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
bool TypeFeedbackOracle::CallIsMonomorphic(Call* expr) {
|
2012-08-06 14:13:09 +00:00
|
|
|
Handle<Object> value = GetInfo(expr->CallFeedbackId());
|
2013-07-08 10:02:16 +00:00
|
|
|
return value->IsMap() || value->IsAllocationSite() || value->IsJSFunction() ||
|
2013-11-14 15:00:13 +00:00
|
|
|
value->IsSmi();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-27 13:03:19 +00:00
|
|
|
bool TypeFeedbackOracle::CallNewIsMonomorphic(CallNew* expr) {
|
2013-03-01 16:06:34 +00:00
|
|
|
Handle<Object> info = GetInfo(expr->CallNewFeedbackId());
|
2013-07-08 10:02:16 +00:00
|
|
|
return info->IsAllocationSite() || info->IsJSFunction();
|
2012-01-27 13:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-13 12:11:46 +00:00
|
|
|
bool TypeFeedbackOracle::ObjectLiteralStoreIsMonomorphic(
|
|
|
|
ObjectLiteral::Property* prop) {
|
2012-08-06 14:13:09 +00:00
|
|
|
Handle<Object> map_or_code = GetInfo(prop->key()->LiteralFeedbackId());
|
2012-03-13 12:11:46 +00:00
|
|
|
return map_or_code->IsMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-27 13:59:20 +00:00
|
|
|
byte TypeFeedbackOracle::ForInType(ForInStatement* stmt) {
|
2012-08-06 14:13:09 +00:00
|
|
|
Handle<Object> value = GetInfo(stmt->ForInFeedbackId());
|
2012-03-02 11:33:33 +00:00
|
|
|
return value->IsSmi() &&
|
2013-05-27 13:59:20 +00:00
|
|
|
Smi::cast(*value)->value() == TypeFeedbackCells::kForInFastCaseMarker
|
|
|
|
? ForInStatement::FAST_FOR_IN : ForInStatement::SLOW_FOR_IN;
|
2012-03-02 11:33:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
Handle<Map> TypeFeedbackOracle::LoadMonomorphicReceiverType(Property* expr) {
|
2011-06-16 06:37:49 +00:00
|
|
|
ASSERT(LoadIsMonomorphicNormal(expr));
|
2012-08-06 14:13:09 +00:00
|
|
|
Handle<Object> map_or_code = GetInfo(expr->PropertyFeedbackId());
|
2011-03-09 15:01:16 +00:00
|
|
|
if (map_or_code->IsCode()) {
|
2011-05-19 13:26:47 +00:00
|
|
|
Handle<Code> code = Handle<Code>::cast(map_or_code);
|
2013-05-21 11:20:24 +00:00
|
|
|
Map* map = code->FindFirstMap()->CurrentMapForDeprecated();
|
|
|
|
return map == NULL || CanRetainOtherContext(map, *native_context_)
|
2011-12-19 12:39:52 +00:00
|
|
|
? Handle<Map>::null()
|
2013-05-21 11:20:24 +00:00
|
|
|
: Handle<Map>(map);
|
2011-03-09 15:01:16 +00:00
|
|
|
}
|
2013-05-21 11:20:24 +00:00
|
|
|
return Handle<Map>::cast(map_or_code);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
Handle<Map> TypeFeedbackOracle::StoreMonomorphicReceiverType(
|
|
|
|
TypeFeedbackId ast_id) {
|
|
|
|
ASSERT(StoreIsMonomorphicNormal(ast_id));
|
|
|
|
Handle<Object> map_or_code = GetInfo(ast_id);
|
2011-03-09 15:01:16 +00:00
|
|
|
if (map_or_code->IsCode()) {
|
2011-05-19 13:26:47 +00:00
|
|
|
Handle<Code> code = Handle<Code>::cast(map_or_code);
|
2013-05-21 11:20:24 +00:00
|
|
|
Map* map = code->FindFirstMap()->CurrentMapForDeprecated();
|
|
|
|
return map == NULL || CanRetainOtherContext(map, *native_context_)
|
2011-12-19 12:39:52 +00:00
|
|
|
? Handle<Map>::null()
|
2013-05-21 11:20:24 +00:00
|
|
|
: Handle<Map>(map);
|
2011-03-09 15:01:16 +00:00
|
|
|
}
|
2013-05-21 11:20:24 +00:00
|
|
|
return Handle<Map>::cast(map_or_code);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-06 21:51:07 +00:00
|
|
|
KeyedAccessStoreMode TypeFeedbackOracle::GetStoreMode(
|
|
|
|
TypeFeedbackId ast_id) {
|
|
|
|
Handle<Object> map_or_code = GetInfo(ast_id);
|
|
|
|
if (map_or_code->IsCode()) {
|
|
|
|
Handle<Code> code = Handle<Code>::cast(map_or_code);
|
|
|
|
if (code->kind() == Code::KEYED_STORE_IC) {
|
|
|
|
return Code::GetKeyedAccessStoreMode(code->extra_ic_state());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return STANDARD_STORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-22 14:23:37 +00:00
|
|
|
void TypeFeedbackOracle::LoadReceiverTypes(Property* expr,
|
|
|
|
Handle<String> name,
|
|
|
|
SmallMapList* types) {
|
2013-06-20 12:07:56 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(
|
2013-09-30 13:53:21 +00:00
|
|
|
Code::HANDLER, MONOMORPHIC, Code::kNoExtraICState,
|
2013-06-20 12:07:56 +00:00
|
|
|
Code::NORMAL, Code::LOAD_IC);
|
2012-08-06 14:13:09 +00:00
|
|
|
CollectReceiverTypes(expr->PropertyFeedbackId(), name, flags, types);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-22 14:23:37 +00:00
|
|
|
void TypeFeedbackOracle::StoreReceiverTypes(Assignment* expr,
|
|
|
|
Handle<String> name,
|
|
|
|
SmallMapList* types) {
|
2013-07-09 08:22:41 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(
|
2013-09-30 13:53:21 +00:00
|
|
|
Code::HANDLER, MONOMORPHIC, Code::kNoExtraICState,
|
2013-07-09 08:22:41 +00:00
|
|
|
Code::NORMAL, Code::STORE_IC);
|
2012-08-06 14:13:09 +00:00
|
|
|
CollectReceiverTypes(expr->AssignmentFeedbackId(), name, flags, types);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-22 14:23:37 +00:00
|
|
|
void TypeFeedbackOracle::CallReceiverTypes(Call* expr,
|
|
|
|
Handle<String> name,
|
|
|
|
CallKind call_kind,
|
|
|
|
SmallMapList* types) {
|
2010-12-07 11:31:57 +00:00
|
|
|
int arity = expr->arguments()->length();
|
2011-05-24 14:01:36 +00:00
|
|
|
|
|
|
|
// Note: Currently we do not take string extra ic data into account
|
|
|
|
// here.
|
|
|
|
Code::ExtraICState extra_ic_state =
|
|
|
|
CallIC::Contextual::encode(call_kind == CALL_AS_FUNCTION);
|
|
|
|
|
2011-01-18 16:54:48 +00:00
|
|
|
Code::Flags flags = Code::ComputeMonomorphicFlags(Code::CALL_IC,
|
2011-05-24 14:01:36 +00:00
|
|
|
extra_ic_state,
|
2013-02-27 15:33:37 +00:00
|
|
|
Code::NORMAL,
|
|
|
|
arity,
|
|
|
|
OWN_MAP);
|
2012-08-06 14:13:09 +00:00
|
|
|
CollectReceiverTypes(expr->CallFeedbackId(), name, flags, types);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-13 14:16:08 +00:00
|
|
|
CheckType TypeFeedbackOracle::GetCallCheckType(Call* expr) {
|
2012-08-06 14:13:09 +00:00
|
|
|
Handle<Object> value = GetInfo(expr->CallFeedbackId());
|
2011-01-13 14:16:08 +00:00
|
|
|
if (!value->IsSmi()) return RECEIVER_MAP_CHECK;
|
|
|
|
CheckType check = static_cast<CheckType>(Smi::cast(*value)->value());
|
|
|
|
ASSERT(check != RECEIVER_MAP_CHECK);
|
|
|
|
return check;
|
|
|
|
}
|
|
|
|
|
2011-09-27 11:42:02 +00:00
|
|
|
|
|
|
|
Handle<JSFunction> TypeFeedbackOracle::GetCallTarget(Call* expr) {
|
2013-06-05 10:43:18 +00:00
|
|
|
Handle<Object> info = GetInfo(expr->CallFeedbackId());
|
2013-07-08 10:02:16 +00:00
|
|
|
if (info->IsAllocationSite()) {
|
2013-06-05 10:43:18 +00:00
|
|
|
return Handle<JSFunction>(isolate_->global_context()->array_function());
|
|
|
|
} else {
|
|
|
|
return Handle<JSFunction>::cast(info);
|
|
|
|
}
|
2011-09-27 11:42:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 09:05:55 +00:00
|
|
|
Handle<JSFunction> TypeFeedbackOracle::GetCallNewTarget(CallNew* expr) {
|
2013-03-01 16:06:34 +00:00
|
|
|
Handle<Object> info = GetInfo(expr->CallNewFeedbackId());
|
2013-07-08 10:02:16 +00:00
|
|
|
if (info->IsAllocationSite()) {
|
2013-03-12 07:06:36 +00:00
|
|
|
return Handle<JSFunction>(isolate_->global_context()->array_function());
|
2013-03-01 16:06:34 +00:00
|
|
|
} else {
|
|
|
|
return Handle<JSFunction>::cast(info);
|
|
|
|
}
|
2012-02-28 09:05:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-12 15:03:44 +00:00
|
|
|
Handle<Cell> TypeFeedbackOracle::GetCallNewAllocationInfoCell(CallNew* expr) {
|
2013-06-07 13:21:20 +00:00
|
|
|
return GetInfoCell(expr->CallNewFeedbackId());
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
2013-06-07 13:21:20 +00:00
|
|
|
|
2012-03-13 12:11:46 +00:00
|
|
|
Handle<Map> TypeFeedbackOracle::GetObjectLiteralStoreMap(
|
|
|
|
ObjectLiteral::Property* prop) {
|
|
|
|
ASSERT(ObjectLiteralStoreIsMonomorphic(prop));
|
2013-05-21 11:20:24 +00:00
|
|
|
return Handle<Map>::cast(GetInfo(prop->key()->LiteralFeedbackId()));
|
2012-03-13 12:11:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
bool TypeFeedbackOracle::LoadIsBuiltin(Property* expr, Builtins::Name id) {
|
2012-08-06 14:13:09 +00:00
|
|
|
return *GetInfo(expr->PropertyFeedbackId()) ==
|
2011-10-10 09:21:48 +00:00
|
|
|
isolate_->builtins()->builtin(id);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-21 14:53:29 +00:00
|
|
|
bool TypeFeedbackOracle::LoadIsStub(Property* expr, ICStub* stub) {
|
|
|
|
Handle<Object> object = GetInfo(expr->PropertyFeedbackId());
|
|
|
|
if (!object->IsCode()) return false;
|
|
|
|
Handle<Code> code = Handle<Code>::cast(object);
|
|
|
|
if (!code->is_load_stub()) return false;
|
2013-03-04 14:03:27 +00:00
|
|
|
if (code->ic_state() != MONOMORPHIC) return false;
|
2013-01-21 14:53:29 +00:00
|
|
|
return stub->Describes(*code);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-21 11:10:06 +00:00
|
|
|
void TypeFeedbackOracle::CompareType(TypeFeedbackId id,
|
|
|
|
Handle<Type>* left_type,
|
|
|
|
Handle<Type>* right_type,
|
|
|
|
Handle<Type>* combined_type) {
|
2013-06-12 17:20:37 +00:00
|
|
|
Handle<Object> info = GetInfo(id);
|
2013-07-02 16:31:39 +00:00
|
|
|
if (!info->IsCode()) {
|
|
|
|
// For some comparisons we don't have ICs, e.g. LiteralCompareTypeof.
|
|
|
|
*left_type = *right_type = *combined_type = handle(Type::None(), isolate_);
|
|
|
|
return;
|
|
|
|
}
|
2013-06-12 17:20:37 +00:00
|
|
|
Handle<Code> code = Handle<Code>::cast(info);
|
|
|
|
|
|
|
|
Handle<Map> map;
|
|
|
|
Map* raw_map = code->FindFirstMap();
|
|
|
|
if (raw_map != NULL) {
|
|
|
|
raw_map = raw_map->CurrentMapForDeprecated();
|
2013-06-14 16:50:50 +00:00
|
|
|
if (raw_map != NULL && !CanRetainOtherContext(raw_map, *native_context_)) {
|
2013-06-12 17:20:37 +00:00
|
|
|
map = handle(raw_map, isolate_);
|
|
|
|
}
|
2012-11-14 15:59:45 +00:00
|
|
|
}
|
|
|
|
|
2013-06-12 17:20:37 +00:00
|
|
|
if (code->is_compare_ic_stub()) {
|
|
|
|
int stub_minor_key = code->stub_info();
|
2013-06-14 17:02:39 +00:00
|
|
|
CompareIC::StubInfoToType(
|
2013-06-21 11:10:06 +00:00
|
|
|
stub_minor_key, left_type, right_type, combined_type, map, isolate());
|
2013-06-12 17:20:37 +00:00
|
|
|
} else if (code->is_compare_nil_ic_stub()) {
|
2013-07-11 17:20:57 +00:00
|
|
|
CompareNilICStub stub(code->extended_extra_ic_state());
|
|
|
|
*combined_type = stub.GetType(isolate_, map);
|
|
|
|
*left_type = *right_type = stub.GetInputType(isolate_, map);
|
2011-12-09 09:26:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-14 17:02:39 +00:00
|
|
|
void TypeFeedbackOracle::BinaryType(TypeFeedbackId id,
|
|
|
|
Handle<Type>* left,
|
|
|
|
Handle<Type>* right,
|
|
|
|
Handle<Type>* result,
|
2013-10-04 08:17:11 +00:00
|
|
|
Maybe<int>* fixed_right_arg,
|
|
|
|
Token::Value operation) {
|
2013-06-14 17:02:39 +00:00
|
|
|
Handle<Object> object = GetInfo(id);
|
2013-07-02 16:31:39 +00:00
|
|
|
if (!object->IsCode()) {
|
2013-10-04 08:17:11 +00:00
|
|
|
// For some binary ops we don't have ICs, e.g. Token::COMMA, but for the
|
|
|
|
// operations covered by the BinaryOpStub we should always have them.
|
|
|
|
ASSERT(!(operation >= BinaryOpStub::FIRST_TOKEN &&
|
|
|
|
operation <= BinaryOpStub::LAST_TOKEN));
|
2013-07-02 16:31:39 +00:00
|
|
|
*left = *right = *result = handle(Type::None(), isolate_);
|
|
|
|
return;
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
Handle<Code> code = Handle<Code>::cast(object);
|
2013-07-02 16:31:39 +00:00
|
|
|
ASSERT(code->is_binary_op_stub());
|
2013-06-14 17:02:39 +00:00
|
|
|
|
2013-10-04 08:17:11 +00:00
|
|
|
BinaryOpStub stub(code->extended_extra_ic_state());
|
|
|
|
|
|
|
|
// Sanity check.
|
|
|
|
ASSERT(stub.operation() == operation);
|
|
|
|
|
|
|
|
*left = stub.GetLeftType(isolate());
|
|
|
|
*right = stub.GetRightType(isolate());
|
|
|
|
*result = stub.GetResultType(isolate());
|
|
|
|
*fixed_right_arg = stub.fixed_right_arg();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2011-01-13 14:16:08 +00:00
|
|
|
|
2013-06-12 17:20:37 +00:00
|
|
|
Handle<Type> TypeFeedbackOracle::ClauseType(TypeFeedbackId id) {
|
|
|
|
Handle<Object> info = GetInfo(id);
|
|
|
|
Handle<Type> result(Type::None(), isolate_);
|
|
|
|
if (info->IsCode() && Handle<Code>::cast(info)->is_compare_ic_stub()) {
|
|
|
|
Handle<Code> code = Handle<Code>::cast(info);
|
|
|
|
CompareIC::State state = ICCompareStub::CompareState(code->stub_info());
|
|
|
|
result = CompareIC::StateToType(isolate_, state);
|
|
|
|
}
|
|
|
|
return result;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-04 08:17:11 +00:00
|
|
|
Handle<Type> TypeFeedbackOracle::IncrementType(CountOperation* expr) {
|
2012-08-06 14:13:09 +00:00
|
|
|
Handle<Object> object = GetInfo(expr->CountBinOpFeedbackId());
|
2013-10-04 08:17:11 +00:00
|
|
|
Handle<Type> unknown(Type::None(), isolate_);
|
2011-04-29 09:21:18 +00:00
|
|
|
if (!object->IsCode()) return unknown;
|
|
|
|
Handle<Code> code = Handle<Code>::cast(object);
|
2011-05-24 12:20:16 +00:00
|
|
|
if (!code->is_binary_op_stub()) return unknown;
|
2011-04-29 09:21:18 +00:00
|
|
|
|
2013-10-04 08:17:11 +00:00
|
|
|
BinaryOpStub stub(code->extended_extra_ic_state());
|
|
|
|
return stub.GetLeftType(isolate());
|
2011-04-29 09:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 14:03:27 +00:00
|
|
|
void TypeFeedbackOracle::CollectPolymorphicMaps(Handle<Code> code,
|
|
|
|
SmallMapList* types) {
|
|
|
|
MapHandleList maps;
|
|
|
|
code->FindAllMaps(&maps);
|
|
|
|
types->Reserve(maps.length(), zone());
|
|
|
|
for (int i = 0; i < maps.length(); i++) {
|
|
|
|
Handle<Map> map(maps.at(i));
|
|
|
|
if (!CanRetainOtherContext(*map, *native_context_)) {
|
2013-05-02 15:40:07 +00:00
|
|
|
types->AddMapIfMissing(map, zone());
|
2013-03-04 14:03:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
void TypeFeedbackOracle::CollectReceiverTypes(TypeFeedbackId ast_id,
|
2011-08-22 14:23:37 +00:00
|
|
|
Handle<String> name,
|
|
|
|
Code::Flags flags,
|
|
|
|
SmallMapList* types) {
|
2011-04-27 15:02:59 +00:00
|
|
|
Handle<Object> object = GetInfo(ast_id);
|
2011-08-22 14:23:37 +00:00
|
|
|
if (object->IsUndefined() || object->IsSmi()) return;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-01-29 12:00:56 +00:00
|
|
|
if (object.is_identical_to(isolate_->builtins()->StoreIC_GlobalProxy())) {
|
2010-12-07 11:31:57 +00:00
|
|
|
// TODO(fschneider): We could collect the maps and signal that
|
|
|
|
// we need a generic store (or load) here.
|
2013-01-16 15:02:58 +00:00
|
|
|
ASSERT(Handle<Code>::cast(object)->ic_state() == GENERIC);
|
2010-12-07 11:31:57 +00:00
|
|
|
} else if (object->IsMap()) {
|
2013-05-02 15:40:07 +00:00
|
|
|
types->AddMapIfMissing(Handle<Map>::cast(object), zone());
|
2013-06-20 16:54:09 +00:00
|
|
|
} else if (Handle<Code>::cast(object)->ic_state() == POLYMORPHIC ||
|
|
|
|
Handle<Code>::cast(object)->ic_state() == MONOMORPHIC) {
|
2013-03-04 14:03:27 +00:00
|
|
|
CollectPolymorphicMaps(Handle<Code>::cast(object), types);
|
2011-11-18 14:08:57 +00:00
|
|
|
} else if (FLAG_collect_megamorphic_maps_from_stub_cache &&
|
|
|
|
Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC) {
|
2012-06-11 12:42:31 +00:00
|
|
|
types->Reserve(4, zone());
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(object->IsCode());
|
2011-12-14 14:01:54 +00:00
|
|
|
isolate_->stub_cache()->CollectMatchingMaps(types,
|
2013-05-02 15:40:07 +00:00
|
|
|
name,
|
2011-12-14 14:01:54 +00:00
|
|
|
flags,
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context_,
|
2012-06-20 08:58:41 +00:00
|
|
|
zone());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
// Check if a map originates from a given native context. We use this
|
2011-12-14 14:01:54 +00:00
|
|
|
// information to filter out maps from different context to avoid
|
|
|
|
// retaining objects from different tabs in Chrome via optimized code.
|
|
|
|
bool TypeFeedbackOracle::CanRetainOtherContext(Map* map,
|
2012-08-17 09:03:08 +00:00
|
|
|
Context* native_context) {
|
2011-12-19 12:39:52 +00:00
|
|
|
Object* constructor = NULL;
|
|
|
|
while (!map->prototype()->IsNull()) {
|
2011-12-14 14:01:54 +00:00
|
|
|
constructor = map->constructor();
|
2011-12-19 12:39:52 +00:00
|
|
|
if (!constructor->IsNull()) {
|
|
|
|
// If the constructor is not null or a JSFunction, we have to
|
2012-08-17 09:03:08 +00:00
|
|
|
// conservatively assume that it may retain a native context.
|
2011-12-19 12:39:52 +00:00
|
|
|
if (!constructor->IsJSFunction()) return true;
|
|
|
|
// Check if the constructor directly references a foreign context.
|
|
|
|
if (CanRetainOtherContext(JSFunction::cast(constructor),
|
2012-08-17 09:03:08 +00:00
|
|
|
native_context)) {
|
2011-12-19 12:39:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
map = HeapObject::cast(map->prototype())->map();
|
2011-12-14 14:01:54 +00:00
|
|
|
}
|
2011-12-19 12:39:52 +00:00
|
|
|
constructor = map->constructor();
|
|
|
|
if (constructor->IsNull()) return false;
|
2011-12-14 14:01:54 +00:00
|
|
|
JSFunction* function = JSFunction::cast(constructor);
|
2012-08-17 09:03:08 +00:00
|
|
|
return CanRetainOtherContext(function, native_context);
|
2011-12-14 14:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TypeFeedbackOracle::CanRetainOtherContext(JSFunction* function,
|
2012-08-17 09:03:08 +00:00
|
|
|
Context* native_context) {
|
2012-08-17 12:59:00 +00:00
|
|
|
return function->context()->global_object() != native_context->global_object()
|
|
|
|
&& function->context()->global_object() != native_context->builtins();
|
2011-12-14 14:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
void TypeFeedbackOracle::CollectKeyedReceiverTypes(TypeFeedbackId ast_id,
|
2011-08-22 14:23:37 +00:00
|
|
|
SmallMapList* types) {
|
2011-06-20 10:19:00 +00:00
|
|
|
Handle<Object> object = GetInfo(ast_id);
|
|
|
|
if (!object->IsCode()) return;
|
|
|
|
Handle<Code> code = Handle<Code>::cast(object);
|
|
|
|
if (code->kind() == Code::KEYED_LOAD_IC ||
|
|
|
|
code->kind() == Code::KEYED_STORE_IC) {
|
2013-03-04 14:03:27 +00:00
|
|
|
CollectPolymorphicMaps(code, types);
|
2011-06-20 10:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-09 08:22:41 +00:00
|
|
|
void TypeFeedbackOracle::CollectPolymorphicStoreReceiverTypes(
|
|
|
|
TypeFeedbackId ast_id,
|
|
|
|
SmallMapList* types) {
|
|
|
|
Handle<Object> object = GetInfo(ast_id);
|
|
|
|
if (!object->IsCode()) return;
|
|
|
|
Handle<Code> code = Handle<Code>::cast(object);
|
|
|
|
if (code->kind() == Code::STORE_IC && code->ic_state() == POLYMORPHIC) {
|
|
|
|
CollectPolymorphicMaps(code, types);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-24 11:32:17 +00:00
|
|
|
byte TypeFeedbackOracle::ToBooleanTypes(TypeFeedbackId id) {
|
|
|
|
Handle<Object> object = GetInfo(id);
|
2011-07-25 14:08:36 +00:00
|
|
|
return object->IsCode() ? Handle<Code>::cast(object)->to_boolean_state() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-20 12:33:08 +00:00
|
|
|
// Things are a bit tricky here: The iterator for the RelocInfos and the infos
|
|
|
|
// themselves are not GC-safe, so we first get all infos, then we create the
|
|
|
|
// dictionary (possibly triggering GC), and finally we relocate the collected
|
|
|
|
// infos before we process them.
|
|
|
|
void TypeFeedbackOracle::BuildDictionary(Handle<Code> code) {
|
2013-06-03 15:32:22 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2012-06-11 12:42:31 +00:00
|
|
|
ZoneList<RelocInfo> infos(16, zone());
|
2013-03-12 07:06:36 +00:00
|
|
|
HandleScope scope(isolate_);
|
2011-06-20 12:33:08 +00:00
|
|
|
GetRelocInfos(code, &infos);
|
|
|
|
CreateDictionary(code, &infos);
|
|
|
|
ProcessRelocInfos(&infos);
|
2012-01-27 13:03:19 +00:00
|
|
|
ProcessTypeFeedbackCells(code);
|
2011-06-20 12:33:08 +00:00
|
|
|
// Allocate handle in the parent scope.
|
|
|
|
dictionary_ = scope.CloseAndEscape(dictionary_);
|
2011-03-30 15:31:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-20 12:33:08 +00:00
|
|
|
void TypeFeedbackOracle::GetRelocInfos(Handle<Code> code,
|
|
|
|
ZoneList<RelocInfo>* infos) {
|
|
|
|
int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID);
|
|
|
|
for (RelocIterator it(*code, mask); !it.done(); it.next()) {
|
2012-06-11 12:42:31 +00:00
|
|
|
infos->Add(*it.rinfo(), zone());
|
2011-06-20 12:33:08 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
|
2011-06-20 12:33:08 +00:00
|
|
|
void TypeFeedbackOracle::CreateDictionary(Handle<Code> code,
|
|
|
|
ZoneList<RelocInfo>* infos) {
|
2013-06-03 15:32:22 +00:00
|
|
|
AllowHeapAllocation allocation_allowed;
|
2012-02-20 12:57:23 +00:00
|
|
|
int cell_count = code->type_feedback_info()->IsTypeFeedbackInfo()
|
|
|
|
? TypeFeedbackInfo::cast(code->type_feedback_info())->
|
|
|
|
type_feedback_cells()->CellCount()
|
|
|
|
: 0;
|
|
|
|
int length = infos->length() + cell_count;
|
2011-06-20 12:33:08 +00:00
|
|
|
byte* old_start = code->instruction_start();
|
2013-06-04 10:30:05 +00:00
|
|
|
dictionary_ = isolate()->factory()->NewUnseededNumberDictionary(length);
|
2011-06-20 12:33:08 +00:00
|
|
|
byte* new_start = code->instruction_start();
|
|
|
|
RelocateRelocInfos(infos, old_start, new_start);
|
|
|
|
}
|
2011-03-07 16:09:56 +00:00
|
|
|
|
2011-06-20 12:33:08 +00:00
|
|
|
|
|
|
|
void TypeFeedbackOracle::RelocateRelocInfos(ZoneList<RelocInfo>* infos,
|
|
|
|
byte* old_start,
|
|
|
|
byte* new_start) {
|
|
|
|
for (int i = 0; i < infos->length(); i++) {
|
|
|
|
RelocInfo* info = &(*infos)[i];
|
|
|
|
info->set_pc(new_start + (info->pc() - old_start));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-20 12:33:08 +00:00
|
|
|
void TypeFeedbackOracle::ProcessRelocInfos(ZoneList<RelocInfo>* infos) {
|
|
|
|
for (int i = 0; i < infos->length(); i++) {
|
2011-10-24 13:53:08 +00:00
|
|
|
RelocInfo reloc_entry = (*infos)[i];
|
|
|
|
Address target_address = reloc_entry.target_address();
|
2012-08-06 14:13:09 +00:00
|
|
|
TypeFeedbackId ast_id =
|
|
|
|
TypeFeedbackId(static_cast<unsigned>((*infos)[i].data()));
|
2011-10-24 13:53:08 +00:00
|
|
|
Code* target = Code::GetCodeFromTargetAddress(target_address);
|
|
|
|
switch (target->kind()) {
|
|
|
|
case Code::LOAD_IC:
|
|
|
|
case Code::STORE_IC:
|
|
|
|
case Code::CALL_IC:
|
2013-11-14 15:00:13 +00:00
|
|
|
case Code::KEYED_CALL_IC:
|
2011-10-24 13:53:08 +00:00
|
|
|
if (target->ic_state() == MONOMORPHIC) {
|
|
|
|
if (target->kind() == Code::CALL_IC &&
|
|
|
|
target->check_type() != RECEIVER_MAP_CHECK) {
|
|
|
|
SetInfo(ast_id, Smi::FromInt(target->check_type()));
|
|
|
|
} else {
|
|
|
|
Object* map = target->FindFirstMap();
|
2011-12-14 14:01:54 +00:00
|
|
|
if (map == NULL) {
|
|
|
|
SetInfo(ast_id, static_cast<Object*>(target));
|
|
|
|
} else if (!CanRetainOtherContext(Map::cast(map),
|
2012-08-17 09:03:08 +00:00
|
|
|
*native_context_)) {
|
2013-05-21 11:20:24 +00:00
|
|
|
Map* feedback = Map::cast(map)->CurrentMapForDeprecated();
|
|
|
|
if (feedback != NULL) SetInfo(ast_id, feedback);
|
2011-12-14 14:01:54 +00:00
|
|
|
}
|
2011-10-24 13:53:08 +00:00
|
|
|
}
|
2012-03-19 15:54:37 +00:00
|
|
|
} else {
|
2011-10-24 13:53:08 +00:00
|
|
|
SetInfo(ast_id, target);
|
|
|
|
}
|
|
|
|
break;
|
2011-10-14 12:26:29 +00:00
|
|
|
|
2011-10-24 13:53:08 +00:00
|
|
|
case Code::KEYED_LOAD_IC:
|
|
|
|
case Code::KEYED_STORE_IC:
|
|
|
|
case Code::BINARY_OP_IC:
|
|
|
|
case Code::COMPARE_IC:
|
|
|
|
case Code::TO_BOOLEAN_IC:
|
2013-04-24 11:32:17 +00:00
|
|
|
case Code::COMPARE_NIL_IC:
|
2011-06-20 12:33:08 +00:00
|
|
|
SetInfo(ast_id, target);
|
2011-10-24 13:53:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-20 12:33:08 +00:00
|
|
|
|
2012-01-27 13:03:19 +00:00
|
|
|
void TypeFeedbackOracle::ProcessTypeFeedbackCells(Handle<Code> code) {
|
2012-02-20 12:57:23 +00:00
|
|
|
Object* raw_info = code->type_feedback_info();
|
|
|
|
if (!raw_info->IsTypeFeedbackInfo()) return;
|
|
|
|
Handle<TypeFeedbackCells> cache(
|
|
|
|
TypeFeedbackInfo::cast(raw_info)->type_feedback_cells());
|
2012-01-27 13:03:19 +00:00
|
|
|
for (int i = 0; i < cache->CellCount(); i++) {
|
2012-08-06 14:13:09 +00:00
|
|
|
TypeFeedbackId ast_id = cache->AstId(i);
|
2013-06-12 15:03:44 +00:00
|
|
|
Cell* cell = cache->GetCell(i);
|
2013-06-07 13:21:20 +00:00
|
|
|
Object* value = cell->value();
|
2012-03-02 11:33:33 +00:00
|
|
|
if (value->IsSmi() ||
|
2013-07-08 10:02:16 +00:00
|
|
|
value->IsAllocationSite() ||
|
2012-03-02 11:33:33 +00:00
|
|
|
(value->IsJSFunction() &&
|
|
|
|
!CanRetainOtherContext(JSFunction::cast(value),
|
2012-08-17 09:03:08 +00:00
|
|
|
*native_context_))) {
|
2013-06-07 13:21:20 +00:00
|
|
|
SetInfo(ast_id, cell);
|
2012-01-27 13:03:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
void TypeFeedbackOracle::SetInfo(TypeFeedbackId ast_id, Object* target) {
|
|
|
|
ASSERT(dictionary_->FindEntry(IdToKey(ast_id)) ==
|
|
|
|
UnseededNumberDictionary::kNotFound);
|
|
|
|
MaybeObject* maybe_result = dictionary_->AtNumberPut(IdToKey(ast_id), target);
|
2011-06-20 12:33:08 +00:00
|
|
|
USE(maybe_result);
|
|
|
|
#ifdef DEBUG
|
|
|
|
Object* result = NULL;
|
|
|
|
// Dictionary has been allocated with sufficient size for all elements.
|
|
|
|
ASSERT(maybe_result->ToObject(&result));
|
|
|
|
ASSERT(*dictionary_ == result);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:26:22 +00:00
|
|
|
|
|
|
|
Representation Representation::FromType(TypeInfo info) {
|
|
|
|
if (info.IsUninitialized()) return Representation::None();
|
2013-07-25 11:53:38 +00:00
|
|
|
if (info.IsSmi()) return Representation::Smi();
|
2013-07-05 09:26:22 +00:00
|
|
|
if (info.IsInteger32()) return Representation::Integer32();
|
|
|
|
if (info.IsDouble()) return Representation::Double();
|
|
|
|
if (info.IsNumber()) return Representation::Double();
|
|
|
|
return Representation::Tagged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-24 15:29:41 +00:00
|
|
|
} } // namespace v8::internal
|