Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(805)

Unified Diff: src/objects.cc

Issue 1433923002: Maintain a FixedArray for the optimized code map. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Missed a case, also turn on flag for testing. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/objects.h ('K') | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index b42ed68a86f4f23f8dea23bdc947c2c657e24a2b..24778f9956ab9027fcaf0e1481b3f48b1ee5afed 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -11057,10 +11057,9 @@ void SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap(
Isolate* isolate = shared->GetIsolate();
if (isolate->serializer_enabled()) return;
DCHECK(code->kind() == Code::OPTIMIZED_FUNCTION);
- Handle<Object> value(shared->optimized_code_map(), isolate);
- if (value->IsSmi()) return; // Empty code maps are unsupported.
- Handle<FixedArray> code_map = Handle<FixedArray>::cast(value);
- code_map->set(kSharedCodeIndex, *code);
+ // Empty code maps are unsupported.
+ if (shared->OptimizedCodeMapIsCleared()) return;
+ shared->optimized_code_map()->set(kSharedCodeIndex, *code);
}
@@ -11077,15 +11076,12 @@ void SharedFunctionInfo::AddToOptimizedCodeMap(
DCHECK(native_context->IsNativeContext());
STATIC_ASSERT(kEntryLength == 4);
Handle<FixedArray> new_code_map;
- Handle<Object> value(shared->optimized_code_map(), isolate);
int entry;
- if (value->IsSmi()) {
- // No optimized code map.
- DCHECK_EQ(0, Smi::cast(*value)->value());
+ if (shared->OptimizedCodeMapIsCleared()) {
new_code_map = isolate->factory()->NewFixedArray(kInitialLength, TENURED);
entry = kEntriesStart;
} else {
- Handle<FixedArray> old_code_map = Handle<FixedArray>::cast(value);
+ Handle<FixedArray> old_code_map(shared->optimized_code_map(), isolate);
entry = shared->SearchOptimizedCodeMapEntry(*native_context, osr_ast_id);
if (entry > kSharedCodeIndex) {
// Found an existing context-specific entry, it must not contain any code.
@@ -11103,7 +11099,7 @@ void SharedFunctionInfo::AddToOptimizedCodeMap(
// TODO(mstarzinger): Temporary workaround. The allocation above might have
// flushed the optimized code map and the copy we created is full of holes.
// For now we just give up on adding the entry and pretend it got flushed.
- if (shared->optimized_code_map()->IsSmi()) return;
+ if (shared->OptimizedCodeMapIsCleared()) return;
entry = old_code_map->length();
}
new_code_map->set(entry + kContextOffset, *native_context);
@@ -11125,8 +11121,8 @@ void SharedFunctionInfo::AddToOptimizedCodeMap(
#endif
// Zap any old optimized code map.
- if (!shared->optimized_code_map()->IsSmi()) {
- FixedArray* old_code_map = FixedArray::cast(shared->optimized_code_map());
+ if (!shared->OptimizedCodeMapIsCleared()) {
+ FixedArray* old_code_map = shared->optimized_code_map();
old_code_map->FillWithHoles(0, old_code_map->length());
}
@@ -11136,22 +11132,23 @@ void SharedFunctionInfo::AddToOptimizedCodeMap(
void SharedFunctionInfo::ClearOptimizedCodeMap() {
// Zap any old optimized code map.
- if (!optimized_code_map()->IsSmi()) {
- FixedArray* old_code_map = FixedArray::cast(optimized_code_map());
+ FixedArray* cleared_map = GetHeap()->cleared_optimized_code_map();
+ if (optimized_code_map() != cleared_map) {
Michael Starzinger 2015/11/13 12:14:22 suggestion: Not sure this optimization is worth it
mvstanton 2015/11/17 20:32:12 Done.
+ FixedArray* old_code_map = optimized_code_map();
old_code_map->FillWithHoles(0, old_code_map->length());
}
- set_optimized_code_map(Smi::FromInt(0));
+ set_optimized_code_map(cleared_map, SKIP_WRITE_BARRIER);
}
void SharedFunctionInfo::EvictFromOptimizedCodeMap(Code* optimized_code,
const char* reason) {
DisallowHeapAllocation no_gc;
- if (optimized_code_map()->IsSmi()) return;
+ if (OptimizedCodeMapIsCleared()) return;
Heap* heap = GetHeap();
- FixedArray* code_map = FixedArray::cast(optimized_code_map());
+ FixedArray* code_map = optimized_code_map();
int dst = kEntriesStart;
int length = code_map->length();
for (int src = kEntriesStart; src < length; src += kEntryLength) {
@@ -11210,7 +11207,7 @@ void SharedFunctionInfo::EvictFromOptimizedCodeMap(Code* optimized_code,
void SharedFunctionInfo::TrimOptimizedCodeMap(int shrink_by) {
- FixedArray* code_map = FixedArray::cast(optimized_code_map());
+ FixedArray* code_map = optimized_code_map();
DCHECK(shrink_by % kEntryLength == 0);
DCHECK(shrink_by <= code_map->length() - kEntriesStart);
// Always trim even when array is cleared because of heap verifier.
@@ -12352,9 +12349,8 @@ int SharedFunctionInfo::SearchOptimizedCodeMapEntry(Context* native_context,
BailoutId osr_ast_id) {
DisallowHeapAllocation no_gc;
DCHECK(native_context->IsNativeContext());
- Object* value = optimized_code_map();
- if (!value->IsSmi()) {
- FixedArray* optimized_code_map = FixedArray::cast(value);
+ if (!OptimizedCodeMapIsCleared()) {
+ FixedArray* optimized_code_map = this->optimized_code_map();
int length = optimized_code_map->length();
Smi* osr_ast_id_smi = Smi::FromInt(osr_ast_id.ToInt());
for (int i = kEntriesStart; i < length; i += kEntryLength) {
@@ -12377,7 +12373,7 @@ CodeAndLiterals SharedFunctionInfo::SearchOptimizedCodeMap(
CodeAndLiterals result = {nullptr, nullptr};
int entry = SearchOptimizedCodeMapEntry(native_context, osr_ast_id);
if (entry != kNotFound) {
- FixedArray* code_map = FixedArray::cast(optimized_code_map());
+ FixedArray* code_map = optimized_code_map();
if (entry == kSharedCodeIndex) {
result = {Code::cast(code_map->get(kSharedCodeIndex)), nullptr};
@@ -12388,7 +12384,7 @@ CodeAndLiterals SharedFunctionInfo::SearchOptimizedCodeMap(
LiteralsArray::cast(code_map->get(entry + kLiteralsOffset))};
}
}
- if (FLAG_trace_opt && !optimized_code_map()->IsSmi() &&
+ if (FLAG_trace_opt && !OptimizedCodeMapIsCleared() &&
result.code == nullptr) {
PrintF("[didn't find optimized code in optimized code map for ");
ShortPrint();
« src/objects.h ('K') | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698