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 "bootstrapper.h"
|
|
|
|
#include "code-stubs.h"
|
2011-05-18 13:17:29 +00:00
|
|
|
#include "stub-cache.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "factory.h"
|
2011-01-18 16:11:01 +00:00
|
|
|
#include "gdb-jit.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "macro-assembler.h"
|
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-11-22 07:58:59 +00:00
|
|
|
bool CodeStub::FindCodeInCache(Code** code_out, Isolate* isolate) {
|
|
|
|
UnseededNumberDictionary* stubs = isolate->heap()->code_stubs();
|
|
|
|
int index = stubs->FindEntry(GetKey());
|
2012-01-16 09:44:35 +00:00
|
|
|
if (index != UnseededNumberDictionary::kNotFound) {
|
2012-11-22 07:58:59 +00:00
|
|
|
*code_out = Code::cast(stubs->ValueAt(index));
|
2009-12-09 14:54:34 +00:00
|
|
|
return true;
|
2009-11-04 08:51:48 +00:00
|
|
|
}
|
2009-12-09 14:54:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-11-04 08:51:48 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-09 22:39:47 +00:00
|
|
|
SmartArrayPointer<const char> CodeStub::GetName() {
|
2011-07-13 11:08:25 +00:00
|
|
|
char buffer[100];
|
|
|
|
NoAllocationStringAllocator allocator(buffer,
|
|
|
|
static_cast<unsigned>(sizeof(buffer)));
|
|
|
|
StringStream stream(&allocator);
|
|
|
|
PrintName(&stream);
|
|
|
|
return stream.ToCString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
void CodeStub::RecordCodeGeneration(Code* code, Isolate* isolate) {
|
2011-09-09 22:39:47 +00:00
|
|
|
SmartArrayPointer<const char> name = GetName();
|
2011-07-13 11:08:25 +00:00
|
|
|
PROFILE(isolate, CodeCreateEvent(Logger::STUB_TAG, code, *name));
|
|
|
|
GDBJIT(AddCode(GDBJITInterface::STUB, *name, code));
|
2011-03-23 11:13:07 +00:00
|
|
|
Counters* counters = isolate->counters();
|
|
|
|
counters->total_stubs_code_size()->Increment(code->instruction_size());
|
2009-12-09 14:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-01 16:24:05 +00:00
|
|
|
int CodeStub::GetCodeKind() {
|
|
|
|
return Code::STUB;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
Handle<Code> PlatformCodeStub::GenerateCode() {
|
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
|
|
|
// Generate the new code.
|
|
|
|
MacroAssembler masm(isolate, NULL, 256);
|
|
|
|
|
|
|
|
{
|
|
|
|
// Update the static counter each time a new code stub is generated.
|
|
|
|
isolate->counters()->code_stubs()->Increment();
|
|
|
|
|
|
|
|
// Nested stubs are not allowed for leaves.
|
|
|
|
AllowStubCallsScope allow_scope(&masm, false);
|
|
|
|
|
|
|
|
// Generate the code for the stub.
|
|
|
|
masm.set_generating_stub(true);
|
|
|
|
NoCurrentFrameScope scope(&masm);
|
|
|
|
Generate(&masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the code object.
|
|
|
|
CodeDesc desc;
|
|
|
|
masm.GetCode(&desc);
|
|
|
|
|
|
|
|
// Copy the generated code into a heap object.
|
|
|
|
Code::Flags flags = Code::ComputeFlags(
|
2013-01-25 11:55:29 +00:00
|
|
|
static_cast<Code::Kind>(GetCodeKind()), GetICState(), GetExtraICState());
|
2012-12-18 16:25:45 +00:00
|
|
|
Handle<Code> new_object = factory->NewCode(
|
|
|
|
desc, flags, masm.CodeObject(), NeedsImmovableCode());
|
|
|
|
return new_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-09 14:54:34 +00:00
|
|
|
Handle<Code> CodeStub::GetCode() {
|
2011-03-28 13:33:48 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
Heap* heap = isolate->heap();
|
2009-12-09 14:54:34 +00:00
|
|
|
Code* code;
|
2011-12-09 09:26:14 +00:00
|
|
|
if (UseSpecialCache()
|
2012-11-22 07:58:59 +00:00
|
|
|
? FindCodeInSpecialCache(&code, isolate)
|
|
|
|
: FindCodeInCache(&code, isolate)) {
|
2011-12-09 09:26:14 +00:00
|
|
|
ASSERT(IsPregenerated() == code->is_pregenerated());
|
|
|
|
return Handle<Code>(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2011-03-28 13:33:48 +00:00
|
|
|
HandleScope scope(isolate);
|
2009-12-09 14:54:34 +00:00
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
Handle<Code> new_object = GenerateCode();
|
2012-04-26 16:19:14 +00:00
|
|
|
new_object->set_major_key(MajorKey());
|
2011-11-11 13:48:14 +00:00
|
|
|
FinishCode(new_object);
|
2012-12-18 16:25:45 +00:00
|
|
|
RecordCodeGeneration(*new_object, isolate);
|
2012-04-26 16:19:14 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_DISASSEMBLER
|
|
|
|
if (FLAG_print_code_stubs) {
|
|
|
|
new_object->Disassemble(*GetName());
|
|
|
|
PrintF("\n");
|
|
|
|
}
|
|
|
|
#endif
|
2009-12-09 14:54:34 +00:00
|
|
|
|
2011-12-09 09:26:14 +00:00
|
|
|
if (UseSpecialCache()) {
|
|
|
|
AddToSpecialCache(new_object);
|
|
|
|
} else {
|
|
|
|
// Update the dictionary and the root in Heap.
|
2012-01-16 09:44:35 +00:00
|
|
|
Handle<UnseededNumberDictionary> dict =
|
2011-12-09 09:26:14 +00:00
|
|
|
factory->DictionaryAtNumberPut(
|
2012-01-16 09:44:35 +00:00
|
|
|
Handle<UnseededNumberDictionary>(heap->code_stubs()),
|
2011-12-09 09:26:14 +00:00
|
|
|
GetKey(),
|
|
|
|
new_object);
|
|
|
|
heap->public_set_code_stubs(*dict);
|
|
|
|
}
|
2009-12-09 14:54:34 +00:00
|
|
|
code = *new_object;
|
|
|
|
}
|
|
|
|
|
2011-12-09 09:26:14 +00:00
|
|
|
Activate(code);
|
2012-09-14 11:16:56 +00:00
|
|
|
ASSERT(!NeedsImmovableCode() ||
|
|
|
|
heap->lo_space()->Contains(code) ||
|
|
|
|
heap->code_space()->FirstPage()->Contains(code->address()));
|
2011-03-28 13:33:48 +00:00
|
|
|
return Handle<Code>(code, isolate);
|
2009-12-09 14:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-05 13:07:00 +00:00
|
|
|
const char* CodeStub::MajorName(CodeStub::Major major_key,
|
|
|
|
bool allow_unknown_keys) {
|
2008-07-03 15:10:15 +00:00
|
|
|
switch (major_key) {
|
2011-07-08 09:40:14 +00:00
|
|
|
#define DEF_CASE(name) case name: return #name "Stub";
|
2009-11-11 14:32:14 +00:00
|
|
|
CODE_STUB_LIST(DEF_CASE)
|
2009-10-26 12:26:42 +00:00
|
|
|
#undef DEF_CASE
|
2008-07-03 15:10:15 +00:00
|
|
|
default:
|
2010-02-05 13:07:00 +00:00
|
|
|
if (!allow_unknown_keys) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-03 11:13:20 +00:00
|
|
|
void CodeStub::PrintName(StringStream* stream) {
|
|
|
|
stream->Add("%s", MajorName(MajorKey(), false));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
void BinaryOpStub::Generate(MacroAssembler* masm) {
|
|
|
|
// Explicitly allow generation of nested stubs. It is safe here because
|
|
|
|
// generation code does not use any raw pointers.
|
|
|
|
AllowStubCallsScope allow_stub_calls(masm, true);
|
|
|
|
|
|
|
|
BinaryOpIC::TypeInfo operands_type = Max(left_type_, right_type_);
|
|
|
|
if (left_type_ == BinaryOpIC::ODDBALL && right_type_ == BinaryOpIC::ODDBALL) {
|
|
|
|
// The OddballStub handles a number and an oddball, not two oddballs.
|
|
|
|
operands_type = BinaryOpIC::GENERIC;
|
|
|
|
}
|
|
|
|
switch (operands_type) {
|
|
|
|
case BinaryOpIC::UNINITIALIZED:
|
|
|
|
GenerateTypeTransition(masm);
|
|
|
|
break;
|
|
|
|
case BinaryOpIC::SMI:
|
|
|
|
GenerateSmiStub(masm);
|
|
|
|
break;
|
|
|
|
case BinaryOpIC::INT32:
|
|
|
|
GenerateInt32Stub(masm);
|
|
|
|
break;
|
|
|
|
case BinaryOpIC::HEAP_NUMBER:
|
|
|
|
GenerateHeapNumberStub(masm);
|
|
|
|
break;
|
|
|
|
case BinaryOpIC::ODDBALL:
|
|
|
|
GenerateOddballStub(masm);
|
|
|
|
break;
|
|
|
|
case BinaryOpIC::STRING:
|
|
|
|
GenerateStringStub(masm);
|
|
|
|
break;
|
|
|
|
case BinaryOpIC::GENERIC:
|
|
|
|
GenerateGeneric(masm);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define __ ACCESS_MASM(masm)
|
|
|
|
|
|
|
|
|
|
|
|
void BinaryOpStub::GenerateCallRuntime(MacroAssembler* masm) {
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD:
|
|
|
|
__ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::SUB:
|
|
|
|
__ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::MUL:
|
|
|
|
__ InvokeBuiltin(Builtins::MUL, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::DIV:
|
|
|
|
__ InvokeBuiltin(Builtins::DIV, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::MOD:
|
|
|
|
__ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::BIT_OR:
|
|
|
|
__ InvokeBuiltin(Builtins::BIT_OR, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::BIT_AND:
|
|
|
|
__ InvokeBuiltin(Builtins::BIT_AND, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
__ InvokeBuiltin(Builtins::BIT_XOR, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::SAR:
|
|
|
|
__ InvokeBuiltin(Builtins::SAR, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::SHR:
|
|
|
|
__ InvokeBuiltin(Builtins::SHR, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::SHL:
|
|
|
|
__ InvokeBuiltin(Builtins::SHL, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#undef __
|
|
|
|
|
|
|
|
|
|
|
|
void BinaryOpStub::PrintName(StringStream* stream) {
|
|
|
|
const char* op_name = Token::Name(op_);
|
|
|
|
const char* overwrite_name;
|
|
|
|
switch (mode_) {
|
|
|
|
case NO_OVERWRITE: overwrite_name = "Alloc"; break;
|
|
|
|
case OVERWRITE_RIGHT: overwrite_name = "OverwriteRight"; break;
|
|
|
|
case OVERWRITE_LEFT: overwrite_name = "OverwriteLeft"; break;
|
|
|
|
default: overwrite_name = "UnknownOverwrite"; break;
|
|
|
|
}
|
|
|
|
stream->Add("BinaryOpStub_%s_%s_%s+%s",
|
|
|
|
op_name,
|
|
|
|
overwrite_name,
|
|
|
|
BinaryOpIC::GetName(left_type_),
|
|
|
|
BinaryOpIC::GetName(right_type_));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BinaryOpStub::GenerateStringStub(MacroAssembler* masm) {
|
|
|
|
ASSERT(left_type_ == BinaryOpIC::STRING || right_type_ == BinaryOpIC::STRING);
|
|
|
|
ASSERT(op_ == Token::ADD);
|
|
|
|
if (left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING) {
|
|
|
|
GenerateBothStringStub(masm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Try to add arguments as strings, otherwise, transition to the generic
|
|
|
|
// BinaryOpIC type.
|
|
|
|
GenerateAddStrings(masm);
|
|
|
|
GenerateTypeTransition(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-09 09:26:14 +00:00
|
|
|
void ICCompareStub::AddToSpecialCache(Handle<Code> new_object) {
|
|
|
|
ASSERT(*known_map_ != NULL);
|
|
|
|
Isolate* isolate = new_object->GetIsolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
return Map::UpdateCodeCache(known_map_,
|
2012-08-15 15:08:42 +00:00
|
|
|
strict() ?
|
|
|
|
factory->strict_compare_ic_symbol() :
|
|
|
|
factory->compare_ic_symbol(),
|
2011-12-09 09:26:14 +00:00
|
|
|
new_object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-22 07:58:59 +00:00
|
|
|
bool ICCompareStub::FindCodeInSpecialCache(Code** code_out, Isolate* isolate) {
|
2011-12-09 09:26:14 +00:00
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
Code::Flags flags = Code::ComputeFlags(
|
|
|
|
static_cast<Code::Kind>(GetCodeKind()),
|
|
|
|
UNINITIALIZED);
|
2012-08-15 15:08:42 +00:00
|
|
|
ASSERT(op_ == Token::EQ || op_ == Token::EQ_STRICT);
|
2011-12-09 09:26:14 +00:00
|
|
|
Handle<Object> probe(
|
2012-08-15 15:08:42 +00:00
|
|
|
known_map_->FindInCodeCache(
|
|
|
|
strict() ?
|
|
|
|
*factory->strict_compare_ic_symbol() :
|
|
|
|
*factory->compare_ic_symbol(),
|
|
|
|
flags));
|
2011-12-09 09:26:14 +00:00
|
|
|
if (probe->IsCode()) {
|
|
|
|
*code_out = Code::cast(*probe);
|
2012-11-14 15:59:45 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
Token::Value cached_op;
|
|
|
|
ICCompareStub::DecodeMinorKey((*code_out)->stub_info(), NULL, NULL, NULL,
|
|
|
|
&cached_op);
|
|
|
|
ASSERT(op_ == cached_op);
|
|
|
|
#endif
|
2011-12-09 09:26:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
int ICCompareStub::MinorKey() {
|
2012-11-14 15:59:45 +00:00
|
|
|
return OpField::encode(op_ - Token::EQ) |
|
|
|
|
LeftStateField::encode(left_) |
|
|
|
|
RightStateField::encode(right_) |
|
|
|
|
HandlerStateField::encode(state_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ICCompareStub::DecodeMinorKey(int minor_key,
|
|
|
|
CompareIC::State* left_state,
|
|
|
|
CompareIC::State* right_state,
|
|
|
|
CompareIC::State* handler_state,
|
|
|
|
Token::Value* op) {
|
|
|
|
if (left_state) {
|
|
|
|
*left_state =
|
|
|
|
static_cast<CompareIC::State>(LeftStateField::decode(minor_key));
|
|
|
|
}
|
|
|
|
if (right_state) {
|
|
|
|
*right_state =
|
|
|
|
static_cast<CompareIC::State>(RightStateField::decode(minor_key));
|
|
|
|
}
|
|
|
|
if (handler_state) {
|
|
|
|
*handler_state =
|
|
|
|
static_cast<CompareIC::State>(HandlerStateField::decode(minor_key));
|
|
|
|
}
|
|
|
|
if (op) {
|
|
|
|
*op = static_cast<Token::Value>(OpField::decode(minor_key) + Token::EQ);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ICCompareStub::Generate(MacroAssembler* masm) {
|
|
|
|
switch (state_) {
|
|
|
|
case CompareIC::UNINITIALIZED:
|
|
|
|
GenerateMiss(masm);
|
|
|
|
break;
|
2012-11-14 15:59:45 +00:00
|
|
|
case CompareIC::SMI:
|
2010-12-07 11:31:57 +00:00
|
|
|
GenerateSmis(masm);
|
|
|
|
break;
|
2012-11-14 15:59:45 +00:00
|
|
|
case CompareIC::HEAP_NUMBER:
|
2010-12-07 11:31:57 +00:00
|
|
|
GenerateHeapNumbers(masm);
|
|
|
|
break;
|
2012-11-14 15:59:45 +00:00
|
|
|
case CompareIC::STRING:
|
2011-05-04 18:30:37 +00:00
|
|
|
GenerateStrings(masm);
|
|
|
|
break;
|
2012-11-14 15:59:45 +00:00
|
|
|
case CompareIC::SYMBOL:
|
2011-05-09 13:30:04 +00:00
|
|
|
GenerateSymbols(masm);
|
|
|
|
break;
|
2012-11-14 15:59:45 +00:00
|
|
|
case CompareIC::OBJECT:
|
2010-12-07 11:31:57 +00:00
|
|
|
GenerateObjects(masm);
|
|
|
|
break;
|
2011-12-09 09:26:14 +00:00
|
|
|
case CompareIC::KNOWN_OBJECTS:
|
|
|
|
ASSERT(*known_map_ != NULL);
|
|
|
|
GenerateKnownObjects(masm);
|
|
|
|
break;
|
2012-11-14 15:59:45 +00:00
|
|
|
case CompareIC::GENERIC:
|
|
|
|
GenerateGeneric(masm);
|
|
|
|
break;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-13 11:08:25 +00:00
|
|
|
void InstanceofStub::PrintName(StringStream* stream) {
|
2011-01-05 12:01:53 +00:00
|
|
|
const char* args = "";
|
|
|
|
if (HasArgsInRegisters()) {
|
|
|
|
args = "_REGS";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* inline_check = "";
|
|
|
|
if (HasCallSiteInlineCheck()) {
|
|
|
|
inline_check = "_INLINE";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* return_true_false_object = "";
|
|
|
|
if (ReturnTrueFalseObject()) {
|
|
|
|
return_true_false_object = "_TRUEFALSE";
|
|
|
|
}
|
|
|
|
|
2011-07-13 11:08:25 +00:00
|
|
|
stream->Add("InstanceofStub%s%s%s",
|
|
|
|
args,
|
|
|
|
inline_check,
|
|
|
|
return_true_false_object);
|
2011-01-05 12:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-11 13:48:14 +00:00
|
|
|
void JSEntryStub::FinishCode(Handle<Code> code) {
|
|
|
|
Handle<FixedArray> handler_table =
|
|
|
|
code->GetIsolate()->factory()->NewFixedArray(1, TENURED);
|
|
|
|
handler_table->set(0, Smi::FromInt(handler_offset_));
|
|
|
|
code->set_handler_table(*handler_table);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
void KeyedLoadDictionaryElementStub::Generate(MacroAssembler* masm) {
|
|
|
|
KeyedLoadStubCompiler::GenerateLoadDictionaryElement(masm);
|
2011-05-18 13:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-08 10:46:10 +00:00
|
|
|
void KeyedStoreElementStub::Generate(MacroAssembler* masm) {
|
|
|
|
switch (elements_kind_) {
|
2011-09-09 09:35:57 +00:00
|
|
|
case FAST_ELEMENTS:
|
2012-05-23 14:24:29 +00:00
|
|
|
case FAST_HOLEY_ELEMENTS:
|
|
|
|
case FAST_SMI_ELEMENTS:
|
|
|
|
case FAST_HOLEY_SMI_ELEMENTS: {
|
2011-09-22 11:30:04 +00:00
|
|
|
KeyedStoreStubCompiler::GenerateStoreFastElement(masm,
|
|
|
|
is_js_array_,
|
2012-02-10 12:36:05 +00:00
|
|
|
elements_kind_,
|
|
|
|
grow_mode_);
|
2011-09-22 11:30:04 +00:00
|
|
|
}
|
2011-07-08 10:46:10 +00:00
|
|
|
break;
|
2011-09-09 09:35:57 +00:00
|
|
|
case FAST_DOUBLE_ELEMENTS:
|
2012-05-23 14:24:29 +00:00
|
|
|
case FAST_HOLEY_DOUBLE_ELEMENTS:
|
2011-07-13 13:50:27 +00:00
|
|
|
KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(masm,
|
2012-02-10 12:36:05 +00:00
|
|
|
is_js_array_,
|
|
|
|
grow_mode_);
|
2011-07-08 10:46:10 +00:00
|
|
|
break;
|
2011-09-09 09:35:57 +00:00
|
|
|
case EXTERNAL_BYTE_ELEMENTS:
|
|
|
|
case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
|
|
|
|
case EXTERNAL_SHORT_ELEMENTS:
|
|
|
|
case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
|
|
|
|
case EXTERNAL_INT_ELEMENTS:
|
|
|
|
case EXTERNAL_UNSIGNED_INT_ELEMENTS:
|
|
|
|
case EXTERNAL_FLOAT_ELEMENTS:
|
|
|
|
case EXTERNAL_DOUBLE_ELEMENTS:
|
|
|
|
case EXTERNAL_PIXEL_ELEMENTS:
|
2011-07-08 10:46:10 +00:00
|
|
|
KeyedStoreStubCompiler::GenerateStoreExternalArray(masm, elements_kind_);
|
|
|
|
break;
|
2011-09-09 09:35:57 +00:00
|
|
|
case DICTIONARY_ELEMENTS:
|
2011-07-08 10:46:10 +00:00
|
|
|
KeyedStoreStubCompiler::GenerateStoreDictionaryElement(masm);
|
|
|
|
break;
|
2011-09-09 09:35:57 +00:00
|
|
|
case NON_STRICT_ARGUMENTS_ELEMENTS:
|
2011-07-08 10:46:10 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
2011-05-18 13:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-13 11:08:25 +00:00
|
|
|
void ArgumentsAccessStub::PrintName(StringStream* stream) {
|
2011-09-27 11:42:02 +00:00
|
|
|
stream->Add("ArgumentsAccessStub_");
|
2011-07-13 11:08:25 +00:00
|
|
|
switch (type_) {
|
2011-09-27 11:42:02 +00:00
|
|
|
case READ_ELEMENT: stream->Add("ReadElement"); break;
|
|
|
|
case NEW_NON_STRICT_FAST: stream->Add("NewNonStrictFast"); break;
|
|
|
|
case NEW_NON_STRICT_SLOW: stream->Add("NewNonStrictSlow"); break;
|
|
|
|
case NEW_STRICT: stream->Add("NewStrict"); break;
|
2011-07-13 11:08:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CallFunctionStub::PrintName(StringStream* stream) {
|
2011-09-27 11:42:02 +00:00
|
|
|
stream->Add("CallFunctionStub_Args%d", argc_);
|
|
|
|
if (ReceiverMightBeImplicit()) stream->Add("_Implicit");
|
|
|
|
if (RecordCallTarget()) stream->Add("_Recording");
|
2011-07-13 11:08:25 +00:00
|
|
|
}
|
|
|
|
|
2011-07-21 13:51:04 +00:00
|
|
|
|
2012-01-27 13:03:19 +00:00
|
|
|
void CallConstructStub::PrintName(StringStream* stream) {
|
|
|
|
stream->Add("CallConstructStub");
|
|
|
|
if (RecordCallTarget()) stream->Add("_Recording");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-21 13:51:04 +00:00
|
|
|
void ToBooleanStub::PrintName(StringStream* stream) {
|
|
|
|
stream->Add("ToBooleanStub_");
|
|
|
|
types_.Print(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-28 13:33:51 +00:00
|
|
|
void ToBooleanStub::Types::Print(StringStream* stream) const {
|
2011-07-21 13:51:04 +00:00
|
|
|
if (IsEmpty()) stream->Add("None");
|
|
|
|
if (Contains(UNDEFINED)) stream->Add("Undefined");
|
|
|
|
if (Contains(BOOLEAN)) stream->Add("Bool");
|
|
|
|
if (Contains(NULL_TYPE)) stream->Add("Null");
|
2011-08-11 07:22:16 +00:00
|
|
|
if (Contains(SMI)) stream->Add("Smi");
|
2011-07-21 13:51:04 +00:00
|
|
|
if (Contains(SPEC_OBJECT)) stream->Add("SpecObject");
|
|
|
|
if (Contains(STRING)) stream->Add("String");
|
|
|
|
if (Contains(HEAP_NUMBER)) stream->Add("HeapNumber");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-28 13:33:51 +00:00
|
|
|
void ToBooleanStub::Types::TraceTransition(Types to) const {
|
2011-07-21 13:51:04 +00:00
|
|
|
if (!FLAG_trace_ic) return;
|
|
|
|
char buffer[100];
|
|
|
|
NoAllocationStringAllocator allocator(buffer,
|
|
|
|
static_cast<unsigned>(sizeof(buffer)));
|
|
|
|
StringStream stream(&allocator);
|
|
|
|
stream.Add("[ToBooleanIC (");
|
|
|
|
Print(&stream);
|
|
|
|
stream.Add("->");
|
|
|
|
to.Print(&stream);
|
|
|
|
stream.Add(")]\n");
|
|
|
|
stream.OutputToStdOut();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ToBooleanStub::Types::Record(Handle<Object> object) {
|
|
|
|
if (object->IsUndefined()) {
|
|
|
|
Add(UNDEFINED);
|
|
|
|
return false;
|
|
|
|
} else if (object->IsBoolean()) {
|
|
|
|
Add(BOOLEAN);
|
|
|
|
return object->IsTrue();
|
|
|
|
} else if (object->IsNull()) {
|
|
|
|
Add(NULL_TYPE);
|
|
|
|
return false;
|
|
|
|
} else if (object->IsSmi()) {
|
|
|
|
Add(SMI);
|
|
|
|
return Smi::cast(*object)->value() != 0;
|
|
|
|
} else if (object->IsSpecObject()) {
|
|
|
|
Add(SPEC_OBJECT);
|
2011-07-22 12:42:40 +00:00
|
|
|
return !object->IsUndetectableObject();
|
2011-07-21 13:51:04 +00:00
|
|
|
} else if (object->IsString()) {
|
|
|
|
Add(STRING);
|
2011-07-22 12:42:40 +00:00
|
|
|
return !object->IsUndetectableObject() &&
|
|
|
|
String::cast(*object)->length() != 0;
|
2011-07-21 13:51:04 +00:00
|
|
|
} else if (object->IsHeapNumber()) {
|
2011-08-11 07:22:16 +00:00
|
|
|
ASSERT(!object->IsUndetectableObject());
|
2011-07-21 13:51:04 +00:00
|
|
|
Add(HEAP_NUMBER);
|
|
|
|
double value = HeapNumber::cast(*object)->value();
|
2011-08-11 07:22:16 +00:00
|
|
|
return value != 0 && !isnan(value);
|
2011-07-21 13:51:04 +00:00
|
|
|
} else {
|
2011-08-11 07:22:16 +00:00
|
|
|
// We should never see an internal object at runtime here!
|
|
|
|
UNREACHABLE();
|
|
|
|
return true;
|
2011-07-21 13:51:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-28 13:33:51 +00:00
|
|
|
bool ToBooleanStub::Types::NeedsMap() const {
|
|
|
|
return Contains(ToBooleanStub::SPEC_OBJECT)
|
|
|
|
|| Contains(ToBooleanStub::STRING)
|
2011-08-11 07:22:16 +00:00
|
|
|
|| Contains(ToBooleanStub::HEAP_NUMBER);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ToBooleanStub::Types::CanBeUndetectable() const {
|
|
|
|
return Contains(ToBooleanStub::SPEC_OBJECT)
|
|
|
|
|| Contains(ToBooleanStub::STRING);
|
2011-07-28 13:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 12:36:45 +00:00
|
|
|
void ElementsTransitionAndStoreStub::Generate(MacroAssembler* masm) {
|
|
|
|
Label fail;
|
2013-01-17 08:41:27 +00:00
|
|
|
AllocationSiteMode mode = AllocationSiteInfo::GetMode(from_, to_);
|
2012-05-23 14:24:29 +00:00
|
|
|
ASSERT(!IsFastHoleyElementsKind(from_) || IsFastHoleyElementsKind(to_));
|
2011-10-20 12:36:45 +00:00
|
|
|
if (!FLAG_trace_elements_transitions) {
|
2012-05-23 14:24:29 +00:00
|
|
|
if (IsFastSmiOrObjectElementsKind(to_)) {
|
|
|
|
if (IsFastSmiOrObjectElementsKind(from_)) {
|
|
|
|
ElementsTransitionGenerator::
|
2013-01-17 08:41:27 +00:00
|
|
|
GenerateMapChangeElementsTransition(masm, mode, &fail);
|
2012-05-23 14:24:29 +00:00
|
|
|
} else if (IsFastDoubleElementsKind(from_)) {
|
|
|
|
ASSERT(!IsFastSmiElementsKind(to_));
|
2013-01-17 08:41:27 +00:00
|
|
|
ElementsTransitionGenerator::GenerateDoubleToObject(masm, mode, &fail);
|
2011-10-20 12:36:45 +00:00
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
KeyedStoreStubCompiler::GenerateStoreFastElement(masm,
|
|
|
|
is_jsarray_,
|
2012-05-23 14:24:29 +00:00
|
|
|
to_,
|
2012-02-10 12:36:05 +00:00
|
|
|
grow_mode_);
|
2012-05-23 14:24:29 +00:00
|
|
|
} else if (IsFastSmiElementsKind(from_) &&
|
|
|
|
IsFastDoubleElementsKind(to_)) {
|
2013-01-17 08:41:27 +00:00
|
|
|
ElementsTransitionGenerator::GenerateSmiToDouble(masm, mode, &fail);
|
2012-02-10 12:36:05 +00:00
|
|
|
KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(masm,
|
|
|
|
is_jsarray_,
|
|
|
|
grow_mode_);
|
2012-05-23 14:24:29 +00:00
|
|
|
} else if (IsFastDoubleElementsKind(from_)) {
|
|
|
|
ASSERT(to_ == FAST_HOLEY_DOUBLE_ELEMENTS);
|
|
|
|
ElementsTransitionGenerator::
|
2013-01-17 08:41:27 +00:00
|
|
|
GenerateMapChangeElementsTransition(masm, mode, &fail);
|
2011-10-13 10:53:31 +00:00
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
2011-10-20 12:36:45 +00:00
|
|
|
masm->bind(&fail);
|
|
|
|
KeyedStoreIC::GenerateRuntimeSetProperty(masm, strict_mode_);
|
2011-10-13 10:53:31 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 15:18:15 +00:00
|
|
|
|
2013-02-05 08:09:32 +00:00
|
|
|
void StubFailureTrampolineStub::GenerateAheadOfTime() {
|
|
|
|
int i = 0;
|
|
|
|
for (; i <= StubFailureTrampolineStub::kMaxExtraExpressionStackCount; ++i) {
|
|
|
|
StubFailureTrampolineStub(i).GetCode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-17 15:18:15 +00:00
|
|
|
FunctionEntryHook ProfileEntryHookStub::entry_hook_ = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
void ProfileEntryHookStub::EntryHookTrampoline(intptr_t function,
|
|
|
|
intptr_t stack_pointer) {
|
|
|
|
if (entry_hook_ != NULL)
|
|
|
|
entry_hook_(function, stack_pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ProfileEntryHookStub::SetFunctionEntryHook(FunctionEntryHook entry_hook) {
|
|
|
|
// We don't allow setting a new entry hook over one that's
|
|
|
|
// already active, as the hooks won't stack.
|
|
|
|
if (entry_hook != 0 && entry_hook_ != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
entry_hook_ = entry_hook;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|