reg_type_cache.h revision 776ac1fa61237db645adb4370a4aab888530caf4
1776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers/*
2776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Copyright (C) 2012 The Android Open Source Project
3776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers *
4776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Licensed under the Apache License, Version 2.0 (the "License");
5776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * you may not use this file except in compliance with the License.
6776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * You may obtain a copy of the License at
7776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers *
8776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers *      http://www.apache.org/licenses/LICENSE-2.0
9776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers *
10776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Unless required by applicable law or agreed to in writing, software
11776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * distributed under the License is distributed on an "AS IS" BASIS,
12776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * See the License for the specific language governing permissions and
14776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * limitations under the License.
15776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers */
16776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
17776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers#ifndef ART_SRC_VERIFIER_REG_TYPE_CACHE_H_
18776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers#define ART_SRC_VERIFIER_REG_TYPE_CACHE_H_
19776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
20776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers#include "macros.h"
21776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers#include "reg_type.h"
22776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers#include "stl_util.h"
23776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
24776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersnamespace art {
25776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersnamespace verifier {
26776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
27776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersclass RegTypeCache {
28776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers public:
29776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  explicit RegTypeCache() : entries_(RegType::kRegTypeLastFixedLocation + 1) {
30776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    Unknown();  // ensure Unknown is initialized
31776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  }
32776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  ~RegTypeCache() {
33776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    STLDeleteElements(&entries_);
34776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  }
35776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
36776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& GetFromId(uint16_t id) {
37776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    DCHECK_LT(id, entries_.size());
38776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    RegType* result = entries_[id];
39776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    DCHECK(result != NULL);
40776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    return *result;
41776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  }
42776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
43776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& From(RegType::Type type, const ClassLoader* loader, const char* descriptor);
44776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& FromClass(Class* klass);
45776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& FromCat1Const(int32_t value);
46776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& FromDescriptor(const ClassLoader* loader, const char* descriptor);
47776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& FromType(RegType::Type);
48776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
49776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& Boolean() { return FromType(RegType::kRegTypeBoolean); }
50776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& Byte()    { return FromType(RegType::kRegTypeByte); }
51776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& Char()    { return FromType(RegType::kRegTypeChar); }
52776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& Short()   { return FromType(RegType::kRegTypeShort); }
53776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& Integer() { return FromType(RegType::kRegTypeInteger); }
54776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& Float()   { return FromType(RegType::kRegTypeFloat); }
55776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& Long()    { return FromType(RegType::kRegTypeLongLo); }
56776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& Double()  { return FromType(RegType::kRegTypeDoubleLo); }
57776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
58776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& JavaLangClass()  { return From(RegType::kRegTypeReference, NULL, "Ljava/lang/Class;"); }
59776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& JavaLangObject() { return From(RegType::kRegTypeReference, NULL, "Ljava/lang/Object;"); }
60776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& JavaLangString() { return From(RegType::kRegTypeReference, NULL, "Ljava/lang/String;"); }
61776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& JavaLangThrowable() { return From(RegType::kRegTypeReference, NULL, "Ljava/lang/Throwable;"); }
62776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
63776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& Unknown()  { return FromType(RegType::kRegTypeUnknown); }
64776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& Conflict() { return FromType(RegType::kRegTypeConflict); }
65776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& ConstLo()  { return FromType(RegType::kRegTypeConstLo); }
66776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& Zero()     { return FromCat1Const(0); }
67776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
68776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& Uninitialized(const RegType& type, uint32_t allocation_pc);
69776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& UninitializedThisArgument(Class* klass);
70776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& FromUninitialized(const RegType& uninit_type);
71776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
72776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // Representatives of various constant types. When merging constants we can't infer a type,
73776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // (an int may later be used as a float) so we select these representative values meaning future
74776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // merges won't know the exact constant value but have some notion of its size.
75776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& ByteConstant() { return FromCat1Const(std::numeric_limits<jbyte>::min()); }
76776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& ShortConstant() { return FromCat1Const(std::numeric_limits<jshort>::min()); }
77776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& IntConstant() { return FromCat1Const(std::numeric_limits<jint>::max()); }
78776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
79776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  const RegType& GetComponentType(const RegType& array, const ClassLoader* loader);
80776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers private:
81776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // The allocated entries
82776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  std::vector<RegType*> entries_;
83776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
84776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  DISALLOW_COPY_AND_ASSIGN(RegTypeCache);
85776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers};
86776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
87776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers}  // namespace verifier
88776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers}  // namespace art
89776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
90776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers#endif  // ART_SRC_VERIFIER_REG_TYPE_CACHE_H_
91