eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'CompiledCode':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: CompiledCode


Inheritance:

   Object
   |
   +--ExecutableFunction
      |
      +--CompiledCode
         |
         +--Block
         |
         +--Method

Package:
stx:libbasic
Category:
Kernel-Methods
Version:
rev: 1.145 date: 2018/05/15 16:09:27
user: cg
file: CompiledCode.st directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
Claus Gittinger

Description:


This is an abstract class, to merge common attributes of Blocks and
Methods i.e. describe all objects consisting of either compiled or
interpreted code.

Instances of CompiledCode are not to be created by user code
(the compilers create Blocks, Methods etc.)


[Instance variables:]

  flags       <SmallInteger>    special flag bits coded in a number
  byteCode    <ByteArray>       bytecode if it's an interpreted codeobject

  The block/methods literals are stored in the indexed instance variables.
  If there is only one indexed instvar, it contains a reference to an
  Object containing the literals.


[Class variables:]

  NoByteCodeSignal              raised if a codeObject is about to be executed
                                which has neither code nor byteCode (i.e. both are nil)
  InvalidByteCodeSignal         raised if byteCode is not an instance of ByteArray
  InvalidInstructionSignal      raised if an invalid instruction opcode is encountered
  BadLiteralsSignal             raised if literalArray is not an array
  NonBooleanReceiverSignal      raised for conditional jumps where receiver is not a boolean
  ArgumentSignal                raised if argument count is not what the codeObject expects

all of these signals are children of ExecutionErrorSignal.

NOTICE: layout known by runtime system and compiler - do not change


Class protocol:

Signal constants
o  wongNumberOfArgumentsSignal
return the signal raised when the number of arguments is wrong in a call

instance creation
o  new
create a new method with an indirect literal array
stored in the first and only indexed instvar

o  new: numberOfLiterals
create a new method with numberOfLiterals.
Implementation note:
If (self size) == 1, the only literal is an indirect literal
containing an array of literals. Otherwise the literals
are stored in self.

queries
o  isAbstract

o  isBuiltInClass
return true if this class is known by the run-time-system.
Here, true is returned for myself, false for subclasses.

o  maxNumberOfArguments
return the maximum number of arguments a method can have.
This is a limit in the VM, which may be removed in one of
the next versions ...

o  numArgsMaskInFlags
fallback if no primitive code
usage example(s):
     self numArgsMaskInFlags

o  numArgsShiftInFlags
fallback if no primitive code
usage example(s):
     self numArgsShiftInFlags

o  numVarsMaskInFlags
fallback if no primitive code
usage example(s):
     self numVarsMaskInFlags

o  numVarsShiftInFlags
fallback if no primitive code
usage example(s):
     self numVarsShiftInFlags


Instance protocol:

Compatibility-ANSI
o  argumentCount
ANSI alias for numArgs: return the number of arguments, the method expects.

Compatibility-ST80
o  getSource
return the code object's source code, nil if none is available

o  getSourceForUserIfNone: aBlock
return the code object's source code.
If none is available, return the result from evaluating aBlock.

o  initialPC

o  methodClass
return the class I am defined in

o  sourceString
return the code object's source code, nil if none is available

o  withAllBlockMethodsDo: aBlock

Compatibility-V'Age
o  bytecodes

accessing
o  allLiterals
return a collection of all literals (includes all block literals)

o  allSymbolLiterals
return a collection of all symbol-literals

o  byteCode
return the bytecode (a ByteArray)

o  changeLiteral: aLiteral to: newLiteral
change aLiteral to newLiteral

o  decompiledSource
reconstruct some synthetic source by decompiling by byteCode

o  decompilerClass

o  do: aBlock
same as #literalsDo:, in order to get common protocol with Array

o  flags
return the flags (number of method variables, stacksize etc.).
Don't depend on the values in the flag field - its interpretations
may change without notice.

o  homeMethod
for common protocol with blocks: if the receiver is a method,
return the receiver; otherwise, if it's a block, return its home
method.

o  literalAt: index
return a literal element

o  literalAt: index ifAbsent: exceptionalValue
return a literal element

o  literalAt: index put: newValue
change a literal slots value.
WARNING: dangerous internal interface; only for knowledgable users

o  literals
return the literals as an array
usage example(s):
     (CompiledCode compiledMethodAt:#literals) literals

o  literalsDetect: aBlock ifNone: exceptionBlock
execute a one arg block for each of our literals.
Return the first literal for which aBlock returns true,
or the value from exceptionBlock, if either no literals or
none satisfied the block

o  literalsDo: aBlock
execute a one arg block for each of our literals

o  mclass
return the class of the receiver's home method.
That's the class of the method where the block was compiled.

o  numLiterals
return the number of literals I have

o  numberOfMethodArgs
return the number of arguments, the method expects.
This method is left for backward compatibility - use #argumentCount.

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  numberOfMethodVars
return the number of method local variables.
This method is left for backward compatibility - use #numVars.

o  source

compiler interface
o  compilerClass
who is responsible to parse the source code?
Fetch it from the class
usage example(s):
     (Object compiledMethodAt:#at:) compilerClass

o  parserClass
who is responsible to parse the source code?
Fetch it from the class
usage example(s):
     (Object compiledMethodAt:#at:) parserClass

o  programmingLanguage
the following is correct, but might be too slow...
usage example(s):
^ mclass programmingLanguage

o  syntaxHighlighterClass
if #askClass is returned here, my owning class will be asked for the syntaxHighlighter.
if nil is returned, no syntaxHighlighting will be done.
Can be redefined in subclasses (MetaMethod) which use special syntax.

converting
o  makeRealMethod
by default, we are a real method.
Subclasses (e.g. LazyMethod) may redefine this

debugging
o  breakPointAfter: countInvocations
arrange for a breakpoint-debugger to be opened when this method
was invoked countInvocations times.

o  breakPointIf: conditionBlock
arrange for a breakpoint-debugger to be opened when this method
is invoked AND conditionBlock evaluates to true.
conditionBlock gets context and method as (optional) arguments.

o  breakPointInProcess: aProcess
arrange for a breakpoint-debugger to be opened when this method
is invoked from withn aProcess.

o  breakPointOnReturnIf: conditionBlock
arrange for a breakpoint-debugger to be opened when this method
returns AND conditionBlock evaluates to true.
conditionBlock gets returnValue, context and method as (optional) arguments.

o  clearBreakPoint
remove any break/trace-point on this method

o  isCounted
obsolete - replaced by isCountingMemoryUsage

o  isCounting
return true, if invokations of this method are counted

o  isCountingByReceiverClass
return true, if invokations of this method are counted

o  isCountingMemoryUsage
return true, if memory allocations done by this method (and callees)
are counted

o  isTiming
return true if timing statistics are being gathered on this method.

o  resetCountingStatistics
reset count statistics of the receiver

o  resetMemoryUsageStatistics
reset count statistics of the receiver

o  resetTimingStatistics
reset timing statistics of the receiver

o  setBreakPoint
arrange for a breakpoint-debugger to be opened when this method
is invoked.

o  setTraceFullPoint
arrange for a full-backtrace to be sent to the standard-error stream
when this method is invoked.

o  setTracePoint
arrange for a trace-message to be sent to the standard-error stream
when this method is invoked.

o  setTraceSenderPoint
arrange for a sender-trace-message to be sent to the standard-error stream
when this method is invoked.

o  setTracelog
( an extension from the stx:libbasic3 package )
Arrange for a trace logging - enter/leave of the method will be logged using
current Logger

o  startCounting
start counting invokations of the receiver

o  startCountingByReceiverClass
start counting invokations of the receiver

o  startCountingMemoryUsage
start counting memory usage of the receiver (and every callee)

o  startTiming
start timing the receiver

o  stopCounting
stop counting calls of the receiver

o  stopCountingMemoryUsage
stop counting memory usage of the receiver

o  stopTiming
stop timing of the receiver

enumeration
o  breakpointsDo: aBlock
Evaluate `aBlock` for every breakpoint installed in this method

error handling
o  badArgumentArray: argsGiven
this error is triggered, if a non-array is passed to
#valueWithReceiver:.. type of methods

o  badLiteralTable
this error is triggered, when a block/method is called with a bad literal
array (i.e. non-array) - this can only happen, if the
compiler is broken or someone played around with a blocks/methods
literal table or the GC is broken and corrupted it.

o  interpretWithReceiver: aReceiver
invoked by VM for non-Smalltalk-methods (MetaMethods)

** This method raises an error - it must be redefined in concrete classes **

o  interpretWithReceiver: aReceiver arg: arg1
invoked by VM for non-Smalltalk-methods (MetaMethods)

** This method raises an error - it must be redefined in concrete classes **

o  interpretWithReceiver: aReceiver arg: arg1 arg: arg2
invoked by VM for non-Smalltalk-methods (MetaMethods)

** This method raises an error - it must be redefined in concrete classes **

o  interpretWithReceiver: aReceiver arg: arg1 arg: arg2 arg: arg3
invoked by VM for non-Smalltalk-methods (MetaMethods)

** This method raises an error - it must be redefined in concrete classes **

o  interpretWithReceiver: aReceiver arguments: argVector
invoked by VM for non-Smalltalk-methods (MetaMethods)

** This method raises an error - it must be redefined in concrete classes **

o  invalidByteCode
this error is triggered when the interpreter tries to execute a
code object, where the byteCode is nonNil, but not a ByteArray.
Can only happen when Compiler/runtime system is broken or
someone played around with a blocks/methods code.

o  invalidInstruction
this error is triggered when the bytecode-interpreter tries to
execute an invalid bytecode instruction.
Can only happen when Compiler/runtime system is broken or
someone played around with a blocks/methods code.

o  noByteCode
this error is triggered when the interpreter tries to execute a
code object, where both the code and byteCode instances are nil.
This can happen if:
- the Compiler/runtime system is broken, (should not happen)

- someone played around with a block/method, (you should not do this)

- compilation of a lazy method failed
(i.e. the lazy method contains an error or
it contains primitive code and there is no stc compiler available)

- an unloaded object modules method is called for.

Only the first case is to be considered serious
- it should not happen if the system is used correctly.

o  receiverNotBoolean: anObject
this error is triggered when the bytecode-interpreter tries to
execute ifTrue:/ifFalse or whileTrue: - type of expressions where the
receiver is neither true nor false.
Machine compiled code does not detect this, and may behave undeterministec.

o  tooManyArguments
this error is triggered, when a method/block tries to perform a send with
more arguments than supported by the interpreter.
This can only happen, if the compiler has been changed without
updating the VM, since the compiler checks for allowed number of
arguments.

o  wrongNumberOfArguments: numArgsGiven
this error is triggered by the VM, if a method is called with a wrong number
of arguments.
This only applies to #valueWithReceiverXXX and #perform:withArguments: - sends.
With a normal send, this error cannot happen.

executing
o  valueWithReceiver: anObject arguments: argArray
low level call of a method's code - BIG DANGER ALERT.
Perform the receiver-method on anObject as receiver and argArray as
arguments. This does NO message lookup at all and mimics a
traditional function call.
This method is provided for debugging- and breakpoint-support
(replacing a method by a stub and recalling the original), or to implement
experimental MI implementations - it is not for general use.

The receiver must be a method compiled in anObject's class or one of its
superclasses and also, the number of arguments given must match the method's
expectations -
- otherwise strange things (and also strange crashes) can occur.
The system is NOT always detecting a wrong method/receiver combination.
YOU HAVE BEEN WARNED.

o  valueWithReceiver: anObject arguments: argArray selector: aSymbol
low level call of a methods code - BIG DANGER ALERT.
Perform the receiver-method on anObject as receiver and argArray as
arguments. This does NO message lookup at all and mimics a
traditional function call.
This method is provided for debugging- and breakpoint-support
(replacing a method by a stub and recalling the original), or to implement
experimental MI implementations - it is not for general use.

The receiver must be a method compiled in anObject's class or one of its
superclasses and also, the number of arguments given must match the method's
expectations -
- otherwise strange things (and also strange crashes) can occur.
The system is NOT always detecting a wrong method/receiver combination.
YOU HAVE BEEN WARNED.

o  valueWithReceiver: anObject arguments: argArray selector: aSymbol search: aClass
low level call of a methods code - BIG DANGER ALERT.
Perform the receiver-method on anObject as receiver and argArray as
arguments. This does NO message lookup at all and mimics a
traditional function call.
This method is provided for debugging- and breakpoint-support
(replacing a method by a stub and recalling the original), or to implement
experimental MI implementations - it is not for general use.

The receiver must be a method compiled in anObject's class or one of its
superclasses and also, the number of arguments given must match the method's
expectations -
- otherwise strange things (and also strange crashes) can occur.
The system is NOT always detecting a wrong method/receiver combination.
YOU HAVE BEEN WARNED.

o  valueWithReceiver: anObject arguments: argArray selector: aSymbol search: aClass sender: virtualSender
low level call of a methods code - BIG DANGER ALERT.
Perform the receiver-method on anObject as receiver and argArray as arguments.
This does NO message lookup at all and mimics a traditional function call.
This method is provided for debugging- and breakpoint-support
(replacing a method by a stub and recalling the original), or to implement
experimental MI implementations - it is not for general use.

The receiver must be a method compiled in anObject's class or one of its
superclasses and also, the number of arguments given must match the methods
expectations -
- otherwise strange things (and also strange crashes) can occur.
The system is NOT always detecting a wrong method/receiver combination.
YOU HAVE BEEN WARNED.
usage example(s):
     (Float compiledMethodAt:#+)
	valueWithReceiver:1.0 arguments:#(2.0)

     'the next example is a wrong one - which is detected by True's method ...'.
     (True compiledMethodAt:#printString)
	valueWithReceiver:false arguments:nil

     'the next example is a wrong one - it is nowhere detected
      and a wrong value returned ...'.
     (Point compiledMethodAt:#x)
	valueWithReceiver:(1->2) arguments:nil

     'the next example is VERY bad one - it is nowhere detected
      and may crash the system WARNING: save your work before doing this ...'.
     (Point compiledMethodAt:#x)
	valueWithReceiver:(Object new) arguments:nil

     'the next example is a wrong one - which is detected here ...'.
     (Object compiledMethodAt:#printOn:)
	valueWithReceiver:false arguments:nil

     'the next example is a wrong one - which is detected here ...'.
     (Object compiledMethodAt:#printOn:)
	valueWithReceiver:false arguments:#()

private-accessing
o  byteCode: aByteArray
set the bytecode field - DANGER ALERT

o  checked: aBoolean
set/clear the flag bit stating that this method has already been checked
by the just-in-time compiler.
Setting the flag prevents it from trying any compilation.
Not for public use - for VM debugging only.

o  clearJittedCodeAndForceJittingAgain
clear the method's jitted code and clear the flag bit stating that this method has already been checked
by the just-in-time compiler. Thus, it will be recompiled when called the next time.
Not for public use - for VM debugging only.

o  dynamic
return the flag stating that the machine code was created
dynamically (from bytecode) or loaded dynamically from an objectFile
(i.e. has machineCode, but is not in the executable).

o  literals: aLiteralArray
set the literal array for evaluation - DANGER ALERT

o  markFlag
return the mark bits value as a boolean.
This bit is not used by the VM, but instead free to mark codeObjects
for any (debugging/tracing) use. For example, the coverage test uses
these to mark reached methods. (inspired by a note in c.l.s)

o  markFlag: aBoolean
set/clear the mark flag bit.
This bit is not used by the VM, but instead free to mark codeObjects
for any (debugging/tracing) use. For example, the coverage test uses
these to mark reached methods. (inspired by a note in c.l.s)

private-compiler interface
o  contextMustBeReturnable: aBoolean

o  flags: newFlags
set the flags (number of method variables, stacksize).
WARNING: for internal use by the compiler only.
playing around here with incorrect values
may crash smalltalk badly.

Don't depend on the values in the flag field - its interpretations
may change without notice.

o  marked: aBoolean
Sets the mark bit. You may use it for whatever you want. Actually,
it's used for marking profiled methods

o  numberOfArgs: aNumber
set the number of arguments, the codeObject expects.
WARNING: for internal use by the compiler only.
playing around here with incorrect values
may (will ?) crash smalltalk badly.

The limitation in the max. number of arguments is due to the
missing SENDxx functions in the VM and cases in #perform. This too
will be removed in a later release, allowing any number of arguments.

o  numberOfVars: aNumber
set the number of local variables - for use by compiler only.
WARNING: for internal use by the compiler only.
playing around here with incorrect values
may (will ?) crash smalltalk badly.

o  stackSize
return thedepth of the local stack in the context.

WARNING: for internal use by ST/X debuggers only.
This method may be removed without notice.

o  stackSize: aNumber
set the depth of the local stack.

WARNING: for internal use by the compiler only.
playing around here with incorrect values
may crash smalltalk badly.
if the runtime library was compiled with DEBUG,
a bad stack will be detected and triggers an error
(by default, the VM is compiled with this option)

queries
o  decompileTo: aStream

o  hasAnnotation: key
Return false here, as a fallback

o  isChecked
return true, if this method has been analyzed for jitting

o  isDynamic
return true, if the machine code was created
dynamically (from bytecode); false if the machine code was
already present in an objectFile
(i.e. has JIT-compiled machineCode, as opposed to stc-compiled code).

o  isExecutable
return true, if this method is executable.
I.e. neither an invalidated nor an unloaded method

o  isExtension
return true, if this method is an extension (i.e. package ~= classes' package)

o  isMarked
return true, if this method has been marked (for whatever reason)

o  isUnloaded
return true, if the method's machine code has been unloaded
from the system (i.e. it is not executable).

o  messages
return a Set of all symbols referenced by this thingy.
(this is more than the message selectors, since also global names
and symbols found in immediate arrays are included).
usage example(s):
     (CompiledCode compiledMethodAt:#messages) messages

o  numArgs
return the number of arguments, the method expects.
Please use argumentCount for ANSI compatibility.
usage example(s):
     (Method compiledMethodAt:#source) numArgs
     (Method compiledMethodAt:#source:) numArgs

o  numVars
return the number of block local variables.
Do not depend on the returned value - future optimizations
may change things here (i.e. when moving locals into
surrounding context for inlining).
- for debugging only.

o  referencesGlobal: aGlobalSymbol
return true, if this method references the global named aGlobalSymbol.
For now, this is the same as #referencesLiteral:,
but this might change in the future to perform a deeper
analyzes on the bytecodes, to detect implicit global
refs (as done by some special bytecodes)
usage example(s):
     (CompiledCode compiledMethodAt:#referencesGlobal:) referencesGlobal:#referencesLiteral:
     (CompiledCode compiledMethodAt:#referencesGlobal:) referencesGlobal:#bla

o  referencesGlobalMatching: aMatchPattern
return true, if this method references the given a literal symbol,
which matches the given pattern.
usage example(s):
     (CompiledCode compiledMethodAt:#referencesGlobalMatching:) referencesGlobalMatching:'*atch*'
     (CompiledCode compiledMethodAt:#referencesGlobalMatching:) referencesGlobalMatching:'*batch*'

o  referencesLiteral: aLiteral
return true, if this method references the given literal directly
(i.e. a flat search, which does not look deeper into literal arrays).
usage example(s):
     (CompiledCode compiledMethodAt:#referencesLiteral:) referencesGlobal:#literalsDetect:ifNone:
     (CompiledCode compiledMethodAt:#referencesLiteral:) referencesGlobal:#bla

o  refersToLiteral: aLiteral
return true if the receiver, or recursively any array element in the receiver,
refers to aLiteral (i.e. a deep search)
usage example(s):
     (CompiledCode compiledMethodAt:#refersToLiteral:) refersToLiteral:#foo
     (CompiledCode compiledMethodAt:#refersToLiteral:) refersToLiteral:#class

o  refersToLiteralMatching: aMatchPattern
return true if the receiver, or recursively any array element in the receiver,
is symbolic and matches aMatchPattern (i.e. a deep search)
usage example(s):
     (CompiledCode compiledMethodAt:#refersToLiteralMatching:) refersToLiteral:'is*'
     (CompiledCode compiledMethodAt:#refersToLiteralMatching:) refersToLiteral:'foo*'



ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Fri, 20 Jul 2018 06:37:13 GMT