• 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 mirror {
32 class Object;
33 }  // namespace mirror
34 
35 // Maintain a table of references.  Used for JNI monitor references and
36 // JNI pinned array references.
37 //
38 // None of the functions are synchronized.
39 class ReferenceTable {
40  public:
41   ReferenceTable(const char* name, size_t initial_size, size_t max_size);
42   ~ReferenceTable();
43 
44   void Add(ObjPtr<mirror::Object> obj) REQUIRES_SHARED(Locks::mutator_lock_);
45 
46   void Remove(ObjPtr<mirror::Object> obj) REQUIRES_SHARED(Locks::mutator_lock_);
47 
48   size_t Size() const;
49 
50   void Dump(std::ostream& os)
51       REQUIRES_SHARED(Locks::mutator_lock_)
52       REQUIRES(!Locks::alloc_tracker_lock_);
53 
54   void VisitRoots(RootVisitor* visitor, const RootInfo& root_info)
55       REQUIRES_SHARED(Locks::mutator_lock_);
56 
57  private:
58   typedef std::vector<GcRoot<mirror::Object>,
59                       TrackingAllocator<GcRoot<mirror::Object>, kAllocatorTagReferenceTable>> Table;
60   static void Dump(std::ostream& os, Table& entries)
61       REQUIRES_SHARED(Locks::mutator_lock_)
62       REQUIRES(!Locks::alloc_tracker_lock_);
63   friend class IndirectReferenceTable;  // For Dump.
64 
65   std::string name_;
66   Table entries_;
67   size_t max_size_;
68 };
69 
70 }  // namespace art
71 
72 #endif  // ART_RUNTIME_REFERENCE_TABLE_H_
73