author | shade |
Tue, 17 May 2016 22:28:00 +0300 | |
changeset 38372 | 017d7578731c |
parent 37819 | 8a2559d6fe5b |
child 38779 | a78d46ad59c1 |
permissions | -rw-r--r-- |
34362 | 1 |
/* |
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
|
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; |
|
32 |
import java.util.Optional; |
|
33 |
import java.util.OptionalInt; |
|
34 |
||
35 |
class StackFrameInfo implements StackFrame { |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
36 |
private final static JavaLangInvokeAccess JLIA = |
34362 | 37 |
SharedSecrets.getJavaLangInvokeAccess(); |
38 |
||
37526 | 39 |
// Footprint improvement: MemberName::clazz can replace |
40 |
// StackFrameInfo::declaringClass. |
|
34362 | 41 |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
42 |
private final StackWalker walker; |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
43 |
private final Class<?> declaringClass; |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
44 |
private final Object memberName; |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
45 |
private final short bci; |
37526 | 46 |
private volatile StackTraceElement ste; |
34362 | 47 |
|
48 |
/* |
|
49 |
* Create StackFrameInfo for StackFrameTraverser and LiveStackFrameTraverser |
|
50 |
* to use |
|
51 |
*/ |
|
52 |
StackFrameInfo(StackWalker walker) { |
|
53 |
this.walker = walker; |
|
54 |
this.declaringClass = null; |
|
55 |
this.bci = -1; |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
56 |
this.memberName = JLIA.newMemberName(); |
34362 | 57 |
} |
58 |
||
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
59 |
// package-private called by StackStreamFactory to skip |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
60 |
// the capability check |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
61 |
Class<?> declaringClass() { |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
62 |
return declaringClass; |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
63 |
} |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
64 |
|
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
65 |
// ----- implementation of StackFrame methods |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
66 |
|
34362 | 67 |
@Override |
68 |
public String getClassName() { |
|
69 |
return declaringClass.getName(); |
|
70 |
} |
|
71 |
||
72 |
@Override |
|
73 |
public Class<?> getDeclaringClass() { |
|
74 |
walker.ensureAccessEnabled(RETAIN_CLASS_REFERENCE); |
|
75 |
return declaringClass; |
|
76 |
} |
|
77 |
||
78 |
@Override |
|
79 |
public String getMethodName() { |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
80 |
return JLIA.getName(memberName); |
34362 | 81 |
} |
82 |
||
83 |
@Override |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
84 |
public int getByteCodeIndex() { |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
85 |
return bci; |
34362 | 86 |
} |
87 |
||
88 |
@Override |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
89 |
public String getFileName() { |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
90 |
if (isNativeMethod()) |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
91 |
return null; |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
92 |
|
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
93 |
return toStackTraceElement().getFileName(); |
34362 | 94 |
} |
95 |
||
96 |
@Override |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
97 |
public int getLineNumber() { |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
98 |
if (isNativeMethod()) |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
99 |
return -2; |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
100 |
|
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
101 |
return toStackTraceElement().getLineNumber(); |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
102 |
} |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
103 |
|
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
104 |
|
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
105 |
@Override |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
106 |
public boolean isNativeMethod() { |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
107 |
return JLIA.isNative(memberName); |
34362 | 108 |
} |
109 |
||
110 |
@Override |
|
111 |
public String toString() { |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
112 |
return toStackTraceElement().toString(); |
34362 | 113 |
} |
114 |
||
115 |
/** |
|
37526 | 116 |
* Fill in the fields of the given StackTraceElement |
34362 | 117 |
*/ |
37526 | 118 |
private native void toStackTraceElement0(StackTraceElement ste); |
36511 | 119 |
|
120 |
@Override |
|
121 |
public StackTraceElement toStackTraceElement() { |
|
37526 | 122 |
StackTraceElement s = ste; |
123 |
if (s == null) { |
|
124 |
synchronized (this) { |
|
125 |
s = ste; |
|
126 |
if (s == null) { |
|
127 |
s = new StackTraceElement(); |
|
128 |
toStackTraceElement0(s); |
|
129 |
ste = s; |
|
130 |
} |
|
131 |
} |
|
36511 | 132 |
} |
37526 | 133 |
return s; |
36511 | 134 |
} |
34362 | 135 |
} |