author | alanb |
Thu, 01 Dec 2016 08:57:53 +0000 | |
changeset 42338 | a60f280f803c |
parent 41911 | b3bb62588635 |
permissions | -rw-r--r-- |
34362 | 1 |
/* |
38779
a78d46ad59c1
8157892: StackFrame::getFileName returns null when a source file exists for native methods
mchung
parents:
37819
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, 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; |
|
32 |
||
33 |
class StackFrameInfo implements StackFrame { |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
34 |
private final static JavaLangInvokeAccess JLIA = |
34362 | 35 |
SharedSecrets.getJavaLangInvokeAccess(); |
36 |
||
37526 | 37 |
// Footprint improvement: MemberName::clazz can replace |
38 |
// StackFrameInfo::declaringClass. |
|
34362 | 39 |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
40 |
private final StackWalker walker; |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
41 |
private final Class<?> declaringClass; |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
42 |
private final Object memberName; |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
43 |
private final short bci; |
37526 | 44 |
private volatile StackTraceElement ste; |
34362 | 45 |
|
46 |
/* |
|
47 |
* Create StackFrameInfo for StackFrameTraverser and LiveStackFrameTraverser |
|
48 |
* to use |
|
49 |
*/ |
|
50 |
StackFrameInfo(StackWalker walker) { |
|
51 |
this.walker = walker; |
|
52 |
this.declaringClass = null; |
|
53 |
this.bci = -1; |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
54 |
this.memberName = JLIA.newMemberName(); |
34362 | 55 |
} |
56 |
||
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
57 |
// package-private called by StackStreamFactory to skip |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
58 |
// the capability check |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
59 |
Class<?> declaringClass() { |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
60 |
return declaringClass; |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
61 |
} |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
62 |
|
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
63 |
// ----- implementation of StackFrame methods |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
64 |
|
34362 | 65 |
@Override |
66 |
public String getClassName() { |
|
67 |
return declaringClass.getName(); |
|
68 |
} |
|
69 |
||
70 |
@Override |
|
71 |
public Class<?> getDeclaringClass() { |
|
72 |
walker.ensureAccessEnabled(RETAIN_CLASS_REFERENCE); |
|
73 |
return declaringClass; |
|
74 |
} |
|
75 |
||
76 |
@Override |
|
77 |
public String getMethodName() { |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
78 |
return JLIA.getName(memberName); |
34362 | 79 |
} |
80 |
||
81 |
@Override |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
82 |
public int getByteCodeIndex() { |
38779
a78d46ad59c1
8157892: StackFrame::getFileName returns null when a source file exists for native methods
mchung
parents:
37819
diff
changeset
|
83 |
// 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
|
84 |
if (isNativeMethod()) |
a78d46ad59c1
8157892: StackFrame::getFileName returns null when a source file exists for native methods
mchung
parents:
37819
diff
changeset
|
85 |
return -1; |
a78d46ad59c1
8157892: StackFrame::getFileName returns null when a source file exists for native methods
mchung
parents:
37819
diff
changeset
|
86 |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
87 |
return bci; |
34362 | 88 |
} |
89 |
||
90 |
@Override |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
91 |
public String getFileName() { |
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
92 |
return toStackTraceElement().getFileName(); |
34362 | 93 |
} |
94 |
||
95 |
@Override |
|
37819
8a2559d6fe5b
8153912: Reconsider StackFrame::getFileName and StackFrame::getLineNumber
mchung
parents:
37526
diff
changeset
|
96 |
public int getLineNumber() { |
38779
a78d46ad59c1
8157892: StackFrame::getFileName returns null when a source file exists for native methods
mchung
parents:
37819
diff
changeset
|
97 |
// line number not available for native methods |
37819
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 |
||
36511 | 115 |
@Override |
116 |
public StackTraceElement toStackTraceElement() { |
|
37526 | 117 |
StackTraceElement s = ste; |
118 |
if (s == null) { |
|
119 |
synchronized (this) { |
|
120 |
s = ste; |
|
121 |
if (s == null) { |
|
41911 | 122 |
ste = s = StackTraceElement.of(this); |
37526 | 123 |
} |
124 |
} |
|
36511 | 125 |
} |
37526 | 126 |
return s; |
36511 | 127 |
} |
34362 | 128 |
} |