• 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/mutex.h"
27 #include "gc_root.h"
28 #include "object_callbacks.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(mirror::Object* obj) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
45 
46   void Remove(mirror::Object* obj) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
47 
48   size_t Size() const;
49 
50   void Dump(std::ostream& os) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
51 
52   void VisitRoots(RootVisitor* visitor, const RootInfo& root_info)
53       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
54 
55  private:
56   typedef std::vector<GcRoot<mirror::Object>,
57                       TrackingAllocator<GcRoot<mirror::Object>, kAllocatorTagReferenceTable>> Table;
58   static void Dump(std::ostream& os, Table& entries)
59       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
60   friend class IndirectReferenceTable;  // For Dump.
61 
62   std::string name_;
63   Table entries_;
64   size_t max_size_;
65 };
66 
67 }  // namespace art
68 
69 #endif  // ART_RUNTIME_REFERENCE_TABLE_H_
70