Commit b591fccb authored by Adam Klein's avatar Adam Klein Committed by V8 LUCI CQ

Revert "Refactor OSROptimizedCodeCache"

This reverts commit d368dcf4.

Reason for revert: https://crbug.com/1312188

Original change's description:
> Refactor OSROptimizedCodeCache
>
> Tweak a few names, remove a few GetIsolate calls, other minor
> usability refactors.
>
> It may be worth taking a closer look at the impl in the future,
> currently the design choices don't seem ideal (see the added TODO
> on top of the class).
>
> Bug: v8:12161
> Change-Id: Ib34e372aa58a30c68c9c5cdd0d1da0ec3e86717c
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3560447
> Reviewed-by: Leszek Swirski <leszeks@chromium.org>
> Commit-Queue: Jakob Linke <jgruber@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#79687}

Bug: v8:12161, chromium:1312188
Change-Id: Ieb3a91682845a23536fdfdf3208af74b3c6585f8
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3564989
Auto-Submit: Adam Klein <adamk@chromium.org>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#79700}
parent 05a58f26
...@@ -903,8 +903,9 @@ class OptimizedCodeCache : public AllStatic { ...@@ -903,8 +903,9 @@ class OptimizedCodeCache : public AllStatic {
CodeT code; CodeT code;
if (IsOSR(osr_offset)) { if (IsOSR(osr_offset)) {
// For OSR, check the OSR optimized code cache. // For OSR, check the OSR optimized code cache.
code = function->native_context().osr_code_cache().TryGet( code = function->native_context()
shared, osr_offset, isolate); .GetOSROptimizedCodeCache()
.GetOptimizedCode(shared, osr_offset, isolate);
} else { } else {
// Non-OSR code may be cached on the feedback vector. // Non-OSR code may be cached on the feedback vector.
if (function->has_feedback_vector()) { if (function->has_feedback_vector()) {
...@@ -942,7 +943,7 @@ class OptimizedCodeCache : public AllStatic { ...@@ -942,7 +943,7 @@ class OptimizedCodeCache : public AllStatic {
DCHECK(CodeKindCanOSR(kind)); DCHECK(CodeKindCanOSR(kind));
Handle<SharedFunctionInfo> shared(function->shared(), isolate); Handle<SharedFunctionInfo> shared(function->shared(), isolate);
Handle<NativeContext> native_context(function->native_context(), isolate); Handle<NativeContext> native_context(function->native_context(), isolate);
OSROptimizedCodeCache::Insert(isolate, native_context, shared, code, OSROptimizedCodeCache::AddOptimizedCode(native_context, shared, code,
osr_offset); osr_offset);
return; return;
} }
......
...@@ -377,7 +377,8 @@ void Deoptimizer::DeoptimizeMarkedCodeForContext(NativeContext native_context) { ...@@ -377,7 +377,8 @@ void Deoptimizer::DeoptimizeMarkedCodeForContext(NativeContext native_context) {
isolate->heap()->InvalidateCodeDeoptimizationData(code); isolate->heap()->InvalidateCodeDeoptimizationData(code);
} }
native_context.osr_code_cache().EvictDeoptimizedCode(isolate); native_context.GetOSROptimizedCodeCache().EvictMarkedCode(
native_context.GetIsolate());
} }
void Deoptimizer::DeoptimizeAll(Isolate* isolate) { void Deoptimizer::DeoptimizeAll(Isolate* isolate) {
...@@ -392,7 +393,7 @@ void Deoptimizer::DeoptimizeAll(Isolate* isolate) { ...@@ -392,7 +393,7 @@ void Deoptimizer::DeoptimizeAll(Isolate* isolate) {
while (!context.IsUndefined(isolate)) { while (!context.IsUndefined(isolate)) {
NativeContext native_context = NativeContext::cast(context); NativeContext native_context = NativeContext::cast(context);
MarkAllCodeForContext(native_context); MarkAllCodeForContext(native_context);
OSROptimizedCodeCache::Clear(isolate, native_context); OSROptimizedCodeCache::Clear(native_context);
DeoptimizeMarkedCodeForContext(native_context); DeoptimizeMarkedCodeForContext(native_context);
context = native_context.next_context_link(); context = native_context.next_context_link();
} }
...@@ -451,7 +452,7 @@ void Deoptimizer::DeoptimizeFunction(JSFunction function, Code code) { ...@@ -451,7 +452,7 @@ void Deoptimizer::DeoptimizeFunction(JSFunction function, Code code) {
// pointers. Update DeoptimizeMarkedCodeForContext to use handles and remove // pointers. Update DeoptimizeMarkedCodeForContext to use handles and remove
// this call from here. // this call from here.
OSROptimizedCodeCache::Compact( OSROptimizedCodeCache::Compact(
isolate, Handle<NativeContext>(function.native_context(), isolate)); Handle<NativeContext>(function.native_context(), isolate));
} }
} }
......
...@@ -156,7 +156,8 @@ bool HaveCachedOSRCodeForCurrentBytecodeOffset(UnoptimizedFrame* frame, ...@@ -156,7 +156,8 @@ bool HaveCachedOSRCodeForCurrentBytecodeOffset(UnoptimizedFrame* frame,
BytecodeArray bytecode = frame->GetBytecodeArray(); BytecodeArray bytecode = frame->GetBytecodeArray();
const int bytecode_offset = frame->GetBytecodeOffset(); const int bytecode_offset = frame->GetBytecodeOffset();
if (V8_UNLIKELY(function.shared().osr_code_cache_state() != kNotCached)) { if (V8_UNLIKELY(function.shared().osr_code_cache_state() != kNotCached)) {
OSROptimizedCodeCache cache = function.native_context().osr_code_cache(); OSROptimizedCodeCache cache =
function.native_context().GetOSROptimizedCodeCache();
interpreter::BytecodeArrayIterator iterator( interpreter::BytecodeArrayIterator iterator(
handle(bytecode, frame->isolate())); handle(bytecode, frame->isolate()));
for (int jump_offset : cache.GetBytecodeOffsetsFromSFI(function.shared())) { for (int jump_offset : cache.GetBytecodeOffsetsFromSFI(function.shared())) {
......
...@@ -1184,7 +1184,7 @@ Handle<NativeContext> Factory::NewNativeContext() { ...@@ -1184,7 +1184,7 @@ Handle<NativeContext> Factory::NewNativeContext() {
context.set_math_random_index(Smi::zero()); context.set_math_random_index(Smi::zero());
context.set_serialized_objects(*empty_fixed_array()); context.set_serialized_objects(*empty_fixed_array());
context.set_microtask_queue(isolate(), nullptr); context.set_microtask_queue(isolate(), nullptr);
context.set_osr_code_cache(*OSROptimizedCodeCache::Empty(isolate())); context.set_osr_code_cache(*empty_weak_fixed_array());
context.set_retained_maps(*empty_weak_array_list()); context.set_retained_maps(*empty_weak_array_list());
return handle(context, isolate()); return handle(context, isolate());
} }
......
...@@ -296,6 +296,10 @@ ScriptContextTable NativeContext::synchronized_script_context_table() const { ...@@ -296,6 +296,10 @@ ScriptContextTable NativeContext::synchronized_script_context_table() const {
get(SCRIPT_CONTEXT_TABLE_INDEX, kAcquireLoad)); get(SCRIPT_CONTEXT_TABLE_INDEX, kAcquireLoad));
} }
OSROptimizedCodeCache NativeContext::GetOSROptimizedCodeCache() {
return OSROptimizedCodeCache::cast(osr_code_cache());
}
void NativeContext::SetOptimizedCodeListHead(Object head) { void NativeContext::SetOptimizedCodeListHead(Object head) {
set(OPTIMIZED_CODE_LIST, head, UPDATE_WEAK_WRITE_BARRIER, kReleaseStore); set(OPTIMIZED_CODE_LIST, head, UPDATE_WEAK_WRITE_BARRIER, kReleaseStore);
} }
......
...@@ -369,7 +369,7 @@ enum ContextLookupFlags { ...@@ -369,7 +369,7 @@ enum ContextLookupFlags {
V(WEAKSET_ADD_INDEX, JSFunction, weakset_add) \ V(WEAKSET_ADD_INDEX, JSFunction, weakset_add) \
V(WRAPPED_FUNCTION_MAP_INDEX, Map, wrapped_function_map) \ V(WRAPPED_FUNCTION_MAP_INDEX, Map, wrapped_function_map) \
V(RETAINED_MAPS, Object, retained_maps) \ V(RETAINED_MAPS, Object, retained_maps) \
V(OSR_CODE_CACHE_INDEX, OSROptimizedCodeCache, osr_code_cache) V(OSR_CODE_CACHE_INDEX, WeakFixedArray, osr_code_cache)
#include "torque-generated/src/objects/contexts-tq.inc" #include "torque-generated/src/objects/contexts-tq.inc"
...@@ -777,6 +777,8 @@ class NativeContext : public Context { ...@@ -777,6 +777,8 @@ class NativeContext : public Context {
inline void SetDeoptimizedCodeListHead(Object head); inline void SetDeoptimizedCodeListHead(Object head);
inline Object DeoptimizedCodeListHead(); inline Object DeoptimizedCodeListHead();
inline OSROptimizedCodeCache GetOSROptimizedCodeCache();
void ResetErrorsThrown(); void ResetErrorsThrown();
void IncrementErrorsThrown(); void IncrementErrorsThrown();
int GetErrorsThrown(); int GetErrorsThrown();
......
...@@ -12,28 +12,22 @@ ...@@ -12,28 +12,22 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
// static const int OSROptimizedCodeCache::kInitialLength;
Handle<OSROptimizedCodeCache> OSROptimizedCodeCache::Empty(Isolate* isolate) { const int OSROptimizedCodeCache::kMaxLength;
return Handle<OSROptimizedCodeCache>::cast(
isolate->factory()->empty_weak_fixed_array());
}
// static void OSROptimizedCodeCache::AddOptimizedCode(
void OSROptimizedCodeCache::Insert(Isolate* isolate, Handle<NativeContext> native_context, Handle<SharedFunctionInfo> shared,
Handle<NativeContext> native_context, Handle<CodeT> code, BytecodeOffset osr_offset) {
Handle<SharedFunctionInfo> shared,
Handle<CodeT> code,
BytecodeOffset osr_offset) {
DCHECK(!osr_offset.IsNone()); DCHECK(!osr_offset.IsNone());
DCHECK(!isolate->serializer_enabled());
DCHECK(CodeKindIsOptimizedJSFunction(code->kind())); DCHECK(CodeKindIsOptimizedJSFunction(code->kind()));
STATIC_ASSERT(kEntryLength == 3);
Isolate* isolate = native_context->GetIsolate();
DCHECK(!isolate->serializer_enabled());
Handle<OSROptimizedCodeCache> osr_cache(native_context->osr_code_cache(), Handle<OSROptimizedCodeCache> osr_cache(
isolate); native_context->GetOSROptimizedCodeCache(), isolate);
DCHECK_EQ(osr_cache->FindEntry(*shared, osr_offset), -1); DCHECK_EQ(osr_cache->FindEntry(*shared, osr_offset), -1);
STATIC_ASSERT(kEntryLength == 3);
int entry = -1; int entry = -1;
for (int index = 0; index < osr_cache->length(); index += kEntryLength) { for (int index = 0; index < osr_cache->length(); index += kEntryLength) {
if (osr_cache->Get(index + kSharedOffset)->IsCleared() || if (osr_cache->Get(index + kSharedOffset)->IsCleared() ||
...@@ -43,31 +37,28 @@ void OSROptimizedCodeCache::Insert(Isolate* isolate, ...@@ -43,31 +37,28 @@ void OSROptimizedCodeCache::Insert(Isolate* isolate,
} }
} }
if (entry == -1) { if (entry == -1 && osr_cache->length() + kEntryLength <= kMaxLength) {
if (osr_cache->length() + kEntryLength <= kMaxLength) { entry = GrowOSRCache(native_context, &osr_cache);
entry = GrowOSRCache(isolate, native_context, &osr_cache); } else if (entry == -1) {
} else { // We reached max capacity and cannot grow further. Reuse an existing entry.
// We reached max capacity and cannot grow further. Reuse an existing
// entry.
// TODO(mythria): We could use better mechanisms (like lru) to replace // TODO(mythria): We could use better mechanisms (like lru) to replace
// existing entries. Though we don't expect this to be a common case, so // existing entries. Though we don't expect this to be a common case, so
// for now choosing to replace the first entry. // for now choosing to replace the first entry.
entry = 0; entry = 0;
} }
}
osr_cache->InitializeEntry(entry, *shared, *code, osr_offset); osr_cache->InitializeEntry(entry, *shared, *code, osr_offset);
} }
void OSROptimizedCodeCache::Clear(Isolate* isolate, void OSROptimizedCodeCache::Clear(NativeContext native_context) {
NativeContext native_context) { native_context.set_osr_code_cache(
native_context.set_osr_code_cache(*OSROptimizedCodeCache::Empty(isolate)); *native_context.GetIsolate()->factory()->empty_weak_fixed_array());
} }
void OSROptimizedCodeCache::Compact(Isolate* isolate, void OSROptimizedCodeCache::Compact(Handle<NativeContext> native_context) {
Handle<NativeContext> native_context) { Handle<OSROptimizedCodeCache> osr_cache(
Handle<OSROptimizedCodeCache> osr_cache(native_context->osr_code_cache(), native_context->GetOSROptimizedCodeCache(), native_context->GetIsolate());
isolate); Isolate* isolate = native_context->GetIsolate();
// Re-adjust the cache so all the valid entries are on one side. This will // Re-adjust the cache so all the valid entries are on one side. This will
// enable us to compress the cache if needed. // enable us to compress the cache if needed.
...@@ -92,31 +83,29 @@ void OSROptimizedCodeCache::Compact(Isolate* isolate, ...@@ -92,31 +83,29 @@ void OSROptimizedCodeCache::Compact(Isolate* isolate,
DCHECK_LT(new_osr_cache->length(), osr_cache->length()); DCHECK_LT(new_osr_cache->length(), osr_cache->length());
{ {
DisallowGarbageCollection no_gc; DisallowGarbageCollection no_gc;
new_osr_cache->CopyElements(isolate, 0, *osr_cache, 0, new_osr_cache->CopyElements(native_context->GetIsolate(), 0, *osr_cache, 0,
new_osr_cache->length(), new_osr_cache->length(),
new_osr_cache->GetWriteBarrierMode(no_gc)); new_osr_cache->GetWriteBarrierMode(no_gc));
} }
native_context->set_osr_code_cache(*new_osr_cache); native_context->set_osr_code_cache(*new_osr_cache);
} }
CodeT OSROptimizedCodeCache::TryGet(SharedFunctionInfo shared, CodeT OSROptimizedCodeCache::GetOptimizedCode(SharedFunctionInfo shared,
BytecodeOffset osr_offset, BytecodeOffset osr_offset,
Isolate* isolate) { Isolate* isolate) {
DisallowGarbageCollection no_gc; DisallowGarbageCollection no_gc;
int index = FindEntry(shared, osr_offset); int index = FindEntry(shared, osr_offset);
if (index == -1) return {}; if (index == -1) return CodeT();
CodeT code = GetCodeFromEntry(index); CodeT code = GetCodeFromEntry(index);
if (code.is_null()) { if (code.is_null()) {
ClearEntry(index, isolate); ClearEntry(index, isolate);
return {}; return CodeT();
} }
DCHECK(code.is_optimized_code() && !code.marked_for_deoptimization()); DCHECK(code.is_optimized_code() && !code.marked_for_deoptimization());
return code; return code;
} }
void OSROptimizedCodeCache::EvictDeoptimizedCode(Isolate* isolate) { void OSROptimizedCodeCache::EvictMarkedCode(Isolate* isolate) {
// This is called from DeoptimizeMarkedCodeForContext that uses raw pointers // This is called from DeoptimizeMarkedCodeForContext that uses raw pointers
// and hence the DisallowGarbageCollection scope here. // and hence the DisallowGarbageCollection scope here.
DisallowGarbageCollection no_gc; DisallowGarbageCollection no_gc;
...@@ -146,8 +135,9 @@ std::vector<int> OSROptimizedCodeCache::GetBytecodeOffsetsFromSFI( ...@@ -146,8 +135,9 @@ std::vector<int> OSROptimizedCodeCache::GetBytecodeOffsetsFromSFI(
} }
int OSROptimizedCodeCache::GrowOSRCache( int OSROptimizedCodeCache::GrowOSRCache(
Isolate* isolate, Handle<NativeContext> native_context, Handle<NativeContext> native_context,
Handle<OSROptimizedCodeCache>* osr_cache) { Handle<OSROptimizedCodeCache>* osr_cache) {
Isolate* isolate = native_context->GetIsolate();
int old_length = (*osr_cache)->length(); int old_length = (*osr_cache)->length();
int grow_by = CapacityForLength(old_length) - old_length; int grow_by = CapacityForLength(old_length) - old_length;
DCHECK_GT(grow_by, kEntryLength); DCHECK_GT(grow_by, kEntryLength);
...@@ -266,13 +256,5 @@ bool OSROptimizedCodeCache::NeedsTrimming(int num_valid_entries, ...@@ -266,13 +256,5 @@ bool OSROptimizedCodeCache::NeedsTrimming(int num_valid_entries,
return curr_length > kInitialLength && curr_length > num_valid_entries * 3; return curr_length > kInitialLength && curr_length > num_valid_entries * 3;
} }
MaybeObject OSROptimizedCodeCache::RawGetForTesting(int index) const {
return WeakFixedArray::Get(index);
}
void OSROptimizedCodeCache::RawSetForTesting(int index, MaybeObject value) {
WeakFixedArray::Set(index, value);
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define V8_OBJECTS_OSR_OPTIMIZED_CODE_CACHE_H_ #define V8_OBJECTS_OSR_OPTIMIZED_CODE_CACHE_H_
#include "src/objects/fixed-array.h" #include "src/objects/fixed-array.h"
// Has to be the last include (doesn't have include guards): // Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h" #include "src/objects/object-macros.h"
...@@ -22,79 +21,51 @@ enum OSRCodeCacheStateOfSFI : uint8_t { ...@@ -22,79 +21,51 @@ enum OSRCodeCacheStateOfSFI : uint8_t {
kCachedMultiple, // Very unlikely state, multiple entries. kCachedMultiple, // Very unlikely state, multiple entries.
}; };
// TODO(jgruber): There are a few issues with the current implementation:
//
// - The cache is a flat list, thus any search operation is O(N). This resulted
// in optimization attempts, see OSRCodeCacheStateOfSFI.
// - We always iterate up to `length` (== capacity).
// - We essentially reimplement WeakArrayList, i.e. growth and shrink logic.
// - On overflow, new entries always pick slot 0.
//
// There are a few alternatives:
//
// 1) we could reuse WeakArrayList logic (but then we'd still have to
// implement custom compaction due to our entry tuple structure).
// 2) we could reuse CompilationCacheTable (but then we lose weakness and have
// to deal with aging).
// 3) we could try to base on a weak HashTable variant (EphemeronHashTable?).
class V8_EXPORT OSROptimizedCodeCache : public WeakFixedArray { class V8_EXPORT OSROptimizedCodeCache : public WeakFixedArray {
public: public:
DECL_CAST(OSROptimizedCodeCache) DECL_CAST(OSROptimizedCodeCache)
static Handle<OSROptimizedCodeCache> Empty(Isolate* isolate); enum OSRCodeCacheConstants {
kSharedOffset,
kCachedCodeOffset,
kOsrIdOffset,
kEntryLength
};
static const int kInitialLength = OSRCodeCacheConstants::kEntryLength * 4;
static const int kMaxLength = OSRCodeCacheConstants::kEntryLength * 1024;
// Caches the optimized code |code| corresponding to the shared function // Caches the optimized code |code| corresponding to the shared function
// |shared| and bailout id |osr_offset| in the OSROptimized code cache. // |shared| and bailout id |osr_offset| in the OSROptimized code cache.
// If the OSR code cache wasn't created before it creates a code cache with // If the OSR code cache wasn't created before it creates a code cache with
// kOSRCodeCacheInitialLength entries. // kOSRCodeCacheInitialLength entries.
static void Insert(Isolate* isolate, Handle<NativeContext> context, static void AddOptimizedCode(Handle<NativeContext> context,
Handle<SharedFunctionInfo> shared, Handle<CodeT> code, Handle<SharedFunctionInfo> shared,
BytecodeOffset osr_offset); Handle<CodeT> code, BytecodeOffset osr_offset);
// Reduces the size of the OSR code cache if the number of valid entries are
// less than the current capacity of the cache.
static void Compact(Handle<NativeContext> context);
// Sets the OSR optimized code cache to an empty array.
static void Clear(NativeContext context);
// Returns the code corresponding to the shared function |shared| and // Returns the code corresponding to the shared function |shared| and
// BytecodeOffset |offset| if an entry exists in the cache. Returns an empty // BytecodeOffset |offset| if an entry exists in the cache. Returns an empty
// object otherwise. // object otherwise.
CodeT TryGet(SharedFunctionInfo shared, BytecodeOffset osr_offset, CodeT GetOptimizedCode(SharedFunctionInfo shared, BytecodeOffset osr_offset,
Isolate* isolate); Isolate* isolate);
// Remove all code objects marked for deoptimization from OSR code cache. // Remove all code objects marked for deoptimization from OSR code cache.
void EvictDeoptimizedCode(Isolate* isolate); void EvictMarkedCode(Isolate* isolate);
// Reduces the size of the OSR code cache if the number of valid entries are
// less than the current capacity of the cache.
static void Compact(Isolate* isolate, Handle<NativeContext> context);
// Sets the OSR optimized code cache to an empty array.
static void Clear(Isolate* isolate, NativeContext context);
// Returns vector of bytecode offsets corresponding to the shared function // Returns vector of bytecode offsets corresponding to the shared function
// |shared| // |shared|
std::vector<int> GetBytecodeOffsetsFromSFI(SharedFunctionInfo shared); std::vector<int> GetBytecodeOffsetsFromSFI(SharedFunctionInfo shared);
enum OSRCodeCacheConstants {
kSharedOffset,
kCachedCodeOffset,
kOsrIdOffset,
kEntryLength
};
static constexpr int kInitialLength = OSRCodeCacheConstants::kEntryLength * 4;
static constexpr int kMaxLength = OSRCodeCacheConstants::kEntryLength * 1024;
// For osr-code-cache-unittest.cc.
MaybeObject RawGetForTesting(int index) const;
void RawSetForTesting(int index, MaybeObject value);
private: private:
// Hide raw accessors to avoid terminology confusion.
using WeakFixedArray::Get;
using WeakFixedArray::Set;
// Functions that implement heuristics on when to grow / shrink the cache. // Functions that implement heuristics on when to grow / shrink the cache.
static int CapacityForLength(int curr_capacity); static int CapacityForLength(int curr_capacity);
static bool NeedsTrimming(int num_valid_entries, int curr_capacity); static bool NeedsTrimming(int num_valid_entries, int curr_capacity);
static int GrowOSRCache(Isolate* isolate, static int GrowOSRCache(Handle<NativeContext> native_context,
Handle<NativeContext> native_context,
Handle<OSROptimizedCodeCache>* osr_cache); Handle<OSROptimizedCodeCache>* osr_cache);
// Helper functions to get individual items from an entry in the cache. // Helper functions to get individual items from an entry in the cache.
......
...@@ -52,24 +52,23 @@ TEST_F(TestWithNativeContext, AddCodeToEmptyCache) { ...@@ -52,24 +52,23 @@ TEST_F(TestWithNativeContext, AddCodeToEmptyCache) {
Handle<SharedFunctionInfo> shared(function->shared(), isolate); Handle<SharedFunctionInfo> shared(function->shared(), isolate);
Handle<CodeT> code(function->code(), isolate); Handle<CodeT> code(function->code(), isolate);
BytecodeOffset bailout_id(1); BytecodeOffset bailout_id(1);
OSROptimizedCodeCache::Insert(isolate, native_context, shared, code, OSROptimizedCodeCache::AddOptimizedCode(native_context, shared, code,
bailout_id); bailout_id);
Handle<OSROptimizedCodeCache> osr_cache(native_context->osr_code_cache(), Handle<OSROptimizedCodeCache> osr_cache(
isolate); native_context->GetOSROptimizedCodeCache(), isolate);
EXPECT_EQ(osr_cache->length(), kInitialLength); EXPECT_EQ(osr_cache->length(), kInitialLength);
HeapObject sfi_entry; HeapObject sfi_entry;
osr_cache->RawGetForTesting(OSROptimizedCodeCache::kSharedOffset) osr_cache->Get(OSROptimizedCodeCache::kSharedOffset)
->GetHeapObject(&sfi_entry); ->GetHeapObject(&sfi_entry);
EXPECT_EQ(sfi_entry, *shared); EXPECT_EQ(sfi_entry, *shared);
HeapObject code_entry; HeapObject code_entry;
osr_cache->RawGetForTesting(OSROptimizedCodeCache::kCachedCodeOffset) osr_cache->Get(OSROptimizedCodeCache::kCachedCodeOffset)
->GetHeapObject(&code_entry); ->GetHeapObject(&code_entry);
EXPECT_EQ(code_entry, *code); EXPECT_EQ(code_entry, *code);
Smi osr_offset_entry; Smi osr_offset_entry;
osr_cache->RawGetForTesting(OSROptimizedCodeCache::kOsrIdOffset) osr_cache->Get(OSROptimizedCodeCache::kOsrIdOffset)->ToSmi(&osr_offset_entry);
->ToSmi(&osr_offset_entry);
EXPECT_EQ(osr_offset_entry.value(), bailout_id.ToInt()); EXPECT_EQ(osr_offset_entry.value(), bailout_id.ToInt());
} }
...@@ -88,30 +87,30 @@ TEST_F(TestWithNativeContext, GrowCodeCache) { ...@@ -88,30 +87,30 @@ TEST_F(TestWithNativeContext, GrowCodeCache) {
int bailout_id = 0; int bailout_id = 0;
for (bailout_id = 0; bailout_id < kInitialEntries; bailout_id++) { for (bailout_id = 0; bailout_id < kInitialEntries; bailout_id++) {
OSROptimizedCodeCache::Insert(isolate, native_context, shared, code, OSROptimizedCodeCache::AddOptimizedCode(native_context, shared, code,
BytecodeOffset(bailout_id)); BytecodeOffset(bailout_id));
} }
Handle<OSROptimizedCodeCache> osr_cache(native_context->osr_code_cache(), Handle<OSROptimizedCodeCache> osr_cache(
isolate); native_context->GetOSROptimizedCodeCache(), isolate);
EXPECT_EQ(osr_cache->length(), kInitialLength); EXPECT_EQ(osr_cache->length(), kInitialLength);
OSROptimizedCodeCache::Insert(isolate, native_context, shared, code, OSROptimizedCodeCache::AddOptimizedCode(native_context, shared, code,
BytecodeOffset(bailout_id)); BytecodeOffset(bailout_id));
osr_cache = osr_cache = Handle<OSROptimizedCodeCache>(
Handle<OSROptimizedCodeCache>(native_context->osr_code_cache(), isolate); native_context->GetOSROptimizedCodeCache(), isolate);
EXPECT_EQ(osr_cache->length(), kInitialLength * 2); EXPECT_EQ(osr_cache->length(), kInitialLength * 2);
int index = kInitialLength; int index = kInitialLength;
HeapObject sfi_entry; HeapObject sfi_entry;
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kSharedOffset) osr_cache->Get(index + OSROptimizedCodeCache::kSharedOffset)
->GetHeapObject(&sfi_entry); ->GetHeapObject(&sfi_entry);
EXPECT_EQ(sfi_entry, *shared); EXPECT_EQ(sfi_entry, *shared);
HeapObject code_entry; HeapObject code_entry;
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kCachedCodeOffset) osr_cache->Get(index + OSROptimizedCodeCache::kCachedCodeOffset)
->GetHeapObject(&code_entry); ->GetHeapObject(&code_entry);
EXPECT_EQ(code_entry, *code); EXPECT_EQ(code_entry, *code);
Smi osr_offset_entry; Smi osr_offset_entry;
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kOsrIdOffset) osr_cache->Get(index + OSROptimizedCodeCache::kOsrIdOffset)
->ToSmi(&osr_offset_entry); ->ToSmi(&osr_offset_entry);
EXPECT_EQ(osr_offset_entry.value(), bailout_id); EXPECT_EQ(osr_offset_entry.value(), bailout_id);
} }
...@@ -131,7 +130,7 @@ TEST_F(TestWithNativeContext, FindCachedEntry) { ...@@ -131,7 +130,7 @@ TEST_F(TestWithNativeContext, FindCachedEntry) {
int bailout_id = 0; int bailout_id = 0;
for (bailout_id = 0; bailout_id < kInitialEntries; bailout_id++) { for (bailout_id = 0; bailout_id < kInitialEntries; bailout_id++) {
OSROptimizedCodeCache::Insert(isolate, native_context, shared, code, OSROptimizedCodeCache::AddOptimizedCode(native_context, shared, code,
BytecodeOffset(bailout_id)); BytecodeOffset(bailout_id));
} }
...@@ -140,22 +139,26 @@ TEST_F(TestWithNativeContext, FindCachedEntry) { ...@@ -140,22 +139,26 @@ TEST_F(TestWithNativeContext, FindCachedEntry) {
Handle<JSFunction> function1 = RunJS<JSFunction>(source1.begin()); Handle<JSFunction> function1 = RunJS<JSFunction>(source1.begin());
Handle<SharedFunctionInfo> shared1(function1->shared(), isolate); Handle<SharedFunctionInfo> shared1(function1->shared(), isolate);
Handle<CodeT> code1(function1->code(), isolate); Handle<CodeT> code1(function1->code(), isolate);
OSROptimizedCodeCache::Insert(isolate, native_context, shared1, code1, OSROptimizedCodeCache::AddOptimizedCode(native_context, shared1, code1,
BytecodeOffset(bailout_id)); BytecodeOffset(bailout_id));
Handle<OSROptimizedCodeCache> osr_cache(native_context->osr_code_cache(), Handle<OSROptimizedCodeCache> osr_cache(
isolate); native_context->GetOSROptimizedCodeCache(), isolate);
EXPECT_EQ(osr_cache->TryGet(*shared, BytecodeOffset(0), isolate), *code); EXPECT_EQ(osr_cache->GetOptimizedCode(*shared, BytecodeOffset(0), isolate),
EXPECT_EQ(osr_cache->TryGet(*shared1, BytecodeOffset(bailout_id), isolate), *code);
EXPECT_EQ(osr_cache->GetOptimizedCode(*shared1, BytecodeOffset(bailout_id),
isolate),
*code1); *code1);
RunJS("%DeoptimizeFunction(f1)"); RunJS("%DeoptimizeFunction(f1)");
EXPECT_TRUE(osr_cache->TryGet(*shared1, BytecodeOffset(bailout_id), isolate) EXPECT_TRUE(
osr_cache->GetOptimizedCode(*shared1, BytecodeOffset(bailout_id), isolate)
.is_null()); .is_null());
osr_cache->RawSetForTesting(OSROptimizedCodeCache::kCachedCodeOffset, osr_cache->Set(OSROptimizedCodeCache::kCachedCodeOffset,
HeapObjectReference::ClearedValue(isolate)); HeapObjectReference::ClearedValue(isolate));
EXPECT_TRUE(osr_cache->TryGet(*shared, BytecodeOffset(0), isolate).is_null()); EXPECT_TRUE(osr_cache->GetOptimizedCode(*shared, BytecodeOffset(0), isolate)
.is_null());
} }
TEST_F(TestWithNativeContext, MaxCapacityCache) { TEST_F(TestWithNativeContext, MaxCapacityCache) {
...@@ -174,11 +177,11 @@ TEST_F(TestWithNativeContext, MaxCapacityCache) { ...@@ -174,11 +177,11 @@ TEST_F(TestWithNativeContext, MaxCapacityCache) {
int bailout_id = 0; int bailout_id = 0;
// Add max_capacity - 1 entries. // Add max_capacity - 1 entries.
for (bailout_id = 0; bailout_id < kMaxEntries - 1; bailout_id++) { for (bailout_id = 0; bailout_id < kMaxEntries - 1; bailout_id++) {
OSROptimizedCodeCache::Insert(isolate, native_context, shared, code, OSROptimizedCodeCache::AddOptimizedCode(native_context, shared, code,
BytecodeOffset(bailout_id)); BytecodeOffset(bailout_id));
} }
Handle<OSROptimizedCodeCache> osr_cache(native_context->osr_code_cache(), Handle<OSROptimizedCodeCache> osr_cache(
isolate); native_context->GetOSROptimizedCodeCache(), isolate);
EXPECT_EQ(osr_cache->length(), kMaxLength); EXPECT_EQ(osr_cache->length(), kMaxLength);
// Add an entry to reach max capacity. // Add an entry to reach max capacity.
...@@ -187,23 +190,22 @@ TEST_F(TestWithNativeContext, MaxCapacityCache) { ...@@ -187,23 +190,22 @@ TEST_F(TestWithNativeContext, MaxCapacityCache) {
Handle<JSFunction> function1 = RunJS<JSFunction>(source1.begin()); Handle<JSFunction> function1 = RunJS<JSFunction>(source1.begin());
Handle<SharedFunctionInfo> shared1(function1->shared(), isolate); Handle<SharedFunctionInfo> shared1(function1->shared(), isolate);
Handle<CodeT> code1(function1->code(), isolate); Handle<CodeT> code1(function1->code(), isolate);
OSROptimizedCodeCache::Insert(isolate, native_context, shared1, code1, OSROptimizedCodeCache::AddOptimizedCode(native_context, shared1, code1,
BytecodeOffset(bailout_id)); BytecodeOffset(bailout_id));
osr_cache = osr_cache = Handle<OSROptimizedCodeCache>(
Handle<OSROptimizedCodeCache>(native_context->osr_code_cache(), isolate); native_context->GetOSROptimizedCodeCache(), isolate);
EXPECT_EQ(osr_cache->length(), kMaxLength); EXPECT_EQ(osr_cache->length(), kMaxLength);
int index = (kMaxEntries - 1) * OSROptimizedCodeCache::kEntryLength; int index = (kMaxEntries - 1) * OSROptimizedCodeCache::kEntryLength;
HeapObject object; HeapObject object;
Smi smi; Smi smi;
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kSharedOffset) osr_cache->Get(index + OSROptimizedCodeCache::kSharedOffset)
->GetHeapObject(&object); ->GetHeapObject(&object);
EXPECT_EQ(object, *shared1); EXPECT_EQ(object, *shared1);
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kCachedCodeOffset) osr_cache->Get(index + OSROptimizedCodeCache::kCachedCodeOffset)
->GetHeapObject(&object); ->GetHeapObject(&object);
EXPECT_EQ(object, *code1); EXPECT_EQ(object, *code1);
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kOsrIdOffset) osr_cache->Get(index + OSROptimizedCodeCache::kOsrIdOffset)->ToSmi(&smi);
->ToSmi(&smi);
EXPECT_EQ(smi.value(), bailout_id); EXPECT_EQ(smi.value(), bailout_id);
// Add an entry beyond max capacity. // Add an entry beyond max capacity.
...@@ -213,21 +215,20 @@ TEST_F(TestWithNativeContext, MaxCapacityCache) { ...@@ -213,21 +215,20 @@ TEST_F(TestWithNativeContext, MaxCapacityCache) {
Handle<SharedFunctionInfo> shared2(function2->shared(), isolate); Handle<SharedFunctionInfo> shared2(function2->shared(), isolate);
Handle<CodeT> code2(function2->code(), isolate); Handle<CodeT> code2(function2->code(), isolate);
bailout_id++; bailout_id++;
OSROptimizedCodeCache::Insert(isolate, native_context, shared2, code2, OSROptimizedCodeCache::AddOptimizedCode(native_context, shared2, code2,
BytecodeOffset(bailout_id)); BytecodeOffset(bailout_id));
osr_cache = osr_cache = Handle<OSROptimizedCodeCache>(
Handle<OSROptimizedCodeCache>(native_context->osr_code_cache(), isolate); native_context->GetOSROptimizedCodeCache(), isolate);
EXPECT_EQ(osr_cache->length(), kMaxLength); EXPECT_EQ(osr_cache->length(), kMaxLength);
index = 0; index = 0;
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kSharedOffset) osr_cache->Get(index + OSROptimizedCodeCache::kSharedOffset)
->GetHeapObject(&object); ->GetHeapObject(&object);
EXPECT_EQ(object, *shared2); EXPECT_EQ(object, *shared2);
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kCachedCodeOffset) osr_cache->Get(index + OSROptimizedCodeCache::kCachedCodeOffset)
->GetHeapObject(&object); ->GetHeapObject(&object);
EXPECT_EQ(object, *code2); EXPECT_EQ(object, *code2);
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kOsrIdOffset) osr_cache->Get(index + OSROptimizedCodeCache::kOsrIdOffset)->ToSmi(&smi);
->ToSmi(&smi);
EXPECT_EQ(smi.value(), bailout_id); EXPECT_EQ(smi.value(), bailout_id);
} }
...@@ -248,20 +249,18 @@ TEST_F(TestWithNativeContext, ReuseClearedEntry) { ...@@ -248,20 +249,18 @@ TEST_F(TestWithNativeContext, ReuseClearedEntry) {
int expected_length = kInitialLength * 2; int expected_length = kInitialLength * 2;
int bailout_id = 0; int bailout_id = 0;
for (bailout_id = 0; bailout_id < num_entries; bailout_id++) { for (bailout_id = 0; bailout_id < num_entries; bailout_id++) {
OSROptimizedCodeCache::Insert(isolate, native_context, shared, code, OSROptimizedCodeCache::AddOptimizedCode(native_context, shared, code,
BytecodeOffset(bailout_id)); BytecodeOffset(bailout_id));
} }
Handle<OSROptimizedCodeCache> osr_cache(native_context->osr_code_cache(), Handle<OSROptimizedCodeCache> osr_cache(
isolate); native_context->GetOSROptimizedCodeCache(), isolate);
EXPECT_EQ(osr_cache->length(), expected_length); EXPECT_EQ(osr_cache->length(), expected_length);
int clear_index1 = 0; int clear_index1 = 0;
int clear_index2 = (num_entries - 1) * OSROptimizedCodeCache::kEntryLength; int clear_index2 = (num_entries - 1) * OSROptimizedCodeCache::kEntryLength;
osr_cache->RawSetForTesting( osr_cache->Set(clear_index1 + OSROptimizedCodeCache::kSharedOffset,
clear_index1 + OSROptimizedCodeCache::kSharedOffset,
HeapObjectReference::ClearedValue(isolate)); HeapObjectReference::ClearedValue(isolate));
osr_cache->RawSetForTesting( osr_cache->Set(clear_index2 + OSROptimizedCodeCache::kCachedCodeOffset,
clear_index2 + OSROptimizedCodeCache::kCachedCodeOffset,
HeapObjectReference::ClearedValue(isolate)); HeapObjectReference::ClearedValue(isolate));
base::ScopedVector<char> source1(1024); base::ScopedVector<char> source1(1024);
...@@ -269,23 +268,22 @@ TEST_F(TestWithNativeContext, ReuseClearedEntry) { ...@@ -269,23 +268,22 @@ TEST_F(TestWithNativeContext, ReuseClearedEntry) {
Handle<JSFunction> function1 = RunJS<JSFunction>(source1.begin()); Handle<JSFunction> function1 = RunJS<JSFunction>(source1.begin());
Handle<SharedFunctionInfo> shared1(function1->shared(), isolate); Handle<SharedFunctionInfo> shared1(function1->shared(), isolate);
Handle<CodeT> code1(function1->code(), isolate); Handle<CodeT> code1(function1->code(), isolate);
OSROptimizedCodeCache::Insert(isolate, native_context, shared1, code1, OSROptimizedCodeCache::AddOptimizedCode(native_context, shared1, code1,
BytecodeOffset(bailout_id)); BytecodeOffset(bailout_id));
osr_cache = osr_cache = Handle<OSROptimizedCodeCache>(
Handle<OSROptimizedCodeCache>(native_context->osr_code_cache(), isolate); native_context->GetOSROptimizedCodeCache(), isolate);
EXPECT_EQ(osr_cache->length(), expected_length); EXPECT_EQ(osr_cache->length(), expected_length);
int index = clear_index1; int index = clear_index1;
HeapObject object; HeapObject object;
Smi smi; Smi smi;
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kSharedOffset) osr_cache->Get(index + OSROptimizedCodeCache::kSharedOffset)
->GetHeapObject(&object); ->GetHeapObject(&object);
EXPECT_EQ(object, *shared1); EXPECT_EQ(object, *shared1);
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kCachedCodeOffset) osr_cache->Get(index + OSROptimizedCodeCache::kCachedCodeOffset)
->GetHeapObject(&object); ->GetHeapObject(&object);
EXPECT_EQ(object, *code1); EXPECT_EQ(object, *code1);
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kOsrIdOffset) osr_cache->Get(index + OSROptimizedCodeCache::kOsrIdOffset)->ToSmi(&smi);
->ToSmi(&smi);
EXPECT_EQ(smi.value(), bailout_id); EXPECT_EQ(smi.value(), bailout_id);
base::ScopedVector<char> source2(1024); base::ScopedVector<char> source2(1024);
...@@ -294,21 +292,20 @@ TEST_F(TestWithNativeContext, ReuseClearedEntry) { ...@@ -294,21 +292,20 @@ TEST_F(TestWithNativeContext, ReuseClearedEntry) {
Handle<SharedFunctionInfo> shared2(function2->shared(), isolate); Handle<SharedFunctionInfo> shared2(function2->shared(), isolate);
Handle<CodeT> code2(function2->code(), isolate); Handle<CodeT> code2(function2->code(), isolate);
bailout_id++; bailout_id++;
OSROptimizedCodeCache::Insert(isolate, native_context, shared2, code2, OSROptimizedCodeCache::AddOptimizedCode(native_context, shared2, code2,
BytecodeOffset(bailout_id)); BytecodeOffset(bailout_id));
osr_cache = osr_cache = Handle<OSROptimizedCodeCache>(
Handle<OSROptimizedCodeCache>(native_context->osr_code_cache(), isolate); native_context->GetOSROptimizedCodeCache(), isolate);
EXPECT_EQ(osr_cache->length(), expected_length); EXPECT_EQ(osr_cache->length(), expected_length);
index = clear_index2; index = clear_index2;
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kSharedOffset) osr_cache->Get(index + OSROptimizedCodeCache::kSharedOffset)
->GetHeapObject(&object); ->GetHeapObject(&object);
EXPECT_EQ(object, *shared2); EXPECT_EQ(object, *shared2);
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kCachedCodeOffset) osr_cache->Get(index + OSROptimizedCodeCache::kCachedCodeOffset)
->GetHeapObject(&object); ->GetHeapObject(&object);
EXPECT_EQ(object, *code2); EXPECT_EQ(object, *code2);
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kOsrIdOffset) osr_cache->Get(index + OSROptimizedCodeCache::kOsrIdOffset)->ToSmi(&smi);
->ToSmi(&smi);
EXPECT_EQ(smi.value(), bailout_id); EXPECT_EQ(smi.value(), bailout_id);
} }
...@@ -338,45 +335,37 @@ TEST_F(TestWithNativeContext, EvictDeoptedEntriesNoCompact) { ...@@ -338,45 +335,37 @@ TEST_F(TestWithNativeContext, EvictDeoptedEntriesNoCompact) {
int bailout_id = 0; int bailout_id = 0;
for (bailout_id = 0; bailout_id < num_entries; bailout_id++) { for (bailout_id = 0; bailout_id < num_entries; bailout_id++) {
if (bailout_id == deopt_id1 || bailout_id == deopt_id2) { if (bailout_id == deopt_id1 || bailout_id == deopt_id2) {
OSROptimizedCodeCache::Insert(isolate, native_context, deopt_shared, OSROptimizedCodeCache::AddOptimizedCode(
deopt_code, BytecodeOffset(bailout_id)); native_context, deopt_shared, deopt_code, BytecodeOffset(bailout_id));
} else { } else {
OSROptimizedCodeCache::Insert(isolate, native_context, shared, code, OSROptimizedCodeCache::AddOptimizedCode(native_context, shared, code,
BytecodeOffset(bailout_id)); BytecodeOffset(bailout_id));
} }
} }
Handle<OSROptimizedCodeCache> osr_cache(native_context->osr_code_cache(), Handle<OSROptimizedCodeCache> osr_cache(
isolate); native_context->GetOSROptimizedCodeCache(), isolate);
EXPECT_EQ(osr_cache->length(), expected_length); EXPECT_EQ(osr_cache->length(), expected_length);
RunJS("%DeoptimizeFunction(f1)"); RunJS("%DeoptimizeFunction(f1)");
osr_cache = osr_cache = Handle<OSROptimizedCodeCache>(
Handle<OSROptimizedCodeCache>(native_context->osr_code_cache(), isolate); native_context->GetOSROptimizedCodeCache(), isolate);
EXPECT_EQ(osr_cache->length(), expected_length); EXPECT_EQ(osr_cache->length(), expected_length);
int index = (num_entries - 2) * OSROptimizedCodeCache::kEntryLength; int index = (num_entries - 2) * OSROptimizedCodeCache::kEntryLength;
EXPECT_TRUE( EXPECT_TRUE(osr_cache->Get(index + OSROptimizedCodeCache::kSharedOffset)
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kSharedOffset)
->IsCleared()); ->IsCleared());
EXPECT_TRUE( EXPECT_TRUE(osr_cache->Get(index + OSROptimizedCodeCache::kCachedCodeOffset)
osr_cache
->RawGetForTesting(index + OSROptimizedCodeCache::kCachedCodeOffset)
->IsCleared()); ->IsCleared());
EXPECT_TRUE( EXPECT_TRUE(
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kOsrIdOffset) osr_cache->Get(index + OSROptimizedCodeCache::kOsrIdOffset)->IsCleared());
->IsCleared());
index = (num_entries - 1) * OSROptimizedCodeCache::kEntryLength; index = (num_entries - 1) * OSROptimizedCodeCache::kEntryLength;
EXPECT_TRUE( EXPECT_TRUE(osr_cache->Get(index + OSROptimizedCodeCache::kSharedOffset)
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kSharedOffset)
->IsCleared()); ->IsCleared());
EXPECT_TRUE( EXPECT_TRUE(osr_cache->Get(index + OSROptimizedCodeCache::kCachedCodeOffset)
osr_cache
->RawGetForTesting(index + OSROptimizedCodeCache::kCachedCodeOffset)
->IsCleared()); ->IsCleared());
EXPECT_TRUE( EXPECT_TRUE(
osr_cache->RawGetForTesting(index + OSROptimizedCodeCache::kOsrIdOffset) osr_cache->Get(index + OSROptimizedCodeCache::kOsrIdOffset)->IsCleared());
->IsCleared());
} }
TEST_F(TestWithNativeContext, EvictDeoptedEntriesCompact) { TEST_F(TestWithNativeContext, EvictDeoptedEntriesCompact) {
...@@ -403,20 +392,20 @@ TEST_F(TestWithNativeContext, EvictDeoptedEntriesCompact) { ...@@ -403,20 +392,20 @@ TEST_F(TestWithNativeContext, EvictDeoptedEntriesCompact) {
int bailout_id = 0; int bailout_id = 0;
for (bailout_id = 0; bailout_id < num_entries; bailout_id++) { for (bailout_id = 0; bailout_id < num_entries; bailout_id++) {
if (bailout_id % 2 == 0) { if (bailout_id % 2 == 0) {
OSROptimizedCodeCache::Insert(isolate, native_context, deopt_shared, OSROptimizedCodeCache::AddOptimizedCode(
deopt_code, BytecodeOffset(bailout_id)); native_context, deopt_shared, deopt_code, BytecodeOffset(bailout_id));
} else { } else {
OSROptimizedCodeCache::Insert(isolate, native_context, shared, code, OSROptimizedCodeCache::AddOptimizedCode(native_context, shared, code,
BytecodeOffset(bailout_id)); BytecodeOffset(bailout_id));
} }
} }
Handle<OSROptimizedCodeCache> osr_cache(native_context->osr_code_cache(), Handle<OSROptimizedCodeCache> osr_cache(
isolate); native_context->GetOSROptimizedCodeCache(), isolate);
EXPECT_EQ(osr_cache->length(), expected_length); EXPECT_EQ(osr_cache->length(), expected_length);
RunJS("%DeoptimizeFunction(f1)"); RunJS("%DeoptimizeFunction(f1)");
osr_cache = osr_cache = Handle<OSROptimizedCodeCache>(
Handle<OSROptimizedCodeCache>(native_context->osr_code_cache(), isolate); native_context->GetOSROptimizedCodeCache(), isolate);
EXPECT_EQ(osr_cache->length(), kInitialLength); EXPECT_EQ(osr_cache->length(), kInitialLength);
} }
......
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