Skip to content

Commit c1cd035

Browse files
committed
CogVM source as per VMMaker.oscog-eem.3349
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.
1 parent aba9cd3 commit c1cd035

31 files changed

+3075
-1675
lines changed

platforms/iOS/plugins/ClipboardExtendedPlugin/sqMacExtendedClipboard.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@
8888
NSArray *arrayOfTypes = @[formatType];
8989

9090
[inPasteboard addTypes: arrayOfTypes owner: nil];
91-
int ok = true;
91+
int ok = false;
9292
@try {
93-
ok = [inPasteboard setData: data forType: formatType];
93+
[inPasteboard setData: data forType: formatType];
94+
ok = true;
9495
}
95-
@catch (NSException *exception) {
96-
ok = false;
96+
@catch (id exception) {
9797
}
9898
if (!ok)
9999
interpreterProxy->primitiveFailFor(PrimErrOperationFailed);

scripts/revertIfEssentiallyUnchanged

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ for f in "$@"; do
1515
*M*) ;;
1616
*) continue
1717
esac
18-
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 = |^\-\-\-|^\+\+\+|^[+-]$'`"
18+
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 = |^\-\-\-|^\+\+\+|^[+-]$'`"
1919
if [ -z "$TEST" ]; then
2020
test -z "$RESULT" && (echo reverting "$f"; git checkout -- "$f")
2121
elif [ "$TEST" = "-T" ]; then
2222
test -z "$RESULT" && echo $f essentially unchanged || echo $f changed
2323
else
2424
echo "testing; no output implies this would be reverted"
25-
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 =|^\-\-\-|^\+\+\+|^[+-]$'
25+
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 =|^\-\-\-|^\+\+\+|^[+-]$'
2626
fi
2727
fi
2828
done

src/plugins/FilePlugin/FilePlugin.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* Automatically generated by
2-
VMPluginCodeGenerator VMMaker.oscog-eem.3339 uuid: b1c834e2-5de7-464c-aeb5-4f2a7b8812d6
2+
VMPluginCodeGenerator VMMaker.oscog-eem.3349 uuid: 09001547-129a-4b6b-9fed-ccdd6790c8f4
33
from
4-
FilePlugin VMMaker.oscog-eem.3339 uuid: b1c834e2-5de7-464c-aeb5-4f2a7b8812d6
4+
FilePlugin VMMaker.oscog-eem.3349 uuid: 09001547-129a-4b6b-9fed-ccdd6790c8f4
55
*/
6-
static char __buildInfo[] = "FilePlugin VMMaker.oscog-eem.3339 uuid: b1c834e2-5de7-464c-aeb5-4f2a7b8812d6 " __DATE__ ;
6+
static char __buildInfo[] = "FilePlugin VMMaker.oscog-eem.3349 uuid: 09001547-129a-4b6b-9fed-ccdd6790c8f4 " __DATE__ ;
77

88

99
#include "config.h"
@@ -220,7 +220,7 @@ extern sqInt unpinObject(sqInt anObject);
220220
extern
221221
#endif
222222
struct VirtualMachine* interpreterProxy;
223-
static const char *moduleName = "FilePlugin VMMaker.oscog-eem.3339 " INT_EXT;
223+
static const char *moduleName = "FilePlugin VMMaker.oscog-eem.3349 " INT_EXT;
224224
static void * sCCPfn;
225225
static void * sCDFfn;
226226
static void * sCDPfn;
@@ -1235,7 +1235,7 @@ primitiveFileRead(void)
12351235
size_t startIndex;
12361236
size_t startIndex1;
12371237
size_t startIndex2;
1238-
sqInt threadIndexAndFlags;
1238+
sqInt vmHandle;
12391239
sqInt wasPinned;
12401240

12411241

@@ -1271,12 +1271,12 @@ primitiveFileRead(void)
12711271
}
12721272

12731273
/* Note: adjust startIndex for zero-origin byte indexing */
1274-
threadIndexAndFlags = disownVM(DisownVMForThreading);
1274+
vmHandle = disownVM(DisownVMForThreading);
12751275
elementSize = (slotSize == 0
12761276
? 1
12771277
: (byteSizeOf(array)) / slotSize);
12781278
bytesRead = sqFileReadIntoAt(file, count * elementSize, ((char *) (firstIndexableField(array))), (startIndex - 1) * elementSize);
1279-
ownVM(threadIndexAndFlags);
1279+
ownVM(vmHandle);
12801280
if (!wasPinned) {
12811281
unpinObject(array);
12821282
}
@@ -1379,7 +1379,7 @@ primitiveFileReadPinningAndDisowning(void)
13791379
sqInt objectPointer;
13801380
size_t slotSize;
13811381
size_t startIndex;
1382-
sqInt threadIndexAndFlags;
1382+
sqInt vmHandle;
13831383
sqInt wasPinned;
13841384

13851385
count = positiveMachineIntegerValueOf(stackValue(0));
@@ -1409,12 +1409,12 @@ primitiveFileReadPinningAndDisowning(void)
14091409
}
14101410

14111411
/* Note: adjust startIndex for zero-origin byte indexing */
1412-
threadIndexAndFlags = disownVM(DisownVMForThreading);
1412+
vmHandle = disownVM(DisownVMForThreading);
14131413
elementSize = (slotSize == 0
14141414
? 1
14151415
: (byteSizeOf(array)) / slotSize);
14161416
bytesRead = sqFileReadIntoAt(file, count * elementSize, ((char *) (firstIndexableField(array))), (startIndex - 1) * elementSize);
1417-
ownVM(threadIndexAndFlags);
1417+
ownVM(vmHandle);
14181418
if (!wasPinned) {
14191419
unpinObject(array);
14201420
}

src/plugins/Squeak3D/Squeak3D.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* Automatically generated by
2-
VMPluginCodeGenerator VMMaker.oscog-eem.3297 uuid: 052ff1ab-c36e-496e-9d02-5c15f1bd3b1b
2+
VMPluginCodeGenerator VMMaker.oscog-eem.3348 uuid: 5a9b79ce-4d0c-4368-96a3-ad3d4147ff63
33
from
4-
B3DEnginePlugin Balloon3D-Plugins-eem.20 uuid: 3a40f0bb-2cf1-4850-8c45-5ace757c3bc3
4+
B3DEnginePlugin Balloon3D-Plugins-eem.21 uuid: 8017be1f-70da-4efb-a5c9-c25f76c677a5
55
*/
6-
static char __buildInfo[] = "B3DEnginePlugin Balloon3D-Plugins-eem.20 uuid: 3a40f0bb-2cf1-4850-8c45-5ace757c3bc3 " __DATE__ ;
6+
static char __buildInfo[] = "B3DEnginePlugin Balloon3D-Plugins-eem.21 uuid: 8017be1f-70da-4efb-a5c9-c25f76c677a5 " __DATE__ ;
77

88

99
#include "config.h"
@@ -280,7 +280,7 @@ static double l2vSpecDir[3];
280280
static sqInt lightFlags;
281281
static float* litVertex;
282282
static void * loadBBFn;
283-
static const char *moduleName = "Squeak3D Balloon3D-Plugins-eem.20 " INT_EXT;
283+
static const char *moduleName = "Squeak3D Balloon3D-Plugins-eem.21 " INT_EXT;
284284
static float* primLight;
285285
static float* primMaterial;
286286
static sqInt vbFlags;
@@ -3849,7 +3849,7 @@ stackPrimitiveVertexArrayofSize(sqInt index, sqInt nItems)
38493849
}
38503850
if (isWords(oop)) {
38513851
oopSize = slotSizeOf(oop);
3852-
if (((oopSize >= nItems) * PrimVertexSize)
3852+
if ((oopSize >= (nItems * PrimVertexSize))
38533853
&& ((oopSize % PrimVertexSize) == 0)) {
38543854
return firstIndexableField(oop);
38553855
}

src/plugins/SqueakSSL/SqueakSSL.c

+74-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* Automatically generated by
2-
VMPluginCodeGenerator VMMaker.oscog-eem.3024 uuid: 417aa150-be4e-4631-b35b-948afa18e190
2+
VMPluginCodeGenerator VMMaker.oscog-eem.3349 uuid: 09001547-129a-4b6b-9fed-ccdd6790c8f4
33
from
4-
SqueakSSLPlugin VMMaker.oscog-eem.3024 uuid: 417aa150-be4e-4631-b35b-948afa18e190
4+
SqueakSSLPlugin VMMaker.oscog-eem.3349 uuid: 09001547-129a-4b6b-9fed-ccdd6790c8f4
55
*/
6-
static char __buildInfo[] = "SqueakSSLPlugin VMMaker.oscog-eem.3024 uuid: 417aa150-be4e-4631-b35b-948afa18e190 " __DATE__ ;
6+
static char __buildInfo[] = "SqueakSSLPlugin VMMaker.oscog-eem.3349 uuid: 09001547-129a-4b6b-9fed-ccdd6790c8f4 " __DATE__ ;
77

88

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

3636

37+
/*** Constants ***/
38+
#define DisownVMForThreading 32
39+
40+
3741
/*** Function Prototypes ***/
3842
EXPORT(const char*) getModuleName(void);
3943
EXPORT(sqInt) primitiveAccept(void);
@@ -54,12 +58,16 @@ EXPORT(sqInt) setInterpreter(struct VirtualMachine *anInterpreter);
5458
#if !defined(SQUEAK_BUILTIN_PLUGIN)
5559
static sqInt (*byteSizeOf)(sqInt oop);
5660
static sqInt (*classString)(void);
61+
static sqInt (*disownVM)(sqInt flags);
5762
static sqInt (*failed)(void);
5863
static void * (*firstIndexableField)(sqInt oop);
5964
static sqInt (*instantiateClassindexableSize)(sqInt classPointer, sqInt size);
6065
static sqInt (*isBytes)(sqInt oop);
66+
static sqInt (*isPinned)(sqInt anObject);
6167
static sqInt (*methodArgumentCount)(void);
6268
static sqInt (*nilObject)(void);
69+
static sqInt (*ownVM)(sqInt flags);
70+
static sqInt (*pinObject)(sqInt anObject);
6371
static sqInt (*pop)(sqInt nItems);
6472
static sqInt (*popthenPush)(sqInt nItems, sqInt oop);
6573
static sqInt (*primitiveFail)(void);
@@ -68,15 +76,28 @@ static sqInt (*signed32BitIntegerFor)(sqInt integerValue);
6876
static int (*signed32BitValueOf)(sqInt oop);
6977
static sqInt (*stackIntegerValue)(sqInt offset);
7078
static sqInt (*stackValue)(sqInt offset);
79+
static sqInt (*unpinObject)(sqInt anObject);
7180
#else /* !defined(SQUEAK_BUILTIN_PLUGIN) */
7281
extern sqInt byteSizeOf(sqInt oop);
7382
extern sqInt classString(void);
83+
extern sqInt disownVM(sqInt flags);
7484
extern sqInt failed(void);
7585
extern void * firstIndexableField(sqInt oop);
7686
extern sqInt instantiateClassindexableSize(sqInt classPointer, sqInt size);
7787
extern sqInt isBytes(sqInt oop);
88+
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 13)
89+
extern sqInt isPinned(sqInt anObject);
90+
#else
91+
# define isPinned(anObject) 0
92+
#endif
7893
extern sqInt methodArgumentCount(void);
7994
extern sqInt nilObject(void);
95+
extern sqInt ownVM(sqInt flags);
96+
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 13)
97+
extern sqInt pinObject(sqInt anObject);
98+
#else
99+
# define pinObject(anObject) 0
100+
#endif
80101
extern sqInt pop(sqInt nItems);
81102
extern sqInt popthenPush(sqInt nItems, sqInt oop);
82103
extern sqInt primitiveFail(void);
@@ -85,10 +106,15 @@ extern sqInt signed32BitIntegerFor(sqInt integerValue);
85106
extern int signed32BitValueOf(sqInt oop);
86107
extern sqInt stackIntegerValue(sqInt offset);
87108
extern sqInt stackValue(sqInt offset);
109+
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 13)
110+
extern sqInt unpinObject(sqInt anObject);
111+
#else
112+
# define unpinObject(anObject) 0
113+
#endif
88114
extern
89115
#endif
90116
struct VirtualMachine* interpreterProxy;
91-
static const char *moduleName = "SqueakSSL VMMaker.oscog-eem.3024 " INT_EXT;
117+
static const char *moduleName = "SqueakSSL VMMaker.oscog-eem.3349 " INT_EXT;
92118

93119

94120

@@ -185,6 +211,9 @@ primitiveConnect(void)
185211
sqInt srcOop;
186212
char *srcPtr;
187213
sqInt start;
214+
sqInt vmHandle;
215+
sqInt wasDestPinned;
216+
sqInt wasSrcPinned;
188217

189218
if (!((methodArgumentCount()) == 5)) {
190219
return primitiveFail();
@@ -204,11 +233,29 @@ primitiveConnect(void)
204233
&& ((byteSizeOf(srcOop)) >= ((start + srcLen) - 1)))))) {
205234
return primitiveFail();
206235
}
236+
if (!((wasSrcPinned = isPinned(srcOop)))) {
237+
srcOop = pinObject(srcOop);
238+
}
239+
if (!((wasDestPinned = isPinned(dstOop)))) {
240+
dstOop = pinObject(dstOop);
241+
}
242+
if ((srcOop == null)
243+
|| (dstOop == null)) {
244+
return primitiveFail();
245+
}
207246
srcPtr = firstIndexableField(srcOop);
208247
dstPtr = firstIndexableField(dstOop);
209248
srcPtr = (srcPtr + start) - 1;
210249
dstLen = byteSizeOf(dstOop);
250+
vmHandle = disownVM(DisownVMForThreading);
211251
result = sqConnectSSL(handle, srcPtr, srcLen, dstPtr, dstLen);
252+
ownVM(vmHandle);
253+
if (!wasSrcPinned) {
254+
unpinObject(srcOop);
255+
}
256+
if (!wasDestPinned) {
257+
unpinObject(dstOop);
258+
}
212259
if (failed()) {
213260
return null;
214261
}
@@ -529,12 +576,28 @@ setInterpreter(struct VirtualMachine *anInterpreter)
529576
#if !defined(SQUEAK_BUILTIN_PLUGIN)
530577
byteSizeOf = interpreterProxy->byteSizeOf;
531578
classString = interpreterProxy->classString;
579+
disownVM = interpreterProxy->disownVM;
532580
failed = interpreterProxy->failed;
533581
firstIndexableField = interpreterProxy->firstIndexableField;
534582
instantiateClassindexableSize = interpreterProxy->instantiateClassindexableSize;
535583
isBytes = interpreterProxy->isBytes;
584+
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 13)
585+
isPinned = interpreterProxy->isPinned;
586+
#else
587+
#if !defined(isPinned)
588+
isPinned = 0;
589+
#endif
590+
#endif
536591
methodArgumentCount = interpreterProxy->methodArgumentCount;
537592
nilObject = interpreterProxy->nilObject;
593+
ownVM = interpreterProxy->ownVM;
594+
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 13)
595+
pinObject = interpreterProxy->pinObject;
596+
#else
597+
#if !defined(pinObject)
598+
pinObject = 0;
599+
#endif
600+
#endif
538601
pop = interpreterProxy->pop;
539602
popthenPush = interpreterProxy->popthenPush;
540603
primitiveFail = interpreterProxy->primitiveFail;
@@ -543,6 +606,13 @@ setInterpreter(struct VirtualMachine *anInterpreter)
543606
signed32BitValueOf = interpreterProxy->signed32BitValueOf;
544607
stackIntegerValue = interpreterProxy->stackIntegerValue;
545608
stackValue = interpreterProxy->stackValue;
609+
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 13)
610+
unpinObject = interpreterProxy->unpinObject;
611+
#else
612+
#if !defined(unpinObject)
613+
unpinObject = 0;
614+
#endif
615+
#endif
546616
#endif /* !defined(SQUEAK_BUILTIN_PLUGIN) */
547617
}
548618
return ok;

0 commit comments

Comments
 (0)