2008-09-09 20:08:45 +00:00
|
|
|
// Copyright 2006-2008 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"
|
|
|
|
#include "factory.h"
|
|
|
|
#include "macro-assembler.h"
|
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
Handle<Code> CodeStub::GetCode() {
|
|
|
|
uint32_t key = GetKey();
|
2009-07-01 16:49:54 +00:00
|
|
|
int index = Heap::code_stubs()->FindNumberEntry(key);
|
|
|
|
if (index == -1) {
|
2008-07-03 15:10:15 +00:00
|
|
|
HandleScope scope;
|
|
|
|
|
|
|
|
// Update the static counter each time a new code stub is generated.
|
|
|
|
Counters::code_stubs.Increment();
|
|
|
|
|
|
|
|
// Generate the new code.
|
|
|
|
MacroAssembler masm(NULL, 256);
|
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
// Nested stubs are not allowed for leafs.
|
|
|
|
masm.set_allow_stub_calls(AllowsStubCalls());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Generate the code for the stub.
|
2008-07-30 08:49:36 +00:00
|
|
|
masm.set_generating_stub(true);
|
2008-07-03 15:10:15 +00:00
|
|
|
Generate(&masm);
|
|
|
|
|
|
|
|
// Create the code object.
|
|
|
|
CodeDesc desc;
|
|
|
|
masm.GetCode(&desc);
|
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
// Copy the generated code into a heap object, and store the major key.
|
2009-05-25 18:29:02 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(Code::STUB, InLoop());
|
2009-02-25 16:52:15 +00:00
|
|
|
Handle<Code> code = Factory::NewCode(desc, NULL, flags, masm.CodeObject());
|
2008-07-30 08:49:36 +00:00
|
|
|
code->set_major_key(MajorKey());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Add unresolved entries in the code to the fixup list.
|
|
|
|
Bootstrapper::AddFixup(*code, &masm);
|
|
|
|
|
2009-06-08 13:39:48 +00:00
|
|
|
LOG(CodeCreateEvent(Logger::STUB_TAG, *code, GetName()));
|
2008-07-03 15:10:15 +00:00
|
|
|
Counters::total_stubs_code_size.Increment(code->instruction_size());
|
|
|
|
|
2009-03-04 06:14:34 +00:00
|
|
|
#ifdef ENABLE_DISASSEMBLER
|
2008-07-03 15:10:15 +00:00
|
|
|
if (FLAG_print_code_stubs) {
|
2009-03-04 06:14:34 +00:00
|
|
|
#ifdef DEBUG
|
2008-07-03 15:10:15 +00:00
|
|
|
Print();
|
2009-03-04 06:14:34 +00:00
|
|
|
#endif
|
|
|
|
code->Disassemble(GetName());
|
2008-07-03 15:10:15 +00:00
|
|
|
PrintF("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Update the dictionary and the root in Heap.
|
2009-07-01 16:49:54 +00:00
|
|
|
Handle<Dictionary> dict =
|
|
|
|
Factory::DictionaryAtNumberPut(Handle<Dictionary>(Heap::code_stubs()),
|
|
|
|
key,
|
|
|
|
code);
|
2008-07-03 15:10:15 +00:00
|
|
|
Heap::set_code_stubs(*dict);
|
2009-07-01 16:49:54 +00:00
|
|
|
index = Heap::code_stubs()->FindNumberEntry(key);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-07-01 16:49:54 +00:00
|
|
|
ASSERT(index != -1);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
return Handle<Code>(Code::cast(Heap::code_stubs()->ValueAt(index)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char* CodeStub::MajorName(CodeStub::Major major_key) {
|
|
|
|
switch (major_key) {
|
|
|
|
case CallFunction:
|
|
|
|
return "CallFunction";
|
2008-07-30 08:49:36 +00:00
|
|
|
case GenericBinaryOp:
|
|
|
|
return "GenericBinaryOp";
|
2008-07-03 15:10:15 +00:00
|
|
|
case SmiOp:
|
|
|
|
return "SmiOp";
|
|
|
|
case Compare:
|
|
|
|
return "Compare";
|
|
|
|
case RecordWrite:
|
|
|
|
return "RecordWrite";
|
|
|
|
case StackCheck:
|
|
|
|
return "StackCheck";
|
|
|
|
case UnarySub:
|
|
|
|
return "UnarySub";
|
|
|
|
case RevertToNumber:
|
|
|
|
return "RevertToNumber";
|
2008-07-30 08:49:36 +00:00
|
|
|
case ToBoolean:
|
|
|
|
return "ToBoolean";
|
2008-10-08 13:33:16 +00:00
|
|
|
case Instanceof:
|
|
|
|
return "Instanceof";
|
2008-07-03 15:10:15 +00:00
|
|
|
case CounterOp:
|
|
|
|
return "CounterOp";
|
|
|
|
case ArgumentsAccess:
|
|
|
|
return "ArgumentsAccess";
|
|
|
|
case Runtime:
|
|
|
|
return "Runtime";
|
|
|
|
case CEntry:
|
|
|
|
return "CEntry";
|
|
|
|
case JSEntry:
|
|
|
|
return "JSEntry";
|
|
|
|
case GetProperty:
|
|
|
|
return "GetProperty";
|
|
|
|
case SetProperty:
|
|
|
|
return "SetProperty";
|
|
|
|
case InvokeBuiltin:
|
|
|
|
return "InvokeBuiltin";
|
|
|
|
case JSExit:
|
|
|
|
return "JSExit";
|
2009-06-30 20:57:44 +00:00
|
|
|
case ConvertToDouble:
|
|
|
|
return "ConvertToDouble";
|
|
|
|
case WriteInt32ToHeapNumber:
|
|
|
|
return "WriteInt32ToHeapNumber";
|
2008-07-03 15:10:15 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|