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 | |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 17 | #include <string.h> |
| 18 | #include <unistd.h> |
| 19 | |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 20 | #include "class_linker.h" |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 21 | #include "common_throws.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 22 | #include "debugger.h" |
Mathieu Chartier | 7410f29 | 2013-11-24 13:17:35 -0800 | [diff] [blame^] | 23 | #include "gc/space/bump_pointer_space.h" |
Hiroshi Yamauchi | 09b07a9 | 2013-07-15 13:17:06 -0700 | [diff] [blame] | 24 | #include "gc/space/dlmalloc_space.h" |
| 25 | #include "gc/space/large_object_space.h" |
| 26 | #include "gc/space/space-inl.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 27 | #include "hprof/hprof.h" |
| 28 | #include "jni_internal.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 29 | #include "mirror/class.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 30 | #include "ScopedUtfChars.h" |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 31 | #include "scoped_thread_state_change.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 32 | #include "toStringArray.h" |
| 33 | #include "trace.h" |
| 34 | |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 35 | namespace art { |
| 36 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 37 | static jobjectArray VMDebug_getVmFeatureList(JNIEnv* env, jclass) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 38 | std::vector<std::string> features; |
jeffhao | e343b76 | 2011-12-05 16:36:44 -0800 | [diff] [blame] | 39 | features.push_back("method-trace-profiling"); |
| 40 | features.push_back("method-trace-profiling-streaming"); |
Jeff Hao | 23009dc | 2013-08-22 15:36:42 -0700 | [diff] [blame] | 41 | features.push_back("method-sample-profiling"); |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 42 | features.push_back("hprof-heap-dump"); |
| 43 | features.push_back("hprof-heap-dump-streaming"); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 44 | return toStringArray(env, features); |
| 45 | } |
| 46 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 47 | static void VMDebug_startAllocCounting(JNIEnv*, jclass) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 48 | Runtime::Current()->SetStatsEnabled(true); |
| 49 | } |
| 50 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 51 | static void VMDebug_stopAllocCounting(JNIEnv*, jclass) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 52 | Runtime::Current()->SetStatsEnabled(false); |
| 53 | } |
| 54 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 55 | static jint VMDebug_getAllocCount(JNIEnv*, jclass, jint kind) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 56 | return Runtime::Current()->GetStat(kind); |
| 57 | } |
| 58 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 59 | static void VMDebug_resetAllocCount(JNIEnv*, jclass, jint kinds) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 60 | Runtime::Current()->ResetStats(kinds); |
| 61 | } |
| 62 | |
Jeff Hao | 23009dc | 2013-08-22 15:36:42 -0700 | [diff] [blame] | 63 | static void VMDebug_startMethodTracingDdmsImpl(JNIEnv*, jclass, jint bufferSize, jint flags, |
| 64 | jboolean samplingEnabled, jint intervalUs) { |
| 65 | Trace::Start("[DDMS]", -1, bufferSize, flags, true, samplingEnabled, intervalUs); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 68 | static void VMDebug_startMethodTracingFd(JNIEnv* env, jclass, jstring javaTraceFilename, |
| 69 | jobject javaFd, jint bufferSize, jint flags) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 70 | int originalFd = jniGetFDFromFileDescriptor(env, javaFd); |
| 71 | if (originalFd < 0) { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | int fd = dup(originalFd); |
| 76 | if (fd < 0) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 77 | ScopedObjectAccess soa(env); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 78 | ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow(); |
| 79 | soa.Self()->ThrowNewExceptionF(throw_location, "Ljava/lang/RuntimeException;", |
| 80 | "dup(%d) failed: %s", originalFd, strerror(errno)); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 81 | return; |
| 82 | } |
| 83 | |
| 84 | ScopedUtfChars traceFilename(env, javaTraceFilename); |
| 85 | if (traceFilename.c_str() == NULL) { |
| 86 | return; |
| 87 | } |
Jeff Hao | 23009dc | 2013-08-22 15:36:42 -0700 | [diff] [blame] | 88 | Trace::Start(traceFilename.c_str(), fd, bufferSize, flags, false, false, 0); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 91 | static void VMDebug_startMethodTracingFilename(JNIEnv* env, jclass, jstring javaTraceFilename, |
| 92 | jint bufferSize, jint flags) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 93 | ScopedUtfChars traceFilename(env, javaTraceFilename); |
| 94 | if (traceFilename.c_str() == NULL) { |
| 95 | return; |
| 96 | } |
Jeff Hao | 23009dc | 2013-08-22 15:36:42 -0700 | [diff] [blame] | 97 | Trace::Start(traceFilename.c_str(), -1, bufferSize, flags, false, false, 0); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Jeff Hao | 64caa7d | 2013-08-29 11:18:01 -0700 | [diff] [blame] | 100 | static jint VMDebug_getMethodTracingMode(JNIEnv*, jclass) { |
| 101 | return Trace::GetMethodTracingMode(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 104 | static void VMDebug_stopMethodTracing(JNIEnv*, jclass) { |
jeffhao | e343b76 | 2011-12-05 16:36:44 -0800 | [diff] [blame] | 105 | Trace::Stop(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 108 | static void VMDebug_startEmulatorTracing(JNIEnv*, jclass) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 109 | UNIMPLEMENTED(WARNING); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 110 | // dvmEmulatorTraceStart(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 113 | static void VMDebug_stopEmulatorTracing(JNIEnv*, jclass) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 114 | UNIMPLEMENTED(WARNING); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 115 | // dvmEmulatorTraceStop(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 118 | static jboolean VMDebug_isDebuggerConnected(JNIEnv*, jclass) { |
Elliott Hughes | c0f0933 | 2012-03-26 13:27:06 -0700 | [diff] [blame] | 119 | return Dbg::IsDebuggerActive(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 122 | static jboolean VMDebug_isDebuggingEnabled(JNIEnv*, jclass) { |
Elliott Hughes | c0f0933 | 2012-03-26 13:27:06 -0700 | [diff] [blame] | 123 | return Dbg::IsJdwpConfigured(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 126 | static jlong VMDebug_lastDebuggerActivity(JNIEnv*, jclass) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 127 | return Dbg::LastDebuggerActivity(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 130 | static void ThrowUnsupportedOperationException(JNIEnv* env) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 131 | ScopedObjectAccess soa(env); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 132 | ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow(); |
| 133 | soa.Self()->ThrowNewException(throw_location, "Ljava/lang/UnsupportedOperationException;", NULL); |
| 134 | } |
| 135 | |
| 136 | static void VMDebug_startInstructionCounting(JNIEnv* env, jclass) { |
| 137 | ThrowUnsupportedOperationException(env); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 140 | static void VMDebug_stopInstructionCounting(JNIEnv* env, jclass) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 141 | ThrowUnsupportedOperationException(env); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 144 | static void VMDebug_getInstructionCount(JNIEnv* env, jclass, jintArray /*javaCounts*/) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 145 | ThrowUnsupportedOperationException(env); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 148 | static void VMDebug_resetInstructionCount(JNIEnv* env, jclass) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 149 | ThrowUnsupportedOperationException(env); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 152 | static void VMDebug_printLoadedClasses(JNIEnv* env, jclass, jint flags) { |
| 153 | ScopedObjectAccess soa(env); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 154 | return Runtime::Current()->GetClassLinker()->DumpAllClasses(flags); |
| 155 | } |
| 156 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 157 | static jint VMDebug_getLoadedClassCount(JNIEnv* env, jclass) { |
| 158 | ScopedObjectAccess soa(env); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 159 | return Runtime::Current()->GetClassLinker()->NumLoadedClasses(); |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * Returns the thread-specific CPU-time clock value for the current thread, |
| 164 | * or -1 if the feature isn't supported. |
| 165 | */ |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 166 | static jlong VMDebug_threadCpuTimeNanos(JNIEnv*, jclass) { |
| 167 | return ThreadCpuNanoTime(); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /* |
| 171 | * static void dumpHprofData(String fileName, FileDescriptor fd) |
| 172 | * |
| 173 | * Cause "hprof" data to be dumped. We can throw an IOException if an |
| 174 | * error occurs during file handling. |
| 175 | */ |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 176 | static void VMDebug_dumpHprofData(JNIEnv* env, jclass, jstring javaFilename, jobject javaFd) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 177 | // Only one of these may be NULL. |
| 178 | if (javaFilename == NULL && javaFd == NULL) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 179 | ScopedObjectAccess soa(env); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 180 | ThrowNullPointerException(NULL, "fileName == null && fd == null"); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 181 | return; |
| 182 | } |
| 183 | |
| 184 | std::string filename; |
| 185 | if (javaFilename != NULL) { |
| 186 | ScopedUtfChars chars(env, javaFilename); |
| 187 | if (env->ExceptionCheck()) { |
| 188 | return; |
| 189 | } |
| 190 | filename = chars.c_str(); |
| 191 | } else { |
| 192 | filename = "[fd]"; |
| 193 | } |
| 194 | |
| 195 | int fd = -1; |
| 196 | if (javaFd != NULL) { |
| 197 | fd = jniGetFDFromFileDescriptor(env, javaFd); |
| 198 | if (fd < 0) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 199 | ScopedObjectAccess soa(env); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 200 | ThrowRuntimeException("Invalid file descriptor"); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 201 | return; |
| 202 | } |
| 203 | } |
| 204 | |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 205 | hprof::DumpHeap(filename.c_str(), fd, false); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 208 | static void VMDebug_dumpHprofDataDdms(JNIEnv*, jclass) { |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 209 | hprof::DumpHeap("[DDMS]", -1, true); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 212 | static void VMDebug_dumpReferenceTables(JNIEnv* env, jclass) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 213 | ScopedObjectAccess soa(env); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 214 | LOG(INFO) << "--- reference table dump ---"; |
| 215 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 216 | soa.Env()->DumpReferenceTables(LOG(INFO)); |
| 217 | soa.Vm()->DumpReferenceTables(LOG(INFO)); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 218 | |
| 219 | LOG(INFO) << "---"; |
| 220 | } |
| 221 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 222 | static void VMDebug_crash(JNIEnv*, jclass) { |
Elliott Hughes | 81ff318 | 2012-03-23 20:35:56 -0700 | [diff] [blame] | 223 | LOG(FATAL) << "Crashing runtime on request"; |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 226 | static void VMDebug_infopoint(JNIEnv*, jclass, jint id) { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 227 | LOG(INFO) << "VMDebug infopoint " << id << " hit"; |
| 228 | } |
| 229 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 230 | static jlong VMDebug_countInstancesOfClass(JNIEnv* env, jclass, jclass javaClass, |
| 231 | jboolean countAssignable) { |
| 232 | ScopedObjectAccess soa(env); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 233 | mirror::Class* c = soa.Decode<mirror::Class*>(javaClass); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 234 | if (c == NULL) { |
| 235 | return 0; |
| 236 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 237 | std::vector<mirror::Class*> classes; |
Elliott Hughes | ec0f83d | 2013-01-15 16:54:08 -0800 | [diff] [blame] | 238 | classes.push_back(c); |
| 239 | uint64_t count = 0; |
| 240 | Runtime::Current()->GetHeap()->CountInstances(classes, countAssignable, &count); |
| 241 | return count; |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Hiroshi Yamauchi | 09b07a9 | 2013-07-15 13:17:06 -0700 | [diff] [blame] | 244 | // We export the VM internal per-heap-space size/alloc/free metrics |
| 245 | // for the zygote space, alloc space (application heap), and the large |
| 246 | // object space for dumpsys meminfo. The other memory region data such |
| 247 | // as PSS, private/shared dirty/shared data are available via |
| 248 | // /proc/<pid>/smaps. |
| 249 | static void VMDebug_getHeapSpaceStats(JNIEnv* env, jclass, jlongArray data) { |
Ian Rogers | 6b99dd1 | 2013-07-25 12:11:32 -0700 | [diff] [blame] | 250 | jlong* arr = reinterpret_cast<jlong*>(env->GetPrimitiveArrayCritical(data, 0)); |
Mathieu Chartier | 7410f29 | 2013-11-24 13:17:35 -0800 | [diff] [blame^] | 251 | if (arr == nullptr || env->GetArrayLength(data) < 9) { |
Hiroshi Yamauchi | 09b07a9 | 2013-07-15 13:17:06 -0700 | [diff] [blame] | 252 | return; |
| 253 | } |
| 254 | |
| 255 | size_t allocSize = 0; |
| 256 | size_t allocUsed = 0; |
| 257 | size_t zygoteSize = 0; |
| 258 | size_t zygoteUsed = 0; |
| 259 | size_t largeObjectsSize = 0; |
| 260 | size_t largeObjectsUsed = 0; |
Hiroshi Yamauchi | 09b07a9 | 2013-07-15 13:17:06 -0700 | [diff] [blame] | 261 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
Mathieu Chartier | 7410f29 | 2013-11-24 13:17:35 -0800 | [diff] [blame^] | 262 | for (gc::space::ContinuousSpace* space : heap->GetContinuousSpaces()) { |
Hiroshi Yamauchi | 09b07a9 | 2013-07-15 13:17:06 -0700 | [diff] [blame] | 263 | if (space->IsImageSpace()) { |
| 264 | // Currently don't include the image space. |
| 265 | } else if (space->IsZygoteSpace()) { |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 266 | gc::space::MallocSpace* malloc_space = space->AsMallocSpace(); |
| 267 | zygoteSize += malloc_space->GetFootprint(); |
| 268 | zygoteUsed += malloc_space->GetBytesAllocated(); |
Mathieu Chartier | 7410f29 | 2013-11-24 13:17:35 -0800 | [diff] [blame^] | 269 | } else if (space->IsMallocSpace()) { |
| 270 | // This is a malloc space. |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 271 | gc::space::MallocSpace* malloc_space = space->AsMallocSpace(); |
| 272 | allocSize += malloc_space->GetFootprint(); |
| 273 | allocUsed += malloc_space->GetBytesAllocated(); |
Mathieu Chartier | 7410f29 | 2013-11-24 13:17:35 -0800 | [diff] [blame^] | 274 | } else if (space->IsBumpPointerSpace()) { |
| 275 | gc::space::BumpPointerSpace* bump_pointer_space = space->AsBumpPointerSpace(); |
| 276 | allocSize += bump_pointer_space->Size(); |
| 277 | allocUsed += bump_pointer_space->GetBytesAllocated(); |
Hiroshi Yamauchi | 09b07a9 | 2013-07-15 13:17:06 -0700 | [diff] [blame] | 278 | } |
| 279 | } |
Mathieu Chartier | 7410f29 | 2013-11-24 13:17:35 -0800 | [diff] [blame^] | 280 | for (gc::space::DiscontinuousSpace* space : heap->GetDiscontinuousSpaces()) { |
Hiroshi Yamauchi | 09b07a9 | 2013-07-15 13:17:06 -0700 | [diff] [blame] | 281 | if (space->IsLargeObjectSpace()) { |
| 282 | largeObjectsSize += space->AsLargeObjectSpace()->GetBytesAllocated(); |
| 283 | largeObjectsUsed += largeObjectsSize; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | size_t allocFree = allocSize - allocUsed; |
| 288 | size_t zygoteFree = zygoteSize - zygoteUsed; |
| 289 | size_t largeObjectsFree = largeObjectsSize - largeObjectsUsed; |
| 290 | |
| 291 | int j = 0; |
| 292 | arr[j++] = allocSize; |
| 293 | arr[j++] = allocUsed; |
| 294 | arr[j++] = allocFree; |
| 295 | arr[j++] = zygoteSize; |
| 296 | arr[j++] = zygoteUsed; |
| 297 | arr[j++] = zygoteFree; |
| 298 | arr[j++] = largeObjectsSize; |
| 299 | arr[j++] = largeObjectsUsed; |
| 300 | arr[j++] = largeObjectsFree; |
| 301 | env->ReleasePrimitiveArrayCritical(data, arr, 0); |
| 302 | } |
| 303 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 304 | static JNINativeMethod gMethods[] = { |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 305 | NATIVE_METHOD(VMDebug, countInstancesOfClass, "(Ljava/lang/Class;Z)J"), |
| 306 | NATIVE_METHOD(VMDebug, crash, "()V"), |
| 307 | NATIVE_METHOD(VMDebug, dumpHprofData, "(Ljava/lang/String;Ljava/io/FileDescriptor;)V"), |
| 308 | NATIVE_METHOD(VMDebug, dumpHprofDataDdms, "()V"), |
| 309 | NATIVE_METHOD(VMDebug, dumpReferenceTables, "()V"), |
| 310 | NATIVE_METHOD(VMDebug, getAllocCount, "(I)I"), |
Hiroshi Yamauchi | 09b07a9 | 2013-07-15 13:17:06 -0700 | [diff] [blame] | 311 | NATIVE_METHOD(VMDebug, getHeapSpaceStats, "([J)V"), |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 312 | NATIVE_METHOD(VMDebug, getInstructionCount, "([I)V"), |
| 313 | NATIVE_METHOD(VMDebug, getLoadedClassCount, "()I"), |
| 314 | NATIVE_METHOD(VMDebug, getVmFeatureList, "()[Ljava/lang/String;"), |
| 315 | NATIVE_METHOD(VMDebug, infopoint, "(I)V"), |
| 316 | NATIVE_METHOD(VMDebug, isDebuggerConnected, "()Z"), |
| 317 | NATIVE_METHOD(VMDebug, isDebuggingEnabled, "()Z"), |
Jeff Hao | 64caa7d | 2013-08-29 11:18:01 -0700 | [diff] [blame] | 318 | NATIVE_METHOD(VMDebug, getMethodTracingMode, "()I"), |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 319 | NATIVE_METHOD(VMDebug, lastDebuggerActivity, "()J"), |
| 320 | NATIVE_METHOD(VMDebug, printLoadedClasses, "(I)V"), |
| 321 | NATIVE_METHOD(VMDebug, resetAllocCount, "(I)V"), |
| 322 | NATIVE_METHOD(VMDebug, resetInstructionCount, "()V"), |
| 323 | NATIVE_METHOD(VMDebug, startAllocCounting, "()V"), |
| 324 | NATIVE_METHOD(VMDebug, startEmulatorTracing, "()V"), |
| 325 | NATIVE_METHOD(VMDebug, startInstructionCounting, "()V"), |
Jeff Hao | 23009dc | 2013-08-22 15:36:42 -0700 | [diff] [blame] | 326 | NATIVE_METHOD(VMDebug, startMethodTracingDdmsImpl, "(IIZI)V"), |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 327 | NATIVE_METHOD(VMDebug, startMethodTracingFd, "(Ljava/lang/String;Ljava/io/FileDescriptor;II)V"), |
| 328 | NATIVE_METHOD(VMDebug, startMethodTracingFilename, "(Ljava/lang/String;II)V"), |
| 329 | NATIVE_METHOD(VMDebug, stopAllocCounting, "()V"), |
| 330 | NATIVE_METHOD(VMDebug, stopEmulatorTracing, "()V"), |
| 331 | NATIVE_METHOD(VMDebug, stopInstructionCounting, "()V"), |
| 332 | NATIVE_METHOD(VMDebug, stopMethodTracing, "()V"), |
| 333 | NATIVE_METHOD(VMDebug, threadCpuTimeNanos, "()J"), |
| 334 | }; |
| 335 | |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 336 | void register_dalvik_system_VMDebug(JNIEnv* env) { |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 337 | REGISTER_NATIVE_METHODS("dalvik/system/VMDebug"); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | } // namespace art |