blob: e369fd0de5324c6142806f548ff61a4612319b48 [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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_REFERENCE_TABLE_H_
18#define ART_RUNTIME_REFERENCE_TABLE_H_
Elliott Hughes11e45072011-08-16 17:40:46 -070019
20#include <cstddef>
21#include <iosfwd>
22#include <string>
23#include <vector>
24
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025#include "locks.h"
26#include "root_visitor.h"
Elliott Hughes410c0c82011-09-01 17:58:25 -070027
Elliott Hughes11e45072011-08-16 17:40:46 -070028namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029namespace mirror {
Elliott Hughes11e45072011-08-16 17:40:46 -070030class Object;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031} // namespace mirror
Elliott Hughes11e45072011-08-16 17:40:46 -070032
Elliott Hughes6c1a3942011-08-17 15:00:06 -070033// Maintain a table of references. Used for JNI monitor references and
34// JNI pinned array references.
Carl Shapiro5b1982d2011-08-16 18:35:19 -070035//
36// None of the functions are synchronized.
Elliott Hughes11e45072011-08-16 17:40:46 -070037class ReferenceTable {
38 public:
39 ReferenceTable(const char* name, size_t initial_size, size_t max_size);
Elliott Hughesc1674ed2011-08-25 18:09:09 -070040 ~ReferenceTable();
Elliott Hughes11e45072011-08-16 17:40:46 -070041
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042 void Add(const mirror::Object* obj);
Elliott Hughes11e45072011-08-16 17:40:46 -070043
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080044 void Remove(const mirror::Object* obj);
Elliott Hughes11e45072011-08-16 17:40:46 -070045
46 size_t Size() const;
47
Ian Rogersb726dcb2012-09-05 08:57:23 -070048 void Dump(std::ostream& os) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes11e45072011-08-16 17:40:46 -070049
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080050 void VisitRoots(RootVisitor* visitor, void* arg);
Elliott Hughes410c0c82011-09-01 17:58:25 -070051
Elliott Hughes11e45072011-08-16 17:40:46 -070052 private:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080053 typedef std::vector<const mirror::Object*> Table;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070054 static void Dump(std::ostream& os, const Table& entries)
Ian Rogersb726dcb2012-09-05 08:57:23 -070055 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -070056 friend class IndirectReferenceTable; // For Dump.
Elliott Hughes6c1a3942011-08-17 15:00:06 -070057
Elliott Hughes11e45072011-08-16 17:40:46 -070058 std::string name_;
Elliott Hughes410c0c82011-09-01 17:58:25 -070059 Table entries_;
Elliott Hughes11e45072011-08-16 17:40:46 -070060 size_t max_size_;
61};
62
63} // namespace art
64
Brian Carlstromfc0e3212013-07-17 14:40:12 -070065#endif // ART_RUNTIME_REFERENCE_TABLE_H_