Skip to content

Commit

Permalink
CogVM source as per VMMaker.oscog-eem.3349
Browse files Browse the repository at this point in the history
Integrate VMMaker.threaded-LM.3339, 3341, 3342 & 3343.

Make vmThread>>#state an atomic_int

Allow -1 to be set as vmOwner.
This is currently used by the heartbeat thread.
In future this will be used by the ownVMFromUnidentifiedThread function.

This combines well with the additional change that makes disownVM return a CogVMThread* disguised as void*.

We can then ensure that the threads variable is only ever accessed by the vm owner.

Fix multiple issues regarding thread safety

1. vmOwner -1 can be used to lock the VM to a thread that is not a classical "VM Thread" (e.g. the heartbeat thread).
2. maxWaitingPriority is now an atomic.

Fix thread switch accidentally disowning the VM which causes an incorrect preemption.

Allow thread switching during the SqueakSSL primitiveConnect.

Rename ownerIndex to threadAffinity.

And update revertIfEssentiallyUnchanged to cope with the CryptographyPlugins.
  • Loading branch information
eliotmiranda committed Feb 13, 2024
1 parent aba9cd3 commit c1cd035
Show file tree
Hide file tree
Showing 31 changed files with 3,075 additions and 1,675 deletions.
Expand Up @@ -88,12 +88,12 @@
NSArray *arrayOfTypes = @[formatType];

[inPasteboard addTypes: arrayOfTypes owner: nil];
int ok = true;
int ok = false;
@try {
ok = [inPasteboard setData: data forType: formatType];
[inPasteboard setData: data forType: formatType];
ok = true;
}
@catch (NSException *exception) {
ok = false;
@catch (id exception) {
}
if (!ok)
interpreterProxy->primitiveFailFor(PrimErrOperationFailed);
Expand Down
4 changes: 2 additions & 2 deletions scripts/revertIfEssentiallyUnchanged
Expand Up @@ -15,14 +15,14 @@ for f in "$@"; do
*M*) ;;
*) continue
esac
RESULT="`git diff -- "$f" | grep '^[+-]' | egrep -v ' VMMaker[-.][a-z][a-z-]*\.[0-9][0-9]* uuid:| Cog[-.][a-z][a-z]*\.[0-9][0-9]* uuid:| 3DICC-Plugins[-.][a-z][a-z]*\.[0-9][0-9]* uuid:| VMMaker[-.][a-z][a-z-]*\.[0-9][0-9]*[ "]|static const char \*moduleName.*" INT_EXT;| Cog[-.][a-z][a-z-]*\.[0-9][0-9]* | Qwaq-Plugins[-.][a-z][a-z]*\.[0-9][0-9]* | VMConstruction-Plugins-OSProcessPlugin[a-z.-][a-z.-]*\.[0-9][0-9]* | Sound[-.][a-z][a-z]*\.[0-9][0-9]* uuid:|^[+-]const char \*interpreterVersion = |^\-\-\-|^\+\+\+|^[+-]$'`"
RESULT="`git diff -- "$f" | grep '^[+-]' | egrep -v ' VMMaker[-.][a-z][a-z-]*\.[0-9][0-9]* uuid:| Cog[-.][a-z][a-z]*\.[0-9][0-9]* uuid:| 3DICC-Plugins[-.][a-z][a-z]*\.[0-9][0-9]* uuid:| CryptographyPlugins[a-z.-][a-z.-]*\.[0-9][0-9]* | VMMaker[-.][a-z][a-z-]*\.[0-9][0-9]*[ "]|static const char \*moduleName.*" INT_EXT;| Cog[-.][a-z][a-z-]*\.[0-9][0-9]* | Qwaq-Plugins[-.][a-z][a-z]*\.[0-9][0-9]* | VMConstruction-Plugins-OSProcessPlugin[a-z.-][a-z.-]*\.[0-9][0-9]* | Sound[-.][a-z][a-z]*\.[0-9][0-9]* uuid:|^[+-]const char \*interpreterVersion = |^\-\-\-|^\+\+\+|^[+-]$'`"
if [ -z "$TEST" ]; then
test -z "$RESULT" && (echo reverting "$f"; git checkout -- "$f")
elif [ "$TEST" = "-T" ]; then
test -z "$RESULT" && echo $f essentially unchanged || echo $f changed
else
echo "testing; no output implies this would be reverted"
git diff -- "$f" | grep '^[+-]' | egrep -v ' VMMaker[-.][a-z][a-z-]*\.[0-9][0-9]* uuid:| Cog[-.][a-z][a-z]*\.[0-9][0-9]* uuid:| 3DICC-Plugins[-.][a-z][a-z]*\.[0-9][0-9]* uuid:| VMMaker[-.][a-z][a-z-]*\.[0-9][0-9]*[ "]|static const char \*moduleName.*" INT_EXT;| Cog[-.][a-z][a-z-]*\.[0-9][0-9]* | Qwaq-Plugins[-.][a-z][a-z]*\.[0-9][0-9]* | VMConstruction-Plugins-OSProcessPlugin[a-z.-][a-z.-]*\.[0-9][0-9]* | Sound[-.][a-z][a-z]*\.[0-9][0-9]* uuid:|^[+-]const char \*interpreterVersion =|^\-\-\-|^\+\+\+|^[+-]$'
git diff -- "$f" | grep '^[+-]' | egrep -v ' VMMaker[-.][a-z][a-z-]*\.[0-9][0-9]* uuid:| Cog[-.][a-z][a-z]*\.[0-9][0-9]* uuid:| 3DICC-Plugins[-.][a-z][a-z]*\.[0-9][0-9]* uuid:| CryptographyPlugins[a-z.-][a-z.-]*\.[0-9][0-9]* | VMMaker[-.][a-z][a-z-]*\.[0-9][0-9]*[ "]|static const char \*moduleName.*" INT_EXT;| Cog[-.][a-z][a-z-]*\.[0-9][0-9]* | Qwaq-Plugins[-.][a-z][a-z]*\.[0-9][0-9]* | VMConstruction-Plugins-OSProcessPlugin[a-z.-][a-z.-]*\.[0-9][0-9]* | Sound[-.][a-z][a-z]*\.[0-9][0-9]* uuid:|^[+-]const char \*interpreterVersion =|^\-\-\-|^\+\+\+|^[+-]$'
fi
fi
done
20 changes: 10 additions & 10 deletions src/plugins/FilePlugin/FilePlugin.c
@@ -1,9 +1,9 @@
/* Automatically generated by
VMPluginCodeGenerator VMMaker.oscog-eem.3339 uuid: b1c834e2-5de7-464c-aeb5-4f2a7b8812d6
VMPluginCodeGenerator VMMaker.oscog-eem.3349 uuid: 09001547-129a-4b6b-9fed-ccdd6790c8f4
from
FilePlugin VMMaker.oscog-eem.3339 uuid: b1c834e2-5de7-464c-aeb5-4f2a7b8812d6
FilePlugin VMMaker.oscog-eem.3349 uuid: 09001547-129a-4b6b-9fed-ccdd6790c8f4
*/
static char __buildInfo[] = "FilePlugin VMMaker.oscog-eem.3339 uuid: b1c834e2-5de7-464c-aeb5-4f2a7b8812d6 " __DATE__ ;
static char __buildInfo[] = "FilePlugin VMMaker.oscog-eem.3349 uuid: 09001547-129a-4b6b-9fed-ccdd6790c8f4 " __DATE__ ;


#include "config.h"
Expand Down Expand Up @@ -220,7 +220,7 @@ extern sqInt unpinObject(sqInt anObject);
extern
#endif
struct VirtualMachine* interpreterProxy;
static const char *moduleName = "FilePlugin VMMaker.oscog-eem.3339 " INT_EXT;
static const char *moduleName = "FilePlugin VMMaker.oscog-eem.3349 " INT_EXT;
static void * sCCPfn;
static void * sCDFfn;
static void * sCDPfn;
Expand Down Expand Up @@ -1235,7 +1235,7 @@ primitiveFileRead(void)
size_t startIndex;
size_t startIndex1;
size_t startIndex2;
sqInt threadIndexAndFlags;
sqInt vmHandle;
sqInt wasPinned;


Expand Down Expand Up @@ -1271,12 +1271,12 @@ primitiveFileRead(void)
}

/* Note: adjust startIndex for zero-origin byte indexing */
threadIndexAndFlags = disownVM(DisownVMForThreading);
vmHandle = disownVM(DisownVMForThreading);
elementSize = (slotSize == 0
? 1
: (byteSizeOf(array)) / slotSize);
bytesRead = sqFileReadIntoAt(file, count * elementSize, ((char *) (firstIndexableField(array))), (startIndex - 1) * elementSize);
ownVM(threadIndexAndFlags);
ownVM(vmHandle);
if (!wasPinned) {
unpinObject(array);
}
Expand Down Expand Up @@ -1379,7 +1379,7 @@ primitiveFileReadPinningAndDisowning(void)
sqInt objectPointer;
size_t slotSize;
size_t startIndex;
sqInt threadIndexAndFlags;
sqInt vmHandle;
sqInt wasPinned;

count = positiveMachineIntegerValueOf(stackValue(0));
Expand Down Expand Up @@ -1409,12 +1409,12 @@ primitiveFileReadPinningAndDisowning(void)
}

/* Note: adjust startIndex for zero-origin byte indexing */
threadIndexAndFlags = disownVM(DisownVMForThreading);
vmHandle = disownVM(DisownVMForThreading);
elementSize = (slotSize == 0
? 1
: (byteSizeOf(array)) / slotSize);
bytesRead = sqFileReadIntoAt(file, count * elementSize, ((char *) (firstIndexableField(array))), (startIndex - 1) * elementSize);
ownVM(threadIndexAndFlags);
ownVM(vmHandle);
if (!wasPinned) {
unpinObject(array);
}
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/Squeak3D/Squeak3D.c
@@ -1,9 +1,9 @@
/* Automatically generated by
VMPluginCodeGenerator VMMaker.oscog-eem.3297 uuid: 052ff1ab-c36e-496e-9d02-5c15f1bd3b1b
VMPluginCodeGenerator VMMaker.oscog-eem.3348 uuid: 5a9b79ce-4d0c-4368-96a3-ad3d4147ff63
from
B3DEnginePlugin Balloon3D-Plugins-eem.20 uuid: 3a40f0bb-2cf1-4850-8c45-5ace757c3bc3
B3DEnginePlugin Balloon3D-Plugins-eem.21 uuid: 8017be1f-70da-4efb-a5c9-c25f76c677a5
*/
static char __buildInfo[] = "B3DEnginePlugin Balloon3D-Plugins-eem.20 uuid: 3a40f0bb-2cf1-4850-8c45-5ace757c3bc3 " __DATE__ ;
static char __buildInfo[] = "B3DEnginePlugin Balloon3D-Plugins-eem.21 uuid: 8017be1f-70da-4efb-a5c9-c25f76c677a5 " __DATE__ ;


#include "config.h"
Expand Down Expand Up @@ -280,7 +280,7 @@ static double l2vSpecDir[3];
static sqInt lightFlags;
static float* litVertex;
static void * loadBBFn;
static const char *moduleName = "Squeak3D Balloon3D-Plugins-eem.20 " INT_EXT;
static const char *moduleName = "Squeak3D Balloon3D-Plugins-eem.21 " INT_EXT;
static float* primLight;
static float* primMaterial;
static sqInt vbFlags;
Expand Down Expand Up @@ -3849,7 +3849,7 @@ stackPrimitiveVertexArrayofSize(sqInt index, sqInt nItems)
}
if (isWords(oop)) {
oopSize = slotSizeOf(oop);
if (((oopSize >= nItems) * PrimVertexSize)
if ((oopSize >= (nItems * PrimVertexSize))
&& ((oopSize % PrimVertexSize) == 0)) {
return firstIndexableField(oop);
}
Expand Down
78 changes: 74 additions & 4 deletions src/plugins/SqueakSSL/SqueakSSL.c
@@ -1,9 +1,9 @@
/* Automatically generated by
VMPluginCodeGenerator VMMaker.oscog-eem.3024 uuid: 417aa150-be4e-4631-b35b-948afa18e190
VMPluginCodeGenerator VMMaker.oscog-eem.3349 uuid: 09001547-129a-4b6b-9fed-ccdd6790c8f4
from
SqueakSSLPlugin VMMaker.oscog-eem.3024 uuid: 417aa150-be4e-4631-b35b-948afa18e190
SqueakSSLPlugin VMMaker.oscog-eem.3349 uuid: 09001547-129a-4b6b-9fed-ccdd6790c8f4
*/
static char __buildInfo[] = "SqueakSSLPlugin VMMaker.oscog-eem.3024 uuid: 417aa150-be4e-4631-b35b-948afa18e190 " __DATE__ ;
static char __buildInfo[] = "SqueakSSLPlugin VMMaker.oscog-eem.3349 uuid: 09001547-129a-4b6b-9fed-ccdd6790c8f4 " __DATE__ ;


#include "config.h"
Expand Down Expand Up @@ -34,6 +34,10 @@ static char __buildInfo[] = "SqueakSSLPlugin VMMaker.oscog-eem.3024 uuid: 417aa1
#endif


/*** Constants ***/
#define DisownVMForThreading 32


/*** Function Prototypes ***/
EXPORT(const char*) getModuleName(void);
EXPORT(sqInt) primitiveAccept(void);
Expand All @@ -54,12 +58,16 @@ EXPORT(sqInt) setInterpreter(struct VirtualMachine *anInterpreter);
#if !defined(SQUEAK_BUILTIN_PLUGIN)
static sqInt (*byteSizeOf)(sqInt oop);
static sqInt (*classString)(void);
static sqInt (*disownVM)(sqInt flags);
static sqInt (*failed)(void);
static void * (*firstIndexableField)(sqInt oop);
static sqInt (*instantiateClassindexableSize)(sqInt classPointer, sqInt size);
static sqInt (*isBytes)(sqInt oop);
static sqInt (*isPinned)(sqInt anObject);
static sqInt (*methodArgumentCount)(void);
static sqInt (*nilObject)(void);
static sqInt (*ownVM)(sqInt flags);
static sqInt (*pinObject)(sqInt anObject);
static sqInt (*pop)(sqInt nItems);
static sqInt (*popthenPush)(sqInt nItems, sqInt oop);
static sqInt (*primitiveFail)(void);
Expand All @@ -68,15 +76,28 @@ static sqInt (*signed32BitIntegerFor)(sqInt integerValue);
static int (*signed32BitValueOf)(sqInt oop);
static sqInt (*stackIntegerValue)(sqInt offset);
static sqInt (*stackValue)(sqInt offset);
static sqInt (*unpinObject)(sqInt anObject);
#else /* !defined(SQUEAK_BUILTIN_PLUGIN) */
extern sqInt byteSizeOf(sqInt oop);
extern sqInt classString(void);
extern sqInt disownVM(sqInt flags);
extern sqInt failed(void);
extern void * firstIndexableField(sqInt oop);
extern sqInt instantiateClassindexableSize(sqInt classPointer, sqInt size);
extern sqInt isBytes(sqInt oop);
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 13)
extern sqInt isPinned(sqInt anObject);
#else
# define isPinned(anObject) 0
#endif
extern sqInt methodArgumentCount(void);
extern sqInt nilObject(void);
extern sqInt ownVM(sqInt flags);
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 13)
extern sqInt pinObject(sqInt anObject);
#else
# define pinObject(anObject) 0
#endif
extern sqInt pop(sqInt nItems);
extern sqInt popthenPush(sqInt nItems, sqInt oop);
extern sqInt primitiveFail(void);
Expand All @@ -85,10 +106,15 @@ extern sqInt signed32BitIntegerFor(sqInt integerValue);
extern int signed32BitValueOf(sqInt oop);
extern sqInt stackIntegerValue(sqInt offset);
extern sqInt stackValue(sqInt offset);
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 13)
extern sqInt unpinObject(sqInt anObject);
#else
# define unpinObject(anObject) 0
#endif
extern
#endif
struct VirtualMachine* interpreterProxy;
static const char *moduleName = "SqueakSSL VMMaker.oscog-eem.3024 " INT_EXT;
static const char *moduleName = "SqueakSSL VMMaker.oscog-eem.3349 " INT_EXT;



Expand Down Expand Up @@ -185,6 +211,9 @@ primitiveConnect(void)
sqInt srcOop;
char *srcPtr;
sqInt start;
sqInt vmHandle;
sqInt wasDestPinned;
sqInt wasSrcPinned;

if (!((methodArgumentCount()) == 5)) {
return primitiveFail();
Expand All @@ -204,11 +233,29 @@ primitiveConnect(void)
&& ((byteSizeOf(srcOop)) >= ((start + srcLen) - 1)))))) {
return primitiveFail();
}
if (!((wasSrcPinned = isPinned(srcOop)))) {
srcOop = pinObject(srcOop);
}
if (!((wasDestPinned = isPinned(dstOop)))) {
dstOop = pinObject(dstOop);
}
if ((srcOop == null)
|| (dstOop == null)) {
return primitiveFail();
}
srcPtr = firstIndexableField(srcOop);
dstPtr = firstIndexableField(dstOop);
srcPtr = (srcPtr + start) - 1;
dstLen = byteSizeOf(dstOop);
vmHandle = disownVM(DisownVMForThreading);
result = sqConnectSSL(handle, srcPtr, srcLen, dstPtr, dstLen);
ownVM(vmHandle);
if (!wasSrcPinned) {
unpinObject(srcOop);
}
if (!wasDestPinned) {
unpinObject(dstOop);
}
if (failed()) {
return null;
}
Expand Down Expand Up @@ -529,12 +576,28 @@ setInterpreter(struct VirtualMachine *anInterpreter)
#if !defined(SQUEAK_BUILTIN_PLUGIN)
byteSizeOf = interpreterProxy->byteSizeOf;
classString = interpreterProxy->classString;
disownVM = interpreterProxy->disownVM;
failed = interpreterProxy->failed;
firstIndexableField = interpreterProxy->firstIndexableField;
instantiateClassindexableSize = interpreterProxy->instantiateClassindexableSize;
isBytes = interpreterProxy->isBytes;
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 13)
isPinned = interpreterProxy->isPinned;
#else
#if !defined(isPinned)
isPinned = 0;
#endif
#endif
methodArgumentCount = interpreterProxy->methodArgumentCount;
nilObject = interpreterProxy->nilObject;
ownVM = interpreterProxy->ownVM;
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 13)
pinObject = interpreterProxy->pinObject;
#else
#if !defined(pinObject)
pinObject = 0;
#endif
#endif
pop = interpreterProxy->pop;
popthenPush = interpreterProxy->popthenPush;
primitiveFail = interpreterProxy->primitiveFail;
Expand All @@ -543,6 +606,13 @@ setInterpreter(struct VirtualMachine *anInterpreter)
signed32BitValueOf = interpreterProxy->signed32BitValueOf;
stackIntegerValue = interpreterProxy->stackIntegerValue;
stackValue = interpreterProxy->stackValue;
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 13)
unpinObject = interpreterProxy->unpinObject;
#else
#if !defined(unpinObject)
unpinObject = 0;
#endif
#endif
#endif /* !defined(SQUEAK_BUILTIN_PLUGIN) */
}
return ok;
Expand Down

0 comments on commit c1cd035

Please sign in to comment.