1 /* 2 * Copyright (C) 2007 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 17 package dalvik.system; 18 19 import static android.annotation.SystemApi.Client.MODULE_LIBRARIES; 20 21 import android.annotation.SystemApi; 22 import android.compat.annotation.UnsupportedAppUsage; 23 24 import java.io.FileDescriptor; 25 import java.io.IOException; 26 import java.util.HashMap; 27 import java.util.Map; 28 29 import dalvik.annotation.optimization.FastNative; 30 31 /** 32 * Provides access to some VM-specific debug features. Though this class and 33 * many of its members are public, this class is meant to be wrapped in a more 34 * friendly way for use by application developers. On the Android platform, the 35 * recommended way to access this functionality is through the class 36 * <code>android.os.Debug</code>. 37 * 38 * @hide 39 */ 40 @SystemApi(client = MODULE_LIBRARIES) 41 public final class VMDebug { 42 /** 43 * flag for startMethodTracing(), which adds the results from 44 * startAllocCounting to the trace key file. 45 * 46 * @hide 47 */ 48 @SystemApi(client = MODULE_LIBRARIES) 49 // Must match android.os.Debug.TRACE_COUNT_ALLOCS. 50 public static final int TRACE_COUNT_ALLOCS = 1; 51 52 /* constants for getAllocCount */ 53 private static final int KIND_ALLOCATED_OBJECTS = 1<<0; 54 private static final int KIND_ALLOCATED_BYTES = 1<<1; 55 private static final int KIND_FREED_OBJECTS = 1<<2; 56 private static final int KIND_FREED_BYTES = 1<<3; 57 private static final int KIND_GC_INVOCATIONS = 1<<4; 58 private static final int KIND_CLASS_INIT_COUNT = 1<<5; 59 private static final int KIND_CLASS_INIT_TIME = 1<<6; 60 private static final int KIND_EXT_ALLOCATED_OBJECTS = 1<<12; 61 private static final int KIND_EXT_ALLOCATED_BYTES = 1<<13; 62 private static final int KIND_EXT_FREED_OBJECTS = 1<<14; 63 private static final int KIND_EXT_FREED_BYTES = 1<<15; 64 65 /** 66 * Constant for {@link #getAllocCount(int)} 67 * to get the number of all allocated objects. 68 * 69 * @hide 70 */ 71 @SystemApi(client = MODULE_LIBRARIES) 72 public static final int KIND_GLOBAL_ALLOCATED_OBJECTS = 73 KIND_ALLOCATED_OBJECTS; 74 75 /** 76 * Constant for {@link #getAllocCount(int)} 77 * to get the cumulative size of all objects allocated. 78 * 79 * @hide 80 */ 81 @SystemApi(client = MODULE_LIBRARIES) 82 public static final int KIND_GLOBAL_ALLOCATED_BYTES = 83 KIND_ALLOCATED_BYTES; 84 85 /** 86 * Constant for {@link #getAllocCount(int)} 87 * to get the number of freed objects. 88 * 89 * @hide 90 */ 91 @SystemApi(client = MODULE_LIBRARIES) 92 public static final int KIND_GLOBAL_FREED_OBJECTS = 93 KIND_FREED_OBJECTS; 94 95 /** 96 * Constant for {@link #getAllocCount(int)} 97 * to get the cumulative size of all freed objects. 98 * 99 * @hide 100 */ 101 @SystemApi(client = MODULE_LIBRARIES) 102 public static final int KIND_GLOBAL_FREED_BYTES = 103 KIND_FREED_BYTES; 104 105 /** 106 * Constant for {@link #getAllocCount(int)} 107 * to get the number of times an allocation triggered a blocking GC. 108 * 109 * @hide 110 */ 111 @SystemApi(client = MODULE_LIBRARIES) 112 public static final int KIND_GLOBAL_GC_INVOCATIONS = 113 KIND_GC_INVOCATIONS; 114 115 /** 116 * Constant for {@link #getAllocCount(int)} 117 * to get the number of initialized classes. 118 * 119 * @hide 120 */ 121 @SystemApi(client = MODULE_LIBRARIES) 122 public static final int KIND_GLOBAL_CLASS_INIT_COUNT = 123 KIND_CLASS_INIT_COUNT; 124 125 /** 126 * Constant for {@link #getAllocCount(int)} 127 * to get the cumulative time spent in class initialization. 128 * 129 * @hide 130 */ 131 @SystemApi(client = MODULE_LIBRARIES) 132 public static final int KIND_GLOBAL_CLASS_INIT_TIME = 133 KIND_CLASS_INIT_TIME; 134 135 /** 136 * Constant for {@link #getAllocCount(int)} 137 * to get the number of all allocated objects for current thread. 138 * 139 * @hide 140 */ 141 @SystemApi(client = MODULE_LIBRARIES) 142 public static final int KIND_THREAD_ALLOCATED_OBJECTS = 143 KIND_ALLOCATED_OBJECTS << 16; 144 145 /** 146 * Constant for {@link #getAllocCount(int)} 147 * to get the cumulative size of all objects allocated for current thread. 148 * 149 * @hide 150 */ 151 @SystemApi(client = MODULE_LIBRARIES) 152 public static final int KIND_THREAD_ALLOCATED_BYTES = 153 KIND_ALLOCATED_BYTES << 16; 154 155 /** 156 * Constant for {@link #getAllocCount(int)} 157 * to get the number of times an allocation triggered a blocking GC for current thread. 158 * 159 * @hide 160 */ 161 @SystemApi(client = MODULE_LIBRARIES) 162 public static final int KIND_THREAD_GC_INVOCATIONS = 163 KIND_GC_INVOCATIONS << 16; 164 165 /** 166 * Constant for {@link #getAllocCount(int)} to get all possible stats. 167 * 168 * @hide 169 */ 170 @SystemApi(client = MODULE_LIBRARIES) 171 public static final int KIND_ALL_COUNTS = 0xffffffff; 172 173 /* all methods are static */ VMDebug()174 private VMDebug() {} 175 176 /** 177 * Returns the time since the last known debugger activity. 178 * 179 * @return the time in milliseconds, or -1 if the debugger is not connected 180 * 181 * @hide 182 */ 183 @SystemApi(client = MODULE_LIBRARIES) 184 @FastNative lastDebuggerActivity()185 public static native long lastDebuggerActivity(); 186 187 /** 188 * Determines if debugging is enabled in this VM. If debugging is not 189 * enabled, a debugger cannot be attached. 190 * 191 * @return true if debugging is enabled 192 * 193 * @hide 194 */ 195 @SystemApi(client = MODULE_LIBRARIES) 196 @FastNative isDebuggingEnabled()197 public static native boolean isDebuggingEnabled(); 198 199 /** 200 * Determines if a debugger is currently attached. 201 * 202 * @return true if (and only if) a debugger is connected 203 * 204 * @hide 205 */ 206 @UnsupportedAppUsage 207 @SystemApi(client = MODULE_LIBRARIES) 208 @FastNative isDebuggerConnected()209 public static native boolean isDebuggerConnected(); 210 211 /** 212 * Returns an array of strings that identify VM features. This is 213 * used by DDMS to determine what sorts of operations the VM can 214 * perform. 215 * 216 * @return array of strings identifying VM features 217 * 218 * @hide 219 */ 220 @SystemApi(client = MODULE_LIBRARIES) getVmFeatureList()221 public static native String[] getVmFeatureList(); 222 223 /** 224 * Start method tracing, specifying a file name as well as a default 225 * buffer size. See <a 226 * href="{@docRoot}guide/developing/tools/traceview.html"> Running the 227 * Traceview Debugging Program</a> for information about reading 228 * trace files. 229 * 230 * <p>You can use either a fully qualified path and 231 * name, or just a name. If only a name is specified, the file will 232 * be created under the /sdcard/ directory. If a name is not given, 233 * the default is /sdcard/dmtrace.trace.</p> 234 * 235 * @param traceFileName name to give the trace file 236 * @param bufferSize the maximum size of both files combined. If passed 237 * as {@code 0}, it defaults to 8MB. 238 * @param flags flags to control method tracing. The only one that 239 * is currently defined is {@link #TRACE_COUNT_ALLOCS}. 240 * @param samplingEnabled if true, sample profiling is enabled. Otherwise, 241 * method instrumentation is used. 242 * @param intervalUs the time between samples in microseconds when 243 * sampling is enabled. 244 * 245 * @hide 246 */ 247 @SystemApi(client = MODULE_LIBRARIES) startMethodTracing(String traceFileName, int bufferSize, int flags, boolean samplingEnabled, int intervalUs)248 public static void startMethodTracing(String traceFileName, int bufferSize, int flags, boolean samplingEnabled, int intervalUs) { 249 startMethodTracingFilename(traceFileName, checkBufferSize(bufferSize), flags, samplingEnabled, intervalUs); 250 } 251 252 /** 253 * Like {@link #startMethodTracing(String, int, int)}, but taking an already-opened 254 * {@code FileDescriptor} in which the trace is written. The file name is also 255 * supplied simply for logging. Makes a dup of the file descriptor. 256 * Streams tracing data to the file if streamingOutput is true. 257 * 258 * @param traceFileName name to give the trace file 259 * @param fd already opened {@code FileDescriptor} in which trace is written 260 * @param bufferSize the maximum size of both files combined. If passed 261 * as {@code 0}, it defaults to 8MB. 262 * @param flags flags to control method tracing. The only one that 263 * is currently defined is {@link #TRACE_COUNT_ALLOCS}. 264 * @param samplingEnabled if true, sample profiling is enabled. Otherwise, 265 * method instrumentation is used. 266 * @param intervalUs the time between samples in microseconds when 267 * sampling is enabled. 268 * @param streamingOutput streams tracing data to the duped {@code fd} file descriptor 269 * if {@code streamingOutput} is {@code true}. 270 * 271 * @hide 272 */ 273 @SystemApi(client = MODULE_LIBRARIES) startMethodTracing(String traceFileName, FileDescriptor fd, int bufferSize, int flags, boolean samplingEnabled, int intervalUs, boolean streamingOutput)274 public static void startMethodTracing(String traceFileName, FileDescriptor fd, int bufferSize, 275 int flags, boolean samplingEnabled, int intervalUs, 276 boolean streamingOutput) { 277 if (fd == null) { 278 throw new NullPointerException("fd == null"); 279 } 280 startMethodTracingFd(traceFileName, fd.getInt$(), checkBufferSize(bufferSize), flags, 281 samplingEnabled, intervalUs, streamingOutput); 282 } 283 284 /** 285 * Starts method tracing without a backing file. When {@link #stopMethodTracing()} 286 * is called, the result is sent directly to DDMS. (If DDMS is not 287 * attached when tracing ends, the profiling data will be discarded.) 288 * 289 * @param bufferSize the maximum size of both files combined. If passed 290 * as {@code 0}, it defaults to 8MB. 291 * @param flags flags to control method tracing. The only one that 292 * is currently defined is {@link #TRACE_COUNT_ALLOCS}. 293 * @param samplingEnabled if true, sample profiling is enabled. Otherwise, 294 * method instrumentation is used. 295 * @param intervalUs the time between samples in microseconds when 296 * sampling is enabled. 297 * 298 * @hide 299 */ 300 @SystemApi(client = MODULE_LIBRARIES) startMethodTracingDdms(int bufferSize, int flags, boolean samplingEnabled, int intervalUs)301 public static void startMethodTracingDdms(int bufferSize, int flags, boolean samplingEnabled, int intervalUs) { 302 startMethodTracingDdmsImpl(checkBufferSize(bufferSize), flags, samplingEnabled, intervalUs); 303 } 304 checkBufferSize(int bufferSize)305 private static int checkBufferSize(int bufferSize) { 306 if (bufferSize == 0) { 307 // Default to 8MB per the documentation. 308 bufferSize = 8 * 1024 * 1024; 309 } 310 if (bufferSize < 1024) { 311 throw new IllegalArgumentException("buffer size < 1024: " + bufferSize); 312 } 313 return bufferSize; 314 } 315 startMethodTracingDdmsImpl(int bufferSize, int flags, boolean samplingEnabled, int intervalUs)316 private static native void startMethodTracingDdmsImpl(int bufferSize, int flags, boolean samplingEnabled, int intervalUs); startMethodTracingFd(String traceFileName, int fd, int bufferSize, int flags, boolean samplingEnabled, int intervalUs, boolean streamingOutput)317 private static native void startMethodTracingFd(String traceFileName, int fd, int bufferSize, 318 int flags, boolean samplingEnabled, int intervalUs, boolean streamingOutput); startMethodTracingFilename(String traceFileName, int bufferSize, int flags, boolean samplingEnabled, int intervalUs)319 private static native void startMethodTracingFilename(String traceFileName, int bufferSize, int flags, boolean samplingEnabled, int intervalUs); 320 321 /** 322 * Determine whether method tracing is currently active and what type is 323 * active. 324 * 325 * @hide 326 */ 327 @SystemApi(client = MODULE_LIBRARIES) getMethodTracingMode()328 public static native int getMethodTracingMode(); 329 330 /** 331 * Stops method tracing. 332 * 333 * @hide 334 */ 335 @SystemApi(client = MODULE_LIBRARIES) stopMethodTracing()336 public static native void stopMethodTracing(); 337 338 /** 339 * Get an indication of thread CPU usage. The value returned indicates the 340 * amount of time that the current thread has spent executing code or 341 * waiting for certain types of I/O. 342 * <p> 343 * The time is expressed in nanoseconds, and is only meaningful when 344 * compared to the result from an earlier call. Note that nanosecond 345 * resolution does not imply nanosecond accuracy. 346 * 347 * @return the CPU usage. A value of -1 means the system does not support 348 * this feature. 349 * 350 * @hide 351 */ 352 @SystemApi(client = MODULE_LIBRARIES) 353 @FastNative threadCpuTimeNanos()354 public static native long threadCpuTimeNanos(); 355 356 /** 357 * Starts counting the number and aggregate size of memory allocations. 358 * 359 * @hide 360 */ 361 @SystemApi(client = MODULE_LIBRARIES) startAllocCounting()362 public static native void startAllocCounting(); 363 364 /** 365 * Stops counting the number and aggregate size of memory allocations. 366 * 367 * @hide 368 */ 369 @SystemApi(client = MODULE_LIBRARIES) stopAllocCounting()370 public static native void stopAllocCounting(); 371 372 /** 373 * Returns information on the number of objects allocated by the runtime between a 374 * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. 375 * 376 * @param kind either {@code KIND_GLOBAL_*} or {@code KIND_THREAD_*}. 377 * 378 * @hide 379 */ 380 @SystemApi(client = MODULE_LIBRARIES) getAllocCount(int kind)381 public static native int getAllocCount(int kind); 382 383 /** 384 * Resets counting the number and aggregate size of memory allocations for the given kinds. 385 * 386 * @param kinds a union of {@code KIND_GLOBAL_*} and {@code KIND_THREAD_*}. 387 * 388 * @hide 389 */ 390 @SystemApi(client = MODULE_LIBRARIES) resetAllocCount(int kinds)391 public static native void resetAllocCount(int kinds); 392 393 /** 394 * This method exists for binary compatibility. It was part of 395 * the allocation limits API which was removed in Android 3.0 (Honeycomb). 396 * 397 * @hide 398 */ 399 @Deprecated setAllocationLimit(int limit)400 public static int setAllocationLimit(int limit) { 401 return -1; 402 } 403 404 /** 405 * This method exists for binary compatibility. It was part of 406 * the allocation limits API which was removed in Android 3.0 (Honeycomb). 407 * 408 * @hide 409 */ 410 @Deprecated setGlobalAllocationLimit(int limit)411 public static int setGlobalAllocationLimit(int limit) { 412 return -1; 413 } 414 415 /** 416 * Count the number of instructions executed between two points. 417 * 418 * @hide 419 */ 420 @Deprecated startInstructionCounting()421 public static void startInstructionCounting() {} 422 423 /** 424 * 425 * @hide 426 */ 427 @Deprecated stopInstructionCounting()428 public static void stopInstructionCounting() {} 429 430 /** 431 * 432 * @hide 433 */ 434 @Deprecated getInstructionCount(int[] counts)435 public static void getInstructionCount(int[] counts) {} 436 437 /** 438 * 439 * @hide 440 */ 441 @Deprecated resetInstructionCount()442 public static void resetInstructionCount() {} 443 444 /** 445 * Dumps a list of loaded class to the log file. 446 * 447 * @param flags a union of {@link android.os.Debug.SHOW_FULL_DETAIL}, 448 * {@link android.os.Debug.SHOW_CLASSLOADER}, and {@link android.os.Debug.SHOW_INITIALIZED}. 449 * 450 * @hide 451 */ 452 @SystemApi(client = MODULE_LIBRARIES) 453 @FastNative printLoadedClasses(int flags)454 public static native void printLoadedClasses(int flags); 455 456 /** 457 * Gets the number of loaded classes. 458 * 459 * @return the number of loaded classes 460 * 461 * @hide 462 */ 463 @SystemApi(client = MODULE_LIBRARIES) 464 @FastNative getLoadedClassCount()465 public static native int getLoadedClassCount(); 466 467 /** 468 * Dumps "hprof" data to the specified file. This may cause a GC. 469 * 470 * The VM may create a temporary file in the same directory. 471 * 472 * @param filename Full pathname of output file (e.g. "/sdcard/dump.hprof"). 473 * @throws UnsupportedOperationException if the VM was built without 474 * HPROF support. 475 * @throws IOException if an error occurs while opening or writing files. 476 * 477 * @hide 478 */ 479 @SystemApi(client = MODULE_LIBRARIES) dumpHprofData(String filename)480 public static void dumpHprofData(String filename) throws IOException { 481 if (filename == null) { 482 throw new NullPointerException("filename == null"); 483 } 484 dumpHprofData(filename, null); 485 } 486 487 /** 488 * Collects "hprof" heap data and sends it to DDMS. This may cause a GC. 489 * 490 * @throws UnsupportedOperationException if the VM was built without 491 * HPROF support. 492 * 493 * @hide 494 */ 495 @SystemApi(client = MODULE_LIBRARIES) dumpHprofDataDdms()496 public static native void dumpHprofDataDdms(); 497 498 /** 499 * Dumps "hprof" heap data to a file, by name or descriptor. 500 * 501 * @param fileName Name of output file. If fd is non-null, the 502 * file name is only used in log messages (and may be null). 503 * @param fd Descriptor of open file that will receive the output. 504 * If this is null, the fileName is used instead. 505 * @throws {@link IOException} if an error occurs while opening or writing files. 506 * 507 * @hide 508 */ 509 @SystemApi(client = MODULE_LIBRARIES) dumpHprofData(String fileName, FileDescriptor fd)510 public static void dumpHprofData(String fileName, FileDescriptor fd) 511 throws IOException { 512 dumpHprofData(fileName, fd != null ? fd.getInt$() : -1); 513 } 514 dumpHprofData(String fileName, int fd)515 private static native void dumpHprofData(String fileName, int fd) 516 throws IOException; 517 518 /** 519 * Dumps the contents of the VM reference tables (e.g. JNI locals and 520 * globals) to the log file. 521 * 522 * @hide 523 */ 524 @UnsupportedAppUsage 525 @SystemApi(client = MODULE_LIBRARIES) dumpReferenceTables()526 public static native void dumpReferenceTables(); 527 528 /** 529 * Counts the instances of a class. 530 * It is the caller's responsibility to do GC if they don't want unreachable 531 * objects to get counted. 532 * 533 * @param klass the class to be counted. 534 * @param assignable if true, any instance whose class is assignable to 535 * {@code klass}, as defined by {@link Class#isAssignableFrom}, 536 * is counted. If false, only instances whose class is 537 * equal to {@code klass} are counted. 538 * @return the number of matching instances. 539 * 540 * @hide 541 */ 542 @SystemApi(client = MODULE_LIBRARIES) countInstancesOfClass(Class klass, boolean assignable)543 public static native long countInstancesOfClass(Class klass, boolean assignable); 544 545 /** 546 * Counts the instances of classes. 547 * It is the caller's responsibility to do GC if they don't want unreachable 548 * objects to get counted. 549 * 550 * @param classes the classes to be counted. 551 * @param assignable if true, any instance whose class is assignable to 552 * {@code classes[i]}, as defined by {@link Class#isAssignableFrom}, 553 * is counted. If false, only instances whose class is 554 * equal to {@code classes[i]} are counted. 555 * @return an array containing the number of matching instances. The value 556 * for index {@code i} is the number of instances of 557 * the class {@code classes[i]} 558 * 559 * @hide 560 */ 561 @SystemApi(client = MODULE_LIBRARIES) countInstancesOfClasses(Class[] classes, boolean assignable)562 public static native long[] countInstancesOfClasses(Class[] classes, boolean assignable); 563 564 /** 565 * Gets instances of classes on the Java heap. 566 * It is the caller's responsibility to do GC if they don't want unreachable 567 * objects to be included. 568 * 569 * @param classes the classes to get instances of. 570 * @param assignable if true, any instance whose class is assignable to 571 * {@code classes[i]}, as defined by {@link Class#isAssignableFrom}, 572 * is included. If false, only instances whose class is 573 * equal to {@code classes[i]} are included. 574 * @return an array containing the list of matching instances. The value 575 * for index {@code i} is an array containing the instances 576 * of the class {@code classes[i]} 577 * 578 * @hide 579 */ getInstancesOfClasses(Class[] classes, boolean assignable)580 public static native Object[][] getInstancesOfClasses(Class[] classes, boolean assignable); 581 582 /* Map from the names of the runtime stats supported by getRuntimeStat() to their IDs */ 583 private static final HashMap<String, Integer> runtimeStatsMap = new HashMap<>(); 584 585 static { 586 runtimeStatsMap.put("art.gc.gc-count", 0); 587 runtimeStatsMap.put("art.gc.gc-time", 1); 588 runtimeStatsMap.put("art.gc.bytes-allocated", 2); 589 runtimeStatsMap.put("art.gc.bytes-freed", 3); 590 runtimeStatsMap.put("art.gc.blocking-gc-count", 4); 591 runtimeStatsMap.put("art.gc.blocking-gc-time", 5); 592 runtimeStatsMap.put("art.gc.gc-count-rate-histogram", 6); 593 runtimeStatsMap.put("art.gc.blocking-gc-count-rate-histogram", 7); 594 runtimeStatsMap.put("art.gc.objects-allocated", 8); 595 runtimeStatsMap.put("art.gc.total-time-waiting-for-gc", 9); 596 runtimeStatsMap.put("art.gc.pre-oome-gc-count", 10); 597 } 598 599 /** 600 * Returns the value of a particular runtime statistic or {@code null} if no 601 * such runtime statistic exists. 602 * 603 * @param statName the name of the runtime statistic to look up. 604 * 605 * @return the value of the runtime statistic. 606 * 607 * @hide 608 */ 609 @SystemApi(client = MODULE_LIBRARIES) getRuntimeStat(String statName)610 public static String getRuntimeStat(String statName) { 611 if (statName == null) { 612 throw new NullPointerException("statName == null"); 613 } 614 Integer statId = runtimeStatsMap.get(statName); 615 if (statId != null) { 616 return getRuntimeStatInternal(statId); 617 } 618 return null; 619 } 620 621 /** 622 * Returns a map of the names/values of the runtime statistics 623 * that {@link #getRuntimeStat()} supports. 624 * 625 * @return a map of the names/values of the supported runtime statistics. 626 * 627 * @hide 628 */ 629 @SystemApi(client = MODULE_LIBRARIES) getRuntimeStats()630 public static Map<String, String> getRuntimeStats() { 631 HashMap<String, String> map = new HashMap<>(); 632 String[] values = getRuntimeStatsInternal(); 633 for (String name : runtimeStatsMap.keySet()) { 634 int id = runtimeStatsMap.get(name); 635 String value = values[id]; 636 map.put(name, value); 637 } 638 return map; 639 } 640 getRuntimeStatInternal(int statId)641 private static native String getRuntimeStatInternal(int statId); getRuntimeStatsInternal()642 private static native String[] getRuntimeStatsInternal(); 643 644 /** 645 * Attaches an agent to the VM. 646 * 647 * @param agent The path to the agent .so file plus optional agent arguments. 648 * @param classLoader The classloader to use as a loading context. 649 * 650 * @throws IOException if an error occurs while opening {@code agent} file. 651 * 652 * @hide 653 */ 654 @SystemApi(client = MODULE_LIBRARIES) attachAgent(String agent, ClassLoader classLoader)655 public static void attachAgent(String agent, ClassLoader classLoader) throws IOException { 656 nativeAttachAgent(agent, classLoader); 657 } 658 nativeAttachAgent(String agent, ClassLoader classLoader)659 private static native void nativeAttachAgent(String agent, ClassLoader classLoader) 660 throws IOException; 661 662 /** 663 * Exempts a class from any future non-SDK API access checks. 664 * Methods declared in the class will be allowed to perform 665 * reflection/JNI against the framework completely unrestricted. 666 * Note that this does not affect uses of non-SDK APIs that the class links against. 667 * Note that this does not affect methods declared outside this class, e.g. 668 * inherited from a superclass or an implemented interface. 669 * 670 * @param klass The class whose methods should be exempted. 671 * 672 * @hide 673 */ 674 @UnsupportedAppUsage allowHiddenApiReflectionFrom(Class<?> klass)675 public static native void allowHiddenApiReflectionFrom(Class<?> klass); 676 677 /** 678 * Sets the number of frames recorded for allocation tracking. 679 * 680 * @param stackDepth The number of frames captured for each stack trace. 681 * 682 * @hide 683 */ 684 @SystemApi(client = MODULE_LIBRARIES) setAllocTrackerStackDepth(int stackDepth)685 public static native void setAllocTrackerStackDepth(int stackDepth); 686 } 687