// Private method to infer the caller's class and method names
  private void inferCaller() {
    needToInferCaller = false;
    // Android-changed: Use VMStack.getThreadStackTrace.
    StackTraceElement[] stack = VMStack.getThreadStackTrace(Thread.currentThread());
    int depth = stack.length;

    boolean lookingForLogger = true;
    for (int ix = 0; ix < depth; ix++) {
      // Calling getStackTraceElement directly prevents the VM
      // from paying the cost of building the entire stack frame.
      //
      // Android-changed: Use value from getThreadStackTrace.
      StackTraceElement frame = stack[ix];
      String cname = frame.getClassName();
      boolean isLoggerImpl = isLoggerImplFrame(cname);
      if (lookingForLogger) {
        // Skip all frames until we have found the first logger frame.
        if (isLoggerImpl) {
          lookingForLogger = false;
        }
      } else {
        if (!isLoggerImpl) {
          // skip reflection call
          if (!cname.startsWith("java.lang.reflect.") && !cname.startsWith("sun.reflect.")) {
            // We've found the relevant frame.
            setSourceClassName(cname);
            setSourceMethodName(frame.getMethodName());
            return;
          }
        }
      }
    }
    // We haven't found a suitable frame, so just punt.  This is
    // OK as we are only committed to making a "best effort" here.
  }
Esempio n. 2
0
 /**
  * Returns a {@code Class} object which represents the class with the specified name. The name
  * should be the name of a class as described in the {@link Class class definition}; however,
  * {@code Class}es representing primitive types can not be found using this method.
  *
  * <p>If the class has not been loaded so far, it is being loaded and linked first. This is done
  * through either the class loader of the calling class or one of its parent class loaders. The
  * class is also being initialized, which means that a possible static initializer block is
  * executed.
  *
  * @param className the name of the non-primitive-type class to find.
  * @return the named {@code Class} instance.
  * @throws ClassNotFoundException if the requested class can not be found.
  * @throws LinkageError if an error occurs during linkage
  * @throws ExceptionInInitializerError if an exception occurs during static initialization of a
  *     class.
  */
 public static Class<?> forName(String className) throws ClassNotFoundException {
   return forName(className, true, VMStack.getCallingClassLoader());
 }
Esempio n. 3
0
 /** Returns an array of {@link StackTraceElement} representing the current thread's stack. */
 public StackTraceElement[] getStackTrace() {
   StackTraceElement ste[] = VMStack.getThreadStackTrace(this);
   return ste != null ? ste : EmptyArray.STACK_TRACE_ELEMENT;
 }