author | claus |
Tue, 23 Aug 1994 18:17:46 +0200 | |
changeset 40 | 45ecd4441edb |
parent 27 | 7e2b3ab54d7c |
child 45 | e8331ba8ad5d |
permissions | -rw-r--r-- |
18 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
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 |
|
14 |
instanceVariableNames:'' |
|
40
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
15 |
classVariableNames:'Access' |
18 | 16 |
poolDictionaries:'' |
17 |
category:'Kernel-Methods' |
|
18 |
! |
|
19 |
||
20 | 20 |
LazyMethod comment:' |
21 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
22 |
All Rights Reserved |
|
27 | 23 |
|
40
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
24 |
$Header: /cvs/stx/stx/libcomp/LazyMethod.st,v 1.4 1994-08-23 16:17:46 claus Exp $ |
20 | 25 |
'! |
26 |
||
27 |
!LazyMethod class methodsFor:'documentation'! |
|
28 |
||
29 |
copyright |
|
30 |
" |
|
31 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
32 |
All Rights Reserved |
|
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 |
" |
|
40
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
45 |
$Header: /cvs/stx/stx/libcomp/LazyMethod.st,v 1.4 1994-08-23 16:17:46 claus Exp $ |
20 | 46 |
" |
47 |
! |
|
48 |
||
49 |
documentation |
|
50 |
" |
|
51 |
Instances of LazyMethod are created when doing a lazy autoload. |
|
52 |
When executed, these will trigger an error in the VM (noByteCode), |
|
53 |
which is cought here to create a real method from the receiver. |
|
54 |
This allows faster loading of code, which will then be compiled |
|
55 |
when first executed; for classes with a large number of methods, of |
|
56 |
which only a small subset is actually used, this can also save |
|
57 |
lots of memory. |
|
58 |
" |
|
59 |
! ! |
|
60 |
||
40
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
61 |
!LazyMethod class methodsFor:'initialization'! |
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 |
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
64 |
Access := Semaphore forMutualExclusion |
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
65 |
! ! |
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
66 |
|
27 | 67 |
!LazyMethod methodsFor:'queries'! |
68 |
||
69 |
isLazyMethod |
|
70 |
^ true |
|
71 |
! ! |
|
72 |
||
18 | 73 |
!LazyMethod methodsFor:'error handling'! |
74 |
||
75 |
noByteCode |
|
76 |
"this error is triggered by the interpreter when a lazy method |
|
77 |
is about to be executed (by sending the bad method this message); |
|
78 |
hard-compile the method now, install its bytecode in the receiver, |
|
79 |
and call it now." |
|
80 |
||
81 |
|code m lazy sender| |
|
82 |
||
83 |
"compile the method" |
|
84 |
||
40
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
85 |
Access wait. |
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
86 |
|
18 | 87 |
lazy := Compiler compileLazy:false. |
88 |
[ |
|
89 |
m := self asByteCodeMethod. |
|
40
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
90 |
] valueOnUnwindDo:[ |
18 | 91 |
Compiler compileLazy:lazy. |
40
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
92 |
Access signal. |
18 | 93 |
]. |
94 |
||
40
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
95 |
m isNil ifTrue:[ |
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
96 |
Access signal. |
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
97 |
^ super invalidMethod |
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
98 |
]. |
18 | 99 |
byteCode := m byteCode. |
100 |
sender := thisContext sender. |
|
101 |
byteCode notNil ifTrue:[ |
|
102 |
literals := m literals. |
|
103 |
flags := m flags. |
|
104 |
" |
|
105 |
thisContext sender is the original sends (the failed ones) |
|
106 |
context ... |
|
107 |
" |
|
27 | 108 |
ObjectMemory flushCaches. |
40
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
109 |
Access signal. |
18 | 110 |
^ self valueWithReceiver:(sender receiver) |
111 |
arguments:(sender args) |
|
112 |
selector:(sender selector) |
|
113 |
]. |
|
40
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
114 |
Access signal. |
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
115 |
^ self error:'cannot compile method' |
18 | 116 |
! ! |