blob: 64b3f448e6e0f97fa360bc924754a11a54fc6cab [file] [log] [blame]
Vladimir Markoc7f83202014-01-24 17:55:18 +00001/*
2 * Copyright (C) 2014 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_COMPILER_DEX_VERIFIED_METHOD_H_
18#define ART_COMPILER_DEX_VERIFIED_METHOD_H_
19
20#include <vector>
21
Ian Rogers719d1a32014-03-06 12:13:39 -080022#include "base/mutex.h"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080023#include "dex_file.h"
Vladimir Markoc7f83202014-01-24 17:55:18 +000024#include "method_reference.h"
25#include "safe_map.h"
26
27namespace art {
28
29namespace verifier {
30class MethodVerifier;
31} // namespace verifier
32
33class VerifiedMethod {
34 public:
Nicolas Geoffray51c17fa2016-11-25 15:56:12 +000035 VerifiedMethod(uint32_t encountered_error_types, bool has_runtime_throw);
36
Vladimir Markoc7f83202014-01-24 17:55:18 +000037 // Cast elision set type.
38 // Since we're adding the dex PCs to the set in increasing order, a sorted vector
39 // is better for performance (not just memory usage), especially for large sets.
40 typedef std::vector<uint32_t> SafeCastSet;
41
Nicolas Geoffrayc51c7ca2016-11-25 15:46:48 +000042 static const VerifiedMethod* Create(verifier::MethodVerifier* method_verifier)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070043 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Markoc7f83202014-01-24 17:55:18 +000044 ~VerifiedMethod() = default;
45
Andreas Gampe26699c62017-05-12 08:19:28 -070046 const SafeCastSet* GetSafeCastSet() const {
47 return safe_cast_set_.get();
Vladimir Markoc7f83202014-01-24 17:55:18 +000048 }
49
Vladimir Markoc7f83202014-01-24 17:55:18 +000050 // Returns true if the cast can statically be verified to be redundant
51 // by using the check-cast elision peephole optimization in the verifier.
52 bool IsSafeCast(uint32_t pc) const;
53
Calin Juravlef1c6d9e2015-04-13 18:42:21 +010054 // Returns true if there were any errors during verification.
55 bool HasVerificationFailures() const {
Andreas Gampe0760a812015-08-26 17:12:51 -070056 return encountered_error_types_ != 0;
57 }
58
59 uint32_t GetEncounteredVerificationFailures() const {
60 return encountered_error_types_;
Calin Juravlef1c6d9e2015-04-13 18:42:21 +010061 }
62
Nicolas Geoffray4824c272015-06-24 15:53:03 +010063 bool HasRuntimeThrow() const {
64 return has_runtime_throw_;
65 }
66
Vladimir Markoc7f83202014-01-24 17:55:18 +000067 private:
Vladimir Markoc7f83202014-01-24 17:55:18 +000068 // Generate safe case set into safe_cast_set_.
69 void GenerateSafeCastSet(verifier::MethodVerifier* method_verifier)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070070 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Markoc7f83202014-01-24 17:55:18 +000071
Andreas Gampe26699c62017-05-12 08:19:28 -070072 std::unique_ptr<SafeCastSet> safe_cast_set_;
Calin Juravlef1c6d9e2015-04-13 18:42:21 +010073
Andreas Gampe0760a812015-08-26 17:12:51 -070074 const uint32_t encountered_error_types_;
75 const bool has_runtime_throw_;
Vladimir Markoc7f83202014-01-24 17:55:18 +000076};
77
78} // namespace art
79
80#endif // ART_COMPILER_DEX_VERIFIED_METHOD_H_