• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
21 #include <stdbool.h>
22 
23 #include <android-base/logging.h>
24 #include <android-base/macros.h>  // For ATTRIBUTE_UNUSED
25 
26 #include "palette_system.h"
27 
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 
PaletteSchedSetPriority(int32_t tid,int32_t priority)32 palette_status_t PaletteSchedSetPriority(int32_t tid, int32_t priority) {
33     if (priority < art::palette::kMinManagedThreadPriority ||
34         priority > art::palette::kMaxManagedThreadPriority) {
35         return PALETTE_STATUS_INVALID_ARGUMENT;
36     }
37     std::lock_guard guard(g_tid_priority_map_mutex);
38     g_tid_priority_map[tid] = priority;
39     return PALETTE_STATUS_OK;
40 }
41 
PaletteSchedGetPriority(int32_t tid,int32_t * priority)42 palette_status_t PaletteSchedGetPriority(int32_t tid,
43                                            /*out*/ int32_t* priority) {
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];
49     return PALETTE_STATUS_OK;
50 }
51 
PaletteWriteCrashThreadStacks(const char * stacks,size_t stacks_len)52 palette_status_t PaletteWriteCrashThreadStacks(/*in*/ const char* stacks, size_t stacks_len) {
53     LOG(INFO) << std::string_view(stacks, stacks_len);
54     return PALETTE_STATUS_OK;
55 }
56 
PaletteTraceEnabled(bool * enabled)57 palette_status_t PaletteTraceEnabled(/*out*/ bool* enabled) {
58     *enabled = false;
59     return PALETTE_STATUS_OK;
60 }
61 
PaletteTraceBegin(const char * name ATTRIBUTE_UNUSED)62 palette_status_t PaletteTraceBegin(const char* name ATTRIBUTE_UNUSED) {
63     return PALETTE_STATUS_OK;
64 }
65 
PaletteTraceEnd()66 palette_status_t PaletteTraceEnd() {
67     return PALETTE_STATUS_OK;
68 }
69 
PaletteTraceIntegerValue(const char * name ATTRIBUTE_UNUSED,int32_t value ATTRIBUTE_UNUSED)70 palette_status_t PaletteTraceIntegerValue(const char* name ATTRIBUTE_UNUSED,
71                                           int32_t value ATTRIBUTE_UNUSED) {
72     return PALETTE_STATUS_OK;
73 }
74 
PaletteAshmemCreateRegion(const char * name ATTRIBUTE_UNUSED,size_t size ATTRIBUTE_UNUSED,int * fd)75 palette_status_t PaletteAshmemCreateRegion(const char* name ATTRIBUTE_UNUSED,
76                                            size_t size ATTRIBUTE_UNUSED, int* fd) {
77     *fd = -1;
78     return PALETTE_STATUS_NOT_SUPPORTED;
79 }
80 
PaletteAshmemSetProtRegion(int fd ATTRIBUTE_UNUSED,int prot ATTRIBUTE_UNUSED)81 palette_status_t PaletteAshmemSetProtRegion(int fd ATTRIBUTE_UNUSED, int prot ATTRIBUTE_UNUSED) {
82     return PALETTE_STATUS_NOT_SUPPORTED;
83 }
84 
PaletteCreateOdrefreshStagingDirectory(const char ** staging_dir)85 palette_status_t PaletteCreateOdrefreshStagingDirectory(const char** staging_dir) {
86     *staging_dir = nullptr;
87     return PALETTE_STATUS_NOT_SUPPORTED;
88 }
89 
PaletteShouldReportDex2oatCompilation(bool * value)90 palette_status_t PaletteShouldReportDex2oatCompilation(bool* value) {
91   *value = false;
92   return PALETTE_STATUS_OK;
93 }
94 
PaletteNotifyStartDex2oatCompilation(int source_fd ATTRIBUTE_UNUSED,int art_fd ATTRIBUTE_UNUSED,int oat_fd ATTRIBUTE_UNUSED,int vdex_fd ATTRIBUTE_UNUSED)95 palette_status_t PaletteNotifyStartDex2oatCompilation(int source_fd ATTRIBUTE_UNUSED,
96                                                       int art_fd ATTRIBUTE_UNUSED,
97                                                       int oat_fd ATTRIBUTE_UNUSED,
98                                                       int vdex_fd ATTRIBUTE_UNUSED) {
99   return PALETTE_STATUS_OK;
100 }
101 
PaletteNotifyEndDex2oatCompilation(int source_fd ATTRIBUTE_UNUSED,int art_fd ATTRIBUTE_UNUSED,int oat_fd ATTRIBUTE_UNUSED,int vdex_fd ATTRIBUTE_UNUSED)102 palette_status_t PaletteNotifyEndDex2oatCompilation(int source_fd ATTRIBUTE_UNUSED,
103                                                     int art_fd ATTRIBUTE_UNUSED,
104                                                     int oat_fd ATTRIBUTE_UNUSED,
105                                                     int vdex_fd ATTRIBUTE_UNUSED) {
106   return PALETTE_STATUS_OK;
107 }
108 
PaletteNotifyDexFileLoaded(const char * path ATTRIBUTE_UNUSED)109 palette_status_t PaletteNotifyDexFileLoaded(const char* path ATTRIBUTE_UNUSED) {
110   return PALETTE_STATUS_OK;
111 }
112 
PaletteNotifyOatFileLoaded(const char * path ATTRIBUTE_UNUSED)113 palette_status_t PaletteNotifyOatFileLoaded(const char* path ATTRIBUTE_UNUSED) {
114   return PALETTE_STATUS_OK;
115 }
116 
PaletteShouldReportJniInvocations(bool * value)117 palette_status_t PaletteShouldReportJniInvocations(bool* value) {
118   *value = false;
119   return PALETTE_STATUS_OK;
120 }
121 
PaletteNotifyBeginJniInvocation(JNIEnv * env ATTRIBUTE_UNUSED)122 palette_status_t PaletteNotifyBeginJniInvocation(JNIEnv* env ATTRIBUTE_UNUSED) {
123   return PALETTE_STATUS_OK;
124 }
125 
PaletteNotifyEndJniInvocation(JNIEnv * env ATTRIBUTE_UNUSED)126 palette_status_t PaletteNotifyEndJniInvocation(JNIEnv* env ATTRIBUTE_UNUSED) {
127   return PALETTE_STATUS_OK;
128 }
129