blob: e6b4095e1d6af3ecc1001cdd51cfbbaafe150f89 [file] [log] [blame]
David Srbeckye3fc2d12018-11-30 13:41:14 +00001/*
2 * Copyright 2018 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_JIT_JIT_INL_H_
18#define ART_RUNTIME_JIT_JIT_INL_H_
19
20#include "jit/jit.h"
21
22#include "art_method.h"
23#include "base/bit_utils.h"
24#include "thread.h"
25#include "runtime-inl.h"
26
27namespace art {
28namespace jit {
29
30inline bool Jit::ShouldUsePriorityThreadWeight(Thread* self) {
31 return self->IsJitSensitiveThread() && Runtime::Current()->InJankPerceptibleProcessState();
32}
33
34inline void Jit::AddSamples(Thread* self,
35 ArtMethod* method,
36 uint16_t samples,
37 bool with_backedges) {
David Srbeckye3fc2d12018-11-30 13:41:14 +000038 if (Jit::ShouldUsePriorityThreadWeight(self)) {
39 samples *= PriorityThreadWeight();
40 }
41 uint32_t old_count = method->GetCounter();
42 uint32_t new_count = old_count + samples;
43
44 // The full check is fairly expensive so we just add to hotness most of the time,
45 // and we do the full check only when some of the higher bits of the count change.
46 // NB: The method needs to see the transitions of the counter past the thresholds.
47 uint32_t old_batch = RoundDown(old_count, kJitSamplesBatchSize); // Clear lower bits.
48 uint32_t new_batch = RoundDown(new_count, kJitSamplesBatchSize); // Clear lower bits.
David Srbecky21821472019-07-29 15:10:31 +010049 if (UNLIKELY(kSlowMode)) { // Check every time in slow-debug mode.
David Srbeckye3fc2d12018-11-30 13:41:14 +000050 if (!MaybeCompileMethod(self, method, old_count, new_count, with_backedges)) {
51 // Tests may check that the counter is 0 for methods that we never compile.
52 return; // Ignore the samples for now and retry later.
53 }
54 } else if (UNLIKELY(old_batch != new_batch)) {
David Srbeckye3fc2d12018-11-30 13:41:14 +000055 if (!MaybeCompileMethod(self, method, old_batch, new_batch, with_backedges)) {
56 // OSR compilation will ignore the samples if they don't have backedges.
57 return; // Ignore the samples for now and retry later.
58 }
59 }
60
61 method->SetCounter(new_count);
62}
63
64} // namespace jit
65} // namespace art
66
67#endif // ART_RUNTIME_JIT_JIT_INL_H_