blob: 6855dcdb2b174a8c12785714ebe47d834967210f [file] [log] [blame]
Vladimir Marko2b5eaa22013-12-13 13:59:30 +00001/*
2 * Copyright (C) 2013 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_RUNTIME_COMPILER_CALLBACKS_H_
18#define ART_RUNTIME_COMPILER_CALLBACKS_H_
19
Ian Rogers719d1a32014-03-06 12:13:39 -080020#include "base/mutex.h"
David Sehre6564f42018-03-19 08:39:26 -070021#include "dex/class_reference.h"
Andreas Gampe5d3b0022017-08-31 10:36:31 -070022#include "class_status.h"
Vladimir Marko2b5eaa22013-12-13 13:59:30 +000023
24namespace art {
25
Mathieu Chartier9e050df2017-08-09 10:05:47 -070026class CompilerDriver;
27
Andreas Gampee9934582018-01-19 21:23:04 -080028namespace mirror {
29
30class Class;
31
32} // namespace mirror
33
Vladimir Marko2b5eaa22013-12-13 13:59:30 +000034namespace verifier {
35
36class MethodVerifier;
David Brazdilca3c8c32016-09-06 14:04:48 +010037class VerifierDeps;
Vladimir Marko2b5eaa22013-12-13 13:59:30 +000038
39} // namespace verifier
40
41class CompilerCallbacks {
Andreas Gampe4585f872015-03-27 23:45:15 -070042 public:
43 enum class CallbackMode { // private
44 kCompileBootImage,
45 kCompileApp
46 };
Vladimir Marko2b5eaa22013-12-13 13:59:30 +000047
Andreas Gampe4585f872015-03-27 23:45:15 -070048 virtual ~CompilerCallbacks() { }
Vladimir Marko2b5eaa22013-12-13 13:59:30 +000049
Andreas Gampe53e32d12015-12-09 21:03:23 -080050 virtual void MethodVerified(verifier::MethodVerifier* verifier)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070051 REQUIRES_SHARED(Locks::mutator_lock_) = 0;
Andreas Gampe4585f872015-03-27 23:45:15 -070052 virtual void ClassRejected(ClassReference ref) = 0;
Alex Lighta59dd802014-07-02 16:28:08 -070053
Andreas Gampe4585f872015-03-27 23:45:15 -070054 // Return true if we should attempt to relocate to a random base address if we have not already
55 // done so. Return false if relocating in this way would be problematic.
56 virtual bool IsRelocationPossible() = 0;
Andreas Gampe81c6f8d2015-03-25 17:19:53 -070057
David Brazdilca3c8c32016-09-06 14:04:48 +010058 virtual verifier::VerifierDeps* GetVerifierDeps() const = 0;
Nicolas Geoffray6bb7f1b2016-11-03 10:52:49 +000059 virtual void SetVerifierDeps(verifier::VerifierDeps* deps ATTRIBUTE_UNUSED) {}
David Brazdilca3c8c32016-09-06 14:04:48 +010060
Andreas Gampe5d3b0022017-08-31 10:36:31 -070061 // Return the class status of a previous stage of the compilation. This can be used, for example,
62 // when class unloading is enabled during multidex compilation.
63 virtual ClassStatus GetPreviousClassState(ClassReference ref ATTRIBUTE_UNUSED) {
Vladimir Marko2c64a832018-01-04 11:31:56 +000064 return ClassStatus::kNotReady;
Mathieu Chartier9e050df2017-08-09 10:05:47 -070065 }
66
67 virtual void SetDoesClassUnloading(bool does_class_unloading ATTRIBUTE_UNUSED,
68 CompilerDriver* compiler_driver ATTRIBUTE_UNUSED) {}
69
Andreas Gampe4585f872015-03-27 23:45:15 -070070 bool IsBootImage() {
Andreas Gampe0dbc8be2018-04-11 20:45:16 +000071 return mode_ == CallbackMode::kCompileBootImage;
Andreas Gampe4585f872015-03-27 23:45:15 -070072 }
Andreas Gampe81c6f8d2015-03-25 17:19:53 -070073
Nicolas Geoffray486dda02017-09-11 14:15:52 +010074 virtual void UpdateClassState(ClassReference ref ATTRIBUTE_UNUSED,
75 ClassStatus state ATTRIBUTE_UNUSED) {}
76
Andreas Gampee9934582018-01-19 21:23:04 -080077 virtual bool CanUseOatStatusForVerification(mirror::Class* klass ATTRIBUTE_UNUSED)
78 REQUIRES_SHARED(Locks::mutator_lock_) {
79 return false;
80 }
81
Andreas Gampe4585f872015-03-27 23:45:15 -070082 protected:
83 explicit CompilerCallbacks(CallbackMode mode) : mode_(mode) { }
84
85 private:
86 // Whether the compiler is creating a boot image.
87 const CallbackMode mode_;
Vladimir Marko2b5eaa22013-12-13 13:59:30 +000088};
89
90} // namespace art
91
92#endif // ART_RUNTIME_COMPILER_CALLBACKS_H_