Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 1 | /* |
| 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 Gampe | 06c42a5 | 2017-07-26 14:17:14 -0700 | [diff] [blame] | 17 | #ifndef ART_OPENJDKJVMTI_TI_HEAP_H_ |
| 18 | #define ART_OPENJDKJVMTI_TI_HEAP_H_ |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 19 | |
Alex Light | 986914b | 2019-11-19 01:12:25 +0000 | [diff] [blame] | 20 | #include <unordered_map> |
| 21 | |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 22 | #include "jvmti.h" |
| 23 | |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 24 | #include "base/locks.h" |
| 25 | |
| 26 | namespace art { |
| 27 | class Thread; |
| 28 | template<typename T> class ObjPtr; |
Alex Light | 986914b | 2019-11-19 01:12:25 +0000 | [diff] [blame] | 29 | class HashObjPtr; |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 30 | namespace mirror { |
| 31 | class Object; |
| 32 | } // namespace mirror |
| 33 | } // namespace art |
| 34 | |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 35 | namespace openjdkjvmti { |
| 36 | |
Alex Light | 72d7e94 | 2019-07-23 13:10:20 -0700 | [diff] [blame] | 37 | class EventHandler; |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 38 | class ObjectTagTable; |
| 39 | |
| 40 | class HeapUtil { |
| 41 | public: |
| 42 | explicit HeapUtil(ObjectTagTable* tags) : tags_(tags) { |
| 43 | } |
| 44 | |
Andreas Gampe | aa8b60c | 2016-10-12 12:51:25 -0700 | [diff] [blame] | 45 | jvmtiError GetLoadedClasses(jvmtiEnv* env, jint* class_count_ptr, jclass** classes_ptr); |
| 46 | |
Alex Light | bbbcb53 | 2018-08-30 12:50:27 -0700 | [diff] [blame] | 47 | jvmtiError IterateOverInstancesOfClass(jvmtiEnv* env, |
| 48 | jclass klass, |
| 49 | jvmtiHeapObjectFilter filter, |
| 50 | jvmtiHeapObjectCallback cb, |
| 51 | const void* user_data); |
| 52 | |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 53 | jvmtiError IterateThroughHeap(jvmtiEnv* env, |
| 54 | jint heap_filter, |
| 55 | jclass klass, |
| 56 | const jvmtiHeapCallbacks* callbacks, |
| 57 | const void* user_data); |
| 58 | |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 59 | 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 Gampe | 8da6d03 | 2016-10-31 19:31:03 -0700 | [diff] [blame] | 66 | static jvmtiError ForceGarbageCollection(jvmtiEnv* env); |
| 67 | |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 68 | ObjectTagTable* GetTags() { |
| 69 | return tags_; |
| 70 | } |
| 71 | |
Andreas Gampe | 9e38a50 | 2017-03-06 08:19:26 -0800 | [diff] [blame] | 72 | static void Register(); |
| 73 | static void Unregister(); |
| 74 | |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 75 | private: |
| 76 | ObjectTagTable* tags_; |
| 77 | }; |
| 78 | |
Andreas Gampe | d73aba4 | 2017-05-03 21:40:26 -0700 | [diff] [blame] | 79 | class HeapExtensions { |
| 80 | public: |
Alex Light | 72d7e94 | 2019-07-23 13:10:20 -0700 | [diff] [blame] | 81 | static void Register(EventHandler* eh); |
| 82 | |
Andreas Gampe | d73aba4 | 2017-05-03 21:40:26 -0700 | [diff] [blame] | 83 | 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 Gampe | 2eb25e4 | 2017-05-09 17:14:58 -0700 | [diff] [blame] | 85 | |
| 86 | static jvmtiError JNICALL IterateThroughHeapExt(jvmtiEnv* env, |
| 87 | jint heap_filter, |
| 88 | jclass klass, |
| 89 | const jvmtiHeapCallbacks* callbacks, |
| 90 | const void* user_data); |
Alex Light | c14ec8f | 2019-07-18 16:08:41 -0700 | [diff] [blame] | 91 | |
| 92 | static jvmtiError JNICALL ChangeArraySize(jvmtiEnv* env, jobject arr, jsize new_size); |
Alex Light | 72d7e94 | 2019-07-23 13:10:20 -0700 | [diff] [blame] | 93 | |
Alex Light | 986914b | 2019-11-19 01:12:25 +0000 | [diff] [blame] | 94 | 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 Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 101 | 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 Light | 72d7e94 | 2019-07-23 13:10:20 -0700 | [diff] [blame] | 107 | private: |
| 108 | static EventHandler* gEventHandler; |
Andreas Gampe | d73aba4 | 2017-05-03 21:40:26 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 111 | } // namespace openjdkjvmti |
| 112 | |
Andreas Gampe | 06c42a5 | 2017-07-26 14:17:14 -0700 | [diff] [blame] | 113 | #endif // ART_OPENJDKJVMTI_TI_HEAP_H_ |