• 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 "locks.h"
26 #include "root_visitor.h"
27 
28 namespace art {
29 namespace mirror {
30 class Object;
31 }  // namespace mirror
32 
33 // Maintain a table of references.  Used for JNI monitor references and
34 // JNI pinned array references.
35 //
36 // None of the functions are synchronized.
37 class ReferenceTable {
38  public:
39   ReferenceTable(const char* name, size_t initial_size, size_t max_size);
40   ~ReferenceTable();
41 
42   void Add(const mirror::Object* obj);
43 
44   void Remove(const mirror::Object* obj);
45 
46   size_t Size() const;
47 
48   void Dump(std::ostream& os) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
49 
50   void VisitRoots(RootVisitor* visitor, void* arg);
51 
52  private:
53   typedef std::vector<const mirror::Object*> Table;
54   static void Dump(std::ostream& os, const Table& entries)
55       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
56   friend class IndirectReferenceTable;  // For Dump.
57 
58   std::string name_;
59   Table entries_;
60   size_t max_size_;
61 };
62 
63 }  // namespace art
64 
65 #endif  // ART_RUNTIME_REFERENCE_TABLE_H_
66