author | Stefan Vogel <sv@exept.de> |
Fri, 06 Mar 1998 16:38:37 +0100 | |
changeset 657 | 0ecf1ff6f6bf |
parent 533 | 885426f6c90b |
child 799 | e8c7957d5138 |
permissions | -rw-r--r-- |
18 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
45 | 3 |
All Rights Reserved |
18 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
13 |
'From Smalltalk/X, Version:2.10.9 on 25-jun-1996 at 14:32:52' ! |
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
14 |
|
18 | 15 |
Method subclass:#LazyMethod |
249
fb82fccfb779
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
190
diff
changeset
|
16 |
instanceVariableNames:'' |
fb82fccfb779
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
190
diff
changeset
|
17 |
classVariableNames:'Access CompilationFailedSignal' |
fb82fccfb779
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
190
diff
changeset
|
18 |
poolDictionaries:'' |
fb82fccfb779
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
190
diff
changeset
|
19 |
category:'Kernel-Methods' |
18 | 20 |
! |
21 |
||
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
22 |
!LazyMethod class methodsFor:'documentation'! |
20 | 23 |
|
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
45 | 27 |
All Rights Reserved |
20 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
Instances of LazyMethod are created when doing a lazy autoload. |
|
45 | 41 |
They do not contain any code (neither byte- nor machinecode), but |
42 |
keep their sourcecode only. |
|
43 |
||
20 | 44 |
When executed, these will trigger an error in the VM (noByteCode), |
533 | 45 |
which is caught here to create a real method from the receiver, |
45 | 46 |
amd re-execute the method. |
47 |
||
48 |
This allows faster loading of code, which will be later compiled |
|
20 | 49 |
when first executed; for classes with a large number of methods, of |
50 |
which only a small subset is actually used, this can also save |
|
45 | 51 |
lots of memory (beside making autoloading faster). |
262 | 52 |
|
53 |
[author:] |
|
54 |
Claus Gittinger |
|
55 |
||
56 |
[see also:] |
|
57 |
Autoload |
|
20 | 58 |
" |
59 |
! ! |
|
60 |
||
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
61 |
!LazyMethod class methodsFor:'initialization'! |
40
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
62 |
|
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
63 |
initialize |
45 | 64 |
CompilationFailedSignal isNil ifTrue:[ |
65 |
CompilationFailedSignal := ExecutionErrorSignal newSignalMayProceed:true. |
|
66 |
CompilationFailedSignal nameClass:self message:#compilationFailedSignal. |
|
67 |
CompilationFailedSignal notifierString:'compilation of lazy method failed'. |
|
68 |
||
488 | 69 |
Access := Semaphore forMutualExclusion name:'LazyAccess'. |
89 | 70 |
"/ Access := RecursionLock new. |
45 | 71 |
] |
72 |
! ! |
|
73 |
||
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
74 |
!LazyMethod class methodsFor:'Signal constants'! |
45 | 75 |
|
76 |
compilationFailedSignal |
|
77 |
^ CompilationFailedSignal |
|
40
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
78 |
! ! |
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
79 |
|
54 | 80 |
!LazyMethod methodsFor:'compiling'! |
18 | 81 |
|
54 | 82 |
makeRealMethod |
83 |
"make the receiver a real method; i.e. compile the sourcecode and |
|
84 |
fill in the bytecode. This must be done in order to execute the receiver." |
|
18 | 85 |
|
54 | 86 |
|m| |
18 | 87 |
|
88 |
"compile the method" |
|
89 |
||
45 | 90 |
"we have to sequentialize this using a lock-semaphore, |
91 |
to make sure only one method is compiled at a time. |
|
92 |
Otherwise, we might get into trouble, if (due to a timeout) |
|
93 |
another recompile is forced while compiling this one ... |
|
94 |
(happened when autoloading animation demos) |
|
95 |
" |
|
190 | 96 |
"/ Access wouldBlock ifTrue:[ |
97 |
"/ 'oops - blocked access lock' printNL. |
|
98 |
"/ Access signal |
|
99 |
"/ ]. |
|
100 |
||
18 | 101 |
[ |
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
102 |
Access critical:[ |
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
103 |
m := self asExecutableMethod. |
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
104 |
]. |
45 | 105 |
] valueUninterruptably. |
106 |
||
126 | 107 |
(m isNil or:[(byteCode := m byteCode) isNil and:[m code isNil]]) ifTrue:[ |
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
108 |
" |
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
109 |
compilation failed |
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
110 |
" |
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
111 |
^ nil |
54 | 112 |
]. |
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
113 |
self literals:m literals. |
54 | 114 |
flags := m flags. |
126 | 115 |
self code:(m code). |
54 | 116 |
self changeClassToThatOf:m. |
117 |
^ self |
|
126 | 118 |
|
119 |
"Created: 24.10.1995 / 14:02:50 / cg" |
|
120 |
"Modified: 24.10.1995 / 15:35:50 / cg" |
|
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
121 |
"Modified: 24.6.1996 / 17:23:57 / stefan" |
54 | 122 |
! ! |
123 |
||
124 |
!LazyMethod methodsFor:'error handling'! |
|
125 |
||
126 |
noByteCode |
|
127 |
"this is triggered by the interpreter when a lazy method is about to |
|
128 |
be executed (by sending the to-be executed method this message). |
|
129 |
Hard-compile the method, install its bytecode in the receiver, |
|
130 |
and recall it." |
|
131 |
||
132 |
|sender spec class selector| |
|
133 |
||
134 |
"compile the method" |
|
135 |
||
136 |
self makeRealMethod isNil ifTrue:[ |
|
137 |
" |
|
138 |
compilation failed |
|
139 |
" |
|
140 |
selector := thisContext sender selector. |
|
45 | 141 |
|
142 |
class := self containingClass. |
|
143 |
class notNil ifTrue:[ |
|
144 |
spec := class name , '>>' , selector |
|
145 |
] ifFalse:[ |
|
146 |
spec := 'unknown>>' , selector |
|
147 |
]. |
|
148 |
" |
|
149 |
this error is triggered, if the compilation of a lazy method |
|
150 |
failed - this happens for example, if a lazy methods code has been |
|
151 |
changed in a fileBrowser without checking the code for syntactical |
|
152 |
correctnes, or if the instvars of an autoloaded classes superclass |
|
153 |
have been changed without changing the subclasses code ... |
|
154 |
You should enter the SystemBrowser on this method, and try accepting |
|
155 |
to see what the problem is. |
|
156 |
The methods class is found in the local 'class', |
|
157 |
the selector is found in the local 'selector'. |
|
158 |
||
159 |
As a general rule: never edit autoloaded classes from anything |
|
160 |
except the browser - to check that they work and are compilable. |
|
161 |
" |
|
162 |
^ CompilationFailedSignal raiseRequestWith:self |
|
163 |
errorString:('compilation of lazy method ' , spec , ' failed') |
|
40
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
164 |
]. |
45 | 165 |
|
166 |
" |
|
167 |
Now, the receiver method has mutated into a real (non-lazy) one. |
|
168 |
Get the original message receiver and args, and execute the method. |
|
169 |
||
170 |
ThisContext sender is the context of the original send (the failed one) |
|
171 |
" |
|
18 | 172 |
sender := thisContext sender. |
45 | 173 |
ObjectMemory flushCaches. |
174 |
||
175 |
^ self valueWithReceiver:(sender receiver) |
|
176 |
arguments:(sender args) |
|
177 |
selector:(sender selector) |
|
54 | 178 |
search:nil |
179 |
sender:nil |
|
18 | 180 |
! ! |
142 | 181 |
|
182 |
!LazyMethod methodsFor:'queries'! |
|
183 |
||
184 |
isLazyMethod |
|
185 |
^ true |
|
186 |
! ! |
|
187 |
||
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
188 |
!LazyMethod class methodsFor:'documentation'! |
249
fb82fccfb779
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
190
diff
changeset
|
189 |
|
fb82fccfb779
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
190
diff
changeset
|
190 |
version |
533 | 191 |
^ '$Header: /cvs/stx/stx/libcomp/LazyMethod.st,v 1.22 1997-06-16 18:22:41 cg Exp $' |
249
fb82fccfb779
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
190
diff
changeset
|
192 |
! ! |
142 | 193 |
LazyMethod initialize! |