< prev index next >

src/java.base/share/classes/java/lang/StackFrameInfo.java

Print this page

  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 package java.lang;
 26 
 27 import jdk.internal.access.JavaLangInvokeAccess;
 28 import jdk.internal.access.SharedSecrets;


 29 
 30 import java.lang.StackWalker.StackFrame;
 31 import java.lang.invoke.MethodType;

 32 
 33 class StackFrameInfo implements StackFrame {
 34     private static final JavaLangInvokeAccess JLIA =
 35         SharedSecrets.getJavaLangInvokeAccess();
 36 
 37     private final boolean retainClassRef;
 38     private final Object memberName;    // MemberName initialized by VM
 39     private int bci;                    // initialized by VM to >= 0

 40     private volatile StackTraceElement ste;
 41 
 42     /*
 43      * Construct an empty StackFrameInfo object that will be filled by the VM
 44      * during stack walking.
 45      *
 46      * @see StackStreamFactory.AbstractStackWalker#callStackWalk
 47      * @see StackStreamFactory.AbstractStackWalker#fetchStackFrames
 48      */
 49     StackFrameInfo(StackWalker walker) {
 50         this.retainClassRef = walker.retainClassRef;
 51         this.memberName = JLIA.newMemberName();
 52     }
 53 
 54     // package-private called by StackStreamFactory to skip
 55     // the capability check
 56     Class<?> declaringClass() {
 57         return JLIA.getDeclaringClass(memberName);
 58     }
 59 















 60     // ----- implementation of StackFrame methods
 61 
 62     @Override
 63     public String getClassName() {
 64         return declaringClass().getName();
 65     }
 66 
 67     @Override
 68     public Class<?> getDeclaringClass() {
 69         ensureRetainClassRefEnabled();
 70         return declaringClass();
 71     }
 72 
 73     @Override
 74     public String getMethodName() {
 75         return JLIA.getName(memberName);
 76     }
 77 
 78     @Override
 79     public MethodType getMethodType() {

 98     @Override
 99     public String getFileName() {
100         return toStackTraceElement().getFileName();
101     }
102 
103     @Override
104     public int getLineNumber() {
105         // line number not available for native methods
106         if (isNativeMethod())
107             return -2;
108 
109         return toStackTraceElement().getLineNumber();
110     }
111 
112 
113     @Override
114     public boolean isNativeMethod() {
115         return JLIA.isNative(memberName);
116     }
117 





118     @Override
119     public String toString() {
120         return toStackTraceElement().toString();
121     }
122 
123     @Override
124     public StackTraceElement toStackTraceElement() {
125         StackTraceElement s = ste;
126         if (s == null) {
127             synchronized (this) {
128                 s = ste;
129                 if (s == null) {
130                     ste = s = StackTraceElement.of(this);
131                 }
132             }
133         }
134         return s;
135     }
136 
137     private void ensureRetainClassRefEnabled() {

  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 package java.lang;
 26 
 27 import jdk.internal.access.JavaLangInvokeAccess;
 28 import jdk.internal.access.SharedSecrets;
 29 import jdk.internal.vm.Continuation;
 30 import jdk.internal.vm.ContinuationScope;
 31 
 32 import java.lang.StackWalker.StackFrame;
 33 import java.lang.invoke.MethodType;
 34 import java.lang.reflect.Method;
 35 
 36 class StackFrameInfo implements StackFrame {
 37     private static final JavaLangInvokeAccess JLIA =
 38         SharedSecrets.getJavaLangInvokeAccess();
 39 
 40     private final boolean retainClassRef;
 41     private Object memberName;    // MemberName initialized by VM
 42     private int bci;              // initialized by VM to >= 0
 43     private ContinuationScope contScope;
 44     private volatile StackTraceElement ste;
 45 
 46     /*
 47      * Construct an empty StackFrameInfo object that will be filled by the VM
 48      * during stack walking.
 49      *
 50      * @see StackStreamFactory.AbstractStackWalker#callStackWalk
 51      * @see StackStreamFactory.AbstractStackWalker#fetchStackFrames
 52      */
 53     StackFrameInfo(StackWalker walker) {
 54         this.retainClassRef = walker.retainClassRef;
 55         this.memberName = JLIA.newMemberName();
 56     }
 57 
 58     // package-private called by StackStreamFactory to skip
 59     // the capability check
 60     Class<?> declaringClass() {
 61         return JLIA.getDeclaringClass(memberName);
 62     }
 63 
 64     void setMemberName(Method method) {
 65         this.memberName = JLIA.newMemberName(method);
 66     }
 67 
 68     void setBCI(short bci) {
 69         this.bci = bci;
 70     }
 71 
 72     void setContinuationScope(ContinuationScope contScope) {
 73         this.contScope = contScope;
 74     }
 75     
 76     protected void clear() {
 77     }
 78 
 79     // ----- implementation of StackFrame methods
 80 
 81     @Override
 82     public String getClassName() {
 83         return declaringClass().getName();
 84     }
 85 
 86     @Override
 87     public Class<?> getDeclaringClass() {
 88         ensureRetainClassRefEnabled();
 89         return declaringClass();
 90     }
 91 
 92     @Override
 93     public String getMethodName() {
 94         return JLIA.getName(memberName);
 95     }
 96 
 97     @Override
 98     public MethodType getMethodType() {

117     @Override
118     public String getFileName() {
119         return toStackTraceElement().getFileName();
120     }
121 
122     @Override
123     public int getLineNumber() {
124         // line number not available for native methods
125         if (isNativeMethod())
126             return -2;
127 
128         return toStackTraceElement().getLineNumber();
129     }
130 
131 
132     @Override
133     public boolean isNativeMethod() {
134         return JLIA.isNative(memberName);
135     }
136 
137     @Override
138     public java.lang.String getContinuationScopeName() {
139         return contScope != null ? contScope.getName() : null;
140     }
141 
142     @Override
143     public String toString() {
144         return toStackTraceElement().toString();
145     }
146 
147     @Override
148     public StackTraceElement toStackTraceElement() {
149         StackTraceElement s = ste;
150         if (s == null) {
151             synchronized (this) {
152                 s = ste;
153                 if (s == null) {
154                     ste = s = StackTraceElement.of(this);
155                 }
156             }
157         }
158         return s;
159     }
160 
161     private void ensureRetainClassRefEnabled() {
< prev index next >