当前位置: 首页>>代码示例>>Java>>正文


Java SharedSecrets.getJavaLangAccess方法代码示例

本文整理汇总了Java中sun.misc.SharedSecrets.getJavaLangAccess方法的典型用法代码示例。如果您正苦于以下问题:Java SharedSecrets.getJavaLangAccess方法的具体用法?Java SharedSecrets.getJavaLangAccess怎么用?Java SharedSecrets.getJavaLangAccess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sun.misc.SharedSecrets的用法示例。


在下文中一共展示了SharedSecrets.getJavaLangAccess方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: inferCaller

import sun.misc.SharedSecrets; //导入方法依赖的package包/类
private void inferCaller() {
    needToInferCaller = false;
    JavaLangAccess access = SharedSecrets.getJavaLangAccess();
    Throwable throwable = new Throwable();
    int depth = access.getStackTraceDepth(throwable);

    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.
        StackTraceElement frame =
            access.getStackTraceElement(throwable, 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.
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:35,代码来源:LogRecord.java

示例2: getCallerInfo

import sun.misc.SharedSecrets; //导入方法依赖的package包/类
private String getCallerInfo() {
    String sourceClassName = null;
    String sourceMethodName = null;

    JavaLangAccess access = SharedSecrets.getJavaLangAccess();
    Throwable throwable = new Throwable();
    int depth = access.getStackTraceDepth(throwable);

    String logClassName = "sun.util.logging.PlatformLogger";
    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.
        StackTraceElement frame =
            access.getStackTraceElement(throwable, ix);
        String cname = frame.getClassName();
        if (lookingForLogger) {
            // Skip all frames until we have found the first logger frame.
            if (cname.equals(logClassName)) {
                lookingForLogger = false;
            }
        } else {
            if (!cname.equals(logClassName)) {
                // We've found the relevant frame.
                sourceClassName = cname;
                sourceMethodName = frame.getMethodName();
                break;
            }
        }
    }

    if (sourceClassName != null) {
        return sourceClassName + " " + sourceMethodName;
    } else {
        return name;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:PlatformLogger.java

示例3: inferCaller

import sun.misc.SharedSecrets; //导入方法依赖的package包/类
/**
 * Infer caller's class and method name and set them to the given {@link LogRecord}.
 * Borrowed from {@link LogRecord}.
 */
private void inferCaller(final LogRecord lr) {
  final JavaLangAccess access = SharedSecrets.getJavaLangAccess();
  final Throwable throwable = new Throwable();
  final int depth = access.getStackTraceDepth(throwable);

  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.
    final StackTraceElement frame =
        access.getStackTraceElement(throwable, ix);
    final String cname = frame.getClassName();
    final 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.
          lr.setSourceClassName(cname);
          lr.setSourceMethodName(frame.getMethodName());
          return;
        }
      }
    }
  }
}
 
开发者ID:snuspl,项目名称:cruise,代码行数:36,代码来源:JobLogger.java

示例4: getCallerInfo

import sun.misc.SharedSecrets; //导入方法依赖的package包/类
static String getCallerInfo(String className) {
    String sourceClassName = null;
    String sourceMethodName = null;

    JavaLangAccess access = SharedSecrets.getJavaLangAccess();
    Throwable throwable = new Throwable();
    int depth = access.getStackTraceDepth(throwable);

    boolean lookingForClassName = true;
    for (int ix = 0; ix < depth; ix++) {
        // Calling getStackTraceElement directly prevents the VM
        // from paying the cost of building the entire stack frame.
        StackTraceElement frame = access.getStackTraceElement(throwable, ix);
        String cname = frame.getClassName();
        if (lookingForClassName) {
            // Skip all frames until we have found the first frame having the class name.
            if (cname.equals(className)) {
                lookingForClassName = false;
            }
        } else {
            if (!cname.equals(className)) {
                // We've found the relevant frame.
                sourceClassName = cname;
                sourceMethodName = frame.getMethodName();
                break;
            }
        }
    }

    if (sourceClassName != null) {
        return sourceClassName + " " + sourceMethodName;
    } else {
        return "unknown";
    }
}
 
开发者ID:bourgesl,项目名称:marlin-renderer,代码行数:36,代码来源:MarlinUtils.java


注:本文中的sun.misc.SharedSecrets.getJavaLangAccess方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。