Commit 0b20d13b authored by yangguo@chromium.org's avatar yangguo@chromium.org

Handlify AddToOptimizedCodeMap.

R=ulan@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20722 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 160263fa
...@@ -9570,52 +9570,38 @@ void SharedFunctionInfo::AddToOptimizedCodeMap( ...@@ -9570,52 +9570,38 @@ void SharedFunctionInfo::AddToOptimizedCodeMap(
Handle<Code> code, Handle<Code> code,
Handle<FixedArray> literals, Handle<FixedArray> literals,
BailoutId osr_ast_id) { BailoutId osr_ast_id) {
CALL_HEAP_FUNCTION_VOID( Isolate* isolate = shared->GetIsolate();
shared->GetIsolate(),
shared->AddToOptimizedCodeMap(
*native_context, *code, *literals, osr_ast_id));
}
MaybeObject* SharedFunctionInfo::AddToOptimizedCodeMap(Context* native_context,
Code* code,
FixedArray* literals,
BailoutId osr_ast_id) {
ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION);
ASSERT(native_context->IsNativeContext()); ASSERT(native_context->IsNativeContext());
STATIC_ASSERT(kEntryLength == 4); STATIC_ASSERT(kEntryLength == 4);
Heap* heap = GetHeap(); Handle<FixedArray> new_code_map;
FixedArray* new_code_map; Handle<Object> value(shared->optimized_code_map(), isolate);
Object* value = optimized_code_map(); int old_length;
Smi* osr_ast_id_smi = Smi::FromInt(osr_ast_id.ToInt());
if (value->IsSmi()) { if (value->IsSmi()) {
// No optimized code map. // No optimized code map.
ASSERT_EQ(0, Smi::cast(value)->value()); ASSERT_EQ(0, Smi::cast(*value)->value());
// Create 3 entries per context {context, code, literals}. // Create 3 entries per context {context, code, literals}.
MaybeObject* maybe = heap->AllocateFixedArray(kInitialLength); new_code_map = isolate->factory()->NewFixedArray(kInitialLength);
if (!maybe->To(&new_code_map)) return maybe; old_length = kEntriesStart;
new_code_map->set(kEntriesStart + kContextOffset, native_context);
new_code_map->set(kEntriesStart + kCachedCodeOffset, code);
new_code_map->set(kEntriesStart + kLiteralsOffset, literals);
new_code_map->set(kEntriesStart + kOsrAstIdOffset, osr_ast_id_smi);
} else { } else {
// Copy old map and append one new entry. // Copy old map and append one new entry.
FixedArray* old_code_map = FixedArray::cast(value); Handle<FixedArray> old_code_map = Handle<FixedArray>::cast(value);
ASSERT_EQ(-1, SearchOptimizedCodeMap(native_context, osr_ast_id)); ASSERT_EQ(-1, shared->SearchOptimizedCodeMap(*native_context, osr_ast_id));
int old_length = old_code_map->length(); old_length = old_code_map->length();
int new_length = old_length + kEntryLength; new_code_map = isolate->factory()->CopySizeFixedArray(
MaybeObject* maybe = old_code_map->CopySize(new_length); old_code_map, old_length + kEntryLength);
if (!maybe->To(&new_code_map)) return maybe;
new_code_map->set(old_length + kContextOffset, native_context);
new_code_map->set(old_length + kCachedCodeOffset, code);
new_code_map->set(old_length + kLiteralsOffset, literals);
new_code_map->set(old_length + kOsrAstIdOffset, osr_ast_id_smi);
// Zap the old map for the sake of the heap verifier. // Zap the old map for the sake of the heap verifier.
if (Heap::ShouldZapGarbage()) { if (Heap::ShouldZapGarbage()) {
Object** data = old_code_map->data_start(); Object** data = old_code_map->data_start();
MemsetPointer(data, heap->the_hole_value(), old_length); MemsetPointer(data, isolate->heap()->the_hole_value(), old_length);
} }
} }
new_code_map->set(old_length + kContextOffset, *native_context);
new_code_map->set(old_length + kCachedCodeOffset, *code);
new_code_map->set(old_length + kLiteralsOffset, *literals);
new_code_map->set(old_length + kOsrAstIdOffset,
Smi::FromInt(osr_ast_id.ToInt()));
#ifdef DEBUG #ifdef DEBUG
for (int i = kEntriesStart; i < new_code_map->length(); i += kEntryLength) { for (int i = kEntriesStart; i < new_code_map->length(); i += kEntryLength) {
ASSERT(new_code_map->get(i + kContextOffset)->IsNativeContext()); ASSERT(new_code_map->get(i + kContextOffset)->IsNativeContext());
...@@ -9626,8 +9612,7 @@ MaybeObject* SharedFunctionInfo::AddToOptimizedCodeMap(Context* native_context, ...@@ -9626,8 +9612,7 @@ MaybeObject* SharedFunctionInfo::AddToOptimizedCodeMap(Context* native_context,
ASSERT(new_code_map->get(i + kOsrAstIdOffset)->IsSmi()); ASSERT(new_code_map->get(i + kOsrAstIdOffset)->IsSmi());
} }
#endif #endif
set_optimized_code_map(new_code_map); shared->set_optimized_code_map(*new_code_map);
return new_code_map;
} }
...@@ -9669,6 +9654,7 @@ void SharedFunctionInfo::ClearOptimizedCodeMap() { ...@@ -9669,6 +9654,7 @@ void SharedFunctionInfo::ClearOptimizedCodeMap() {
void SharedFunctionInfo::EvictFromOptimizedCodeMap(Code* optimized_code, void SharedFunctionInfo::EvictFromOptimizedCodeMap(Code* optimized_code,
const char* reason) { const char* reason) {
DisallowHeapAllocation no_gc;
if (optimized_code_map()->IsSmi()) return; if (optimized_code_map()->IsSmi()) return;
FixedArray* code_map = FixedArray::cast(optimized_code_map()); FixedArray* code_map = FixedArray::cast(optimized_code_map());
...@@ -10258,6 +10244,7 @@ void SharedFunctionInfo::CompleteInobjectSlackTracking() { ...@@ -10258,6 +10244,7 @@ void SharedFunctionInfo::CompleteInobjectSlackTracking() {
int SharedFunctionInfo::SearchOptimizedCodeMap(Context* native_context, int SharedFunctionInfo::SearchOptimizedCodeMap(Context* native_context,
BailoutId osr_ast_id) { BailoutId osr_ast_id) {
DisallowHeapAllocation no_gc;
ASSERT(native_context->IsNativeContext()); ASSERT(native_context->IsNativeContext());
if (!FLAG_cache_optimized_code) return -1; if (!FLAG_cache_optimized_code) return -1;
Object* value = optimized_code_map(); Object* value = optimized_code_map();
......
...@@ -6927,10 +6927,6 @@ class SharedFunctionInfo: public HeapObject { ...@@ -6927,10 +6927,6 @@ class SharedFunctionInfo: public HeapObject {
void TrimOptimizedCodeMap(int shrink_by); void TrimOptimizedCodeMap(int shrink_by);
// Add a new entry to the optimized code map. // Add a new entry to the optimized code map.
MUST_USE_RESULT MaybeObject* AddToOptimizedCodeMap(Context* native_context,
Code* code,
FixedArray* literals,
BailoutId osr_ast_id);
static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared,
Handle<Context> native_context, Handle<Context> native_context,
Handle<Code> code, Handle<Code> code,
......
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