VM Maker: VMMaker.oscog-eem.2435.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

VM Maker: VMMaker.oscog-eem.2435.mcz

commits-2
 
Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.2435.mcz

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

Name: VMMaker.oscog-eem.2435
Author: eem
Time: 24 August 2018, 4:52:23.139258 pm
UUID: b14b74e3-fc8b-4450-becf-350fc12c9ff1
Ancestors: VMMaker.oscog-eem.2434

Work around the hack use of (dis)ownVM: for storing the argumentCount of the current method on callback return in the non-threaded VM.  The argument to disownVM: is either an immediate integer (callback) or flags which can't be immediate (FFI callout, plugin primitive callout).  I regret this but it works, so keep it going for now.

=============== Diff against VMMaker.oscog-eem.2434 ===============

Item was changed:
  ----- Method: CoInterpreterMT class>>initializeMiscConstants (in category 'initialization') -----
  initializeMiscConstants
 
  super initializeMiscConstants.
 
  "N.B. some of these DisownFlags are replicated in platforms/Cross/vm/sqVirtualMachine.h.
  Hence they should always be initialized."
+ DisownVMForProcessorRelinquish := 64.
- DisownVMForProcessorRelinquish := 8.
 
  (InitializationOptions at: #COGMTVM ifAbsent: [false]) == false ifTrue:
  [^self].
 
  COGMTVM := true.
 
  ReturnToThreadSchedulingLoop := 2 "setjmp/longjmp code."!

Item was removed:
- ----- Method: SpurMemoryManager>>activateFailingPrimitiveMethod (in category 'simulation only') -----
- activateFailingPrimitiveMethod
- "hack around the CoInterpreter/ObjectMemory split refactoring"
- <doNotGenerate>
- ^coInterpreter activateFailingPrimitiveMethod!

Item was added:
+ ----- Method: SpurMemoryManager>>disownVM: (in category 'simulation only') -----
+ disownVM: flags
+ "hack around the CoInterpreter/ObjectMemory split refactoring"
+ <doNotGenerate>
+ ^coInterpreter disownVM: flags!

Item was added:
+ ----- Method: SpurMemoryManager>>ownVM: (in category 'simulation only') -----
+ ownVM: flags
+ "hack around the CoInterpreter/ObjectMemory split refactoring"
+ <doNotGenerate>
+ ^coInterpreter ownVM: flags!

Item was changed:
  ----- Method: StackInterpreter class>>initializeMiscConstants (in category 'initialization') -----
  initializeMiscConstants
 
  super initializeMiscConstants.
  STACKVM := true.
 
  "These flags function to identify a GC operation, or
  to specify what operations the leak checker should be run for."
  GCModeFull := 1. "stop-the-world global GC"
  GCModeNewSpace := 2. "Spur's scavenge, or V3's incremental"
  GCModeIncremental := 4. "incremental global gc (Dijkstra tri-colour marking); as yet unimplemented"
  GCModeBecome := 8. "v3 post-become sweeping/Spur forwarding"
  GCModeImageSegment := 16. "just a flag for leak checking image segments"
  GCModeFreeSpace := 32. "just a flag for leak checking free space; Spur only"
  GCCheckPrimCall := 64. "just a flag for leak checking external primitive calls"
 
  StackPageTraceInvalid := -1.
  StackPageUnreached := 0.
  StackPageReachedButUntraced := 1.
  StackPageTraced := 2.
 
  DumpStackOnLowSpace := 0.
  MillisecondClockMask := 16r1FFFFFFF.
  "Note: The external primitive table should actually be dynamically sized but for the sake of inferior platforms (e.g., Mac :-) who cannot allocate memory in any reasonable way, we keep it static (and cross our fingers...)"
  MaxExternalPrimitiveTableSize := 4096. "entries"
 
  MaxJumpBuf := 32. "max. callback depth"
  FailImbalancedPrimitives := InitializationOptions at: #FailImbalancedPrimitives ifAbsentPut: [true].
  EnforceAccessControl := InitializationOptions at: #EnforceAccessControl ifAbsent: [true].
 
  ReturnToInterpreter := 1. "setjmp/longjmp code."
 
  "N.B. some of these DisownFlags are replicated in platforms/Cross/vm/sqVirtualMachine.h.
+ Hence they should always be initialized.  Because of a hack with callbacks in the non-threaded
+ VM they must not conflct with the VM's tag bits."
+ DisownVMLockOutFullGC := 8.
+ DisownVMForFFICall := 16.
+ DisownVMForThreading := 32
- Hence they should always be initialized."
- DisownVMLockOutFullGC := 1.
- DisownVMForFFICall := 2.
- DisownVMForThreading := 4
  !

Item was changed:
  ----- Method: StackInterpreter>>disownVM: (in category 'vm scheduling') -----
  disownVM: flags
  <api>
  <inline: false>
  "Release the VM to other threads and answer the current thread's index.
  Currently valid flags for the non-threaded VM are:
  DisownVMLockOutFullGC - prevent fullGCs while this thread disowns the VM
  DisownVMForFFICall - informs the VM that it is entering an FFI call
 
  This is the entry-point for plugins and primitives that wish to release the VM while
  performing some operation that may potentially block, and for callbacks returning
  back to some blocking operation.  While this exists for the threaded FFI VM we use
  it to reset newMethod and the argumentCount after a callback."
- self assert: ((objectMemory isIntegerObject: flags)
- and: [(objectMemory integerValueOf: flags)
- between: 0
- and: (self argumentCountOfMethodHeader: -1)]).
  self assert: primFailCode = 0.
 
+ "Hack encodings of client state.  We use non-immediates (bottom three bits clear)
+ for FFI/Plugin doing
+ save := self disownVM: FLAGS. ... callout ... self ownVM: save.
+ We use immediate integer (bottom bit 1) for callbacks doing
+ save := self ownVM: 0. ... callback ... self disownVM: save. return to C"
+ self assert: ((objectMemory isImmediate: flags)
+ ifFalse:
+ [flags = (flags bitAnd: DisownVMLockOutFullGC+DisownVMForFFICall+DisownVMForThreading)
+ and: [flags anyMask: DisownVMForFFICall]]
+ ifTrue:
+ [(objectMemory isIntegerObject: flags)
+ and: [(objectMemory integerValueOf: flags)
+ between: 0
+ and: (self argumentCountOfMethodHeader: -1)]]).
+
  "If DisownVMForFFICall this is from the FFI plugin and we're making a callout; remember the fact."
+ (((objectMemory isImmediate: flags)) not
+ and: [flags anyMask: DisownVMForFFICall]) ifTrue:
- (flags anyMask: DisownVMForFFICall) ifTrue:
  [self assert: ((objectMemory isOopCompiledMethod: newMethod)
  and: [(self argumentCountOf: newMethod) = argumentCount]).
  inFFIFlags := DisownVMForFFICall.
  ^flags].
 
+ self assert: ((objectMemory isIntegerObject: flags)
+ and: [(objectMemory integerValueOf: flags)
+ between: 0
+ and: (self argumentCountOfMethodHeader: -1)]).
+
  "Otherwise this is a callback return; restore argumentCount and newMethod as per the ownVM: on callback."
  argumentCount := objectMemory integerValueOf: flags.
  newMethod := self popStack.
  self assert: ((objectMemory isOopCompiledMethod: newMethod)
  and: [(self argumentCountOf: newMethod) = argumentCount]).
  ^0!

Item was changed:
  ----- Method: StackInterpreter>>ownVM: (in category 'vm scheduling') -----
  ownVM: threadIndexAndFlags
  <api>
  <inline: false>
  "This is the entry-point for plugins and primitives that wish to reacquire the VM after having
  released it via disownVM or callbacks that want to acquire it without knowing their ownership
  status.  While this exists for the threaded FFI VM we use it to reset newMethod and the
  argumentCount after a callback.
 
  Answer -1 if the current thread is unknown to the VM and fails to take ownership."
  <var: 'amInVMThread' declareC: 'extern sqInt amInVMThread(void)'>
+ self cppIf: COGMTVM
+ ifTrue:
+ [self amInVMThread ifFalse:
+ [^-1]].
+
- self amInVMThread ifFalse:
- [^-1].
- self assert: primFailCode = 0.
  self assert: ((objectMemory isOopCompiledMethod: newMethod)
  and: [(self argumentCountOf: newMethod) = argumentCount]).
 
+ "Hack encodings of client state.  We use non-immediates (bottom three bits clear)
+ for FFI/Plugin doing
+ save := self disownVM: FLAGS. ... callout ... self ownVM: save.
+ We use immediate integer (bottom bit 1) for callbacks doing
+ save := self ownVM: 0. ... callback ... self disownVM: save. return to C"
+
  "If DisownVMForFFICall this is from the FFI plugin and we're returning from a callout."
  (threadIndexAndFlags anyMask: DisownVMForFFICall) ifTrue:
  [inFFIFlags := 0.
+ ^threadIndexAndFlags].
- ^0].
 
+ "Otherwise this is a callback; stash newMethod on the stack and encode
+ argumentCount in the flags retrieved when the calback calls disownVM:."
+ self assert: primFailCode = 0.
- "Otherwise this is a callback; stash newMethod on the stack and argumentCount in the flags
- we'll get back when the calback calls disownVM:."
  self push: newMethod.
  ^objectMemory integerObjectOf: argumentCount!