blob: 2e4d95401b1b1b71a887d2024b983db170b8c8e4 [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
25namespace art {
26
27class Object;
28
Elliott Hughes6c1a3942011-08-17 15:00:06 -070029// Maintain a table of references. Used for JNI monitor references and
30// JNI pinned array references.
Carl Shapiro5b1982d2011-08-16 18:35:19 -070031//
32// None of the functions are synchronized.
Elliott Hughes11e45072011-08-16 17:40:46 -070033class ReferenceTable {
34 public:
35 ReferenceTable(const char* name, size_t initial_size, size_t max_size);
36
37 void Add(Object* obj);
38
39 void Remove(Object* obj);
40
41 size_t Size() const;
42
43 void Dump() const;
44
45 private:
Elliott Hughes6c1a3942011-08-17 15:00:06 -070046 static void Dump(const std::vector<Object*>& entries);
47 friend class IndirectReferenceTable; // For Dump.
48
Elliott Hughes11e45072011-08-16 17:40:46 -070049 std::string name_;
50 std::vector<Object*> entries_;
51 size_t max_size_;
52};
53
54} // namespace art
55
56#endif // ART_SRC_REFERENCE_TABLE_H_