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