blob: bbf8f2dd8c0165dfdaf2105580b858449a3f2497 [file] [log] [blame]
Orion Hodson119733d2019-01-30 15:14:41 +00001/*
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 Geoffray4f6bb442021-06-02 18:05:51 +010021#include <stdbool.h>
Orion Hodson119733d2019-01-30 15:14:41 +000022
Orion Hodsond3374a02019-05-02 10:56:33 +010023#include <android-base/logging.h>
Orion Hodson119733d2019-01-30 15:14:41 +000024#include <android-base/macros.h> // For ATTRIBUTE_UNUSED
25
26#include "palette_system.h"
27
Orion Hodson119733d2019-01-30 15:14:41 +000028// Cached thread priority for testing. No thread priorities are ever affected.
29static std::mutex g_tid_priority_map_mutex;
30static std::map<int32_t, int32_t> g_tid_priority_map;
31
Orion Hodsonc5323fe2021-02-04 21:20:30 +000032palette_status_t PaletteSchedSetPriority(int32_t tid, int32_t priority) {
Orion Hodson119733d2019-01-30 15:14:41 +000033 if (priority < art::palette::kMinManagedThreadPriority ||
34 priority > art::palette::kMaxManagedThreadPriority) {
Orion Hodsonc5323fe2021-02-04 21:20:30 +000035 return PALETTE_STATUS_INVALID_ARGUMENT;
Orion Hodson119733d2019-01-30 15:14:41 +000036 }
37 std::lock_guard guard(g_tid_priority_map_mutex);
38 g_tid_priority_map[tid] = priority;
Orion Hodsonc5323fe2021-02-04 21:20:30 +000039 return PALETTE_STATUS_OK;
Orion Hodson119733d2019-01-30 15:14:41 +000040}
41
Orion Hodsonc5323fe2021-02-04 21:20:30 +000042palette_status_t PaletteSchedGetPriority(int32_t tid,
Nicolas Geoffray4f6bb442021-06-02 18:05:51 +010043 /*out*/int32_t* priority) {
Orion Hodson119733d2019-01-30 15:14:41 +000044 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 Hodsonc5323fe2021-02-04 21:20:30 +000049 return PALETTE_STATUS_OK;
Orion Hodson119733d2019-01-30 15:14:41 +000050}
51
Orion Hodsonc5323fe2021-02-04 21:20:30 +000052palette_status_t PaletteWriteCrashThreadStacks(/*in*/ const char* stacks, size_t stacks_len) {
Orion Hodsond3374a02019-05-02 10:56:33 +010053 LOG(INFO) << std::string_view(stacks, stacks_len);
Orion Hodsonc5323fe2021-02-04 21:20:30 +000054 return PALETTE_STATUS_OK;
Martin Stjernholm2e2c45e2019-04-09 20:40:59 +010055}
56
Nicolas Geoffray4f6bb442021-06-02 18:05:51 +010057palette_status_t PaletteTraceEnabled(/*out*/bool* enabled) {
58 *enabled = false;
Orion Hodsonc5323fe2021-02-04 21:20:30 +000059 return PALETTE_STATUS_OK;
Orion Hodson119733d2019-01-30 15:14:41 +000060}
61
Orion Hodsonc5323fe2021-02-04 21:20:30 +000062palette_status_t PaletteTraceBegin(const char* name ATTRIBUTE_UNUSED) {
63 return PALETTE_STATUS_OK;
Orion Hodson119733d2019-01-30 15:14:41 +000064}
65
Orion Hodsonc5323fe2021-02-04 21:20:30 +000066palette_status_t PaletteTraceEnd() {
67 return PALETTE_STATUS_OK;
Orion Hodson119733d2019-01-30 15:14:41 +000068}
69
Orion Hodsonc5323fe2021-02-04 21:20:30 +000070palette_status_t PaletteTraceIntegerValue(const char* name ATTRIBUTE_UNUSED,
Nicolas Geoffray4f6bb442021-06-02 18:05:51 +010071 int32_t value ATTRIBUTE_UNUSED) {
Orion Hodsonc5323fe2021-02-04 21:20:30 +000072 return PALETTE_STATUS_OK;
Orion Hodson119733d2019-01-30 15:14:41 +000073}
Nicolas Geoffray2411f492019-06-14 08:54:46 +010074
Orion Hodsonc5323fe2021-02-04 21:20:30 +000075palette_status_t PaletteAshmemCreateRegion(const char* name ATTRIBUTE_UNUSED,
Nicolas Geoffray4f6bb442021-06-02 18:05:51 +010076 size_t size ATTRIBUTE_UNUSED,
77 int* fd) {
Nicolas Geoffray2411f492019-06-14 08:54:46 +010078 *fd = -1;
Orion Hodsonc5323fe2021-02-04 21:20:30 +000079 return PALETTE_STATUS_NOT_SUPPORTED;
Nicolas Geoffray2411f492019-06-14 08:54:46 +010080}
81
Orion Hodsonc5323fe2021-02-04 21:20:30 +000082palette_status_t PaletteAshmemSetProtRegion(int fd ATTRIBUTE_UNUSED,
Nicolas Geoffray4f6bb442021-06-02 18:05:51 +010083 int prot ATTRIBUTE_UNUSED) {
Orion Hodsonc5323fe2021-02-04 21:20:30 +000084 return PALETTE_STATUS_NOT_SUPPORTED;
Nicolas Geoffray3d22dbb2020-08-03 10:46:39 +010085}
Orion Hodsonc4986f52021-01-28 16:57:33 +000086
87palette_status_t PaletteCreateOdrefreshStagingDirectory(const char** staging_dir) {
88 *staging_dir = nullptr;
89 return PALETTE_STATUS_NOT_SUPPORTED;
90}
Nicolas Geoffray4f6bb442021-06-02 18:05:51 +010091
92palette_status_t PaletteShouldReportDex2oatCompilation(bool* value) {
93 *value = false;
94 return PALETTE_STATUS_OK;
95}
96
97palette_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
104palette_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
111palette_status_t PaletteNotifyDexFileLoaded(const char* path ATTRIBUTE_UNUSED) {
112 return PALETTE_STATUS_OK;
113}
114
115palette_status_t PaletteNotifyOatFileLoaded(const char* path ATTRIBUTE_UNUSED) {
116 return PALETTE_STATUS_OK;
117}
118
119palette_status_t PaletteShouldReportJniInvocations(bool* value) {
120 *value = false;
121 return PALETTE_STATUS_OK;
122}
123
124palette_status_t PaletteNotifyBeginJniInvocation(JNIEnv* env ATTRIBUTE_UNUSED) {
125 return PALETTE_STATUS_OK;
126}
127
128palette_status_t PaletteNotifyEndJniInvocation(JNIEnv* env ATTRIBUTE_UNUSED) {
129 return PALETTE_STATUS_OK;
130}
Nicolas Geoffraye2613562021-08-18 22:46:32 +0100131
132palette_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}