blob: f398eb2a4482818871fc5109918f0adc32abbada [file] [log] [blame]
Elliott Hughes11e45072011-08-16 17:40:46 -07001/*
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_SRC_REFERENCE_TABLE_H_
18#define ART_SRC_REFERENCE_TABLE_H_
19
20#include <cstddef>
21#include <iosfwd>
22#include <string>
23#include <vector>
24
Elliott Hughes410c0c82011-09-01 17:58:25 -070025#include "heap.h"
26
Elliott Hughes11e45072011-08-16 17:40:46 -070027namespace art {
28
29class Object;
30
Elliott Hughes6c1a3942011-08-17 15:00:06 -070031// Maintain a table of references. Used for JNI monitor references and
32// JNI pinned array references.
Carl Shapiro5b1982d2011-08-16 18:35:19 -070033//
34// None of the functions are synchronized.
Elliott Hughes11e45072011-08-16 17:40:46 -070035class ReferenceTable {
36 public:
37 ReferenceTable(const char* name, size_t initial_size, size_t max_size);
Elliott Hughesc1674ed2011-08-25 18:09:09 -070038 ~ReferenceTable();
Elliott Hughes11e45072011-08-16 17:40:46 -070039
Elliott Hughes75770752011-08-24 17:52:38 -070040 void Add(const Object* obj);
Elliott Hughes11e45072011-08-16 17:40:46 -070041
Elliott Hughes75770752011-08-24 17:52:38 -070042 void Remove(const Object* obj);
Elliott Hughes11e45072011-08-16 17:40:46 -070043
44 size_t Size() const;
45
Ian Rogersb726dcb2012-09-05 08:57:23 -070046 void Dump(std::ostream& os) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes11e45072011-08-16 17:40:46 -070047
Elliott Hughes410c0c82011-09-01 17:58:25 -070048 void VisitRoots(Heap::RootVisitor* visitor, void* arg);
49
Elliott Hughes11e45072011-08-16 17:40:46 -070050 private:
Elliott Hughes410c0c82011-09-01 17:58:25 -070051 typedef std::vector<const Object*> Table;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070052 static void Dump(std::ostream& os, const Table& entries)
Ian Rogersb726dcb2012-09-05 08:57:23 -070053 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes6c1a3942011-08-17 15:00:06 -070054 friend class IndirectReferenceTable; // For Dump.
55
Elliott Hughes11e45072011-08-16 17:40:46 -070056 std::string name_;
Elliott Hughes410c0c82011-09-01 17:58:25 -070057 Table entries_;
Elliott Hughes11e45072011-08-16 17:40:46 -070058 size_t max_size_;
59};
60
61} // namespace art
62
63#endif // ART_SRC_REFERENCE_TABLE_H_