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