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