blob: 28af887d1848f8bea01ce99f4b3728a55e570091 [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
Elliott Hughes73e66f72012-05-09 09:34:45 -070046 void Dump(std::ostream& os) const;
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;
Elliott Hughes73e66f72012-05-09 09:34:45 -070052 static void Dump(std::ostream& os, const Table& entries);
Elliott Hughes6c1a3942011-08-17 15:00:06 -070053 friend class IndirectReferenceTable; // For Dump.
54
Elliott Hughes11e45072011-08-16 17:40:46 -070055 std::string name_;
Elliott Hughes410c0c82011-09-01 17:58:25 -070056 Table entries_;
Elliott Hughes11e45072011-08-16 17:40:46 -070057 size_t max_size_;
58};
59
60} // namespace art
61
62#endif // ART_SRC_REFERENCE_TABLE_H_