8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint

8153682: StackFrameInfo.declaringClass could be removed

Reviewed-by: coleenp, mchung
This commit is contained in:
Brent Christian 2017-11-09 11:13:50 -08:00
parent 09c2ca5809
commit ac52bdcdd1
8 changed files with 42 additions and 43 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -32,14 +32,12 @@ import java.lang.StackWalker.StackFrame;
import java.lang.invoke.MethodType;
class StackFrameInfo implements StackFrame {
private final byte RETAIN_CLASS_REF = 0x01;
private final static JavaLangInvokeAccess JLIA =
SharedSecrets.getJavaLangInvokeAccess();
// Footprint improvement: MemberName::clazz can replace
// StackFrameInfo::declaringClass.
private final StackWalker walker;
private final Class<?> declaringClass;
private final byte flags;
private final Object memberName;
private final short bci;
private volatile StackTraceElement ste;
@ -49,8 +47,7 @@ class StackFrameInfo implements StackFrame {
* to use
*/
StackFrameInfo(StackWalker walker) {
this.walker = walker;
this.declaringClass = null;
this.flags = walker.retainClassRef ? RETAIN_CLASS_REF : 0;
this.bci = -1;
this.memberName = JLIA.newMemberName();
}
@ -58,20 +55,20 @@ class StackFrameInfo implements StackFrame {
// package-private called by StackStreamFactory to skip
// the capability check
Class<?> declaringClass() {
return declaringClass;
return JLIA.getDeclaringClass(memberName);
}
// ----- implementation of StackFrame methods
@Override
public String getClassName() {
return declaringClass.getName();
return declaringClass().getName();
}
@Override
public Class<?> getDeclaringClass() {
walker.ensureAccessEnabled(RETAIN_CLASS_REFERENCE);
return declaringClass;
ensureRetainClassRefEnabled();
return declaringClass();
}
@Override
@ -81,7 +78,7 @@ class StackFrameInfo implements StackFrame {
@Override
public MethodType getMethodType() {
walker.ensureAccessEnabled(RETAIN_CLASS_REFERENCE);
ensureRetainClassRefEnabled();
return JLIA.getMethodType(memberName);
}
@ -137,4 +134,10 @@ class StackFrameInfo implements StackFrame {
}
return s;
}
private void ensureRetainClassRefEnabled() {
if ((flags & RETAIN_CLASS_REF) == 0) {
throw new UnsupportedOperationException("No access to RETAIN_CLASS_REFERENCE");
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -296,6 +296,7 @@ public final class StackWalker {
private final Set<Option> options;
private final ExtendedOption extendedOption;
private final int estimateDepth;
final boolean retainClassRef; // cached for performance
/**
* Returns a {@code StackWalker} instance.
@ -412,6 +413,7 @@ public final class StackWalker {
this.options = options;
this.estimateDepth = estimateDepth;
this.extendedOption = extendedOption;
this.retainClassRef = hasOption(Option.RETAIN_CLASS_REFERENCE);
}
private static void checkPermission(Set<Option> options) {
@ -590,7 +592,7 @@ public final class StackWalker {
*/
@CallerSensitive
public Class<?> getCallerClass() {
if (!options.contains(Option.RETAIN_CLASS_REFERENCE)) {
if (!retainClassRef) {
throw new UnsupportedOperationException("This stack walker " +
"does not have RETAIN_CLASS_REFERENCE access");
}
@ -617,11 +619,4 @@ public final class StackWalker {
boolean hasLocalsOperandsOption() {
return extendedOption == ExtendedOption.LOCALS_AND_OPERANDS;
}
void ensureAccessEnabled(Option access) {
if (!hasOption(access)) {
throw new UnsupportedOperationException("No access to " + access +
": " + options.toString());
}
}
}

View file

@ -1784,6 +1784,11 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
MemberName memberName = (MemberName)mname;
return memberName.getName();
}
@Override
public Class<?> getDeclaringClass(Object mname) {
MemberName memberName = (MemberName)mname;
return memberName.getDeclaringClass();
}
@Override
public MethodType getMethodType(Object mname) {