author | jiangli |
Sat, 03 Nov 2018 15:40:19 -0400 | |
changeset 52402 | 72d4e10305b9 |
parent 47818 | 2f6ab27efb60 |
child 52427 | 3c6aa484536c |
permissions | -rw-r--r-- |
34362 | 1 |
/* |
47818
2f6ab27efb60
8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents:
47294
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
34362 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
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.misc.JavaLangInvokeAccess; |
|
28 |
import jdk.internal.misc.SharedSecrets; |
|
29 |
||
30 |
import static java.lang.StackWalker.Option.*; |
|
31 |
import java.lang.StackWalker.StackFrame; |
|
47294
7d67bb6b0599
8186050: StackFrame should provide the method signature
mchung
parents:
47216
diff
changeset
|
32 |
import java.lang.invoke.MethodType; |
34362 | 33 |
|
34 |
class StackFrameInfo implements StackFrame { |
|
47818
2f6ab27efb60
8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents:
47294
diff
changeset
|
35 |
private final byte RETAIN_CLASS_REF = 0x01; |
2f6ab27efb60
8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents:
47294
diff
changeset
|
36 |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
37 |
private final static JavaLangInvokeAccess JLIA = |
34362 | 38 |
SharedSecrets.getJavaLangInvokeAccess(); |
39 |
||
47818
2f6ab27efb60
8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents:
47294
diff
changeset
|
40 |
private final byte flags; |
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
41 |
private final Object memberName; |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
42 |
private final short bci; |
37526 | 43 |
private volatile StackTraceElement ste; |
34362 | 44 |
|
45 |
/* |
|
46 |
* Create StackFrameInfo for StackFrameTraverser and LiveStackFrameTraverser |
|
47 |
* to use |
|
48 |
*/ |
|
49 |
StackFrameInfo(StackWalker walker) { |
|
47818
2f6ab27efb60
8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents:
47294
diff
changeset
|
50 |
this.flags = walker.retainClassRef ? RETAIN_CLASS_REF : 0; |
34362 | 51 |
this.bci = -1; |
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
52 |
this.memberName = JLIA.newMemberName(); |
34362 | 53 |
} |
54 |
||
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
55 |
// package-private called by StackStreamFactory to skip |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
56 |
// the capability check |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
57 |
Class<?> declaringClass() { |
47818
2f6ab27efb60
8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents:
47294
diff
changeset
|
58 |
return JLIA.getDeclaringClass(memberName); |
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
59 |
} |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
60 |
|
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
61 |
// ----- implementation of StackFrame methods |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
62 |
|
34362 | 63 |
@Override |
64 |
public String getClassName() { |
|
47818
2f6ab27efb60
8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents:
47294
diff
changeset
|
65 |
return declaringClass().getName(); |
34362 | 66 |
} |
67 |
||
68 |
@Override |
|
69 |
public Class<?> getDeclaringClass() { |
|
47818
2f6ab27efb60
8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents:
47294
diff
changeset
|
70 |
ensureRetainClassRefEnabled(); |
2f6ab27efb60
8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents:
47294
diff
changeset
|
71 |
return declaringClass(); |
34362 | 72 |
} |
73 |
||
74 |
@Override |
|
75 |
public String getMethodName() { |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
76 |
return JLIA.getName(memberName); |
34362 | 77 |
} |
78 |
||
79 |
@Override |
|
47294
7d67bb6b0599
8186050: StackFrame should provide the method signature
mchung
parents:
47216
diff
changeset
|
80 |
public MethodType getMethodType() { |
47818
2f6ab27efb60
8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents:
47294
diff
changeset
|
81 |
ensureRetainClassRefEnabled(); |
47294
7d67bb6b0599
8186050: StackFrame should provide the method signature
mchung
parents:
47216
diff
changeset
|
82 |
return JLIA.getMethodType(memberName); |
7d67bb6b0599
8186050: StackFrame should provide the method signature
mchung
parents:
47216
diff
changeset
|
83 |
} |
7d67bb6b0599
8186050: StackFrame should provide the method signature
mchung
parents:
47216
diff
changeset
|
84 |
|
7d67bb6b0599
8186050: StackFrame should provide the method signature
mchung
parents:
47216
diff
changeset
|
85 |
@Override |
7d67bb6b0599
8186050: StackFrame should provide the method signature
mchung
parents:
47216
diff
changeset
|
86 |
public String getDescriptor() { |
7d67bb6b0599
8186050: StackFrame should provide the method signature
mchung
parents:
47216
diff
changeset
|
87 |
return JLIA.getMethodDescriptor(memberName); |
7d67bb6b0599
8186050: StackFrame should provide the method signature
mchung
parents:
47216
diff
changeset
|
88 |
} |
7d67bb6b0599
8186050: StackFrame should provide the method signature
mchung
parents:
47216
diff
changeset
|
89 |
|
7d67bb6b0599
8186050: StackFrame should provide the method signature
mchung
parents:
47216
diff
changeset
|
90 |
@Override |
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
91 |
public int getByteCodeIndex() { |
38779
a78d46ad59c1
8157892: StackFrame::getFileName returns null when a source file exists for native methods
mchung
parents:
37819
diff
changeset
|
92 |
// bci not available for native methods |
a78d46ad59c1
8157892: StackFrame::getFileName returns null when a source file exists for native methods
mchung
parents:
37819
diff
changeset
|
93 |
if (isNativeMethod()) |
a78d46ad59c1
8157892: StackFrame::getFileName returns null when a source file exists for native methods
mchung
parents:
37819
diff
changeset
|
94 |
return -1; |
a78d46ad59c1
8157892: StackFrame::getFileName returns null when a source file exists for native methods
mchung
parents:
37819
diff
changeset
|
95 |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
96 |
return bci; |
34362 | 97 |
} |
98 |
||
99 |
@Override |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
100 |
public String getFileName() { |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
101 |
return toStackTraceElement().getFileName(); |
34362 | 102 |
} |
103 |
||
104 |
@Override |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
105 |
public int getLineNumber() { |
38779
a78d46ad59c1
8157892: StackFrame::getFileName returns null when a source file exists for native methods
mchung
parents:
37819
diff
changeset
|
106 |
// line number not available for native methods |
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
107 |
if (isNativeMethod()) |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
108 |
return -2; |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
109 |
|
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
110 |
return toStackTraceElement().getLineNumber(); |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
111 |
} |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
112 |
|
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
113 |
|
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
114 |
@Override |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
115 |
public boolean isNativeMethod() { |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
116 |
return JLIA.isNative(memberName); |
34362 | 117 |
} |
118 |
||
119 |
@Override |
|
120 |
public String toString() { |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
121 |
return toStackTraceElement().toString(); |
34362 | 122 |
} |
123 |
||
36511 | 124 |
@Override |
125 |
public StackTraceElement toStackTraceElement() { |
|
37526 | 126 |
StackTraceElement s = ste; |
127 |
if (s == null) { |
|
128 |
synchronized (this) { |
|
129 |
s = ste; |
|
130 |
if (s == null) { |
|
41911 | 131 |
ste = s = StackTraceElement.of(this); |
37526 | 132 |
} |
133 |
} |
|
36511 | 134 |
} |
37526 | 135 |
return s; |
36511 | 136 |
} |
47818
2f6ab27efb60
8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents:
47294
diff
changeset
|
137 |
|
2f6ab27efb60
8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents:
47294
diff
changeset
|
138 |
private void ensureRetainClassRefEnabled() { |
2f6ab27efb60
8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents:
47294
diff
changeset
|
139 |
if ((flags & RETAIN_CLASS_REF) == 0) { |
2f6ab27efb60
8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents:
47294
diff
changeset
|
140 |
throw new UnsupportedOperationException("No access to RETAIN_CLASS_REFERENCE"); |
2f6ab27efb60
8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents:
47294
diff
changeset
|
141 |
} |
2f6ab27efb60
8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents:
47294
diff
changeset
|
142 |
} |
34362 | 143 |
} |