Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 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 | |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 17 | #include "dalvik_system_VMDebug.h" |
| 18 | |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 19 | #include <string.h> |
| 20 | #include <unistd.h> |
| 21 | |
Hiroshi Yamauchi | a1c9f01 | 2015-04-02 10:18:12 -0700 | [diff] [blame] | 22 | #include <sstream> |
| 23 | |
Andreas Gampe | a14100c | 2017-04-24 15:09:56 -0700 | [diff] [blame] | 24 | #include "nativehelper/jni_macros.h" |
| 25 | |
Andreas Gampe | dfcd82c | 2018-10-16 20:22:37 -0700 | [diff] [blame] | 26 | #include "base/file_utils.h" |
Hiroshi Yamauchi | a1c9f01 | 2015-04-02 10:18:12 -0700 | [diff] [blame] | 27 | #include "base/histogram-inl.h" |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 28 | #include "base/time_utils.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 29 | #include "class_linker.h" |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 30 | #include "common_throws.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 31 | #include "debugger.h" |
Mathieu Chartier | 7410f29 | 2013-11-24 13:17:35 -0800 | [diff] [blame] | 32 | #include "gc/space/bump_pointer_space.h" |
Hiroshi Yamauchi | 09b07a9 | 2013-07-15 13:17:06 -0700 | [diff] [blame] | 33 | #include "gc/space/dlmalloc_space.h" |
| 34 | #include "gc/space/large_object_space.h" |
| 35 | #include "gc/space/space-inl.h" |
Mathieu Chartier | 1f3b535 | 2014-02-03 14:00:42 -0800 | [diff] [blame] | 36 | #include "gc/space/zygote_space.h" |
Andreas Gampe | c15a2f4 | 2017-04-21 12:09:39 -0700 | [diff] [blame] | 37 | #include "handle_scope-inl.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 38 | #include "hprof/hprof.h" |
Vladimir Marko | a3ad0cd | 2018-05-04 10:06:38 +0100 | [diff] [blame] | 39 | #include "jni/java_vm_ext.h" |
| 40 | #include "jni/jni_internal.h" |
Andreas Gampe | 8e0f043 | 2018-10-24 13:38:03 -0700 | [diff] [blame^] | 41 | #include "mirror/array-alloc-inl.h" |
| 42 | #include "mirror/array-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 43 | #include "mirror/class.h" |
Andreas Gampe | c15a2f4 | 2017-04-21 12:09:39 -0700 | [diff] [blame] | 44 | #include "mirror/object_array-inl.h" |
Andreas Gampe | 87583b3 | 2017-05-25 11:22:18 -0700 | [diff] [blame] | 45 | #include "native_util.h" |
Andreas Gampe | 373a9b5 | 2017-10-18 09:01:57 -0700 | [diff] [blame] | 46 | #include "nativehelper/scoped_local_ref.h" |
| 47 | #include "nativehelper/scoped_utf_chars.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 48 | #include "scoped_fast_native_object_access-inl.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 49 | #include "trace.h" |
Ian Rogers | dd157d7 | 2014-05-15 14:47:50 -0700 | [diff] [blame] | 50 | #include "well_known_classes.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 51 | |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 52 | namespace art { |
| 53 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 54 | static jobjectArray VMDebug_getVmFeatureList(JNIEnv* env, jclass) { |
Ian Rogers | dd157d7 | 2014-05-15 14:47:50 -0700 | [diff] [blame] | 55 | static const char* features[] = { |
| 56 | "method-trace-profiling", |
| 57 | "method-trace-profiling-streaming", |
| 58 | "method-sample-profiling", |
| 59 | "hprof-heap-dump", |
| 60 | "hprof-heap-dump-streaming", |
| 61 | }; |
| 62 | jobjectArray result = env->NewObjectArray(arraysize(features), |
| 63 | WellKnownClasses::java_lang_String, |
| 64 | nullptr); |
| 65 | if (result != nullptr) { |
| 66 | for (size_t i = 0; i < arraysize(features); ++i) { |
| 67 | ScopedLocalRef<jstring> jfeature(env, env->NewStringUTF(features[i])); |
| 68 | if (jfeature.get() == nullptr) { |
| 69 | return nullptr; |
| 70 | } |
| 71 | env->SetObjectArrayElement(result, i, jfeature.get()); |
| 72 | } |
| 73 | } |
| 74 | return result; |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 77 | static void VMDebug_startAllocCounting(JNIEnv*, jclass) { |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 78 | Runtime::Current()->SetStatsEnabled(true); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 81 | static void VMDebug_stopAllocCounting(JNIEnv*, jclass) { |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 82 | Runtime::Current()->SetStatsEnabled(false); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 85 | static jint VMDebug_getAllocCount(JNIEnv*, jclass, jint kind) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 86 | return Runtime::Current()->GetStat(kind); |
| 87 | } |
| 88 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 89 | static void VMDebug_resetAllocCount(JNIEnv*, jclass, jint kinds) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 90 | Runtime::Current()->ResetStats(kinds); |
| 91 | } |
| 92 | |
Jeff Hao | 23009dc | 2013-08-22 15:36:42 -0700 | [diff] [blame] | 93 | static void VMDebug_startMethodTracingDdmsImpl(JNIEnv*, jclass, jint bufferSize, jint flags, |
| 94 | jboolean samplingEnabled, jint intervalUs) { |
Andreas Gampe | 6ff3b37 | 2018-03-15 08:53:16 -0700 | [diff] [blame] | 95 | Trace::StartDDMS(bufferSize, |
| 96 | flags, |
| 97 | samplingEnabled ? Trace::TraceMode::kSampling : Trace::TraceMode::kMethodTracing, |
| 98 | intervalUs); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Andreas Gampe | 6ff3b37 | 2018-03-15 08:53:16 -0700 | [diff] [blame] | 101 | static void VMDebug_startMethodTracingFd(JNIEnv* env, |
| 102 | jclass, |
| 103 | jstring javaTraceFilename ATTRIBUTE_UNUSED, |
| 104 | jint javaFd, |
| 105 | jint bufferSize, |
| 106 | jint flags, |
| 107 | jboolean samplingEnabled, |
| 108 | jint intervalUs, |
Shukang Zhou | ca6e14e | 2017-01-25 00:35:21 -0800 | [diff] [blame] | 109 | jboolean streamingOutput) { |
Andreas Gampe | ad5df10 | 2017-10-04 16:31:08 -0700 | [diff] [blame] | 110 | int originalFd = javaFd; |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 111 | if (originalFd < 0) { |
Andreas Gampe | 6ff3b37 | 2018-03-15 08:53:16 -0700 | [diff] [blame] | 112 | ScopedObjectAccess soa(env); |
| 113 | soa.Self()->ThrowNewExceptionF("Ljava/lang/RuntimeException;", |
| 114 | "Trace fd is invalid: %d", |
| 115 | originalFd); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 116 | return; |
| 117 | } |
| 118 | |
Andreas Gampe | dfcd82c | 2018-10-16 20:22:37 -0700 | [diff] [blame] | 119 | int fd = DupCloexec(originalFd); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 120 | if (fd < 0) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 121 | ScopedObjectAccess soa(env); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 122 | soa.Self()->ThrowNewExceptionF("Ljava/lang/RuntimeException;", |
Andreas Gampe | 6ff3b37 | 2018-03-15 08:53:16 -0700 | [diff] [blame] | 123 | "dup(%d) failed: %s", |
| 124 | originalFd, |
| 125 | strerror(errno)); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 126 | return; |
| 127 | } |
| 128 | |
Andreas Gampe | 6ff3b37 | 2018-03-15 08:53:16 -0700 | [diff] [blame] | 129 | // Ignore the traceFilename. |
Shukang Zhou | ca6e14e | 2017-01-25 00:35:21 -0800 | [diff] [blame] | 130 | Trace::TraceOutputMode outputMode = streamingOutput |
| 131 | ? Trace::TraceOutputMode::kStreaming |
| 132 | : Trace::TraceOutputMode::kFile; |
Andreas Gampe | 6ff3b37 | 2018-03-15 08:53:16 -0700 | [diff] [blame] | 133 | Trace::Start(fd, |
| 134 | bufferSize, |
| 135 | flags, |
| 136 | outputMode, |
Andreas Gampe | 7e7e0f4 | 2015-03-29 15:26:23 -0700 | [diff] [blame] | 137 | samplingEnabled ? Trace::TraceMode::kSampling : Trace::TraceMode::kMethodTracing, |
| 138 | intervalUs); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 141 | static void VMDebug_startMethodTracingFilename(JNIEnv* env, jclass, jstring javaTraceFilename, |
Jeff Hao | 4044bda | 2014-01-06 15:50:45 -0800 | [diff] [blame] | 142 | jint bufferSize, jint flags, |
| 143 | jboolean samplingEnabled, jint intervalUs) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 144 | ScopedUtfChars traceFilename(env, javaTraceFilename); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 145 | if (traceFilename.c_str() == nullptr) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 146 | return; |
| 147 | } |
Andreas Gampe | 6ff3b37 | 2018-03-15 08:53:16 -0700 | [diff] [blame] | 148 | Trace::Start(traceFilename.c_str(), |
| 149 | bufferSize, |
| 150 | flags, |
| 151 | Trace::TraceOutputMode::kFile, |
Andreas Gampe | 7e7e0f4 | 2015-03-29 15:26:23 -0700 | [diff] [blame] | 152 | samplingEnabled ? Trace::TraceMode::kSampling : Trace::TraceMode::kMethodTracing, |
| 153 | intervalUs); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Jeff Hao | 64caa7d | 2013-08-29 11:18:01 -0700 | [diff] [blame] | 156 | static jint VMDebug_getMethodTracingMode(JNIEnv*, jclass) { |
| 157 | return Trace::GetMethodTracingMode(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 160 | static void VMDebug_stopMethodTracing(JNIEnv*, jclass) { |
jeffhao | e343b76 | 2011-12-05 16:36:44 -0800 | [diff] [blame] | 161 | Trace::Stop(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 164 | static void VMDebug_startEmulatorTracing(JNIEnv*, jclass) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 165 | UNIMPLEMENTED(WARNING); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 166 | // dvmEmulatorTraceStart(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 169 | static void VMDebug_stopEmulatorTracing(JNIEnv*, jclass) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 170 | UNIMPLEMENTED(WARNING); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 171 | // dvmEmulatorTraceStop(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 174 | static jboolean VMDebug_isDebuggerConnected(JNIEnv*, jclass) { |
Elliott Hughes | c0f0933 | 2012-03-26 13:27:06 -0700 | [diff] [blame] | 175 | return Dbg::IsDebuggerActive(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Alex Light | 4032071 | 2017-12-14 11:52:04 -0800 | [diff] [blame] | 178 | static jboolean VMDebug_isDebuggingEnabled(JNIEnv* env, jclass) { |
| 179 | ScopedObjectAccess soa(env); |
| 180 | return Runtime::Current()->GetRuntimeCallbacks()->IsDebuggerConfigured(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 183 | static jlong VMDebug_lastDebuggerActivity(JNIEnv*, jclass) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 184 | return Dbg::LastDebuggerActivity(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 187 | static void ThrowUnsupportedOperationException(JNIEnv* env) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 188 | ScopedObjectAccess soa(env); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 189 | soa.Self()->ThrowNewException("Ljava/lang/UnsupportedOperationException;", nullptr); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | static void VMDebug_startInstructionCounting(JNIEnv* env, jclass) { |
| 193 | ThrowUnsupportedOperationException(env); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 196 | static void VMDebug_stopInstructionCounting(JNIEnv* env, jclass) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 197 | ThrowUnsupportedOperationException(env); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 200 | static void VMDebug_getInstructionCount(JNIEnv* env, jclass, jintArray /*javaCounts*/) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 201 | ThrowUnsupportedOperationException(env); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 204 | static void VMDebug_resetInstructionCount(JNIEnv* env, jclass) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 205 | ThrowUnsupportedOperationException(env); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 208 | static void VMDebug_printLoadedClasses(JNIEnv* env, jclass, jint flags) { |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 209 | class DumpClassVisitor : public ClassVisitor { |
| 210 | public: |
| 211 | explicit DumpClassVisitor(int dump_flags) : flags_(dump_flags) {} |
| 212 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 213 | bool operator()(ObjPtr<mirror::Class> klass) override REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 214 | klass->DumpClass(LOG_STREAM(ERROR), flags_); |
| 215 | return true; |
| 216 | } |
| 217 | |
| 218 | private: |
| 219 | const int flags_; |
| 220 | }; |
| 221 | DumpClassVisitor visitor(flags); |
| 222 | |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 223 | ScopedFastNativeObjectAccess soa(env); |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 224 | return Runtime::Current()->GetClassLinker()->VisitClasses(&visitor); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 227 | static jint VMDebug_getLoadedClassCount(JNIEnv* env, jclass) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 228 | ScopedFastNativeObjectAccess soa(env); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 229 | return Runtime::Current()->GetClassLinker()->NumLoadedClasses(); |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | * Returns the thread-specific CPU-time clock value for the current thread, |
| 234 | * or -1 if the feature isn't supported. |
| 235 | */ |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 236 | static jlong VMDebug_threadCpuTimeNanos(JNIEnv*, jclass) { |
| 237 | return ThreadCpuNanoTime(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /* |
| 241 | * static void dumpHprofData(String fileName, FileDescriptor fd) |
| 242 | * |
| 243 | * Cause "hprof" data to be dumped. We can throw an IOException if an |
| 244 | * error occurs during file handling. |
| 245 | */ |
Andreas Gampe | ad5df10 | 2017-10-04 16:31:08 -0700 | [diff] [blame] | 246 | static void VMDebug_dumpHprofData(JNIEnv* env, jclass, jstring javaFilename, jint javaFd) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 247 | // Only one of these may be null. |
Andreas Gampe | ad5df10 | 2017-10-04 16:31:08 -0700 | [diff] [blame] | 248 | if (javaFilename == nullptr && javaFd < 0) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 249 | ScopedObjectAccess soa(env); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 250 | ThrowNullPointerException("fileName == null && fd == null"); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 251 | return; |
| 252 | } |
| 253 | |
| 254 | std::string filename; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 255 | if (javaFilename != nullptr) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 256 | ScopedUtfChars chars(env, javaFilename); |
| 257 | if (env->ExceptionCheck()) { |
| 258 | return; |
| 259 | } |
| 260 | filename = chars.c_str(); |
| 261 | } else { |
| 262 | filename = "[fd]"; |
| 263 | } |
| 264 | |
Andreas Gampe | ad5df10 | 2017-10-04 16:31:08 -0700 | [diff] [blame] | 265 | int fd = javaFd; |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 266 | |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 267 | hprof::DumpHeap(filename.c_str(), fd, false); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 270 | static void VMDebug_dumpHprofDataDdms(JNIEnv*, jclass) { |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 271 | hprof::DumpHeap("[DDMS]", -1, true); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 274 | static void VMDebug_dumpReferenceTables(JNIEnv* env, jclass) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 275 | ScopedObjectAccess soa(env); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 276 | LOG(INFO) << "--- reference table dump ---"; |
| 277 | |
Andreas Gampe | 3fec9ac | 2016-09-13 10:47:28 -0700 | [diff] [blame] | 278 | soa.Env()->DumpReferenceTables(LOG_STREAM(INFO)); |
| 279 | soa.Vm()->DumpReferenceTables(LOG_STREAM(INFO)); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 280 | |
| 281 | LOG(INFO) << "---"; |
| 282 | } |
| 283 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 284 | static void VMDebug_crash(JNIEnv*, jclass) { |
Elliott Hughes | 81ff318 | 2012-03-23 20:35:56 -0700 | [diff] [blame] | 285 | LOG(FATAL) << "Crashing runtime on request"; |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 288 | static void VMDebug_infopoint(JNIEnv*, jclass, jint id) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 289 | LOG(INFO) << "VMDebug infopoint " << id << " hit"; |
| 290 | } |
| 291 | |
Mathieu Chartier | 9d156d5 | 2016-10-06 17:44:26 -0700 | [diff] [blame] | 292 | static jlong VMDebug_countInstancesOfClass(JNIEnv* env, |
| 293 | jclass, |
| 294 | jclass javaClass, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 295 | jboolean countAssignable) { |
| 296 | ScopedObjectAccess soa(env); |
Mathieu Chartier | f182085 | 2015-07-10 13:19:51 -0700 | [diff] [blame] | 297 | gc::Heap* const heap = Runtime::Current()->GetHeap(); |
| 298 | // Caller's responsibility to do GC if desired. |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 299 | ObjPtr<mirror::Class> c = soa.Decode<mirror::Class>(javaClass); |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 300 | if (c == nullptr) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 301 | return 0; |
| 302 | } |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 303 | VariableSizedHandleScope hs(soa.Self()); |
Mathieu Chartier | 9d156d5 | 2016-10-06 17:44:26 -0700 | [diff] [blame] | 304 | std::vector<Handle<mirror::Class>> classes {hs.NewHandle(c)}; |
Elliott Hughes | ec0f83d | 2013-01-15 16:54:08 -0800 | [diff] [blame] | 305 | uint64_t count = 0; |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 306 | heap->CountInstances(classes, countAssignable, &count); |
Elliott Hughes | ec0f83d | 2013-01-15 16:54:08 -0800 | [diff] [blame] | 307 | return count; |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Mathieu Chartier | 9d156d5 | 2016-10-06 17:44:26 -0700 | [diff] [blame] | 310 | static jlongArray VMDebug_countInstancesOfClasses(JNIEnv* env, |
| 311 | jclass, |
| 312 | jobjectArray javaClasses, |
Mathieu Chartier | f182085 | 2015-07-10 13:19:51 -0700 | [diff] [blame] | 313 | jboolean countAssignable) { |
| 314 | ScopedObjectAccess soa(env); |
| 315 | gc::Heap* const heap = Runtime::Current()->GetHeap(); |
| 316 | // Caller's responsibility to do GC if desired. |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 317 | ObjPtr<mirror::ObjectArray<mirror::Class>> decoded_classes = |
| 318 | soa.Decode<mirror::ObjectArray<mirror::Class>>(javaClasses); |
Mathieu Chartier | f182085 | 2015-07-10 13:19:51 -0700 | [diff] [blame] | 319 | if (decoded_classes == nullptr) { |
| 320 | return nullptr; |
| 321 | } |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 322 | VariableSizedHandleScope hs(soa.Self()); |
Mathieu Chartier | 9d156d5 | 2016-10-06 17:44:26 -0700 | [diff] [blame] | 323 | std::vector<Handle<mirror::Class>> classes; |
Mathieu Chartier | f182085 | 2015-07-10 13:19:51 -0700 | [diff] [blame] | 324 | for (size_t i = 0, count = decoded_classes->GetLength(); i < count; ++i) { |
Mathieu Chartier | 9d156d5 | 2016-10-06 17:44:26 -0700 | [diff] [blame] | 325 | classes.push_back(hs.NewHandle(decoded_classes->Get(i))); |
Mathieu Chartier | f182085 | 2015-07-10 13:19:51 -0700 | [diff] [blame] | 326 | } |
| 327 | std::vector<uint64_t> counts(classes.size(), 0u); |
| 328 | // Heap::CountInstances can handle null and will put 0 for these classes. |
| 329 | heap->CountInstances(classes, countAssignable, &counts[0]); |
Mathieu Chartier | 9d156d5 | 2016-10-06 17:44:26 -0700 | [diff] [blame] | 330 | ObjPtr<mirror::LongArray> long_counts = mirror::LongArray::Alloc(soa.Self(), counts.size()); |
Mathieu Chartier | f182085 | 2015-07-10 13:19:51 -0700 | [diff] [blame] | 331 | if (long_counts == nullptr) { |
| 332 | soa.Self()->AssertPendingOOMException(); |
| 333 | return nullptr; |
| 334 | } |
| 335 | for (size_t i = 0; i < counts.size(); ++i) { |
| 336 | long_counts->Set(i, counts[i]); |
| 337 | } |
| 338 | return soa.AddLocalReference<jlongArray>(long_counts); |
| 339 | } |
| 340 | |
Richard Uhler | 660be6f | 2017-11-22 16:12:29 +0000 | [diff] [blame] | 341 | static jobjectArray VMDebug_getInstancesOfClasses(JNIEnv* env, |
| 342 | jclass, |
| 343 | jobjectArray javaClasses, |
| 344 | jboolean includeAssignable) { |
| 345 | ScopedObjectAccess soa(env); |
| 346 | StackHandleScope<2> hs(soa.Self()); |
| 347 | Handle<mirror::ObjectArray<mirror::Class>> classes = hs.NewHandle( |
| 348 | soa.Decode<mirror::ObjectArray<mirror::Class>>(javaClasses)); |
| 349 | if (classes == nullptr) { |
| 350 | return nullptr; |
| 351 | } |
| 352 | |
| 353 | jclass object_array_class = env->FindClass("[Ljava/lang/Object;"); |
| 354 | if (env->ExceptionCheck() == JNI_TRUE) { |
| 355 | return nullptr; |
| 356 | } |
| 357 | CHECK(object_array_class != nullptr); |
| 358 | |
| 359 | size_t num_classes = classes->GetLength(); |
| 360 | jobjectArray result = env->NewObjectArray(num_classes, object_array_class, nullptr); |
| 361 | if (env->ExceptionCheck() == JNI_TRUE) { |
| 362 | return nullptr; |
| 363 | } |
| 364 | |
| 365 | gc::Heap* const heap = Runtime::Current()->GetHeap(); |
| 366 | MutableHandle<mirror::Class> h_class(hs.NewHandle<mirror::Class>(nullptr)); |
| 367 | for (size_t i = 0; i < num_classes; ++i) { |
| 368 | h_class.Assign(classes->Get(i)); |
| 369 | |
| 370 | VariableSizedHandleScope hs2(soa.Self()); |
| 371 | std::vector<Handle<mirror::Object>> raw_instances; |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 372 | heap->GetInstances(hs2, h_class, includeAssignable, /* max_count= */ 0, raw_instances); |
Richard Uhler | 660be6f | 2017-11-22 16:12:29 +0000 | [diff] [blame] | 373 | jobjectArray array = env->NewObjectArray(raw_instances.size(), |
| 374 | WellKnownClasses::java_lang_Object, |
| 375 | nullptr); |
| 376 | if (env->ExceptionCheck() == JNI_TRUE) { |
| 377 | return nullptr; |
| 378 | } |
| 379 | |
| 380 | for (size_t j = 0; j < raw_instances.size(); ++j) { |
| 381 | env->SetObjectArrayElement(array, j, raw_instances[j].ToJObject()); |
| 382 | } |
| 383 | env->SetObjectArrayElement(result, i, array); |
| 384 | } |
| 385 | return result; |
| 386 | } |
| 387 | |
Hiroshi Yamauchi | 09b07a9 | 2013-07-15 13:17:06 -0700 | [diff] [blame] | 388 | // We export the VM internal per-heap-space size/alloc/free metrics |
| 389 | // for the zygote space, alloc space (application heap), and the large |
| 390 | // object space for dumpsys meminfo. The other memory region data such |
| 391 | // as PSS, private/shared dirty/shared data are available via |
| 392 | // /proc/<pid>/smaps. |
| 393 | static void VMDebug_getHeapSpaceStats(JNIEnv* env, jclass, jlongArray data) { |
Yi Kong | 4b22b34 | 2018-08-02 14:43:21 -0700 | [diff] [blame] | 394 | jlong* arr = reinterpret_cast<jlong*>(env->GetPrimitiveArrayCritical(data, nullptr)); |
Mathieu Chartier | 7410f29 | 2013-11-24 13:17:35 -0800 | [diff] [blame] | 395 | if (arr == nullptr || env->GetArrayLength(data) < 9) { |
Hiroshi Yamauchi | 09b07a9 | 2013-07-15 13:17:06 -0700 | [diff] [blame] | 396 | return; |
| 397 | } |
| 398 | |
| 399 | size_t allocSize = 0; |
| 400 | size_t allocUsed = 0; |
| 401 | size_t zygoteSize = 0; |
| 402 | size_t zygoteUsed = 0; |
| 403 | size_t largeObjectsSize = 0; |
| 404 | size_t largeObjectsUsed = 0; |
Hiroshi Yamauchi | 09b07a9 | 2013-07-15 13:17:06 -0700 | [diff] [blame] | 405 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
Mathieu Chartier | a9d82fe | 2016-01-25 20:06:11 -0800 | [diff] [blame] | 406 | { |
| 407 | ScopedObjectAccess soa(env); |
| 408 | for (gc::space::ContinuousSpace* space : heap->GetContinuousSpaces()) { |
| 409 | if (space->IsImageSpace()) { |
| 410 | // Currently don't include the image space. |
| 411 | } else if (space->IsZygoteSpace()) { |
| 412 | gc::space::ZygoteSpace* zygote_space = space->AsZygoteSpace(); |
| 413 | zygoteSize += zygote_space->Size(); |
| 414 | zygoteUsed += zygote_space->GetBytesAllocated(); |
| 415 | } else if (space->IsMallocSpace()) { |
| 416 | // This is a malloc space. |
| 417 | gc::space::MallocSpace* malloc_space = space->AsMallocSpace(); |
| 418 | allocSize += malloc_space->GetFootprint(); |
| 419 | allocUsed += malloc_space->GetBytesAllocated(); |
| 420 | } else if (space->IsBumpPointerSpace()) { |
| 421 | gc::space::BumpPointerSpace* bump_pointer_space = space->AsBumpPointerSpace(); |
| 422 | allocSize += bump_pointer_space->Size(); |
| 423 | allocUsed += bump_pointer_space->GetBytesAllocated(); |
| 424 | } |
| 425 | } |
| 426 | for (gc::space::DiscontinuousSpace* space : heap->GetDiscontinuousSpaces()) { |
| 427 | if (space->IsLargeObjectSpace()) { |
| 428 | largeObjectsSize += space->AsLargeObjectSpace()->GetBytesAllocated(); |
| 429 | largeObjectsUsed += largeObjectsSize; |
| 430 | } |
Hiroshi Yamauchi | 09b07a9 | 2013-07-15 13:17:06 -0700 | [diff] [blame] | 431 | } |
| 432 | } |
Hiroshi Yamauchi | 09b07a9 | 2013-07-15 13:17:06 -0700 | [diff] [blame] | 433 | size_t allocFree = allocSize - allocUsed; |
| 434 | size_t zygoteFree = zygoteSize - zygoteUsed; |
| 435 | size_t largeObjectsFree = largeObjectsSize - largeObjectsUsed; |
| 436 | |
| 437 | int j = 0; |
| 438 | arr[j++] = allocSize; |
| 439 | arr[j++] = allocUsed; |
| 440 | arr[j++] = allocFree; |
| 441 | arr[j++] = zygoteSize; |
| 442 | arr[j++] = zygoteUsed; |
| 443 | arr[j++] = zygoteFree; |
| 444 | arr[j++] = largeObjectsSize; |
| 445 | arr[j++] = largeObjectsUsed; |
| 446 | arr[j++] = largeObjectsFree; |
| 447 | env->ReleasePrimitiveArrayCritical(data, arr, 0); |
| 448 | } |
| 449 | |
Hiroshi Yamauchi | a1c9f01 | 2015-04-02 10:18:12 -0700 | [diff] [blame] | 450 | // The runtime stat names for VMDebug.getRuntimeStat(). |
| 451 | enum class VMDebugRuntimeStatId { |
| 452 | kArtGcGcCount = 0, |
| 453 | kArtGcGcTime, |
| 454 | kArtGcBytesAllocated, |
| 455 | kArtGcBytesFreed, |
| 456 | kArtGcBlockingGcCount, |
| 457 | kArtGcBlockingGcTime, |
| 458 | kArtGcGcCountRateHistogram, |
| 459 | kArtGcBlockingGcCountRateHistogram, |
| 460 | kNumRuntimeStats, |
| 461 | }; |
| 462 | |
Igor Murashkin | 06537f7 | 2018-02-22 15:03:05 -0800 | [diff] [blame] | 463 | static jstring VMDebug_getRuntimeStatInternal(JNIEnv* env, jclass, jint statId) { |
Hiroshi Yamauchi | a1c9f01 | 2015-04-02 10:18:12 -0700 | [diff] [blame] | 464 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 465 | switch (static_cast<VMDebugRuntimeStatId>(statId)) { |
| 466 | case VMDebugRuntimeStatId::kArtGcGcCount: { |
| 467 | std::string output = std::to_string(heap->GetGcCount()); |
| 468 | return env->NewStringUTF(output.c_str()); |
| 469 | } |
| 470 | case VMDebugRuntimeStatId::kArtGcGcTime: { |
| 471 | std::string output = std::to_string(NsToMs(heap->GetGcTime())); |
| 472 | return env->NewStringUTF(output.c_str()); |
| 473 | } |
| 474 | case VMDebugRuntimeStatId::kArtGcBytesAllocated: { |
| 475 | std::string output = std::to_string(heap->GetBytesAllocatedEver()); |
| 476 | return env->NewStringUTF(output.c_str()); |
| 477 | } |
| 478 | case VMDebugRuntimeStatId::kArtGcBytesFreed: { |
| 479 | std::string output = std::to_string(heap->GetBytesFreedEver()); |
| 480 | return env->NewStringUTF(output.c_str()); |
| 481 | } |
| 482 | case VMDebugRuntimeStatId::kArtGcBlockingGcCount: { |
| 483 | std::string output = std::to_string(heap->GetBlockingGcCount()); |
| 484 | return env->NewStringUTF(output.c_str()); |
| 485 | } |
| 486 | case VMDebugRuntimeStatId::kArtGcBlockingGcTime: { |
| 487 | std::string output = std::to_string(NsToMs(heap->GetBlockingGcTime())); |
| 488 | return env->NewStringUTF(output.c_str()); |
| 489 | } |
| 490 | case VMDebugRuntimeStatId::kArtGcGcCountRateHistogram: { |
| 491 | std::ostringstream output; |
| 492 | heap->DumpGcCountRateHistogram(output); |
| 493 | return env->NewStringUTF(output.str().c_str()); |
| 494 | } |
| 495 | case VMDebugRuntimeStatId::kArtGcBlockingGcCountRateHistogram: { |
| 496 | std::ostringstream output; |
| 497 | heap->DumpBlockingGcCountRateHistogram(output); |
| 498 | return env->NewStringUTF(output.str().c_str()); |
| 499 | } |
| 500 | default: |
| 501 | return nullptr; |
| 502 | } |
| 503 | } |
| 504 | |
Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 505 | static bool SetRuntimeStatValue(JNIEnv* env, |
| 506 | jobjectArray result, |
| 507 | VMDebugRuntimeStatId id, |
| 508 | const std::string& value) { |
Hiroshi Yamauchi | a1c9f01 | 2015-04-02 10:18:12 -0700 | [diff] [blame] | 509 | ScopedLocalRef<jstring> jvalue(env, env->NewStringUTF(value.c_str())); |
| 510 | if (jvalue.get() == nullptr) { |
| 511 | return false; |
| 512 | } |
| 513 | env->SetObjectArrayElement(result, static_cast<jint>(id), jvalue.get()); |
| 514 | return true; |
| 515 | } |
| 516 | |
| 517 | static jobjectArray VMDebug_getRuntimeStatsInternal(JNIEnv* env, jclass) { |
| 518 | jobjectArray result = env->NewObjectArray( |
| 519 | static_cast<jint>(VMDebugRuntimeStatId::kNumRuntimeStats), |
| 520 | WellKnownClasses::java_lang_String, |
| 521 | nullptr); |
| 522 | if (result == nullptr) { |
| 523 | return nullptr; |
| 524 | } |
| 525 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 526 | if (!SetRuntimeStatValue(env, result, VMDebugRuntimeStatId::kArtGcGcCount, |
| 527 | std::to_string(heap->GetGcCount()))) { |
| 528 | return nullptr; |
| 529 | } |
| 530 | if (!SetRuntimeStatValue(env, result, VMDebugRuntimeStatId::kArtGcGcTime, |
| 531 | std::to_string(NsToMs(heap->GetGcTime())))) { |
| 532 | return nullptr; |
| 533 | } |
| 534 | if (!SetRuntimeStatValue(env, result, VMDebugRuntimeStatId::kArtGcBytesAllocated, |
| 535 | std::to_string(heap->GetBytesAllocatedEver()))) { |
| 536 | return nullptr; |
| 537 | } |
| 538 | if (!SetRuntimeStatValue(env, result, VMDebugRuntimeStatId::kArtGcBytesFreed, |
| 539 | std::to_string(heap->GetBytesFreedEver()))) { |
| 540 | return nullptr; |
| 541 | } |
| 542 | if (!SetRuntimeStatValue(env, result, VMDebugRuntimeStatId::kArtGcBlockingGcCount, |
| 543 | std::to_string(heap->GetBlockingGcCount()))) { |
| 544 | return nullptr; |
| 545 | } |
| 546 | if (!SetRuntimeStatValue(env, result, VMDebugRuntimeStatId::kArtGcBlockingGcTime, |
| 547 | std::to_string(NsToMs(heap->GetBlockingGcTime())))) { |
| 548 | return nullptr; |
| 549 | } |
| 550 | { |
| 551 | std::ostringstream output; |
| 552 | heap->DumpGcCountRateHistogram(output); |
| 553 | if (!SetRuntimeStatValue(env, result, VMDebugRuntimeStatId::kArtGcGcCountRateHistogram, |
| 554 | output.str())) { |
| 555 | return nullptr; |
| 556 | } |
| 557 | } |
| 558 | { |
| 559 | std::ostringstream output; |
| 560 | heap->DumpBlockingGcCountRateHistogram(output); |
| 561 | if (!SetRuntimeStatValue(env, result, VMDebugRuntimeStatId::kArtGcBlockingGcCountRateHistogram, |
| 562 | output.str())) { |
| 563 | return nullptr; |
| 564 | } |
| 565 | } |
| 566 | return result; |
| 567 | } |
| 568 | |
Andreas Gampe | 7b38e69 | 2017-12-28 19:18:28 -0800 | [diff] [blame] | 569 | static void VMDebug_nativeAttachAgent(JNIEnv* env, jclass, jstring agent, jobject classloader) { |
Leonard Mosescu | eb84221 | 2016-10-06 17:26:36 -0700 | [diff] [blame] | 570 | if (agent == nullptr) { |
| 571 | ScopedObjectAccess soa(env); |
| 572 | ThrowNullPointerException("agent is null"); |
| 573 | return; |
| 574 | } |
| 575 | |
| 576 | if (!Dbg::IsJdwpAllowed()) { |
| 577 | ScopedObjectAccess soa(env); |
| 578 | ThrowSecurityException("Can't attach agent, process is not debuggable."); |
| 579 | return; |
| 580 | } |
| 581 | |
| 582 | std::string filename; |
| 583 | { |
| 584 | ScopedUtfChars chars(env, agent); |
| 585 | if (env->ExceptionCheck()) { |
| 586 | return; |
| 587 | } |
| 588 | filename = chars.c_str(); |
| 589 | } |
| 590 | |
Andreas Gampe | 7b38e69 | 2017-12-28 19:18:28 -0800 | [diff] [blame] | 591 | Runtime::Current()->AttachAgent(env, filename, classloader); |
Leonard Mosescu | eb84221 | 2016-10-06 17:26:36 -0700 | [diff] [blame] | 592 | } |
| 593 | |
David Brazdil | 59a49a6 | 2018-05-09 10:58:27 +0100 | [diff] [blame] | 594 | static void VMDebug_allowHiddenApiReflectionFrom(JNIEnv* env, jclass, jclass j_caller) { |
| 595 | Runtime* runtime = Runtime::Current(); |
| 596 | ScopedObjectAccess soa(env); |
| 597 | |
| 598 | if (!runtime->IsJavaDebuggable()) { |
| 599 | ThrowSecurityException("Can't exempt class, process is not debuggable."); |
| 600 | return; |
| 601 | } |
| 602 | |
| 603 | StackHandleScope<1> hs(soa.Self()); |
| 604 | Handle<mirror::Class> h_caller(hs.NewHandle(soa.Decode<mirror::Class>(j_caller))); |
| 605 | if (h_caller.IsNull()) { |
| 606 | ThrowNullPointerException("argument is null"); |
| 607 | return; |
| 608 | } |
| 609 | |
| 610 | h_caller->SetSkipHiddenApiChecks(); |
| 611 | } |
| 612 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 613 | static JNINativeMethod gMethods[] = { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 614 | NATIVE_METHOD(VMDebug, countInstancesOfClass, "(Ljava/lang/Class;Z)J"), |
Mathieu Chartier | f182085 | 2015-07-10 13:19:51 -0700 | [diff] [blame] | 615 | NATIVE_METHOD(VMDebug, countInstancesOfClasses, "([Ljava/lang/Class;Z)[J"), |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 616 | NATIVE_METHOD(VMDebug, crash, "()V"), |
Andreas Gampe | ad5df10 | 2017-10-04 16:31:08 -0700 | [diff] [blame] | 617 | NATIVE_METHOD(VMDebug, dumpHprofData, "(Ljava/lang/String;I)V"), |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 618 | NATIVE_METHOD(VMDebug, dumpHprofDataDdms, "()V"), |
| 619 | NATIVE_METHOD(VMDebug, dumpReferenceTables, "()V"), |
| 620 | NATIVE_METHOD(VMDebug, getAllocCount, "(I)I"), |
Hiroshi Yamauchi | 09b07a9 | 2013-07-15 13:17:06 -0700 | [diff] [blame] | 621 | NATIVE_METHOD(VMDebug, getHeapSpaceStats, "([J)V"), |
Richard Uhler | 660be6f | 2017-11-22 16:12:29 +0000 | [diff] [blame] | 622 | NATIVE_METHOD(VMDebug, getInstancesOfClasses, "([Ljava/lang/Class;Z)[[Ljava/lang/Object;"), |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 623 | NATIVE_METHOD(VMDebug, getInstructionCount, "([I)V"), |
Igor Murashkin | 3b6f440 | 2017-02-16 16:13:17 -0800 | [diff] [blame] | 624 | FAST_NATIVE_METHOD(VMDebug, getLoadedClassCount, "()I"), |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 625 | NATIVE_METHOD(VMDebug, getVmFeatureList, "()[Ljava/lang/String;"), |
| 626 | NATIVE_METHOD(VMDebug, infopoint, "(I)V"), |
Igor Murashkin | 3b6f440 | 2017-02-16 16:13:17 -0800 | [diff] [blame] | 627 | FAST_NATIVE_METHOD(VMDebug, isDebuggerConnected, "()Z"), |
| 628 | FAST_NATIVE_METHOD(VMDebug, isDebuggingEnabled, "()Z"), |
Jeff Hao | 64caa7d | 2013-08-29 11:18:01 -0700 | [diff] [blame] | 629 | NATIVE_METHOD(VMDebug, getMethodTracingMode, "()I"), |
Igor Murashkin | 3b6f440 | 2017-02-16 16:13:17 -0800 | [diff] [blame] | 630 | FAST_NATIVE_METHOD(VMDebug, lastDebuggerActivity, "()J"), |
| 631 | FAST_NATIVE_METHOD(VMDebug, printLoadedClasses, "(I)V"), |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 632 | NATIVE_METHOD(VMDebug, resetAllocCount, "(I)V"), |
| 633 | NATIVE_METHOD(VMDebug, resetInstructionCount, "()V"), |
| 634 | NATIVE_METHOD(VMDebug, startAllocCounting, "()V"), |
| 635 | NATIVE_METHOD(VMDebug, startEmulatorTracing, "()V"), |
| 636 | NATIVE_METHOD(VMDebug, startInstructionCounting, "()V"), |
Jeff Hao | 23009dc | 2013-08-22 15:36:42 -0700 | [diff] [blame] | 637 | NATIVE_METHOD(VMDebug, startMethodTracingDdmsImpl, "(IIZI)V"), |
Andreas Gampe | ad5df10 | 2017-10-04 16:31:08 -0700 | [diff] [blame] | 638 | NATIVE_METHOD(VMDebug, startMethodTracingFd, "(Ljava/lang/String;IIIZIZ)V"), |
Jeff Hao | 4044bda | 2014-01-06 15:50:45 -0800 | [diff] [blame] | 639 | NATIVE_METHOD(VMDebug, startMethodTracingFilename, "(Ljava/lang/String;IIZI)V"), |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 640 | NATIVE_METHOD(VMDebug, stopAllocCounting, "()V"), |
| 641 | NATIVE_METHOD(VMDebug, stopEmulatorTracing, "()V"), |
| 642 | NATIVE_METHOD(VMDebug, stopInstructionCounting, "()V"), |
| 643 | NATIVE_METHOD(VMDebug, stopMethodTracing, "()V"), |
Igor Murashkin | 3b6f440 | 2017-02-16 16:13:17 -0800 | [diff] [blame] | 644 | FAST_NATIVE_METHOD(VMDebug, threadCpuTimeNanos, "()J"), |
Hiroshi Yamauchi | a1c9f01 | 2015-04-02 10:18:12 -0700 | [diff] [blame] | 645 | NATIVE_METHOD(VMDebug, getRuntimeStatInternal, "(I)Ljava/lang/String;"), |
Leonard Mosescu | eb84221 | 2016-10-06 17:26:36 -0700 | [diff] [blame] | 646 | NATIVE_METHOD(VMDebug, getRuntimeStatsInternal, "()[Ljava/lang/String;"), |
Andreas Gampe | 7b38e69 | 2017-12-28 19:18:28 -0800 | [diff] [blame] | 647 | NATIVE_METHOD(VMDebug, nativeAttachAgent, "(Ljava/lang/String;Ljava/lang/ClassLoader;)V"), |
David Brazdil | 59a49a6 | 2018-05-09 10:58:27 +0100 | [diff] [blame] | 648 | NATIVE_METHOD(VMDebug, allowHiddenApiReflectionFrom, "(Ljava/lang/Class;)V"), |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 649 | }; |
| 650 | |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 651 | void register_dalvik_system_VMDebug(JNIEnv* env) { |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 652 | REGISTER_NATIVE_METHODS("dalvik/system/VMDebug"); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | } // namespace art |