111e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes/* 211e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes * Copyright (C) 2008 The Android Open Source Project 311e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes * 411e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 511e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes * you may not use this file except in compliance with the License. 611e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes * You may obtain a copy of the License at 711e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes * 811e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 911e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes * 1011e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes * Unless required by applicable law or agreed to in writing, software 1111e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 1211e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1311e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes * See the License for the specific language governing permissions and 1411e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes * limitations under the License. 1511e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes */ 1611e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes 17fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#ifndef ART_RUNTIME_REFERENCE_TABLE_H_ 18fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#define ART_RUNTIME_REFERENCE_TABLE_H_ 1911e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes 2011e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes#include <cstddef> 2111e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes#include <iosfwd> 2211e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes#include <string> 2311e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes#include <vector> 2411e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes 252dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "locks.h" 262dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "root_visitor.h" 27410c0c876f326e14c176a39ba21fc4dd3f7db8abElliott Hughes 2811e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughesnamespace art { 292dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogersnamespace mirror { 3011e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughesclass Object; 312dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers} // namespace mirror 3211e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes 336c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes// Maintain a table of references. Used for JNI monitor references and 346c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes// JNI pinned array references. 355b1982d2b41ab7a664fb04117539f29eadafa773Carl Shapiro// 365b1982d2b41ab7a664fb04117539f29eadafa773Carl Shapiro// None of the functions are synchronized. 3711e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughesclass ReferenceTable { 3811e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes public: 3911e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes ReferenceTable(const char* name, size_t initial_size, size_t max_size); 40c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughes ~ReferenceTable(); 4111e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes 422dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers void Add(const mirror::Object* obj); 4311e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes 442dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers void Remove(const mirror::Object* obj); 4511e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes 4611e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes size_t Size() const; 4711e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes 48b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers void Dump(std::ostream& os) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 4911e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes 502dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers void VisitRoots(RootVisitor* visitor, void* arg); 51410c0c876f326e14c176a39ba21fc4dd3f7db8abElliott Hughes 5211e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes private: 532dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers typedef std::vector<const mirror::Object*> Table; 5400f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers static void Dump(std::ostream& os, const Table& entries) 55b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 567934ac288acfb2552bb0b06ec1f61e5820d924a4Brian Carlstrom friend class IndirectReferenceTable; // For Dump. 576c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 5811e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes std::string name_; 59410c0c876f326e14c176a39ba21fc4dd3f7db8abElliott Hughes Table entries_; 6011e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes size_t max_size_; 6111e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes}; 6211e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes 6311e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes} // namespace art 6411e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes 65fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#endif // ART_RUNTIME_REFERENCE_TABLE_H_ 66