• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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_REFERENCE_TABLE_H_
18 #define ART_RUNTIME_REFERENCE_TABLE_H_
19 
20 #include <cstddef>
21 #include <iosfwd>
22 #include <string>
23 #include <vector>
24 
25 #include "base/allocator.h"
26 #include "base/locks.h"
27 #include "gc_root.h"
28 #include "obj_ptr.h"
29 
30 namespace art {
31 namespace jni {
32 class LocalReferenceTable;
33 }  // namespace jni
34 namespace mirror {
35 class Object;
36 }  // namespace mirror
37 
38 // Maintain a table of references.  Used for JNI monitor references and
39 // JNI pinned array references.
40 //
41 // None of the functions are synchronized.
42 class ReferenceTable {
43  public:
44   ReferenceTable(const char* name, size_t initial_size, size_t max_size);
45   ~ReferenceTable();
46 
47   void Add(ObjPtr<mirror::Object> obj) REQUIRES_SHARED(Locks::mutator_lock_);
48 
49   void Remove(ObjPtr<mirror::Object> obj) REQUIRES_SHARED(Locks::mutator_lock_);
50 
51   size_t Size() const;
52 
53   void Dump(std::ostream& os)
54       REQUIRES_SHARED(Locks::mutator_lock_)
55       REQUIRES(!Locks::alloc_tracker_lock_);
56 
57   void VisitRoots(RootVisitor* visitor, const RootInfo& root_info)
58       REQUIRES_SHARED(Locks::mutator_lock_);
59 
60  private:
61   using Table = std::vector<GcRoot<mirror::Object>,
62                             TrackingAllocator<GcRoot<mirror::Object>, kAllocatorTagReferenceTable>>;
63   static void Dump(std::ostream& os, Table& entries)
64       REQUIRES_SHARED(Locks::mutator_lock_)
65       REQUIRES(!Locks::alloc_tracker_lock_);
66   friend class IndirectReferenceTable;  // For Dump.
67   friend class jni::LocalReferenceTable;  // For Dump.
68 
69   std::string name_;
70   Table entries_;
71   size_t max_size_;
72 };
73 
74 }  // namespace art
75 
76 #endif  // ART_RUNTIME_REFERENCE_TABLE_H_
77