blob: ee8b4d6128cd140b8bef41ebba02f2c2ccebd696 [file] [log] [blame]
Andreas Gampee54d9922016-10-11 19:55:37 -07001/*
2 * Copyright (C) 2016 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
Andreas Gampe06c42a52017-07-26 14:17:14 -070017#ifndef ART_OPENJDKJVMTI_TI_HEAP_H_
18#define ART_OPENJDKJVMTI_TI_HEAP_H_
Andreas Gampee54d9922016-10-11 19:55:37 -070019
Alex Light986914b2019-11-19 01:12:25 +000020#include <unordered_map>
21
Andreas Gampee54d9922016-10-11 19:55:37 -070022#include "jvmti.h"
23
Nicolas Geoffray4ac0e152019-09-18 06:14:50 +000024#include "base/locks.h"
25
26namespace art {
27class Thread;
28template<typename T> class ObjPtr;
Alex Light986914b2019-11-19 01:12:25 +000029class HashObjPtr;
Nicolas Geoffray4ac0e152019-09-18 06:14:50 +000030namespace mirror {
31class Object;
32} // namespace mirror
33} // namespace art
34
Andreas Gampee54d9922016-10-11 19:55:37 -070035namespace openjdkjvmti {
36
Alex Light72d7e942019-07-23 13:10:20 -070037class EventHandler;
Andreas Gampee54d9922016-10-11 19:55:37 -070038class ObjectTagTable;
39
40class HeapUtil {
41 public:
42 explicit HeapUtil(ObjectTagTable* tags) : tags_(tags) {
43 }
44
Andreas Gampeaa8b60c2016-10-12 12:51:25 -070045 jvmtiError GetLoadedClasses(jvmtiEnv* env, jint* class_count_ptr, jclass** classes_ptr);
46
Alex Lightbbbcb532018-08-30 12:50:27 -070047 jvmtiError IterateOverInstancesOfClass(jvmtiEnv* env,
48 jclass klass,
49 jvmtiHeapObjectFilter filter,
50 jvmtiHeapObjectCallback cb,
51 const void* user_data);
52
Andreas Gampee54d9922016-10-11 19:55:37 -070053 jvmtiError IterateThroughHeap(jvmtiEnv* env,
54 jint heap_filter,
55 jclass klass,
56 const jvmtiHeapCallbacks* callbacks,
57 const void* user_data);
58
Andreas Gampe70bfc8a2016-11-03 11:04:15 -070059 jvmtiError FollowReferences(jvmtiEnv* env,
60 jint heap_filter,
61 jclass klass,
62 jobject initial_object,
63 const jvmtiHeapCallbacks* callbacks,
64 const void* user_data);
65
Andreas Gampe8da6d032016-10-31 19:31:03 -070066 static jvmtiError ForceGarbageCollection(jvmtiEnv* env);
67
Andreas Gampee54d9922016-10-11 19:55:37 -070068 ObjectTagTable* GetTags() {
69 return tags_;
70 }
71
Andreas Gampe9e38a502017-03-06 08:19:26 -080072 static void Register();
73 static void Unregister();
74
Andreas Gampee54d9922016-10-11 19:55:37 -070075 private:
76 ObjectTagTable* tags_;
77};
78
Andreas Gamped73aba42017-05-03 21:40:26 -070079class HeapExtensions {
80 public:
Alex Light72d7e942019-07-23 13:10:20 -070081 static void Register(EventHandler* eh);
82
Andreas Gamped73aba42017-05-03 21:40:26 -070083 static jvmtiError JNICALL GetObjectHeapId(jvmtiEnv* env, jlong tag, jint* heap_id, ...);
84 static jvmtiError JNICALL GetHeapName(jvmtiEnv* env, jint heap_id, char** heap_name, ...);
Andreas Gampe2eb25e42017-05-09 17:14:58 -070085
86 static jvmtiError JNICALL IterateThroughHeapExt(jvmtiEnv* env,
87 jint heap_filter,
88 jclass klass,
89 const jvmtiHeapCallbacks* callbacks,
90 const void* user_data);
Alex Lightc14ec8f2019-07-18 16:08:41 -070091
92 static jvmtiError JNICALL ChangeArraySize(jvmtiEnv* env, jobject arr, jsize new_size);
Alex Light72d7e942019-07-23 13:10:20 -070093
Alex Light986914b2019-11-19 01:12:25 +000094 static void ReplaceReferences(
95 art::Thread* self,
96 const std::unordered_map<art::ObjPtr<art::mirror::Object>,
97 art::ObjPtr<art::mirror::Object>,
98 art::HashObjPtr>& refs)
99 REQUIRES(art::Locks::mutator_lock_, art::Roles::uninterruptible_);
100
Nicolas Geoffray4ac0e152019-09-18 06:14:50 +0000101 static void ReplaceReference(art::Thread* self,
102 art::ObjPtr<art::mirror::Object> original,
103 art::ObjPtr<art::mirror::Object> replacement)
104 REQUIRES(art::Locks::mutator_lock_,
105 art::Roles::uninterruptible_);
106
Alex Light72d7e942019-07-23 13:10:20 -0700107 private:
108 static EventHandler* gEventHandler;
Andreas Gamped73aba42017-05-03 21:40:26 -0700109};
110
Andreas Gampee54d9922016-10-11 19:55:37 -0700111} // namespace openjdkjvmti
112
Andreas Gampe06c42a52017-07-26 14:17:14 -0700113#endif // ART_OPENJDKJVMTI_TI_HEAP_H_