Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_RUNTIME_ART_CODE_H_ |
| 18 | #define ART_RUNTIME_ART_CODE_H_ |
| 19 | |
| 20 | #include "base/mutex.h" |
| 21 | #include "offsets.h" |
| 22 | #include "quick/quick_method_frame_info.h" |
| 23 | #include "stack_map.h" |
| 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | class ArtMethod; |
| 28 | |
| 29 | class ArtCode FINAL { |
| 30 | public: |
| 31 | explicit ArtCode(ArtMethod** method) : method_(*method) {} |
| 32 | explicit ArtCode(ArtMethod* method) : method_(method) {} |
| 33 | ArtCode() : method_(nullptr) {} |
| 34 | |
| 35 | // Converts a dex PC to a native PC. |
| 36 | uintptr_t ToNativeQuickPc(const uint32_t dex_pc, |
| 37 | bool is_for_catch_handler, |
| 38 | bool abort_on_failure = true) |
| 39 | SHARED_REQUIRES(Locks::mutator_lock_); |
| 40 | |
| 41 | bool IsOptimized(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_); |
| 42 | |
| 43 | CodeInfo GetOptimizedCodeInfo() SHARED_REQUIRES(Locks::mutator_lock_); |
| 44 | |
| 45 | uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_); |
| 46 | |
| 47 | // Converts a native PC to a dex PC. |
| 48 | uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true) |
| 49 | SHARED_REQUIRES(Locks::mutator_lock_); |
| 50 | |
| 51 | // Callers should wrap the uint8_t* in a GcMap instance for convenient access. |
| 52 | const uint8_t* GetNativeGcMap(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_); |
| 53 | |
| 54 | const uint8_t* GetVmapTable(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_); |
| 55 | |
| 56 | const uint8_t* GetMappingTable(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_); |
| 57 | |
| 58 | QuickMethodFrameInfo GetQuickFrameInfo() SHARED_REQUIRES(Locks::mutator_lock_); |
| 59 | |
| 60 | FrameOffset GetReturnPcOffset() SHARED_REQUIRES(Locks::mutator_lock_) { |
| 61 | return FrameOffset(GetFrameSizeInBytes() - sizeof(void*)); |
| 62 | } |
| 63 | |
| 64 | template <bool kCheckFrameSize = true> |
| 65 | uint32_t GetFrameSizeInBytes() SHARED_REQUIRES(Locks::mutator_lock_) { |
| 66 | uint32_t result = GetQuickFrameInfo().FrameSizeInBytes(); |
| 67 | if (kCheckFrameSize) { |
| 68 | DCHECK_LE(static_cast<size_t>(kStackAlignment), result); |
| 69 | } |
| 70 | return result; |
| 71 | } |
| 72 | |
| 73 | const void* GetQuickOatEntryPoint(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_); |
| 74 | |
| 75 | void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_); |
| 76 | |
| 77 | bool PcIsWithinQuickCode(uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_); |
| 78 | |
| 79 | FrameOffset GetHandleScopeOffset() SHARED_REQUIRES(Locks::mutator_lock_) { |
| 80 | constexpr size_t handle_scope_offset = sizeof(ArtMethod*); |
| 81 | DCHECK_LT(handle_scope_offset, GetFrameSizeInBytes()); |
| 82 | return FrameOffset(handle_scope_offset); |
| 83 | } |
| 84 | |
| 85 | ArtMethod* GetMethod() const { return method_; } |
| 86 | |
| 87 | private: |
| 88 | ArtMethod* method_; |
| 89 | }; |
| 90 | |
| 91 | } // namespace art |
| 92 | |
| 93 | #endif // ART_RUNTIME_ART_CODE_H_ |