blob: 2e27cc7f35fca842852d0da0bb07c3f376e92cf0 [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
20#include "jvmti.h"
21
Nicolas Geoffray4ac0e152019-09-18 06:14:50 +000022#include "base/locks.h"
23
24namespace art {
25class Thread;
26template<typename T> class ObjPtr;
27namespace mirror {
28class Object;
29} // namespace mirror
30} // namespace art
31
Andreas Gampee54d9922016-10-11 19:55:37 -070032namespace openjdkjvmti {
33
Alex Light72d7e942019-07-23 13:10:20 -070034class EventHandler;
Andreas Gampee54d9922016-10-11 19:55:37 -070035class ObjectTagTable;
36
37class HeapUtil {
38 public:
39 explicit HeapUtil(ObjectTagTable* tags) : tags_(tags) {
40 }
41
Andreas Gampeaa8b60c2016-10-12 12:51:25 -070042 jvmtiError GetLoadedClasses(jvmtiEnv* env, jint* class_count_ptr, jclass** classes_ptr);
43
Alex Lightbbbcb532018-08-30 12:50:27 -070044 jvmtiError IterateOverInstancesOfClass(jvmtiEnv* env,
45 jclass klass,
46 jvmtiHeapObjectFilter filter,
47 jvmtiHeapObjectCallback cb,
48 const void* user_data);
49
Andreas Gampee54d9922016-10-11 19:55:37 -070050 jvmtiError IterateThroughHeap(jvmtiEnv* env,
51 jint heap_filter,
52 jclass klass,
53 const jvmtiHeapCallbacks* callbacks,
54 const void* user_data);
55
Andreas Gampe70bfc8a2016-11-03 11:04:15 -070056 jvmtiError FollowReferences(jvmtiEnv* env,
57 jint heap_filter,
58 jclass klass,
59 jobject initial_object,
60 const jvmtiHeapCallbacks* callbacks,
61 const void* user_data);
62
Andreas Gampe8da6d032016-10-31 19:31:03 -070063 static jvmtiError ForceGarbageCollection(jvmtiEnv* env);
64
Andreas Gampee54d9922016-10-11 19:55:37 -070065 ObjectTagTable* GetTags() {
66 return tags_;
67 }
68
Andreas Gampe9e38a502017-03-06 08:19:26 -080069 static void Register();
70 static void Unregister();
71
Andreas Gampee54d9922016-10-11 19:55:37 -070072 private:
73 ObjectTagTable* tags_;
74};
75
Andreas Gamped73aba42017-05-03 21:40:26 -070076class HeapExtensions {
77 public:
Alex Light72d7e942019-07-23 13:10:20 -070078 static void Register(EventHandler* eh);
79
Andreas Gamped73aba42017-05-03 21:40:26 -070080 static jvmtiError JNICALL GetObjectHeapId(jvmtiEnv* env, jlong tag, jint* heap_id, ...);
81 static jvmtiError JNICALL GetHeapName(jvmtiEnv* env, jint heap_id, char** heap_name, ...);
Andreas Gampe2eb25e42017-05-09 17:14:58 -070082
83 static jvmtiError JNICALL IterateThroughHeapExt(jvmtiEnv* env,
84 jint heap_filter,
85 jclass klass,
86 const jvmtiHeapCallbacks* callbacks,
87 const void* user_data);
Alex Lightc14ec8f2019-07-18 16:08:41 -070088
89 static jvmtiError JNICALL ChangeArraySize(jvmtiEnv* env, jobject arr, jsize new_size);
Alex Light72d7e942019-07-23 13:10:20 -070090
Nicolas Geoffray4ac0e152019-09-18 06:14:50 +000091 static void ReplaceReference(art::Thread* self,
92 art::ObjPtr<art::mirror::Object> original,
93 art::ObjPtr<art::mirror::Object> replacement)
94 REQUIRES(art::Locks::mutator_lock_,
95 art::Roles::uninterruptible_);
96
Alex Light72d7e942019-07-23 13:10:20 -070097 private:
98 static EventHandler* gEventHandler;
Andreas Gamped73aba42017-05-03 21:40:26 -070099};
100
Andreas Gampee54d9922016-10-11 19:55:37 -0700101} // namespace openjdkjvmti
102
Andreas Gampe06c42a52017-07-26 14:17:14 -0700103#endif // ART_OPENJDKJVMTI_TI_HEAP_H_