[squeak-dev] The Trunk: Kernel-eem.1155.mcz

commits at source.squeak.org commits at source.squeak.org
Tue Feb 27 20:52:57 UTC 2018


Eliot Miranda uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-eem.1155.mcz

==================== Summary ====================

Name: Kernel-eem.1155
Author: eem
Time: 27 February 2018, 12:52:46.556955 pm
UUID: 0041924e-8077-4c30-8456-45ce511eb376
Ancestors: Kernel-eem.1154

Improve class comments for CompiledCode, CompiledMethod, and CompiledBlock.

=============== Diff against Kernel-eem.1154 ===============

Item was changed:
  CompiledCode variableByteSubclass: #CompiledBlock
  	instanceVariableNames: ''
  	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'Kernel-Methods'!
  
+ !CompiledBlock commentStamp: 'eem 2/27/2018 12:27' prior: 0!
+ CompiledBlock instances are blocks suitable for interpretation by the virtual machine.  They are a specialization of CompiledCode.  This requires both bytecode set and compiler support.  The V3 bytecode (EncoderForV3PlusClosures) does not provide support for CompiledBlock.  The SistaV1 set does (EncoderForSistaV1).
- !CompiledBlock commentStamp: 'eem 3/22/2017 12:10' prior: 0!
- CompiledBlock instances are blocks suitable for interpretation by the virtual machine.  They are a specialization oif CompiledCode.  This requires both bytecode set and compiler support.  The V3 bytecode (EncoderForV3PlusClosures) does not provide support for CompiledBlock.  The SistaV1 set does (EncoderForSistaV1).
  
  The last literal in a CompiledBlock is reserved for a reference to its enclosing CompiledBlock or CompiledMethod.  Super sends in CompiledBlocks must use the directed super send bytecode.  
  
  By convention the penultimate literal of a method is either its selector or an instance of AdditionalMethodState.  AdditionalMethodState may be used to add instance variables to a method, albeit ones held in the method's AdditionalMethodState.  Subclasses of CompiledBlock that want to add state should subclass AdditionalMethodState to add the state they want, and implement methodPropertiesClass on the class side of the CompiledBlock subclass to answer the specialized subclass of AdditionalMethodState.  Enterprising programmers are encouraged to try and implement this support automatically through suitable modifications to the compiler and class builder.!

Item was changed:
  ByteArray variableByteSubclass: #CompiledCode
  	instanceVariableNames: ''
  	classVariableNames: 'LargeFrame PreferredBytecodeSetEncoderClass PrimaryBytecodeSetEncoderClass SecondaryBytecodeSetEncoderClass SmallFrame'
  	poolDictionaries: ''
  	category: 'Kernel-Methods'!
  
+ !CompiledCode commentStamp: 'eem 2/27/2018 12:23' prior: 0!
+ CompiledCode instances are methods suitable for execution by the virtual machine.  Instances of CompiledCode and its subclasses are the only objects in the system that have both indexable pointer fields and indexable 8-bit integer fields.  The pointer fields are used for literals and metadata, and the bytes are used for bytecodes and a variety of encoded informaton such as source code, source code position, etc.  The first part of a CompiledCode object is pointers, the second part is bytes.  CompiledCode inherits from ByteArray to avoid duplicating some of ByteArray's methods, not because a CompiledCode is-a ByteArray.
- !CompiledCode commentStamp: 'eem 3/23/2017 14:33' prior: 0!
- CompiledCode instances are methods suitable for execution by the virtual machine.  Instances of CompiledCode and its subclasses are the only objects in the system that have both indexable pointer fields and indexable 8-bit integer fields.  The first part of a CompiledCode object is pointers, the second part is bytes.  CompiledCode inherits from ByteArray to avoid duplicating some of ByteArray's methods, not because a CompiledCode is-a ByteArray.
  
  Instance variables: *indexed* (no named inst vars)
  
  Class variables:
  SmallFrame								- the number of stack slots in a small frame Context
  LargeFrame							- the number of stack slots in a large frame Context
  PrimaryBytecodeSetEncoderClass		- the encoder class that defines the primary instruction set
  SecondaryBytecodeSetEncoderClass	- the encoder class that defines the secondary instruction set
  
  The current format of a CompiledCode object is as follows:
  
  	header (4 or 8 bytes, SmallInteger)
  	literals (4 or 8 bytes each, Object, see "The last literal..." below)
  	bytecodes  (variable, bytes)
  	trailer (variable, bytes)
  
  The header is a SmallInteger (which in the 32-bit system has 31 bits, and in the 64-bit system, 61 bits) in the following format:
  
  	(index 0)		15 bits:	number of literals (#numLiterals)
  	(index 15)		  1 bit:	jit without counters - reserved for methods that have been optimized by Sista
  	(index 16)		  1 bit:	has primitive
  	(index 17)		  1 bit:	whether a large frame size is needed (#frameSize => either SmallFrame or LargeFrame)
  	(index 18)		  6 bits:	number of temporary variables (#numTemps)
  	(index 24)		  4 bits:	number of arguments to the method (#numArgs)
  	(index 28)		  2 bits:	reserved for an access modifier (00-unused, 01-private, 10-protected, 11-public), although accessors for bit 29 exist (see #flag).
  	sign bit:		  1 bit: selects the instruction set, >= 0 Primary, < 0 Secondary (#signFlag)
  
  If the method has a primitive then the first bytecode of the method must be a callPrimitive: bytecode that encodes the primitive index.  This bytecode can encode a primitive index from 0 to 65535.
  
  The trailer is an encoding of an instance of CompiledMethodTrailer.  It is typically used to encode the index into the source files array of the method's source, but may be used to encode other values, e.g. tempNames, source as a string, etc.  See the class CompiledMethodTrailer.
  
  While there are disadvantages to this "flat" representation (it is impossible to add named instance variables to CompiledCode or its subclasses, but it is possible indirectly; see AdditionalMethodState) it is effective for interpreters.  It means that both bytecodes and literals can be fetched directly from a single method object, and that only one object, the method, must be saved and restored on activation and return.  A more natural representation, in which there are searate instance variables for the bytecode, and (conveniently) the literals, requires either much more work on activation and return setting up references to the literals and bytecodes, or slower access to bytecodes and literals, indirecting on each access.
  
  The last literal of a CompiledCode object is reserved for special use by the kernel and/or the virtual machine.  In CompiledMethod instances it must either be the methodClassAssociation, used to implement super sends, or nil, if the method is anonymous. In CompiledBlock it is to be used for a reference to the enclosing method or block object.
  
+ By convention, the penultimate literal is reserved for special use by the kernel. In CompiledMethod instances it must either be the method selector, or an instance of AdditionalMethodState which holds the selector and any pragmas or properties in the method.  In CompiledBlock it is reserved for use for an AdditionalMethodState.
- By convention, the penultimate literal is reserved for special use by the kernel. CompiledMethod instances it must either be the method selector, or an instance of AdditionalMethodState which holds the selector and any pragmas or properties in the method.  In CompiledBlock it is reserved for use for an AdditionalMethodState.
  
  Note that super sends in CompiledBlock instances do not use a methodClass association, but expect a directed supersend bytecode, in which the method class (the subclass of the class in which to start the lookup) is a literal.  Logically when we switch to a bytecode set that supports the directed super send bytecode, and discard the old super send bytecodes, we can use the last literal to store the selector or the enclosing method/block or an AdditionalMethodState, and the AdditionalMethodState can hold the selector and/or the enclosing method/block.!

Item was changed:
  CompiledCode variableByteSubclass: #CompiledMethod
  	instanceVariableNames: ''
  	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'Kernel-Methods'!
  
+ !CompiledMethod commentStamp: 'eem 2/27/2018 12:48' prior: 0!
+ CompiledMethod instances are methods suitable for interpretation by the virtual machine.  They are a specialization of CompiledCode.  They represent methods, and may also, depending on the bytecode set, include nested blocks.  Bytecode sets that support non-nested blocks use CompiledBlock instances to implement nested block methods, that are separate from their enclosing method.  Bytecode sets that do not support non-nested blocks require the literals and bytecodes for a block to occur within the literals and bytecodes of a single CompiledMethod.  For example, the inject:into: method in the EncoderForV3PlusClosures bytecode set is as follows
- !CompiledMethod commentStamp: 'eem 3/22/2017 13:17' prior: 0!
- CompiledMethod instances are methods suitable for interpretation by the virtual machine.  They are a specialization of CompiledCode.  They represent methods, and may also, depending on the bytecode set, include nested blocks.  Bytecode sets that support non-nested blocks with use CompiledBlock instances to implement nested block methods, that are separate from their enclosing method.  This requires compiler support.
  
+ Collection>>#inject:into:
+ 	header	((primitive: 0) (numArgs: 2) (numTemps: 3) (numLiterals: 3) (frameSize: 16) (bytecodeSet: V3PlusClosures))
+ 	literal1	#value:value:
+ 	literal2	#inject:into:
+ 	literal3	#Collection=>Collection
+ 	33	<8A 01> push: (Array new: 1)
+ 	35	<6A> popIntoTemp: 2
+ 	36	<10> pushTemp: 0
+ 	37	<8E 00 02> popIntoTemp: 0 inVectorAt: 2
+ 	40	<70> self
+ 	41	<11> pushTemp: 1
+ 	42	<12> pushTemp: 2
+ 	43	<8F 21 00 0A> closureNumCopied: 2 numArgs: 1 bytes 47 to 56
+ 	47	        <11> pushTemp: 1
+ 	48	        <8C 00 02> pushTemp: 0 inVectorAt: 2
+ 	51	        <10> pushTemp: 0
+ 	52	        <F0> send: value:value:
+ 	53	        <8D 00 02> storeIntoTemp: 0 inVectorAt: 2
+ 	56	        <7D> blockReturn
+ 	57	<CB> send: do:
+ 	58	<87> pop
+ 	59	<8C 00 02> pushTemp: 0 inVectorAt: 2
+ 	62	<7C> returnTop
+ 
+ whereas using the encoderForSistaV1 bytecode set it is
+ 
+ Collection>>#inject:into:
+ 	header	((primitive: 0) (numArgs: 2) (numTemps: 3) (numLiterals: 3) (frameSize: 16) (bytecodeSet: #SistaV1))
+ 	literal1	([] in Collection>>#inject:into: "a CompiledBlock(3755867)")
+ 	literal2	#inject:into:
+ 	literal3	#Collection=>Collection
+ 	33	<E7 01> push: (Array new: 1)
+ 	35	<D2> popIntoTemp: 2
+ 	36	<40> pushTemp: 0
+ 	37	<FD 00 02> popIntoTemp: 0 inVectorAt: 2
+ 	40	<4C> self
+ 	41	<41> pushTemp: 1
+ 	42	<42> pushTemp: 2
+ 	43	<F9 00 02> closureNumCopied: 2 numArgs: 1
+ 	46	<7B> send: do:
+ 	47	<D8> pop
+ 	48	<FB 00 02> pushTemp: 0 inVectorAt: 2
+ 	51	<5C> returnTop
+ 
+ [] in Collection>>#inject:into: "a CompiledBlock(3755867)"
+ 	header	((block #full) (numArgs: 1) (numTemps: 3) (numLiterals: 3) (frameSize: 16) (bytecodeSet: #SistaV1))
+ 	literal1	#value:value:
+ 	literal2	nil
+ 	literal3	(Collection>>#inject:into: "a CompiledMethod(736427)")
+ 	33	<41> pushTemp: 1
+ 	34	<FB 00 02> pushTemp: 0 inVectorAt: 2
+ 	37	<40> pushTemp: 0
+ 	38	<A0> send: value:value:
+ 	39	<FC 00 02> storeIntoTemp: 0 inVectorAt: 2
+ 	42	<5E> blockReturn
+ 
  The last literal in a CompiledMethod must be its methodClassAssociation, a binding whose value is the class the method is installed in.  The methodClassAssociation is used to implement super sends.  If a method contains no super send then its methodClassAssociation may be nil (as would be the case for example of methods providing a pool of inst var accessors).  
  
  By convention the penultimate literal of a method is either its selector or an instance of AdditionalMethodState.  AdditionalMethodState holds the method's selector and any pragmas and properties of the method.  AdditionalMethodState may also be used to add instance variables to a method, albeit ones held in the method's AdditionalMethodState.  Subclasses of CompiledMethod that want to add state should subclass AdditionalMethodState to add the state they want, and implement methodPropertiesClass on the class side of the CompiledMethod subclass to answer the specialized subclass of AdditionalMethodState.  Enterprising programmers are encouraged to try and implement this support automatically through suitable modifications to the compiler and class builder.!



More information about the Squeak-dev mailing list