Home | History | Annotate | Download | only in runtime
      1 /*
      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_RUNTIME_REFERENCE_TABLE_H_
     18 #define ART_RUNTIME_REFERENCE_TABLE_H_
     19 
     20 #include <cstddef>
     21 #include <iosfwd>
     22 #include <string>
     23 #include <vector>
     24 
     25 #include "base/allocator.h"
     26 #include "base/mutex.h"
     27 #include "gc_root.h"
     28 #include "object_callbacks.h"
     29 
     30 namespace art {
     31 namespace mirror {
     32 class Object;
     33 }  // namespace mirror
     34 
     35 // Maintain a table of references.  Used for JNI monitor references and
     36 // JNI pinned array references.
     37 //
     38 // None of the functions are synchronized.
     39 class ReferenceTable {
     40  public:
     41   ReferenceTable(const char* name, size_t initial_size, size_t max_size);
     42   ~ReferenceTable();
     43 
     44   void Add(mirror::Object* obj) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
     45 
     46   void Remove(mirror::Object* obj) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
     47 
     48   size_t Size() const;
     49 
     50   void Dump(std::ostream& os) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
     51 
     52   void VisitRoots(RootCallback* visitor, void* arg, const RootInfo& root_info);
     53 
     54  private:
     55   typedef std::vector<GcRoot<mirror::Object>,
     56                       TrackingAllocator<GcRoot<mirror::Object>, kAllocatorTagReferenceTable>> Table;
     57   static void Dump(std::ostream& os, Table& entries)
     58       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
     59   friend class IndirectReferenceTable;  // For Dump.
     60 
     61   std::string name_;
     62   Table entries_;
     63   size_t max_size_;
     64 };
     65 
     66 }  // namespace art
     67 
     68 #endif  // ART_RUNTIME_REFERENCE_TABLE_H_
     69