| 1 | // Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | #include "vm/instructions.h" |
| 6 | |
| 7 | #include "vm/object.h" |
| 8 | #if defined(DART_PRECOMPILER) |
| 9 | #include "vm/compiler/aot/precompiler.h" |
| 10 | #endif |
| 11 | |
| 12 | namespace dart { |
| 13 | |
| 14 | bool ObjectAtPoolIndex(const Code& code, intptr_t index, Object* obj) { |
| 15 | #if defined(DART_PRECOMPILER) |
| 16 | if (FLAG_precompiled_mode) { |
| 17 | Precompiler* precompiler = Precompiler::Instance(); |
| 18 | if (precompiler != nullptr) { |
| 19 | compiler::ObjectPoolBuilder* pool = |
| 20 | precompiler->global_object_pool_builder(); |
| 21 | if (index < pool->CurrentLength()) { |
| 22 | compiler::ObjectPoolBuilderEntry& entry = pool->EntryAt(index); |
| 23 | if (entry.type() == compiler::ObjectPoolBuilderEntry::kTaggedObject) { |
| 24 | *obj = entry.obj_->ptr(); |
| 25 | return true; |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | return false; |
| 30 | } |
| 31 | #endif |
| 32 | const ObjectPool& pool = ObjectPool::Handle(ptr: code.GetObjectPool()); |
| 33 | if (!pool.IsNull() && (index < pool.Length()) && |
| 34 | (pool.TypeAt(index) == ObjectPool::EntryType::kTaggedObject)) { |
| 35 | *obj = pool.ObjectAt(index); |
| 36 | return true; |
| 37 | } |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | } // namespace dart |
| 42 | |