summaryrefslogtreecommitdiff
path: root/runtime/jit/jit_code_cache-inl.h
blob: 6f2a9ddaae8c3bb00d30e300308039de87f4ac4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * Copyright 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ART_RUNTIME_JIT_JIT_CODE_CACHE_INL_H_
#define ART_RUNTIME_JIT_JIT_CODE_CACHE_INL_H_

#include "jit/jit_code_cache.h"

#include "base/macros.h"
#include "read_barrier.h"
#include "thread.h"
#include "well_known_classes-inl.h"

namespace art HIDDEN {

class ArtMethod;

namespace jit {

template<typename RootVisitorType>
EXPORT void JitCodeCache::VisitRootTables(ArtMethod* method, RootVisitorType& visitor) {
  if (method->IsNative()) {
    return;
  }

  Thread* self = Thread::Current();
  ScopedDebugDisallowReadBarriers sddrb(self);
  MutexLock mu(self, *Locks::jit_lock_);

  auto range = method_code_map_reversed_.equal_range(method);

  for (auto it = range.first; it != range.second; ++it) {
    uint32_t number_of_roots = 0;
    const uint8_t* root_table = GetRootTable(it->second, &number_of_roots);
    uint8_t* roots_data = private_region_.IsInDataSpace(root_table)
        ? private_region_.GetWritableDataAddress(root_table)
        : shared_region_.GetWritableDataAddress(root_table);
    GcRoot<mirror::Object>* roots = reinterpret_cast<GcRoot<mirror::Object>*>(roots_data);
    for (uint32_t i = 0; i < number_of_roots; ++i) {
      // This does not need a read barrier because this is called by GC.
      mirror::Object* object = roots[i].Read<kWithoutReadBarrier>();
      if (!(object == nullptr ||
            object == Runtime::GetWeakClassSentinel() ||
            object->IsString<kDefaultVerifyFlags>() ||
            object->IsClass<kDefaultVerifyFlags>())) {
        // We don't need to visit j.l.Class and j.l.String and the only remaining possible
        // objects are MethodType-s.
        if (kIsDebugBuild) {
          ObjPtr<mirror::Class> method_type_class =
              WellKnownClasses::java_lang_invoke_MethodType.Get<kWithoutReadBarrier>();
          ObjPtr<mirror::Class> klass =
              object->GetClass<kDefaultVerifyFlags, kWithoutReadBarrier>();
          CHECK(klass == method_type_class ||
                klass == ReadBarrier::IsMarked(method_type_class.Ptr()) ||
                ReadBarrier::IsMarked(klass.Ptr()) == method_type_class);
        }

        visitor.VisitRoot(roots[i].AddressWithoutBarrier());
      }
    }
  }
}

}  // namespace jit
}  // namespace art

#endif  // ART_RUNTIME_JIT_JIT_CODE_CACHE_INL_H_