Commit a49ac519 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Serialize code stubs using stub key.

Also add some tracing to the code serializer.

R=mvstanton@chromium.org

Review URL: https://codereview.chromium.org/556243005

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24002 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent cbf66711
......@@ -246,6 +246,22 @@ void CodeStub::InitializeDescriptor(Isolate* isolate, uint32_t key,
}
void CodeStub::GetCodeDispatchCall(CodeStub* stub, void** value_out) {
Handle<Code>* code_out = reinterpret_cast<Handle<Code>*>(value_out);
// Code stubs with special cache cannot be recreated from stub key.
*code_out = stub->UseSpecialCache() ? Handle<Code>() : stub->GetCode();
}
MaybeHandle<Code> CodeStub::GetCode(Isolate* isolate, uint32_t key) {
HandleScope scope(isolate);
Handle<Code> code;
void** value_out = reinterpret_cast<void**>(&code);
Dispatch(isolate, key, value_out, &GetCodeDispatchCall);
return scope.CloseAndEscape(code);
}
// static
void BinaryOpICStub::GenerateAheadOfTime(Isolate* isolate) {
// Generate the uninitialized versions of the stub.
......
......@@ -187,6 +187,8 @@ class CodeStub BASE_EMBEDDED {
static void InitializeDescriptor(Isolate* isolate, uint32_t key,
CodeStubDescriptor* desc);
static MaybeHandle<Code> GetCode(Isolate* isolate, uint32_t key);
// Returns information for computing the number key.
virtual Major MajorKey() const = 0;
uint32_t MinorKey() const { return minor_key_; }
......@@ -261,6 +263,8 @@ class CodeStub BASE_EMBEDDED {
static void Dispatch(Isolate* isolate, uint32_t key, void** value_out,
DispatchedCall call);
static void GetCodeDispatchCall(CodeStub* stub, void** value_out);
STATIC_ASSERT(NUMBER_OF_IDS < (1 << kStubMajorKeyBits));
class MajorKeyBits: public BitField<uint32_t, 0, kStubMajorKeyBits> {};
class MinorKeyBits: public BitField<uint32_t,
......
......@@ -438,6 +438,7 @@ DEFINE_BOOL(trace_stub_failures, false,
"trace deoptimization of generated code stubs")
DEFINE_BOOL(serialize_toplevel, false, "enable caching of toplevel scripts")
DEFINE_BOOL(trace_code_serializer, false, "trace code serializer")
// compiler.cc
DEFINE_INT(min_preparse_length, 1024,
......
This diff is collapsed.
......@@ -257,7 +257,7 @@ class Deserializer: public SerializerDeserializer {
// Serialized user code reference certain objects that are provided in a list
// By calling this method, we assume that we are deserializing user code.
void SetAttachedObjects(Vector<Object*>* attached_objects) {
void SetAttachedObjects(Vector<Handle<Object> >* attached_objects) {
attached_objects_ = attached_objects;
}
......@@ -308,7 +308,7 @@ class Deserializer: public SerializerDeserializer {
Isolate* isolate_;
// Objects from the attached object descriptions in the serialized user code.
Vector<Object*>* attached_objects_;
Vector<Handle<Object> >* attached_objects_;
SnapshotByteSource* source_;
// This is the address of the next object that will be allocated in each
......@@ -459,12 +459,10 @@ class Serializer : public SerializerDeserializer {
HowToCode how_to_code,
WhereToPoint where_to_point,
int skip) = 0;
void SerializeReferenceToPreviousObject(
int space,
int address,
HowToCode how_to_code,
WhereToPoint where_to_point,
int skip);
void SerializeReferenceToPreviousObject(HeapObject* heap_object,
HowToCode how_to_code,
WhereToPoint where_to_point,
int skip);
void InitializeAllocators();
// This will return the space for an object.
static int SpaceOfObject(HeapObject* object);
......@@ -594,20 +592,29 @@ class CodeSerializer : public Serializer {
Handle<String> source);
static const int kSourceObjectIndex = 0;
static const int kCodeStubsBaseIndex = 1;
String* source() {
DCHECK(!AllowHeapAllocation::IsAllowed());
return source_;
}
List<uint32_t>* stub_keys() { return &stub_keys_; }
private:
void SerializeBuiltin(Code* builtin, HowToCode how_to_code,
WhereToPoint where_to_point, int skip);
void SerializeCodeStub(Code* code, HowToCode how_to_code,
WhereToPoint where_to_point, int skip);
void SerializeSourceObject(HowToCode how_to_code, WhereToPoint where_to_point,
int skip);
void SerializeHeapObject(HeapObject* heap_object, HowToCode how_to_code,
WhereToPoint where_to_point, int skip);
int AddCodeStubKey(uint32_t stub_key);
DisallowHeapAllocation no_gc_;
String* source_;
List<uint32_t> stub_keys_;
DISALLOW_COPY_AND_ASSIGN(CodeSerializer);
};
......@@ -638,12 +645,22 @@ class SerializedCodeData {
return result;
}
Vector<const uint32_t> CodeStubKeys() const {
return Vector<const uint32_t>(
reinterpret_cast<const uint32_t*>(script_data_->data() + kHeaderSize),
GetHeaderValue(kNumCodeStubKeysOffset));
}
const byte* Payload() const {
return script_data_->data() + kHeaderEntries * kIntSize;
int code_stubs_size = GetHeaderValue(kNumCodeStubKeysOffset) * kInt32Size;
return script_data_->data() + kHeaderSize + code_stubs_size;
}
int PayloadLength() const {
return script_data_->length() - kHeaderEntries * kIntSize;
int payload_length = GetHeaderValue(kPayloadLengthOffset);
DCHECK_EQ(script_data_->data() + script_data_->length(),
Payload() + payload_length);
return payload_length;
}
int GetReservation(int space) const {
......@@ -666,10 +683,21 @@ class SerializedCodeData {
// The data header consists of int-sized entries:
// [0] version hash
// [1..7] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE.
// [1] number of code stub keys
// [2] payload length
// [3..9] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE.
static const int kCheckSumOffset = 0;
static const int kReservationsOffset = 1;
static const int kHeaderEntries = 8;
static const int kNumCodeStubKeysOffset = 1;
static const int kPayloadLengthOffset = 2;
static const int kReservationsOffset = 3;
static const int kNumSpaces = PROPERTY_CELL_SPACE - NEW_SPACE + 1;
static const int kHeaderEntries = kReservationsOffset + kNumSpaces;
static const int kHeaderSize = kHeaderEntries * kIntSize;
// Following the header, we store, in sequential order
// - code stub keys
// - serialization payload
ScriptData* script_data_;
bool owns_script_data_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment