Skip to content

Commit b0fc229

Browse files
committed
CogVM source as per VMMaker.oscog-eem.2970
Merge VMMaker.oscog-dtl.2968. Add support for tracing primitives in a single plugin. The normal 256 element circular buffer is limited for tracking down plugin bugs because there is so much noise (context switches, other primitives, etc, etc). So if the primTracePluginName is non-nil only calls of primitives within that plugin are logged (plus a handful of other potentially significant events). This successfully traces primitives in e.g. the SoundPlugin: use via e.g. cogvm -logtrace SoundPlugin myimage.image Then sending SIGUSR1 one would see something like primSoundAvailableBytes primSoundPlaySamples:from:startingAt: primSoundAvailableBytes primSoundAvailableBytes primSoundAvailableBytes primSoundAvailableBytes primSoundAvailableBytes primSoundPlaySamples:from:startingAt: primSoundAvailableBytes stack page bytes 4096 available headroom 1480 minimum unused headroom 1912 (SIGUSR1)
1 parent 342e5e6 commit b0fc229

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2481
-866
lines changed

platforms/iOS/vm/OSX/sqSqueakOSXApplication.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ - (int) parseArgument: (NSString *) argData peek: (char *) peek
265265
}
266266
#endif
267267
#if COGVM
268+
if ([argData isEqualToString: VMOPTIONOBJ("logplugin")]) {
269+
extern char *primTracePluginName;
270+
primTracePluginName = peek;
271+
return 2;
272+
}
268273
if ([argData compare: VMOPTIONOBJ("trace") options: NSLiteralSearch range: NSMakeRange(0,VMOPTIONLEN(6))] == NSOrderedSame) {
269274
extern int traceFlags;
270275

@@ -539,6 +544,7 @@ - (void) printUsage {
539544
#endif
540545
#if STACKVM || NewspeakVM
541546
# if COGVM
547+
printf(" "VMOPTION("logplugin")" name only log primitives in plugin\n");
542548
printf(" "VMOPTION("trace")"[=num] enable tracing (optionally to a specific value)\n");
543549
# else
544550
printf(" "VMOPTION("sendtrace")" enable send tracing\n");

platforms/unix/vm/sqUnixMain.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,10 @@ static int vm_parseArgument(int argc, char **argv)
16231623
extern sqInt desiredCogCodeSize;
16241624
desiredCogCodeSize = strtobkm(argv[1]);
16251625
return 2; }
1626+
else if (argc > 1 && !strcmp(argv[0], VMOPTION("logplugin"))) {
1627+
extern char *primTracePluginName;
1628+
primTracePluginName = argv[1];
1629+
return 2; }
16261630
# define TLSLEN (sizeof(VMOPTION("trace"))-1)
16271631
else if (!strncmp(argv[0], VMOPTION("trace"), TLSLEN)) {
16281632
extern int traceFlags;
@@ -1715,6 +1719,7 @@ static void vm_printUsage(void)
17151719
printf(" -vm-<sys>-<dev> use the <dev> driver for <sys> (see below)\n");
17161720
#if STACKVM || NewspeakVM
17171721
# if COGVM
1722+
printf(" "VMOPTION("logplugin")" name only log primitives in plugin\n");
17181723
printf(" "VMOPTION("trace")"[=num] enable tracing (optionally to a specific value)\n");
17191724
# else
17201725
printf(" "VMOPTION("sendtrace")" enable send tracing\n");

platforms/win32/vm/sqWin32Main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,10 @@ parseVMArgument(int argc, char *argv[])
20002000
extern sqInt desiredCogCodeSize;
20012001
desiredCogCodeSize = strtobkm(argv[1]);
20022002
return 2; }
2003+
else if (argc > 1 && !strcmp(argv[0], VMOPTION("logplugin"))) {
2004+
extern char *primTracePluginName;
2005+
primTracePluginName = argv[1];
2006+
return 2; }
20032007
# define TLSLEN (sizeof(VMOPTION("trace"))-1)
20042008
else if (!strncmp(argv[0], VMOPTION("trace"), TLSLEN)) {
20052009
extern int traceFlags;

platforms/win32/vm/sqWin32Window.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3082,6 +3082,7 @@ printUsage(int level)
30823082
#endif /* STACKVM */
30833083
#if STACKVM || NewspeakVM
30843084
# if COGVM
3085+
TEXT("\n\t") TVMOPTION("logplugin")" TEXT(" name\t\tonly log primitives in plugin\n")
30853086
TEXT("\n\t") TVMOPTION("trace") TEXT("[=num]\t\tenable tracing (optionally to a specific value)")
30863087
# else
30873088
TEXT("\n\t") TVMOPTION("sendtrace") TEXT(" \t\t(trace sends to stdout for debug)")

spur64src/vm/cogit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Automatically generated by
2-
CCodeGenerator VMMaker.oscog-eem.2969 uuid: e47dec6d-965d-4dc1-ad51-ad192f9f6181
2+
CCodeGenerator VMMaker.oscog-eem.2970 uuid: 18899133-c885-4672-8722-9faceaa8bd85
33
*/
44

55

spur64src/vm/cogitARMv8.c

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* Automatically generated by
2-
CCodeGenerator VMMaker.oscog-eem.2969 uuid: e47dec6d-965d-4dc1-ad51-ad192f9f6181
2+
CCodeGenerator VMMaker.oscog-eem.2970 uuid: 18899133-c885-4672-8722-9faceaa8bd85
33
from
4-
StackToRegisterMappingCogit VMMaker.oscog-eem.2969 uuid: e47dec6d-965d-4dc1-ad51-ad192f9f6181
4+
StackToRegisterMappingCogit VMMaker.oscog-eem.2970 uuid: 18899133-c885-4672-8722-9faceaa8bd85
55
*/
6-
static char __buildInfo[] = "StackToRegisterMappingCogit VMMaker.oscog-eem.2969 uuid: e47dec6d-965d-4dc1-ad51-ad192f9f6181 " __DATE__ ;
6+
static char __buildInfo[] = "StackToRegisterMappingCogit VMMaker.oscog-eem.2970 uuid: 18899133-c885-4672-8722-9faceaa8bd85 " __DATE__ ;
77
char *__cogitBuildInfo = __buildInfo;
88

99

@@ -1423,9 +1423,9 @@ static sqInt expectedFPAlignment;
14231423
static sqInt expectedSPAlignment;
14241424
static sqInt extA;
14251425
static sqInt extB;
1426-
static sqInt externalPrimCallOffsets[MaxNumArgs + 1];
1427-
static sqInt externalPrimJumpOffsets[MaxNumArgs + 1];
1428-
static sqInt externalSetPrimOffsets[MaxNumArgs + 1];
1426+
static sqInt externalPrimCallOffsets[MaxNumArgs + MaxNumArgs + 2];
1427+
static sqInt externalPrimJumpOffsets[MaxNumArgs + MaxNumArgs + 2];
1428+
static sqInt externalSetPrimOffsets[MaxNumArgs + MaxNumArgs + 2];
14291429
static sqInt firstCPICCaseOffset;
14301430
static sqInt firstOpcodeIndex;
14311431
static sqInt firstSend;
@@ -25469,7 +25469,7 @@ compileInterpreterPrimitiveflags(void (*primitiveRoutine)(void), sqInt flags)
2546925469
/* begin Label */
2547025470
continuePostSampleNonPrim = genoperandoperand(Label, (labelCounter += 1), bytecodePC);
2547125471
}
25472-
if (recordPrimTrace()) {
25472+
if (recordPrimTraceForMethod(methodObj)) {
2547325473
genFastPrimTraceUsingand(ClassReg, SendNumArgsReg);
2547425474
}
2547525475
/* begin checkQuickConstant:forInstruction: */
@@ -27552,29 +27552,42 @@ primitiveGeneratorOrNil(void)
2755227552
return null;
2755327553
}
2755427554

27555+
27556+
/* Remember the offsets in an external primitive method where the function
27557+
address is assigned
27558+
to primitiveFunctionPointer (Spur) and where the external function is
27559+
either called or jumped to.
27560+
This allows the machine code to be unlinked when a plugin is unloaded,
27561+
etc.
27562+
*/
27563+
2755527564
/* SimpleStackBasedCogit>>#recordCallOffsetIn: */
2755627565
void
2755727566
recordCallOffsetIn(CogMethod *cogMethod)
2755827567
{
27568+
usqInt index;
2755927569
sqInt offset;
2756027570
sqInt *offsetTable;
2756127571

2756227572
offset = ((primSetFunctionLabel->address)) - (((sqInt)cogMethod));
27563-
if ((externalSetPrimOffsets[(cogMethod->cmNumArgs)]) == null) {
27564-
externalSetPrimOffsets[(cogMethod->cmNumArgs)] = offset;
27573+
index = (recordPrimTraceForMethod((cogMethod->methodObject))
27574+
? (((cogMethod->cmNumArgs)) + MaxNumArgs) + 1
27575+
: (cogMethod->cmNumArgs));
27576+
if ((externalSetPrimOffsets[index]) == null) {
27577+
externalSetPrimOffsets[index] = offset;
2756527578
}
2756627579
else {
27567-
assert((externalSetPrimOffsets[(cogMethod->cmNumArgs)]) == offset);
27580+
assert((externalSetPrimOffsets[index]) == offset);
2756827581
}
2756927582
offsetTable = (isJump(primInvokeInstruction)
2757027583
? externalPrimJumpOffsets
2757127584
: externalPrimCallOffsets);
2757227585
offset = (((primInvokeInstruction->address)) + ((primInvokeInstruction->machineCodeSize))) - (((sqInt)cogMethod));
27573-
if ((offsetTable[(cogMethod->cmNumArgs)]) == null) {
27574-
offsetTable[(cogMethod->cmNumArgs)] = offset;
27586+
if ((offsetTable[index]) == null) {
27587+
offsetTable[index] = offset;
2757527588
}
2757627589
else {
27577-
assert((offsetTable[(cogMethod->cmNumArgs)]) == offset);
27590+
assert((offsetTable[index]) == offset);
2757827591
}
2757927592
}
2758027593

@@ -27592,20 +27605,24 @@ rewritePrimInvocationInto(CogMethod *cogMethod, void (*primFunctionPointer)(void
2759227605
usqInt address;
2759327606
sqInt extent;
2759427607
sqInt flags;
27608+
usqInt index;
2759527609
sqInt primIndex;
2759627610

2759727611
assert(((cogMethod->cmType)) == CMMethod);
27612+
index = (recordPrimTraceForMethod((cogMethod->methodObject))
27613+
? (((cogMethod->cmNumArgs)) + MaxNumArgs) + 1
27614+
: (cogMethod->cmNumArgs));
2759827615
primIndex = primitiveIndexOfMethodheader((cogMethod->methodObject), (cogMethod->methodHeader));
2759927616
flags = primitivePropertyFlags(primIndex);
2760027617
if (flags & PrimCallNeedsPrimitiveFunction) {
27601-
storeLiteralbeforeFollowingAddress(backEnd, ((usqInt)primFunctionPointer), (((usqInt)cogMethod)) + (externalSetPrimOffsets[(cogMethod->cmNumArgs)]));
27618+
storeLiteralbeforeFollowingAddress(backEnd, ((usqInt)primFunctionPointer), (((usqInt)cogMethod)) + (externalSetPrimOffsets[index]));
2760227619
}
2760327620
if (flags & PrimCallMayEndureCodeCompaction) {
27604-
address = (((usqInt)cogMethod)) + (externalPrimJumpOffsets[(cogMethod->cmNumArgs)]);
27621+
address = (((usqInt)cogMethod)) + (externalPrimJumpOffsets[index]);
2760527622
extent = rewriteJumpFullAttarget(backEnd, address, ((usqInt)primFunctionPointer));
2760627623
}
2760727624
else {
27608-
address = (((usqInt)cogMethod)) + (externalPrimCallOffsets[(cogMethod->cmNumArgs)]);
27625+
address = (((usqInt)cogMethod)) + (externalPrimCallOffsets[index]);
2760927626
extent = rewriteCallFullAttarget(backEnd, address, ((usqInt)primFunctionPointer));
2761027627
}
2761127628
if (extent > 0) {
@@ -27796,7 +27813,7 @@ voidCogCompiledCode(void)
2779627813
sqInt i;
2779727814

2779827815
clearCogCompiledCode();
27799-
for (i = 0; i <= MaxNumArgs; i += 1) {
27816+
for (i = 0; i <= ((MaxNumArgs + MaxNumArgs) + 1); i += 1) {
2780027817
externalPrimJumpOffsets[i] = null;
2780127818
externalPrimCallOffsets[i] = null;
2780227819
externalSetPrimOffsets[i] = null;

spur64src/vm/cogitX64SysV.c

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* Automatically generated by
2-
CCodeGenerator VMMaker.oscog-eem.2969 uuid: e47dec6d-965d-4dc1-ad51-ad192f9f6181
2+
CCodeGenerator VMMaker.oscog-eem.2970 uuid: 18899133-c885-4672-8722-9faceaa8bd85
33
from
4-
StackToRegisterMappingCogit VMMaker.oscog-eem.2969 uuid: e47dec6d-965d-4dc1-ad51-ad192f9f6181
4+
StackToRegisterMappingCogit VMMaker.oscog-eem.2970 uuid: 18899133-c885-4672-8722-9faceaa8bd85
55
*/
6-
static char __buildInfo[] = "StackToRegisterMappingCogit VMMaker.oscog-eem.2969 uuid: e47dec6d-965d-4dc1-ad51-ad192f9f6181 " __DATE__ ;
6+
static char __buildInfo[] = "StackToRegisterMappingCogit VMMaker.oscog-eem.2970 uuid: 18899133-c885-4672-8722-9faceaa8bd85 " __DATE__ ;
77
char *__cogitBuildInfo = __buildInfo;
88

99

@@ -1375,9 +1375,9 @@ static sqInt expectedFPAlignment;
13751375
static sqInt expectedSPAlignment;
13761376
static sqInt extA;
13771377
static sqInt extB;
1378-
static sqInt externalPrimCallOffsets[MaxNumArgs + 1];
1379-
static sqInt externalPrimJumpOffsets[MaxNumArgs + 1];
1380-
static sqInt externalSetPrimOffsets[MaxNumArgs + 1];
1378+
static sqInt externalPrimCallOffsets[MaxNumArgs + MaxNumArgs + 2];
1379+
static sqInt externalPrimJumpOffsets[MaxNumArgs + MaxNumArgs + 2];
1380+
static sqInt externalSetPrimOffsets[MaxNumArgs + MaxNumArgs + 2];
13811381
static sqInt firstCPICCaseOffset;
13821382
static sqInt firstSend;
13831383
static BytecodeFixup * fixups;
@@ -24920,7 +24920,7 @@ compileInterpreterPrimitiveflags(void (*primitiveRoutine)(void), sqInt flags)
2492024920
/* begin Label */
2492124921
continuePostSampleNonPrim = genoperandoperand(Label, (labelCounter += 1), bytecodePC);
2492224922
}
24923-
if (recordPrimTrace()) {
24923+
if (recordPrimTraceForMethod(methodObj)) {
2492424924
genFastPrimTraceUsingand(ClassReg, SendNumArgsReg);
2492524925
}
2492624926
/* begin checkQuickConstant:forInstruction: */
@@ -26981,29 +26981,42 @@ primitiveGeneratorOrNil(void)
2698126981
return null;
2698226982
}
2698326983

26984+
26985+
/* Remember the offsets in an external primitive method where the function
26986+
address is assigned
26987+
to primitiveFunctionPointer (Spur) and where the external function is
26988+
either called or jumped to.
26989+
This allows the machine code to be unlinked when a plugin is unloaded,
26990+
etc.
26991+
*/
26992+
2698426993
/* SimpleStackBasedCogit>>#recordCallOffsetIn: */
2698526994
void
2698626995
recordCallOffsetIn(CogMethod *cogMethod)
2698726996
{
26997+
usqInt index;
2698826998
sqInt offset;
2698926999
sqInt *offsetTable;
2699027000

2699127001
offset = ((primSetFunctionLabel->address)) - (((sqInt)cogMethod));
26992-
if ((externalSetPrimOffsets[(cogMethod->cmNumArgs)]) == null) {
26993-
externalSetPrimOffsets[(cogMethod->cmNumArgs)] = offset;
27002+
index = (recordPrimTraceForMethod((cogMethod->methodObject))
27003+
? (((cogMethod->cmNumArgs)) + MaxNumArgs) + 1
27004+
: (cogMethod->cmNumArgs));
27005+
if ((externalSetPrimOffsets[index]) == null) {
27006+
externalSetPrimOffsets[index] = offset;
2699427007
}
2699527008
else {
26996-
assert((externalSetPrimOffsets[(cogMethod->cmNumArgs)]) == offset);
27009+
assert((externalSetPrimOffsets[index]) == offset);
2699727010
}
2699827011
offsetTable = (isJump(primInvokeInstruction)
2699927012
? externalPrimJumpOffsets
2700027013
: externalPrimCallOffsets);
2700127014
offset = (((primInvokeInstruction->address)) + ((primInvokeInstruction->machineCodeSize))) - (((sqInt)cogMethod));
27002-
if ((offsetTable[(cogMethod->cmNumArgs)]) == null) {
27003-
offsetTable[(cogMethod->cmNumArgs)] = offset;
27015+
if ((offsetTable[index]) == null) {
27016+
offsetTable[index] = offset;
2700427017
}
2700527018
else {
27006-
assert((offsetTable[(cogMethod->cmNumArgs)]) == offset);
27019+
assert((offsetTable[index]) == offset);
2700727020
}
2700827021
}
2700927022

@@ -27014,20 +27027,24 @@ rewritePrimInvocationInto(CogMethod *cogMethod, void (*primFunctionPointer)(void
2701427027
usqInt address;
2701527028
sqInt extent;
2701627029
sqInt flags;
27030+
usqInt index;
2701727031
sqInt primIndex;
2701827032

2701927033
assert(((cogMethod->cmType)) == CMMethod);
27034+
index = (recordPrimTraceForMethod((cogMethod->methodObject))
27035+
? (((cogMethod->cmNumArgs)) + MaxNumArgs) + 1
27036+
: (cogMethod->cmNumArgs));
2702027037
primIndex = primitiveIndexOfMethodheader((cogMethod->methodObject), (cogMethod->methodHeader));
2702127038
flags = primitivePropertyFlags(primIndex);
2702227039
if (flags & PrimCallNeedsPrimitiveFunction) {
27023-
storeLiteralbeforeFollowingAddress(backEnd, ((usqInt)primFunctionPointer), (((usqInt)cogMethod)) + (externalSetPrimOffsets[(cogMethod->cmNumArgs)]));
27040+
storeLiteralbeforeFollowingAddress(backEnd, ((usqInt)primFunctionPointer), (((usqInt)cogMethod)) + (externalSetPrimOffsets[index]));
2702427041
}
2702527042
if (flags & PrimCallMayEndureCodeCompaction) {
27026-
address = (((usqInt)cogMethod)) + (externalPrimJumpOffsets[(cogMethod->cmNumArgs)]);
27043+
address = (((usqInt)cogMethod)) + (externalPrimJumpOffsets[index]);
2702727044
extent = rewriteJumpFullAttarget(backEnd, address, ((usqInt)primFunctionPointer));
2702827045
}
2702927046
else {
27030-
address = (((usqInt)cogMethod)) + (externalPrimCallOffsets[(cogMethod->cmNumArgs)]);
27047+
address = (((usqInt)cogMethod)) + (externalPrimCallOffsets[index]);
2703127048
extent = rewriteCallFullAttarget(backEnd, address, ((usqInt)primFunctionPointer));
2703227049
}
2703327050
if (extent > 0) {
@@ -27218,7 +27235,7 @@ voidCogCompiledCode(void)
2721827235
sqInt i;
2721927236

2722027237
clearCogCompiledCode();
27221-
for (i = 0; i <= MaxNumArgs; i += 1) {
27238+
for (i = 0; i <= ((MaxNumArgs + MaxNumArgs) + 1); i += 1) {
2722227239
externalPrimJumpOffsets[i] = null;
2722327240
externalPrimCallOffsets[i] = null;
2722427241
externalSetPrimOffsets[i] = null;

0 commit comments

Comments
 (0)