Orion Hodson | 119733d | 2019-01-30 15:14:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | #include "palette/palette.h" |
| 18 | |
| 19 | #include <map> |
| 20 | #include <mutex> |
Nicolas Geoffray | 4f6bb44 | 2021-06-02 18:05:51 +0100 | [diff] [blame] | 21 | #include <stdbool.h> |
Orion Hodson | 119733d | 2019-01-30 15:14:41 +0000 | [diff] [blame] | 22 | |
Orion Hodson | d3374a0 | 2019-05-02 10:56:33 +0100 | [diff] [blame] | 23 | #include <android-base/logging.h> |
Orion Hodson | 119733d | 2019-01-30 15:14:41 +0000 | [diff] [blame] | 24 | #include <android-base/macros.h> // For ATTRIBUTE_UNUSED |
| 25 | |
| 26 | #include "palette_system.h" |
| 27 | |
Orion Hodson | 119733d | 2019-01-30 15:14:41 +0000 | [diff] [blame] | 28 | // Cached thread priority for testing. No thread priorities are ever affected. |
| 29 | static std::mutex g_tid_priority_map_mutex; |
| 30 | static std::map<int32_t, int32_t> g_tid_priority_map; |
| 31 | |
Orion Hodson | c5323fe | 2021-02-04 21:20:30 +0000 | [diff] [blame] | 32 | palette_status_t PaletteSchedSetPriority(int32_t tid, int32_t priority) { |
Orion Hodson | 119733d | 2019-01-30 15:14:41 +0000 | [diff] [blame] | 33 | if (priority < art::palette::kMinManagedThreadPriority || |
| 34 | priority > art::palette::kMaxManagedThreadPriority) { |
Orion Hodson | c5323fe | 2021-02-04 21:20:30 +0000 | [diff] [blame] | 35 | return PALETTE_STATUS_INVALID_ARGUMENT; |
Orion Hodson | 119733d | 2019-01-30 15:14:41 +0000 | [diff] [blame] | 36 | } |
| 37 | std::lock_guard guard(g_tid_priority_map_mutex); |
| 38 | g_tid_priority_map[tid] = priority; |
Orion Hodson | c5323fe | 2021-02-04 21:20:30 +0000 | [diff] [blame] | 39 | return PALETTE_STATUS_OK; |
Orion Hodson | 119733d | 2019-01-30 15:14:41 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Orion Hodson | c5323fe | 2021-02-04 21:20:30 +0000 | [diff] [blame] | 42 | palette_status_t PaletteSchedGetPriority(int32_t tid, |
Nicolas Geoffray | 4f6bb44 | 2021-06-02 18:05:51 +0100 | [diff] [blame] | 43 | /*out*/int32_t* priority) { |
Orion Hodson | 119733d | 2019-01-30 15:14:41 +0000 | [diff] [blame] | 44 | std::lock_guard guard(g_tid_priority_map_mutex); |
| 45 | if (g_tid_priority_map.find(tid) == g_tid_priority_map.end()) { |
| 46 | g_tid_priority_map[tid] = art::palette::kNormalManagedThreadPriority; |
| 47 | } |
| 48 | *priority = g_tid_priority_map[tid]; |
Orion Hodson | c5323fe | 2021-02-04 21:20:30 +0000 | [diff] [blame] | 49 | return PALETTE_STATUS_OK; |
Orion Hodson | 119733d | 2019-01-30 15:14:41 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Orion Hodson | c5323fe | 2021-02-04 21:20:30 +0000 | [diff] [blame] | 52 | palette_status_t PaletteWriteCrashThreadStacks(/*in*/ const char* stacks, size_t stacks_len) { |
Orion Hodson | d3374a0 | 2019-05-02 10:56:33 +0100 | [diff] [blame] | 53 | LOG(INFO) << std::string_view(stacks, stacks_len); |
Orion Hodson | c5323fe | 2021-02-04 21:20:30 +0000 | [diff] [blame] | 54 | return PALETTE_STATUS_OK; |
Martin Stjernholm | 2e2c45e | 2019-04-09 20:40:59 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Nicolas Geoffray | 4f6bb44 | 2021-06-02 18:05:51 +0100 | [diff] [blame] | 57 | palette_status_t PaletteTraceEnabled(/*out*/bool* enabled) { |
| 58 | *enabled = false; |
Orion Hodson | c5323fe | 2021-02-04 21:20:30 +0000 | [diff] [blame] | 59 | return PALETTE_STATUS_OK; |
Orion Hodson | 119733d | 2019-01-30 15:14:41 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Orion Hodson | c5323fe | 2021-02-04 21:20:30 +0000 | [diff] [blame] | 62 | palette_status_t PaletteTraceBegin(const char* name ATTRIBUTE_UNUSED) { |
| 63 | return PALETTE_STATUS_OK; |
Orion Hodson | 119733d | 2019-01-30 15:14:41 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Orion Hodson | c5323fe | 2021-02-04 21:20:30 +0000 | [diff] [blame] | 66 | palette_status_t PaletteTraceEnd() { |
| 67 | return PALETTE_STATUS_OK; |
Orion Hodson | 119733d | 2019-01-30 15:14:41 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Orion Hodson | c5323fe | 2021-02-04 21:20:30 +0000 | [diff] [blame] | 70 | palette_status_t PaletteTraceIntegerValue(const char* name ATTRIBUTE_UNUSED, |
Nicolas Geoffray | 4f6bb44 | 2021-06-02 18:05:51 +0100 | [diff] [blame] | 71 | int32_t value ATTRIBUTE_UNUSED) { |
Orion Hodson | c5323fe | 2021-02-04 21:20:30 +0000 | [diff] [blame] | 72 | return PALETTE_STATUS_OK; |
Orion Hodson | 119733d | 2019-01-30 15:14:41 +0000 | [diff] [blame] | 73 | } |
Nicolas Geoffray | 2411f49 | 2019-06-14 08:54:46 +0100 | [diff] [blame] | 74 | |
Orion Hodson | c5323fe | 2021-02-04 21:20:30 +0000 | [diff] [blame] | 75 | palette_status_t PaletteAshmemCreateRegion(const char* name ATTRIBUTE_UNUSED, |
Nicolas Geoffray | 4f6bb44 | 2021-06-02 18:05:51 +0100 | [diff] [blame] | 76 | size_t size ATTRIBUTE_UNUSED, |
| 77 | int* fd) { |
Nicolas Geoffray | 2411f49 | 2019-06-14 08:54:46 +0100 | [diff] [blame] | 78 | *fd = -1; |
Orion Hodson | c5323fe | 2021-02-04 21:20:30 +0000 | [diff] [blame] | 79 | return PALETTE_STATUS_NOT_SUPPORTED; |
Nicolas Geoffray | 2411f49 | 2019-06-14 08:54:46 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Orion Hodson | c5323fe | 2021-02-04 21:20:30 +0000 | [diff] [blame] | 82 | palette_status_t PaletteAshmemSetProtRegion(int fd ATTRIBUTE_UNUSED, |
Nicolas Geoffray | 4f6bb44 | 2021-06-02 18:05:51 +0100 | [diff] [blame] | 83 | int prot ATTRIBUTE_UNUSED) { |
Orion Hodson | c5323fe | 2021-02-04 21:20:30 +0000 | [diff] [blame] | 84 | return PALETTE_STATUS_NOT_SUPPORTED; |
Nicolas Geoffray | 3d22dbb | 2020-08-03 10:46:39 +0100 | [diff] [blame] | 85 | } |
Orion Hodson | c4986f5 | 2021-01-28 16:57:33 +0000 | [diff] [blame] | 86 | |
| 87 | palette_status_t PaletteCreateOdrefreshStagingDirectory(const char** staging_dir) { |
| 88 | *staging_dir = nullptr; |
| 89 | return PALETTE_STATUS_NOT_SUPPORTED; |
| 90 | } |
Nicolas Geoffray | 4f6bb44 | 2021-06-02 18:05:51 +0100 | [diff] [blame] | 91 | |
| 92 | palette_status_t PaletteShouldReportDex2oatCompilation(bool* value) { |
| 93 | *value = false; |
| 94 | return PALETTE_STATUS_OK; |
| 95 | } |
| 96 | |
| 97 | palette_status_t PaletteNotifyStartDex2oatCompilation(int source_fd ATTRIBUTE_UNUSED, |
| 98 | int art_fd ATTRIBUTE_UNUSED, |
| 99 | int oat_fd ATTRIBUTE_UNUSED, |
| 100 | int vdex_fd ATTRIBUTE_UNUSED) { |
| 101 | return PALETTE_STATUS_OK; |
| 102 | } |
| 103 | |
| 104 | palette_status_t PaletteNotifyEndDex2oatCompilation(int source_fd ATTRIBUTE_UNUSED, |
| 105 | int art_fd ATTRIBUTE_UNUSED, |
| 106 | int oat_fd ATTRIBUTE_UNUSED, |
| 107 | int vdex_fd ATTRIBUTE_UNUSED) { |
| 108 | return PALETTE_STATUS_OK; |
| 109 | } |
| 110 | |
| 111 | palette_status_t PaletteNotifyDexFileLoaded(const char* path ATTRIBUTE_UNUSED) { |
| 112 | return PALETTE_STATUS_OK; |
| 113 | } |
| 114 | |
| 115 | palette_status_t PaletteNotifyOatFileLoaded(const char* path ATTRIBUTE_UNUSED) { |
| 116 | return PALETTE_STATUS_OK; |
| 117 | } |
| 118 | |
| 119 | palette_status_t PaletteShouldReportJniInvocations(bool* value) { |
| 120 | *value = false; |
| 121 | return PALETTE_STATUS_OK; |
| 122 | } |
| 123 | |
| 124 | palette_status_t PaletteNotifyBeginJniInvocation(JNIEnv* env ATTRIBUTE_UNUSED) { |
| 125 | return PALETTE_STATUS_OK; |
| 126 | } |
| 127 | |
| 128 | palette_status_t PaletteNotifyEndJniInvocation(JNIEnv* env ATTRIBUTE_UNUSED) { |
| 129 | return PALETTE_STATUS_OK; |
| 130 | } |
Nicolas Geoffray | e261356 | 2021-08-18 22:46:32 +0100 | [diff] [blame] | 131 | |
| 132 | palette_status_t PaletteReportLockContention(JNIEnv* env ATTRIBUTE_UNUSED, |
| 133 | int32_t wait_ms ATTRIBUTE_UNUSED, |
| 134 | const char* filename ATTRIBUTE_UNUSED, |
| 135 | int32_t line_number ATTRIBUTE_UNUSED, |
| 136 | const char* method_name ATTRIBUTE_UNUSED, |
| 137 | const char* owner_filename ATTRIBUTE_UNUSED, |
| 138 | int32_t owner_line_number ATTRIBUTE_UNUSED, |
| 139 | const char* owner_method_name ATTRIBUTE_UNUSED, |
| 140 | const char* proc_name ATTRIBUTE_UNUSED, |
| 141 | const char* thread_name ATTRIBUTE_UNUSED) { |
| 142 | return PALETTE_STATUS_OK; |
| 143 | } |