Logan Chien | 7e6e33d | 2012-01-31 09:22:09 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
Elliott Hughes | 13b835a | 2012-03-13 19:45:22 -0700 | [diff] [blame] | 17 | #include "utils_llvm.h" |
| 18 | |
Shih-wei Liao | 5b8b1ed | 2012-02-23 23:48:21 -0800 | [diff] [blame] | 19 | #include <fcntl.h> |
| 20 | #include <string.h> |
| 21 | #include <sys/mman.h> |
Elliott Hughes | 13b835a | 2012-03-13 19:45:22 -0700 | [diff] [blame] | 22 | #include <sys/stat.h> |
| 23 | #include <sys/types.h> |
| 24 | #include <unistd.h> |
Shih-wei Liao | 5b8b1ed | 2012-02-23 23:48:21 -0800 | [diff] [blame] | 25 | |
Elliott Hughes | 13b835a | 2012-03-13 19:45:22 -0700 | [diff] [blame] | 26 | #include "android/librsloader.h" |
Logan Chien | 7e6e33d | 2012-01-31 09:22:09 +0800 | [diff] [blame] | 27 | #include "class_loader.h" |
| 28 | #include "object.h" |
| 29 | #include "object_utils.h" |
Shih-wei Liao | a8a9c34 | 2012-03-03 22:35:16 -0800 | [diff] [blame] | 30 | #include "runtime_support_llvm.h" |
| 31 | |
Logan Chien | 7e6e33d | 2012-01-31 09:22:09 +0800 | [diff] [blame] | 32 | namespace art { |
| 33 | |
| 34 | std::string MangleForLLVM(const std::string& s) { |
| 35 | std::string result; |
| 36 | size_t char_count = CountModifiedUtf8Chars(s.c_str()); |
| 37 | const char* cp = &s[0]; |
| 38 | for (size_t i = 0; i < char_count; ++i) { |
| 39 | uint16_t ch = GetUtf16FromUtf8(&cp); |
| 40 | if (ch == '$' || ch == '<' || ch == '>' || ch > 127) { |
| 41 | StringAppendF(&result, "_0%04x", ch); |
| 42 | } else { |
| 43 | switch (ch) { |
| 44 | case '_': |
| 45 | result += "_1"; |
| 46 | break; |
| 47 | case ';': |
| 48 | result += "_2"; |
| 49 | break; |
| 50 | case '[': |
| 51 | result += "_3"; |
| 52 | break; |
TDYa127 | f058c0f | 2012-04-01 07:43:08 -0700 | [diff] [blame] | 53 | case ')': |
| 54 | result += "_4"; |
| 55 | break; |
Logan Chien | 7e6e33d | 2012-01-31 09:22:09 +0800 | [diff] [blame] | 56 | case '/': |
| 57 | result += "_"; |
| 58 | break; |
| 59 | default: |
| 60 | result.push_back(ch); |
| 61 | break; |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | return result; |
| 66 | } |
| 67 | |
| 68 | std::string LLVMShortName(const Method* m) { |
| 69 | MethodHelper mh(m); |
| 70 | std::string class_name(mh.GetDeclaringClassDescriptor()); |
| 71 | // Remove the leading 'L' and trailing ';'... |
| 72 | CHECK_EQ(class_name[0], 'L') << class_name; |
| 73 | CHECK_EQ(class_name[class_name.size() - 1], ';') << class_name; |
| 74 | class_name.erase(0, 1); |
| 75 | class_name.erase(class_name.size() - 1, 1); |
| 76 | |
| 77 | std::string method_name(mh.GetName()); |
| 78 | |
| 79 | std::string short_name; |
| 80 | short_name += "Art_"; |
| 81 | short_name += MangleForLLVM(class_name); |
| 82 | short_name += "_"; |
| 83 | short_name += MangleForLLVM(method_name); |
| 84 | return short_name; |
| 85 | } |
| 86 | |
| 87 | std::string LLVMLongName(const Method* m) { |
| 88 | std::string long_name; |
| 89 | long_name += LLVMShortName(m); |
| 90 | long_name += "__"; |
| 91 | |
| 92 | std::string signature(MethodHelper(m).GetSignature()); |
| 93 | signature.erase(0, 1); |
Logan Chien | 7e6e33d | 2012-01-31 09:22:09 +0800 | [diff] [blame] | 94 | |
| 95 | long_name += MangleForLLVM(signature); |
| 96 | |
| 97 | return long_name; |
| 98 | } |
| 99 | |
Shih-wei Liao | 5b8b1ed | 2012-02-23 23:48:21 -0800 | [diff] [blame] | 100 | std::string LLVMStubName(const Method* m) { |
| 101 | MethodHelper mh(m); |
| 102 | std::string stub_name; |
| 103 | if (m->IsStatic()) { |
| 104 | stub_name += "ArtSUpcall_"; |
| 105 | } else { |
| 106 | stub_name += "ArtUpcall_"; |
| 107 | } |
| 108 | stub_name += mh.GetShorty(); |
| 109 | |
| 110 | return stub_name; |
| 111 | } |
| 112 | |
Logan Chien | 7e6e33d | 2012-01-31 09:22:09 +0800 | [diff] [blame] | 113 | } // namespace art |