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