Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [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 | |
| 17 | #ifndef ART_SRC_VERIFIER_REG_TYPE_CACHE_H_ |
| 18 | #define ART_SRC_VERIFIER_REG_TYPE_CACHE_H_ |
| 19 | |
| 20 | #include "macros.h" |
| 21 | #include "reg_type.h" |
| 22 | #include "stl_util.h" |
| 23 | |
| 24 | namespace art { |
| 25 | namespace verifier { |
| 26 | |
| 27 | class RegTypeCache { |
| 28 | public: |
| 29 | explicit RegTypeCache() : entries_(RegType::kRegTypeLastFixedLocation + 1) { |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 30 | Undefined(); // ensure Undefined is initialized |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 31 | } |
| 32 | ~RegTypeCache() { |
| 33 | STLDeleteElements(&entries_); |
| 34 | } |
| 35 | |
| 36 | const RegType& GetFromId(uint16_t id) { |
| 37 | DCHECK_LT(id, entries_.size()); |
| 38 | RegType* result = entries_[id]; |
| 39 | DCHECK(result != NULL); |
| 40 | return *result; |
| 41 | } |
| 42 | |
| 43 | const RegType& From(RegType::Type type, const ClassLoader* loader, const char* descriptor); |
| 44 | const RegType& FromClass(Class* klass); |
| 45 | const RegType& FromCat1Const(int32_t value); |
| 46 | const RegType& FromDescriptor(const ClassLoader* loader, const char* descriptor); |
| 47 | const RegType& FromType(RegType::Type); |
| 48 | |
| 49 | const RegType& Boolean() { return FromType(RegType::kRegTypeBoolean); } |
| 50 | const RegType& Byte() { return FromType(RegType::kRegTypeByte); } |
| 51 | const RegType& Char() { return FromType(RegType::kRegTypeChar); } |
| 52 | const RegType& Short() { return FromType(RegType::kRegTypeShort); } |
| 53 | const RegType& Integer() { return FromType(RegType::kRegTypeInteger); } |
| 54 | const RegType& Float() { return FromType(RegType::kRegTypeFloat); } |
| 55 | const RegType& Long() { return FromType(RegType::kRegTypeLongLo); } |
| 56 | const RegType& Double() { return FromType(RegType::kRegTypeDoubleLo); } |
| 57 | |
| 58 | const RegType& JavaLangClass() { return From(RegType::kRegTypeReference, NULL, "Ljava/lang/Class;"); } |
| 59 | const RegType& JavaLangObject() { return From(RegType::kRegTypeReference, NULL, "Ljava/lang/Object;"); } |
| 60 | const RegType& JavaLangString() { return From(RegType::kRegTypeReference, NULL, "Ljava/lang/String;"); } |
| 61 | const RegType& JavaLangThrowable() { return From(RegType::kRegTypeReference, NULL, "Ljava/lang/Throwable;"); } |
| 62 | |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 63 | const RegType& Undefined() { return FromType(RegType::kRegTypeUndefined); } |
| 64 | const RegType& Conflict() { return FromType(RegType::kRegTypeConflict); } |
| 65 | const RegType& ConstLo() { return FromType(RegType::kRegTypeConstLo); } |
| 66 | const RegType& Zero() { return FromCat1Const(0); } |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 67 | |
| 68 | const RegType& Uninitialized(const RegType& type, uint32_t allocation_pc); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 69 | // Create an uninitialized 'this' argument for the given type. |
| 70 | const RegType& UninitializedThisArgument(const RegType& type); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 71 | const RegType& FromUninitialized(const RegType& uninit_type); |
| 72 | |
| 73 | // Representatives of various constant types. When merging constants we can't infer a type, |
| 74 | // (an int may later be used as a float) so we select these representative values meaning future |
| 75 | // merges won't know the exact constant value but have some notion of its size. |
| 76 | const RegType& ByteConstant() { return FromCat1Const(std::numeric_limits<jbyte>::min()); } |
| 77 | const RegType& ShortConstant() { return FromCat1Const(std::numeric_limits<jshort>::min()); } |
| 78 | const RegType& IntConstant() { return FromCat1Const(std::numeric_limits<jint>::max()); } |
| 79 | |
| 80 | const RegType& GetComponentType(const RegType& array, const ClassLoader* loader); |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame^] | 81 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 82 | private: |
| 83 | // The allocated entries |
| 84 | std::vector<RegType*> entries_; |
| 85 | |
| 86 | DISALLOW_COPY_AND_ASSIGN(RegTypeCache); |
| 87 | }; |
| 88 | |
| 89 | } // namespace verifier |
| 90 | } // namespace art |
| 91 | |
| 92 | #endif // ART_SRC_VERIFIER_REG_TYPE_CACHE_H_ |