CompileMethod limits

Klaus D. Witzel klaus.witzel at cobss.com
Sat Feb 24 09:07:38 UTC 2007


Hi Milan,

on Sat, 24 Feb 2007 09:53:50 +0100, you wrote:
> On 2007 February 13 06:10, Bert Freudenberg wrote:
>>
>> Use #storeString instead of #printString.
>
> Hi Bert,
>
> Thanks for your comments along the way. I ended up storing each project
> as "manually serialized" ByteArrays returned from a method.
>
> Along the way I found a problem related to compiler which prevented me  
> from
> using the "storeString" for large volume.
>
>    -# I used MultiByteFileStream to stream project into a ByteArray, for
> example byteArr:=#(80 75 3 4 20 0 0 0 0 0 76 134 203 ....). Then I tried
> something like:
>
>     byteArr := #(80 75 3 4 20 0 0 0 0 0 76 134 203) asByteArray.
>     byteArrStoreString := byteArr storeString.
>     method := 'method1 ^',  '''', byteArrStoreString, ''''.
>     TestCompile compile: method classified: 'my-compile-test'
>
> This worked for the short ByteArray above, but for a long one, I get an  
> Error
> from CompileMethod:
>
>   "Error: Cannot compile - too many literal variables"
>
> There are limits in the CompileMethod code such as:
> 	nTemps > 63 ifTrue:
> 		[^ self error: 'Cannot compile -- too many temporary variables'].	
> 	nLits > 255 ifTrue:
> 		[^ self error: 'Cannot compile -- too many literals variables'].
> A naive question, does this have to do with the way classes are  
> represented in
> the VM?

Since I am [in part] responsible for having the above checks in a  
consistent way, here's my part of the answer:

No. These limits exist because the header field in CompiledMethod has room  
for just these respective number of bits.

Has nothing to do with, how classes are represented in the VM, but with,  
how CompiledMethods are represented in the VM.

>   -# So I ended up "manually serializing" the ByteArray, esentially as a
> literal String such as '80 75 3 4 20 0 0 0 0 0 76 134 203' in the small
> example above. Then deserialized after the method answered.

Correct. This way you have only one literal in the CompiledMethod, instead  
of one literals for each value less than -1 or greater than 2 :)

/Klaus




More information about the Squeak-dev mailing list