blob: 140cc37ea1a58dc3d687304b0c6e8bfacc84f38b [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
29#define kInvalidIndirectRefObject reinterpret_cast<Object*>(0xdead4321)
30#define kClearedJniWeakGlobal reinterpret_cast<Object*>(0xdead1234)
31
32/*
33 * Maintain a table of references. Used for internal local references,
34 * JNI monitor references, and JNI pinned array references.
35 *
36 * None of the functions are synchronized.
37 */
38class ReferenceTable {
39 public:
40 ReferenceTable(const char* name, size_t initial_size, size_t max_size);
41
42 void Add(Object* obj);
43
44 void Remove(Object* obj);
45
46 size_t Size() const;
47
48 void Dump() const;
49
50 private:
51 std::string name_;
52 std::vector<Object*> entries_;
53 size_t max_size_;
54};
55
56} // namespace art
57
58#endif // ART_SRC_REFERENCE_TABLE_H_