[squeak-dev] A reengineering the CompiledMethod trailers

Igor Stasenko siguctua at gmail.com
Sun Dec 13 22:14:05 UTC 2009

Hello guys,

please take a look at changeset i just uploaded:


There is an initial implementation of CompiledMethodTrailer with some
test coverage.

My motivation behind this is simple:

1. no more poking with raw bytes, like this:

	"Are tempNames stored in trailer bytes"

	| flagByte |
	flagByte := self last.
	(flagByte = 0 or: [flagByte = 251 "some source-less methods have flag
= 251, rest = 0"
			and: [(1 to: 3) allSatisfy: [:i | (self at: self size - i) = 0]]])
		ifTrue: [^ false].  "No source pointer & no temp names"
	flagByte < 252 ifTrue: [^ true].  "temp names compressed"
	^ false	"Source pointer"

or this:

	"Answer the index of the last bytecode."
	| size flagByte |
	"Can't create a zero-sized CompiledMethod so no need to use last for
the errorEmptyCollection check.
	 We can reuse size."
	size := self size.
	flagByte := self at: size.
	flagByte = 0 ifTrue:
		["If last byte = 0, may be either 0, 0, 0, 0 or just 0"
		1 to: 4 do: [:i | (self at: size - i) = 0 ifFalse: [^size - i]]].
	flagByte < 252 ifTrue:
		["Magic sources (temp names encoded in last few bytes)"
		^flagByte <= 127
			ifTrue: [size - flagByte - 1]
			ifFalse: [size - (flagByte - 128 * 128) - (self at: size - 1) - 2]].
	"Normal 4-byte source pointer"
	^size - 4

2. method's trailer can be used for storing a variety of stuff, not
just source pointer or temps names. And it will be easy to add new
kinds of trailers.
    A most useful, as to me, and which i've added initially is:
  - being able to embed the source code in trailer, so a compiled
method and its source lives together in image.
     Some of you have expressed this idea before, so here it is.
  - being able to retrieve the method's source using other way, than
through SourceFiles or embedded in trailer.
     I added two kinds of trailers for that:
     - get method's source by class+selector where it installed to.
     - get method's source by class+some string identifier

  - yours. Please tell me, what kind you want to have in addition.

3.  a source pointer could surpass the 32Mb limit. A CompiledMethod
already can encode a source pointer value of any size.
  Its now only a matter of fixing the source pointer encoding logic to
enable having .source and .changes files above 32Mb.

Please, review my code and send me your comments and wishes.
At next stage i will create a changeset which will put this stuff in
use, as well as cleanup lots of places in CompiledMethod and

Best regards,
Igor Stasenko AKA sig.

More information about the Squeak-dev mailing list