author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 04 Aug 2014 16:13:14 +0100 | |
changeset 3196 | d617b4590431 |
parent 2942 | c39cbf09ea3d |
child 3324 | a58245c0e83a |
permissions | -rw-r--r-- |
749 | 1 |
" |
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
3 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
4 |
New code and modifications done at SWING Research Group [1]: |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
5 |
|
749 | 6 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
7 |
SWING Research Group, Czech Technical University in Prague |
|
8 |
||
9 |
This software is furnished under a license and may be used |
|
10 |
only in accordance with the terms of that license and with the |
|
11 |
inclusion of the above copyright notice. This software may not |
|
12 |
be provided or otherwise made available to, or used by, any |
|
13 |
other person. No title to or ownership of the software is |
|
14 |
hereby transferred. |
|
15 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
16 |
[1] Code written at SWING Research Group contains a signature |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
17 |
of one of the above copright owners. For exact set of such code, |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
18 |
see the differences between this version and version stx:libjava |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
19 |
as of 1.9.2010 |
749 | 20 |
" |
21 |
"{ Package: 'stx:libjava' }" |
|
22 |
||
23 |
Object subclass:#JavaResolver |
|
24 |
instanceVariableNames:'exceptionThrower' |
|
25 |
classVariableNames:'uniqueInstance' |
|
26 |
poolDictionaries:'' |
|
27 |
category:'Languages-Java-Reader-Support-new' |
|
28 |
! |
|
29 |
||
30 |
!JavaResolver class methodsFor:'documentation'! |
|
31 |
||
32 |
copyright |
|
33 |
" |
|
34 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
35 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
36 |
New code and modifications done at SWING Research Group [1]: |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
37 |
|
749 | 38 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
39 |
SWING Research Group, Czech Technical University in Prague |
|
40 |
||
41 |
This software is furnished under a license and may be used |
|
42 |
only in accordance with the terms of that license and with the |
|
43 |
inclusion of the above copyright notice. This software may not |
|
44 |
be provided or otherwise made available to, or used by, any |
|
45 |
other person. No title to or ownership of the software is |
|
46 |
hereby transferred. |
|
47 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
48 |
[1] Code written at SWING Research Group contains a signature |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
49 |
of one of the above copright owners. For exact set of such code, |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
50 |
see the differences between this version and version stx:libjava |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
51 |
as of 1.9.2010 |
749 | 52 |
|
53 |
" |
|
54 |
! ! |
|
55 |
||
56 |
!JavaResolver class methodsFor:'initialization'! |
|
57 |
||
58 |
initialize |
|
59 |
uniqueInstance := JavaResolver new. |
|
60 |
uniqueInstance exceptionThrower: JavaVM. |
|
61 |
||
62 |
"/has methods at: and at: put: |
|
63 |
"/uniqueInstance resolvedClasses: Java. |
|
64 |
||
65 |
"Modified: / 10-04-2011 / 10:23:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
66 |
"Modified: / 13-04-2011 / 14:07:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
67 |
! ! |
|
68 |
||
69 |
!JavaResolver class methodsFor:'instance creation'! |
|
70 |
||
71 |
uniqueInstance |
|
72 |
^uniqueInstance. |
|
73 |
||
74 |
"Created: / 08-04-2011 / 17:36:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
75 |
"Modified: / 11-04-2011 / 19:06:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
76 |
! ! |
|
77 |
||
78 |
!JavaResolver methodsFor:'accessing'! |
|
79 |
||
80 |
exceptionThrower |
|
81 |
^ exceptionThrower |
|
82 |
! |
|
83 |
||
84 |
exceptionThrower:something |
|
85 |
exceptionThrower := something. |
|
86 |
! ! |
|
87 |
||
88 |
!JavaResolver methodsFor:'class resolving'! |
|
89 |
||
90 |
checkIfPrimitiveArrayRef: aJavaClassRef andWrap: result |
|
91 |
||
92 |
^ (JavaDescriptor readFromString: aJavaClassRef name) javaClass. |
|
93 |
||
94 |
"Created: / 23-05-2011 / 21:12:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
95 |
! |
|
96 |
||
97 |
resolveClassIndentifiedByRef: aJavaClassRef init: doInit |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
98 |
"marcel is back working harder then ever :)" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
99 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
100 |
| result | |
749 | 101 |
self validateClassRef: aJavaClassRef. |
2678
c865275e48a7
Updated to match Mercurial revision a00302fe5083 with two tweaks:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2396
diff
changeset
|
102 |
result := self |
2794
cec025d0f359
Oops, fix for resolving.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2732
diff
changeset
|
103 |
lookupClassIfAlreadyResolved: aJavaClassRef javaClassNameOrPrimitiveTypeId |
2678
c865275e48a7
Updated to match Mercurial revision a00302fe5083 with two tweaks:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2396
diff
changeset
|
104 |
definedBy: aJavaClassRef classLoader. |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
105 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
106 |
"/ result notNil ifTrue:[ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
107 |
"/ "/wrap result with array(s) if needed and return it |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
108 |
"/ "/FIXME: Marcel, can you have a look? Is that correct? |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
109 |
"/ ^self checkIfArrayRef: aJavaClassRef andWrap: result. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
110 |
"/ ]. |
2678
c865275e48a7
Updated to match Mercurial revision a00302fe5083 with two tweaks:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2396
diff
changeset
|
111 |
" |
749 | 112 |
To resolve an unresolved symbolic reference from D to a class or interface C denoted by N, |
113 |
the following steps are performed: |
|
114 |
The defining class loader of D is used to create a class or interface denoted by N. |
|
115 |
This class or interface is C. Any exception that can be thrown as a result of failure |
|
116 |
of class or interface creation can thus be thrown as a result of failure of class and |
|
117 |
interface resolution. The details of the process are given in Section 5.3. |
|
118 |
" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
119 |
result isNil ifTrue: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
120 |
JavaClassReader classLoaderQuerySignal answer: (aJavaClassRef classLoader) |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
121 |
do: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
122 |
"#loadUnresolvedClass: wraps the class!!!!!!" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
123 |
result := self loadUnresolvedClass: aJavaClassRef. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
124 |
((aJavaClassRef name first == $[) and: [ result isJavaArrayClass not ]) ifTrue: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
125 |
self breakPoint: #jv. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
126 |
] |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
127 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
128 |
] ifFalse: [ result := self checkIfArrayRef: aJavaClassRef andWrap: result. ]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
129 |
result isNil ifTrue: [ self breakPoint: #mh ]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
130 |
result isJavaPrimitiveType ifTrue: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
131 |
^ self checkIfPrimitiveArrayRef: aJavaClassRef andWrap: result |
749 | 132 |
]. |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
133 |
(doInit and: [ result isJavaClass and: [ result isJavaArrayClass not ] ]) ifTrue: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
134 |
result classInit |
749 | 135 |
]. |
136 |
" |
|
137 |
If C is an array class and its element type is a reference type, then the symbolic reference |
|
138 |
to the class or interface representing the element type is resolved by invoking the algorithm |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
139 |
in Section 5.4.3.1 recursively.""Finally, access permissions to C are checked: |
749 | 140 |
If C is not accessible (5.4.4) to D, class or interface resolution throws an IllegalAccessError. |
141 |
This condition can occur, for example, if C is a class that was originally declared to be |
|
142 |
public but was changed to be non-public after D was compiled. |
|
143 |
||
144 |
If steps 1 and 2 succeed but step 3 fails, C is still valid and usable. Nevertheless, resolution |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
145 |
fails, and D is prohibited from accessing C." |
749 | 146 |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
147 |
(self checkPermissionsFrom: aJavaClassRef owner to: result) ifFalse: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
148 |
self throwIllegalAccessError. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
149 |
^nil. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
150 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
151 |
^result |
749 | 152 |
|
153 |
"Created: / 11-04-2011 / 19:07:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
154 |
"Created: / 12-08-2011 / 22:19:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
155 |
"Modified (comment): / 03-10-2011 / 23:03:01 / m" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
156 |
"Modified: / 01-12-2012 / 13:44:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
2794
cec025d0f359
Oops, fix for resolving.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2732
diff
changeset
|
157 |
"Modified: / 05-10-2013 / 01:05:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 158 |
! ! |
159 |
||
160 |
!JavaResolver methodsFor:'class resolving helpers'! |
|
161 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
162 |
checkIfArrayRef: aJavaClassRef andWrap: nonArrayClass |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
163 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
164 |
"/wrap result with array(s) if needed and return it |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
165 |
| class| |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
166 |
class := nonArrayClass. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
167 |
aJavaClassRef name do:[:c| |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
168 |
c ~~ $[ ifTrue:[ ^ class ]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
169 |
class := class javaArrayClass. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
170 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
171 |
^class |
749 | 172 |
|
173 |
"Modified: / 11-04-2011 / 19:31:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
174 |
"Modified: / 23-10-2011 / 23:46:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 175 |
! |
176 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
177 |
checkPermissionsFrom: refOwner to: resolvedClass |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
178 |
refOwner hasMagicAccessRights ifTrue: [ ^ true ]. |
2942
c39cbf09ea3d
Fixes for Java reflection on Smalltalk classes.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2908
diff
changeset
|
179 |
resolvedClass isJavaClass ifFalse:[ ^ true ]. |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
180 |
(JavaDescriptor isJavaPrimitiveArrayName: resolvedClass javaName) ifTrue: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
181 |
^ true |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
182 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
183 |
resolvedClass isPublic ifTrue: [ ^ true ]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
184 |
resolvedClass classLoader = refOwner classLoader ifFalse: [ ^ false. ]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
185 |
refOwner javaPackage = resolvedClass javaPackage ifTrue: [ ^ true ]. |
749 | 186 |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
187 |
"/a little bit too verbose here just so it's clear what's in query |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
188 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
189 |
JavaVM privilegedAccessQuery query ifTrue: [ ^ true ] ifFalse: [ ^ false ]. |
749 | 190 |
|
191 |
"Created: / 11-04-2011 / 19:35:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
192 |
"Modified (comment): / 09-10-2011 / 23:11:54 / Marcel Hlopko <hlopik@gmail.com>" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
193 |
"Modified: / 23-08-2012 / 20:21:40 / m" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
194 |
"Modified: / 30-11-2012 / 20:34:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
2942
c39cbf09ea3d
Fixes for Java reflection on Smalltalk classes.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2908
diff
changeset
|
195 |
"Modified: / 20-11-2013 / 16:07:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 196 |
! |
197 |
||
198 |
loadUnresolvedClass: aJavaClassRef |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
199 |
| nm cls i | |
749 | 200 |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
201 |
nm := aJavaClassRef name. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
202 |
nm size == 1 ifTrue:[ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
203 |
JavaDescriptor baseTypes at: nm first ifPresent: [:cls | ^ cls ] |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
204 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
205 |
"Note, that JavaVM>>classForName: itself deals with class loaders. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
206 |
The caller of me should set one using code like: |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
207 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
208 |
JavaClassReader classLoaderQuerySignal answer: loader do:[call me] |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
209 |
" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
210 |
cls := JavaVM classForName: nm. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
211 |
(nm startsWith:$[) ifTrue:[ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
212 |
i := 1. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
213 |
[ (nm at:i) == $[ ] whileTrue:[ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
214 |
cls := cls javaArrayClass. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
215 |
i := i + 1. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
216 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
217 |
self assert: (nm at:i) == $L. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
218 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
219 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
220 |
^cls. |
749 | 221 |
|
222 |
"Created: / 11-04-2011 / 19:27:10 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
223 |
"Modified: / 23-05-2011 / 21:06:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
224 |
"Modified: / 29-02-2012 / 09:20:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 225 |
! |
226 |
||
2678
c865275e48a7
Updated to match Mercurial revision a00302fe5083 with two tweaks:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2396
diff
changeset
|
227 |
lookupClassIfAlreadyResolved: javaClassName definedBy: classLoader |
c865275e48a7
Updated to match Mercurial revision a00302fe5083 with two tweaks:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2396
diff
changeset
|
228 |
^ JavaVM classNamed: javaClassName definedBy: classLoader |
749 | 229 |
|
2678
c865275e48a7
Updated to match Mercurial revision a00302fe5083 with two tweaks:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2396
diff
changeset
|
230 |
"Created: / 02-05-2013 / 01:20:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 231 |
! |
232 |
||
233 |
validateClassRef: aJavaClassRef |
|
234 |
self assert: aJavaClassRef isJavaRef. |
|
235 |
self assert: aJavaClassRef isJavaClassRef . |
|
236 |
||
237 |
"Modified: / 23-05-2011 / 21:04:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
238 |
! ! |
|
239 |
||
240 |
!JavaResolver methodsFor:'common helpers'! |
|
241 |
||
242 |
checkPermissionsForMethodOrField: aJavaMethodOrField from: accessingJavaClass to: resolvedJavaClass |
|
243 |
"A class or interface C is accessible to a class or interface D if |
|
244 |
and only if either of the following conditions are true: |
|
245 |
C is public. |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
246 |
C and D are members of the same runtime package (§5.3). |
749 | 247 |
A field or method R is accessible to a class or interface D if and only |
248 |
if any of the following conditions is true: |
|
249 |
R is public. |
|
250 |
R is protected and is declared in a class C, and D is either a subclass |
|
251 |
of C or C itself. |
|
252 |
R is either protected or package private (that is, neither public nor |
|
253 |
protected nor private), and is declared by a class in the same runtime |
|
254 |
package as D. |
|
255 |
R is private and is declared in D. |
|
256 |
This discussion of access control omits a related restriction on the target |
|
257 |
of a protected field access or method invocation (the target must be of class |
|
258 |
D or a subtype of D). That requirement is checked as part of the verification |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
259 |
process (§5.4.1); it is not part of link-time access control." |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
260 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
261 |
accessingJavaClass hasMagicAccessRights ifTrue: [ ^true ]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
262 |
|
749 | 263 |
(self checkPermissionsFrom: accessingJavaClass to: resolvedJavaClass) ifFalse: [ |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
264 |
JavaVM privilegedAccessQuery query ifTrue: [ ^ true ]. |
749 | 265 |
^ false |
266 |
]. |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
267 |
aJavaMethodOrField isPublic ifTrue: [ ^ true ]. |
749 | 268 |
((aJavaMethodOrField isProtected |
269 |
and: [ |
|
270 |
resolvedJavaClass javaComponentClass |
|
271 |
equalsOrIsSubclassOf: aJavaMethodOrField javaClass |
|
272 |
]) |
|
273 |
and: [ |
|
274 |
accessingJavaClass javaComponentClass |
|
275 |
equalsOrIsSubclassOf: aJavaMethodOrField javaClass |
|
276 |
]) |
|
277 |
ifTrue: [ ^ true ]. |
|
2730
272689c14005
Fixed removing of Java classes (issue #40)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2578
diff
changeset
|
278 |
(( |
272689c14005
Fixed removing of Java classes (issue #40)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2578
diff
changeset
|
279 |
aJavaMethodOrField isPrivate not |
749 | 280 |
and: [ resolvedJavaClass javaPackage = accessingJavaClass javaPackage ]) |
281 |
and: [ resolvedJavaClass classLoader = accessingJavaClass classLoader ]) |
|
282 |
ifTrue: [ ^ true ]. |
|
283 |
(aJavaMethodOrField isPrivate |
|
284 |
and: [ aJavaMethodOrField javaClass name = accessingJavaClass name ]) |
|
285 |
ifTrue: [ ^ true ]. |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
286 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
287 |
"/a little bit too verbose here just so it's clear what's in query |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
288 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
289 |
JavaVM privilegedAccessQuery query ifTrue: [ ^ true ] ifFalse: [ ^ false ]. |
749 | 290 |
|
291 |
"Created: / 14-04-2011 / 14:19:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
292 |
"Modified (comment): / 09-10-2011 / 23:12:48 / Marcel Hlopko <hlopik@gmail.com>" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
293 |
"Modified: / 18-11-2012 / 16:24:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
2730
272689c14005
Fixed removing of Java classes (issue #40)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2578
diff
changeset
|
294 |
"Modified (format): / 15-09-2013 / 00:09:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 295 |
! ! |
296 |
||
297 |
!JavaResolver methodsFor:'exceptions'! |
|
298 |
||
299 |
throwAbstractMethodError |
|
300 |
exceptionThrower throwAbstractMethodError. |
|
301 |
||
302 |
"Created: / 11-04-2011 / 20:19:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
303 |
"Modified: / 13-04-2011 / 14:07:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
304 |
! |
|
305 |
||
306 |
throwIllegalAccessError |
|
307 |
exceptionThrower throwIllegalAccessError. |
|
308 |
||
309 |
"Created: / 11-04-2011 / 19:39:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
310 |
"Modified: / 13-04-2011 / 23:06:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
311 |
! |
|
312 |
||
313 |
throwIncompatibleClassChangeError |
|
314 |
exceptionThrower throwIncompatibleClassChangeError. |
|
315 |
||
316 |
"Created: / 11-04-2011 / 20:02:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
317 |
"Modified: / 13-04-2011 / 14:07:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
318 |
! |
|
319 |
||
320 |
throwNoSuchFieldException |
|
321 |
exceptionThrower throwNoSuchFieldException. |
|
322 |
||
323 |
"Created: / 11-04-2011 / 21:35:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
324 |
"Modified: / 13-04-2011 / 14:07:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
325 |
! |
|
326 |
||
327 |
throwNoSuchMethodError |
|
328 |
exceptionThrower throwNoSuchMethodError. |
|
329 |
||
330 |
"Created: / 11-04-2011 / 20:19:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
331 |
"Modified: / 13-04-2011 / 14:08:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
332 |
! ! |
|
333 |
||
334 |
!JavaResolver methodsFor:'field resolving'! |
|
335 |
||
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
336 |
resolveFieldIndentifiedByRef:aJavaFieldRef |
749 | 337 |
| result class | |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
338 |
|
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
339 |
self validateFieldRef:aJavaFieldRef. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
340 |
result := self lookupFieldIfAlreadyResolved:aJavaFieldRef. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
341 |
result notNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
342 |
^ result |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
343 |
]. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
344 |
class := aJavaFieldRef classRef resolve:false. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
345 |
class isNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
346 |
self error:'should not happen - tell mh' |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
347 |
]. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
348 |
result := class lookupFieldByNameAndType:aJavaFieldRef nameAndType. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
349 |
result isNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
350 |
self throwNoSuchFieldException |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
351 |
]. |
749 | 352 |
(self |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
353 |
checkPermissionsForField:result |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
354 |
from:aJavaFieldRef classRef owner |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
355 |
to:class) ifFalse:[ self throwIllegalAccessError ]. |
749 | 356 |
^ result. |
357 |
||
358 |
" |
|
359 |
To resolve an unresolved symbolic reference from D to a field in a class |
|
360 |
or interface C, the symbolic reference to C given by the field reference |
|
361 |
must first be resolved (§5.4.3.1). Therefore, any exception that can be |
|
362 |
thrown as a result of failure of resolution of a class or interface reference |
|
363 |
can be thrown as a result of failure of field resolution. If the reference |
|
364 |
to C can be successfully resolved, an exception relating to the failure of |
|
365 |
resolution of the field reference itself can be thrown. |
|
366 |
When resolving a field reference, field resolution first attempts to look |
|
367 |
up the referenced field in C and its superclasses: |
|
368 |
||
369 |
If C declares a field with the name and descriptor specified by the field |
|
370 |
reference, field lookup succeeds. The declared field is the result of the |
|
371 |
field lookup. |
|
372 |
||
373 |
Otherwise, field lookup is applied recursively to the direct superinterfaces |
|
374 |
of the specified class or interface C. |
|
375 |
||
376 |
Otherwise, if C has a superclass S, field lookup is applied recursively to S. |
|
377 |
||
378 |
Otherwise, field lookup fails. |
|
379 |
If field lookup fails, field resolution throws a NoSuchFieldError. Otherwise, |
|
380 |
if field lookup succeeds but the referenced field is not accessible (§5.4.4) |
|
381 |
to D, field resolution throws an IllegalAccessError. |
|
382 |
Otherwise, let <E, L1> be the class or interface in which the referenced |
|
383 |
field is actually declared and let L2 be the defining loader of D. Let T be |
|
384 |
the name of the type of the referenced field. The Java virtual machine must |
|
385 |
impose the loading constraint that TL1=TL2(§5.3.4)." |
|
386 |
||
387 |
"Created: / 11-04-2011 / 21:15:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
388 |
"Modified: / 01-12-2012 / 13:45:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
389 |
"Modified: / 04-08-2014 / 15:52:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 390 |
! |
391 |
||
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
392 |
resolveStaticFieldIndentifiedByRef:aJavaFieldRef |
749 | 393 |
| result class | |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
394 |
|
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
395 |
self validateFieldRef:aJavaFieldRef. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
396 |
result := self lookupFieldIfAlreadyResolved:aJavaFieldRef. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
397 |
result notNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
398 |
^ result |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
399 |
]. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
400 |
class := aJavaFieldRef classRef resolve:false. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
401 |
class isNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
402 |
self error:'should not happen - tell mh' |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
403 |
]. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
404 |
result := class lookupStaticFieldByNameAndType:aJavaFieldRef nameAndType. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
405 |
result isNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
406 |
self throwNoSuchFieldException |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
407 |
]. |
749 | 408 |
(self |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
409 |
checkPermissionsForField:result |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
410 |
from:aJavaFieldRef classRef owner |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
411 |
to:class) ifFalse:[ self throwIllegalAccessError ]. |
749 | 412 |
^ result. |
413 |
||
414 |
" |
|
415 |
To resolve an unresolved symbolic reference from D to a field in a class |
|
416 |
or interface C, the symbolic reference to C given by the field reference |
|
417 |
must first be resolved (§5.4.3.1). Therefore, any exception that can be |
|
418 |
thrown as a result of failure of resolution of a class or interface reference |
|
419 |
can be thrown as a result of failure of field resolution. If the reference |
|
420 |
to C can be successfully resolved, an exception relating to the failure of |
|
421 |
resolution of the field reference itself can be thrown. |
|
422 |
When resolving a field reference, field resolution first attempts to look |
|
423 |
up the referenced field in C and its superclasses: |
|
424 |
||
425 |
If C declares a field with the name and descriptor specified by the field |
|
426 |
reference, field lookup succeeds. The declared field is the result of the |
|
427 |
field lookup. |
|
428 |
||
429 |
Otherwise, field lookup is applied recursively to the direct superinterfaces |
|
430 |
of the specified class or interface C. |
|
431 |
||
432 |
Otherwise, if C has a superclass S, field lookup is applied recursively to S. |
|
433 |
||
434 |
Otherwise, field lookup fails. |
|
435 |
If field lookup fails, field resolution throws a NoSuchFieldError. Otherwise, |
|
436 |
if field lookup succeeds but the referenced field is not accessible (§5.4.4) |
|
437 |
to D, field resolution throws an IllegalAccessError. |
|
438 |
Otherwise, let <E, L1> be the class or interface in which the referenced |
|
439 |
field is actually declared and let L2 be the defining loader of D. Let T be |
|
440 |
the name of the type of the referenced field. The Java virtual machine must |
|
441 |
impose the loading constraint that TL1=TL2(§5.3.4)." |
|
442 |
||
443 |
"Created: / 28-04-2011 / 22:31:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
444 |
"Modified: / 01-12-2012 / 13:45:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
445 |
"Modified: / 04-08-2014 / 15:52:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 446 |
! ! |
447 |
||
448 |
!JavaResolver methodsFor:'field resolving helpers'! |
|
449 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
450 |
checkPermissionsForField: aJavaField from: accessingJavaClass to: resolvedJavaClass |
749 | 451 |
^ self |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
452 |
checkPermissionsForMethodOrField: aJavaField |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
453 |
from: accessingJavaClass |
749 | 454 |
to: resolvedJavaClass. |
455 |
||
456 |
"Created: / 11-04-2011 / 21:46:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
457 |
"Modified: / 01-12-2012 / 13:45:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
749 | 458 |
! |
459 |
||
460 |
lookupFieldIfAlreadyResolved: aJavaFieldRef |
|
461 |
^ nil. |
|
462 |
||
463 |
"Created: / 11-04-2011 / 21:16:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
464 |
"Modified: / 13-04-2011 / 11:57:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
465 |
! |
|
466 |
||
467 |
validateFieldRef: aJavaFieldRef |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
468 |
aJavaFieldRef isJavaRef ifFalse: [ self halt: 'I expected Java Ref' ]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
469 |
aJavaFieldRef isJavaFieldRef ifFalse: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
470 |
self error: 'I expected Java Field Ref' |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
471 |
]. |
749 | 472 |
|
473 |
"Created: / 11-04-2011 / 21:16:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
474 |
"Modified: / 01-12-2012 / 13:46:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
749 | 475 |
! ! |
476 |
||
477 |
!JavaResolver methodsFor:'interface method resolving'! |
|
478 |
||
479 |
resolveInterfaceMethodIdentifiedByRef: aJavaInterfaceMethodRef |
|
480 |
| result class | |
|
481 |
self validateInterfaceMethodRef: aJavaInterfaceMethodRef. |
|
482 |
result := self |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
483 |
lookupInterfaceMethodIfAlreadyResolved: aJavaInterfaceMethodRef. |
2908
064418faa2e3
Another pass over Mauve tests.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2794
diff
changeset
|
484 |
result notNil ifTrue: [ ^ result ]. |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
485 |
class := aJavaInterfaceMethodRef classRef resolve: false. |
2908
064418faa2e3
Another pass over Mauve tests.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2794
diff
changeset
|
486 |
class isNil ifTrue: [ self error: 'should not happen - tell mh' ]. |
749 | 487 |
class isInterface ifFalse: [ self throwIncompatibleClassChangeError ]. |
488 |
result := class |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
489 |
lookupMethodByNameAndType: aJavaInterfaceMethodRef nameAndType. |
2908
064418faa2e3
Another pass over Mauve tests.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2794
diff
changeset
|
490 |
result isNil ifTrue: [ self throwNoSuchMethodError ]. |
749 | 491 |
(self |
492 |
checkPermissionsForMethod: result |
|
493 |
from: aJavaInterfaceMethodRef classRef owner |
|
494 |
to: class) ifFalse: [ self throwIllegalAccessError ]. |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
495 |
^ result. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
496 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
497 |
" |
749 | 498 |
To resolve an unresolved symbolic reference from D to an interface method in an |
499 |
interface C, the symbolic reference to C given by the interface method reference is |
|
500 |
first resolved (§5.4.3.1). Therefore, any exceptions that can be thrown as a result |
|
501 |
of failure of resolution of an interface reference can be thrown as a result of |
|
502 |
failure of interface method resolution. If the reference to C can be successfully |
|
503 |
resolved, exceptions relating to the resolution of the interface method reference |
|
504 |
itself can be thrown. |
|
505 |
When resolving an interface method reference: |
|
506 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
507 |
If C is not an interface, interface method resolution throws an IncompatibleClassChangeError." |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
508 |
"Otherwise, if the referenced method does not have the same name and descriptor as |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
509 |
a method in C or in one of the superinterfaces of C, or in class Object, interface |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
510 |
method resolution throws a NoSuchMethodError. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
511 |
Otherwise, let <E, L1> be the interface in which the referenced interface method is |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
512 |
actually declared and let L2 be the defining loader of D. Let T0 be the name of |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
513 |
the type returned by the referenced method, and let T1, ..., Tn be the names of the |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
514 |
argument types of the referenced method. The Java virtual machine must impose the |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
515 |
loading constraints TiL1 = TiL2 for i = 0 to n (§5.3.4)." |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
516 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
517 |
"Modified: / 01-12-2012 / 13:46:09 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
2908
064418faa2e3
Another pass over Mauve tests.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2794
diff
changeset
|
518 |
"Modified: / 09-11-2013 / 00:12:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 519 |
! ! |
520 |
||
521 |
!JavaResolver methodsFor:'interface method resolving helpers'! |
|
522 |
||
523 |
lookupInterfaceMethodIfAlreadyResolved: aJavaInterfaceMethodRef |
|
524 |
^ nil. |
|
525 |
||
526 |
"Created: / 13-04-2011 / 11:53:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
527 |
! |
|
528 |
||
529 |
validateInterfaceMethodRef: aJavaInterfaceMethodRef |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
530 |
aJavaInterfaceMethodRef isJavaRef ifFalse: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
531 |
self error: 'I expected JavaRef instance as an argument' |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
532 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
533 |
aJavaInterfaceMethodRef isJavaInterfaceMethodRef ifFalse: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
534 |
self error: 'I expected JavaMethodRef instance as an argument' |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
535 |
]. |
749 | 536 |
|
537 |
"Created: / 13-04-2011 / 11:53:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
538 |
"Modified: / 01-12-2012 / 13:46:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
749 | 539 |
! ! |
540 |
||
541 |
!JavaResolver methodsFor:'method resolving'! |
|
542 |
||
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
543 |
resolveMethodIndentifiedByRef:aJavaMethodRef |
749 | 544 |
| result class | |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
545 |
|
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
546 |
self validateMethodRef:aJavaMethodRef. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
547 |
result := self lookupMethodIfAlreadyResolved:aJavaMethodRef. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
548 |
result notNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
549 |
^ result |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
550 |
]. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
551 |
class := aJavaMethodRef classRef resolve:false. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
552 |
class isNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
553 |
self error:'should not happen - tell mh' |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
554 |
]. |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
555 |
"Array types responds to all method of class java.lang.Object" |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
556 |
class isJavaArrayClass ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
557 |
class := JavaVM classForName:'java.lang.Object'. |
749 | 558 |
]. |
559 |
" |
|
560 |
To resolve an unresolved symbolic reference from D to a method in |
|
561 |
a class C, the symbolic reference to C given by the method reference |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
562 |
is first resolved (§5.4.3.1). Therefore, any exceptions that can be |
749 | 563 |
thrown due to resolution of a class reference can be thrown as a result |
564 |
of method resolution. If the reference to C can be successfully resolved, |
|
565 |
exceptions relating to the resolution of the method reference itself |
|
566 |
can be thrown. |
|
567 |
When resolving a method reference: |
|
568 |
||
569 |
Method resolution checks whether C is a class or an interface. |
|
570 |
If C is an interface, method resolution throws an IncompatibleClassChangeError." |
|
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
571 |
class isInterface ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
572 |
self throwIncompatibleClassChangeError |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
573 |
]. |
749 | 574 |
"Method resolution attempts to look up the referenced method in C and its |
575 |
superclasses: |
|
576 |
If C declares a method with the name and descriptor specified by the method |
|
577 |
reference, method lookup succeeds. |
|
578 |
Otherwise, if C has a superclass, step 2 of method lookup is recursively |
|
579 |
invoked on the direct superclass of C. |
|
580 |
||
581 |
Otherwise, method lookup attempts to locate the referenced method in any of |
|
582 |
the superinterfaces of the specified class C. |
|
583 |
If any superinterface of C declares a method with the name and descriptor |
|
584 |
specified by the method reference, method lookup succeeds. |
|
585 |
Otherwise, method lookup fails. |
|
586 |
If method lookup fails, method resolution throws a NoSuchMethodError. If method |
|
587 |
lookup succeeds and the method is abstract, but C is not abstract, method resolution |
|
588 |
throws an AbstractMethodError. Otherwise, if the referenced method is not accessible |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
589 |
(§5.4.4) to D, method resolution throws an IllegalAccessError." |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
590 |
result := class lookupMethodByNameAndType:aJavaMethodRef nameAndType. |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
591 |
result isNil ifTrue:[ |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
592 |
self throwNoSuchMethodError |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
593 |
]. |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
594 |
(result isAbstract |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
595 |
and:[ result javaClass isInterface not and:[ class isAbstract not ] ]) |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
596 |
ifTrue:[ self throwAbstractMethodError ]. |
749 | 597 |
(self |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
598 |
checkPermissionsForMethod:result |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
599 |
from:aJavaMethodRef classRef owner |
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
600 |
to:class) ifFalse:[ self throwIllegalAccessError ]. |
749 | 601 |
^ result. |
602 |
||
603 |
"Otherwise, let <E, L1> be the class or interface in which the referenced method is |
|
604 |
actually declared and let L2 be the defining loader of D. Let T0 be the name of |
|
605 |
the type returned by the referenced method, and let T1, ..., Tn be the names of |
|
606 |
the argument types of the referenced method. The Java virtual machine must impose |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
607 |
the loading constraints TiL1=TiL2 for i = 0 to n (§5.3.4)." |
749 | 608 |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
609 |
"Created: / 11-04-2011 / 19:45:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
610 |
"Modified: / 14-04-2011 / 00:01:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
611 |
"Modified (format): / 01-12-2012 / 13:46:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
3196
d617b4590431
(Class reading) optimization [2/4]: rewrite slow ifNil:... by faster isNil ifTrue:...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2942
diff
changeset
|
612 |
"Modified: / 04-08-2014 / 15:55:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
749 | 613 |
! ! |
614 |
||
615 |
!JavaResolver methodsFor:'method resolving helpers'! |
|
616 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
617 |
checkPermissionsForMethod: aJavaMethod from: accessingJavaClass to: resolvedJavaClass |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
618 |
^ self |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
619 |
checkPermissionsForMethodOrField: aJavaMethod |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
620 |
from: accessingJavaClass |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
621 |
to: resolvedJavaClass. |
749 | 622 |
|
623 |
"Created: / 11-04-2011 / 20:20:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
624 |
"Modified: / 24-05-2011 / 14:06:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
625 |
"Modified: / 09-02-2012 / 23:15:48 / mh <hlopik@gmail.com>" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
626 |
"Modified: / 01-12-2012 / 13:46:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
749 | 627 |
! |
628 |
||
629 |
lookupMethodIfAlreadyResolved: aJavaMethodRef |
|
630 |
^ nil. |
|
631 |
||
632 |
"Created: / 11-04-2011 / 19:50:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
633 |
"Modified: / 13-04-2011 / 11:57:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
634 |
! |
|
635 |
||
636 |
validateMethodRef: aJavaMethodRef |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
637 |
aJavaMethodRef isJavaRef ifFalse: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
638 |
self error: 'I expected JavaRef instance as an argument' |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
639 |
]. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
640 |
aJavaMethodRef isJavaMethodRef ifFalse: [ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
641 |
self error: 'I expected JavaMethodRef instance as an argument' |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
642 |
]. |
749 | 643 |
|
644 |
"Created: / 11-04-2011 / 19:47:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
645 |
"Modified: / 01-12-2012 / 13:47:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
749 | 646 |
! ! |
647 |
||
648 |
!JavaResolver class methodsFor:'documentation'! |
|
649 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
650 |
version_CVS |
2678
c865275e48a7
Updated to match Mercurial revision a00302fe5083 with two tweaks:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2396
diff
changeset
|
651 |
^ '$Header: /cvs/stx/stx/libjava/JavaResolver.st,v 1.6 2013-09-06 00:41:26 vrany Exp $' |
2156
a8c5720d1d05
changed: #resolveMethodIndentifiedByRef:
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
652 |
! |
a8c5720d1d05
changed: #resolveMethodIndentifiedByRef:
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
653 |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
654 |
version_HG |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
655 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
656 |
^ '$Changeset: <not expanded> $' |
2156
a8c5720d1d05
changed: #resolveMethodIndentifiedByRef:
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
657 |
! |
a8c5720d1d05
changed: #resolveMethodIndentifiedByRef:
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
658 |
|
749 | 659 |
version_SVN |
2731
13f5be2bf83b
Merged d87e89dd5276 and fe83a843a7bf (branch default - CVS HEAD)
Jan Vrany <jan.vrany@fit.cvut.cz>
diff
changeset
|
660 |
^ 'Id' |
749 | 661 |
! ! |
662 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2231
diff
changeset
|
663 |
|
2152 | 664 |
JavaResolver initialize! |