本文整理汇总了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.
}
示例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;
}
}
示例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;
}
}
}
}
}
示例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";
}
}